John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/ |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | //===----------------------------------------------------------------------===/ |
| 8 | // |
| 9 | // This file implements a semantic tree transformation that takes a given |
| 10 | // AST and rebuilds it, possibly transforming some nodes in the process. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===/ |
| 13 | #ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 14 | #define LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 15 | |
| 16 | #include "Sema.h" |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 17 | #include "Lookup.h" |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 18 | #include "clang/Sema/SemaDiagnostic.h" |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 19 | #include "clang/AST/Decl.h" |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 20 | #include "clang/AST/Expr.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 21 | #include "clang/AST/ExprCXX.h" |
| 22 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 23 | #include "clang/AST/Stmt.h" |
| 24 | #include "clang/AST/StmtCXX.h" |
| 25 | #include "clang/AST/StmtObjC.h" |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 26 | #include "clang/AST/TypeLocBuilder.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 27 | #include "clang/Parse/Ownership.h" |
| 28 | #include "clang/Parse/Designator.h" |
| 29 | #include "clang/Lex/Preprocessor.h" |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 30 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 31 | #include <algorithm> |
| 32 | |
| 33 | namespace clang { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 34 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 35 | /// \brief A semantic tree transformation that allows one to transform one |
| 36 | /// abstract syntax tree into another. |
| 37 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 38 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 39 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 40 | /// behavior specific to that transformation. For example, template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 41 | /// instantiation is implemented as a tree transformation where the |
| 42 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 43 | /// template arguments for their corresponding template parameters; a similar |
| 44 | /// transformation is performed for non-type template parameters and |
| 45 | /// template template parameters. |
| 46 | /// |
| 47 | /// This tree-transformation template uses static polymorphism to allow |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 48 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 49 | /// override any of the transformation or rebuild operators by providing an |
| 50 | /// operation with the same signature as the default implementation. The |
| 51 | /// overridding function should not be virtual. |
| 52 | /// |
| 53 | /// Semantic tree transformations are split into two stages, either of which |
| 54 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 55 | /// or the parts of an AST node using the various transformation functions, |
| 56 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 57 | /// node of the appropriate kind from the pieces. The default transformation |
| 58 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 59 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 60 | /// were changed by the transformation, invokes the rebuild operation to create |
| 61 | /// a new AST node. |
| 62 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 63 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 64 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 65 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(), |
| 66 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 67 | /// new implementations. |
| 68 | /// |
| 69 | /// For more fine-grained transformations, subclasses can replace any of the |
| 70 | /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 71 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 72 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 73 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 74 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 75 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 76 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 77 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 78 | /// be able to use more efficient rebuild steps. |
| 79 | /// |
| 80 | /// There are a handful of other functions that can be overridden, allowing one |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 81 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 82 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 83 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 84 | /// default locations and entity names used for type-checking |
| 85 | /// (\c getBaseLocation(), \c getBaseEntity()). |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 86 | template<typename Derived> |
| 87 | class TreeTransform { |
| 88 | protected: |
| 89 | Sema &SemaRef; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 90 | |
| 91 | public: |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 92 | typedef Sema::OwningStmtResult OwningStmtResult; |
| 93 | typedef Sema::OwningExprResult OwningExprResult; |
| 94 | typedef Sema::StmtArg StmtArg; |
| 95 | typedef Sema::ExprArg ExprArg; |
| 96 | typedef Sema::MultiExprArg MultiExprArg; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 97 | typedef Sema::MultiStmtArg MultiStmtArg; |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 98 | typedef Sema::DeclPtrTy DeclPtrTy; |
| 99 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 100 | /// \brief Initializes a new tree transformer. |
| 101 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 103 | /// \brief Retrieves a reference to the derived class. |
| 104 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 105 | |
| 106 | /// \brief Retrieves a reference to the derived class. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 107 | const Derived &getDerived() const { |
| 108 | return static_cast<const Derived&>(*this); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /// \brief Retrieves a reference to the semantic analysis object used for |
| 112 | /// this tree transform. |
| 113 | Sema &getSema() const { return SemaRef; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 114 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 115 | /// \brief Whether the transformation should always rebuild AST nodes, even |
| 116 | /// if none of the children have changed. |
| 117 | /// |
| 118 | /// Subclasses may override this function to specify when the transformation |
| 119 | /// should rebuild all AST nodes. |
| 120 | bool AlwaysRebuild() { return false; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 122 | /// \brief Returns the location of the entity being transformed, if that |
| 123 | /// information was not available elsewhere in the AST. |
| 124 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 125 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 126 | /// provide an alternative implementation that provides better location |
| 127 | /// information. |
| 128 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 129 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 130 | /// \brief Returns the name of the entity being transformed, if that |
| 131 | /// information was not available elsewhere in the AST. |
| 132 | /// |
| 133 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 134 | /// implementation with a more precise name. |
| 135 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 136 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 137 | /// \brief Sets the "base" location and entity when that |
| 138 | /// information is known based on another transformation. |
| 139 | /// |
| 140 | /// By default, the source location and entity are ignored. Subclasses can |
| 141 | /// override this function to provide a customized implementation. |
| 142 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 143 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 144 | /// \brief RAII object that temporarily sets the base location and entity |
| 145 | /// used for reporting diagnostics in types. |
| 146 | class TemporaryBase { |
| 147 | TreeTransform &Self; |
| 148 | SourceLocation OldLocation; |
| 149 | DeclarationName OldEntity; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 150 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 151 | public: |
| 152 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 153 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 154 | OldLocation = Self.getDerived().getBaseLocation(); |
| 155 | OldEntity = Self.getDerived().getBaseEntity(); |
| 156 | Self.getDerived().setBase(Location, Entity); |
| 157 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 158 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 159 | ~TemporaryBase() { |
| 160 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 161 | } |
| 162 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 163 | |
| 164 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 165 | /// transformed. |
| 166 | /// |
| 167 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 168 | /// to short-circuit evaluation when it is known that a given type will |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 169 | /// not change. For example, template instantiation need not traverse |
| 170 | /// non-dependent types. |
| 171 | bool AlreadyTransformed(QualType T) { |
| 172 | return T.isNull(); |
| 173 | } |
| 174 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 175 | /// \brief Determine whether the given call argument should be dropped, e.g., |
| 176 | /// because it is a default argument. |
| 177 | /// |
| 178 | /// Subclasses can provide an alternative implementation of this routine to |
| 179 | /// determine which kinds of call arguments get dropped. By default, |
| 180 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 181 | bool DropCallArgument(Expr *E) { |
| 182 | return E->isDefaultArgument(); |
| 183 | } |
| 184 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 185 | /// \brief Transforms the given type into another type. |
| 186 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 187 | /// By default, this routine transforms a type by creating a |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 188 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 189 | /// function. This is expensive, but we don't mind, because |
| 190 | /// this method is deprecated anyway; all users should be |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 191 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 192 | /// |
| 193 | /// \returns the transformed type. |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 194 | QualType TransformType(QualType T, QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 195 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 196 | /// \brief Transforms the given type-with-location into a new |
| 197 | /// type-with-location. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 198 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 199 | /// By default, this routine transforms a type by delegating to the |
| 200 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 201 | /// may override this function (to take over all type |
| 202 | /// transformations) or some set of the TransformXXXType functions |
| 203 | /// to alter the transformation. |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 204 | TypeSourceInfo *TransformType(TypeSourceInfo *DI, |
| 205 | QualType ObjectType = QualType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 206 | |
| 207 | /// \brief Transform the given type-with-location into a new |
| 208 | /// type, collecting location information in the given builder |
| 209 | /// as necessary. |
| 210 | /// |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 211 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL, |
| 212 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 213 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 214 | /// \brief Transform the given statement. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 215 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 216 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 217 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 218 | /// statement or the TransformExpr() function to transform an expression. |
| 219 | /// Subclasses may override this function to transform statements using some |
| 220 | /// other mechanism. |
| 221 | /// |
| 222 | /// \returns the transformed statement. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 223 | OwningStmtResult TransformStmt(Stmt *S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 224 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 225 | /// \brief Transform the given expression. |
| 226 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 227 | /// By default, this routine transforms an expression by delegating to the |
| 228 | /// appropriate TransformXXXExpr function to build a new expression. |
| 229 | /// Subclasses may override this function to transform expressions using some |
| 230 | /// other mechanism. |
| 231 | /// |
| 232 | /// \returns the transformed expression. |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 233 | OwningExprResult TransformExpr(Expr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 234 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 235 | /// \brief Transform the given declaration, which is referenced from a type |
| 236 | /// or expression. |
| 237 | /// |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 238 | /// By default, acts as the identity function on declarations. Subclasses |
| 239 | /// may override this function to provide alternate behavior. |
| 240 | Decl *TransformDecl(Decl *D) { return D; } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 241 | |
| 242 | /// \brief Transform the definition of the given declaration. |
| 243 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 244 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 245 | /// Subclasses may override this function to provide alternate behavior. |
| 246 | Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 247 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 248 | /// \brief Transform the given declaration, which was the first part of a |
| 249 | /// nested-name-specifier in a member access expression. |
| 250 | /// |
| 251 | /// This specific declaration transformation only applies to the first |
| 252 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 253 | /// the \c T in \c x->T::member |
| 254 | /// |
| 255 | /// By default, invokes TransformDecl() to transform the declaration. |
| 256 | /// Subclasses may override this function to provide alternate behavior. |
| 257 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 258 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(D)); |
| 259 | } |
| 260 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 261 | /// \brief Transform the given nested-name-specifier. |
| 262 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 263 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 264 | /// nested-name-specifier. Subclasses may override this function to provide |
| 265 | /// alternate behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 266 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 267 | SourceRange Range, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 268 | bool MayBePseudoDestructor, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 269 | QualType ObjectType = QualType(), |
| 270 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 271 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 272 | /// \brief Transform the given declaration name. |
| 273 | /// |
| 274 | /// By default, transforms the types of conversion function, constructor, |
| 275 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 276 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 277 | /// override this function to provide alternate behavior. |
| 278 | DeclarationName TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 279 | SourceLocation Loc, |
| 280 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 281 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 282 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 283 | /// |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 284 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 285 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 286 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 287 | TemplateName TransformTemplateName(TemplateName Name, |
| 288 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 289 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 290 | /// \brief Transform the given template argument. |
| 291 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 292 | /// By default, this operation transforms the type, expression, or |
| 293 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 294 | /// new template argument from the transformed result. Subclasses may |
| 295 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 296 | /// |
| 297 | /// Returns true if there was an error. |
| 298 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 299 | TemplateArgumentLoc &Output); |
| 300 | |
| 301 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 302 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 303 | TemplateArgumentLoc &ArgLoc); |
| 304 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 305 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 306 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 307 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 308 | getDerived().getBaseLocation()); |
| 309 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 310 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 311 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 312 | #define TYPELOC(CLASS, PARENT) \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 313 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \ |
| 314 | QualType ObjectType = QualType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 315 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 316 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 317 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL, |
| 318 | QualType ObjectType); |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 319 | |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 320 | QualType |
| 321 | TransformTemplateSpecializationType(const TemplateSpecializationType *T, |
| 322 | QualType ObjectType); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 323 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 324 | OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 325 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 326 | #define STMT(Node, Parent) \ |
| 327 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 328 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 329 | OwningExprResult Transform##Node(Node *E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 330 | #define ABSTRACT_EXPR(Node, Parent) |
| 331 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 332 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 333 | /// \brief Build a new pointer type given its pointee type. |
| 334 | /// |
| 335 | /// By default, performs semantic analysis when building the pointer type. |
| 336 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 337 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 338 | |
| 339 | /// \brief Build a new block pointer type given its pointee type. |
| 340 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 341 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 342 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 343 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 344 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 345 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 346 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 347 | /// By default, performs semantic analysis when building the |
| 348 | /// reference type. Subclasses may override this routine to provide |
| 349 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 350 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 351 | /// \param LValue whether the type was written with an lvalue sigil |
| 352 | /// or an rvalue sigil. |
| 353 | QualType RebuildReferenceType(QualType ReferentType, |
| 354 | bool LValue, |
| 355 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 356 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 357 | /// \brief Build a new member pointer type given the pointee type and the |
| 358 | /// class type it refers into. |
| 359 | /// |
| 360 | /// By default, performs semantic analysis when building the member pointer |
| 361 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 362 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 363 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 364 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 365 | /// \brief Build a new Objective C object pointer type. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 366 | QualType RebuildObjCObjectPointerType(QualType PointeeType, |
| 367 | SourceLocation Sigil); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 368 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 369 | /// \brief Build a new array type given the element type, size |
| 370 | /// modifier, size of the array (if known), size expression, and index type |
| 371 | /// qualifiers. |
| 372 | /// |
| 373 | /// By default, performs semantic analysis when building the array type. |
| 374 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 375 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 376 | QualType RebuildArrayType(QualType ElementType, |
| 377 | ArrayType::ArraySizeModifier SizeMod, |
| 378 | const llvm::APInt *Size, |
| 379 | Expr *SizeExpr, |
| 380 | unsigned IndexTypeQuals, |
| 381 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 382 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 383 | /// \brief Build a new constant array type given the element type, size |
| 384 | /// modifier, (known) size of the array, and index type qualifiers. |
| 385 | /// |
| 386 | /// By default, performs semantic analysis when building the array type. |
| 387 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 389 | ArrayType::ArraySizeModifier SizeMod, |
| 390 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 391 | unsigned IndexTypeQuals, |
| 392 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 393 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 394 | /// \brief Build a new incomplete array type given the element type, size |
| 395 | /// modifier, and index type qualifiers. |
| 396 | /// |
| 397 | /// By default, performs semantic analysis when building the array type. |
| 398 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 399 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 400 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 401 | unsigned IndexTypeQuals, |
| 402 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 403 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 404 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 405 | /// size modifier, size expression, and index type qualifiers. |
| 406 | /// |
| 407 | /// By default, performs semantic analysis when building the array type. |
| 408 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 409 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 410 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 411 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 412 | unsigned IndexTypeQuals, |
| 413 | SourceRange BracketsRange); |
| 414 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 415 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 416 | /// size modifier, size expression, and index type qualifiers. |
| 417 | /// |
| 418 | /// By default, performs semantic analysis when building the array type. |
| 419 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 420 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 421 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 422 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 423 | unsigned IndexTypeQuals, |
| 424 | SourceRange BracketsRange); |
| 425 | |
| 426 | /// \brief Build a new vector type given the element type and |
| 427 | /// number of elements. |
| 428 | /// |
| 429 | /// By default, performs semantic analysis when building the vector type. |
| 430 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 431 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
| 432 | bool IsAltiVec, bool IsPixel); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 433 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 434 | /// \brief Build a new extended vector type given the element type and |
| 435 | /// number of elements. |
| 436 | /// |
| 437 | /// By default, performs semantic analysis when building the vector type. |
| 438 | /// Subclasses may override this routine to provide different behavior. |
| 439 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 440 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 441 | |
| 442 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 443 | /// given the element type and number of elements. |
| 444 | /// |
| 445 | /// By default, performs semantic analysis when building the vector type. |
| 446 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 447 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 448 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 449 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 450 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 451 | /// \brief Build a new function type. |
| 452 | /// |
| 453 | /// By default, performs semantic analysis when building the function type. |
| 454 | /// Subclasses may override this routine to provide different behavior. |
| 455 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 456 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 457 | unsigned NumParamTypes, |
| 458 | bool Variadic, unsigned Quals); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 459 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 460 | /// \brief Build a new unprototyped function type. |
| 461 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 462 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 463 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 464 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 465 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 466 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 467 | /// \brief Build a new typedef type. |
| 468 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 469 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 470 | } |
| 471 | |
| 472 | /// \brief Build a new class/struct/union type. |
| 473 | QualType RebuildRecordType(RecordDecl *Record) { |
| 474 | return SemaRef.Context.getTypeDeclType(Record); |
| 475 | } |
| 476 | |
| 477 | /// \brief Build a new Enum type. |
| 478 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 479 | return SemaRef.Context.getTypeDeclType(Enum); |
| 480 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 481 | |
| 482 | /// \brief Build a new elaborated type. |
| 483 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) { |
| 484 | return SemaRef.Context.getElaboratedType(T, Tag); |
| 485 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 486 | |
| 487 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 488 | /// |
| 489 | /// By default, performs semantic analysis when building the typeof type. |
| 490 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 491 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 492 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 493 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 494 | /// |
| 495 | /// By default, builds a new TypeOfType with the given underlying type. |
| 496 | QualType RebuildTypeOfType(QualType Underlying); |
| 497 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 498 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 499 | /// |
| 500 | /// By default, performs semantic analysis when building the decltype type. |
| 501 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 502 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 503 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 504 | /// \brief Build a new template specialization type. |
| 505 | /// |
| 506 | /// By default, performs semantic analysis when building the template |
| 507 | /// specialization type. Subclasses may override this routine to provide |
| 508 | /// different behavior. |
| 509 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 510 | SourceLocation TemplateLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 511 | const TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 512 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 513 | /// \brief Build a new qualified name type. |
| 514 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 515 | /// By default, builds a new QualifiedNameType type from the |
| 516 | /// nested-name-specifier and the named type. Subclasses may override |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 517 | /// this routine to provide different behavior. |
| 518 | QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) { |
| 519 | return SemaRef.Context.getQualifiedNameType(NNS, Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 520 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 521 | |
| 522 | /// \brief Build a new typename type that refers to a template-id. |
| 523 | /// |
| 524 | /// By default, builds a new TypenameType type from the nested-name-specifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 525 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 526 | /// different behavior. |
| 527 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) { |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 528 | if (NNS->isDependent()) { |
| 529 | CXXScopeSpec SS; |
| 530 | SS.setScopeRep(NNS); |
| 531 | if (!SemaRef.computeDeclContext(SS)) |
| 532 | return SemaRef.Context.getTypenameType(NNS, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 533 | cast<TemplateSpecializationType>(T)); |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 534 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 535 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 536 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 537 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 538 | |
| 539 | /// \brief Build a new typename type that refers to an identifier. |
| 540 | /// |
| 541 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 542 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 543 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 544 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 545 | const IdentifierInfo *Id, |
| 546 | SourceRange SR) { |
| 547 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 548 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 549 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 550 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 551 | /// identifier that names the next step in the nested-name-specifier. |
| 552 | /// |
| 553 | /// By default, performs semantic analysis when building the new |
| 554 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 555 | /// different behavior. |
| 556 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 557 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 558 | IdentifierInfo &II, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 559 | bool MayBePseudoDestructor, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 560 | QualType ObjectType, |
| 561 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 562 | |
| 563 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 564 | /// namespace named in the next step in the nested-name-specifier. |
| 565 | /// |
| 566 | /// By default, performs semantic analysis when building the new |
| 567 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 568 | /// different behavior. |
| 569 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 570 | SourceRange Range, |
| 571 | NamespaceDecl *NS); |
| 572 | |
| 573 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 574 | /// type named in the next step in the nested-name-specifier. |
| 575 | /// |
| 576 | /// By default, performs semantic analysis when building the new |
| 577 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 578 | /// different behavior. |
| 579 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 580 | SourceRange Range, |
| 581 | bool TemplateKW, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 582 | QualType T, |
| 583 | bool MayBePseudoDestructor); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 584 | |
| 585 | /// \brief Build a new template name given a nested name specifier, a flag |
| 586 | /// indicating whether the "template" keyword was provided, and the template |
| 587 | /// that the template name refers to. |
| 588 | /// |
| 589 | /// By default, builds the new template name directly. Subclasses may override |
| 590 | /// this routine to provide different behavior. |
| 591 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 592 | bool TemplateKW, |
| 593 | TemplateDecl *Template); |
| 594 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 595 | /// \brief Build a new template name given a nested name specifier and the |
| 596 | /// name that is referred to as a template. |
| 597 | /// |
| 598 | /// By default, performs semantic analysis to determine whether the name can |
| 599 | /// be resolved to a specific template, then builds the appropriate kind of |
| 600 | /// template name. Subclasses may override this routine to provide different |
| 601 | /// behavior. |
| 602 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 603 | const IdentifierInfo &II, |
| 604 | QualType ObjectType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 605 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 606 | /// \brief Build a new template name given a nested name specifier and the |
| 607 | /// overloaded operator name that is referred to as a template. |
| 608 | /// |
| 609 | /// By default, performs semantic analysis to determine whether the name can |
| 610 | /// be resolved to a specific template, then builds the appropriate kind of |
| 611 | /// template name. Subclasses may override this routine to provide different |
| 612 | /// behavior. |
| 613 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 614 | OverloadedOperatorKind Operator, |
| 615 | QualType ObjectType); |
| 616 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 617 | /// \brief Build a new compound statement. |
| 618 | /// |
| 619 | /// By default, performs semantic analysis to build the new statement. |
| 620 | /// Subclasses may override this routine to provide different behavior. |
| 621 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 622 | MultiStmtArg Statements, |
| 623 | SourceLocation RBraceLoc, |
| 624 | bool IsStmtExpr) { |
| 625 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 626 | IsStmtExpr); |
| 627 | } |
| 628 | |
| 629 | /// \brief Build a new case statement. |
| 630 | /// |
| 631 | /// By default, performs semantic analysis to build the new statement. |
| 632 | /// Subclasses may override this routine to provide different behavior. |
| 633 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 634 | ExprArg LHS, |
| 635 | SourceLocation EllipsisLoc, |
| 636 | ExprArg RHS, |
| 637 | SourceLocation ColonLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 638 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 639 | ColonLoc); |
| 640 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 641 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 642 | /// \brief Attach the body to a new case statement. |
| 643 | /// |
| 644 | /// By default, performs semantic analysis to build the new statement. |
| 645 | /// Subclasses may override this routine to provide different behavior. |
| 646 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 647 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 648 | return move(S); |
| 649 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 650 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 651 | /// \brief Build a new default statement. |
| 652 | /// |
| 653 | /// By default, performs semantic analysis to build the new statement. |
| 654 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 655 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 656 | SourceLocation ColonLoc, |
| 657 | StmtArg SubStmt) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 658 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 659 | /*CurScope=*/0); |
| 660 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 661 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 662 | /// \brief Build a new label statement. |
| 663 | /// |
| 664 | /// By default, performs semantic analysis to build the new statement. |
| 665 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 666 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 667 | IdentifierInfo *Id, |
| 668 | SourceLocation ColonLoc, |
| 669 | StmtArg SubStmt) { |
| 670 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 671 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 672 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 673 | /// \brief Build a new "if" statement. |
| 674 | /// |
| 675 | /// By default, performs semantic analysis to build the new statement. |
| 676 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 677 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 678 | VarDecl *CondVar, StmtArg Then, |
| 679 | SourceLocation ElseLoc, StmtArg Else) { |
| 680 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
| 681 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 682 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 683 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 684 | /// \brief Start building a new switch statement. |
| 685 | /// |
| 686 | /// By default, performs semantic analysis to build the new statement. |
| 687 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 688 | OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond, |
| 689 | VarDecl *CondVar) { |
| 690 | return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 691 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 692 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 693 | /// \brief Attach the body to the switch statement. |
| 694 | /// |
| 695 | /// By default, performs semantic analysis to build the new statement. |
| 696 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 697 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 698 | StmtArg Switch, StmtArg Body) { |
| 699 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 700 | move(Body)); |
| 701 | } |
| 702 | |
| 703 | /// \brief Build a new while statement. |
| 704 | /// |
| 705 | /// By default, performs semantic analysis to build the new statement. |
| 706 | /// Subclasses may override this routine to provide different behavior. |
| 707 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 708 | Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 709 | VarDecl *CondVar, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 710 | StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 711 | return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar), |
| 712 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 713 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 714 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 715 | /// \brief Build a new do-while statement. |
| 716 | /// |
| 717 | /// By default, performs semantic analysis to build the new statement. |
| 718 | /// Subclasses may override this routine to provide different behavior. |
| 719 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 720 | SourceLocation WhileLoc, |
| 721 | SourceLocation LParenLoc, |
| 722 | ExprArg Cond, |
| 723 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 724 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 725 | move(Cond), RParenLoc); |
| 726 | } |
| 727 | |
| 728 | /// \brief Build a new for statement. |
| 729 | /// |
| 730 | /// By default, performs semantic analysis to build the new statement. |
| 731 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 732 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 733 | SourceLocation LParenLoc, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 734 | StmtArg Init, Sema::FullExprArg Cond, |
| 735 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 736 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 737 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
| 738 | DeclPtrTy::make(CondVar), |
| 739 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 740 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 741 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 742 | /// \brief Build a new goto statement. |
| 743 | /// |
| 744 | /// By default, performs semantic analysis to build the new statement. |
| 745 | /// Subclasses may override this routine to provide different behavior. |
| 746 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 747 | SourceLocation LabelLoc, |
| 748 | LabelStmt *Label) { |
| 749 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 750 | } |
| 751 | |
| 752 | /// \brief Build a new indirect goto statement. |
| 753 | /// |
| 754 | /// By default, performs semantic analysis to build the new statement. |
| 755 | /// Subclasses may override this routine to provide different behavior. |
| 756 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 757 | SourceLocation StarLoc, |
| 758 | ExprArg Target) { |
| 759 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 760 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 761 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 762 | /// \brief Build a new return statement. |
| 763 | /// |
| 764 | /// By default, performs semantic analysis to build the new statement. |
| 765 | /// Subclasses may override this routine to provide different behavior. |
| 766 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 767 | ExprArg Result) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 768 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 769 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 770 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 771 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 772 | /// \brief Build a new declaration statement. |
| 773 | /// |
| 774 | /// By default, performs semantic analysis to build the new statement. |
| 775 | /// Subclasses may override this routine to provide different behavior. |
| 776 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 777 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 778 | SourceLocation EndLoc) { |
| 779 | return getSema().Owned( |
| 780 | new (getSema().Context) DeclStmt( |
| 781 | DeclGroupRef::Create(getSema().Context, |
| 782 | Decls, NumDecls), |
| 783 | StartLoc, EndLoc)); |
| 784 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 785 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 786 | /// \brief Build a new inline asm statement. |
| 787 | /// |
| 788 | /// By default, performs semantic analysis to build the new statement. |
| 789 | /// Subclasses may override this routine to provide different behavior. |
| 790 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 791 | bool IsSimple, |
| 792 | bool IsVolatile, |
| 793 | unsigned NumOutputs, |
| 794 | unsigned NumInputs, |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 795 | IdentifierInfo **Names, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 796 | MultiExprArg Constraints, |
| 797 | MultiExprArg Exprs, |
| 798 | ExprArg AsmString, |
| 799 | MultiExprArg Clobbers, |
| 800 | SourceLocation RParenLoc, |
| 801 | bool MSAsm) { |
| 802 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 803 | NumInputs, Names, move(Constraints), |
| 804 | move(Exprs), move(AsmString), move(Clobbers), |
| 805 | RParenLoc, MSAsm); |
| 806 | } |
| 807 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 808 | /// \brief Build a new C++ exception declaration. |
| 809 | /// |
| 810 | /// By default, performs semantic analysis to build the new decaration. |
| 811 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 812 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 813 | TypeSourceInfo *Declarator, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 814 | IdentifierInfo *Name, |
| 815 | SourceLocation Loc, |
| 816 | SourceRange TypeRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 817 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 818 | TypeRange); |
| 819 | } |
| 820 | |
| 821 | /// \brief Build a new C++ catch statement. |
| 822 | /// |
| 823 | /// By default, performs semantic analysis to build the new statement. |
| 824 | /// Subclasses may override this routine to provide different behavior. |
| 825 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 826 | VarDecl *ExceptionDecl, |
| 827 | StmtArg Handler) { |
| 828 | return getSema().Owned( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 829 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 830 | Handler.takeAs<Stmt>())); |
| 831 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 832 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 833 | /// \brief Build a new C++ try statement. |
| 834 | /// |
| 835 | /// By default, performs semantic analysis to build the new statement. |
| 836 | /// Subclasses may override this routine to provide different behavior. |
| 837 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 838 | StmtArg TryBlock, |
| 839 | MultiStmtArg Handlers) { |
| 840 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 841 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 842 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 843 | /// \brief Build a new expression that references a declaration. |
| 844 | /// |
| 845 | /// By default, performs semantic analysis to build the new expression. |
| 846 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 847 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 848 | LookupResult &R, |
| 849 | bool RequiresADL) { |
| 850 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 851 | } |
| 852 | |
| 853 | |
| 854 | /// \brief Build a new expression that references a declaration. |
| 855 | /// |
| 856 | /// By default, performs semantic analysis to build the new expression. |
| 857 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 858 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 859 | SourceRange QualifierRange, |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 860 | ValueDecl *VD, SourceLocation Loc, |
| 861 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 862 | CXXScopeSpec SS; |
| 863 | SS.setScopeRep(Qualifier); |
| 864 | SS.setRange(QualifierRange); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 865 | |
| 866 | // FIXME: loses template args. |
| 867 | |
| 868 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 869 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 870 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 871 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 872 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 873 | /// By default, performs semantic analysis to build the new expression. |
| 874 | /// Subclasses may override this routine to provide different behavior. |
| 875 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 876 | SourceLocation RParen) { |
| 877 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 878 | } |
| 879 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 880 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 881 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 882 | /// By default, performs semantic analysis to build the new expression. |
| 883 | /// Subclasses may override this routine to provide different behavior. |
| 884 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 885 | SourceLocation OperatorLoc, |
| 886 | bool isArrow, |
| 887 | SourceLocation DestroyedTypeLoc, |
| 888 | QualType DestroyedType, |
| 889 | NestedNameSpecifier *Qualifier, |
| 890 | SourceRange QualifierRange) { |
| 891 | CXXScopeSpec SS; |
| 892 | if (Qualifier) { |
| 893 | SS.setRange(QualifierRange); |
| 894 | SS.setScopeRep(Qualifier); |
| 895 | } |
| 896 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 897 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 898 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 899 | DeclarationName Name |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 900 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 901 | SemaRef.Context.getCanonicalType(DestroyedType)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 902 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 903 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 904 | OperatorLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 905 | SS, /*FIXME: FirstQualifier*/ 0, |
| 906 | Name, DestroyedTypeLoc, |
| 907 | /*TemplateArgs*/ 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 908 | } |
| 909 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 910 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 911 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 912 | /// By default, performs semantic analysis to build the new expression. |
| 913 | /// Subclasses may override this routine to provide different behavior. |
| 914 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 915 | UnaryOperator::Opcode Opc, |
| 916 | ExprArg SubExpr) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 917 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 918 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 919 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 920 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 921 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 922 | /// By default, performs semantic analysis to build the new expression. |
| 923 | /// Subclasses may override this routine to provide different behavior. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 924 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 925 | SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 926 | bool isSizeOf, SourceRange R) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 927 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 928 | } |
| 929 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 930 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 931 | /// argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 932 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 933 | /// By default, performs semantic analysis to build the new expression. |
| 934 | /// Subclasses may override this routine to provide different behavior. |
| 935 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 936 | bool isSizeOf, SourceRange R) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 937 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 938 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 939 | OpLoc, isSizeOf, R); |
| 940 | if (Result.isInvalid()) |
| 941 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 942 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 943 | SubExpr.release(); |
| 944 | return move(Result); |
| 945 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 946 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 947 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 948 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 949 | /// By default, performs semantic analysis to build the new expression. |
| 950 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 951 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 952 | SourceLocation LBracketLoc, |
| 953 | ExprArg RHS, |
| 954 | SourceLocation RBracketLoc) { |
| 955 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 956 | LBracketLoc, move(RHS), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 957 | RBracketLoc); |
| 958 | } |
| 959 | |
| 960 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 961 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 962 | /// By default, performs semantic analysis to build the new expression. |
| 963 | /// Subclasses may override this routine to provide different behavior. |
| 964 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 965 | MultiExprArg Args, |
| 966 | SourceLocation *CommaLocs, |
| 967 | SourceLocation RParenLoc) { |
| 968 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 969 | move(Args), CommaLocs, RParenLoc); |
| 970 | } |
| 971 | |
| 972 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 973 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 974 | /// By default, performs semantic analysis to build the new expression. |
| 975 | /// Subclasses may override this routine to provide different behavior. |
| 976 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 977 | bool isArrow, |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 978 | NestedNameSpecifier *Qualifier, |
| 979 | SourceRange QualifierRange, |
| 980 | SourceLocation MemberLoc, |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 981 | ValueDecl *Member, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 982 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 983 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 984 | if (!Member->getDeclName()) { |
| 985 | // We have a reference to an unnamed field. |
| 986 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 987 | |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 988 | Expr *BaseExpr = Base.takeAs<Expr>(); |
| 989 | if (getSema().PerformObjectMemberConversion(BaseExpr, Member)) |
| 990 | return getSema().ExprError(); |
Douglas Gregor | 4b65441 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 991 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 992 | MemberExpr *ME = |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 993 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 994 | Member, MemberLoc, |
| 995 | cast<FieldDecl>(Member)->getType()); |
| 996 | return getSema().Owned(ME); |
| 997 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 998 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 999 | CXXScopeSpec SS; |
| 1000 | if (Qualifier) { |
| 1001 | SS.setRange(QualifierRange); |
| 1002 | SS.setScopeRep(Qualifier); |
| 1003 | } |
| 1004 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1005 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1006 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1007 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 1008 | Sema::LookupMemberName); |
| 1009 | R.addDecl(Member); |
| 1010 | R.resolveKind(); |
| 1011 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1012 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 1013 | OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1014 | SS, FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1015 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1016 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1017 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1018 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1019 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1020 | /// By default, performs semantic analysis to build the new expression. |
| 1021 | /// Subclasses may override this routine to provide different behavior. |
| 1022 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1023 | BinaryOperator::Opcode Opc, |
| 1024 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1025 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 1026 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1030 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1031 | /// By default, performs semantic analysis to build the new expression. |
| 1032 | /// Subclasses may override this routine to provide different behavior. |
| 1033 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1034 | SourceLocation QuestionLoc, |
| 1035 | ExprArg LHS, |
| 1036 | SourceLocation ColonLoc, |
| 1037 | ExprArg RHS) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1038 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1039 | move(LHS), move(RHS)); |
| 1040 | } |
| 1041 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1042 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1043 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1044 | /// By default, performs semantic analysis to build the new expression. |
| 1045 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1046 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1047 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1048 | SourceLocation RParenLoc, |
| 1049 | ExprArg SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1050 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1051 | move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1052 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1053 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1054 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1055 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1056 | /// By default, performs semantic analysis to build the new expression. |
| 1057 | /// Subclasses may override this routine to provide different behavior. |
| 1058 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1059 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1060 | SourceLocation RParenLoc, |
| 1061 | ExprArg Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1062 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1063 | move(Init)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1064 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1065 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1066 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1067 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1068 | /// By default, performs semantic analysis to build the new expression. |
| 1069 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1070 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1071 | SourceLocation OpLoc, |
| 1072 | SourceLocation AccessorLoc, |
| 1073 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1074 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1075 | CXXScopeSpec SS; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1076 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1077 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1078 | OpLoc, /*IsArrow*/ false, |
| 1079 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 30d60cb | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1080 | DeclarationName(&Accessor), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1081 | AccessorLoc, |
| 1082 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1083 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1084 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1085 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1086 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1087 | /// By default, performs semantic analysis to build the new expression. |
| 1088 | /// Subclasses may override this routine to provide different behavior. |
| 1089 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1090 | MultiExprArg Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1091 | SourceLocation RBraceLoc, |
| 1092 | QualType ResultTy) { |
| 1093 | OwningExprResult Result |
| 1094 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1095 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1096 | return move(Result); |
| 1097 | |
| 1098 | // Patch in the result type we were given, which may have been computed |
| 1099 | // when the initial InitListExpr was built. |
| 1100 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1101 | ILE->setType(ResultTy); |
| 1102 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1103 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1104 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1105 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1106 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1107 | /// By default, performs semantic analysis to build the new expression. |
| 1108 | /// Subclasses may override this routine to provide different behavior. |
| 1109 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1110 | MultiExprArg ArrayExprs, |
| 1111 | SourceLocation EqualOrColonLoc, |
| 1112 | bool GNUSyntax, |
| 1113 | ExprArg Init) { |
| 1114 | OwningExprResult Result |
| 1115 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1116 | move(Init)); |
| 1117 | if (Result.isInvalid()) |
| 1118 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1119 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1120 | ArrayExprs.release(); |
| 1121 | return move(Result); |
| 1122 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1123 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1124 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1125 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1126 | /// By default, builds the implicit value initialization without performing |
| 1127 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1128 | /// different behavior. |
| 1129 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1130 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1131 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1132 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1133 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1134 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1135 | /// By default, performs semantic analysis to build the new expression. |
| 1136 | /// Subclasses may override this routine to provide different behavior. |
| 1137 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1138 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1139 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1140 | RParenLoc); |
| 1141 | } |
| 1142 | |
| 1143 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1144 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1145 | /// By default, performs semantic analysis to build the new expression. |
| 1146 | /// Subclasses may override this routine to provide different behavior. |
| 1147 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1148 | MultiExprArg SubExprs, |
| 1149 | SourceLocation RParenLoc) { |
Fariborz Jahanian | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1150 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1151 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1152 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1153 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1154 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1155 | /// |
| 1156 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1157 | /// rather than attempting to map the label statement itself. |
| 1158 | /// Subclasses may override this routine to provide different behavior. |
| 1159 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1160 | SourceLocation LabelLoc, |
| 1161 | LabelStmt *Label) { |
| 1162 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1163 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1164 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1165 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1166 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1167 | /// By default, performs semantic analysis to build the new expression. |
| 1168 | /// Subclasses may override this routine to provide different behavior. |
| 1169 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1170 | StmtArg SubStmt, |
| 1171 | SourceLocation RParenLoc) { |
| 1172 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1173 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1174 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1175 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1176 | /// |
| 1177 | /// By default, performs semantic analysis to build the new expression. |
| 1178 | /// Subclasses may override this routine to provide different behavior. |
| 1179 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1180 | QualType T1, QualType T2, |
| 1181 | SourceLocation RParenLoc) { |
| 1182 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1183 | T1.getAsOpaquePtr(), |
| 1184 | T2.getAsOpaquePtr(), |
| 1185 | RParenLoc); |
| 1186 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1187 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1188 | /// \brief Build a new __builtin_choose_expr expression. |
| 1189 | /// |
| 1190 | /// By default, performs semantic analysis to build the new expression. |
| 1191 | /// Subclasses may override this routine to provide different behavior. |
| 1192 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1193 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1194 | SourceLocation RParenLoc) { |
| 1195 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1196 | move(Cond), move(LHS), move(RHS), |
| 1197 | RParenLoc); |
| 1198 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1199 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1200 | /// \brief Build a new overloaded operator call expression. |
| 1201 | /// |
| 1202 | /// By default, performs semantic analysis to build the new expression. |
| 1203 | /// The semantic analysis provides the behavior of template instantiation, |
| 1204 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1205 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1206 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1207 | /// provide different behavior. |
| 1208 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1209 | SourceLocation OpLoc, |
| 1210 | ExprArg Callee, |
| 1211 | ExprArg First, |
| 1212 | ExprArg Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1213 | |
| 1214 | /// \brief Build a new C++ "named" cast expression, such as static_cast or |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1215 | /// reinterpret_cast. |
| 1216 | /// |
| 1217 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1218 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1219 | /// Subclasses may override this routine to provide different behavior. |
| 1220 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1221 | Stmt::StmtClass Class, |
| 1222 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1223 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1224 | SourceLocation RAngleLoc, |
| 1225 | SourceLocation LParenLoc, |
| 1226 | ExprArg SubExpr, |
| 1227 | SourceLocation RParenLoc) { |
| 1228 | switch (Class) { |
| 1229 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1230 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1231 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1232 | move(SubExpr), RParenLoc); |
| 1233 | |
| 1234 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1235 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1236 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1237 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1238 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1239 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1240 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1241 | RAngleLoc, LParenLoc, |
| 1242 | move(SubExpr), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1243 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1244 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1245 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1246 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1247 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1248 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1249 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1250 | default: |
| 1251 | assert(false && "Invalid C++ named cast"); |
| 1252 | break; |
| 1253 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1254 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1255 | return getSema().ExprError(); |
| 1256 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1257 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1258 | /// \brief Build a new C++ static_cast expression. |
| 1259 | /// |
| 1260 | /// By default, performs semantic analysis to build the new expression. |
| 1261 | /// Subclasses may override this routine to provide different behavior. |
| 1262 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1263 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1264 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1265 | SourceLocation RAngleLoc, |
| 1266 | SourceLocation LParenLoc, |
| 1267 | ExprArg SubExpr, |
| 1268 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1269 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1270 | TInfo, move(SubExpr), |
| 1271 | SourceRange(LAngleLoc, RAngleLoc), |
| 1272 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | /// \brief Build a new C++ dynamic_cast expression. |
| 1276 | /// |
| 1277 | /// By default, performs semantic analysis to build the new expression. |
| 1278 | /// Subclasses may override this routine to provide different behavior. |
| 1279 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1280 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1281 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1282 | SourceLocation RAngleLoc, |
| 1283 | SourceLocation LParenLoc, |
| 1284 | ExprArg SubExpr, |
| 1285 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1286 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1287 | TInfo, move(SubExpr), |
| 1288 | SourceRange(LAngleLoc, RAngleLoc), |
| 1289 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1293 | /// |
| 1294 | /// By default, performs semantic analysis to build the new expression. |
| 1295 | /// Subclasses may override this routine to provide different behavior. |
| 1296 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1297 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1298 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1299 | SourceLocation RAngleLoc, |
| 1300 | SourceLocation LParenLoc, |
| 1301 | ExprArg SubExpr, |
| 1302 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1303 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1304 | TInfo, move(SubExpr), |
| 1305 | SourceRange(LAngleLoc, RAngleLoc), |
| 1306 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | /// \brief Build a new C++ const_cast expression. |
| 1310 | /// |
| 1311 | /// By default, performs semantic analysis to build the new expression. |
| 1312 | /// Subclasses may override this routine to provide different behavior. |
| 1313 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1314 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1315 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1316 | SourceLocation RAngleLoc, |
| 1317 | SourceLocation LParenLoc, |
| 1318 | ExprArg SubExpr, |
| 1319 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1320 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1321 | TInfo, move(SubExpr), |
| 1322 | SourceRange(LAngleLoc, RAngleLoc), |
| 1323 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1324 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1325 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1326 | /// \brief Build a new C++ functional-style cast expression. |
| 1327 | /// |
| 1328 | /// By default, performs semantic analysis to build the new expression. |
| 1329 | /// Subclasses may override this routine to provide different behavior. |
| 1330 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1331 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1332 | SourceLocation LParenLoc, |
| 1333 | ExprArg SubExpr, |
| 1334 | SourceLocation RParenLoc) { |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1335 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1336 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1337 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1338 | LParenLoc, |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1339 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1340 | /*CommaLocs=*/0, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1341 | RParenLoc); |
| 1342 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1343 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1344 | /// \brief Build a new C++ typeid(type) expression. |
| 1345 | /// |
| 1346 | /// By default, performs semantic analysis to build the new expression. |
| 1347 | /// Subclasses may override this routine to provide different behavior. |
| 1348 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1349 | SourceLocation LParenLoc, |
| 1350 | QualType T, |
| 1351 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1352 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1353 | T.getAsOpaquePtr(), RParenLoc); |
| 1354 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1355 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1356 | /// \brief Build a new C++ typeid(expr) expression. |
| 1357 | /// |
| 1358 | /// By default, performs semantic analysis to build the new expression. |
| 1359 | /// Subclasses may override this routine to provide different behavior. |
| 1360 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1361 | SourceLocation LParenLoc, |
| 1362 | ExprArg Operand, |
| 1363 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1364 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1365 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1366 | RParenLoc); |
| 1367 | if (Result.isInvalid()) |
| 1368 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1369 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1370 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1371 | return move(Result); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1374 | /// \brief Build a new C++ "this" expression. |
| 1375 | /// |
| 1376 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1377 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1378 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1379 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1380 | QualType ThisType, |
| 1381 | bool isImplicit) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1382 | return getSema().Owned( |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1383 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1384 | isImplicit)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | /// \brief Build a new C++ throw expression. |
| 1388 | /// |
| 1389 | /// By default, performs semantic analysis to build the new expression. |
| 1390 | /// Subclasses may override this routine to provide different behavior. |
| 1391 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1392 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1393 | } |
| 1394 | |
| 1395 | /// \brief Build a new C++ default-argument expression. |
| 1396 | /// |
| 1397 | /// By default, builds a new default-argument expression, which does not |
| 1398 | /// require any semantic analysis. Subclasses may override this routine to |
| 1399 | /// provide different behavior. |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1400 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
| 1401 | ParmVarDecl *Param) { |
| 1402 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1403 | Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | /// \brief Build a new C++ zero-initialization expression. |
| 1407 | /// |
| 1408 | /// By default, performs semantic analysis to build the new expression. |
| 1409 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1410 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1411 | SourceLocation LParenLoc, |
| 1412 | QualType T, |
| 1413 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1414 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1415 | T.getAsOpaquePtr(), LParenLoc, |
| 1416 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1417 | 0, RParenLoc); |
| 1418 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1419 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1420 | /// \brief Build a new C++ "new" expression. |
| 1421 | /// |
| 1422 | /// By default, performs semantic analysis to build the new expression. |
| 1423 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1424 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1425 | bool UseGlobal, |
| 1426 | SourceLocation PlacementLParen, |
| 1427 | MultiExprArg PlacementArgs, |
| 1428 | SourceLocation PlacementRParen, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1429 | bool ParenTypeId, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1430 | QualType AllocType, |
| 1431 | SourceLocation TypeLoc, |
| 1432 | SourceRange TypeRange, |
| 1433 | ExprArg ArraySize, |
| 1434 | SourceLocation ConstructorLParen, |
| 1435 | MultiExprArg ConstructorArgs, |
| 1436 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1437 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1438 | PlacementLParen, |
| 1439 | move(PlacementArgs), |
| 1440 | PlacementRParen, |
| 1441 | ParenTypeId, |
| 1442 | AllocType, |
| 1443 | TypeLoc, |
| 1444 | TypeRange, |
| 1445 | move(ArraySize), |
| 1446 | ConstructorLParen, |
| 1447 | move(ConstructorArgs), |
| 1448 | ConstructorRParen); |
| 1449 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1450 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1451 | /// \brief Build a new C++ "delete" expression. |
| 1452 | /// |
| 1453 | /// By default, performs semantic analysis to build the new expression. |
| 1454 | /// Subclasses may override this routine to provide different behavior. |
| 1455 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1456 | bool IsGlobalDelete, |
| 1457 | bool IsArrayForm, |
| 1458 | ExprArg Operand) { |
| 1459 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1460 | move(Operand)); |
| 1461 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1462 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1463 | /// \brief Build a new unary type trait expression. |
| 1464 | /// |
| 1465 | /// By default, performs semantic analysis to build the new expression. |
| 1466 | /// Subclasses may override this routine to provide different behavior. |
| 1467 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1468 | SourceLocation StartLoc, |
| 1469 | SourceLocation LParenLoc, |
| 1470 | QualType T, |
| 1471 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1472 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1473 | T.getAsOpaquePtr(), RParenLoc); |
| 1474 | } |
| 1475 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1476 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1477 | /// expression. |
| 1478 | /// |
| 1479 | /// By default, performs semantic analysis to build the new expression. |
| 1480 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1481 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1482 | SourceRange QualifierRange, |
| 1483 | DeclarationName Name, |
| 1484 | SourceLocation Location, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1485 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1486 | CXXScopeSpec SS; |
| 1487 | SS.setRange(QualifierRange); |
| 1488 | SS.setScopeRep(NNS); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1489 | |
| 1490 | if (TemplateArgs) |
| 1491 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1492 | *TemplateArgs); |
| 1493 | |
| 1494 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | /// \brief Build a new template-id expression. |
| 1498 | /// |
| 1499 | /// By default, performs semantic analysis to build the new expression. |
| 1500 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1501 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1502 | LookupResult &R, |
| 1503 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1504 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1505 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | /// \brief Build a new object-construction expression. |
| 1509 | /// |
| 1510 | /// By default, performs semantic analysis to build the new expression. |
| 1511 | /// Subclasses may override this routine to provide different behavior. |
| 1512 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1513 | SourceLocation Loc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1514 | CXXConstructorDecl *Constructor, |
| 1515 | bool IsElidable, |
| 1516 | MultiExprArg Args) { |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1517 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
| 1518 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
| 1519 | ConvertedArgs)) |
| 1520 | return getSema().ExprError(); |
| 1521 | |
| 1522 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1523 | move_arg(ConvertedArgs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | /// \brief Build a new object-construction expression. |
| 1527 | /// |
| 1528 | /// By default, performs semantic analysis to build the new expression. |
| 1529 | /// Subclasses may override this routine to provide different behavior. |
| 1530 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1531 | QualType T, |
| 1532 | SourceLocation LParenLoc, |
| 1533 | MultiExprArg Args, |
| 1534 | SourceLocation *Commas, |
| 1535 | SourceLocation RParenLoc) { |
| 1536 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1537 | T.getAsOpaquePtr(), |
| 1538 | LParenLoc, |
| 1539 | move(Args), |
| 1540 | Commas, |
| 1541 | RParenLoc); |
| 1542 | } |
| 1543 | |
| 1544 | /// \brief Build a new object-construction expression. |
| 1545 | /// |
| 1546 | /// By default, performs semantic analysis to build the new expression. |
| 1547 | /// Subclasses may override this routine to provide different behavior. |
| 1548 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1549 | QualType T, |
| 1550 | SourceLocation LParenLoc, |
| 1551 | MultiExprArg Args, |
| 1552 | SourceLocation *Commas, |
| 1553 | SourceLocation RParenLoc) { |
| 1554 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1555 | /*FIXME*/LParenLoc), |
| 1556 | T.getAsOpaquePtr(), |
| 1557 | LParenLoc, |
| 1558 | move(Args), |
| 1559 | Commas, |
| 1560 | RParenLoc); |
| 1561 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1562 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1563 | /// \brief Build a new member reference expression. |
| 1564 | /// |
| 1565 | /// By default, performs semantic analysis to build the new expression. |
| 1566 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1567 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1568 | QualType BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1569 | bool IsArrow, |
| 1570 | SourceLocation OperatorLoc, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1571 | NestedNameSpecifier *Qualifier, |
| 1572 | SourceRange QualifierRange, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1573 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1574 | DeclarationName Name, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1575 | SourceLocation MemberLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1576 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1577 | CXXScopeSpec SS; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1578 | SS.setRange(QualifierRange); |
| 1579 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1580 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1581 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1582 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1583 | SS, FirstQualifierInScope, |
| 1584 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1587 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1588 | /// |
| 1589 | /// By default, performs semantic analysis to build the new expression. |
| 1590 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1591 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1592 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1593 | SourceLocation OperatorLoc, |
| 1594 | bool IsArrow, |
| 1595 | NestedNameSpecifier *Qualifier, |
| 1596 | SourceRange QualifierRange, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1597 | NamedDecl *FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1598 | LookupResult &R, |
| 1599 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1600 | CXXScopeSpec SS; |
| 1601 | SS.setRange(QualifierRange); |
| 1602 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1603 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1604 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1605 | OperatorLoc, IsArrow, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1606 | SS, FirstQualifierInScope, |
| 1607 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1608 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1609 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1610 | /// \brief Build a new Objective-C @encode expression. |
| 1611 | /// |
| 1612 | /// By default, performs semantic analysis to build the new expression. |
| 1613 | /// Subclasses may override this routine to provide different behavior. |
| 1614 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 1615 | QualType T, |
| 1616 | SourceLocation RParenLoc) { |
| 1617 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T, |
| 1618 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1619 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1620 | |
| 1621 | /// \brief Build a new Objective-C protocol expression. |
| 1622 | /// |
| 1623 | /// By default, performs semantic analysis to build the new expression. |
| 1624 | /// Subclasses may override this routine to provide different behavior. |
| 1625 | OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol, |
| 1626 | SourceLocation AtLoc, |
| 1627 | SourceLocation ProtoLoc, |
| 1628 | SourceLocation LParenLoc, |
| 1629 | SourceLocation RParenLoc) { |
| 1630 | return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression( |
| 1631 | Protocol->getIdentifier(), |
| 1632 | AtLoc, |
| 1633 | ProtoLoc, |
| 1634 | LParenLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1635 | RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1636 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1637 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1638 | /// \brief Build a new shuffle vector expression. |
| 1639 | /// |
| 1640 | /// By default, performs semantic analysis to build the new expression. |
| 1641 | /// Subclasses may override this routine to provide different behavior. |
| 1642 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1643 | MultiExprArg SubExprs, |
| 1644 | SourceLocation RParenLoc) { |
| 1645 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1646 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1647 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1648 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1649 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1650 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1651 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1652 | // Build a reference to the __builtin_shufflevector builtin |
| 1653 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1654 | Expr *Callee |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1655 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1656 | BuiltinLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1657 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1658 | |
| 1659 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1660 | unsigned NumSubExprs = SubExprs.size(); |
| 1661 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1662 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1663 | Subs, NumSubExprs, |
| 1664 | Builtin->getResultType(), |
| 1665 | RParenLoc); |
| 1666 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1667 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1668 | // Type-check the __builtin_shufflevector expression. |
| 1669 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1670 | if (Result.isInvalid()) |
| 1671 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1672 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1673 | OwnedCall.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1674 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1675 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1676 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1677 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1678 | template<typename Derived> |
| 1679 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1680 | if (!S) |
| 1681 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1682 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1683 | switch (S->getStmtClass()) { |
| 1684 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1685 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1686 | // Transform individual statement nodes |
| 1687 | #define STMT(Node, Parent) \ |
| 1688 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1689 | #define EXPR(Node, Parent) |
| 1690 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1691 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1692 | // Transform expressions by calling TransformExpr. |
| 1693 | #define STMT(Node, Parent) |
John McCall | 2adddca | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1694 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1695 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1696 | #include "clang/AST/StmtNodes.def" |
| 1697 | { |
| 1698 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1699 | if (E.isInvalid()) |
| 1700 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1701 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1702 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1703 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1704 | } |
| 1705 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1706 | return SemaRef.Owned(S->Retain()); |
| 1707 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1708 | |
| 1709 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1710 | template<typename Derived> |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1711 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1712 | if (!E) |
| 1713 | return SemaRef.Owned(E); |
| 1714 | |
| 1715 | switch (E->getStmtClass()) { |
| 1716 | case Stmt::NoStmtClass: break; |
| 1717 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
John McCall | 2adddca | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1718 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1719 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1720 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1721 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1722 | } |
| 1723 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1724 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | template<typename Derived> |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1728 | NestedNameSpecifier * |
| 1729 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1730 | SourceRange Range, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 1731 | bool MayBePseudoDestructor, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1732 | QualType ObjectType, |
| 1733 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 96ee789 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1734 | if (!NNS) |
| 1735 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1736 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1737 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1738 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1739 | if (Prefix) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1740 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 1741 | false, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1742 | ObjectType, |
| 1743 | FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1744 | if (!Prefix) |
| 1745 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1746 | |
| 1747 | // Clear out the object type and the first qualifier in scope; they only |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1748 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1749 | ObjectType = QualType(); |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1750 | FirstQualifierInScope = 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1751 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1752 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1753 | switch (NNS->getKind()) { |
| 1754 | case NestedNameSpecifier::Identifier: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1755 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1756 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1757 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1758 | ObjectType.isNull()) |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1759 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1760 | |
| 1761 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1762 | *NNS->getAsIdentifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 1763 | MayBePseudoDestructor, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1764 | ObjectType, |
| 1765 | FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1766 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1767 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1768 | NamespaceDecl *NS |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1769 | = cast_or_null<NamespaceDecl>( |
| 1770 | getDerived().TransformDecl(NNS->getAsNamespace())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1771 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1772 | Prefix == NNS->getPrefix() && |
| 1773 | NS == NNS->getAsNamespace()) |
| 1774 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1775 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1776 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1777 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1778 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1779 | case NestedNameSpecifier::Global: |
| 1780 | // There is no meaningful transformation that one could perform on the |
| 1781 | // global scope. |
| 1782 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1783 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1784 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1785 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | 07cc4ac | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1786 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1787 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 1788 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1789 | if (T.isNull()) |
| 1790 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1791 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1792 | if (!getDerived().AlwaysRebuild() && |
| 1793 | Prefix == NNS->getPrefix() && |
| 1794 | T == QualType(NNS->getAsType(), 0)) |
| 1795 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1796 | |
| 1797 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1798 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 1799 | T, |
| 1800 | MayBePseudoDestructor); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1801 | } |
| 1802 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1803 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1804 | // Required to silence a GCC warning |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1805 | return 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1809 | DeclarationName |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1810 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1811 | SourceLocation Loc, |
| 1812 | QualType ObjectType) { |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1813 | if (!Name) |
| 1814 | return Name; |
| 1815 | |
| 1816 | switch (Name.getNameKind()) { |
| 1817 | case DeclarationName::Identifier: |
| 1818 | case DeclarationName::ObjCZeroArgSelector: |
| 1819 | case DeclarationName::ObjCOneArgSelector: |
| 1820 | case DeclarationName::ObjCMultiArgSelector: |
| 1821 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 1822 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1823 | case DeclarationName::CXXUsingDirective: |
| 1824 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1825 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1826 | case DeclarationName::CXXConstructorName: |
| 1827 | case DeclarationName::CXXDestructorName: |
| 1828 | case DeclarationName::CXXConversionFunctionName: { |
| 1829 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1830 | QualType T = getDerived().TransformType(Name.getCXXNameType(), |
| 1831 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1832 | if (T.isNull()) |
| 1833 | return DeclarationName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1834 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1835 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1836 | Name.getNameKind(), |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1837 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1838 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1839 | } |
| 1840 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1841 | return DeclarationName(); |
| 1842 | } |
| 1843 | |
| 1844 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1845 | TemplateName |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1846 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1847 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1848 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1849 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1850 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1851 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 1852 | false, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1853 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1854 | if (!NNS) |
| 1855 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1856 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1857 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1858 | TemplateDecl *TransTemplate |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1859 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1860 | if (!TransTemplate) |
| 1861 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1862 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1863 | if (!getDerived().AlwaysRebuild() && |
| 1864 | NNS == QTN->getQualifier() && |
| 1865 | TransTemplate == Template) |
| 1866 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1867 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1868 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1869 | TransTemplate); |
| 1870 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1871 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1872 | // These should be getting filtered out before they make it into the AST. |
| 1873 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1874 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1875 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1876 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1877 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1878 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1879 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 1880 | false, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1881 | ObjectType); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1882 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1883 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1884 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1885 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1886 | NNS == DTN->getQualifier() && |
| 1887 | ObjectType.isNull()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1888 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1889 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1890 | if (DTN->isIdentifier()) |
| 1891 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 1892 | ObjectType); |
| 1893 | |
| 1894 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 1895 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1896 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1897 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1898 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1899 | TemplateDecl *TransTemplate |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1900 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1901 | if (!TransTemplate) |
| 1902 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1903 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1904 | if (!getDerived().AlwaysRebuild() && |
| 1905 | TransTemplate == Template) |
| 1906 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1907 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1908 | return TemplateName(TransTemplate); |
| 1909 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1910 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1911 | // These should be getting filtered out before they reach the AST. |
| 1912 | assert(false && "overloaded function decl survived to here"); |
| 1913 | return TemplateName(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1917 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 1918 | const TemplateArgument &Arg, |
| 1919 | TemplateArgumentLoc &Output) { |
| 1920 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1921 | switch (Arg.getKind()) { |
| 1922 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 1923 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1924 | break; |
| 1925 | |
| 1926 | case TemplateArgument::Type: |
| 1927 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1928 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1929 | |
| 1930 | break; |
| 1931 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1932 | case TemplateArgument::Template: |
| 1933 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 1934 | break; |
| 1935 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1936 | case TemplateArgument::Expression: |
| 1937 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 1938 | break; |
| 1939 | |
| 1940 | case TemplateArgument::Declaration: |
| 1941 | case TemplateArgument::Integral: |
| 1942 | case TemplateArgument::Pack: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1943 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1944 | break; |
| 1945 | } |
| 1946 | } |
| 1947 | |
| 1948 | template<typename Derived> |
| 1949 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 1950 | const TemplateArgumentLoc &Input, |
| 1951 | TemplateArgumentLoc &Output) { |
| 1952 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1953 | switch (Arg.getKind()) { |
| 1954 | case TemplateArgument::Null: |
| 1955 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1956 | Output = Input; |
| 1957 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1958 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1959 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1960 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1961 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1962 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1963 | |
| 1964 | DI = getDerived().TransformType(DI); |
| 1965 | if (!DI) return true; |
| 1966 | |
| 1967 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 1968 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1969 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1970 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1971 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1972 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 1973 | DeclarationName Name; |
| 1974 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 1975 | Name = ND->getDeclName(); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1976 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1977 | Decl *D = getDerived().TransformDecl(Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1978 | if (!D) return true; |
| 1979 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1980 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 1981 | if (SourceExpr) { |
| 1982 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 1983 | Action::Unevaluated); |
| 1984 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 1985 | if (E.isInvalid()) |
| 1986 | SourceExpr = NULL; |
| 1987 | else { |
| 1988 | SourceExpr = E.takeAs<Expr>(); |
| 1989 | SourceExpr->Retain(); |
| 1990 | } |
| 1991 | } |
| 1992 | |
| 1993 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1994 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1995 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1996 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1997 | case TemplateArgument::Template: { |
| 1998 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 1999 | TemplateName Template |
| 2000 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2001 | if (Template.isNull()) |
| 2002 | return true; |
| 2003 | |
| 2004 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2005 | Input.getTemplateQualifierRange(), |
| 2006 | Input.getTemplateNameLoc()); |
| 2007 | return false; |
| 2008 | } |
| 2009 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2010 | case TemplateArgument::Expression: { |
| 2011 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2012 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2013 | Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2014 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2015 | Expr *InputExpr = Input.getSourceExpression(); |
| 2016 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2017 | |
| 2018 | Sema::OwningExprResult E |
| 2019 | = getDerived().TransformExpr(InputExpr); |
| 2020 | if (E.isInvalid()) return true; |
| 2021 | |
| 2022 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2023 | ETaken->Retain(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2024 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2025 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2026 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2027 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2028 | case TemplateArgument::Pack: { |
| 2029 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2030 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2031 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2032 | AEnd = Arg.pack_end(); |
| 2033 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2034 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2035 | // FIXME: preserve source information here when we start |
| 2036 | // caring about parameter packs. |
| 2037 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2038 | TemplateArgumentLoc InputArg; |
| 2039 | TemplateArgumentLoc OutputArg; |
| 2040 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2041 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2042 | return true; |
| 2043 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2044 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2045 | } |
| 2046 | TemplateArgument Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2047 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2048 | true); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2049 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2050 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2051 | } |
| 2052 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2053 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2054 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2055 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2056 | } |
| 2057 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2058 | //===----------------------------------------------------------------------===// |
| 2059 | // Type transformation |
| 2060 | //===----------------------------------------------------------------------===// |
| 2061 | |
| 2062 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2063 | QualType TreeTransform<Derived>::TransformType(QualType T, |
| 2064 | QualType ObjectType) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2065 | if (getDerived().AlreadyTransformed(T)) |
| 2066 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2067 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2068 | // Temporary workaround. All of these transformations should |
| 2069 | // eventually turn into transformations on TypeLocs. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2070 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | de88989 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2071 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2072 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2073 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2074 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2075 | if (!NewDI) |
| 2076 | return QualType(); |
| 2077 | |
| 2078 | return NewDI->getType(); |
| 2079 | } |
| 2080 | |
| 2081 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2082 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2083 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2084 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2085 | return DI; |
| 2086 | |
| 2087 | TypeLocBuilder TLB; |
| 2088 | |
| 2089 | TypeLoc TL = DI->getTypeLoc(); |
| 2090 | TLB.reserve(TL.getFullDataSize()); |
| 2091 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2092 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2093 | if (Result.isNull()) |
| 2094 | return 0; |
| 2095 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2096 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2097 | } |
| 2098 | |
| 2099 | template<typename Derived> |
| 2100 | QualType |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2101 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2102 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2103 | switch (T.getTypeLocClass()) { |
| 2104 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2105 | #define TYPELOC(CLASS, PARENT) \ |
| 2106 | case TypeLoc::CLASS: \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2107 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2108 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2109 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2110 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2111 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2112 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2113 | return QualType(); |
| 2114 | } |
| 2115 | |
| 2116 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2117 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2118 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2119 | /// types). This is the right thing for template instantiation, but |
| 2120 | /// probably not for other clients. |
| 2121 | template<typename Derived> |
| 2122 | QualType |
| 2123 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2124 | QualifiedTypeLoc T, |
| 2125 | QualType ObjectType) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2126 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2127 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2128 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2129 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2130 | if (Result.isNull()) |
| 2131 | return QualType(); |
| 2132 | |
| 2133 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2134 | // FIXME: this is the right thing for template instantiation, but |
| 2135 | // probably not for other clients. |
| 2136 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2137 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2138 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2139 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2140 | |
| 2141 | TLB.push<QualifiedTypeLoc>(Result); |
| 2142 | |
| 2143 | // No location information to preserve. |
| 2144 | |
| 2145 | return Result; |
| 2146 | } |
| 2147 | |
| 2148 | template <class TyLoc> static inline |
| 2149 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2150 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2151 | NewT.setNameLoc(T.getNameLoc()); |
| 2152 | return T.getType(); |
| 2153 | } |
| 2154 | |
| 2155 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2156 | // the equivalent template version work. |
| 2157 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2158 | QualType PointeeType \ |
| 2159 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2160 | if (PointeeType.isNull()) \ |
| 2161 | return QualType(); \ |
| 2162 | \ |
| 2163 | QualType Result = TL.getType(); \ |
| 2164 | if (getDerived().AlwaysRebuild() || \ |
| 2165 | PointeeType != TL.getPointeeLoc().getType()) { \ |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2166 | Result = getDerived().Rebuild##TypeClass(PointeeType, \ |
| 2167 | TL.getSigilLoc()); \ |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2168 | if (Result.isNull()) \ |
| 2169 | return QualType(); \ |
| 2170 | } \ |
| 2171 | \ |
| 2172 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2173 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2174 | \ |
| 2175 | return Result; \ |
| 2176 | } while(0) |
| 2177 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2178 | template<typename Derived> |
| 2179 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2180 | BuiltinTypeLoc T, |
| 2181 | QualType ObjectType) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2182 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2183 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2184 | if (T.needsExtraLocalData()) |
| 2185 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2186 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2187 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2188 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2189 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2190 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2191 | ComplexTypeLoc T, |
| 2192 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2193 | // FIXME: recurse? |
| 2194 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2195 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2196 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2197 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2198 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2199 | PointerTypeLoc TL, |
| 2200 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2201 | TransformPointerLikeType(PointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2202 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2203 | |
| 2204 | template<typename Derived> |
| 2205 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2206 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2207 | BlockPointerTypeLoc TL, |
| 2208 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2209 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2210 | } |
| 2211 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2212 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2213 | /// don't care whether the type itself is an l-value type or an r-value |
| 2214 | /// type; we only care if the type was *written* as an l-value type |
| 2215 | /// or an r-value type. |
| 2216 | template<typename Derived> |
| 2217 | QualType |
| 2218 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2219 | ReferenceTypeLoc TL, |
| 2220 | QualType ObjectType) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2221 | const ReferenceType *T = TL.getTypePtr(); |
| 2222 | |
| 2223 | // Note that this works with the pointee-as-written. |
| 2224 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2225 | if (PointeeType.isNull()) |
| 2226 | return QualType(); |
| 2227 | |
| 2228 | QualType Result = TL.getType(); |
| 2229 | if (getDerived().AlwaysRebuild() || |
| 2230 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2231 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2232 | T->isSpelledAsLValue(), |
| 2233 | TL.getSigilLoc()); |
| 2234 | if (Result.isNull()) |
| 2235 | return QualType(); |
| 2236 | } |
| 2237 | |
| 2238 | // r-value references can be rebuilt as l-value references. |
| 2239 | ReferenceTypeLoc NewTL; |
| 2240 | if (isa<LValueReferenceType>(Result)) |
| 2241 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2242 | else |
| 2243 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2244 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2245 | |
| 2246 | return Result; |
| 2247 | } |
| 2248 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2249 | template<typename Derived> |
| 2250 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2251 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2252 | LValueReferenceTypeLoc TL, |
| 2253 | QualType ObjectType) { |
| 2254 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2255 | } |
| 2256 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2257 | template<typename Derived> |
| 2258 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2259 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2260 | RValueReferenceTypeLoc TL, |
| 2261 | QualType ObjectType) { |
| 2262 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2263 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2264 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2265 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2266 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2267 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2268 | MemberPointerTypeLoc TL, |
| 2269 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2270 | MemberPointerType *T = TL.getTypePtr(); |
| 2271 | |
| 2272 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2273 | if (PointeeType.isNull()) |
| 2274 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2275 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2276 | // TODO: preserve source information for this. |
| 2277 | QualType ClassType |
| 2278 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2279 | if (ClassType.isNull()) |
| 2280 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2281 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2282 | QualType Result = TL.getType(); |
| 2283 | if (getDerived().AlwaysRebuild() || |
| 2284 | PointeeType != T->getPointeeType() || |
| 2285 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2286 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2287 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2288 | if (Result.isNull()) |
| 2289 | return QualType(); |
| 2290 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2291 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2292 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2293 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2294 | |
| 2295 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2296 | } |
| 2297 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2298 | template<typename Derived> |
| 2299 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2300 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2301 | ConstantArrayTypeLoc TL, |
| 2302 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2303 | ConstantArrayType *T = TL.getTypePtr(); |
| 2304 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2305 | if (ElementType.isNull()) |
| 2306 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2307 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2308 | QualType Result = TL.getType(); |
| 2309 | if (getDerived().AlwaysRebuild() || |
| 2310 | ElementType != T->getElementType()) { |
| 2311 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2312 | T->getSizeModifier(), |
| 2313 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2314 | T->getIndexTypeCVRQualifiers(), |
| 2315 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2316 | if (Result.isNull()) |
| 2317 | return QualType(); |
| 2318 | } |
| 2319 | |
| 2320 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2321 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2322 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2323 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2324 | Expr *Size = TL.getSizeExpr(); |
| 2325 | if (Size) { |
| 2326 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2327 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2328 | } |
| 2329 | NewTL.setSizeExpr(Size); |
| 2330 | |
| 2331 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2332 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2333 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2334 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2335 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2336 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2337 | IncompleteArrayTypeLoc TL, |
| 2338 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2339 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2340 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2341 | if (ElementType.isNull()) |
| 2342 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2343 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2344 | QualType Result = TL.getType(); |
| 2345 | if (getDerived().AlwaysRebuild() || |
| 2346 | ElementType != T->getElementType()) { |
| 2347 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2348 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2349 | T->getIndexTypeCVRQualifiers(), |
| 2350 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2351 | if (Result.isNull()) |
| 2352 | return QualType(); |
| 2353 | } |
| 2354 | |
| 2355 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2356 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2357 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2358 | NewTL.setSizeExpr(0); |
| 2359 | |
| 2360 | return Result; |
| 2361 | } |
| 2362 | |
| 2363 | template<typename Derived> |
| 2364 | QualType |
| 2365 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2366 | VariableArrayTypeLoc TL, |
| 2367 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2368 | VariableArrayType *T = TL.getTypePtr(); |
| 2369 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2370 | if (ElementType.isNull()) |
| 2371 | return QualType(); |
| 2372 | |
| 2373 | // Array bounds are not potentially evaluated contexts |
| 2374 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2375 | |
| 2376 | Sema::OwningExprResult SizeResult |
| 2377 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2378 | if (SizeResult.isInvalid()) |
| 2379 | return QualType(); |
| 2380 | |
| 2381 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2382 | |
| 2383 | QualType Result = TL.getType(); |
| 2384 | if (getDerived().AlwaysRebuild() || |
| 2385 | ElementType != T->getElementType() || |
| 2386 | Size != T->getSizeExpr()) { |
| 2387 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2388 | T->getSizeModifier(), |
| 2389 | move(SizeResult), |
| 2390 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2391 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2392 | if (Result.isNull()) |
| 2393 | return QualType(); |
| 2394 | } |
| 2395 | else SizeResult.take(); |
| 2396 | |
| 2397 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2398 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2399 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2400 | NewTL.setSizeExpr(Size); |
| 2401 | |
| 2402 | return Result; |
| 2403 | } |
| 2404 | |
| 2405 | template<typename Derived> |
| 2406 | QualType |
| 2407 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2408 | DependentSizedArrayTypeLoc TL, |
| 2409 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2410 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2411 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2412 | if (ElementType.isNull()) |
| 2413 | return QualType(); |
| 2414 | |
| 2415 | // Array bounds are not potentially evaluated contexts |
| 2416 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2417 | |
| 2418 | Sema::OwningExprResult SizeResult |
| 2419 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2420 | if (SizeResult.isInvalid()) |
| 2421 | return QualType(); |
| 2422 | |
| 2423 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2424 | |
| 2425 | QualType Result = TL.getType(); |
| 2426 | if (getDerived().AlwaysRebuild() || |
| 2427 | ElementType != T->getElementType() || |
| 2428 | Size != T->getSizeExpr()) { |
| 2429 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2430 | T->getSizeModifier(), |
| 2431 | move(SizeResult), |
| 2432 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2433 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2434 | if (Result.isNull()) |
| 2435 | return QualType(); |
| 2436 | } |
| 2437 | else SizeResult.take(); |
| 2438 | |
| 2439 | // We might have any sort of array type now, but fortunately they |
| 2440 | // all have the same location layout. |
| 2441 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2442 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2443 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2444 | NewTL.setSizeExpr(Size); |
| 2445 | |
| 2446 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2447 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2448 | |
| 2449 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2450 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2451 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2452 | DependentSizedExtVectorTypeLoc TL, |
| 2453 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2454 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2455 | |
| 2456 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2457 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2458 | if (ElementType.isNull()) |
| 2459 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2460 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2461 | // Vector sizes are not potentially evaluated contexts |
| 2462 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2463 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2464 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2465 | if (Size.isInvalid()) |
| 2466 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2467 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2468 | QualType Result = TL.getType(); |
| 2469 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2470 | ElementType != T->getElementType() || |
| 2471 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2472 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2473 | move(Size), |
| 2474 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2475 | if (Result.isNull()) |
| 2476 | return QualType(); |
| 2477 | } |
| 2478 | else Size.take(); |
| 2479 | |
| 2480 | // Result might be dependent or not. |
| 2481 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2482 | DependentSizedExtVectorTypeLoc NewTL |
| 2483 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2484 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2485 | } else { |
| 2486 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2487 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2488 | } |
| 2489 | |
| 2490 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2491 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2492 | |
| 2493 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2494 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2495 | VectorTypeLoc TL, |
| 2496 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2497 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2498 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2499 | if (ElementType.isNull()) |
| 2500 | return QualType(); |
| 2501 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2502 | QualType Result = TL.getType(); |
| 2503 | if (getDerived().AlwaysRebuild() || |
| 2504 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2505 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 2506 | T->isAltiVec(), T->isPixel()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2507 | if (Result.isNull()) |
| 2508 | return QualType(); |
| 2509 | } |
| 2510 | |
| 2511 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2512 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2513 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2514 | return Result; |
| 2515 | } |
| 2516 | |
| 2517 | template<typename Derived> |
| 2518 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2519 | ExtVectorTypeLoc TL, |
| 2520 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2521 | VectorType *T = TL.getTypePtr(); |
| 2522 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2523 | if (ElementType.isNull()) |
| 2524 | return QualType(); |
| 2525 | |
| 2526 | QualType Result = TL.getType(); |
| 2527 | if (getDerived().AlwaysRebuild() || |
| 2528 | ElementType != T->getElementType()) { |
| 2529 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2530 | T->getNumElements(), |
| 2531 | /*FIXME*/ SourceLocation()); |
| 2532 | if (Result.isNull()) |
| 2533 | return QualType(); |
| 2534 | } |
| 2535 | |
| 2536 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2537 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2538 | |
| 2539 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2540 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2541 | |
| 2542 | template<typename Derived> |
| 2543 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2544 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2545 | FunctionProtoTypeLoc TL, |
| 2546 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2547 | FunctionProtoType *T = TL.getTypePtr(); |
| 2548 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2549 | if (ResultType.isNull()) |
| 2550 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2551 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2552 | // Transform the parameters. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2553 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2554 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
| 2555 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2556 | ParmVarDecl *OldParm = TL.getArg(i); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2557 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2558 | QualType NewType; |
| 2559 | ParmVarDecl *NewParm; |
| 2560 | |
| 2561 | if (OldParm) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2562 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2563 | assert(OldDI->getType() == T->getArgType(i)); |
| 2564 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2565 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2566 | if (!NewDI) |
| 2567 | return QualType(); |
| 2568 | |
| 2569 | if (NewDI == OldDI) |
| 2570 | NewParm = OldParm; |
| 2571 | else |
| 2572 | NewParm = ParmVarDecl::Create(SemaRef.Context, |
| 2573 | OldParm->getDeclContext(), |
| 2574 | OldParm->getLocation(), |
| 2575 | OldParm->getIdentifier(), |
| 2576 | NewDI->getType(), |
| 2577 | NewDI, |
| 2578 | OldParm->getStorageClass(), |
| 2579 | /* DefArg */ NULL); |
| 2580 | NewType = NewParm->getType(); |
| 2581 | |
| 2582 | // Deal with the possibility that we don't have a parameter |
| 2583 | // declaration for this parameter. |
| 2584 | } else { |
| 2585 | NewParm = 0; |
| 2586 | |
| 2587 | QualType OldType = T->getArgType(i); |
| 2588 | NewType = getDerived().TransformType(OldType); |
| 2589 | if (NewType.isNull()) |
| 2590 | return QualType(); |
| 2591 | } |
| 2592 | |
| 2593 | ParamTypes.push_back(NewType); |
| 2594 | ParamDecls.push_back(NewParm); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2595 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2596 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2597 | QualType Result = TL.getType(); |
| 2598 | if (getDerived().AlwaysRebuild() || |
| 2599 | ResultType != T->getResultType() || |
| 2600 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2601 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2602 | ParamTypes.data(), |
| 2603 | ParamTypes.size(), |
| 2604 | T->isVariadic(), |
| 2605 | T->getTypeQuals()); |
| 2606 | if (Result.isNull()) |
| 2607 | return QualType(); |
| 2608 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2609 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2610 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2611 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2612 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2613 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2614 | NewTL.setArg(i, ParamDecls[i]); |
| 2615 | |
| 2616 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2617 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2618 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2619 | template<typename Derived> |
| 2620 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2621 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2622 | FunctionNoProtoTypeLoc TL, |
| 2623 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2624 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2625 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2626 | if (ResultType.isNull()) |
| 2627 | return QualType(); |
| 2628 | |
| 2629 | QualType Result = TL.getType(); |
| 2630 | if (getDerived().AlwaysRebuild() || |
| 2631 | ResultType != T->getResultType()) |
| 2632 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2633 | |
| 2634 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2635 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2636 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2637 | |
| 2638 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2639 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2640 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2641 | template<typename Derived> QualType |
| 2642 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2643 | UnresolvedUsingTypeLoc TL, |
| 2644 | QualType ObjectType) { |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2645 | UnresolvedUsingType *T = TL.getTypePtr(); |
| 2646 | Decl *D = getDerived().TransformDecl(T->getDecl()); |
| 2647 | if (!D) |
| 2648 | return QualType(); |
| 2649 | |
| 2650 | QualType Result = TL.getType(); |
| 2651 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2652 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2653 | if (Result.isNull()) |
| 2654 | return QualType(); |
| 2655 | } |
| 2656 | |
| 2657 | // We might get an arbitrary type spec type back. We should at |
| 2658 | // least always get a type spec type, though. |
| 2659 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2660 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2661 | |
| 2662 | return Result; |
| 2663 | } |
| 2664 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2665 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2666 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2667 | TypedefTypeLoc TL, |
| 2668 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2669 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2670 | TypedefDecl *Typedef |
| 2671 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl())); |
| 2672 | if (!Typedef) |
| 2673 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2674 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2675 | QualType Result = TL.getType(); |
| 2676 | if (getDerived().AlwaysRebuild() || |
| 2677 | Typedef != T->getDecl()) { |
| 2678 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2679 | if (Result.isNull()) |
| 2680 | return QualType(); |
| 2681 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2682 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2683 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2684 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2685 | |
| 2686 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2687 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2688 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2689 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2690 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2691 | TypeOfExprTypeLoc TL, |
| 2692 | QualType ObjectType) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2693 | // typeof expressions are not potentially evaluated contexts |
| 2694 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2695 | |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2696 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2697 | if (E.isInvalid()) |
| 2698 | return QualType(); |
| 2699 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2700 | QualType Result = TL.getType(); |
| 2701 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2702 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2703 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2704 | if (Result.isNull()) |
| 2705 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2706 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2707 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2708 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2709 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2710 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2711 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2712 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2713 | |
| 2714 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2715 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2716 | |
| 2717 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2718 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2719 | TypeOfTypeLoc TL, |
| 2720 | QualType ObjectType) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2721 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 2722 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 2723 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2724 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2725 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2726 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2727 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 2728 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2729 | if (Result.isNull()) |
| 2730 | return QualType(); |
| 2731 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2732 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2733 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2734 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2735 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2736 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2737 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2738 | |
| 2739 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2740 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2741 | |
| 2742 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2743 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2744 | DecltypeTypeLoc TL, |
| 2745 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2746 | DecltypeType *T = TL.getTypePtr(); |
| 2747 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2748 | // decltype expressions are not potentially evaluated contexts |
| 2749 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2750 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2751 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2752 | if (E.isInvalid()) |
| 2753 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2754 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2755 | QualType Result = TL.getType(); |
| 2756 | if (getDerived().AlwaysRebuild() || |
| 2757 | E.get() != T->getUnderlyingExpr()) { |
| 2758 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2759 | if (Result.isNull()) |
| 2760 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2761 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2762 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2763 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2764 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2765 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2766 | |
| 2767 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2768 | } |
| 2769 | |
| 2770 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2771 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2772 | RecordTypeLoc TL, |
| 2773 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2774 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2775 | RecordDecl *Record |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2776 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2777 | if (!Record) |
| 2778 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2779 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2780 | QualType Result = TL.getType(); |
| 2781 | if (getDerived().AlwaysRebuild() || |
| 2782 | Record != T->getDecl()) { |
| 2783 | Result = getDerived().RebuildRecordType(Record); |
| 2784 | if (Result.isNull()) |
| 2785 | return QualType(); |
| 2786 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2787 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2788 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2789 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2790 | |
| 2791 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2792 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2793 | |
| 2794 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2795 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2796 | EnumTypeLoc TL, |
| 2797 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2798 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2799 | EnumDecl *Enum |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2800 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2801 | if (!Enum) |
| 2802 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2803 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2804 | QualType Result = TL.getType(); |
| 2805 | if (getDerived().AlwaysRebuild() || |
| 2806 | Enum != T->getDecl()) { |
| 2807 | Result = getDerived().RebuildEnumType(Enum); |
| 2808 | if (Result.isNull()) |
| 2809 | return QualType(); |
| 2810 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2811 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2812 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2813 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2814 | |
| 2815 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2816 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2817 | |
| 2818 | template <typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2819 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2820 | ElaboratedTypeLoc TL, |
| 2821 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2822 | ElaboratedType *T = TL.getTypePtr(); |
| 2823 | |
| 2824 | // FIXME: this should be a nested type. |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2825 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2826 | if (Underlying.isNull()) |
| 2827 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2828 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2829 | QualType Result = TL.getType(); |
| 2830 | if (getDerived().AlwaysRebuild() || |
| 2831 | Underlying != T->getUnderlyingType()) { |
| 2832 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2833 | if (Result.isNull()) |
| 2834 | return QualType(); |
| 2835 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2836 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2837 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2838 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2839 | |
| 2840 | return Result; |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2841 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2842 | |
| 2843 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2844 | template<typename Derived> |
| 2845 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2846 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2847 | TemplateTypeParmTypeLoc TL, |
| 2848 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2849 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2850 | } |
| 2851 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2852 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2853 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2854 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2855 | SubstTemplateTypeParmTypeLoc TL, |
| 2856 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2857 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2858 | } |
| 2859 | |
| 2860 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2861 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2862 | const TemplateSpecializationType *TST, |
| 2863 | QualType ObjectType) { |
| 2864 | // FIXME: this entire method is a temporary workaround; callers |
| 2865 | // should be rewritten to provide real type locs. |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2866 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2867 | // Fake up a TemplateSpecializationTypeLoc. |
| 2868 | TypeLocBuilder TLB; |
| 2869 | TemplateSpecializationTypeLoc TL |
| 2870 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2871 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2872 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 2873 | |
| 2874 | TL.setTemplateNameLoc(BaseLoc); |
| 2875 | TL.setLAngleLoc(BaseLoc); |
| 2876 | TL.setRAngleLoc(BaseLoc); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2877 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2878 | const TemplateArgument &TA = TST->getArg(i); |
| 2879 | TemplateArgumentLoc TAL; |
| 2880 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2881 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2882 | } |
| 2883 | |
| 2884 | TypeLocBuilder IgnoredTLB; |
| 2885 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2886 | } |
| 2887 | |
| 2888 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2889 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2890 | TypeLocBuilder &TLB, |
| 2891 | TemplateSpecializationTypeLoc TL, |
| 2892 | QualType ObjectType) { |
| 2893 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 2894 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2895 | TemplateName Template |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2896 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2897 | if (Template.isNull()) |
| 2898 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2899 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2900 | TemplateArgumentListInfo NewTemplateArgs; |
| 2901 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 2902 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 2903 | |
| 2904 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 2905 | TemplateArgumentLoc Loc; |
| 2906 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2907 | return QualType(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2908 | NewTemplateArgs.addArgument(Loc); |
| 2909 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2910 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2911 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 2912 | |
| 2913 | QualType Result = |
| 2914 | getDerived().RebuildTemplateSpecializationType(Template, |
| 2915 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2916 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2917 | |
| 2918 | if (!Result.isNull()) { |
| 2919 | TemplateSpecializationTypeLoc NewTL |
| 2920 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 2921 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 2922 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 2923 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 2924 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 2925 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2926 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2927 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2928 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2929 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2930 | |
| 2931 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2932 | QualType |
| 2933 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2934 | QualifiedNameTypeLoc TL, |
| 2935 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2936 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2937 | NestedNameSpecifier *NNS |
| 2938 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2939 | SourceRange(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 2940 | false, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2941 | ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2942 | if (!NNS) |
| 2943 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2944 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2945 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 2946 | if (Named.isNull()) |
| 2947 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2948 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2949 | QualType Result = TL.getType(); |
| 2950 | if (getDerived().AlwaysRebuild() || |
| 2951 | NNS != T->getQualifier() || |
| 2952 | Named != T->getNamedType()) { |
| 2953 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 2954 | if (Result.isNull()) |
| 2955 | return QualType(); |
| 2956 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2957 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2958 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 2959 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2960 | |
| 2961 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2962 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2963 | |
| 2964 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2965 | QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2966 | TypenameTypeLoc TL, |
| 2967 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2968 | TypenameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2969 | |
| 2970 | /* FIXME: preserve source information better than this */ |
| 2971 | SourceRange SR(TL.getNameLoc()); |
| 2972 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2973 | NestedNameSpecifier *NNS |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2974 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 2975 | false, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2976 | if (!NNS) |
| 2977 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2978 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2979 | QualType Result; |
| 2980 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2981 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2982 | QualType NewTemplateId |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2983 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 2984 | if (NewTemplateId.isNull()) |
| 2985 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2986 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2987 | if (!getDerived().AlwaysRebuild() && |
| 2988 | NNS == T->getQualifier() && |
| 2989 | NewTemplateId == QualType(TemplateId, 0)) |
| 2990 | return QualType(T, 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2991 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2992 | Result = getDerived().RebuildTypenameType(NNS, NewTemplateId); |
| 2993 | } else { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2994 | Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2995 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2996 | if (Result.isNull()) |
| 2997 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2998 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2999 | TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result); |
| 3000 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3001 | |
| 3002 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3003 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3004 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3005 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3006 | QualType |
| 3007 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3008 | ObjCInterfaceTypeLoc TL, |
| 3009 | QualType ObjectType) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3010 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 3011 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3012 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3013 | |
| 3014 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3015 | QualType |
| 3016 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3017 | ObjCObjectPointerTypeLoc TL, |
| 3018 | QualType ObjectType) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3019 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 3020 | return QualType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3021 | } |
| 3022 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3023 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3024 | // Statement transformation |
| 3025 | //===----------------------------------------------------------------------===// |
| 3026 | template<typename Derived> |
| 3027 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3028 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3029 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3030 | } |
| 3031 | |
| 3032 | template<typename Derived> |
| 3033 | Sema::OwningStmtResult |
| 3034 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3035 | return getDerived().TransformCompoundStmt(S, false); |
| 3036 | } |
| 3037 | |
| 3038 | template<typename Derived> |
| 3039 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3040 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3041 | bool IsStmtExpr) { |
| 3042 | bool SubStmtChanged = false; |
| 3043 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3044 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3045 | B != BEnd; ++B) { |
| 3046 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3047 | if (Result.isInvalid()) |
| 3048 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3049 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3050 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3051 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3052 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3053 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3054 | if (!getDerived().AlwaysRebuild() && |
| 3055 | !SubStmtChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3056 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3057 | |
| 3058 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3059 | move_arg(Statements), |
| 3060 | S->getRBracLoc(), |
| 3061 | IsStmtExpr); |
| 3062 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3063 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3064 | template<typename Derived> |
| 3065 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3066 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3067 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3068 | { |
| 3069 | // The case value expressions are not potentially evaluated. |
| 3070 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3071 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3072 | // Transform the left-hand case value. |
| 3073 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3074 | if (LHS.isInvalid()) |
| 3075 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3076 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3077 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3078 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3079 | if (RHS.isInvalid()) |
| 3080 | return SemaRef.StmtError(); |
| 3081 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3082 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3083 | // Build the case statement. |
| 3084 | // Case statements are always rebuilt so that they will attached to their |
| 3085 | // transformed switch statement. |
| 3086 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3087 | move(LHS), |
| 3088 | S->getEllipsisLoc(), |
| 3089 | move(RHS), |
| 3090 | S->getColonLoc()); |
| 3091 | if (Case.isInvalid()) |
| 3092 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3093 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3094 | // Transform the statement following the case |
| 3095 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3096 | if (SubStmt.isInvalid()) |
| 3097 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3098 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3099 | // Attach the body to the case statement |
| 3100 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3101 | } |
| 3102 | |
| 3103 | template<typename Derived> |
| 3104 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3105 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3106 | // Transform the statement following the default case |
| 3107 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3108 | if (SubStmt.isInvalid()) |
| 3109 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3110 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3111 | // Default statements are always rebuilt |
| 3112 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3113 | move(SubStmt)); |
| 3114 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3115 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3116 | template<typename Derived> |
| 3117 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3118 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3119 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3120 | if (SubStmt.isInvalid()) |
| 3121 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3122 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3123 | // FIXME: Pass the real colon location in. |
| 3124 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3125 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3126 | move(SubStmt)); |
| 3127 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3128 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3129 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3130 | Sema::OwningStmtResult |
| 3131 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3132 | // Transform the condition |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3133 | OwningExprResult Cond(SemaRef); |
| 3134 | VarDecl *ConditionVar = 0; |
| 3135 | if (S->getConditionVariable()) { |
| 3136 | ConditionVar |
| 3137 | = cast_or_null<VarDecl>( |
| 3138 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3139 | if (!ConditionVar) |
| 3140 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3141 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3142 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3143 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3144 | if (Cond.isInvalid()) |
| 3145 | return SemaRef.StmtError(); |
| 3146 | } |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3147 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3148 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3149 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3150 | // Transform the "then" branch. |
| 3151 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3152 | if (Then.isInvalid()) |
| 3153 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3154 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3155 | // Transform the "else" branch. |
| 3156 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3157 | if (Else.isInvalid()) |
| 3158 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3159 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3160 | if (!getDerived().AlwaysRebuild() && |
| 3161 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3162 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3163 | Then.get() == S->getThen() && |
| 3164 | Else.get() == S->getElse()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3165 | return SemaRef.Owned(S->Retain()); |
| 3166 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3167 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3168 | move(Then), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3169 | S->getElseLoc(), move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3170 | } |
| 3171 | |
| 3172 | template<typename Derived> |
| 3173 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3174 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3175 | // Transform the condition. |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3176 | OwningExprResult Cond(SemaRef); |
| 3177 | VarDecl *ConditionVar = 0; |
| 3178 | if (S->getConditionVariable()) { |
| 3179 | ConditionVar |
| 3180 | = cast_or_null<VarDecl>( |
| 3181 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3182 | if (!ConditionVar) |
| 3183 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3184 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3185 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3186 | |
| 3187 | if (Cond.isInvalid()) |
| 3188 | return SemaRef.StmtError(); |
| 3189 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3190 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3191 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3192 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3193 | // Rebuild the switch statement. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3194 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3195 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3196 | if (Switch.isInvalid()) |
| 3197 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3198 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3199 | // Transform the body of the switch statement. |
| 3200 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3201 | if (Body.isInvalid()) |
| 3202 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3203 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3204 | // Complete the switch statement. |
| 3205 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3206 | move(Body)); |
| 3207 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3208 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3209 | template<typename Derived> |
| 3210 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3211 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3212 | // Transform the condition |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3213 | OwningExprResult Cond(SemaRef); |
| 3214 | VarDecl *ConditionVar = 0; |
| 3215 | if (S->getConditionVariable()) { |
| 3216 | ConditionVar |
| 3217 | = cast_or_null<VarDecl>( |
| 3218 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3219 | if (!ConditionVar) |
| 3220 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3221 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3222 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3223 | |
| 3224 | if (Cond.isInvalid()) |
| 3225 | return SemaRef.StmtError(); |
| 3226 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3227 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3228 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3229 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3230 | // Transform the body |
| 3231 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3232 | if (Body.isInvalid()) |
| 3233 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3234 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3235 | if (!getDerived().AlwaysRebuild() && |
| 3236 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3237 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3238 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3239 | return SemaRef.Owned(S->Retain()); |
| 3240 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3241 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3242 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3243 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3244 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3245 | template<typename Derived> |
| 3246 | Sema::OwningStmtResult |
| 3247 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3248 | // Transform the condition |
| 3249 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3250 | if (Cond.isInvalid()) |
| 3251 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3252 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3253 | // Transform the body |
| 3254 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3255 | if (Body.isInvalid()) |
| 3256 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3257 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3258 | if (!getDerived().AlwaysRebuild() && |
| 3259 | Cond.get() == S->getCond() && |
| 3260 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3261 | return SemaRef.Owned(S->Retain()); |
| 3262 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3263 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3264 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3265 | S->getRParenLoc()); |
| 3266 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3267 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3268 | template<typename Derived> |
| 3269 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3270 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3271 | // Transform the initialization statement |
| 3272 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3273 | if (Init.isInvalid()) |
| 3274 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3275 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3276 | // Transform the condition |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3277 | OwningExprResult Cond(SemaRef); |
| 3278 | VarDecl *ConditionVar = 0; |
| 3279 | if (S->getConditionVariable()) { |
| 3280 | ConditionVar |
| 3281 | = cast_or_null<VarDecl>( |
| 3282 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3283 | if (!ConditionVar) |
| 3284 | return SemaRef.StmtError(); |
| 3285 | } else { |
| 3286 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3287 | |
| 3288 | if (Cond.isInvalid()) |
| 3289 | return SemaRef.StmtError(); |
| 3290 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3291 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3292 | // Transform the increment |
| 3293 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3294 | if (Inc.isInvalid()) |
| 3295 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3296 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3297 | // Transform the body |
| 3298 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3299 | if (Body.isInvalid()) |
| 3300 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3301 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3302 | if (!getDerived().AlwaysRebuild() && |
| 3303 | Init.get() == S->getInit() && |
| 3304 | Cond.get() == S->getCond() && |
| 3305 | Inc.get() == S->getInc() && |
| 3306 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3307 | return SemaRef.Owned(S->Retain()); |
| 3308 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3309 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3310 | move(Init), getSema().MakeFullExpr(Cond), |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3311 | ConditionVar, |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3312 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3313 | S->getRParenLoc(), move(Body)); |
| 3314 | } |
| 3315 | |
| 3316 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3317 | Sema::OwningStmtResult |
| 3318 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3319 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3320 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3321 | S->getLabel()); |
| 3322 | } |
| 3323 | |
| 3324 | template<typename Derived> |
| 3325 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3326 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3327 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3328 | if (Target.isInvalid()) |
| 3329 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3330 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3331 | if (!getDerived().AlwaysRebuild() && |
| 3332 | Target.get() == S->getTarget()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3333 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3334 | |
| 3335 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3336 | move(Target)); |
| 3337 | } |
| 3338 | |
| 3339 | template<typename Derived> |
| 3340 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3341 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3342 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3343 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3344 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3345 | template<typename Derived> |
| 3346 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3347 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3348 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3349 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3350 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3351 | template<typename Derived> |
| 3352 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3353 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3354 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3355 | if (Result.isInvalid()) |
| 3356 | return SemaRef.StmtError(); |
| 3357 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3358 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3359 | // to tell whether the return type of the function has changed. |
| 3360 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3361 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3362 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3363 | template<typename Derived> |
| 3364 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3365 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3366 | bool DeclChanged = false; |
| 3367 | llvm::SmallVector<Decl *, 4> Decls; |
| 3368 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3369 | D != DEnd; ++D) { |
| 3370 | Decl *Transformed = getDerived().TransformDefinition(*D); |
| 3371 | if (!Transformed) |
| 3372 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3373 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3374 | if (Transformed != *D) |
| 3375 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3376 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3377 | Decls.push_back(Transformed); |
| 3378 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3379 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3380 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3381 | return SemaRef.Owned(S->Retain()); |
| 3382 | |
| 3383 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3384 | S->getStartLoc(), S->getEndLoc()); |
| 3385 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3386 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3387 | template<typename Derived> |
| 3388 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3389 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3390 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3391 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | template<typename Derived> |
| 3395 | Sema::OwningStmtResult |
| 3396 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3397 | |
| 3398 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3399 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3400 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3401 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3402 | OwningExprResult AsmString(SemaRef); |
| 3403 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3404 | |
| 3405 | bool ExprsChanged = false; |
| 3406 | |
| 3407 | // Go through the outputs. |
| 3408 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3409 | Names.push_back(S->getOutputIdentifier(I)); |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3410 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3411 | // No need to transform the constraint literal. |
| 3412 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
| 3413 | |
| 3414 | // Transform the output expr. |
| 3415 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3416 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3417 | if (Result.isInvalid()) |
| 3418 | return SemaRef.StmtError(); |
| 3419 | |
| 3420 | ExprsChanged |= Result.get() != OutputExpr; |
| 3421 | |
| 3422 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3423 | } |
| 3424 | |
| 3425 | // Go through the inputs. |
| 3426 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3427 | Names.push_back(S->getInputIdentifier(I)); |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3428 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3429 | // No need to transform the constraint literal. |
| 3430 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
| 3431 | |
| 3432 | // Transform the input expr. |
| 3433 | Expr *InputExpr = S->getInputExpr(I); |
| 3434 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3435 | if (Result.isInvalid()) |
| 3436 | return SemaRef.StmtError(); |
| 3437 | |
| 3438 | ExprsChanged |= Result.get() != InputExpr; |
| 3439 | |
| 3440 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3441 | } |
| 3442 | |
| 3443 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3444 | return SemaRef.Owned(S->Retain()); |
| 3445 | |
| 3446 | // Go through the clobbers. |
| 3447 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3448 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3449 | |
| 3450 | // No need to transform the asm string literal. |
| 3451 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3452 | |
| 3453 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3454 | S->isSimple(), |
| 3455 | S->isVolatile(), |
| 3456 | S->getNumOutputs(), |
| 3457 | S->getNumInputs(), |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3458 | Names.data(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3459 | move_arg(Constraints), |
| 3460 | move_arg(Exprs), |
| 3461 | move(AsmString), |
| 3462 | move_arg(Clobbers), |
| 3463 | S->getRParenLoc(), |
| 3464 | S->isMSAsm()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3465 | } |
| 3466 | |
| 3467 | |
| 3468 | template<typename Derived> |
| 3469 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3470 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3471 | // FIXME: Implement this |
| 3472 | assert(false && "Cannot transform an Objective-C @try statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3473 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3474 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3475 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3476 | template<typename Derived> |
| 3477 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3478 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3479 | // FIXME: Implement this |
| 3480 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3481 | return SemaRef.Owned(S->Retain()); |
| 3482 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3483 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3484 | template<typename Derived> |
| 3485 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3486 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3487 | // FIXME: Implement this |
| 3488 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3489 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3490 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3491 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3492 | template<typename Derived> |
| 3493 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3494 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3495 | // FIXME: Implement this |
| 3496 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3497 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3498 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3499 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3500 | template<typename Derived> |
| 3501 | Sema::OwningStmtResult |
| 3502 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3503 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3504 | // FIXME: Implement this |
| 3505 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3506 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | template<typename Derived> |
| 3510 | Sema::OwningStmtResult |
| 3511 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3512 | ObjCForCollectionStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3513 | // FIXME: Implement this |
| 3514 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3515 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3516 | } |
| 3517 | |
| 3518 | |
| 3519 | template<typename Derived> |
| 3520 | Sema::OwningStmtResult |
| 3521 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3522 | // Transform the exception declaration, if any. |
| 3523 | VarDecl *Var = 0; |
| 3524 | if (S->getExceptionDecl()) { |
| 3525 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3526 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3527 | ExceptionDecl->getDeclName()); |
| 3528 | |
| 3529 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3530 | if (T.isNull()) |
| 3531 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3532 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3533 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3534 | T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3535 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3536 | ExceptionDecl->getIdentifier(), |
| 3537 | ExceptionDecl->getLocation(), |
| 3538 | /*FIXME: Inaccurate*/ |
| 3539 | SourceRange(ExceptionDecl->getLocation())); |
| 3540 | if (!Var || Var->isInvalidDecl()) { |
| 3541 | if (Var) |
| 3542 | Var->Destroy(SemaRef.Context); |
| 3543 | return SemaRef.StmtError(); |
| 3544 | } |
| 3545 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3546 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3547 | // Transform the actual exception handler. |
| 3548 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3549 | if (Handler.isInvalid()) { |
| 3550 | if (Var) |
| 3551 | Var->Destroy(SemaRef.Context); |
| 3552 | return SemaRef.StmtError(); |
| 3553 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3554 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3555 | if (!getDerived().AlwaysRebuild() && |
| 3556 | !Var && |
| 3557 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3558 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3559 | |
| 3560 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3561 | Var, |
| 3562 | move(Handler)); |
| 3563 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3564 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3565 | template<typename Derived> |
| 3566 | Sema::OwningStmtResult |
| 3567 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3568 | // Transform the try block itself. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3569 | OwningStmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3570 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3571 | if (TryBlock.isInvalid()) |
| 3572 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3573 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3574 | // Transform the handlers. |
| 3575 | bool HandlerChanged = false; |
| 3576 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3577 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3578 | OwningStmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3579 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3580 | if (Handler.isInvalid()) |
| 3581 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3582 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3583 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3584 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3585 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3586 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3587 | if (!getDerived().AlwaysRebuild() && |
| 3588 | TryBlock.get() == S->getTryBlock() && |
| 3589 | !HandlerChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3590 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3591 | |
| 3592 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3593 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3594 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3595 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3596 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3597 | // Expression transformation |
| 3598 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3599 | template<typename Derived> |
| 3600 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3601 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3602 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3603 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3604 | |
| 3605 | template<typename Derived> |
| 3606 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3607 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3608 | NestedNameSpecifier *Qualifier = 0; |
| 3609 | if (E->getQualifier()) { |
| 3610 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 3611 | E->getQualifierRange(), |
| 3612 | false); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3613 | if (!Qualifier) |
| 3614 | return SemaRef.ExprError(); |
| 3615 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3616 | |
| 3617 | ValueDecl *ND |
| 3618 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3619 | if (!ND) |
| 3620 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3621 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3622 | if (!getDerived().AlwaysRebuild() && |
| 3623 | Qualifier == E->getQualifier() && |
| 3624 | ND == E->getDecl() && |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3625 | !E->hasExplicitTemplateArgumentList()) { |
| 3626 | |
| 3627 | // Mark it referenced in the new context regardless. |
| 3628 | // FIXME: this is a bit instantiation-specific. |
| 3629 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 3630 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3631 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3632 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3633 | |
| 3634 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 3635 | if (E->hasExplicitTemplateArgumentList()) { |
| 3636 | TemplateArgs = &TransArgs; |
| 3637 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3638 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 3639 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3640 | TemplateArgumentLoc Loc; |
| 3641 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 3642 | return SemaRef.ExprError(); |
| 3643 | TransArgs.addArgument(Loc); |
| 3644 | } |
| 3645 | } |
| 3646 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3647 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3648 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3649 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3650 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3651 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3652 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3653 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3654 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3655 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3656 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3657 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3658 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3659 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3660 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3661 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3662 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3663 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3664 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3665 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3666 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3667 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3668 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3669 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3670 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3671 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3672 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3673 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3674 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3675 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3676 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3677 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3678 | return SemaRef.Owned(E->Retain()); |
| 3679 | } |
| 3680 | |
| 3681 | template<typename Derived> |
| 3682 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3683 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3684 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3685 | if (SubExpr.isInvalid()) |
| 3686 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3687 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3688 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3689 | return SemaRef.Owned(E->Retain()); |
| 3690 | |
| 3691 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3692 | E->getRParen()); |
| 3693 | } |
| 3694 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3695 | template<typename Derived> |
| 3696 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3697 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 3698 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3699 | if (SubExpr.isInvalid()) |
| 3700 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3701 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3702 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3703 | return SemaRef.Owned(E->Retain()); |
| 3704 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3705 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3706 | E->getOpcode(), |
| 3707 | move(SubExpr)); |
| 3708 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3709 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3710 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3711 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3712 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3713 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3714 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3715 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3716 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3717 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3718 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3719 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3720 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3721 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3722 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3723 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3724 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3725 | E->getSourceRange()); |
| 3726 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3727 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3728 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3729 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3730 | // C++0x [expr.sizeof]p1: |
| 3731 | // The operand is either an expression, which is an unevaluated operand |
| 3732 | // [...] |
| 3733 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3734 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3735 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3736 | if (SubExpr.isInvalid()) |
| 3737 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3738 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3739 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3740 | return SemaRef.Owned(E->Retain()); |
| 3741 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3742 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3743 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3744 | E->isSizeOf(), |
| 3745 | E->getSourceRange()); |
| 3746 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3747 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3748 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3749 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3750 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3751 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3752 | if (LHS.isInvalid()) |
| 3753 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3754 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3755 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3756 | if (RHS.isInvalid()) |
| 3757 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3758 | |
| 3759 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3760 | if (!getDerived().AlwaysRebuild() && |
| 3761 | LHS.get() == E->getLHS() && |
| 3762 | RHS.get() == E->getRHS()) |
| 3763 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3764 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3765 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3766 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3767 | move(RHS), |
| 3768 | E->getRBracketLoc()); |
| 3769 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3770 | |
| 3771 | template<typename Derived> |
| 3772 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3773 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3774 | // Transform the callee. |
| 3775 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3776 | if (Callee.isInvalid()) |
| 3777 | return SemaRef.ExprError(); |
| 3778 | |
| 3779 | // Transform arguments. |
| 3780 | bool ArgChanged = false; |
| 3781 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3782 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3783 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3784 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3785 | if (Arg.isInvalid()) |
| 3786 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3787 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3788 | // FIXME: Wrong source location information for the ','. |
| 3789 | FakeCommaLocs.push_back( |
| 3790 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3791 | |
| 3792 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3793 | Args.push_back(Arg.takeAs<Expr>()); |
| 3794 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3795 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3796 | if (!getDerived().AlwaysRebuild() && |
| 3797 | Callee.get() == E->getCallee() && |
| 3798 | !ArgChanged) |
| 3799 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3800 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3801 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3802 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3803 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3804 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3805 | move_arg(Args), |
| 3806 | FakeCommaLocs.data(), |
| 3807 | E->getRParenLoc()); |
| 3808 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3809 | |
| 3810 | template<typename Derived> |
| 3811 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3812 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3813 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3814 | if (Base.isInvalid()) |
| 3815 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3816 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3817 | NestedNameSpecifier *Qualifier = 0; |
| 3818 | if (E->hasQualifier()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3819 | Qualifier |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3820 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 3821 | E->getQualifierRange(), |
| 3822 | false); |
Douglas Gregor | 84f14dd | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3823 | if (Qualifier == 0) |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3824 | return SemaRef.ExprError(); |
| 3825 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3826 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 3827 | ValueDecl *Member |
| 3828 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3829 | if (!Member) |
| 3830 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3831 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3832 | if (!getDerived().AlwaysRebuild() && |
| 3833 | Base.get() == E->getBase() && |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3834 | Qualifier == E->getQualifier() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3835 | Member == E->getMemberDecl() && |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3836 | !E->hasExplicitTemplateArgumentList()) { |
| 3837 | |
| 3838 | // Mark it referenced in the new context regardless. |
| 3839 | // FIXME: this is a bit instantiation-specific. |
| 3840 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3841 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3842 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3843 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3844 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3845 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3846 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3847 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3848 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3849 | TemplateArgumentLoc Loc; |
| 3850 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3851 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3852 | TransArgs.addArgument(Loc); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3853 | } |
| 3854 | } |
| 3855 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3856 | // FIXME: Bogus source location for the operator |
| 3857 | SourceLocation FakeOperatorLoc |
| 3858 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3859 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3860 | // FIXME: to do this check properly, we will need to preserve the |
| 3861 | // first-qualifier-in-scope here, just in case we had a dependent |
| 3862 | // base (and therefore couldn't do the check) and a |
| 3863 | // nested-name-qualifier (and therefore could do the lookup). |
| 3864 | NamedDecl *FirstQualifierInScope = 0; |
| 3865 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3866 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3867 | E->isArrow(), |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3868 | Qualifier, |
| 3869 | E->getQualifierRange(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3870 | E->getMemberLoc(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3871 | Member, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3872 | (E->hasExplicitTemplateArgumentList() |
| 3873 | ? &TransArgs : 0), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3874 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3875 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3876 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3877 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3878 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3879 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3880 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3881 | if (LHS.isInvalid()) |
| 3882 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3883 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3884 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3885 | if (RHS.isInvalid()) |
| 3886 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3887 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3888 | if (!getDerived().AlwaysRebuild() && |
| 3889 | LHS.get() == E->getLHS() && |
| 3890 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3891 | return SemaRef.Owned(E->Retain()); |
| 3892 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3893 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 3894 | move(LHS), move(RHS)); |
| 3895 | } |
| 3896 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3897 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3898 | Sema::OwningExprResult |
| 3899 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3900 | CompoundAssignOperator *E) { |
| 3901 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3902 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3903 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3904 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3905 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3906 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3907 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3908 | if (Cond.isInvalid()) |
| 3909 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3910 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3911 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3912 | if (LHS.isInvalid()) |
| 3913 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3914 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3915 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3916 | if (RHS.isInvalid()) |
| 3917 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3918 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3919 | if (!getDerived().AlwaysRebuild() && |
| 3920 | Cond.get() == E->getCond() && |
| 3921 | LHS.get() == E->getLHS() && |
| 3922 | RHS.get() == E->getRHS()) |
| 3923 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3924 | |
| 3925 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3926 | E->getQuestionLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3927 | move(LHS), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3928 | E->getColonLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3929 | move(RHS)); |
| 3930 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3931 | |
| 3932 | template<typename Derived> |
| 3933 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3934 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3935 | // Implicit casts are eliminated during transformation, since they |
| 3936 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3937 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3938 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3939 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3940 | template<typename Derived> |
| 3941 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3942 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3943 | TypeSourceInfo *OldT; |
| 3944 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3945 | { |
| 3946 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3947 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3948 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3949 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3950 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3951 | OldT = E->getTypeInfoAsWritten(); |
| 3952 | NewT = getDerived().TransformType(OldT); |
| 3953 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3954 | return SemaRef.ExprError(); |
| 3955 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3956 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3957 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3958 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3959 | if (SubExpr.isInvalid()) |
| 3960 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3961 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3962 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3963 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3964 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3965 | return SemaRef.Owned(E->Retain()); |
| 3966 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3967 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 3968 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3969 | E->getRParenLoc(), |
| 3970 | move(SubExpr)); |
| 3971 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3972 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3973 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3974 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3975 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3976 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 3977 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 3978 | if (!NewT) |
| 3979 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3980 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3981 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 3982 | if (Init.isInvalid()) |
| 3983 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3984 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3985 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3986 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3987 | Init.get() == E->getInitializer()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3988 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3989 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 3990 | // Note: the expression type doesn't necessarily match the |
| 3991 | // type-as-written, but that's okay, because it should always be |
| 3992 | // derivable from the initializer. |
| 3993 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3994 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3995 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 3996 | move(Init)); |
| 3997 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3998 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3999 | template<typename Derived> |
| 4000 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4001 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4002 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4003 | if (Base.isInvalid()) |
| 4004 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4005 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4006 | if (!getDerived().AlwaysRebuild() && |
| 4007 | Base.get() == E->getBase()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4008 | return SemaRef.Owned(E->Retain()); |
| 4009 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4010 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4011 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4012 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 4013 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 4014 | E->getAccessorLoc(), |
| 4015 | E->getAccessor()); |
| 4016 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4017 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4018 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4019 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4020 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4021 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4022 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4023 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4024 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4025 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4026 | if (Init.isInvalid()) |
| 4027 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4028 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4029 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4030 | Inits.push_back(Init.takeAs<Expr>()); |
| 4031 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4032 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4033 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4034 | return SemaRef.Owned(E->Retain()); |
| 4035 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4036 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4037 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4038 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4039 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4040 | template<typename Derived> |
| 4041 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4042 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4043 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4044 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4045 | // transform the initializer value |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4046 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4047 | if (Init.isInvalid()) |
| 4048 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4049 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4050 | // transform the designators. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4051 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4052 | bool ExprChanged = false; |
| 4053 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4054 | DEnd = E->designators_end(); |
| 4055 | D != DEnd; ++D) { |
| 4056 | if (D->isFieldDesignator()) { |
| 4057 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4058 | D->getDotLoc(), |
| 4059 | D->getFieldLoc())); |
| 4060 | continue; |
| 4061 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4062 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4063 | if (D->isArrayDesignator()) { |
| 4064 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4065 | if (Index.isInvalid()) |
| 4066 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4067 | |
| 4068 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4069 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4070 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4071 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4072 | ArrayExprs.push_back(Index.release()); |
| 4073 | continue; |
| 4074 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4075 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4076 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4077 | OwningExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4078 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4079 | if (Start.isInvalid()) |
| 4080 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4081 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4082 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4083 | if (End.isInvalid()) |
| 4084 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4085 | |
| 4086 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4087 | End.get(), |
| 4088 | D->getLBracketLoc(), |
| 4089 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4090 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4091 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4092 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4093 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4094 | ArrayExprs.push_back(Start.release()); |
| 4095 | ArrayExprs.push_back(End.release()); |
| 4096 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4097 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4098 | if (!getDerived().AlwaysRebuild() && |
| 4099 | Init.get() == E->getInit() && |
| 4100 | !ExprChanged) |
| 4101 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4102 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4103 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4104 | E->getEqualOrColonLoc(), |
| 4105 | E->usesGNUSyntax(), move(Init)); |
| 4106 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4107 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4108 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4109 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4110 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4111 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4112 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4113 | |
| 4114 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4115 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4116 | QualType T = getDerived().TransformType(E->getType()); |
| 4117 | if (T.isNull()) |
| 4118 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4119 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4120 | if (!getDerived().AlwaysRebuild() && |
| 4121 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4122 | return SemaRef.Owned(E->Retain()); |
| 4123 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4124 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4125 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4126 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4127 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4128 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4129 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4130 | // FIXME: Do we want the type as written? |
| 4131 | QualType T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4132 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4133 | { |
| 4134 | // FIXME: Source location isn't quite accurate. |
| 4135 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4136 | T = getDerived().TransformType(E->getType()); |
| 4137 | if (T.isNull()) |
| 4138 | return SemaRef.ExprError(); |
| 4139 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4140 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4141 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4142 | if (SubExpr.isInvalid()) |
| 4143 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4144 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4145 | if (!getDerived().AlwaysRebuild() && |
| 4146 | T == E->getType() && |
| 4147 | SubExpr.get() == E->getSubExpr()) |
| 4148 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4149 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4150 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4151 | T, E->getRParenLoc()); |
| 4152 | } |
| 4153 | |
| 4154 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4155 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4156 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4157 | bool ArgumentChanged = false; |
| 4158 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4159 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4160 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4161 | if (Init.isInvalid()) |
| 4162 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4163 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4164 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4165 | Inits.push_back(Init.takeAs<Expr>()); |
| 4166 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4167 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4168 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4169 | move_arg(Inits), |
| 4170 | E->getRParenLoc()); |
| 4171 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4172 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4173 | /// \brief Transform an address-of-label expression. |
| 4174 | /// |
| 4175 | /// By default, the transformation of an address-of-label expression always |
| 4176 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4177 | /// the corresponding label statement by semantic analysis. |
| 4178 | template<typename Derived> |
| 4179 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4180 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4181 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4182 | E->getLabel()); |
| 4183 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4184 | |
| 4185 | template<typename Derived> |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4186 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4187 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4188 | OwningStmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4189 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4190 | if (SubStmt.isInvalid()) |
| 4191 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4192 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4193 | if (!getDerived().AlwaysRebuild() && |
| 4194 | SubStmt.get() == E->getSubStmt()) |
| 4195 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4196 | |
| 4197 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4198 | move(SubStmt), |
| 4199 | E->getRParenLoc()); |
| 4200 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4201 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4202 | template<typename Derived> |
| 4203 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4204 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4205 | QualType T1, T2; |
| 4206 | { |
| 4207 | // FIXME: Source location isn't quite accurate. |
| 4208 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4209 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4210 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4211 | if (T1.isNull()) |
| 4212 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4213 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4214 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4215 | if (T2.isNull()) |
| 4216 | return SemaRef.ExprError(); |
| 4217 | } |
| 4218 | |
| 4219 | if (!getDerived().AlwaysRebuild() && |
| 4220 | T1 == E->getArgType1() && |
| 4221 | T2 == E->getArgType2()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4222 | return SemaRef.Owned(E->Retain()); |
| 4223 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4224 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4225 | T1, T2, E->getRParenLoc()); |
| 4226 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4227 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4228 | template<typename Derived> |
| 4229 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4230 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4231 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4232 | if (Cond.isInvalid()) |
| 4233 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4234 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4235 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4236 | if (LHS.isInvalid()) |
| 4237 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4238 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4239 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4240 | if (RHS.isInvalid()) |
| 4241 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4242 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4243 | if (!getDerived().AlwaysRebuild() && |
| 4244 | Cond.get() == E->getCond() && |
| 4245 | LHS.get() == E->getLHS() && |
| 4246 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4247 | return SemaRef.Owned(E->Retain()); |
| 4248 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4249 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4250 | move(Cond), move(LHS), move(RHS), |
| 4251 | E->getRParenLoc()); |
| 4252 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4253 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4254 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4255 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4256 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4257 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4258 | } |
| 4259 | |
| 4260 | template<typename Derived> |
| 4261 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4262 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4263 | switch (E->getOperator()) { |
| 4264 | case OO_New: |
| 4265 | case OO_Delete: |
| 4266 | case OO_Array_New: |
| 4267 | case OO_Array_Delete: |
| 4268 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4269 | return SemaRef.ExprError(); |
| 4270 | |
| 4271 | case OO_Call: { |
| 4272 | // This is a call to an object's operator(). |
| 4273 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4274 | |
| 4275 | // Transform the object itself. |
| 4276 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4277 | if (Object.isInvalid()) |
| 4278 | return SemaRef.ExprError(); |
| 4279 | |
| 4280 | // FIXME: Poor location information |
| 4281 | SourceLocation FakeLParenLoc |
| 4282 | = SemaRef.PP.getLocForEndOfToken( |
| 4283 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4284 | |
| 4285 | // Transform the call arguments. |
| 4286 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4287 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4288 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4289 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4290 | break; |
| 4291 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4292 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4293 | if (Arg.isInvalid()) |
| 4294 | return SemaRef.ExprError(); |
| 4295 | |
| 4296 | // FIXME: Poor source location information. |
| 4297 | SourceLocation FakeCommaLoc |
| 4298 | = SemaRef.PP.getLocForEndOfToken( |
| 4299 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4300 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4301 | Args.push_back(Arg.release()); |
| 4302 | } |
| 4303 | |
| 4304 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4305 | move_arg(Args), |
| 4306 | FakeCommaLocs.data(), |
| 4307 | E->getLocEnd()); |
| 4308 | } |
| 4309 | |
| 4310 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4311 | case OO_##Name: |
| 4312 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4313 | #include "clang/Basic/OperatorKinds.def" |
| 4314 | case OO_Subscript: |
| 4315 | // Handled below. |
| 4316 | break; |
| 4317 | |
| 4318 | case OO_Conditional: |
| 4319 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4320 | return SemaRef.ExprError(); |
| 4321 | |
| 4322 | case OO_None: |
| 4323 | case NUM_OVERLOADED_OPERATORS: |
| 4324 | llvm_unreachable("not an overloaded operator?"); |
| 4325 | return SemaRef.ExprError(); |
| 4326 | } |
| 4327 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4328 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4329 | if (Callee.isInvalid()) |
| 4330 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4331 | |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4332 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4333 | if (First.isInvalid()) |
| 4334 | return SemaRef.ExprError(); |
| 4335 | |
| 4336 | OwningExprResult Second(SemaRef); |
| 4337 | if (E->getNumArgs() == 2) { |
| 4338 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4339 | if (Second.isInvalid()) |
| 4340 | return SemaRef.ExprError(); |
| 4341 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4342 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4343 | if (!getDerived().AlwaysRebuild() && |
| 4344 | Callee.get() == E->getCallee() && |
| 4345 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4346 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4347 | return SemaRef.Owned(E->Retain()); |
| 4348 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4349 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4350 | E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4351 | move(Callee), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4352 | move(First), |
| 4353 | move(Second)); |
| 4354 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4355 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4356 | template<typename Derived> |
| 4357 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4358 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4359 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4360 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4361 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4362 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4363 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4364 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4365 | TypeSourceInfo *OldT; |
| 4366 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4367 | { |
| 4368 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4369 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4370 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4371 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4372 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4373 | OldT = E->getTypeInfoAsWritten(); |
| 4374 | NewT = getDerived().TransformType(OldT); |
| 4375 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4376 | return SemaRef.ExprError(); |
| 4377 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4378 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4379 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4380 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4381 | if (SubExpr.isInvalid()) |
| 4382 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4383 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4384 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4385 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4386 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4387 | return SemaRef.Owned(E->Retain()); |
| 4388 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4389 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4390 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4391 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4392 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4393 | SourceLocation FakeRParenLoc |
| 4394 | = SemaRef.PP.getLocForEndOfToken( |
| 4395 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4396 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4397 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4398 | FakeLAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4399 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4400 | FakeRAngleLoc, |
| 4401 | FakeRAngleLoc, |
| 4402 | move(SubExpr), |
| 4403 | FakeRParenLoc); |
| 4404 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4405 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4406 | template<typename Derived> |
| 4407 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4408 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4409 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4410 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4411 | |
| 4412 | template<typename Derived> |
| 4413 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4414 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4415 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4416 | } |
| 4417 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4418 | template<typename Derived> |
| 4419 | Sema::OwningExprResult |
| 4420 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4421 | CXXReinterpretCastExpr *E) { |
| 4422 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4423 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4424 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4425 | template<typename Derived> |
| 4426 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4427 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4428 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4429 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4430 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4431 | template<typename Derived> |
| 4432 | Sema::OwningExprResult |
| 4433 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4434 | CXXFunctionalCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4435 | TypeSourceInfo *OldT; |
| 4436 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4437 | { |
| 4438 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4439 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4440 | OldT = E->getTypeInfoAsWritten(); |
| 4441 | NewT = getDerived().TransformType(OldT); |
| 4442 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4443 | return SemaRef.ExprError(); |
| 4444 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4445 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4446 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4447 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4448 | if (SubExpr.isInvalid()) |
| 4449 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4450 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4451 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4452 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4453 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4454 | return SemaRef.Owned(E->Retain()); |
| 4455 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4456 | // FIXME: The end of the type's source range is wrong |
| 4457 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4458 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4459 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4460 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4461 | move(SubExpr), |
| 4462 | E->getRParenLoc()); |
| 4463 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4464 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4465 | template<typename Derived> |
| 4466 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4467 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4468 | if (E->isTypeOperand()) { |
| 4469 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4470 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4471 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4472 | if (T.isNull()) |
| 4473 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4474 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4475 | if (!getDerived().AlwaysRebuild() && |
| 4476 | T == E->getTypeOperand()) |
| 4477 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4478 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4479 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4480 | /*FIXME:*/E->getLocStart(), |
| 4481 | T, |
| 4482 | E->getLocEnd()); |
| 4483 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4484 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4485 | // We don't know whether the expression is potentially evaluated until |
| 4486 | // after we perform semantic analysis, so the expression is potentially |
| 4487 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4488 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4489 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4490 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4491 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4492 | if (SubExpr.isInvalid()) |
| 4493 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4494 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4495 | if (!getDerived().AlwaysRebuild() && |
| 4496 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4497 | return SemaRef.Owned(E->Retain()); |
| 4498 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4499 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4500 | /*FIXME:*/E->getLocStart(), |
| 4501 | move(SubExpr), |
| 4502 | E->getLocEnd()); |
| 4503 | } |
| 4504 | |
| 4505 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4506 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4507 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4508 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4509 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4510 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4511 | template<typename Derived> |
| 4512 | Sema::OwningExprResult |
| 4513 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4514 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4515 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4516 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4517 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4518 | template<typename Derived> |
| 4519 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4520 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4521 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4522 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4523 | QualType T = getDerived().TransformType(E->getType()); |
| 4524 | if (T.isNull()) |
| 4525 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4526 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4527 | if (!getDerived().AlwaysRebuild() && |
| 4528 | T == E->getType()) |
| 4529 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4530 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 4531 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4532 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4533 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4534 | template<typename Derived> |
| 4535 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4536 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4537 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4538 | if (SubExpr.isInvalid()) |
| 4539 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4540 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4541 | if (!getDerived().AlwaysRebuild() && |
| 4542 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4543 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4544 | |
| 4545 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4546 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4547 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4548 | template<typename Derived> |
| 4549 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4550 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4551 | ParmVarDecl *Param |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4552 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam())); |
| 4553 | if (!Param) |
| 4554 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4555 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 4556 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4557 | Param == E->getParam()) |
| 4558 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4559 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 4560 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4561 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4562 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4563 | template<typename Derived> |
| 4564 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4565 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4566 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4567 | |
| 4568 | QualType T = getDerived().TransformType(E->getType()); |
| 4569 | if (T.isNull()) |
| 4570 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4571 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4572 | if (!getDerived().AlwaysRebuild() && |
| 4573 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4574 | return SemaRef.Owned(E->Retain()); |
| 4575 | |
| 4576 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4577 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4578 | T, |
| 4579 | E->getRParenLoc()); |
| 4580 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4581 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4582 | template<typename Derived> |
| 4583 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4584 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4585 | // Transform the type that we're allocating |
| 4586 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4587 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4588 | if (AllocType.isNull()) |
| 4589 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4590 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4591 | // Transform the size of the array we're allocating (if any). |
| 4592 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4593 | if (ArraySize.isInvalid()) |
| 4594 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4595 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4596 | // Transform the placement arguments (if any). |
| 4597 | bool ArgumentChanged = false; |
| 4598 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4599 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4600 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4601 | if (Arg.isInvalid()) |
| 4602 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4603 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4604 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4605 | PlacementArgs.push_back(Arg.take()); |
| 4606 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4607 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4608 | // transform the constructor arguments (if any). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4609 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4610 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4611 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4612 | if (Arg.isInvalid()) |
| 4613 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4614 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4615 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4616 | ConstructorArgs.push_back(Arg.take()); |
| 4617 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4618 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4619 | if (!getDerived().AlwaysRebuild() && |
| 4620 | AllocType == E->getAllocatedType() && |
| 4621 | ArraySize.get() == E->getArraySize() && |
| 4622 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4623 | return SemaRef.Owned(E->Retain()); |
| 4624 | |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 4625 | if (!ArraySize.get()) { |
| 4626 | // If no array size was specified, but the new expression was |
| 4627 | // instantiated with an array type (e.g., "new T" where T is |
| 4628 | // instantiated with "int[4]"), extract the outer bound from the |
| 4629 | // array type as our array size. We do this with constant and |
| 4630 | // dependently-sized array types. |
| 4631 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 4632 | if (!ArrayT) { |
| 4633 | // Do nothing |
| 4634 | } else if (const ConstantArrayType *ConsArrayT |
| 4635 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 4636 | ArraySize |
| 4637 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 4638 | ConsArrayT->getSize(), |
| 4639 | SemaRef.Context.getSizeType(), |
| 4640 | /*FIXME:*/E->getLocStart())); |
| 4641 | AllocType = ConsArrayT->getElementType(); |
| 4642 | } else if (const DependentSizedArrayType *DepArrayT |
| 4643 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 4644 | if (DepArrayT->getSizeExpr()) { |
| 4645 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 4646 | AllocType = DepArrayT->getElementType(); |
| 4647 | } |
| 4648 | } |
| 4649 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4650 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4651 | E->isGlobalNew(), |
| 4652 | /*FIXME:*/E->getLocStart(), |
| 4653 | move_arg(PlacementArgs), |
| 4654 | /*FIXME:*/E->getLocStart(), |
| 4655 | E->isParenTypeId(), |
| 4656 | AllocType, |
| 4657 | /*FIXME:*/E->getLocStart(), |
| 4658 | /*FIXME:*/SourceRange(), |
| 4659 | move(ArraySize), |
| 4660 | /*FIXME:*/E->getLocStart(), |
| 4661 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4662 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4663 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4664 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4665 | template<typename Derived> |
| 4666 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4667 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4668 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4669 | if (Operand.isInvalid()) |
| 4670 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4671 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4672 | if (!getDerived().AlwaysRebuild() && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4673 | Operand.get() == E->getArgument()) |
| 4674 | return SemaRef.Owned(E->Retain()); |
| 4675 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4676 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4677 | E->isGlobalDelete(), |
| 4678 | E->isArrayForm(), |
| 4679 | move(Operand)); |
| 4680 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4681 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4682 | template<typename Derived> |
| 4683 | Sema::OwningExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4684 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4685 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4686 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4687 | if (Base.isInvalid()) |
| 4688 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4689 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4690 | NestedNameSpecifier *Qualifier |
| 4691 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 4692 | E->getQualifierRange(), |
| 4693 | true); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4694 | if (E->getQualifier() && !Qualifier) |
| 4695 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4696 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4697 | QualType DestroyedType; |
| 4698 | { |
| 4699 | TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName()); |
| 4700 | DestroyedType = getDerived().TransformType(E->getDestroyedType()); |
| 4701 | if (DestroyedType.isNull()) |
| 4702 | return SemaRef.ExprError(); |
| 4703 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4704 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4705 | if (!getDerived().AlwaysRebuild() && |
| 4706 | Base.get() == E->getBase() && |
| 4707 | Qualifier == E->getQualifier() && |
| 4708 | DestroyedType == E->getDestroyedType()) |
| 4709 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4710 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4711 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4712 | E->getOperatorLoc(), |
| 4713 | E->isArrow(), |
| 4714 | E->getDestroyedTypeLoc(), |
| 4715 | DestroyedType, |
| 4716 | Qualifier, |
| 4717 | E->getQualifierRange()); |
| 4718 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4719 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4720 | template<typename Derived> |
| 4721 | Sema::OwningExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 4722 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4723 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4724 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 4725 | |
| 4726 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 4727 | Sema::LookupOrdinaryName); |
| 4728 | |
| 4729 | // Transform all the decls. |
| 4730 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 4731 | E = Old->decls_end(); I != E; ++I) { |
| 4732 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 4733 | if (!InstD) { |
| 4734 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 4735 | // This can happen because of dependent hiding. |
| 4736 | if (isa<UsingShadowDecl>(*I)) |
| 4737 | continue; |
| 4738 | else |
| 4739 | return SemaRef.ExprError(); |
| 4740 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4741 | |
| 4742 | // Expand using declarations. |
| 4743 | if (isa<UsingDecl>(InstD)) { |
| 4744 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 4745 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 4746 | E = UD->shadow_end(); I != E; ++I) |
| 4747 | R.addDecl(*I); |
| 4748 | continue; |
| 4749 | } |
| 4750 | |
| 4751 | R.addDecl(InstD); |
| 4752 | } |
| 4753 | |
| 4754 | // Resolve a kind, but don't do any further analysis. If it's |
| 4755 | // ambiguous, the callee needs to deal with it. |
| 4756 | R.resolveKind(); |
| 4757 | |
| 4758 | // Rebuild the nested-name qualifier, if present. |
| 4759 | CXXScopeSpec SS; |
| 4760 | NestedNameSpecifier *Qualifier = 0; |
| 4761 | if (Old->getQualifier()) { |
| 4762 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 4763 | Old->getQualifierRange(), |
| 4764 | false); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4765 | if (!Qualifier) |
| 4766 | return SemaRef.ExprError(); |
| 4767 | |
| 4768 | SS.setScopeRep(Qualifier); |
| 4769 | SS.setRange(Old->getQualifierRange()); |
| 4770 | } |
| 4771 | |
| 4772 | // If we have no template arguments, it's a normal declaration name. |
| 4773 | if (!Old->hasExplicitTemplateArgs()) |
| 4774 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 4775 | |
| 4776 | // If we have template arguments, rebuild them, then rebuild the |
| 4777 | // templateid expression. |
| 4778 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 4779 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 4780 | TemplateArgumentLoc Loc; |
| 4781 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 4782 | return SemaRef.ExprError(); |
| 4783 | TransArgs.addArgument(Loc); |
| 4784 | } |
| 4785 | |
| 4786 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 4787 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4788 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4789 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4790 | template<typename Derived> |
| 4791 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4792 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4793 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4794 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4795 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 4796 | if (T.isNull()) |
| 4797 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4798 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4799 | if (!getDerived().AlwaysRebuild() && |
| 4800 | T == E->getQueriedType()) |
| 4801 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4802 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4803 | // FIXME: Bad location information |
| 4804 | SourceLocation FakeLParenLoc |
| 4805 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4806 | |
| 4807 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4808 | E->getLocStart(), |
| 4809 | /*FIXME:*/FakeLParenLoc, |
| 4810 | T, |
| 4811 | E->getLocEnd()); |
| 4812 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4813 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4814 | template<typename Derived> |
| 4815 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4816 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4817 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4818 | NestedNameSpecifier *NNS |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4819 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 4820 | E->getQualifierRange(), |
| 4821 | false); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4822 | if (!NNS) |
| 4823 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4824 | |
| 4825 | DeclarationName Name |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4826 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 4827 | if (!Name) |
| 4828 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4829 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4830 | if (!E->hasExplicitTemplateArgs()) { |
| 4831 | if (!getDerived().AlwaysRebuild() && |
| 4832 | NNS == E->getQualifier() && |
| 4833 | Name == E->getDeclName()) |
| 4834 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4835 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4836 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4837 | E->getQualifierRange(), |
| 4838 | Name, E->getLocation(), |
| 4839 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4840 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4841 | |
| 4842 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4843 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4844 | TemplateArgumentLoc Loc; |
| 4845 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4846 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4847 | TransArgs.addArgument(Loc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4848 | } |
| 4849 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4850 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4851 | E->getQualifierRange(), |
| 4852 | Name, E->getLocation(), |
| 4853 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4854 | } |
| 4855 | |
| 4856 | template<typename Derived> |
| 4857 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4858 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 4859 | // CXXConstructExprs are always implicit, so when we have a |
| 4860 | // 1-argument construction we just transform that argument. |
| 4861 | if (E->getNumArgs() == 1 || |
| 4862 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 4863 | return getDerived().TransformExpr(E->getArg(0)); |
| 4864 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4865 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 4866 | |
| 4867 | QualType T = getDerived().TransformType(E->getType()); |
| 4868 | if (T.isNull()) |
| 4869 | return SemaRef.ExprError(); |
| 4870 | |
| 4871 | CXXConstructorDecl *Constructor |
| 4872 | = cast_or_null<CXXConstructorDecl>( |
| 4873 | getDerived().TransformDecl(E->getConstructor())); |
| 4874 | if (!Constructor) |
| 4875 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4876 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4877 | bool ArgumentChanged = false; |
| 4878 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4879 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4880 | ArgEnd = E->arg_end(); |
| 4881 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4882 | if (getDerived().DropCallArgument(*Arg)) { |
| 4883 | ArgumentChanged = true; |
| 4884 | break; |
| 4885 | } |
| 4886 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4887 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4888 | if (TransArg.isInvalid()) |
| 4889 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4890 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4891 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4892 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4893 | } |
| 4894 | |
| 4895 | if (!getDerived().AlwaysRebuild() && |
| 4896 | T == E->getType() && |
| 4897 | Constructor == E->getConstructor() && |
| 4898 | !ArgumentChanged) |
| 4899 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4900 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 4901 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 4902 | Constructor, E->isElidable(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4903 | move_arg(Args)); |
| 4904 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4905 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4906 | /// \brief Transform a C++ temporary-binding expression. |
| 4907 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4908 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 4909 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4910 | template<typename Derived> |
| 4911 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4912 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4913 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4914 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4915 | |
Anders Carlsson | ba6c437 | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 4916 | /// \brief Transform a C++ reference-binding expression. |
| 4917 | /// |
| 4918 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 4919 | /// transform the subexpression and return that. |
| 4920 | template<typename Derived> |
| 4921 | Sema::OwningExprResult |
| 4922 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 4923 | return getDerived().TransformExpr(E->getSubExpr()); |
| 4924 | } |
| 4925 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4926 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4927 | /// be destroyed after the expression is evaluated. |
| 4928 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4929 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 4930 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4931 | template<typename Derived> |
| 4932 | Sema::OwningExprResult |
| 4933 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4934 | CXXExprWithTemporaries *E) { |
| 4935 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4936 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4937 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4938 | template<typename Derived> |
| 4939 | Sema::OwningExprResult |
| 4940 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4941 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4942 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4943 | QualType T = getDerived().TransformType(E->getType()); |
| 4944 | if (T.isNull()) |
| 4945 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4946 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4947 | CXXConstructorDecl *Constructor |
| 4948 | = cast_or_null<CXXConstructorDecl>( |
| 4949 | getDerived().TransformDecl(E->getConstructor())); |
| 4950 | if (!Constructor) |
| 4951 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4952 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4953 | bool ArgumentChanged = false; |
| 4954 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4955 | Args.reserve(E->getNumArgs()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4956 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4957 | ArgEnd = E->arg_end(); |
| 4958 | Arg != ArgEnd; ++Arg) { |
| 4959 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4960 | if (TransArg.isInvalid()) |
| 4961 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4962 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4963 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4964 | Args.push_back((Expr *)TransArg.release()); |
| 4965 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4966 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4967 | if (!getDerived().AlwaysRebuild() && |
| 4968 | T == E->getType() && |
| 4969 | Constructor == E->getConstructor() && |
| 4970 | !ArgumentChanged) |
| 4971 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4972 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4973 | // FIXME: Bogus location information |
| 4974 | SourceLocation CommaLoc; |
| 4975 | if (Args.size() > 1) { |
| 4976 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4977 | CommaLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4978 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 4979 | } |
| 4980 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 4981 | T, |
| 4982 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4983 | move_arg(Args), |
| 4984 | &CommaLoc, |
| 4985 | E->getLocEnd()); |
| 4986 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4987 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4988 | template<typename Derived> |
| 4989 | Sema::OwningExprResult |
| 4990 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4991 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4992 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4993 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 4994 | if (T.isNull()) |
| 4995 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4996 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4997 | bool ArgumentChanged = false; |
| 4998 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4999 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 5000 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 5001 | ArgEnd = E->arg_end(); |
| 5002 | Arg != ArgEnd; ++Arg) { |
| 5003 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5004 | if (TransArg.isInvalid()) |
| 5005 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5006 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5007 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5008 | FakeCommaLocs.push_back( |
| 5009 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 5010 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5011 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5012 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5013 | if (!getDerived().AlwaysRebuild() && |
| 5014 | T == E->getTypeAsWritten() && |
| 5015 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5016 | return SemaRef.Owned(E->Retain()); |
| 5017 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5018 | // FIXME: we're faking the locations of the commas |
| 5019 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5020 | T, |
| 5021 | E->getLParenLoc(), |
| 5022 | move_arg(Args), |
| 5023 | FakeCommaLocs.data(), |
| 5024 | E->getRParenLoc()); |
| 5025 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5026 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5027 | template<typename Derived> |
| 5028 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5029 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5030 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5031 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5032 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5033 | Expr *OldBase; |
| 5034 | QualType BaseType; |
| 5035 | QualType ObjectType; |
| 5036 | if (!E->isImplicitAccess()) { |
| 5037 | OldBase = E->getBase(); |
| 5038 | Base = getDerived().TransformExpr(OldBase); |
| 5039 | if (Base.isInvalid()) |
| 5040 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5041 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5042 | // Start the member reference and compute the object's type. |
| 5043 | Sema::TypeTy *ObjectTy = 0; |
| 5044 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5045 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5046 | E->isArrow()? tok::arrow : tok::period, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5047 | ObjectTy); |
| 5048 | if (Base.isInvalid()) |
| 5049 | return SemaRef.ExprError(); |
| 5050 | |
| 5051 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5052 | BaseType = ((Expr*) Base.get())->getType(); |
| 5053 | } else { |
| 5054 | OldBase = 0; |
| 5055 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5056 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5057 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5058 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5059 | // Transform the first part of the nested-name-specifier that qualifies |
| 5060 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5061 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5062 | = getDerived().TransformFirstQualifierInScope( |
| 5063 | E->getFirstQualifierFoundInScope(), |
| 5064 | E->getQualifierRange().getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5065 | |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5066 | NestedNameSpecifier *Qualifier = 0; |
| 5067 | if (E->getQualifier()) { |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 5068 | bool MayBePseudoDestructor |
| 5069 | = E->getMember().getNameKind() == DeclarationName::CXXDestructorName; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5070 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5071 | E->getQualifierRange(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 5072 | MayBePseudoDestructor, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5073 | ObjectType, |
| 5074 | FirstQualifierInScope); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5075 | if (!Qualifier) |
| 5076 | return SemaRef.ExprError(); |
| 5077 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5078 | |
| 5079 | DeclarationName Name |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5080 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5081 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5082 | if (!Name) |
| 5083 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5084 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5085 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5086 | // This is a reference to a member without an explicitly-specified |
| 5087 | // template argument list. Optimize for this common case. |
| 5088 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5089 | Base.get() == OldBase && |
| 5090 | BaseType == E->getBaseType() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5091 | Qualifier == E->getQualifier() && |
| 5092 | Name == E->getMember() && |
| 5093 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5094 | return SemaRef.Owned(E->Retain()); |
| 5095 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5096 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5097 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5098 | E->isArrow(), |
| 5099 | E->getOperatorLoc(), |
| 5100 | Qualifier, |
| 5101 | E->getQualifierRange(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5102 | FirstQualifierInScope, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5103 | Name, |
| 5104 | E->getMemberLoc(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5105 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5106 | } |
| 5107 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5108 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5109 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5110 | TemplateArgumentLoc Loc; |
| 5111 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5112 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5113 | TransArgs.addArgument(Loc); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5114 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5115 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5116 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5117 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5118 | E->isArrow(), |
| 5119 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5120 | Qualifier, |
| 5121 | E->getQualifierRange(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5122 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5123 | Name, |
| 5124 | E->getMemberLoc(), |
| 5125 | &TransArgs); |
| 5126 | } |
| 5127 | |
| 5128 | template<typename Derived> |
| 5129 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5130 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5131 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5132 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5133 | QualType BaseType; |
| 5134 | if (!Old->isImplicitAccess()) { |
| 5135 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5136 | if (Base.isInvalid()) |
| 5137 | return SemaRef.ExprError(); |
| 5138 | BaseType = ((Expr*) Base.get())->getType(); |
| 5139 | } else { |
| 5140 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5141 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5142 | |
| 5143 | NestedNameSpecifier *Qualifier = 0; |
| 5144 | if (Old->getQualifier()) { |
| 5145 | Qualifier |
| 5146 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 5147 | Old->getQualifierRange(), |
| 5148 | false); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5149 | if (Qualifier == 0) |
| 5150 | return SemaRef.ExprError(); |
| 5151 | } |
| 5152 | |
| 5153 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5154 | Sema::LookupOrdinaryName); |
| 5155 | |
| 5156 | // Transform all the decls. |
| 5157 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5158 | E = Old->decls_end(); I != E; ++I) { |
| 5159 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5160 | if (!InstD) { |
| 5161 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5162 | // This can happen because of dependent hiding. |
| 5163 | if (isa<UsingShadowDecl>(*I)) |
| 5164 | continue; |
| 5165 | else |
| 5166 | return SemaRef.ExprError(); |
| 5167 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5168 | |
| 5169 | // Expand using declarations. |
| 5170 | if (isa<UsingDecl>(InstD)) { |
| 5171 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5172 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5173 | E = UD->shadow_end(); I != E; ++I) |
| 5174 | R.addDecl(*I); |
| 5175 | continue; |
| 5176 | } |
| 5177 | |
| 5178 | R.addDecl(InstD); |
| 5179 | } |
| 5180 | |
| 5181 | R.resolveKind(); |
| 5182 | |
| 5183 | TemplateArgumentListInfo TransArgs; |
| 5184 | if (Old->hasExplicitTemplateArgs()) { |
| 5185 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5186 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5187 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5188 | TemplateArgumentLoc Loc; |
| 5189 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5190 | Loc)) |
| 5191 | return SemaRef.ExprError(); |
| 5192 | TransArgs.addArgument(Loc); |
| 5193 | } |
| 5194 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5195 | |
| 5196 | // FIXME: to do this check properly, we will need to preserve the |
| 5197 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5198 | // base (and therefore couldn't do the check) and a |
| 5199 | // nested-name-qualifier (and therefore could do the lookup). |
| 5200 | NamedDecl *FirstQualifierInScope = 0; |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5201 | |
| 5202 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5203 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5204 | Old->getOperatorLoc(), |
| 5205 | Old->isArrow(), |
| 5206 | Qualifier, |
| 5207 | Old->getQualifierRange(), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5208 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5209 | R, |
| 5210 | (Old->hasExplicitTemplateArgs() |
| 5211 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5212 | } |
| 5213 | |
| 5214 | template<typename Derived> |
| 5215 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5216 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5217 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5218 | } |
| 5219 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5220 | template<typename Derived> |
| 5221 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5222 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5223 | // FIXME: poor source location |
| 5224 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 5225 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 5226 | if (EncodedType.isNull()) |
| 5227 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5228 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5229 | if (!getDerived().AlwaysRebuild() && |
| 5230 | EncodedType == E->getEncodedType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5231 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5232 | |
| 5233 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 5234 | EncodedType, |
| 5235 | E->getRParenLoc()); |
| 5236 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5237 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5238 | template<typename Derived> |
| 5239 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5240 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5241 | // FIXME: Implement this! |
| 5242 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5243 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5244 | } |
| 5245 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5246 | template<typename Derived> |
| 5247 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5248 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5249 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5250 | } |
| 5251 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5252 | template<typename Derived> |
| 5253 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5254 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5255 | ObjCProtocolDecl *Protocol |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5256 | = cast_or_null<ObjCProtocolDecl>( |
| 5257 | getDerived().TransformDecl(E->getProtocol())); |
| 5258 | if (!Protocol) |
| 5259 | return SemaRef.ExprError(); |
| 5260 | |
| 5261 | if (!getDerived().AlwaysRebuild() && |
| 5262 | Protocol == E->getProtocol()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5263 | return SemaRef.Owned(E->Retain()); |
| 5264 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5265 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 5266 | E->getAtLoc(), |
| 5267 | /*FIXME:*/E->getAtLoc(), |
| 5268 | /*FIXME:*/E->getAtLoc(), |
| 5269 | E->getRParenLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5270 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5271 | } |
| 5272 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5273 | template<typename Derived> |
| 5274 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5275 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5276 | // FIXME: Implement this! |
| 5277 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5278 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5279 | } |
| 5280 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5281 | template<typename Derived> |
| 5282 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5283 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5284 | // FIXME: Implement this! |
| 5285 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5286 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5287 | } |
| 5288 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5289 | template<typename Derived> |
| 5290 | Sema::OwningExprResult |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5291 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5292 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5293 | // FIXME: Implement this! |
| 5294 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5295 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5296 | } |
| 5297 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5298 | template<typename Derived> |
| 5299 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5300 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5301 | // FIXME: Implement this! |
| 5302 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5303 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5304 | } |
| 5305 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5306 | template<typename Derived> |
| 5307 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5308 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5309 | // FIXME: Implement this! |
| 5310 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5311 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5312 | } |
| 5313 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5314 | template<typename Derived> |
| 5315 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5316 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5317 | bool ArgumentChanged = false; |
| 5318 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5319 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5320 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5321 | if (SubExpr.isInvalid()) |
| 5322 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5323 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5324 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5325 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5326 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5327 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5328 | if (!getDerived().AlwaysRebuild() && |
| 5329 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5330 | return SemaRef.Owned(E->Retain()); |
| 5331 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5332 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5333 | move_arg(SubExprs), |
| 5334 | E->getRParenLoc()); |
| 5335 | } |
| 5336 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5337 | template<typename Derived> |
| 5338 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5339 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5340 | // FIXME: Implement this! |
| 5341 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5342 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5343 | } |
| 5344 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5345 | template<typename Derived> |
| 5346 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5347 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5348 | // FIXME: Implement this! |
| 5349 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5350 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5351 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5352 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5353 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5354 | // Type reconstruction |
| 5355 | //===----------------------------------------------------------------------===// |
| 5356 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5357 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5358 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5359 | SourceLocation Star) { |
| 5360 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5361 | getDerived().getBaseEntity()); |
| 5362 | } |
| 5363 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5364 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5365 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5366 | SourceLocation Star) { |
| 5367 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5368 | getDerived().getBaseEntity()); |
| 5369 | } |
| 5370 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5371 | template<typename Derived> |
| 5372 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5373 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5374 | bool WrittenAsLValue, |
| 5375 | SourceLocation Sigil) { |
| 5376 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5377 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5378 | } |
| 5379 | |
| 5380 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5381 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5382 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5383 | QualType ClassType, |
| 5384 | SourceLocation Sigil) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5385 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5386 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5387 | } |
| 5388 | |
| 5389 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5390 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5391 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType, |
| 5392 | SourceLocation Sigil) { |
| 5393 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5394 | getDerived().getBaseEntity()); |
| 5395 | } |
| 5396 | |
| 5397 | template<typename Derived> |
| 5398 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5399 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5400 | ArrayType::ArraySizeModifier SizeMod, |
| 5401 | const llvm::APInt *Size, |
| 5402 | Expr *SizeExpr, |
| 5403 | unsigned IndexTypeQuals, |
| 5404 | SourceRange BracketsRange) { |
| 5405 | if (SizeExpr || !Size) |
| 5406 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5407 | IndexTypeQuals, BracketsRange, |
| 5408 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5409 | |
| 5410 | QualType Types[] = { |
| 5411 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5412 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5413 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5414 | }; |
| 5415 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5416 | QualType SizeType; |
| 5417 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5418 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5419 | SizeType = Types[I]; |
| 5420 | break; |
| 5421 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5422 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5423 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5424 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5425 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5426 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5427 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5428 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5429 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5430 | QualType |
| 5431 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5432 | ArrayType::ArraySizeModifier SizeMod, |
| 5433 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5434 | unsigned IndexTypeQuals, |
| 5435 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5436 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5437 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5438 | } |
| 5439 | |
| 5440 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5441 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5442 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5443 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5444 | unsigned IndexTypeQuals, |
| 5445 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5446 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5447 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5448 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5449 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5450 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5451 | QualType |
| 5452 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5453 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5454 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5455 | unsigned IndexTypeQuals, |
| 5456 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5457 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5458 | SizeExpr.takeAs<Expr>(), |
| 5459 | IndexTypeQuals, BracketsRange); |
| 5460 | } |
| 5461 | |
| 5462 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5463 | QualType |
| 5464 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5465 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5466 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5467 | unsigned IndexTypeQuals, |
| 5468 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5469 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5470 | SizeExpr.takeAs<Expr>(), |
| 5471 | IndexTypeQuals, BracketsRange); |
| 5472 | } |
| 5473 | |
| 5474 | template<typename Derived> |
| 5475 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5476 | unsigned NumElements, |
| 5477 | bool IsAltiVec, bool IsPixel) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5478 | // FIXME: semantic checking! |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5479 | return SemaRef.Context.getVectorType(ElementType, NumElements, |
| 5480 | IsAltiVec, IsPixel); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5481 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5482 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5483 | template<typename Derived> |
| 5484 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5485 | unsigned NumElements, |
| 5486 | SourceLocation AttributeLoc) { |
| 5487 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5488 | NumElements, true); |
| 5489 | IntegerLiteral *VectorSize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5490 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5491 | AttributeLoc); |
| 5492 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5493 | AttributeLoc); |
| 5494 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5495 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5496 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5497 | QualType |
| 5498 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5499 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5500 | SourceLocation AttributeLoc) { |
| 5501 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5502 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5503 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5504 | template<typename Derived> |
| 5505 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5506 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5507 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5508 | bool Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5509 | unsigned Quals) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5510 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5511 | Quals, |
| 5512 | getDerived().getBaseLocation(), |
| 5513 | getDerived().getBaseEntity()); |
| 5514 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5515 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5516 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5517 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5518 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5519 | } |
| 5520 | |
| 5521 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5522 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 5523 | assert(D && "no decl found"); |
| 5524 | if (D->isInvalidDecl()) return QualType(); |
| 5525 | |
| 5526 | TypeDecl *Ty; |
| 5527 | if (isa<UsingDecl>(D)) { |
| 5528 | UsingDecl *Using = cast<UsingDecl>(D); |
| 5529 | assert(Using->isTypeName() && |
| 5530 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 5531 | |
| 5532 | // A valid resolved using typename decl points to exactly one type decl. |
| 5533 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 5534 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 5535 | |
| 5536 | } else { |
| 5537 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 5538 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 5539 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 5540 | } |
| 5541 | |
| 5542 | return SemaRef.Context.getTypeDeclType(Ty); |
| 5543 | } |
| 5544 | |
| 5545 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5546 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5547 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5548 | } |
| 5549 | |
| 5550 | template<typename Derived> |
| 5551 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5552 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5553 | } |
| 5554 | |
| 5555 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5556 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5557 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5558 | } |
| 5559 | |
| 5560 | template<typename Derived> |
| 5561 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5562 | TemplateName Template, |
| 5563 | SourceLocation TemplateNameLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5564 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5565 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5566 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5567 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5568 | template<typename Derived> |
| 5569 | NestedNameSpecifier * |
| 5570 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5571 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5572 | IdentifierInfo &II, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 5573 | bool MayBePseudoDestructor, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5574 | QualType ObjectType, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5575 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5576 | CXXScopeSpec SS; |
| 5577 | // FIXME: The source location information is all wrong. |
| 5578 | SS.setRange(Range); |
| 5579 | SS.setScopeRep(Prefix); |
| 5580 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5581 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | e861bac | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5582 | Range.getEnd(), II, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 5583 | MayBePseudoDestructor, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5584 | ObjectType, |
| 5585 | FirstQualifierInScope, |
Chris Lattner | 1c42803 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 5586 | false, false)); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5587 | } |
| 5588 | |
| 5589 | template<typename Derived> |
| 5590 | NestedNameSpecifier * |
| 5591 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5592 | SourceRange Range, |
| 5593 | NamespaceDecl *NS) { |
| 5594 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5595 | } |
| 5596 | |
| 5597 | template<typename Derived> |
| 5598 | NestedNameSpecifier * |
| 5599 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5600 | SourceRange Range, |
| 5601 | bool TemplateKW, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame^] | 5602 | QualType T, |
| 5603 | bool MayBePseudoDestructor) { |
| 5604 | if (MayBePseudoDestructor || T->isDependentType() || T->isRecordType() || |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5605 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5606 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5607 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5608 | T.getTypePtr()); |
| 5609 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5610 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5611 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5612 | return 0; |
| 5613 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5614 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5615 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5616 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5617 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5618 | bool TemplateKW, |
| 5619 | TemplateDecl *Template) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5620 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5621 | Template); |
| 5622 | } |
| 5623 | |
| 5624 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5625 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5626 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5627 | const IdentifierInfo &II, |
| 5628 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5629 | CXXScopeSpec SS; |
| 5630 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5631 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5632 | UnqualifiedId Name; |
| 5633 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5634 | return getSema().ActOnDependentTemplateName( |
| 5635 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5636 | SS, |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5637 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5638 | ObjectType.getAsOpaquePtr(), |
| 5639 | /*EnteringContext=*/false) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5640 | .template getAsVal<TemplateName>(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5641 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5642 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5643 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5644 | TemplateName |
| 5645 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5646 | OverloadedOperatorKind Operator, |
| 5647 | QualType ObjectType) { |
| 5648 | CXXScopeSpec SS; |
| 5649 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5650 | SS.setScopeRep(Qualifier); |
| 5651 | UnqualifiedId Name; |
| 5652 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5653 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5654 | Operator, SymbolLocations); |
| 5655 | return getSema().ActOnDependentTemplateName( |
| 5656 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5657 | SS, |
| 5658 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5659 | ObjectType.getAsOpaquePtr(), |
| 5660 | /*EnteringContext=*/false) |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5661 | .template getAsVal<TemplateName>(); |
| 5662 | } |
| 5663 | |
| 5664 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5665 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5666 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5667 | SourceLocation OpLoc, |
| 5668 | ExprArg Callee, |
| 5669 | ExprArg First, |
| 5670 | ExprArg Second) { |
| 5671 | Expr *FirstExpr = (Expr *)First.get(); |
| 5672 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5673 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5674 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5675 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5676 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5677 | if (Op == OO_Subscript) { |
| 5678 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5679 | !SecondExpr->getType()->isOverloadableType()) |
| 5680 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5681 | CalleeExpr->getLocStart(), |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5682 | move(Second), OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 5683 | } else if (Op == OO_Arrow) { |
| 5684 | // -> is never a builtin operation. |
| 5685 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5686 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5687 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5688 | // The argument is not of overloadable type, so try to create a |
| 5689 | // built-in unary operation. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5690 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5691 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5692 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5693 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5694 | } |
| 5695 | } else { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5696 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5697 | !SecondExpr->getType()->isOverloadableType()) { |
| 5698 | // Neither of the arguments is an overloadable type, so try to |
| 5699 | // create a built-in binary operation. |
| 5700 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5701 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5702 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5703 | if (Result.isInvalid()) |
| 5704 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5705 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5706 | First.release(); |
| 5707 | Second.release(); |
| 5708 | return move(Result); |
| 5709 | } |
| 5710 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5711 | |
| 5712 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5713 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5714 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5715 | |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5716 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 5717 | assert(ULE->requiresADL()); |
| 5718 | |
| 5719 | // FIXME: Do we have to check |
| 5720 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5721 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5722 | } else { |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5723 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5724 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5725 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5726 | // Add any functions found via argument-dependent lookup. |
| 5727 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5728 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5729 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5730 | // Create the overloaded operator invocation for unary operators. |
| 5731 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5732 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5733 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5734 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5735 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5736 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5737 | if (Op == OO_Subscript) |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5738 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 5739 | OpLoc, |
| 5740 | move(First), |
| 5741 | move(Second)); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5742 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5743 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5744 | BinaryOperator::Opcode Opc = |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5745 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5746 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5747 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5748 | if (Result.isInvalid()) |
| 5749 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5750 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5751 | First.release(); |
| 5752 | Second.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5753 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5754 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5755 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5756 | } // end namespace clang |
| 5757 | |
| 5758 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |