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. |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 240 | Decl *TransformDecl(SourceLocation Loc, 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. |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 246 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 247 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 248 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 249 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 250 | /// \brief Transform the given declaration, which was the first part of a |
| 251 | /// nested-name-specifier in a member access expression. |
| 252 | /// |
| 253 | /// This specific declaration transformation only applies to the first |
| 254 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 255 | /// the \c T in \c x->T::member |
| 256 | /// |
| 257 | /// By default, invokes TransformDecl() to transform the declaration. |
| 258 | /// Subclasses may override this function to provide alternate behavior. |
| 259 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 260 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 263 | /// \brief Transform the given nested-name-specifier. |
| 264 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 265 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 266 | /// nested-name-specifier. Subclasses may override this function to provide |
| 267 | /// alternate behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 268 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 269 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 270 | QualType ObjectType = QualType(), |
| 271 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 272 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 273 | /// \brief Transform the given declaration name. |
| 274 | /// |
| 275 | /// By default, transforms the types of conversion function, constructor, |
| 276 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 277 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 278 | /// override this function to provide alternate behavior. |
| 279 | DeclarationName TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 280 | SourceLocation Loc, |
| 281 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 283 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 284 | /// |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 285 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 286 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 287 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 288 | TemplateName TransformTemplateName(TemplateName Name, |
| 289 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 290 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 291 | /// \brief Transform the given template argument. |
| 292 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 293 | /// By default, this operation transforms the type, expression, or |
| 294 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 295 | /// new template argument from the transformed result. Subclasses may |
| 296 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 297 | /// |
| 298 | /// Returns true if there was an error. |
| 299 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 300 | TemplateArgumentLoc &Output); |
| 301 | |
| 302 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 303 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 304 | TemplateArgumentLoc &ArgLoc); |
| 305 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 306 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 307 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 308 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 309 | getDerived().getBaseLocation()); |
| 310 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 311 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 312 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 313 | #define TYPELOC(CLASS, PARENT) \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 314 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \ |
| 315 | QualType ObjectType = QualType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 316 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 317 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 318 | /// \brief Transforms the parameters of a function type into the |
| 319 | /// given vectors. |
| 320 | /// |
| 321 | /// The result vectors should be kept in sync; null entries in the |
| 322 | /// variables vector are acceptable. |
| 323 | /// |
| 324 | /// Return true on error. |
| 325 | bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 326 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 327 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars); |
| 328 | |
| 329 | /// \brief Transforms a single function-type parameter. Return null |
| 330 | /// on error. |
| 331 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm); |
| 332 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 333 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL, |
| 334 | QualType ObjectType); |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 335 | |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 336 | QualType |
| 337 | TransformTemplateSpecializationType(const TemplateSpecializationType *T, |
| 338 | QualType ObjectType); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 339 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 340 | OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
Zhongxing Xu | 105dfb5 | 2010-04-21 06:32:25 +0000 | [diff] [blame] | 341 | OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 342 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 343 | #define STMT(Node, Parent) \ |
| 344 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 345 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 346 | OwningExprResult Transform##Node(Node *E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 347 | #define ABSTRACT_EXPR(Node, Parent) |
| 348 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 349 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 350 | /// \brief Build a new pointer type given its pointee type. |
| 351 | /// |
| 352 | /// By default, performs semantic analysis when building the pointer type. |
| 353 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 354 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 355 | |
| 356 | /// \brief Build a new block pointer type given its pointee type. |
| 357 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 358 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 359 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 360 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 361 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 362 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 363 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 364 | /// By default, performs semantic analysis when building the |
| 365 | /// reference type. Subclasses may override this routine to provide |
| 366 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 367 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 368 | /// \param LValue whether the type was written with an lvalue sigil |
| 369 | /// or an rvalue sigil. |
| 370 | QualType RebuildReferenceType(QualType ReferentType, |
| 371 | bool LValue, |
| 372 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 373 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 374 | /// \brief Build a new member pointer type given the pointee type and the |
| 375 | /// class type it refers into. |
| 376 | /// |
| 377 | /// By default, performs semantic analysis when building the member pointer |
| 378 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 379 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 380 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 382 | /// \brief Build a new array type given the element type, size |
| 383 | /// modifier, size of the array (if known), size expression, and index type |
| 384 | /// 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 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 389 | QualType RebuildArrayType(QualType ElementType, |
| 390 | ArrayType::ArraySizeModifier SizeMod, |
| 391 | const llvm::APInt *Size, |
| 392 | Expr *SizeExpr, |
| 393 | unsigned IndexTypeQuals, |
| 394 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 395 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 396 | /// \brief Build a new constant array type given the element type, size |
| 397 | /// modifier, (known) size of the array, and index type qualifiers. |
| 398 | /// |
| 399 | /// By default, performs semantic analysis when building the array type. |
| 400 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 401 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 402 | ArrayType::ArraySizeModifier SizeMod, |
| 403 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 404 | unsigned IndexTypeQuals, |
| 405 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 406 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 407 | /// \brief Build a new incomplete array type given the element type, size |
| 408 | /// modifier, and index type qualifiers. |
| 409 | /// |
| 410 | /// By default, performs semantic analysis when building the array type. |
| 411 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 412 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 413 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 414 | unsigned IndexTypeQuals, |
| 415 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 416 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 417 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 418 | /// size modifier, size expression, and index type qualifiers. |
| 419 | /// |
| 420 | /// By default, performs semantic analysis when building the array type. |
| 421 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 422 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 423 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 424 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 425 | unsigned IndexTypeQuals, |
| 426 | SourceRange BracketsRange); |
| 427 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 428 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 429 | /// size modifier, size expression, and index type qualifiers. |
| 430 | /// |
| 431 | /// By default, performs semantic analysis when building the array type. |
| 432 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 433 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 434 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 435 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 436 | unsigned IndexTypeQuals, |
| 437 | SourceRange BracketsRange); |
| 438 | |
| 439 | /// \brief Build a new vector type given the element type and |
| 440 | /// number of elements. |
| 441 | /// |
| 442 | /// By default, performs semantic analysis when building the vector type. |
| 443 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 444 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
| 445 | bool IsAltiVec, bool IsPixel); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 447 | /// \brief Build a new extended vector type given the element type and |
| 448 | /// number of elements. |
| 449 | /// |
| 450 | /// By default, performs semantic analysis when building the vector type. |
| 451 | /// Subclasses may override this routine to provide different behavior. |
| 452 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 453 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 454 | |
| 455 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 456 | /// given the element type and number of elements. |
| 457 | /// |
| 458 | /// By default, performs semantic analysis when building the vector type. |
| 459 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 460 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 461 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 462 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 463 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 464 | /// \brief Build a new function type. |
| 465 | /// |
| 466 | /// By default, performs semantic analysis when building the function type. |
| 467 | /// Subclasses may override this routine to provide different behavior. |
| 468 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 469 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 470 | unsigned NumParamTypes, |
| 471 | bool Variadic, unsigned Quals); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 472 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 473 | /// \brief Build a new unprototyped function type. |
| 474 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 475 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 476 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 477 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 478 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 479 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 480 | /// \brief Build a new typedef type. |
| 481 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 482 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 483 | } |
| 484 | |
| 485 | /// \brief Build a new class/struct/union type. |
| 486 | QualType RebuildRecordType(RecordDecl *Record) { |
| 487 | return SemaRef.Context.getTypeDeclType(Record); |
| 488 | } |
| 489 | |
| 490 | /// \brief Build a new Enum type. |
| 491 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 492 | return SemaRef.Context.getTypeDeclType(Enum); |
| 493 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 494 | |
| 495 | /// \brief Build a new elaborated type. |
| 496 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) { |
| 497 | return SemaRef.Context.getElaboratedType(T, Tag); |
| 498 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 499 | |
| 500 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 501 | /// |
| 502 | /// By default, performs semantic analysis when building the typeof type. |
| 503 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 504 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 505 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 506 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 507 | /// |
| 508 | /// By default, builds a new TypeOfType with the given underlying type. |
| 509 | QualType RebuildTypeOfType(QualType Underlying); |
| 510 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 512 | /// |
| 513 | /// By default, performs semantic analysis when building the decltype type. |
| 514 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 515 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 516 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 517 | /// \brief Build a new template specialization type. |
| 518 | /// |
| 519 | /// By default, performs semantic analysis when building the template |
| 520 | /// specialization type. Subclasses may override this routine to provide |
| 521 | /// different behavior. |
| 522 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 523 | SourceLocation TemplateLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 524 | const TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 525 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 526 | /// \brief Build a new qualified name type. |
| 527 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 | /// By default, builds a new QualifiedNameType type from the |
| 529 | /// nested-name-specifier and the named type. Subclasses may override |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 530 | /// this routine to provide different behavior. |
| 531 | QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) { |
| 532 | return SemaRef.Context.getQualifiedNameType(NNS, Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 533 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 534 | |
| 535 | /// \brief Build a new typename type that refers to a template-id. |
| 536 | /// |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 537 | /// By default, builds a new DependentNameType type from the |
| 538 | /// nested-name-specifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 540 | /// different behavior. |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 541 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
| 542 | NestedNameSpecifier *NNS, QualType T) { |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 543 | if (NNS->isDependent()) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 544 | // If the name is still dependent, just build a new dependent name type. |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 545 | CXXScopeSpec SS; |
| 546 | SS.setScopeRep(NNS); |
| 547 | if (!SemaRef.computeDeclContext(SS)) |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 548 | return SemaRef.Context.getDependentNameType(Keyword, NNS, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 549 | cast<TemplateSpecializationType>(T)); |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 550 | } |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 551 | |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 552 | // FIXME: Handle elaborated-type-specifiers separately. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 553 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 554 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 555 | |
| 556 | /// \brief Build a new typename type that refers to an identifier. |
| 557 | /// |
| 558 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 559 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 560 | /// different behavior. |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 561 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
| 562 | NestedNameSpecifier *NNS, |
| 563 | const IdentifierInfo *Id, |
| 564 | SourceRange SR) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 565 | CXXScopeSpec SS; |
| 566 | SS.setScopeRep(NNS); |
| 567 | |
| 568 | if (NNS->isDependent()) { |
| 569 | // If the name is still dependent, just build a new dependent name type. |
| 570 | if (!SemaRef.computeDeclContext(SS)) |
| 571 | return SemaRef.Context.getDependentNameType(Keyword, NNS, Id); |
| 572 | } |
| 573 | |
| 574 | TagDecl::TagKind Kind = TagDecl::TK_enum; |
| 575 | switch (Keyword) { |
| 576 | case ETK_None: |
| 577 | // FIXME: Note the lack of the "typename" specifier! |
| 578 | // Fall through |
| 579 | case ETK_Typename: |
| 580 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
| 581 | |
| 582 | case ETK_Class: Kind = TagDecl::TK_class; break; |
| 583 | case ETK_Struct: Kind = TagDecl::TK_struct; break; |
| 584 | case ETK_Union: Kind = TagDecl::TK_union; break; |
| 585 | case ETK_Enum: Kind = TagDecl::TK_enum; break; |
| 586 | } |
| 587 | |
| 588 | // We had a dependent elaborated-type-specifier that as been transformed |
| 589 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 590 | // referring to. |
| 591 | LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName); |
| 592 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 593 | if (!DC) |
| 594 | return QualType(); |
| 595 | |
| 596 | TagDecl *Tag = 0; |
| 597 | SemaRef.LookupQualifiedName(Result, DC); |
| 598 | switch (Result.getResultKind()) { |
| 599 | case LookupResult::NotFound: |
| 600 | case LookupResult::NotFoundInCurrentInstantiation: |
| 601 | break; |
| 602 | |
| 603 | case LookupResult::Found: |
| 604 | Tag = Result.getAsSingle<TagDecl>(); |
| 605 | break; |
| 606 | |
| 607 | case LookupResult::FoundOverloaded: |
| 608 | case LookupResult::FoundUnresolvedValue: |
| 609 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 610 | return QualType(); |
| 611 | |
| 612 | case LookupResult::Ambiguous: |
| 613 | // Let the LookupResult structure handle ambiguities. |
| 614 | return QualType(); |
| 615 | } |
| 616 | |
| 617 | if (!Tag) { |
Douglas Gregor | f5af358 | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 618 | // FIXME: Would be nice to highlight just the source range. |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 619 | SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope) |
Douglas Gregor | f5af358 | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 620 | << Kind << Id << DC; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 621 | return QualType(); |
| 622 | } |
| 623 | |
| 624 | // FIXME: Terrible location information |
| 625 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) { |
| 626 | SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id; |
| 627 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 628 | return QualType(); |
| 629 | } |
| 630 | |
| 631 | // Build the elaborated-type-specifier type. |
| 632 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
| 633 | T = SemaRef.Context.getQualifiedNameType(NNS, T); |
| 634 | return SemaRef.Context.getElaboratedType(T, Kind); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 635 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 636 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 637 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 638 | /// identifier that names the next step in the nested-name-specifier. |
| 639 | /// |
| 640 | /// By default, performs semantic analysis when building the new |
| 641 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 642 | /// different behavior. |
| 643 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 644 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 645 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 646 | QualType ObjectType, |
| 647 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 648 | |
| 649 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 650 | /// namespace named in the next step in the nested-name-specifier. |
| 651 | /// |
| 652 | /// By default, performs semantic analysis when building the new |
| 653 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 654 | /// different behavior. |
| 655 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 656 | SourceRange Range, |
| 657 | NamespaceDecl *NS); |
| 658 | |
| 659 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 660 | /// type named in the next step in the nested-name-specifier. |
| 661 | /// |
| 662 | /// By default, performs semantic analysis when building the new |
| 663 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 664 | /// different behavior. |
| 665 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 666 | SourceRange Range, |
| 667 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 668 | QualType T); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 669 | |
| 670 | /// \brief Build a new template name given a nested name specifier, a flag |
| 671 | /// indicating whether the "template" keyword was provided, and the template |
| 672 | /// that the template name refers to. |
| 673 | /// |
| 674 | /// By default, builds the new template name directly. Subclasses may override |
| 675 | /// this routine to provide different behavior. |
| 676 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 677 | bool TemplateKW, |
| 678 | TemplateDecl *Template); |
| 679 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 680 | /// \brief Build a new template name given a nested name specifier and the |
| 681 | /// name that is referred to as a template. |
| 682 | /// |
| 683 | /// By default, performs semantic analysis to determine whether the name can |
| 684 | /// be resolved to a specific template, then builds the appropriate kind of |
| 685 | /// template name. Subclasses may override this routine to provide different |
| 686 | /// behavior. |
| 687 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 688 | const IdentifierInfo &II, |
| 689 | QualType ObjectType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 690 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 691 | /// \brief Build a new template name given a nested name specifier and the |
| 692 | /// overloaded operator name that is referred to as a template. |
| 693 | /// |
| 694 | /// By default, performs semantic analysis to determine whether the name can |
| 695 | /// be resolved to a specific template, then builds the appropriate kind of |
| 696 | /// template name. Subclasses may override this routine to provide different |
| 697 | /// behavior. |
| 698 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 699 | OverloadedOperatorKind Operator, |
| 700 | QualType ObjectType); |
| 701 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 702 | /// \brief Build a new compound statement. |
| 703 | /// |
| 704 | /// By default, performs semantic analysis to build the new statement. |
| 705 | /// Subclasses may override this routine to provide different behavior. |
| 706 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 707 | MultiStmtArg Statements, |
| 708 | SourceLocation RBraceLoc, |
| 709 | bool IsStmtExpr) { |
| 710 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 711 | IsStmtExpr); |
| 712 | } |
| 713 | |
| 714 | /// \brief Build a new case statement. |
| 715 | /// |
| 716 | /// By default, performs semantic analysis to build the new statement. |
| 717 | /// Subclasses may override this routine to provide different behavior. |
| 718 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 719 | ExprArg LHS, |
| 720 | SourceLocation EllipsisLoc, |
| 721 | ExprArg RHS, |
| 722 | SourceLocation ColonLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 723 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 724 | ColonLoc); |
| 725 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 726 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 727 | /// \brief Attach the body to a new case statement. |
| 728 | /// |
| 729 | /// By default, performs semantic analysis to build the new statement. |
| 730 | /// Subclasses may override this routine to provide different behavior. |
| 731 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 732 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 733 | return move(S); |
| 734 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 735 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 736 | /// \brief Build a new default statement. |
| 737 | /// |
| 738 | /// By default, performs semantic analysis to build the new statement. |
| 739 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 740 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 741 | SourceLocation ColonLoc, |
| 742 | StmtArg SubStmt) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 743 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 744 | /*CurScope=*/0); |
| 745 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 746 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 747 | /// \brief Build a new label statement. |
| 748 | /// |
| 749 | /// By default, performs semantic analysis to build the new statement. |
| 750 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 751 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 752 | IdentifierInfo *Id, |
| 753 | SourceLocation ColonLoc, |
| 754 | StmtArg SubStmt) { |
| 755 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 756 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 757 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 758 | /// \brief Build a new "if" statement. |
| 759 | /// |
| 760 | /// By default, performs semantic analysis to build the new statement. |
| 761 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 762 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 763 | VarDecl *CondVar, StmtArg Then, |
| 764 | SourceLocation ElseLoc, StmtArg Else) { |
| 765 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
| 766 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 767 | } |
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 | /// \brief Start building a new switch statement. |
| 770 | /// |
| 771 | /// By default, performs semantic analysis to build the new statement. |
| 772 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 773 | OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond, |
| 774 | VarDecl *CondVar) { |
| 775 | return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 776 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 777 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 778 | /// \brief Attach the body to the switch statement. |
| 779 | /// |
| 780 | /// By default, performs semantic analysis to build the new statement. |
| 781 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 782 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 783 | StmtArg Switch, StmtArg Body) { |
| 784 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 785 | move(Body)); |
| 786 | } |
| 787 | |
| 788 | /// \brief Build a new while statement. |
| 789 | /// |
| 790 | /// By default, performs semantic analysis to build the new statement. |
| 791 | /// Subclasses may override this routine to provide different behavior. |
| 792 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 793 | Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 794 | VarDecl *CondVar, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 795 | StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 796 | return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar), |
| 797 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 798 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 799 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 800 | /// \brief Build a new do-while statement. |
| 801 | /// |
| 802 | /// By default, performs semantic analysis to build the new statement. |
| 803 | /// Subclasses may override this routine to provide different behavior. |
| 804 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 805 | SourceLocation WhileLoc, |
| 806 | SourceLocation LParenLoc, |
| 807 | ExprArg Cond, |
| 808 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 809 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 810 | move(Cond), RParenLoc); |
| 811 | } |
| 812 | |
| 813 | /// \brief Build a new for statement. |
| 814 | /// |
| 815 | /// By default, performs semantic analysis to build the new statement. |
| 816 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 817 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 818 | SourceLocation LParenLoc, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 819 | StmtArg Init, Sema::FullExprArg Cond, |
| 820 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 821 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 822 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
| 823 | DeclPtrTy::make(CondVar), |
| 824 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 825 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 826 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 827 | /// \brief Build a new goto statement. |
| 828 | /// |
| 829 | /// By default, performs semantic analysis to build the new statement. |
| 830 | /// Subclasses may override this routine to provide different behavior. |
| 831 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 832 | SourceLocation LabelLoc, |
| 833 | LabelStmt *Label) { |
| 834 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 835 | } |
| 836 | |
| 837 | /// \brief Build a new indirect goto statement. |
| 838 | /// |
| 839 | /// By default, performs semantic analysis to build the new statement. |
| 840 | /// Subclasses may override this routine to provide different behavior. |
| 841 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 842 | SourceLocation StarLoc, |
| 843 | ExprArg Target) { |
| 844 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 845 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 846 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 847 | /// \brief Build a new return statement. |
| 848 | /// |
| 849 | /// By default, performs semantic analysis to build the new statement. |
| 850 | /// Subclasses may override this routine to provide different behavior. |
| 851 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 852 | ExprArg Result) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 853 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 854 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 855 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 856 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 857 | /// \brief Build a new declaration statement. |
| 858 | /// |
| 859 | /// By default, performs semantic analysis to build the new statement. |
| 860 | /// Subclasses may override this routine to provide different behavior. |
| 861 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 862 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 863 | SourceLocation EndLoc) { |
| 864 | return getSema().Owned( |
| 865 | new (getSema().Context) DeclStmt( |
| 866 | DeclGroupRef::Create(getSema().Context, |
| 867 | Decls, NumDecls), |
| 868 | StartLoc, EndLoc)); |
| 869 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 870 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 871 | /// \brief Build a new inline asm statement. |
| 872 | /// |
| 873 | /// By default, performs semantic analysis to build the new statement. |
| 874 | /// Subclasses may override this routine to provide different behavior. |
| 875 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 876 | bool IsSimple, |
| 877 | bool IsVolatile, |
| 878 | unsigned NumOutputs, |
| 879 | unsigned NumInputs, |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 880 | IdentifierInfo **Names, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 881 | MultiExprArg Constraints, |
| 882 | MultiExprArg Exprs, |
| 883 | ExprArg AsmString, |
| 884 | MultiExprArg Clobbers, |
| 885 | SourceLocation RParenLoc, |
| 886 | bool MSAsm) { |
| 887 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 888 | NumInputs, Names, move(Constraints), |
| 889 | move(Exprs), move(AsmString), move(Clobbers), |
| 890 | RParenLoc, MSAsm); |
| 891 | } |
| 892 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 893 | /// \brief Build a new C++ exception declaration. |
| 894 | /// |
| 895 | /// By default, performs semantic analysis to build the new decaration. |
| 896 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 897 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 898 | TypeSourceInfo *Declarator, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 899 | IdentifierInfo *Name, |
| 900 | SourceLocation Loc, |
| 901 | SourceRange TypeRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 902 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 903 | TypeRange); |
| 904 | } |
| 905 | |
| 906 | /// \brief Build a new C++ catch statement. |
| 907 | /// |
| 908 | /// By default, performs semantic analysis to build the new statement. |
| 909 | /// Subclasses may override this routine to provide different behavior. |
| 910 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 911 | VarDecl *ExceptionDecl, |
| 912 | StmtArg Handler) { |
| 913 | return getSema().Owned( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 914 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 915 | Handler.takeAs<Stmt>())); |
| 916 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 917 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 918 | /// \brief Build a new C++ try statement. |
| 919 | /// |
| 920 | /// By default, performs semantic analysis to build the new statement. |
| 921 | /// Subclasses may override this routine to provide different behavior. |
| 922 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 923 | StmtArg TryBlock, |
| 924 | MultiStmtArg Handlers) { |
| 925 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 926 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 927 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 928 | /// \brief Build a new expression that references a declaration. |
| 929 | /// |
| 930 | /// By default, performs semantic analysis to build the new expression. |
| 931 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 932 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 933 | LookupResult &R, |
| 934 | bool RequiresADL) { |
| 935 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 936 | } |
| 937 | |
| 938 | |
| 939 | /// \brief Build a new expression that references a declaration. |
| 940 | /// |
| 941 | /// By default, performs semantic analysis to build the new expression. |
| 942 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 943 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 944 | SourceRange QualifierRange, |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 945 | ValueDecl *VD, SourceLocation Loc, |
| 946 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 947 | CXXScopeSpec SS; |
| 948 | SS.setScopeRep(Qualifier); |
| 949 | SS.setRange(QualifierRange); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 950 | |
| 951 | // FIXME: loses template args. |
| 952 | |
| 953 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 954 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 955 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 956 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 957 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 958 | /// By default, performs semantic analysis to build the new expression. |
| 959 | /// Subclasses may override this routine to provide different behavior. |
| 960 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 961 | SourceLocation RParen) { |
| 962 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 963 | } |
| 964 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 965 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 966 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 967 | /// By default, performs semantic analysis to build the new expression. |
| 968 | /// Subclasses may override this routine to provide different behavior. |
| 969 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 970 | SourceLocation OperatorLoc, |
| 971 | bool isArrow, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 972 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 973 | SourceRange QualifierRange, |
| 974 | TypeSourceInfo *ScopeType, |
| 975 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 976 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 977 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 978 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 979 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 980 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 981 | /// By default, performs semantic analysis to build the new expression. |
| 982 | /// Subclasses may override this routine to provide different behavior. |
| 983 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 984 | UnaryOperator::Opcode Opc, |
| 985 | ExprArg SubExpr) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 986 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 987 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 988 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 989 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 990 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 991 | /// By default, performs semantic analysis to build the new expression. |
| 992 | /// Subclasses may override this routine to provide different behavior. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 993 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 994 | SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 995 | bool isSizeOf, SourceRange R) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 996 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 997 | } |
| 998 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 999 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1000 | /// argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1001 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1002 | /// By default, performs semantic analysis to build the new expression. |
| 1003 | /// Subclasses may override this routine to provide different behavior. |
| 1004 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 1005 | bool isSizeOf, SourceRange R) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1006 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1007 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 1008 | OpLoc, isSizeOf, R); |
| 1009 | if (Result.isInvalid()) |
| 1010 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1011 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1012 | SubExpr.release(); |
| 1013 | return move(Result); |
| 1014 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1015 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1016 | /// \brief Build a new array subscript expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1019 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1020 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1021 | SourceLocation LBracketLoc, |
| 1022 | ExprArg RHS, |
| 1023 | SourceLocation RBracketLoc) { |
| 1024 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1025 | LBracketLoc, move(RHS), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1026 | RBracketLoc); |
| 1027 | } |
| 1028 | |
| 1029 | /// \brief Build a new call 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 RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 1034 | MultiExprArg Args, |
| 1035 | SourceLocation *CommaLocs, |
| 1036 | SourceLocation RParenLoc) { |
| 1037 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 1038 | move(Args), CommaLocs, RParenLoc); |
| 1039 | } |
| 1040 | |
| 1041 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1042 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1043 | /// By default, performs semantic analysis to build the new expression. |
| 1044 | /// Subclasses may override this routine to provide different behavior. |
| 1045 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1046 | bool isArrow, |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1047 | NestedNameSpecifier *Qualifier, |
| 1048 | SourceRange QualifierRange, |
| 1049 | SourceLocation MemberLoc, |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 1050 | ValueDecl *Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1051 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1052 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 1053 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1054 | if (!Member->getDeclName()) { |
| 1055 | // We have a reference to an unnamed field. |
| 1056 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1057 | |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1058 | Expr *BaseExpr = Base.takeAs<Expr>(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1059 | if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, |
| 1060 | FoundDecl, Member)) |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1061 | return getSema().ExprError(); |
Douglas Gregor | 4b65441 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 1062 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1063 | MemberExpr *ME = |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1064 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1065 | Member, MemberLoc, |
| 1066 | cast<FieldDecl>(Member)->getType()); |
| 1067 | return getSema().Owned(ME); |
| 1068 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1069 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1070 | CXXScopeSpec SS; |
| 1071 | if (Qualifier) { |
| 1072 | SS.setRange(QualifierRange); |
| 1073 | SS.setScopeRep(Qualifier); |
| 1074 | } |
| 1075 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1076 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1077 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1078 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1079 | // cases; we should avoid this when possible. |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1080 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 1081 | Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1082 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1083 | R.resolveKind(); |
| 1084 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1085 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 1086 | OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1087 | SS, FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1088 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1089 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1090 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1091 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1092 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1093 | /// By default, performs semantic analysis to build the new expression. |
| 1094 | /// Subclasses may override this routine to provide different behavior. |
| 1095 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1096 | BinaryOperator::Opcode Opc, |
| 1097 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1098 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 1099 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1103 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1104 | /// By default, performs semantic analysis to build the new expression. |
| 1105 | /// Subclasses may override this routine to provide different behavior. |
| 1106 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1107 | SourceLocation QuestionLoc, |
| 1108 | ExprArg LHS, |
| 1109 | SourceLocation ColonLoc, |
| 1110 | ExprArg RHS) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1111 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1112 | move(LHS), move(RHS)); |
| 1113 | } |
| 1114 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1115 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1116 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1117 | /// By default, performs semantic analysis to build the new expression. |
| 1118 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1119 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1120 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1121 | SourceLocation RParenLoc, |
| 1122 | ExprArg SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1123 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1124 | move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1125 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1126 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1127 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1128 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1129 | /// By default, performs semantic analysis to build the new expression. |
| 1130 | /// Subclasses may override this routine to provide different behavior. |
| 1131 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1132 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1133 | SourceLocation RParenLoc, |
| 1134 | ExprArg Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1135 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1136 | move(Init)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1137 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1138 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1139 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1140 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1141 | /// By default, performs semantic analysis to build the new expression. |
| 1142 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1143 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1144 | SourceLocation OpLoc, |
| 1145 | SourceLocation AccessorLoc, |
| 1146 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1147 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1148 | CXXScopeSpec SS; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1149 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1150 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1151 | OpLoc, /*IsArrow*/ false, |
| 1152 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 30d60cb | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1153 | DeclarationName(&Accessor), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1154 | AccessorLoc, |
| 1155 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1156 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1157 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1158 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1159 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1160 | /// By default, performs semantic analysis to build the new expression. |
| 1161 | /// Subclasses may override this routine to provide different behavior. |
| 1162 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1163 | MultiExprArg Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1164 | SourceLocation RBraceLoc, |
| 1165 | QualType ResultTy) { |
| 1166 | OwningExprResult Result |
| 1167 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1168 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1169 | return move(Result); |
| 1170 | |
| 1171 | // Patch in the result type we were given, which may have been computed |
| 1172 | // when the initial InitListExpr was built. |
| 1173 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1174 | ILE->setType(ResultTy); |
| 1175 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1176 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1177 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1178 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1179 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1180 | /// By default, performs semantic analysis to build the new expression. |
| 1181 | /// Subclasses may override this routine to provide different behavior. |
| 1182 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1183 | MultiExprArg ArrayExprs, |
| 1184 | SourceLocation EqualOrColonLoc, |
| 1185 | bool GNUSyntax, |
| 1186 | ExprArg Init) { |
| 1187 | OwningExprResult Result |
| 1188 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1189 | move(Init)); |
| 1190 | if (Result.isInvalid()) |
| 1191 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1192 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1193 | ArrayExprs.release(); |
| 1194 | return move(Result); |
| 1195 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1196 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1197 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1198 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1199 | /// By default, builds the implicit value initialization without performing |
| 1200 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1201 | /// different behavior. |
| 1202 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1203 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1204 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1205 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1206 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1207 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1208 | /// By default, performs semantic analysis to build the new expression. |
| 1209 | /// Subclasses may override this routine to provide different behavior. |
| 1210 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1211 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1212 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1213 | RParenLoc); |
| 1214 | } |
| 1215 | |
| 1216 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1217 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1218 | /// By default, performs semantic analysis to build the new expression. |
| 1219 | /// Subclasses may override this routine to provide different behavior. |
| 1220 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1221 | MultiExprArg SubExprs, |
| 1222 | SourceLocation RParenLoc) { |
Fariborz Jahanian | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1223 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1224 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1225 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1226 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1227 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1228 | /// |
| 1229 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1230 | /// rather than attempting to map the label statement itself. |
| 1231 | /// Subclasses may override this routine to provide different behavior. |
| 1232 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1233 | SourceLocation LabelLoc, |
| 1234 | LabelStmt *Label) { |
| 1235 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1236 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1237 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1238 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1239 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1240 | /// By default, performs semantic analysis to build the new expression. |
| 1241 | /// Subclasses may override this routine to provide different behavior. |
| 1242 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1243 | StmtArg SubStmt, |
| 1244 | SourceLocation RParenLoc) { |
| 1245 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1246 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1247 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1248 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1249 | /// |
| 1250 | /// By default, performs semantic analysis to build the new expression. |
| 1251 | /// Subclasses may override this routine to provide different behavior. |
| 1252 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1253 | QualType T1, QualType T2, |
| 1254 | SourceLocation RParenLoc) { |
| 1255 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1256 | T1.getAsOpaquePtr(), |
| 1257 | T2.getAsOpaquePtr(), |
| 1258 | RParenLoc); |
| 1259 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1260 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1261 | /// \brief Build a new __builtin_choose_expr expression. |
| 1262 | /// |
| 1263 | /// By default, performs semantic analysis to build the new expression. |
| 1264 | /// Subclasses may override this routine to provide different behavior. |
| 1265 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1266 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1267 | SourceLocation RParenLoc) { |
| 1268 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1269 | move(Cond), move(LHS), move(RHS), |
| 1270 | RParenLoc); |
| 1271 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1272 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1273 | /// \brief Build a new overloaded operator call expression. |
| 1274 | /// |
| 1275 | /// By default, performs semantic analysis to build the new expression. |
| 1276 | /// The semantic analysis provides the behavior of template instantiation, |
| 1277 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1278 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1279 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1280 | /// provide different behavior. |
| 1281 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1282 | SourceLocation OpLoc, |
| 1283 | ExprArg Callee, |
| 1284 | ExprArg First, |
| 1285 | ExprArg Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1286 | |
| 1287 | /// \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] | 1288 | /// reinterpret_cast. |
| 1289 | /// |
| 1290 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1291 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1292 | /// Subclasses may override this routine to provide different behavior. |
| 1293 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1294 | Stmt::StmtClass Class, |
| 1295 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1296 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1297 | SourceLocation RAngleLoc, |
| 1298 | SourceLocation LParenLoc, |
| 1299 | ExprArg SubExpr, |
| 1300 | SourceLocation RParenLoc) { |
| 1301 | switch (Class) { |
| 1302 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1303 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1304 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1305 | move(SubExpr), RParenLoc); |
| 1306 | |
| 1307 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1308 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1309 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1310 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1311 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1312 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1313 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1314 | RAngleLoc, LParenLoc, |
| 1315 | move(SubExpr), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1316 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1317 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1318 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1319 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1320 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1321 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1322 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1323 | default: |
| 1324 | assert(false && "Invalid C++ named cast"); |
| 1325 | break; |
| 1326 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1327 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1328 | return getSema().ExprError(); |
| 1329 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1330 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1331 | /// \brief Build a new C++ static_cast expression. |
| 1332 | /// |
| 1333 | /// By default, performs semantic analysis to build the new expression. |
| 1334 | /// Subclasses may override this routine to provide different behavior. |
| 1335 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1336 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1337 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1338 | SourceLocation RAngleLoc, |
| 1339 | SourceLocation LParenLoc, |
| 1340 | ExprArg SubExpr, |
| 1341 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1342 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1343 | TInfo, move(SubExpr), |
| 1344 | SourceRange(LAngleLoc, RAngleLoc), |
| 1345 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | /// \brief Build a new C++ dynamic_cast expression. |
| 1349 | /// |
| 1350 | /// By default, performs semantic analysis to build the new expression. |
| 1351 | /// Subclasses may override this routine to provide different behavior. |
| 1352 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1353 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1354 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1355 | SourceLocation RAngleLoc, |
| 1356 | SourceLocation LParenLoc, |
| 1357 | ExprArg SubExpr, |
| 1358 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1359 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1360 | TInfo, move(SubExpr), |
| 1361 | SourceRange(LAngleLoc, RAngleLoc), |
| 1362 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1366 | /// |
| 1367 | /// By default, performs semantic analysis to build the new expression. |
| 1368 | /// Subclasses may override this routine to provide different behavior. |
| 1369 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1370 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1371 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1372 | SourceLocation RAngleLoc, |
| 1373 | SourceLocation LParenLoc, |
| 1374 | ExprArg SubExpr, |
| 1375 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1376 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1377 | TInfo, move(SubExpr), |
| 1378 | SourceRange(LAngleLoc, RAngleLoc), |
| 1379 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | /// \brief Build a new C++ const_cast expression. |
| 1383 | /// |
| 1384 | /// By default, performs semantic analysis to build the new expression. |
| 1385 | /// Subclasses may override this routine to provide different behavior. |
| 1386 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1387 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1388 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1389 | SourceLocation RAngleLoc, |
| 1390 | SourceLocation LParenLoc, |
| 1391 | ExprArg SubExpr, |
| 1392 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1393 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1394 | TInfo, move(SubExpr), |
| 1395 | SourceRange(LAngleLoc, RAngleLoc), |
| 1396 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1397 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1398 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1399 | /// \brief Build a new C++ functional-style cast expression. |
| 1400 | /// |
| 1401 | /// By default, performs semantic analysis to build the new expression. |
| 1402 | /// Subclasses may override this routine to provide different behavior. |
| 1403 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1404 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1405 | SourceLocation LParenLoc, |
| 1406 | ExprArg SubExpr, |
| 1407 | SourceLocation RParenLoc) { |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1408 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1409 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1410 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1411 | LParenLoc, |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1412 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1413 | /*CommaLocs=*/0, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1414 | RParenLoc); |
| 1415 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1416 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1417 | /// \brief Build a new C++ typeid(type) expression. |
| 1418 | /// |
| 1419 | /// By default, performs semantic analysis to build the new expression. |
| 1420 | /// Subclasses may override this routine to provide different behavior. |
| 1421 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1422 | SourceLocation LParenLoc, |
| 1423 | QualType T, |
| 1424 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1425 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1426 | T.getAsOpaquePtr(), RParenLoc); |
| 1427 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1428 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1429 | /// \brief Build a new C++ typeid(expr) expression. |
| 1430 | /// |
| 1431 | /// By default, performs semantic analysis to build the new expression. |
| 1432 | /// Subclasses may override this routine to provide different behavior. |
| 1433 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1434 | SourceLocation LParenLoc, |
| 1435 | ExprArg Operand, |
| 1436 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1437 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1438 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1439 | RParenLoc); |
| 1440 | if (Result.isInvalid()) |
| 1441 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1442 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1443 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1444 | return move(Result); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1445 | } |
| 1446 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1447 | /// \brief Build a new C++ "this" expression. |
| 1448 | /// |
| 1449 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1450 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1451 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1452 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1453 | QualType ThisType, |
| 1454 | bool isImplicit) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1455 | return getSema().Owned( |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1456 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1457 | isImplicit)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | /// \brief Build a new C++ throw expression. |
| 1461 | /// |
| 1462 | /// By default, performs semantic analysis to build the new expression. |
| 1463 | /// Subclasses may override this routine to provide different behavior. |
| 1464 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1465 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1466 | } |
| 1467 | |
| 1468 | /// \brief Build a new C++ default-argument expression. |
| 1469 | /// |
| 1470 | /// By default, builds a new default-argument expression, which does not |
| 1471 | /// require any semantic analysis. Subclasses may override this routine to |
| 1472 | /// provide different behavior. |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1473 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
| 1474 | ParmVarDecl *Param) { |
| 1475 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1476 | Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | /// \brief Build a new C++ zero-initialization expression. |
| 1480 | /// |
| 1481 | /// By default, performs semantic analysis to build the new expression. |
| 1482 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1483 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1484 | SourceLocation LParenLoc, |
| 1485 | QualType T, |
| 1486 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1487 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1488 | T.getAsOpaquePtr(), LParenLoc, |
| 1489 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1490 | 0, RParenLoc); |
| 1491 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1492 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1493 | /// \brief Build a new C++ "new" expression. |
| 1494 | /// |
| 1495 | /// By default, performs semantic analysis to build the new expression. |
| 1496 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1497 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1498 | bool UseGlobal, |
| 1499 | SourceLocation PlacementLParen, |
| 1500 | MultiExprArg PlacementArgs, |
| 1501 | SourceLocation PlacementRParen, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1502 | bool ParenTypeId, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1503 | QualType AllocType, |
| 1504 | SourceLocation TypeLoc, |
| 1505 | SourceRange TypeRange, |
| 1506 | ExprArg ArraySize, |
| 1507 | SourceLocation ConstructorLParen, |
| 1508 | MultiExprArg ConstructorArgs, |
| 1509 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1510 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1511 | PlacementLParen, |
| 1512 | move(PlacementArgs), |
| 1513 | PlacementRParen, |
| 1514 | ParenTypeId, |
| 1515 | AllocType, |
| 1516 | TypeLoc, |
| 1517 | TypeRange, |
| 1518 | move(ArraySize), |
| 1519 | ConstructorLParen, |
| 1520 | move(ConstructorArgs), |
| 1521 | ConstructorRParen); |
| 1522 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1523 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1524 | /// \brief Build a new C++ "delete" expression. |
| 1525 | /// |
| 1526 | /// By default, performs semantic analysis to build the new expression. |
| 1527 | /// Subclasses may override this routine to provide different behavior. |
| 1528 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1529 | bool IsGlobalDelete, |
| 1530 | bool IsArrayForm, |
| 1531 | ExprArg Operand) { |
| 1532 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1533 | move(Operand)); |
| 1534 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1535 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1536 | /// \brief Build a new unary type trait expression. |
| 1537 | /// |
| 1538 | /// By default, performs semantic analysis to build the new expression. |
| 1539 | /// Subclasses may override this routine to provide different behavior. |
| 1540 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1541 | SourceLocation StartLoc, |
| 1542 | SourceLocation LParenLoc, |
| 1543 | QualType T, |
| 1544 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1545 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1546 | T.getAsOpaquePtr(), RParenLoc); |
| 1547 | } |
| 1548 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1549 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1550 | /// expression. |
| 1551 | /// |
| 1552 | /// By default, performs semantic analysis to build the new expression. |
| 1553 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1554 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1555 | SourceRange QualifierRange, |
| 1556 | DeclarationName Name, |
| 1557 | SourceLocation Location, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1558 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1559 | CXXScopeSpec SS; |
| 1560 | SS.setRange(QualifierRange); |
| 1561 | SS.setScopeRep(NNS); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1562 | |
| 1563 | if (TemplateArgs) |
| 1564 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1565 | *TemplateArgs); |
| 1566 | |
| 1567 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | /// \brief Build a new template-id expression. |
| 1571 | /// |
| 1572 | /// By default, performs semantic analysis to build the new expression. |
| 1573 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1574 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1575 | LookupResult &R, |
| 1576 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1577 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1578 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | /// \brief Build a new object-construction expression. |
| 1582 | /// |
| 1583 | /// By default, performs semantic analysis to build the new expression. |
| 1584 | /// Subclasses may override this routine to provide different behavior. |
| 1585 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1586 | SourceLocation Loc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1587 | CXXConstructorDecl *Constructor, |
| 1588 | bool IsElidable, |
| 1589 | MultiExprArg Args) { |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1590 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
| 1591 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
| 1592 | ConvertedArgs)) |
| 1593 | return getSema().ExprError(); |
| 1594 | |
| 1595 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1596 | move_arg(ConvertedArgs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | /// \brief Build a new object-construction expression. |
| 1600 | /// |
| 1601 | /// By default, performs semantic analysis to build the new expression. |
| 1602 | /// Subclasses may override this routine to provide different behavior. |
| 1603 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1604 | QualType T, |
| 1605 | SourceLocation LParenLoc, |
| 1606 | MultiExprArg Args, |
| 1607 | SourceLocation *Commas, |
| 1608 | SourceLocation RParenLoc) { |
| 1609 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1610 | T.getAsOpaquePtr(), |
| 1611 | LParenLoc, |
| 1612 | move(Args), |
| 1613 | Commas, |
| 1614 | RParenLoc); |
| 1615 | } |
| 1616 | |
| 1617 | /// \brief Build a new object-construction expression. |
| 1618 | /// |
| 1619 | /// By default, performs semantic analysis to build the new expression. |
| 1620 | /// Subclasses may override this routine to provide different behavior. |
| 1621 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1622 | QualType T, |
| 1623 | SourceLocation LParenLoc, |
| 1624 | MultiExprArg Args, |
| 1625 | SourceLocation *Commas, |
| 1626 | SourceLocation RParenLoc) { |
| 1627 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1628 | /*FIXME*/LParenLoc), |
| 1629 | T.getAsOpaquePtr(), |
| 1630 | LParenLoc, |
| 1631 | move(Args), |
| 1632 | Commas, |
| 1633 | RParenLoc); |
| 1634 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1635 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1636 | /// \brief Build a new member reference expression. |
| 1637 | /// |
| 1638 | /// By default, performs semantic analysis to build the new expression. |
| 1639 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1640 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1641 | QualType BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1642 | bool IsArrow, |
| 1643 | SourceLocation OperatorLoc, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1644 | NestedNameSpecifier *Qualifier, |
| 1645 | SourceRange QualifierRange, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1646 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1647 | DeclarationName Name, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1648 | SourceLocation MemberLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1649 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1650 | CXXScopeSpec SS; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1651 | SS.setRange(QualifierRange); |
| 1652 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1653 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1654 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1655 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1656 | SS, FirstQualifierInScope, |
| 1657 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1660 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1661 | /// |
| 1662 | /// By default, performs semantic analysis to build the new expression. |
| 1663 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1664 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1665 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1666 | SourceLocation OperatorLoc, |
| 1667 | bool IsArrow, |
| 1668 | NestedNameSpecifier *Qualifier, |
| 1669 | SourceRange QualifierRange, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1670 | NamedDecl *FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1671 | LookupResult &R, |
| 1672 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1673 | CXXScopeSpec SS; |
| 1674 | SS.setRange(QualifierRange); |
| 1675 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1676 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1677 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1678 | OperatorLoc, IsArrow, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1679 | SS, FirstQualifierInScope, |
| 1680 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1681 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1682 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1683 | /// \brief Build a new Objective-C @encode expression. |
| 1684 | /// |
| 1685 | /// By default, performs semantic analysis to build the new expression. |
| 1686 | /// Subclasses may override this routine to provide different behavior. |
| 1687 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1688 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1689 | SourceLocation RParenLoc) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1690 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1691 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1692 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1693 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1694 | /// \brief Build a new Objective-C class message. |
| 1695 | OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
| 1696 | Selector Sel, |
| 1697 | ObjCMethodDecl *Method, |
| 1698 | SourceLocation LBracLoc, |
| 1699 | MultiExprArg Args, |
| 1700 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1701 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 1702 | ReceiverTypeInfo->getType(), |
| 1703 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | b5186b1 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1704 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1705 | move(Args)); |
| 1706 | } |
| 1707 | |
| 1708 | /// \brief Build a new Objective-C instance message. |
| 1709 | OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver, |
| 1710 | Selector Sel, |
| 1711 | ObjCMethodDecl *Method, |
| 1712 | SourceLocation LBracLoc, |
| 1713 | MultiExprArg Args, |
| 1714 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1715 | QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType(); |
| 1716 | return SemaRef.BuildInstanceMessage(move(Receiver), |
| 1717 | ReceiverType, |
| 1718 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | b5186b1 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1719 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1720 | move(Args)); |
| 1721 | } |
| 1722 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1723 | /// \brief Build a new shuffle vector expression. |
| 1724 | /// |
| 1725 | /// By default, performs semantic analysis to build the new expression. |
| 1726 | /// Subclasses may override this routine to provide different behavior. |
| 1727 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1728 | MultiExprArg SubExprs, |
| 1729 | SourceLocation RParenLoc) { |
| 1730 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1731 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1732 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1733 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1734 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1735 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1736 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1737 | // Build a reference to the __builtin_shufflevector builtin |
| 1738 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1739 | Expr *Callee |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1740 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1741 | BuiltinLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1742 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1743 | |
| 1744 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1745 | unsigned NumSubExprs = SubExprs.size(); |
| 1746 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1747 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1748 | Subs, NumSubExprs, |
| 1749 | Builtin->getResultType(), |
| 1750 | RParenLoc); |
| 1751 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1752 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1753 | // Type-check the __builtin_shufflevector expression. |
| 1754 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1755 | if (Result.isInvalid()) |
| 1756 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1757 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1758 | OwnedCall.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1759 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1760 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1761 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1762 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1763 | template<typename Derived> |
| 1764 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1765 | if (!S) |
| 1766 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1767 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1768 | switch (S->getStmtClass()) { |
| 1769 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1770 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1771 | // Transform individual statement nodes |
| 1772 | #define STMT(Node, Parent) \ |
| 1773 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1774 | #define EXPR(Node, Parent) |
| 1775 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1776 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1777 | // Transform expressions by calling TransformExpr. |
| 1778 | #define STMT(Node, Parent) |
John McCall | 2adddca | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1779 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1780 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1781 | #include "clang/AST/StmtNodes.def" |
| 1782 | { |
| 1783 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1784 | if (E.isInvalid()) |
| 1785 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1786 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1787 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1788 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1789 | } |
| 1790 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1791 | return SemaRef.Owned(S->Retain()); |
| 1792 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1793 | |
| 1794 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1795 | template<typename Derived> |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1796 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1797 | if (!E) |
| 1798 | return SemaRef.Owned(E); |
| 1799 | |
| 1800 | switch (E->getStmtClass()) { |
| 1801 | case Stmt::NoStmtClass: break; |
| 1802 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
John McCall | 2adddca | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1803 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1804 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1805 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1806 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1807 | } |
| 1808 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1809 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | template<typename Derived> |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1813 | NestedNameSpecifier * |
| 1814 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1815 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1816 | QualType ObjectType, |
| 1817 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 96ee789 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1818 | if (!NNS) |
| 1819 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1820 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1821 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1822 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1823 | if (Prefix) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1824 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1825 | ObjectType, |
| 1826 | FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1827 | if (!Prefix) |
| 1828 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1829 | |
| 1830 | // 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] | 1831 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1832 | ObjectType = QualType(); |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1833 | FirstQualifierInScope = 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1834 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1835 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1836 | switch (NNS->getKind()) { |
| 1837 | case NestedNameSpecifier::Identifier: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1838 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1839 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1840 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1841 | ObjectType.isNull()) |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1842 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1843 | |
| 1844 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1845 | *NNS->getAsIdentifier(), |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1846 | ObjectType, |
| 1847 | FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1848 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1849 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1850 | NamespaceDecl *NS |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1851 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1852 | getDerived().TransformDecl(Range.getBegin(), |
| 1853 | NNS->getAsNamespace())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1854 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1855 | Prefix == NNS->getPrefix() && |
| 1856 | NS == NNS->getAsNamespace()) |
| 1857 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1858 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1859 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1860 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1861 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1862 | case NestedNameSpecifier::Global: |
| 1863 | // There is no meaningful transformation that one could perform on the |
| 1864 | // global scope. |
| 1865 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1866 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1867 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1868 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | 07cc4ac | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1869 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1870 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 1871 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1872 | if (T.isNull()) |
| 1873 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1874 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1875 | if (!getDerived().AlwaysRebuild() && |
| 1876 | Prefix == NNS->getPrefix() && |
| 1877 | T == QualType(NNS->getAsType(), 0)) |
| 1878 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1879 | |
| 1880 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1881 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 1882 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1883 | } |
| 1884 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1885 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1886 | // Required to silence a GCC warning |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1887 | return 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1891 | DeclarationName |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1892 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1893 | SourceLocation Loc, |
| 1894 | QualType ObjectType) { |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1895 | if (!Name) |
| 1896 | return Name; |
| 1897 | |
| 1898 | switch (Name.getNameKind()) { |
| 1899 | case DeclarationName::Identifier: |
| 1900 | case DeclarationName::ObjCZeroArgSelector: |
| 1901 | case DeclarationName::ObjCOneArgSelector: |
| 1902 | case DeclarationName::ObjCMultiArgSelector: |
| 1903 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 1904 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1905 | case DeclarationName::CXXUsingDirective: |
| 1906 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1907 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1908 | case DeclarationName::CXXConstructorName: |
| 1909 | case DeclarationName::CXXDestructorName: |
| 1910 | case DeclarationName::CXXConversionFunctionName: { |
| 1911 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1912 | QualType T = getDerived().TransformType(Name.getCXXNameType(), |
| 1913 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1914 | if (T.isNull()) |
| 1915 | return DeclarationName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1916 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1917 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1918 | Name.getNameKind(), |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1919 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1920 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1921 | } |
| 1922 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1923 | return DeclarationName(); |
| 1924 | } |
| 1925 | |
| 1926 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1927 | TemplateName |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1928 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1929 | QualType ObjectType) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1930 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1931 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1932 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1933 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1934 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1935 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 1936 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1937 | if (!NNS) |
| 1938 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1939 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1940 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1941 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1942 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1943 | if (!TransTemplate) |
| 1944 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1945 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1946 | if (!getDerived().AlwaysRebuild() && |
| 1947 | NNS == QTN->getQualifier() && |
| 1948 | TransTemplate == Template) |
| 1949 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1950 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1951 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1952 | TransTemplate); |
| 1953 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1954 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1955 | // These should be getting filtered out before they make it into the AST. |
| 1956 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1957 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1958 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1959 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1960 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1961 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1962 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 1963 | ObjectType); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1964 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1965 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1966 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1967 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1968 | NNS == DTN->getQualifier() && |
| 1969 | ObjectType.isNull()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1970 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1971 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1972 | if (DTN->isIdentifier()) |
| 1973 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 1974 | ObjectType); |
| 1975 | |
| 1976 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 1977 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1978 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1979 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1980 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1981 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1982 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1983 | if (!TransTemplate) |
| 1984 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1985 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1986 | if (!getDerived().AlwaysRebuild() && |
| 1987 | TransTemplate == Template) |
| 1988 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1989 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1990 | return TemplateName(TransTemplate); |
| 1991 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1992 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1993 | // These should be getting filtered out before they reach the AST. |
| 1994 | assert(false && "overloaded function decl survived to here"); |
| 1995 | return TemplateName(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1999 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2000 | const TemplateArgument &Arg, |
| 2001 | TemplateArgumentLoc &Output) { |
| 2002 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2003 | switch (Arg.getKind()) { |
| 2004 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2005 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2006 | break; |
| 2007 | |
| 2008 | case TemplateArgument::Type: |
| 2009 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2010 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2011 | |
| 2012 | break; |
| 2013 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2014 | case TemplateArgument::Template: |
| 2015 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 2016 | break; |
| 2017 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2018 | case TemplateArgument::Expression: |
| 2019 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2020 | break; |
| 2021 | |
| 2022 | case TemplateArgument::Declaration: |
| 2023 | case TemplateArgument::Integral: |
| 2024 | case TemplateArgument::Pack: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2025 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2026 | break; |
| 2027 | } |
| 2028 | } |
| 2029 | |
| 2030 | template<typename Derived> |
| 2031 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2032 | const TemplateArgumentLoc &Input, |
| 2033 | TemplateArgumentLoc &Output) { |
| 2034 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2035 | switch (Arg.getKind()) { |
| 2036 | case TemplateArgument::Null: |
| 2037 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2038 | Output = Input; |
| 2039 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2040 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2041 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2042 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2043 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2044 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2045 | |
| 2046 | DI = getDerived().TransformType(DI); |
| 2047 | if (!DI) return true; |
| 2048 | |
| 2049 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2050 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2051 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2052 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2053 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2054 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2055 | DeclarationName Name; |
| 2056 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2057 | Name = ND->getDeclName(); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2058 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2059 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2060 | if (!D) return true; |
| 2061 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2062 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2063 | if (SourceExpr) { |
| 2064 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 2065 | Action::Unevaluated); |
| 2066 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 2067 | if (E.isInvalid()) |
| 2068 | SourceExpr = NULL; |
| 2069 | else { |
| 2070 | SourceExpr = E.takeAs<Expr>(); |
| 2071 | SourceExpr->Retain(); |
| 2072 | } |
| 2073 | } |
| 2074 | |
| 2075 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2076 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2077 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2078 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2079 | case TemplateArgument::Template: { |
| 2080 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 2081 | TemplateName Template |
| 2082 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2083 | if (Template.isNull()) |
| 2084 | return true; |
| 2085 | |
| 2086 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2087 | Input.getTemplateQualifierRange(), |
| 2088 | Input.getTemplateNameLoc()); |
| 2089 | return false; |
| 2090 | } |
| 2091 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2092 | case TemplateArgument::Expression: { |
| 2093 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2094 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2095 | Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2096 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2097 | Expr *InputExpr = Input.getSourceExpression(); |
| 2098 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2099 | |
| 2100 | Sema::OwningExprResult E |
| 2101 | = getDerived().TransformExpr(InputExpr); |
| 2102 | if (E.isInvalid()) return true; |
| 2103 | |
| 2104 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2105 | ETaken->Retain(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2106 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2107 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2108 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2109 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2110 | case TemplateArgument::Pack: { |
| 2111 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2112 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2113 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2114 | AEnd = Arg.pack_end(); |
| 2115 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2116 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2117 | // FIXME: preserve source information here when we start |
| 2118 | // caring about parameter packs. |
| 2119 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2120 | TemplateArgumentLoc InputArg; |
| 2121 | TemplateArgumentLoc OutputArg; |
| 2122 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2123 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2124 | return true; |
| 2125 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2126 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2127 | } |
| 2128 | TemplateArgument Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2129 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2130 | true); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2131 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2132 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2133 | } |
| 2134 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2135 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2136 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2137 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2138 | } |
| 2139 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2140 | //===----------------------------------------------------------------------===// |
| 2141 | // Type transformation |
| 2142 | //===----------------------------------------------------------------------===// |
| 2143 | |
| 2144 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2145 | QualType TreeTransform<Derived>::TransformType(QualType T, |
| 2146 | QualType ObjectType) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2147 | if (getDerived().AlreadyTransformed(T)) |
| 2148 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2149 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2150 | // Temporary workaround. All of these transformations should |
| 2151 | // eventually turn into transformations on TypeLocs. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2152 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | de88989 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2153 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2154 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2155 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2156 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2157 | if (!NewDI) |
| 2158 | return QualType(); |
| 2159 | |
| 2160 | return NewDI->getType(); |
| 2161 | } |
| 2162 | |
| 2163 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2164 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2165 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2166 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2167 | return DI; |
| 2168 | |
| 2169 | TypeLocBuilder TLB; |
| 2170 | |
| 2171 | TypeLoc TL = DI->getTypeLoc(); |
| 2172 | TLB.reserve(TL.getFullDataSize()); |
| 2173 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2174 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2175 | if (Result.isNull()) |
| 2176 | return 0; |
| 2177 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2178 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2179 | } |
| 2180 | |
| 2181 | template<typename Derived> |
| 2182 | QualType |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2183 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2184 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2185 | switch (T.getTypeLocClass()) { |
| 2186 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2187 | #define TYPELOC(CLASS, PARENT) \ |
| 2188 | case TypeLoc::CLASS: \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2189 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2190 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2191 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2192 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2193 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2194 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2195 | return QualType(); |
| 2196 | } |
| 2197 | |
| 2198 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2199 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2200 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2201 | /// types). This is the right thing for template instantiation, but |
| 2202 | /// probably not for other clients. |
| 2203 | template<typename Derived> |
| 2204 | QualType |
| 2205 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2206 | QualifiedTypeLoc T, |
| 2207 | QualType ObjectType) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2208 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2209 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2210 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2211 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2212 | if (Result.isNull()) |
| 2213 | return QualType(); |
| 2214 | |
| 2215 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2216 | // FIXME: this is the right thing for template instantiation, but |
| 2217 | // probably not for other clients. |
| 2218 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2219 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2220 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2221 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2222 | |
| 2223 | TLB.push<QualifiedTypeLoc>(Result); |
| 2224 | |
| 2225 | // No location information to preserve. |
| 2226 | |
| 2227 | return Result; |
| 2228 | } |
| 2229 | |
| 2230 | template <class TyLoc> static inline |
| 2231 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2232 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2233 | NewT.setNameLoc(T.getNameLoc()); |
| 2234 | return T.getType(); |
| 2235 | } |
| 2236 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2237 | template<typename Derived> |
| 2238 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2239 | BuiltinTypeLoc T, |
| 2240 | QualType ObjectType) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2241 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2242 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2243 | if (T.needsExtraLocalData()) |
| 2244 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2245 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2246 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2247 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2248 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2249 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2250 | ComplexTypeLoc T, |
| 2251 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2252 | // FIXME: recurse? |
| 2253 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2254 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2255 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2256 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2257 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2258 | PointerTypeLoc TL, |
| 2259 | QualType ObjectType) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2260 | QualType PointeeType |
| 2261 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2262 | if (PointeeType.isNull()) |
| 2263 | return QualType(); |
| 2264 | |
| 2265 | QualType Result = TL.getType(); |
| 2266 | if (PointeeType->isObjCInterfaceType()) { |
| 2267 | // A dependent pointer type 'T *' has is being transformed such |
| 2268 | // that an Objective-C class type is being replaced for 'T'. The |
| 2269 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 2270 | // PointerType. |
| 2271 | const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>(); |
| 2272 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType, |
| 2273 | const_cast<ObjCProtocolDecl **>( |
| 2274 | IFace->qual_begin()), |
| 2275 | IFace->getNumProtocols()); |
| 2276 | |
| 2277 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 2278 | NewT.setStarLoc(TL.getSigilLoc()); |
| 2279 | NewT.setHasProtocolsAsWritten(false); |
| 2280 | NewT.setLAngleLoc(SourceLocation()); |
| 2281 | NewT.setRAngleLoc(SourceLocation()); |
| 2282 | NewT.setHasBaseTypeAsWritten(true); |
| 2283 | return Result; |
| 2284 | } |
| 2285 | |
| 2286 | if (getDerived().AlwaysRebuild() || |
| 2287 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2288 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 2289 | if (Result.isNull()) |
| 2290 | return QualType(); |
| 2291 | } |
| 2292 | |
| 2293 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 2294 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 2295 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2296 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2297 | |
| 2298 | template<typename Derived> |
| 2299 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2300 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2301 | BlockPointerTypeLoc TL, |
| 2302 | QualType ObjectType) { |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2303 | QualType PointeeType |
| 2304 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2305 | if (PointeeType.isNull()) |
| 2306 | return QualType(); |
| 2307 | |
| 2308 | QualType Result = TL.getType(); |
| 2309 | if (getDerived().AlwaysRebuild() || |
| 2310 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2311 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
| 2312 | TL.getSigilLoc()); |
| 2313 | if (Result.isNull()) |
| 2314 | return QualType(); |
| 2315 | } |
| 2316 | |
Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 2317 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2318 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 2319 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2320 | } |
| 2321 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2322 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2323 | /// don't care whether the type itself is an l-value type or an r-value |
| 2324 | /// type; we only care if the type was *written* as an l-value type |
| 2325 | /// or an r-value type. |
| 2326 | template<typename Derived> |
| 2327 | QualType |
| 2328 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2329 | ReferenceTypeLoc TL, |
| 2330 | QualType ObjectType) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2331 | const ReferenceType *T = TL.getTypePtr(); |
| 2332 | |
| 2333 | // Note that this works with the pointee-as-written. |
| 2334 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2335 | if (PointeeType.isNull()) |
| 2336 | return QualType(); |
| 2337 | |
| 2338 | QualType Result = TL.getType(); |
| 2339 | if (getDerived().AlwaysRebuild() || |
| 2340 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2341 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2342 | T->isSpelledAsLValue(), |
| 2343 | TL.getSigilLoc()); |
| 2344 | if (Result.isNull()) |
| 2345 | return QualType(); |
| 2346 | } |
| 2347 | |
| 2348 | // r-value references can be rebuilt as l-value references. |
| 2349 | ReferenceTypeLoc NewTL; |
| 2350 | if (isa<LValueReferenceType>(Result)) |
| 2351 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2352 | else |
| 2353 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2354 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2355 | |
| 2356 | return Result; |
| 2357 | } |
| 2358 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2359 | template<typename Derived> |
| 2360 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2361 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2362 | LValueReferenceTypeLoc TL, |
| 2363 | QualType ObjectType) { |
| 2364 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2365 | } |
| 2366 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2367 | template<typename Derived> |
| 2368 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2369 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2370 | RValueReferenceTypeLoc TL, |
| 2371 | QualType ObjectType) { |
| 2372 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2373 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2374 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2375 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2376 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2377 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2378 | MemberPointerTypeLoc TL, |
| 2379 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2380 | MemberPointerType *T = TL.getTypePtr(); |
| 2381 | |
| 2382 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2383 | if (PointeeType.isNull()) |
| 2384 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2385 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2386 | // TODO: preserve source information for this. |
| 2387 | QualType ClassType |
| 2388 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2389 | if (ClassType.isNull()) |
| 2390 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2391 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2392 | QualType Result = TL.getType(); |
| 2393 | if (getDerived().AlwaysRebuild() || |
| 2394 | PointeeType != T->getPointeeType() || |
| 2395 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2396 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2397 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2398 | if (Result.isNull()) |
| 2399 | return QualType(); |
| 2400 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2401 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2402 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2403 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2404 | |
| 2405 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2406 | } |
| 2407 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2408 | template<typename Derived> |
| 2409 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2410 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2411 | ConstantArrayTypeLoc TL, |
| 2412 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2413 | ConstantArrayType *T = TL.getTypePtr(); |
| 2414 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2415 | if (ElementType.isNull()) |
| 2416 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2417 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2418 | QualType Result = TL.getType(); |
| 2419 | if (getDerived().AlwaysRebuild() || |
| 2420 | ElementType != T->getElementType()) { |
| 2421 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2422 | T->getSizeModifier(), |
| 2423 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2424 | T->getIndexTypeCVRQualifiers(), |
| 2425 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2426 | if (Result.isNull()) |
| 2427 | return QualType(); |
| 2428 | } |
| 2429 | |
| 2430 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2431 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2432 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2433 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2434 | Expr *Size = TL.getSizeExpr(); |
| 2435 | if (Size) { |
| 2436 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2437 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2438 | } |
| 2439 | NewTL.setSizeExpr(Size); |
| 2440 | |
| 2441 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2442 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2443 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2444 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2445 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2446 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2447 | IncompleteArrayTypeLoc TL, |
| 2448 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2449 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2450 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2451 | if (ElementType.isNull()) |
| 2452 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2453 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2454 | QualType Result = TL.getType(); |
| 2455 | if (getDerived().AlwaysRebuild() || |
| 2456 | ElementType != T->getElementType()) { |
| 2457 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2458 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2459 | T->getIndexTypeCVRQualifiers(), |
| 2460 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2461 | if (Result.isNull()) |
| 2462 | return QualType(); |
| 2463 | } |
| 2464 | |
| 2465 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2466 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2467 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2468 | NewTL.setSizeExpr(0); |
| 2469 | |
| 2470 | return Result; |
| 2471 | } |
| 2472 | |
| 2473 | template<typename Derived> |
| 2474 | QualType |
| 2475 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2476 | VariableArrayTypeLoc TL, |
| 2477 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2478 | VariableArrayType *T = TL.getTypePtr(); |
| 2479 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2480 | if (ElementType.isNull()) |
| 2481 | return QualType(); |
| 2482 | |
| 2483 | // Array bounds are not potentially evaluated contexts |
| 2484 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2485 | |
| 2486 | Sema::OwningExprResult SizeResult |
| 2487 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2488 | if (SizeResult.isInvalid()) |
| 2489 | return QualType(); |
| 2490 | |
| 2491 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2492 | |
| 2493 | QualType Result = TL.getType(); |
| 2494 | if (getDerived().AlwaysRebuild() || |
| 2495 | ElementType != T->getElementType() || |
| 2496 | Size != T->getSizeExpr()) { |
| 2497 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2498 | T->getSizeModifier(), |
| 2499 | move(SizeResult), |
| 2500 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2501 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2502 | if (Result.isNull()) |
| 2503 | return QualType(); |
| 2504 | } |
| 2505 | else SizeResult.take(); |
| 2506 | |
| 2507 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2508 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2509 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2510 | NewTL.setSizeExpr(Size); |
| 2511 | |
| 2512 | return Result; |
| 2513 | } |
| 2514 | |
| 2515 | template<typename Derived> |
| 2516 | QualType |
| 2517 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2518 | DependentSizedArrayTypeLoc TL, |
| 2519 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2520 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2521 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2522 | if (ElementType.isNull()) |
| 2523 | return QualType(); |
| 2524 | |
| 2525 | // Array bounds are not potentially evaluated contexts |
| 2526 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2527 | |
| 2528 | Sema::OwningExprResult SizeResult |
| 2529 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2530 | if (SizeResult.isInvalid()) |
| 2531 | return QualType(); |
| 2532 | |
| 2533 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2534 | |
| 2535 | QualType Result = TL.getType(); |
| 2536 | if (getDerived().AlwaysRebuild() || |
| 2537 | ElementType != T->getElementType() || |
| 2538 | Size != T->getSizeExpr()) { |
| 2539 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2540 | T->getSizeModifier(), |
| 2541 | move(SizeResult), |
| 2542 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2543 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2544 | if (Result.isNull()) |
| 2545 | return QualType(); |
| 2546 | } |
| 2547 | else SizeResult.take(); |
| 2548 | |
| 2549 | // We might have any sort of array type now, but fortunately they |
| 2550 | // all have the same location layout. |
| 2551 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2552 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2553 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2554 | NewTL.setSizeExpr(Size); |
| 2555 | |
| 2556 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2557 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2558 | |
| 2559 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2560 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2561 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2562 | DependentSizedExtVectorTypeLoc TL, |
| 2563 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2564 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2565 | |
| 2566 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2567 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2568 | if (ElementType.isNull()) |
| 2569 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2570 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2571 | // Vector sizes are not potentially evaluated contexts |
| 2572 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2573 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2574 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2575 | if (Size.isInvalid()) |
| 2576 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2577 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2578 | QualType Result = TL.getType(); |
| 2579 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2580 | ElementType != T->getElementType() || |
| 2581 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2582 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2583 | move(Size), |
| 2584 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2585 | if (Result.isNull()) |
| 2586 | return QualType(); |
| 2587 | } |
| 2588 | else Size.take(); |
| 2589 | |
| 2590 | // Result might be dependent or not. |
| 2591 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2592 | DependentSizedExtVectorTypeLoc NewTL |
| 2593 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2594 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2595 | } else { |
| 2596 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2597 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2598 | } |
| 2599 | |
| 2600 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2601 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2602 | |
| 2603 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2604 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2605 | VectorTypeLoc TL, |
| 2606 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2607 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2608 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2609 | if (ElementType.isNull()) |
| 2610 | return QualType(); |
| 2611 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2612 | QualType Result = TL.getType(); |
| 2613 | if (getDerived().AlwaysRebuild() || |
| 2614 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2615 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 2616 | T->isAltiVec(), T->isPixel()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2617 | if (Result.isNull()) |
| 2618 | return QualType(); |
| 2619 | } |
| 2620 | |
| 2621 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2622 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2623 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2624 | return Result; |
| 2625 | } |
| 2626 | |
| 2627 | template<typename Derived> |
| 2628 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2629 | ExtVectorTypeLoc TL, |
| 2630 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2631 | VectorType *T = TL.getTypePtr(); |
| 2632 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2633 | if (ElementType.isNull()) |
| 2634 | return QualType(); |
| 2635 | |
| 2636 | QualType Result = TL.getType(); |
| 2637 | if (getDerived().AlwaysRebuild() || |
| 2638 | ElementType != T->getElementType()) { |
| 2639 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2640 | T->getNumElements(), |
| 2641 | /*FIXME*/ SourceLocation()); |
| 2642 | if (Result.isNull()) |
| 2643 | return QualType(); |
| 2644 | } |
| 2645 | |
| 2646 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2647 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2648 | |
| 2649 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2650 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2651 | |
| 2652 | template<typename Derived> |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2653 | ParmVarDecl * |
| 2654 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) { |
| 2655 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| 2656 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
| 2657 | if (!NewDI) |
| 2658 | return 0; |
| 2659 | |
| 2660 | if (NewDI == OldDI) |
| 2661 | return OldParm; |
| 2662 | else |
| 2663 | return ParmVarDecl::Create(SemaRef.Context, |
| 2664 | OldParm->getDeclContext(), |
| 2665 | OldParm->getLocation(), |
| 2666 | OldParm->getIdentifier(), |
| 2667 | NewDI->getType(), |
| 2668 | NewDI, |
| 2669 | OldParm->getStorageClass(), |
Douglas Gregor | c4df407 | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 2670 | OldParm->getStorageClassAsWritten(), |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2671 | /* DefArg */ NULL); |
| 2672 | } |
| 2673 | |
| 2674 | template<typename Derived> |
| 2675 | bool TreeTransform<Derived>:: |
| 2676 | TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 2677 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 2678 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars) { |
| 2679 | FunctionProtoType *T = TL.getTypePtr(); |
| 2680 | |
| 2681 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2682 | ParmVarDecl *OldParm = TL.getArg(i); |
| 2683 | |
| 2684 | QualType NewType; |
| 2685 | ParmVarDecl *NewParm; |
| 2686 | |
| 2687 | if (OldParm) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2688 | NewParm = getDerived().TransformFunctionTypeParam(OldParm); |
| 2689 | if (!NewParm) |
| 2690 | return true; |
| 2691 | NewType = NewParm->getType(); |
| 2692 | |
| 2693 | // Deal with the possibility that we don't have a parameter |
| 2694 | // declaration for this parameter. |
| 2695 | } else { |
| 2696 | NewParm = 0; |
| 2697 | |
| 2698 | QualType OldType = T->getArgType(i); |
| 2699 | NewType = getDerived().TransformType(OldType); |
| 2700 | if (NewType.isNull()) |
| 2701 | return true; |
| 2702 | } |
| 2703 | |
| 2704 | PTypes.push_back(NewType); |
| 2705 | PVars.push_back(NewParm); |
| 2706 | } |
| 2707 | |
| 2708 | return false; |
| 2709 | } |
| 2710 | |
| 2711 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2712 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2713 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2714 | FunctionProtoTypeLoc TL, |
| 2715 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2716 | FunctionProtoType *T = TL.getTypePtr(); |
| 2717 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2718 | if (ResultType.isNull()) |
| 2719 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2720 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2721 | // Transform the parameters. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2722 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2723 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2724 | if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls)) |
| 2725 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2726 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2727 | QualType Result = TL.getType(); |
| 2728 | if (getDerived().AlwaysRebuild() || |
| 2729 | ResultType != T->getResultType() || |
| 2730 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2731 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2732 | ParamTypes.data(), |
| 2733 | ParamTypes.size(), |
| 2734 | T->isVariadic(), |
| 2735 | T->getTypeQuals()); |
| 2736 | if (Result.isNull()) |
| 2737 | return QualType(); |
| 2738 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2739 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2740 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2741 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2742 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2743 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2744 | NewTL.setArg(i, ParamDecls[i]); |
| 2745 | |
| 2746 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2747 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2748 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2749 | template<typename Derived> |
| 2750 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2751 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2752 | FunctionNoProtoTypeLoc TL, |
| 2753 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2754 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2755 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2756 | if (ResultType.isNull()) |
| 2757 | return QualType(); |
| 2758 | |
| 2759 | QualType Result = TL.getType(); |
| 2760 | if (getDerived().AlwaysRebuild() || |
| 2761 | ResultType != T->getResultType()) |
| 2762 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2763 | |
| 2764 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2765 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2766 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2767 | |
| 2768 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2769 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2770 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2771 | template<typename Derived> QualType |
| 2772 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2773 | UnresolvedUsingTypeLoc TL, |
| 2774 | QualType ObjectType) { |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2775 | UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2776 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2777 | if (!D) |
| 2778 | return QualType(); |
| 2779 | |
| 2780 | QualType Result = TL.getType(); |
| 2781 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2782 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2783 | if (Result.isNull()) |
| 2784 | return QualType(); |
| 2785 | } |
| 2786 | |
| 2787 | // We might get an arbitrary type spec type back. We should at |
| 2788 | // least always get a type spec type, though. |
| 2789 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2790 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2791 | |
| 2792 | return Result; |
| 2793 | } |
| 2794 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2795 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2796 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2797 | TypedefTypeLoc TL, |
| 2798 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2799 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2800 | TypedefDecl *Typedef |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2801 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2802 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2803 | if (!Typedef) |
| 2804 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2805 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2806 | QualType Result = TL.getType(); |
| 2807 | if (getDerived().AlwaysRebuild() || |
| 2808 | Typedef != T->getDecl()) { |
| 2809 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2810 | if (Result.isNull()) |
| 2811 | return QualType(); |
| 2812 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2813 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2814 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2815 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2816 | |
| 2817 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2818 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2819 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2820 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2821 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2822 | TypeOfExprTypeLoc TL, |
| 2823 | QualType ObjectType) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2824 | // typeof expressions are not potentially evaluated contexts |
| 2825 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2826 | |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2827 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2828 | if (E.isInvalid()) |
| 2829 | return QualType(); |
| 2830 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2831 | QualType Result = TL.getType(); |
| 2832 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2833 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2834 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2835 | if (Result.isNull()) |
| 2836 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2837 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2838 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2839 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2840 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2841 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2842 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2843 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2844 | |
| 2845 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2846 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2847 | |
| 2848 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2849 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2850 | TypeOfTypeLoc TL, |
| 2851 | QualType ObjectType) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2852 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 2853 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 2854 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2855 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2856 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2857 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2858 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 2859 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2860 | if (Result.isNull()) |
| 2861 | return QualType(); |
| 2862 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2863 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2864 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2865 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2866 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2867 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2868 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2869 | |
| 2870 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2871 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2872 | |
| 2873 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2874 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2875 | DecltypeTypeLoc TL, |
| 2876 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2877 | DecltypeType *T = TL.getTypePtr(); |
| 2878 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2879 | // decltype expressions are not potentially evaluated contexts |
| 2880 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2881 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2882 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2883 | if (E.isInvalid()) |
| 2884 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2885 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2886 | QualType Result = TL.getType(); |
| 2887 | if (getDerived().AlwaysRebuild() || |
| 2888 | E.get() != T->getUnderlyingExpr()) { |
| 2889 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2890 | if (Result.isNull()) |
| 2891 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2892 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2893 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2894 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2895 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2896 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2897 | |
| 2898 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2899 | } |
| 2900 | |
| 2901 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2902 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2903 | RecordTypeLoc TL, |
| 2904 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2905 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2906 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2907 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2908 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2909 | if (!Record) |
| 2910 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2911 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2912 | QualType Result = TL.getType(); |
| 2913 | if (getDerived().AlwaysRebuild() || |
| 2914 | Record != T->getDecl()) { |
| 2915 | Result = getDerived().RebuildRecordType(Record); |
| 2916 | if (Result.isNull()) |
| 2917 | return QualType(); |
| 2918 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2919 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2920 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2921 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2922 | |
| 2923 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2924 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2925 | |
| 2926 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2927 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2928 | EnumTypeLoc TL, |
| 2929 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2930 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2931 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2932 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2933 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2934 | if (!Enum) |
| 2935 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2936 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2937 | QualType Result = TL.getType(); |
| 2938 | if (getDerived().AlwaysRebuild() || |
| 2939 | Enum != T->getDecl()) { |
| 2940 | Result = getDerived().RebuildEnumType(Enum); |
| 2941 | if (Result.isNull()) |
| 2942 | return QualType(); |
| 2943 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2944 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2945 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2946 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2947 | |
| 2948 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2949 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2950 | |
| 2951 | template <typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2952 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2953 | ElaboratedTypeLoc TL, |
| 2954 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2955 | ElaboratedType *T = TL.getTypePtr(); |
| 2956 | |
| 2957 | // FIXME: this should be a nested type. |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2958 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2959 | if (Underlying.isNull()) |
| 2960 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2961 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2962 | QualType Result = TL.getType(); |
| 2963 | if (getDerived().AlwaysRebuild() || |
| 2964 | Underlying != T->getUnderlyingType()) { |
| 2965 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2966 | if (Result.isNull()) |
| 2967 | return QualType(); |
| 2968 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2969 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2970 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2971 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2972 | |
| 2973 | return Result; |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2974 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2975 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 2976 | template<typename Derived> |
| 2977 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 2978 | TypeLocBuilder &TLB, |
| 2979 | InjectedClassNameTypeLoc TL, |
| 2980 | QualType ObjectType) { |
| 2981 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 2982 | TL.getTypePtr()->getDecl()); |
| 2983 | if (!D) return QualType(); |
| 2984 | |
| 2985 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 2986 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 2987 | return T; |
| 2988 | } |
| 2989 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2990 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2991 | template<typename Derived> |
| 2992 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2993 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2994 | TemplateTypeParmTypeLoc TL, |
| 2995 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2996 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2997 | } |
| 2998 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2999 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3000 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3001 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3002 | SubstTemplateTypeParmTypeLoc TL, |
| 3003 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3004 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3005 | } |
| 3006 | |
| 3007 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3008 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 3009 | const TemplateSpecializationType *TST, |
| 3010 | QualType ObjectType) { |
| 3011 | // FIXME: this entire method is a temporary workaround; callers |
| 3012 | // should be rewritten to provide real type locs. |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3013 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3014 | // Fake up a TemplateSpecializationTypeLoc. |
| 3015 | TypeLocBuilder TLB; |
| 3016 | TemplateSpecializationTypeLoc TL |
| 3017 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 3018 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3019 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 3020 | |
| 3021 | TL.setTemplateNameLoc(BaseLoc); |
| 3022 | TL.setLAngleLoc(BaseLoc); |
| 3023 | TL.setRAngleLoc(BaseLoc); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3024 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 3025 | const TemplateArgument &TA = TST->getArg(i); |
| 3026 | TemplateArgumentLoc TAL; |
| 3027 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 3028 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 3029 | } |
| 3030 | |
| 3031 | TypeLocBuilder IgnoredTLB; |
| 3032 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3033 | } |
| 3034 | |
| 3035 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3036 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3037 | TypeLocBuilder &TLB, |
| 3038 | TemplateSpecializationTypeLoc TL, |
| 3039 | QualType ObjectType) { |
| 3040 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 3041 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3042 | TemplateName Template |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3043 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3044 | if (Template.isNull()) |
| 3045 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3046 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3047 | TemplateArgumentListInfo NewTemplateArgs; |
| 3048 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 3049 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 3050 | |
| 3051 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 3052 | TemplateArgumentLoc Loc; |
| 3053 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3054 | return QualType(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3055 | NewTemplateArgs.addArgument(Loc); |
| 3056 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3057 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3058 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 3059 | |
| 3060 | QualType Result = |
| 3061 | getDerived().RebuildTemplateSpecializationType(Template, |
| 3062 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3063 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3064 | |
| 3065 | if (!Result.isNull()) { |
| 3066 | TemplateSpecializationTypeLoc NewTL |
| 3067 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 3068 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 3069 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 3070 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 3071 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 3072 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3073 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3074 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3075 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3076 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3077 | |
| 3078 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3079 | QualType |
| 3080 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3081 | QualifiedNameTypeLoc TL, |
| 3082 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3083 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3084 | NestedNameSpecifier *NNS |
| 3085 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3086 | SourceRange(), |
| 3087 | ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3088 | if (!NNS) |
| 3089 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3090 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3091 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 3092 | if (Named.isNull()) |
| 3093 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3094 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3095 | QualType Result = TL.getType(); |
| 3096 | if (getDerived().AlwaysRebuild() || |
| 3097 | NNS != T->getQualifier() || |
| 3098 | Named != T->getNamedType()) { |
| 3099 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 3100 | if (Result.isNull()) |
| 3101 | return QualType(); |
| 3102 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3103 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3104 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 3105 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3106 | |
| 3107 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3108 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3109 | |
| 3110 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3111 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
| 3112 | DependentNameTypeLoc TL, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3113 | QualType ObjectType) { |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3114 | DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3115 | |
| 3116 | /* FIXME: preserve source information better than this */ |
| 3117 | SourceRange SR(TL.getNameLoc()); |
| 3118 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3119 | NestedNameSpecifier *NNS |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3120 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3121 | ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3122 | if (!NNS) |
| 3123 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3124 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3125 | QualType Result; |
| 3126 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3127 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3128 | QualType NewTemplateId |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3129 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 3130 | if (NewTemplateId.isNull()) |
| 3131 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3132 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3133 | if (!getDerived().AlwaysRebuild() && |
| 3134 | NNS == T->getQualifier() && |
| 3135 | NewTemplateId == QualType(TemplateId, 0)) |
| 3136 | return QualType(T, 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3137 | |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3138 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 3139 | NewTemplateId); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3140 | } else { |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3141 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 3142 | T->getIdentifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3143 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3144 | if (Result.isNull()) |
| 3145 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3146 | |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3147 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3148 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3149 | |
| 3150 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3151 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3152 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3153 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3154 | QualType |
| 3155 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3156 | ObjCInterfaceTypeLoc TL, |
| 3157 | QualType ObjectType) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame^] | 3158 | // ObjCInterfaceType is never dependent. |
| 3159 | return TL.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3160 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3161 | |
| 3162 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3163 | QualType |
| 3164 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3165 | ObjCObjectPointerTypeLoc TL, |
| 3166 | QualType ObjectType) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame^] | 3167 | // ObjCObjectPointerType is never dependent. |
| 3168 | return TL.getType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3169 | } |
| 3170 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3171 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3172 | // Statement transformation |
| 3173 | //===----------------------------------------------------------------------===// |
| 3174 | template<typename Derived> |
| 3175 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3176 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3177 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3178 | } |
| 3179 | |
| 3180 | template<typename Derived> |
| 3181 | Sema::OwningStmtResult |
| 3182 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3183 | return getDerived().TransformCompoundStmt(S, false); |
| 3184 | } |
| 3185 | |
| 3186 | template<typename Derived> |
| 3187 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3188 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3189 | bool IsStmtExpr) { |
| 3190 | bool SubStmtChanged = false; |
| 3191 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3192 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3193 | B != BEnd; ++B) { |
| 3194 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3195 | if (Result.isInvalid()) |
| 3196 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3197 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3198 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3199 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3200 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3201 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3202 | if (!getDerived().AlwaysRebuild() && |
| 3203 | !SubStmtChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3204 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3205 | |
| 3206 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3207 | move_arg(Statements), |
| 3208 | S->getRBracLoc(), |
| 3209 | IsStmtExpr); |
| 3210 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3211 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3212 | template<typename Derived> |
| 3213 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3214 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3215 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3216 | { |
| 3217 | // The case value expressions are not potentially evaluated. |
| 3218 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3219 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3220 | // Transform the left-hand case value. |
| 3221 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3222 | if (LHS.isInvalid()) |
| 3223 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3224 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3225 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3226 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3227 | if (RHS.isInvalid()) |
| 3228 | return SemaRef.StmtError(); |
| 3229 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3230 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3231 | // Build the case statement. |
| 3232 | // Case statements are always rebuilt so that they will attached to their |
| 3233 | // transformed switch statement. |
| 3234 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3235 | move(LHS), |
| 3236 | S->getEllipsisLoc(), |
| 3237 | move(RHS), |
| 3238 | S->getColonLoc()); |
| 3239 | if (Case.isInvalid()) |
| 3240 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3241 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3242 | // Transform the statement following the case |
| 3243 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3244 | if (SubStmt.isInvalid()) |
| 3245 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3246 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3247 | // Attach the body to the case statement |
| 3248 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3249 | } |
| 3250 | |
| 3251 | template<typename Derived> |
| 3252 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3253 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3254 | // Transform the statement following the default case |
| 3255 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3256 | if (SubStmt.isInvalid()) |
| 3257 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3258 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3259 | // Default statements are always rebuilt |
| 3260 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3261 | move(SubStmt)); |
| 3262 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3263 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3264 | template<typename Derived> |
| 3265 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3266 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3267 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3268 | if (SubStmt.isInvalid()) |
| 3269 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3270 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3271 | // FIXME: Pass the real colon location in. |
| 3272 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3273 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3274 | move(SubStmt)); |
| 3275 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3276 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3277 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3278 | Sema::OwningStmtResult |
| 3279 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3280 | // Transform the condition |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3281 | OwningExprResult Cond(SemaRef); |
| 3282 | VarDecl *ConditionVar = 0; |
| 3283 | if (S->getConditionVariable()) { |
| 3284 | ConditionVar |
| 3285 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3286 | getDerived().TransformDefinition( |
| 3287 | S->getConditionVariable()->getLocation(), |
| 3288 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3289 | if (!ConditionVar) |
| 3290 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3291 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3292 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3293 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3294 | if (Cond.isInvalid()) |
| 3295 | return SemaRef.StmtError(); |
| 3296 | } |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3297 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3298 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3299 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3300 | // Transform the "then" branch. |
| 3301 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3302 | if (Then.isInvalid()) |
| 3303 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3304 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3305 | // Transform the "else" branch. |
| 3306 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3307 | if (Else.isInvalid()) |
| 3308 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3309 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3310 | if (!getDerived().AlwaysRebuild() && |
| 3311 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3312 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3313 | Then.get() == S->getThen() && |
| 3314 | Else.get() == S->getElse()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3315 | return SemaRef.Owned(S->Retain()); |
| 3316 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3317 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3318 | move(Then), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3319 | S->getElseLoc(), move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3320 | } |
| 3321 | |
| 3322 | template<typename Derived> |
| 3323 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3324 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3325 | // Transform the condition. |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3326 | OwningExprResult Cond(SemaRef); |
| 3327 | VarDecl *ConditionVar = 0; |
| 3328 | if (S->getConditionVariable()) { |
| 3329 | ConditionVar |
| 3330 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3331 | getDerived().TransformDefinition( |
| 3332 | S->getConditionVariable()->getLocation(), |
| 3333 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3334 | if (!ConditionVar) |
| 3335 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3336 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3337 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3338 | |
| 3339 | if (Cond.isInvalid()) |
| 3340 | return SemaRef.StmtError(); |
| 3341 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3342 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3343 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3344 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3345 | // Rebuild the switch statement. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3346 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3347 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3348 | if (Switch.isInvalid()) |
| 3349 | return SemaRef.StmtError(); |
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 | // Transform the body of the switch statement. |
| 3352 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3353 | if (Body.isInvalid()) |
| 3354 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3355 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3356 | // Complete the switch statement. |
| 3357 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3358 | move(Body)); |
| 3359 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3360 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3361 | template<typename Derived> |
| 3362 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3363 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3364 | // Transform the condition |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3365 | OwningExprResult Cond(SemaRef); |
| 3366 | VarDecl *ConditionVar = 0; |
| 3367 | if (S->getConditionVariable()) { |
| 3368 | ConditionVar |
| 3369 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3370 | getDerived().TransformDefinition( |
| 3371 | S->getConditionVariable()->getLocation(), |
| 3372 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3373 | if (!ConditionVar) |
| 3374 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3375 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3376 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3377 | |
| 3378 | if (Cond.isInvalid()) |
| 3379 | return SemaRef.StmtError(); |
| 3380 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3381 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3382 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3383 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3384 | // Transform the body |
| 3385 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3386 | if (Body.isInvalid()) |
| 3387 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3388 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3389 | if (!getDerived().AlwaysRebuild() && |
| 3390 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3391 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3392 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3393 | return SemaRef.Owned(S->Retain()); |
| 3394 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3395 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3396 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3397 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3398 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3399 | template<typename Derived> |
| 3400 | Sema::OwningStmtResult |
| 3401 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3402 | // Transform the condition |
| 3403 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3404 | if (Cond.isInvalid()) |
| 3405 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3406 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3407 | // Transform the body |
| 3408 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3409 | if (Body.isInvalid()) |
| 3410 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3411 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3412 | if (!getDerived().AlwaysRebuild() && |
| 3413 | Cond.get() == S->getCond() && |
| 3414 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3415 | return SemaRef.Owned(S->Retain()); |
| 3416 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3417 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3418 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3419 | S->getRParenLoc()); |
| 3420 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3421 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3422 | template<typename Derived> |
| 3423 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3424 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3425 | // Transform the initialization statement |
| 3426 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3427 | if (Init.isInvalid()) |
| 3428 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3429 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3430 | // Transform the condition |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3431 | OwningExprResult Cond(SemaRef); |
| 3432 | VarDecl *ConditionVar = 0; |
| 3433 | if (S->getConditionVariable()) { |
| 3434 | ConditionVar |
| 3435 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3436 | getDerived().TransformDefinition( |
| 3437 | S->getConditionVariable()->getLocation(), |
| 3438 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3439 | if (!ConditionVar) |
| 3440 | return SemaRef.StmtError(); |
| 3441 | } else { |
| 3442 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3443 | |
| 3444 | if (Cond.isInvalid()) |
| 3445 | return SemaRef.StmtError(); |
| 3446 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3447 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3448 | // Transform the increment |
| 3449 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3450 | if (Inc.isInvalid()) |
| 3451 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3452 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3453 | // Transform the body |
| 3454 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3455 | if (Body.isInvalid()) |
| 3456 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3457 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3458 | if (!getDerived().AlwaysRebuild() && |
| 3459 | Init.get() == S->getInit() && |
| 3460 | Cond.get() == S->getCond() && |
| 3461 | Inc.get() == S->getInc() && |
| 3462 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3463 | return SemaRef.Owned(S->Retain()); |
| 3464 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3465 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3466 | move(Init), getSema().MakeFullExpr(Cond), |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3467 | ConditionVar, |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3468 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3469 | S->getRParenLoc(), move(Body)); |
| 3470 | } |
| 3471 | |
| 3472 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3473 | Sema::OwningStmtResult |
| 3474 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3475 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3476 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3477 | S->getLabel()); |
| 3478 | } |
| 3479 | |
| 3480 | template<typename Derived> |
| 3481 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3482 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3483 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3484 | if (Target.isInvalid()) |
| 3485 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3486 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3487 | if (!getDerived().AlwaysRebuild() && |
| 3488 | Target.get() == S->getTarget()) |
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 | |
| 3491 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3492 | move(Target)); |
| 3493 | } |
| 3494 | |
| 3495 | template<typename Derived> |
| 3496 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3497 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3498 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3499 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3500 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3501 | template<typename Derived> |
| 3502 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3503 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3504 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3505 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3506 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3507 | template<typename Derived> |
| 3508 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3509 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3510 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3511 | if (Result.isInvalid()) |
| 3512 | return SemaRef.StmtError(); |
| 3513 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3514 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3515 | // to tell whether the return type of the function has changed. |
| 3516 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3517 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3518 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3519 | template<typename Derived> |
| 3520 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3521 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3522 | bool DeclChanged = false; |
| 3523 | llvm::SmallVector<Decl *, 4> Decls; |
| 3524 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3525 | D != DEnd; ++D) { |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3526 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 3527 | *D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3528 | if (!Transformed) |
| 3529 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3530 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3531 | if (Transformed != *D) |
| 3532 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3533 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3534 | Decls.push_back(Transformed); |
| 3535 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3536 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3537 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3538 | return SemaRef.Owned(S->Retain()); |
| 3539 | |
| 3540 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3541 | S->getStartLoc(), S->getEndLoc()); |
| 3542 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3543 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3544 | template<typename Derived> |
| 3545 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3546 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3547 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3548 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3549 | } |
| 3550 | |
| 3551 | template<typename Derived> |
| 3552 | Sema::OwningStmtResult |
| 3553 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3554 | |
| 3555 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3556 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3557 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3558 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3559 | OwningExprResult AsmString(SemaRef); |
| 3560 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3561 | |
| 3562 | bool ExprsChanged = false; |
| 3563 | |
| 3564 | // Go through the outputs. |
| 3565 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3566 | Names.push_back(S->getOutputIdentifier(I)); |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3567 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3568 | // No need to transform the constraint literal. |
| 3569 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
| 3570 | |
| 3571 | // Transform the output expr. |
| 3572 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3573 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3574 | if (Result.isInvalid()) |
| 3575 | return SemaRef.StmtError(); |
| 3576 | |
| 3577 | ExprsChanged |= Result.get() != OutputExpr; |
| 3578 | |
| 3579 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3580 | } |
| 3581 | |
| 3582 | // Go through the inputs. |
| 3583 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3584 | Names.push_back(S->getInputIdentifier(I)); |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3585 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3586 | // No need to transform the constraint literal. |
| 3587 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
| 3588 | |
| 3589 | // Transform the input expr. |
| 3590 | Expr *InputExpr = S->getInputExpr(I); |
| 3591 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3592 | if (Result.isInvalid()) |
| 3593 | return SemaRef.StmtError(); |
| 3594 | |
| 3595 | ExprsChanged |= Result.get() != InputExpr; |
| 3596 | |
| 3597 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3598 | } |
| 3599 | |
| 3600 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3601 | return SemaRef.Owned(S->Retain()); |
| 3602 | |
| 3603 | // Go through the clobbers. |
| 3604 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3605 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3606 | |
| 3607 | // No need to transform the asm string literal. |
| 3608 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3609 | |
| 3610 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3611 | S->isSimple(), |
| 3612 | S->isVolatile(), |
| 3613 | S->getNumOutputs(), |
| 3614 | S->getNumInputs(), |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3615 | Names.data(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3616 | move_arg(Constraints), |
| 3617 | move_arg(Exprs), |
| 3618 | move(AsmString), |
| 3619 | move_arg(Clobbers), |
| 3620 | S->getRParenLoc(), |
| 3621 | S->isMSAsm()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3622 | } |
| 3623 | |
| 3624 | |
| 3625 | template<typename Derived> |
| 3626 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3627 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3628 | // FIXME: Implement this |
| 3629 | assert(false && "Cannot transform an Objective-C @try statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3630 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3631 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3632 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3633 | template<typename Derived> |
| 3634 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3635 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3636 | // FIXME: Implement this |
| 3637 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3638 | return SemaRef.Owned(S->Retain()); |
| 3639 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3640 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3641 | template<typename Derived> |
| 3642 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3643 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3644 | // FIXME: Implement this |
| 3645 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3646 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3647 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3648 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3649 | template<typename Derived> |
| 3650 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3651 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3652 | // FIXME: Implement this |
| 3653 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3654 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3655 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3656 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3657 | template<typename Derived> |
| 3658 | Sema::OwningStmtResult |
| 3659 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3660 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3661 | // FIXME: Implement this |
| 3662 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3663 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3664 | } |
| 3665 | |
| 3666 | template<typename Derived> |
| 3667 | Sema::OwningStmtResult |
| 3668 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3669 | ObjCForCollectionStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3670 | // FIXME: Implement this |
| 3671 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3672 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3673 | } |
| 3674 | |
| 3675 | |
| 3676 | template<typename Derived> |
| 3677 | Sema::OwningStmtResult |
| 3678 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3679 | // Transform the exception declaration, if any. |
| 3680 | VarDecl *Var = 0; |
| 3681 | if (S->getExceptionDecl()) { |
| 3682 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3683 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3684 | ExceptionDecl->getDeclName()); |
| 3685 | |
| 3686 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3687 | if (T.isNull()) |
| 3688 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3689 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3690 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3691 | T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3692 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3693 | ExceptionDecl->getIdentifier(), |
| 3694 | ExceptionDecl->getLocation(), |
| 3695 | /*FIXME: Inaccurate*/ |
| 3696 | SourceRange(ExceptionDecl->getLocation())); |
| 3697 | if (!Var || Var->isInvalidDecl()) { |
| 3698 | if (Var) |
| 3699 | Var->Destroy(SemaRef.Context); |
| 3700 | return SemaRef.StmtError(); |
| 3701 | } |
| 3702 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3703 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3704 | // Transform the actual exception handler. |
| 3705 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3706 | if (Handler.isInvalid()) { |
| 3707 | if (Var) |
| 3708 | Var->Destroy(SemaRef.Context); |
| 3709 | return SemaRef.StmtError(); |
| 3710 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3711 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3712 | if (!getDerived().AlwaysRebuild() && |
| 3713 | !Var && |
| 3714 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3715 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3716 | |
| 3717 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3718 | Var, |
| 3719 | move(Handler)); |
| 3720 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3721 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3722 | template<typename Derived> |
| 3723 | Sema::OwningStmtResult |
| 3724 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3725 | // Transform the try block itself. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3726 | OwningStmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3727 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3728 | if (TryBlock.isInvalid()) |
| 3729 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3730 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3731 | // Transform the handlers. |
| 3732 | bool HandlerChanged = false; |
| 3733 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3734 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3735 | OwningStmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3736 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3737 | if (Handler.isInvalid()) |
| 3738 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3739 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3740 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3741 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3742 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3743 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3744 | if (!getDerived().AlwaysRebuild() && |
| 3745 | TryBlock.get() == S->getTryBlock() && |
| 3746 | !HandlerChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3747 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3748 | |
| 3749 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3750 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3751 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3752 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3753 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3754 | // Expression transformation |
| 3755 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3756 | template<typename Derived> |
| 3757 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3758 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3759 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3760 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3761 | |
| 3762 | template<typename Derived> |
| 3763 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3764 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3765 | NestedNameSpecifier *Qualifier = 0; |
| 3766 | if (E->getQualifier()) { |
| 3767 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3768 | E->getQualifierRange()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3769 | if (!Qualifier) |
| 3770 | return SemaRef.ExprError(); |
| 3771 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3772 | |
| 3773 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3774 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 3775 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3776 | if (!ND) |
| 3777 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3778 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3779 | if (!getDerived().AlwaysRebuild() && |
| 3780 | Qualifier == E->getQualifier() && |
| 3781 | ND == E->getDecl() && |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3782 | !E->hasExplicitTemplateArgumentList()) { |
| 3783 | |
| 3784 | // Mark it referenced in the new context regardless. |
| 3785 | // FIXME: this is a bit instantiation-specific. |
| 3786 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 3787 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3788 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3789 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3790 | |
| 3791 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 3792 | if (E->hasExplicitTemplateArgumentList()) { |
| 3793 | TemplateArgs = &TransArgs; |
| 3794 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3795 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 3796 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3797 | TemplateArgumentLoc Loc; |
| 3798 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 3799 | return SemaRef.ExprError(); |
| 3800 | TransArgs.addArgument(Loc); |
| 3801 | } |
| 3802 | } |
| 3803 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3804 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3805 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3806 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3807 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3808 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3809 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3810 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3811 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3812 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3813 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3814 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3815 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3816 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3817 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3818 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3819 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3820 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3821 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3822 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3823 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3824 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3825 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3826 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3827 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3828 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3829 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3830 | } |
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 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3833 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3834 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3835 | return SemaRef.Owned(E->Retain()); |
| 3836 | } |
| 3837 | |
| 3838 | template<typename Derived> |
| 3839 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3840 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3841 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3842 | if (SubExpr.isInvalid()) |
| 3843 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3844 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3845 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3846 | return SemaRef.Owned(E->Retain()); |
| 3847 | |
| 3848 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3849 | E->getRParen()); |
| 3850 | } |
| 3851 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3852 | template<typename Derived> |
| 3853 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3854 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 3855 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3856 | if (SubExpr.isInvalid()) |
| 3857 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3858 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3859 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3860 | return SemaRef.Owned(E->Retain()); |
| 3861 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3862 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3863 | E->getOpcode(), |
| 3864 | move(SubExpr)); |
| 3865 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3866 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3867 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3868 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3869 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3870 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3871 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3872 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3873 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3874 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3875 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3876 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3877 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3878 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3879 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3880 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3881 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3882 | E->getSourceRange()); |
| 3883 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3884 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3885 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3886 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3887 | // C++0x [expr.sizeof]p1: |
| 3888 | // The operand is either an expression, which is an unevaluated operand |
| 3889 | // [...] |
| 3890 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3891 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3892 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3893 | if (SubExpr.isInvalid()) |
| 3894 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3895 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3896 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3897 | return SemaRef.Owned(E->Retain()); |
| 3898 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3899 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3900 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3901 | E->isSizeOf(), |
| 3902 | E->getSourceRange()); |
| 3903 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3904 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3905 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3906 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3907 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3908 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3909 | if (LHS.isInvalid()) |
| 3910 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3911 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3912 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3913 | if (RHS.isInvalid()) |
| 3914 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3915 | |
| 3916 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3917 | if (!getDerived().AlwaysRebuild() && |
| 3918 | LHS.get() == E->getLHS() && |
| 3919 | RHS.get() == E->getRHS()) |
| 3920 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3921 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3922 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3923 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3924 | move(RHS), |
| 3925 | E->getRBracketLoc()); |
| 3926 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3927 | |
| 3928 | template<typename Derived> |
| 3929 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3930 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3931 | // Transform the callee. |
| 3932 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3933 | if (Callee.isInvalid()) |
| 3934 | return SemaRef.ExprError(); |
| 3935 | |
| 3936 | // Transform arguments. |
| 3937 | bool ArgChanged = false; |
| 3938 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3939 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3940 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3941 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3942 | if (Arg.isInvalid()) |
| 3943 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3944 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3945 | // FIXME: Wrong source location information for the ','. |
| 3946 | FakeCommaLocs.push_back( |
| 3947 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3948 | |
| 3949 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3950 | Args.push_back(Arg.takeAs<Expr>()); |
| 3951 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3952 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3953 | if (!getDerived().AlwaysRebuild() && |
| 3954 | Callee.get() == E->getCallee() && |
| 3955 | !ArgChanged) |
| 3956 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3957 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3958 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3959 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3960 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3961 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3962 | move_arg(Args), |
| 3963 | FakeCommaLocs.data(), |
| 3964 | E->getRParenLoc()); |
| 3965 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3966 | |
| 3967 | template<typename Derived> |
| 3968 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3969 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3970 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3971 | if (Base.isInvalid()) |
| 3972 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3973 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3974 | NestedNameSpecifier *Qualifier = 0; |
| 3975 | if (E->hasQualifier()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3976 | Qualifier |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3977 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3978 | E->getQualifierRange()); |
Douglas Gregor | 84f14dd | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3979 | if (Qualifier == 0) |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3980 | return SemaRef.ExprError(); |
| 3981 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3982 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 3983 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3984 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 3985 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3986 | if (!Member) |
| 3987 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3988 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 3989 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 3990 | if (FoundDecl == E->getMemberDecl()) { |
| 3991 | FoundDecl = Member; |
| 3992 | } else { |
| 3993 | FoundDecl = cast_or_null<NamedDecl>( |
| 3994 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 3995 | if (!FoundDecl) |
| 3996 | return SemaRef.ExprError(); |
| 3997 | } |
| 3998 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3999 | if (!getDerived().AlwaysRebuild() && |
| 4000 | Base.get() == E->getBase() && |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4001 | Qualifier == E->getQualifier() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4002 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4003 | FoundDecl == E->getFoundDecl() && |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4004 | !E->hasExplicitTemplateArgumentList()) { |
| 4005 | |
| 4006 | // Mark it referenced in the new context regardless. |
| 4007 | // FIXME: this is a bit instantiation-specific. |
| 4008 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4009 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4010 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4011 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4012 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4013 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4014 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4015 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4016 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4017 | TemplateArgumentLoc Loc; |
| 4018 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4019 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4020 | TransArgs.addArgument(Loc); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4021 | } |
| 4022 | } |
| 4023 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4024 | // FIXME: Bogus source location for the operator |
| 4025 | SourceLocation FakeOperatorLoc |
| 4026 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 4027 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4028 | // FIXME: to do this check properly, we will need to preserve the |
| 4029 | // first-qualifier-in-scope here, just in case we had a dependent |
| 4030 | // base (and therefore couldn't do the check) and a |
| 4031 | // nested-name-qualifier (and therefore could do the lookup). |
| 4032 | NamedDecl *FirstQualifierInScope = 0; |
| 4033 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4034 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 4035 | E->isArrow(), |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4036 | Qualifier, |
| 4037 | E->getQualifierRange(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4038 | E->getMemberLoc(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4039 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4040 | FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4041 | (E->hasExplicitTemplateArgumentList() |
| 4042 | ? &TransArgs : 0), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4043 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4044 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4045 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4046 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4047 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4048 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4049 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4050 | if (LHS.isInvalid()) |
| 4051 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4052 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4053 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4054 | if (RHS.isInvalid()) |
| 4055 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4056 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4057 | if (!getDerived().AlwaysRebuild() && |
| 4058 | LHS.get() == E->getLHS() && |
| 4059 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4060 | return SemaRef.Owned(E->Retain()); |
| 4061 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4062 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 4063 | move(LHS), move(RHS)); |
| 4064 | } |
| 4065 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4066 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4067 | Sema::OwningExprResult |
| 4068 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4069 | CompoundAssignOperator *E) { |
| 4070 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4071 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4072 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4073 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4074 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4075 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4076 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4077 | if (Cond.isInvalid()) |
| 4078 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4079 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4080 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4081 | if (LHS.isInvalid()) |
| 4082 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4083 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4084 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4085 | if (RHS.isInvalid()) |
| 4086 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4087 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4088 | if (!getDerived().AlwaysRebuild() && |
| 4089 | Cond.get() == E->getCond() && |
| 4090 | LHS.get() == E->getLHS() && |
| 4091 | RHS.get() == E->getRHS()) |
| 4092 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4093 | |
| 4094 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4095 | E->getQuestionLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4096 | move(LHS), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4097 | E->getColonLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4098 | move(RHS)); |
| 4099 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4100 | |
| 4101 | template<typename Derived> |
| 4102 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4103 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4104 | // Implicit casts are eliminated during transformation, since they |
| 4105 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4106 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4107 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4108 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4109 | template<typename Derived> |
| 4110 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4111 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4112 | TypeSourceInfo *OldT; |
| 4113 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4114 | { |
| 4115 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4116 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4117 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 4118 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4119 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4120 | OldT = E->getTypeInfoAsWritten(); |
| 4121 | NewT = getDerived().TransformType(OldT); |
| 4122 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4123 | return SemaRef.ExprError(); |
| 4124 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4125 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4126 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4127 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4128 | if (SubExpr.isInvalid()) |
| 4129 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4130 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4131 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4132 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4133 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4134 | return SemaRef.Owned(E->Retain()); |
| 4135 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4136 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 4137 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4138 | E->getRParenLoc(), |
| 4139 | move(SubExpr)); |
| 4140 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4141 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4142 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4143 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4144 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4145 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 4146 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 4147 | if (!NewT) |
| 4148 | return SemaRef.ExprError(); |
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 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 4151 | if (Init.isInvalid()) |
| 4152 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4153 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4154 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4155 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4156 | Init.get() == E->getInitializer()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4157 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4158 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 4159 | // Note: the expression type doesn't necessarily match the |
| 4160 | // type-as-written, but that's okay, because it should always be |
| 4161 | // derivable from the initializer. |
| 4162 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4163 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4164 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 4165 | move(Init)); |
| 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 | template<typename Derived> |
| 4169 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4170 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4171 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4172 | if (Base.isInvalid()) |
| 4173 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4174 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4175 | if (!getDerived().AlwaysRebuild() && |
| 4176 | Base.get() == E->getBase()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4177 | return SemaRef.Owned(E->Retain()); |
| 4178 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4179 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4180 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4181 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 4182 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 4183 | E->getAccessorLoc(), |
| 4184 | E->getAccessor()); |
| 4185 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4186 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4187 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4188 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4189 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4190 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4191 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4192 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4193 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4194 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4195 | if (Init.isInvalid()) |
| 4196 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4197 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4198 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4199 | Inits.push_back(Init.takeAs<Expr>()); |
| 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 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4203 | return SemaRef.Owned(E->Retain()); |
| 4204 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4205 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4206 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4207 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4208 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4209 | template<typename Derived> |
| 4210 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4211 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4212 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4213 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4214 | // transform the initializer value |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4215 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4216 | if (Init.isInvalid()) |
| 4217 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4218 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4219 | // transform the designators. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4220 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4221 | bool ExprChanged = false; |
| 4222 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4223 | DEnd = E->designators_end(); |
| 4224 | D != DEnd; ++D) { |
| 4225 | if (D->isFieldDesignator()) { |
| 4226 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4227 | D->getDotLoc(), |
| 4228 | D->getFieldLoc())); |
| 4229 | continue; |
| 4230 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4231 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4232 | if (D->isArrayDesignator()) { |
| 4233 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4234 | if (Index.isInvalid()) |
| 4235 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4236 | |
| 4237 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4238 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4239 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4240 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4241 | ArrayExprs.push_back(Index.release()); |
| 4242 | continue; |
| 4243 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4244 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4245 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4246 | OwningExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4247 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4248 | if (Start.isInvalid()) |
| 4249 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4250 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4251 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4252 | if (End.isInvalid()) |
| 4253 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4254 | |
| 4255 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4256 | End.get(), |
| 4257 | D->getLBracketLoc(), |
| 4258 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4259 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4260 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4261 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4262 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4263 | ArrayExprs.push_back(Start.release()); |
| 4264 | ArrayExprs.push_back(End.release()); |
| 4265 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4266 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4267 | if (!getDerived().AlwaysRebuild() && |
| 4268 | Init.get() == E->getInit() && |
| 4269 | !ExprChanged) |
| 4270 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4271 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4272 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4273 | E->getEqualOrColonLoc(), |
| 4274 | E->usesGNUSyntax(), move(Init)); |
| 4275 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4276 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4277 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4278 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4279 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4280 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4281 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4282 | |
| 4283 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4284 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4285 | QualType T = getDerived().TransformType(E->getType()); |
| 4286 | if (T.isNull()) |
| 4287 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4288 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4289 | if (!getDerived().AlwaysRebuild() && |
| 4290 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4291 | return SemaRef.Owned(E->Retain()); |
| 4292 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4293 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4294 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4295 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4296 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4297 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4298 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4299 | // FIXME: Do we want the type as written? |
| 4300 | QualType T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4301 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4302 | { |
| 4303 | // FIXME: Source location isn't quite accurate. |
| 4304 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4305 | T = getDerived().TransformType(E->getType()); |
| 4306 | if (T.isNull()) |
| 4307 | return SemaRef.ExprError(); |
| 4308 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4309 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4310 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4311 | if (SubExpr.isInvalid()) |
| 4312 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4313 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4314 | if (!getDerived().AlwaysRebuild() && |
| 4315 | T == E->getType() && |
| 4316 | SubExpr.get() == E->getSubExpr()) |
| 4317 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4318 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4319 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4320 | T, E->getRParenLoc()); |
| 4321 | } |
| 4322 | |
| 4323 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4324 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4325 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4326 | bool ArgumentChanged = false; |
| 4327 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4328 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4329 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4330 | if (Init.isInvalid()) |
| 4331 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4332 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4333 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4334 | Inits.push_back(Init.takeAs<Expr>()); |
| 4335 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4336 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4337 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4338 | move_arg(Inits), |
| 4339 | E->getRParenLoc()); |
| 4340 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4341 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4342 | /// \brief Transform an address-of-label expression. |
| 4343 | /// |
| 4344 | /// By default, the transformation of an address-of-label expression always |
| 4345 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4346 | /// the corresponding label statement by semantic analysis. |
| 4347 | template<typename Derived> |
| 4348 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4349 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4350 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4351 | E->getLabel()); |
| 4352 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4353 | |
| 4354 | template<typename Derived> |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4355 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4356 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4357 | OwningStmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4358 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4359 | if (SubStmt.isInvalid()) |
| 4360 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 4363 | SubStmt.get() == E->getSubStmt()) |
| 4364 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4365 | |
| 4366 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4367 | move(SubStmt), |
| 4368 | E->getRParenLoc()); |
| 4369 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4370 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4371 | template<typename Derived> |
| 4372 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4373 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4374 | QualType T1, T2; |
| 4375 | { |
| 4376 | // FIXME: Source location isn't quite accurate. |
| 4377 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4378 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4379 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4380 | if (T1.isNull()) |
| 4381 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4382 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4383 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4384 | if (T2.isNull()) |
| 4385 | return SemaRef.ExprError(); |
| 4386 | } |
| 4387 | |
| 4388 | if (!getDerived().AlwaysRebuild() && |
| 4389 | T1 == E->getArgType1() && |
| 4390 | T2 == E->getArgType2()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4391 | return SemaRef.Owned(E->Retain()); |
| 4392 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4393 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4394 | T1, T2, E->getRParenLoc()); |
| 4395 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4396 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4397 | template<typename Derived> |
| 4398 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4399 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4400 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4401 | if (Cond.isInvalid()) |
| 4402 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4403 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4404 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4405 | if (LHS.isInvalid()) |
| 4406 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4407 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4408 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4409 | if (RHS.isInvalid()) |
| 4410 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4411 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4412 | if (!getDerived().AlwaysRebuild() && |
| 4413 | Cond.get() == E->getCond() && |
| 4414 | LHS.get() == E->getLHS() && |
| 4415 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4416 | return SemaRef.Owned(E->Retain()); |
| 4417 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4418 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4419 | move(Cond), move(LHS), move(RHS), |
| 4420 | E->getRParenLoc()); |
| 4421 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4422 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4423 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4424 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4425 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4426 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4427 | } |
| 4428 | |
| 4429 | template<typename Derived> |
| 4430 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4431 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4432 | switch (E->getOperator()) { |
| 4433 | case OO_New: |
| 4434 | case OO_Delete: |
| 4435 | case OO_Array_New: |
| 4436 | case OO_Array_Delete: |
| 4437 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4438 | return SemaRef.ExprError(); |
| 4439 | |
| 4440 | case OO_Call: { |
| 4441 | // This is a call to an object's operator(). |
| 4442 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4443 | |
| 4444 | // Transform the object itself. |
| 4445 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4446 | if (Object.isInvalid()) |
| 4447 | return SemaRef.ExprError(); |
| 4448 | |
| 4449 | // FIXME: Poor location information |
| 4450 | SourceLocation FakeLParenLoc |
| 4451 | = SemaRef.PP.getLocForEndOfToken( |
| 4452 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4453 | |
| 4454 | // Transform the call arguments. |
| 4455 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4456 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4457 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4458 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4459 | break; |
| 4460 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4461 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4462 | if (Arg.isInvalid()) |
| 4463 | return SemaRef.ExprError(); |
| 4464 | |
| 4465 | // FIXME: Poor source location information. |
| 4466 | SourceLocation FakeCommaLoc |
| 4467 | = SemaRef.PP.getLocForEndOfToken( |
| 4468 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4469 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4470 | Args.push_back(Arg.release()); |
| 4471 | } |
| 4472 | |
| 4473 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4474 | move_arg(Args), |
| 4475 | FakeCommaLocs.data(), |
| 4476 | E->getLocEnd()); |
| 4477 | } |
| 4478 | |
| 4479 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4480 | case OO_##Name: |
| 4481 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4482 | #include "clang/Basic/OperatorKinds.def" |
| 4483 | case OO_Subscript: |
| 4484 | // Handled below. |
| 4485 | break; |
| 4486 | |
| 4487 | case OO_Conditional: |
| 4488 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4489 | return SemaRef.ExprError(); |
| 4490 | |
| 4491 | case OO_None: |
| 4492 | case NUM_OVERLOADED_OPERATORS: |
| 4493 | llvm_unreachable("not an overloaded operator?"); |
| 4494 | return SemaRef.ExprError(); |
| 4495 | } |
| 4496 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4497 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4498 | if (Callee.isInvalid()) |
| 4499 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4500 | |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4501 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4502 | if (First.isInvalid()) |
| 4503 | return SemaRef.ExprError(); |
| 4504 | |
| 4505 | OwningExprResult Second(SemaRef); |
| 4506 | if (E->getNumArgs() == 2) { |
| 4507 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4508 | if (Second.isInvalid()) |
| 4509 | return SemaRef.ExprError(); |
| 4510 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4511 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4512 | if (!getDerived().AlwaysRebuild() && |
| 4513 | Callee.get() == E->getCallee() && |
| 4514 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4515 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4516 | return SemaRef.Owned(E->Retain()); |
| 4517 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4518 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4519 | E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4520 | move(Callee), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4521 | move(First), |
| 4522 | move(Second)); |
| 4523 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4524 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4525 | template<typename Derived> |
| 4526 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4527 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4528 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4529 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4530 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4531 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4532 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4533 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4534 | TypeSourceInfo *OldT; |
| 4535 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4536 | { |
| 4537 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4538 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4539 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4540 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4541 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4542 | OldT = E->getTypeInfoAsWritten(); |
| 4543 | NewT = getDerived().TransformType(OldT); |
| 4544 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4545 | return SemaRef.ExprError(); |
| 4546 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4547 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4548 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4549 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4550 | if (SubExpr.isInvalid()) |
| 4551 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4552 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4553 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4554 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4555 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4556 | return SemaRef.Owned(E->Retain()); |
| 4557 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4558 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4559 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4560 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4561 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4562 | SourceLocation FakeRParenLoc |
| 4563 | = SemaRef.PP.getLocForEndOfToken( |
| 4564 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4565 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4566 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4567 | FakeLAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4568 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4569 | FakeRAngleLoc, |
| 4570 | FakeRAngleLoc, |
| 4571 | move(SubExpr), |
| 4572 | FakeRParenLoc); |
| 4573 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4574 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4575 | template<typename Derived> |
| 4576 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4577 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4578 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4579 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4580 | |
| 4581 | template<typename Derived> |
| 4582 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4583 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4584 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4585 | } |
| 4586 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4587 | template<typename Derived> |
| 4588 | Sema::OwningExprResult |
| 4589 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4590 | CXXReinterpretCastExpr *E) { |
| 4591 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4592 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4593 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4594 | template<typename Derived> |
| 4595 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4596 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4597 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4598 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4599 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4600 | template<typename Derived> |
| 4601 | Sema::OwningExprResult |
| 4602 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4603 | CXXFunctionalCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4604 | TypeSourceInfo *OldT; |
| 4605 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4606 | { |
| 4607 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4608 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4609 | OldT = E->getTypeInfoAsWritten(); |
| 4610 | NewT = getDerived().TransformType(OldT); |
| 4611 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4612 | return SemaRef.ExprError(); |
| 4613 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4614 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4615 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4616 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4617 | if (SubExpr.isInvalid()) |
| 4618 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4619 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4620 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4621 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4622 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4623 | return SemaRef.Owned(E->Retain()); |
| 4624 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4625 | // FIXME: The end of the type's source range is wrong |
| 4626 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4627 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4628 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4629 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4630 | move(SubExpr), |
| 4631 | E->getRParenLoc()); |
| 4632 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4633 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4634 | template<typename Derived> |
| 4635 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4636 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4637 | if (E->isTypeOperand()) { |
| 4638 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4639 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4640 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4641 | if (T.isNull()) |
| 4642 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4643 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4644 | if (!getDerived().AlwaysRebuild() && |
| 4645 | T == E->getTypeOperand()) |
| 4646 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4647 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4648 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4649 | /*FIXME:*/E->getLocStart(), |
| 4650 | T, |
| 4651 | E->getLocEnd()); |
| 4652 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4653 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4654 | // We don't know whether the expression is potentially evaluated until |
| 4655 | // after we perform semantic analysis, so the expression is potentially |
| 4656 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4657 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4658 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4659 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4660 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4661 | if (SubExpr.isInvalid()) |
| 4662 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4663 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4664 | if (!getDerived().AlwaysRebuild() && |
| 4665 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4666 | return SemaRef.Owned(E->Retain()); |
| 4667 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4668 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4669 | /*FIXME:*/E->getLocStart(), |
| 4670 | move(SubExpr), |
| 4671 | E->getLocEnd()); |
| 4672 | } |
| 4673 | |
| 4674 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4675 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4676 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4677 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4678 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4679 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4680 | template<typename Derived> |
| 4681 | Sema::OwningExprResult |
| 4682 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4683 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4684 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4685 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4686 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4687 | template<typename Derived> |
| 4688 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4689 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4690 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4691 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4692 | QualType T = getDerived().TransformType(E->getType()); |
| 4693 | if (T.isNull()) |
| 4694 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4695 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4696 | if (!getDerived().AlwaysRebuild() && |
| 4697 | T == E->getType()) |
| 4698 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4699 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 4700 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4701 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4702 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4703 | template<typename Derived> |
| 4704 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4705 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4706 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4707 | if (SubExpr.isInvalid()) |
| 4708 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4709 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4710 | if (!getDerived().AlwaysRebuild() && |
| 4711 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4712 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4713 | |
| 4714 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4715 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4716 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4717 | template<typename Derived> |
| 4718 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4719 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4720 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4721 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 4722 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4723 | if (!Param) |
| 4724 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4725 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 4726 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4727 | Param == E->getParam()) |
| 4728 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4729 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 4730 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4731 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4732 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4733 | template<typename Derived> |
| 4734 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4735 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4736 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4737 | |
| 4738 | QualType T = getDerived().TransformType(E->getType()); |
| 4739 | if (T.isNull()) |
| 4740 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4741 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4742 | if (!getDerived().AlwaysRebuild() && |
| 4743 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4744 | return SemaRef.Owned(E->Retain()); |
| 4745 | |
| 4746 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4747 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4748 | T, |
| 4749 | E->getRParenLoc()); |
| 4750 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4751 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4752 | template<typename Derived> |
| 4753 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4754 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4755 | // Transform the type that we're allocating |
| 4756 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4757 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4758 | if (AllocType.isNull()) |
| 4759 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4760 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4761 | // Transform the size of the array we're allocating (if any). |
| 4762 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4763 | if (ArraySize.isInvalid()) |
| 4764 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4765 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4766 | // Transform the placement arguments (if any). |
| 4767 | bool ArgumentChanged = false; |
| 4768 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4769 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4770 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4771 | if (Arg.isInvalid()) |
| 4772 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4773 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4774 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4775 | PlacementArgs.push_back(Arg.take()); |
| 4776 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4777 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4778 | // transform the constructor arguments (if any). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4779 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4780 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4781 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4782 | if (Arg.isInvalid()) |
| 4783 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4784 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4785 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4786 | ConstructorArgs.push_back(Arg.take()); |
| 4787 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4788 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4789 | // Transform constructor, new operator, and delete operator. |
| 4790 | CXXConstructorDecl *Constructor = 0; |
| 4791 | if (E->getConstructor()) { |
| 4792 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4793 | getDerived().TransformDecl(E->getLocStart(), |
| 4794 | E->getConstructor())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4795 | if (!Constructor) |
| 4796 | return SemaRef.ExprError(); |
| 4797 | } |
| 4798 | |
| 4799 | FunctionDecl *OperatorNew = 0; |
| 4800 | if (E->getOperatorNew()) { |
| 4801 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4802 | getDerived().TransformDecl(E->getLocStart(), |
| 4803 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4804 | if (!OperatorNew) |
| 4805 | return SemaRef.ExprError(); |
| 4806 | } |
| 4807 | |
| 4808 | FunctionDecl *OperatorDelete = 0; |
| 4809 | if (E->getOperatorDelete()) { |
| 4810 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4811 | getDerived().TransformDecl(E->getLocStart(), |
| 4812 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4813 | if (!OperatorDelete) |
| 4814 | return SemaRef.ExprError(); |
| 4815 | } |
| 4816 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4817 | if (!getDerived().AlwaysRebuild() && |
| 4818 | AllocType == E->getAllocatedType() && |
| 4819 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4820 | Constructor == E->getConstructor() && |
| 4821 | OperatorNew == E->getOperatorNew() && |
| 4822 | OperatorDelete == E->getOperatorDelete() && |
| 4823 | !ArgumentChanged) { |
| 4824 | // Mark any declarations we need as referenced. |
| 4825 | // FIXME: instantiation-specific. |
| 4826 | if (Constructor) |
| 4827 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 4828 | if (OperatorNew) |
| 4829 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 4830 | if (OperatorDelete) |
| 4831 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4832 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4833 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4834 | |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 4835 | if (!ArraySize.get()) { |
| 4836 | // If no array size was specified, but the new expression was |
| 4837 | // instantiated with an array type (e.g., "new T" where T is |
| 4838 | // instantiated with "int[4]"), extract the outer bound from the |
| 4839 | // array type as our array size. We do this with constant and |
| 4840 | // dependently-sized array types. |
| 4841 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 4842 | if (!ArrayT) { |
| 4843 | // Do nothing |
| 4844 | } else if (const ConstantArrayType *ConsArrayT |
| 4845 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 4846 | ArraySize |
| 4847 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 4848 | ConsArrayT->getSize(), |
| 4849 | SemaRef.Context.getSizeType(), |
| 4850 | /*FIXME:*/E->getLocStart())); |
| 4851 | AllocType = ConsArrayT->getElementType(); |
| 4852 | } else if (const DependentSizedArrayType *DepArrayT |
| 4853 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 4854 | if (DepArrayT->getSizeExpr()) { |
| 4855 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 4856 | AllocType = DepArrayT->getElementType(); |
| 4857 | } |
| 4858 | } |
| 4859 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4860 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4861 | E->isGlobalNew(), |
| 4862 | /*FIXME:*/E->getLocStart(), |
| 4863 | move_arg(PlacementArgs), |
| 4864 | /*FIXME:*/E->getLocStart(), |
| 4865 | E->isParenTypeId(), |
| 4866 | AllocType, |
| 4867 | /*FIXME:*/E->getLocStart(), |
| 4868 | /*FIXME:*/SourceRange(), |
| 4869 | move(ArraySize), |
| 4870 | /*FIXME:*/E->getLocStart(), |
| 4871 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4872 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4873 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4874 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4875 | template<typename Derived> |
| 4876 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4877 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4878 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4879 | if (Operand.isInvalid()) |
| 4880 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4881 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4882 | // Transform the delete operator, if known. |
| 4883 | FunctionDecl *OperatorDelete = 0; |
| 4884 | if (E->getOperatorDelete()) { |
| 4885 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4886 | getDerived().TransformDecl(E->getLocStart(), |
| 4887 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4888 | if (!OperatorDelete) |
| 4889 | return SemaRef.ExprError(); |
| 4890 | } |
| 4891 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4892 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4893 | Operand.get() == E->getArgument() && |
| 4894 | OperatorDelete == E->getOperatorDelete()) { |
| 4895 | // Mark any declarations we need as referenced. |
| 4896 | // FIXME: instantiation-specific. |
| 4897 | if (OperatorDelete) |
| 4898 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4899 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4900 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4901 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4902 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4903 | E->isGlobalDelete(), |
| 4904 | E->isArrayForm(), |
| 4905 | move(Operand)); |
| 4906 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4907 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4908 | template<typename Derived> |
| 4909 | Sema::OwningExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4910 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4911 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4912 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4913 | if (Base.isInvalid()) |
| 4914 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4915 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4916 | Sema::TypeTy *ObjectTypePtr = 0; |
| 4917 | bool MayBePseudoDestructor = false; |
| 4918 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 4919 | E->getOperatorLoc(), |
| 4920 | E->isArrow()? tok::arrow : tok::period, |
| 4921 | ObjectTypePtr, |
| 4922 | MayBePseudoDestructor); |
| 4923 | if (Base.isInvalid()) |
| 4924 | return SemaRef.ExprError(); |
| 4925 | |
| 4926 | QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4927 | NestedNameSpecifier *Qualifier |
| 4928 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 4929 | E->getQualifierRange(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4930 | ObjectType); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4931 | if (E->getQualifier() && !Qualifier) |
| 4932 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4933 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4934 | PseudoDestructorTypeStorage Destroyed; |
| 4935 | if (E->getDestroyedTypeInfo()) { |
| 4936 | TypeSourceInfo *DestroyedTypeInfo |
| 4937 | = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType); |
| 4938 | if (!DestroyedTypeInfo) |
| 4939 | return SemaRef.ExprError(); |
| 4940 | Destroyed = DestroyedTypeInfo; |
| 4941 | } else if (ObjectType->isDependentType()) { |
| 4942 | // We aren't likely to be able to resolve the identifier down to a type |
| 4943 | // now anyway, so just retain the identifier. |
| 4944 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 4945 | E->getDestroyedTypeLoc()); |
| 4946 | } else { |
| 4947 | // Look for a destructor known with the given name. |
| 4948 | CXXScopeSpec SS; |
| 4949 | if (Qualifier) { |
| 4950 | SS.setScopeRep(Qualifier); |
| 4951 | SS.setRange(E->getQualifierRange()); |
| 4952 | } |
| 4953 | |
| 4954 | Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(), |
| 4955 | *E->getDestroyedTypeIdentifier(), |
| 4956 | E->getDestroyedTypeLoc(), |
| 4957 | /*Scope=*/0, |
| 4958 | SS, ObjectTypePtr, |
| 4959 | false); |
| 4960 | if (!T) |
| 4961 | return SemaRef.ExprError(); |
| 4962 | |
| 4963 | Destroyed |
| 4964 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 4965 | E->getDestroyedTypeLoc()); |
| 4966 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4967 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4968 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 4969 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4970 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(), |
| 4971 | ObjectType); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4972 | if (!ScopeTypeInfo) |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4973 | return SemaRef.ExprError(); |
| 4974 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4975 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4976 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4977 | E->getOperatorLoc(), |
| 4978 | E->isArrow(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4979 | Qualifier, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4980 | E->getQualifierRange(), |
| 4981 | ScopeTypeInfo, |
| 4982 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 4983 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4984 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4985 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4986 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4987 | template<typename Derived> |
| 4988 | Sema::OwningExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 4989 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4990 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4991 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 4992 | |
| 4993 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 4994 | Sema::LookupOrdinaryName); |
| 4995 | |
| 4996 | // Transform all the decls. |
| 4997 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 4998 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4999 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5000 | getDerived().TransformDecl(Old->getNameLoc(), |
| 5001 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5002 | if (!InstD) { |
| 5003 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5004 | // This can happen because of dependent hiding. |
| 5005 | if (isa<UsingShadowDecl>(*I)) |
| 5006 | continue; |
| 5007 | else |
| 5008 | return SemaRef.ExprError(); |
| 5009 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5010 | |
| 5011 | // Expand using declarations. |
| 5012 | if (isa<UsingDecl>(InstD)) { |
| 5013 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5014 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5015 | E = UD->shadow_end(); I != E; ++I) |
| 5016 | R.addDecl(*I); |
| 5017 | continue; |
| 5018 | } |
| 5019 | |
| 5020 | R.addDecl(InstD); |
| 5021 | } |
| 5022 | |
| 5023 | // Resolve a kind, but don't do any further analysis. If it's |
| 5024 | // ambiguous, the callee needs to deal with it. |
| 5025 | R.resolveKind(); |
| 5026 | |
| 5027 | // Rebuild the nested-name qualifier, if present. |
| 5028 | CXXScopeSpec SS; |
| 5029 | NestedNameSpecifier *Qualifier = 0; |
| 5030 | if (Old->getQualifier()) { |
| 5031 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5032 | Old->getQualifierRange()); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5033 | if (!Qualifier) |
| 5034 | return SemaRef.ExprError(); |
| 5035 | |
| 5036 | SS.setScopeRep(Qualifier); |
| 5037 | SS.setRange(Old->getQualifierRange()); |
| 5038 | } |
| 5039 | |
| 5040 | // If we have no template arguments, it's a normal declaration name. |
| 5041 | if (!Old->hasExplicitTemplateArgs()) |
| 5042 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 5043 | |
| 5044 | // If we have template arguments, rebuild them, then rebuild the |
| 5045 | // templateid expression. |
| 5046 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 5047 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5048 | TemplateArgumentLoc Loc; |
| 5049 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 5050 | return SemaRef.ExprError(); |
| 5051 | TransArgs.addArgument(Loc); |
| 5052 | } |
| 5053 | |
| 5054 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 5055 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5056 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5057 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5058 | template<typename Derived> |
| 5059 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5060 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5061 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5062 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5063 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 5064 | if (T.isNull()) |
| 5065 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5066 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5067 | if (!getDerived().AlwaysRebuild() && |
| 5068 | T == E->getQueriedType()) |
| 5069 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5070 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5071 | // FIXME: Bad location information |
| 5072 | SourceLocation FakeLParenLoc |
| 5073 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5074 | |
| 5075 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5076 | E->getLocStart(), |
| 5077 | /*FIXME:*/FakeLParenLoc, |
| 5078 | T, |
| 5079 | E->getLocEnd()); |
| 5080 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5081 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5082 | template<typename Derived> |
| 5083 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5084 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5085 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5086 | NestedNameSpecifier *NNS |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5087 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5088 | E->getQualifierRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5089 | if (!NNS) |
| 5090 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5091 | |
| 5092 | DeclarationName Name |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5093 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 5094 | if (!Name) |
| 5095 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5096 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5097 | if (!E->hasExplicitTemplateArgs()) { |
| 5098 | if (!getDerived().AlwaysRebuild() && |
| 5099 | NNS == E->getQualifier() && |
| 5100 | Name == E->getDeclName()) |
| 5101 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5102 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5103 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5104 | E->getQualifierRange(), |
| 5105 | Name, E->getLocation(), |
| 5106 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5107 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5108 | |
| 5109 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5110 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5111 | TemplateArgumentLoc Loc; |
| 5112 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5113 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5114 | TransArgs.addArgument(Loc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5115 | } |
| 5116 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5117 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5118 | E->getQualifierRange(), |
| 5119 | Name, E->getLocation(), |
| 5120 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | template<typename Derived> |
| 5124 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5125 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 5126 | // CXXConstructExprs are always implicit, so when we have a |
| 5127 | // 1-argument construction we just transform that argument. |
| 5128 | if (E->getNumArgs() == 1 || |
| 5129 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 5130 | return getDerived().TransformExpr(E->getArg(0)); |
| 5131 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5132 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 5133 | |
| 5134 | QualType T = getDerived().TransformType(E->getType()); |
| 5135 | if (T.isNull()) |
| 5136 | return SemaRef.ExprError(); |
| 5137 | |
| 5138 | CXXConstructorDecl *Constructor |
| 5139 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5140 | getDerived().TransformDecl(E->getLocStart(), |
| 5141 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5142 | if (!Constructor) |
| 5143 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5144 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5145 | bool ArgumentChanged = false; |
| 5146 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5147 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5148 | ArgEnd = E->arg_end(); |
| 5149 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5150 | if (getDerived().DropCallArgument(*Arg)) { |
| 5151 | ArgumentChanged = true; |
| 5152 | break; |
| 5153 | } |
| 5154 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5155 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5156 | if (TransArg.isInvalid()) |
| 5157 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5158 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5159 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5160 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5161 | } |
| 5162 | |
| 5163 | if (!getDerived().AlwaysRebuild() && |
| 5164 | T == E->getType() && |
| 5165 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5166 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5167 | // Mark the constructor as referenced. |
| 5168 | // FIXME: Instantiation-specific |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5169 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5170 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5171 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5172 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 5173 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 5174 | Constructor, E->isElidable(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5175 | move_arg(Args)); |
| 5176 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5177 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5178 | /// \brief Transform a C++ temporary-binding expression. |
| 5179 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5180 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 5181 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5182 | template<typename Derived> |
| 5183 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5184 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5185 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5186 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5187 | |
Anders Carlsson | ba6c437 | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 5188 | /// \brief Transform a C++ reference-binding expression. |
| 5189 | /// |
| 5190 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 5191 | /// transform the subexpression and return that. |
| 5192 | template<typename Derived> |
| 5193 | Sema::OwningExprResult |
| 5194 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 5195 | return getDerived().TransformExpr(E->getSubExpr()); |
| 5196 | } |
| 5197 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5198 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5199 | /// be destroyed after the expression is evaluated. |
| 5200 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5201 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 5202 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5203 | template<typename Derived> |
| 5204 | Sema::OwningExprResult |
| 5205 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5206 | CXXExprWithTemporaries *E) { |
| 5207 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5208 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5209 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5210 | template<typename Derived> |
| 5211 | Sema::OwningExprResult |
| 5212 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5213 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5214 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5215 | QualType T = getDerived().TransformType(E->getType()); |
| 5216 | if (T.isNull()) |
| 5217 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5218 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5219 | CXXConstructorDecl *Constructor |
| 5220 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5221 | getDerived().TransformDecl(E->getLocStart(), |
| 5222 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5223 | if (!Constructor) |
| 5224 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5225 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5226 | bool ArgumentChanged = false; |
| 5227 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5228 | Args.reserve(E->getNumArgs()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5229 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5230 | ArgEnd = E->arg_end(); |
| 5231 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5232 | if (getDerived().DropCallArgument(*Arg)) { |
| 5233 | ArgumentChanged = true; |
| 5234 | break; |
| 5235 | } |
| 5236 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5237 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5238 | if (TransArg.isInvalid()) |
| 5239 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5240 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5241 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5242 | Args.push_back((Expr *)TransArg.release()); |
| 5243 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5244 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5245 | if (!getDerived().AlwaysRebuild() && |
| 5246 | T == E->getType() && |
| 5247 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5248 | !ArgumentChanged) { |
| 5249 | // FIXME: Instantiation-specific |
| 5250 | SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor); |
Chandler Carruth | b32b344 | 2010-03-31 18:34:58 +0000 | [diff] [blame] | 5251 | return SemaRef.MaybeBindToTemporary(E->Retain()); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5252 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5253 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5254 | // FIXME: Bogus location information |
| 5255 | SourceLocation CommaLoc; |
| 5256 | if (Args.size() > 1) { |
| 5257 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5258 | CommaLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5259 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 5260 | } |
| 5261 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 5262 | T, |
| 5263 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5264 | move_arg(Args), |
| 5265 | &CommaLoc, |
| 5266 | E->getLocEnd()); |
| 5267 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5268 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5269 | template<typename Derived> |
| 5270 | Sema::OwningExprResult |
| 5271 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5272 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5273 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5274 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 5275 | if (T.isNull()) |
| 5276 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5277 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5278 | bool ArgumentChanged = false; |
| 5279 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5280 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 5281 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 5282 | ArgEnd = E->arg_end(); |
| 5283 | Arg != ArgEnd; ++Arg) { |
| 5284 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5285 | if (TransArg.isInvalid()) |
| 5286 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5287 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5288 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5289 | FakeCommaLocs.push_back( |
| 5290 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 5291 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5292 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5293 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5294 | if (!getDerived().AlwaysRebuild() && |
| 5295 | T == E->getTypeAsWritten() && |
| 5296 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5297 | return SemaRef.Owned(E->Retain()); |
| 5298 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5299 | // FIXME: we're faking the locations of the commas |
| 5300 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5301 | T, |
| 5302 | E->getLParenLoc(), |
| 5303 | move_arg(Args), |
| 5304 | FakeCommaLocs.data(), |
| 5305 | E->getRParenLoc()); |
| 5306 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5307 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5308 | template<typename Derived> |
| 5309 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5310 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5311 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5312 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5313 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5314 | Expr *OldBase; |
| 5315 | QualType BaseType; |
| 5316 | QualType ObjectType; |
| 5317 | if (!E->isImplicitAccess()) { |
| 5318 | OldBase = E->getBase(); |
| 5319 | Base = getDerived().TransformExpr(OldBase); |
| 5320 | if (Base.isInvalid()) |
| 5321 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5322 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5323 | // Start the member reference and compute the object's type. |
| 5324 | Sema::TypeTy *ObjectTy = 0; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5325 | bool MayBePseudoDestructor = false; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5326 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5327 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5328 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5329 | ObjectTy, |
| 5330 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5331 | if (Base.isInvalid()) |
| 5332 | return SemaRef.ExprError(); |
| 5333 | |
| 5334 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5335 | BaseType = ((Expr*) Base.get())->getType(); |
| 5336 | } else { |
| 5337 | OldBase = 0; |
| 5338 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5339 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5340 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5341 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5342 | // Transform the first part of the nested-name-specifier that qualifies |
| 5343 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5344 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5345 | = getDerived().TransformFirstQualifierInScope( |
| 5346 | E->getFirstQualifierFoundInScope(), |
| 5347 | E->getQualifierRange().getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5348 | |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5349 | NestedNameSpecifier *Qualifier = 0; |
| 5350 | if (E->getQualifier()) { |
| 5351 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5352 | E->getQualifierRange(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5353 | ObjectType, |
| 5354 | FirstQualifierInScope); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5355 | if (!Qualifier) |
| 5356 | return SemaRef.ExprError(); |
| 5357 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5358 | |
| 5359 | DeclarationName Name |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5360 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5361 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5362 | if (!Name) |
| 5363 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5364 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5365 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5366 | // This is a reference to a member without an explicitly-specified |
| 5367 | // template argument list. Optimize for this common case. |
| 5368 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5369 | Base.get() == OldBase && |
| 5370 | BaseType == E->getBaseType() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5371 | Qualifier == E->getQualifier() && |
| 5372 | Name == E->getMember() && |
| 5373 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5374 | return SemaRef.Owned(E->Retain()); |
| 5375 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5376 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5377 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5378 | E->isArrow(), |
| 5379 | E->getOperatorLoc(), |
| 5380 | Qualifier, |
| 5381 | E->getQualifierRange(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5382 | FirstQualifierInScope, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5383 | Name, |
| 5384 | E->getMemberLoc(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5385 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5386 | } |
| 5387 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5388 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5389 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5390 | TemplateArgumentLoc Loc; |
| 5391 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5392 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5393 | TransArgs.addArgument(Loc); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5394 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5395 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5396 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5397 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5398 | E->isArrow(), |
| 5399 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5400 | Qualifier, |
| 5401 | E->getQualifierRange(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5402 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5403 | Name, |
| 5404 | E->getMemberLoc(), |
| 5405 | &TransArgs); |
| 5406 | } |
| 5407 | |
| 5408 | template<typename Derived> |
| 5409 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5410 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5411 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5412 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5413 | QualType BaseType; |
| 5414 | if (!Old->isImplicitAccess()) { |
| 5415 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5416 | if (Base.isInvalid()) |
| 5417 | return SemaRef.ExprError(); |
| 5418 | BaseType = ((Expr*) Base.get())->getType(); |
| 5419 | } else { |
| 5420 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5421 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5422 | |
| 5423 | NestedNameSpecifier *Qualifier = 0; |
| 5424 | if (Old->getQualifier()) { |
| 5425 | Qualifier |
| 5426 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5427 | Old->getQualifierRange()); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5428 | if (Qualifier == 0) |
| 5429 | return SemaRef.ExprError(); |
| 5430 | } |
| 5431 | |
| 5432 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5433 | Sema::LookupOrdinaryName); |
| 5434 | |
| 5435 | // Transform all the decls. |
| 5436 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5437 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5438 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5439 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 5440 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5441 | if (!InstD) { |
| 5442 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5443 | // This can happen because of dependent hiding. |
| 5444 | if (isa<UsingShadowDecl>(*I)) |
| 5445 | continue; |
| 5446 | else |
| 5447 | return SemaRef.ExprError(); |
| 5448 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5449 | |
| 5450 | // Expand using declarations. |
| 5451 | if (isa<UsingDecl>(InstD)) { |
| 5452 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5453 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5454 | E = UD->shadow_end(); I != E; ++I) |
| 5455 | R.addDecl(*I); |
| 5456 | continue; |
| 5457 | } |
| 5458 | |
| 5459 | R.addDecl(InstD); |
| 5460 | } |
| 5461 | |
| 5462 | R.resolveKind(); |
| 5463 | |
| 5464 | TemplateArgumentListInfo TransArgs; |
| 5465 | if (Old->hasExplicitTemplateArgs()) { |
| 5466 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5467 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5468 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5469 | TemplateArgumentLoc Loc; |
| 5470 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5471 | Loc)) |
| 5472 | return SemaRef.ExprError(); |
| 5473 | TransArgs.addArgument(Loc); |
| 5474 | } |
| 5475 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5476 | |
| 5477 | // FIXME: to do this check properly, we will need to preserve the |
| 5478 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5479 | // base (and therefore couldn't do the check) and a |
| 5480 | // nested-name-qualifier (and therefore could do the lookup). |
| 5481 | NamedDecl *FirstQualifierInScope = 0; |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5482 | |
| 5483 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5484 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5485 | Old->getOperatorLoc(), |
| 5486 | Old->isArrow(), |
| 5487 | Qualifier, |
| 5488 | Old->getQualifierRange(), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5489 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5490 | R, |
| 5491 | (Old->hasExplicitTemplateArgs() |
| 5492 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5493 | } |
| 5494 | |
| 5495 | template<typename Derived> |
| 5496 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5497 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5498 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5499 | } |
| 5500 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5501 | template<typename Derived> |
| 5502 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5503 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5504 | TypeSourceInfo *EncodedTypeInfo |
| 5505 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 5506 | if (!EncodedTypeInfo) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5507 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5508 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5509 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5510 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5511 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5512 | |
| 5513 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5514 | EncodedTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5515 | E->getRParenLoc()); |
| 5516 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5517 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5518 | template<typename Derived> |
| 5519 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5520 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5521 | // Transform arguments. |
| 5522 | bool ArgChanged = false; |
| 5523 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5524 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 5525 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 5526 | if (Arg.isInvalid()) |
| 5527 | return SemaRef.ExprError(); |
| 5528 | |
| 5529 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
| 5530 | Args.push_back(Arg.takeAs<Expr>()); |
| 5531 | } |
| 5532 | |
| 5533 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 5534 | // Class message: transform the receiver type. |
| 5535 | TypeSourceInfo *ReceiverTypeInfo |
| 5536 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 5537 | if (!ReceiverTypeInfo) |
| 5538 | return SemaRef.ExprError(); |
| 5539 | |
| 5540 | // If nothing changed, just retain the existing message send. |
| 5541 | if (!getDerived().AlwaysRebuild() && |
| 5542 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
| 5543 | return SemaRef.Owned(E->Retain()); |
| 5544 | |
| 5545 | // Build a new class message send. |
| 5546 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 5547 | E->getSelector(), |
| 5548 | E->getMethodDecl(), |
| 5549 | E->getLeftLoc(), |
| 5550 | move_arg(Args), |
| 5551 | E->getRightLoc()); |
| 5552 | } |
| 5553 | |
| 5554 | // Instance message: transform the receiver |
| 5555 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 5556 | "Only class and instance messages may be instantiated"); |
| 5557 | OwningExprResult Receiver |
| 5558 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 5559 | if (Receiver.isInvalid()) |
| 5560 | return SemaRef.ExprError(); |
| 5561 | |
| 5562 | // If nothing changed, just retain the existing message send. |
| 5563 | if (!getDerived().AlwaysRebuild() && |
| 5564 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
| 5565 | return SemaRef.Owned(E->Retain()); |
| 5566 | |
| 5567 | // Build a new instance message send. |
| 5568 | return getDerived().RebuildObjCMessageExpr(move(Receiver), |
| 5569 | E->getSelector(), |
| 5570 | E->getMethodDecl(), |
| 5571 | E->getLeftLoc(), |
| 5572 | move_arg(Args), |
| 5573 | E->getRightLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5574 | } |
| 5575 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5576 | template<typename Derived> |
| 5577 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5578 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5579 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5580 | } |
| 5581 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5582 | template<typename Derived> |
| 5583 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5584 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame^] | 5585 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5586 | } |
| 5587 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5588 | template<typename Derived> |
| 5589 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5590 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5591 | // FIXME: Implement this! |
| 5592 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5593 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5594 | } |
| 5595 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5596 | template<typename Derived> |
| 5597 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5598 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5599 | // FIXME: Implement this! |
| 5600 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5601 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5602 | } |
| 5603 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5604 | template<typename Derived> |
| 5605 | Sema::OwningExprResult |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5606 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5607 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5608 | // FIXME: Implement this! |
| 5609 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5610 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5611 | } |
| 5612 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5613 | template<typename Derived> |
| 5614 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5615 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame^] | 5616 | // Can never occur in a dependent context. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5617 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5618 | } |
| 5619 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5620 | template<typename Derived> |
| 5621 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5622 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5623 | // FIXME: Implement this! |
| 5624 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5625 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5626 | } |
| 5627 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5628 | template<typename Derived> |
| 5629 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5630 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5631 | bool ArgumentChanged = false; |
| 5632 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5633 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5634 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5635 | if (SubExpr.isInvalid()) |
| 5636 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5637 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5638 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5639 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5640 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5641 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5642 | if (!getDerived().AlwaysRebuild() && |
| 5643 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5644 | return SemaRef.Owned(E->Retain()); |
| 5645 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5646 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5647 | move_arg(SubExprs), |
| 5648 | E->getRParenLoc()); |
| 5649 | } |
| 5650 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5651 | template<typename Derived> |
| 5652 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5653 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5654 | // FIXME: Implement this! |
| 5655 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5656 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5657 | } |
| 5658 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5659 | template<typename Derived> |
| 5660 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5661 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5662 | // FIXME: Implement this! |
| 5663 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5664 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5665 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5666 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5667 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5668 | // Type reconstruction |
| 5669 | //===----------------------------------------------------------------------===// |
| 5670 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5671 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5672 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5673 | SourceLocation Star) { |
| 5674 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5675 | getDerived().getBaseEntity()); |
| 5676 | } |
| 5677 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5678 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5679 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5680 | SourceLocation Star) { |
| 5681 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5682 | getDerived().getBaseEntity()); |
| 5683 | } |
| 5684 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5685 | template<typename Derived> |
| 5686 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5687 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5688 | bool WrittenAsLValue, |
| 5689 | SourceLocation Sigil) { |
| 5690 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5691 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5692 | } |
| 5693 | |
| 5694 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5695 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5696 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5697 | QualType ClassType, |
| 5698 | SourceLocation Sigil) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5699 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5700 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5701 | } |
| 5702 | |
| 5703 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5704 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5705 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5706 | ArrayType::ArraySizeModifier SizeMod, |
| 5707 | const llvm::APInt *Size, |
| 5708 | Expr *SizeExpr, |
| 5709 | unsigned IndexTypeQuals, |
| 5710 | SourceRange BracketsRange) { |
| 5711 | if (SizeExpr || !Size) |
| 5712 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5713 | IndexTypeQuals, BracketsRange, |
| 5714 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5715 | |
| 5716 | QualType Types[] = { |
| 5717 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5718 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5719 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5720 | }; |
| 5721 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5722 | QualType SizeType; |
| 5723 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5724 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5725 | SizeType = Types[I]; |
| 5726 | break; |
| 5727 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5728 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5729 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5730 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5731 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5732 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5733 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5734 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5735 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5736 | QualType |
| 5737 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5738 | ArrayType::ArraySizeModifier SizeMod, |
| 5739 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5740 | unsigned IndexTypeQuals, |
| 5741 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5742 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5743 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5744 | } |
| 5745 | |
| 5746 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5747 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5748 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5749 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5750 | unsigned IndexTypeQuals, |
| 5751 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5752 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5753 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +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 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5757 | QualType |
| 5758 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5759 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5760 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5761 | unsigned IndexTypeQuals, |
| 5762 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5763 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5764 | SizeExpr.takeAs<Expr>(), |
| 5765 | IndexTypeQuals, BracketsRange); |
| 5766 | } |
| 5767 | |
| 5768 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5769 | QualType |
| 5770 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5771 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5772 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5773 | unsigned IndexTypeQuals, |
| 5774 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5775 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5776 | SizeExpr.takeAs<Expr>(), |
| 5777 | IndexTypeQuals, BracketsRange); |
| 5778 | } |
| 5779 | |
| 5780 | template<typename Derived> |
| 5781 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5782 | unsigned NumElements, |
| 5783 | bool IsAltiVec, bool IsPixel) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5784 | // FIXME: semantic checking! |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5785 | return SemaRef.Context.getVectorType(ElementType, NumElements, |
| 5786 | IsAltiVec, IsPixel); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5787 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5788 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5789 | template<typename Derived> |
| 5790 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5791 | unsigned NumElements, |
| 5792 | SourceLocation AttributeLoc) { |
| 5793 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5794 | NumElements, true); |
| 5795 | IntegerLiteral *VectorSize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5796 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5797 | AttributeLoc); |
| 5798 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5799 | AttributeLoc); |
| 5800 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5801 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5802 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5803 | QualType |
| 5804 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5805 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5806 | SourceLocation AttributeLoc) { |
| 5807 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5808 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5809 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5810 | template<typename Derived> |
| 5811 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5812 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5813 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5814 | bool Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5815 | unsigned Quals) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5816 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5817 | Quals, |
| 5818 | getDerived().getBaseLocation(), |
| 5819 | getDerived().getBaseEntity()); |
| 5820 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5821 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5822 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5823 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5824 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5825 | } |
| 5826 | |
| 5827 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5828 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 5829 | assert(D && "no decl found"); |
| 5830 | if (D->isInvalidDecl()) return QualType(); |
| 5831 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5832 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5833 | TypeDecl *Ty; |
| 5834 | if (isa<UsingDecl>(D)) { |
| 5835 | UsingDecl *Using = cast<UsingDecl>(D); |
| 5836 | assert(Using->isTypeName() && |
| 5837 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 5838 | |
| 5839 | // A valid resolved using typename decl points to exactly one type decl. |
| 5840 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 5841 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 5842 | |
| 5843 | } else { |
| 5844 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 5845 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 5846 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 5847 | } |
| 5848 | |
| 5849 | return SemaRef.Context.getTypeDeclType(Ty); |
| 5850 | } |
| 5851 | |
| 5852 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5853 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5854 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5855 | } |
| 5856 | |
| 5857 | template<typename Derived> |
| 5858 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5859 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5860 | } |
| 5861 | |
| 5862 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5863 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5864 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5865 | } |
| 5866 | |
| 5867 | template<typename Derived> |
| 5868 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5869 | TemplateName Template, |
| 5870 | SourceLocation TemplateNameLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5871 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5872 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5873 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5874 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5875 | template<typename Derived> |
| 5876 | NestedNameSpecifier * |
| 5877 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5878 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5879 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5880 | QualType ObjectType, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5881 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5882 | CXXScopeSpec SS; |
| 5883 | // FIXME: The source location information is all wrong. |
| 5884 | SS.setRange(Range); |
| 5885 | SS.setScopeRep(Prefix); |
| 5886 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5887 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | e861bac | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5888 | Range.getEnd(), II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5889 | ObjectType, |
| 5890 | FirstQualifierInScope, |
Chris Lattner | 1c42803 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 5891 | false, false)); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5892 | } |
| 5893 | |
| 5894 | template<typename Derived> |
| 5895 | NestedNameSpecifier * |
| 5896 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5897 | SourceRange Range, |
| 5898 | NamespaceDecl *NS) { |
| 5899 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5900 | } |
| 5901 | |
| 5902 | template<typename Derived> |
| 5903 | NestedNameSpecifier * |
| 5904 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5905 | SourceRange Range, |
| 5906 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5907 | QualType T) { |
| 5908 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5909 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5910 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5911 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5912 | T.getTypePtr()); |
| 5913 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5914 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5915 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5916 | return 0; |
| 5917 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5918 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5919 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5920 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5921 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5922 | bool TemplateKW, |
| 5923 | TemplateDecl *Template) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5924 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5925 | Template); |
| 5926 | } |
| 5927 | |
| 5928 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5929 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5930 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5931 | const IdentifierInfo &II, |
| 5932 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5933 | CXXScopeSpec SS; |
| 5934 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5935 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5936 | UnqualifiedId Name; |
| 5937 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5938 | return getSema().ActOnDependentTemplateName( |
| 5939 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5940 | SS, |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5941 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5942 | ObjectType.getAsOpaquePtr(), |
| 5943 | /*EnteringContext=*/false) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5944 | .template getAsVal<TemplateName>(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5945 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5946 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5947 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5948 | TemplateName |
| 5949 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5950 | OverloadedOperatorKind Operator, |
| 5951 | QualType ObjectType) { |
| 5952 | CXXScopeSpec SS; |
| 5953 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5954 | SS.setScopeRep(Qualifier); |
| 5955 | UnqualifiedId Name; |
| 5956 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5957 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5958 | Operator, SymbolLocations); |
| 5959 | return getSema().ActOnDependentTemplateName( |
| 5960 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5961 | SS, |
| 5962 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5963 | ObjectType.getAsOpaquePtr(), |
| 5964 | /*EnteringContext=*/false) |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5965 | .template getAsVal<TemplateName>(); |
| 5966 | } |
| 5967 | |
| 5968 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5969 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5970 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5971 | SourceLocation OpLoc, |
| 5972 | ExprArg Callee, |
| 5973 | ExprArg First, |
| 5974 | ExprArg Second) { |
| 5975 | Expr *FirstExpr = (Expr *)First.get(); |
| 5976 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5977 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5978 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5979 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5980 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5981 | if (Op == OO_Subscript) { |
| 5982 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5983 | !SecondExpr->getType()->isOverloadableType()) |
| 5984 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5985 | CalleeExpr->getLocStart(), |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5986 | move(Second), OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 5987 | } else if (Op == OO_Arrow) { |
| 5988 | // -> is never a builtin operation. |
| 5989 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5990 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5991 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5992 | // The argument is not of overloadable type, so try to create a |
| 5993 | // built-in unary operation. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5994 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5995 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5996 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5997 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5998 | } |
| 5999 | } else { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6000 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6001 | !SecondExpr->getType()->isOverloadableType()) { |
| 6002 | // Neither of the arguments is an overloadable type, so try to |
| 6003 | // create a built-in binary operation. |
| 6004 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6005 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6006 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 6007 | if (Result.isInvalid()) |
| 6008 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6009 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6010 | First.release(); |
| 6011 | Second.release(); |
| 6012 | return move(Result); |
| 6013 | } |
| 6014 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6015 | |
| 6016 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6017 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6018 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6019 | |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6020 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 6021 | assert(ULE->requiresADL()); |
| 6022 | |
| 6023 | // FIXME: Do we have to check |
| 6024 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6025 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6026 | } else { |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6027 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6028 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6029 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6030 | // Add any functions found via argument-dependent lookup. |
| 6031 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 6032 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6033 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6034 | // Create the overloaded operator invocation for unary operators. |
| 6035 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6036 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6037 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 6038 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 6039 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6040 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6041 | if (Op == OO_Subscript) |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6042 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 6043 | OpLoc, |
| 6044 | move(First), |
| 6045 | move(Second)); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6046 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6047 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6048 | BinaryOperator::Opcode Opc = |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6049 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6050 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6051 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 6052 | if (Result.isInvalid()) |
| 6053 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6054 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6055 | First.release(); |
| 6056 | Second.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6057 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6058 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6059 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6060 | template<typename Derived> |
| 6061 | Sema::OwningExprResult |
| 6062 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 6063 | SourceLocation OperatorLoc, |
| 6064 | bool isArrow, |
| 6065 | NestedNameSpecifier *Qualifier, |
| 6066 | SourceRange QualifierRange, |
| 6067 | TypeSourceInfo *ScopeType, |
| 6068 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6069 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6070 | PseudoDestructorTypeStorage Destroyed) { |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6071 | CXXScopeSpec SS; |
| 6072 | if (Qualifier) { |
| 6073 | SS.setRange(QualifierRange); |
| 6074 | SS.setScopeRep(Qualifier); |
| 6075 | } |
| 6076 | |
| 6077 | Expr *BaseE = (Expr *)Base.get(); |
| 6078 | QualType BaseType = BaseE->getType(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6079 | if (BaseE->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6080 | (!isArrow && !BaseType->getAs<RecordType>()) || |
| 6081 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 6082 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 6083 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6084 | // This pseudo-destructor expression is still a pseudo-destructor. |
| 6085 | return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc, |
| 6086 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6087 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6088 | Destroyed, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6089 | /*FIXME?*/true); |
| 6090 | } |
| 6091 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6092 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6093 | DeclarationName Name |
| 6094 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 6095 | SemaRef.Context.getCanonicalType(DestroyedType->getType())); |
| 6096 | |
| 6097 | // FIXME: the ScopeType should be tacked onto SS. |
| 6098 | |
| 6099 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 6100 | OperatorLoc, isArrow, |
| 6101 | SS, /*FIXME: FirstQualifier*/ 0, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6102 | Name, Destroyed.getLocation(), |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6103 | /*TemplateArgs*/ 0); |
| 6104 | } |
| 6105 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6106 | } // end namespace clang |
| 6107 | |
| 6108 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |