John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/ |
Douglas Gregor | 577f75a | 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 | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 17 | #include "Lookup.h" |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 18 | #include "clang/Sema/SemaDiagnostic.h" |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 19 | #include "clang/AST/Decl.h" |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 20 | #include "clang/AST/Expr.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 21 | #include "clang/AST/ExprCXX.h" |
| 22 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | 43959a9 | 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 | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 26 | #include "clang/AST/TypeLocBuilder.h" |
Douglas Gregor | b98b199 | 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 | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 30 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 31 | #include <algorithm> |
| 32 | |
| 33 | namespace clang { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 34 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 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 | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 48 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 63 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 64 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | 577f75a | 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 | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 71 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 72 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 73 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 81 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | 577f75a | 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 | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 86 | template<typename Derived> |
| 87 | class TreeTransform { |
| 88 | protected: |
| 89 | Sema &SemaRef; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 90 | |
| 91 | public: |
Douglas Gregor | b98b199 | 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 | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 97 | typedef Sema::MultiStmtArg MultiStmtArg; |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 98 | typedef Sema::DeclPtrTy DeclPtrTy; |
| 99 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 100 | /// \brief Initializes a new tree transformer. |
| 101 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 107 | const Derived &getDerived() const { |
| 108 | return static_cast<const Derived&>(*this); |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 114 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 125 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 129 | |
Douglas Gregor | 577f75a | 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 | b98b199 | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 143 | |
Douglas Gregor | b98b199 | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 150 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 151 | public: |
| 152 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 153 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | b98b199 | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 158 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 159 | ~TemporaryBase() { |
| 160 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 161 | } |
| 162 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 163 | |
| 164 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 165 | /// transformed. |
| 166 | /// |
| 167 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 1eb4433 | 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 | 577f75a | 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 | 6eef519 | 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 | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 185 | /// \brief Transforms the given type into another type. |
| 186 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 187 | /// By default, this routine transforms a type by creating a |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 188 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | a2becad | 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 | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 191 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 192 | /// |
| 193 | /// \returns the transformed type. |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 194 | QualType TransformType(QualType T, QualType ObjectType = QualType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 195 | |
John McCall | a2becad | 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 | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 198 | /// |
John McCall | a2becad | 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 | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 204 | TypeSourceInfo *TransformType(TypeSourceInfo *DI, |
| 205 | QualType ObjectType = QualType()); |
John McCall | a2becad | 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 | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 211 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL, |
| 212 | QualType ObjectType = QualType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 213 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 214 | /// \brief Transform the given statement. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 215 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 216 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | 43959a9 | 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 | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 223 | OwningStmtResult TransformStmt(Stmt *S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 224 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 225 | /// \brief Transform the given expression. |
| 226 | /// |
Douglas Gregor | b98b199 | 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 | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 233 | OwningExprResult TransformExpr(Expr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 234 | |
Douglas Gregor | 577f75a | 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 | dcee1a1 | 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 | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 240 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 241 | |
| 242 | /// \brief Transform the definition of the given declaration. |
| 243 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 244 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 245 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 246 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 247 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 248 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 249 | |
Douglas Gregor | 6cd2198 | 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 | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 260 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 263 | /// \brief Transform the given nested-name-specifier. |
| 264 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 265 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | dcee1a1 | 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 | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 268 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 269 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 270 | QualType ObjectType = QualType(), |
| 271 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 272 | |
Douglas Gregor | 81499bb | 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 | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 280 | SourceLocation Loc, |
| 281 | QualType ObjectType = QualType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 283 | /// \brief Transform the given template name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 284 | /// |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 285 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 286 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 287 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 288 | TemplateName TransformTemplateName(TemplateName Name, |
| 289 | QualType ObjectType = QualType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 290 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 291 | /// \brief Transform the given template argument. |
| 292 | /// |
Mike Stump | 1eb4433 | 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 | 670444e | 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 | 833ca99 | 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 | a93c934 | 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 | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 309 | getDerived().getBaseLocation()); |
| 310 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 311 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 312 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 313 | #define TYPELOC(CLASS, PARENT) \ |
Douglas Gregor | 124b878 | 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 | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 316 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 317 | |
John McCall | 21ef0fa | 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 | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 333 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL, |
| 334 | QualType ObjectType); |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 335 | |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 336 | QualType |
| 337 | TransformTemplateSpecializationType(const TemplateSpecializationType *T, |
| 338 | QualType ObjectType); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 339 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 340 | OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
Zhongxing Xu | d8383d4 | 2010-04-21 06:32:25 +0000 | [diff] [blame] | 341 | OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 342 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 343 | #define STMT(Node, Parent) \ |
| 344 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 345 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 346 | OwningExprResult Transform##Node(Node *E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 347 | #define ABSTRACT_EXPR(Node, Parent) |
| 348 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 349 | |
Douglas Gregor | 577f75a | 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 | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 354 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 358 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 359 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 360 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 361 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 362 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 363 | /// |
John McCall | 85737a7 | 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 | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 367 | /// |
John McCall | 85737a7 | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 373 | |
Douglas Gregor | 577f75a | 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 | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 379 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 380 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 395 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 401 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 402 | ArrayType::ArraySizeModifier SizeMod, |
| 403 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 404 | unsigned IndexTypeQuals, |
| 405 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 406 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 412 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 413 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 414 | unsigned IndexTypeQuals, |
| 415 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 416 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 417 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 422 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 423 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 424 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 425 | unsigned IndexTypeQuals, |
| 426 | SourceRange BracketsRange); |
| 427 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 428 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 433 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 434 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 435 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 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 | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 444 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
| 445 | bool IsAltiVec, bool IsPixel); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 454 | |
| 455 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 460 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 461 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 462 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 463 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 469 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 470 | unsigned NumParamTypes, |
| 471 | bool Variadic, unsigned Quals); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 472 | |
John McCall | a2becad | 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 | ed97649 | 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 | 577f75a | 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 | 7da2431 | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 499 | |
| 500 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 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 | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 504 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 505 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 506 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | 577f75a | 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 | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 515 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 516 | |
Douglas Gregor | 577f75a | 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 | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 523 | SourceLocation TemplateLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 524 | const TemplateArgumentListInfo &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 525 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 526 | /// \brief Build a new qualified name type. |
| 527 | /// |
Mike Stump | 1eb4433 | 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 | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 533 | } |
Douglas Gregor | 577f75a | 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 | 4033642 | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 540 | /// different behavior. |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 541 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
| 542 | NestedNameSpecifier *NNS, QualType T) { |
Douglas Gregor | ae62889 | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 543 | if (NNS->isDependent()) { |
Douglas Gregor | 4033642 | 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 | ae62889 | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 545 | CXXScopeSpec SS; |
| 546 | SS.setScopeRep(NNS); |
| 547 | if (!SemaRef.computeDeclContext(SS)) |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 548 | return SemaRef.Context.getDependentNameType(Keyword, NNS, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 549 | cast<TemplateSpecializationType>(T)); |
Douglas Gregor | ae62889 | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 550 | } |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 551 | |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 552 | // FIXME: Handle elaborated-type-specifiers separately. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 553 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 554 | } |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 559 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 560 | /// different behavior. |
Douglas Gregor | 4a2023f | 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 | 4033642 | 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: |
Douglas Gregor | 107de90 | 2010-04-24 15:35:55 +0000 | [diff] [blame] | 577 | // Fall through. |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 578 | case ETK_Typename: |
Douglas Gregor | 107de90 | 2010-04-24 15:35:55 +0000 | [diff] [blame] | 579 | return SemaRef.CheckTypenameType(Keyword, NNS, *Id, SR); |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 580 | |
| 581 | case ETK_Class: Kind = TagDecl::TK_class; break; |
| 582 | case ETK_Struct: Kind = TagDecl::TK_struct; break; |
| 583 | case ETK_Union: Kind = TagDecl::TK_union; break; |
| 584 | case ETK_Enum: Kind = TagDecl::TK_enum; break; |
| 585 | } |
| 586 | |
| 587 | // We had a dependent elaborated-type-specifier that as been transformed |
| 588 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 589 | // referring to. |
| 590 | LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName); |
| 591 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 592 | if (!DC) |
| 593 | return QualType(); |
| 594 | |
| 595 | TagDecl *Tag = 0; |
| 596 | SemaRef.LookupQualifiedName(Result, DC); |
| 597 | switch (Result.getResultKind()) { |
| 598 | case LookupResult::NotFound: |
| 599 | case LookupResult::NotFoundInCurrentInstantiation: |
| 600 | break; |
| 601 | |
| 602 | case LookupResult::Found: |
| 603 | Tag = Result.getAsSingle<TagDecl>(); |
| 604 | break; |
| 605 | |
| 606 | case LookupResult::FoundOverloaded: |
| 607 | case LookupResult::FoundUnresolvedValue: |
| 608 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 609 | return QualType(); |
| 610 | |
| 611 | case LookupResult::Ambiguous: |
| 612 | // Let the LookupResult structure handle ambiguities. |
| 613 | return QualType(); |
| 614 | } |
| 615 | |
| 616 | if (!Tag) { |
Douglas Gregor | 1eabb7d | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 617 | // FIXME: Would be nice to highlight just the source range. |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 618 | SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope) |
Douglas Gregor | 1eabb7d | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 619 | << Kind << Id << DC; |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 620 | return QualType(); |
| 621 | } |
| 622 | |
| 623 | // FIXME: Terrible location information |
| 624 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) { |
| 625 | SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id; |
| 626 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 627 | return QualType(); |
| 628 | } |
| 629 | |
| 630 | // Build the elaborated-type-specifier type. |
| 631 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
| 632 | T = SemaRef.Context.getQualifiedNameType(NNS, T); |
| 633 | return SemaRef.Context.getElaboratedType(T, Kind); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 634 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 636 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 637 | /// identifier that names the next step in the nested-name-specifier. |
| 638 | /// |
| 639 | /// By default, performs semantic analysis when building the new |
| 640 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 641 | /// different behavior. |
| 642 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 643 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 644 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 645 | QualType ObjectType, |
| 646 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 647 | |
| 648 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 649 | /// namespace named in the next step in the nested-name-specifier. |
| 650 | /// |
| 651 | /// By default, performs semantic analysis when building the new |
| 652 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 653 | /// different behavior. |
| 654 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 655 | SourceRange Range, |
| 656 | NamespaceDecl *NS); |
| 657 | |
| 658 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 659 | /// type named in the next step in the nested-name-specifier. |
| 660 | /// |
| 661 | /// By default, performs semantic analysis when building the new |
| 662 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 663 | /// different behavior. |
| 664 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 665 | SourceRange Range, |
| 666 | bool TemplateKW, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 667 | QualType T); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 668 | |
| 669 | /// \brief Build a new template name given a nested name specifier, a flag |
| 670 | /// indicating whether the "template" keyword was provided, and the template |
| 671 | /// that the template name refers to. |
| 672 | /// |
| 673 | /// By default, builds the new template name directly. Subclasses may override |
| 674 | /// this routine to provide different behavior. |
| 675 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 676 | bool TemplateKW, |
| 677 | TemplateDecl *Template); |
| 678 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 679 | /// \brief Build a new template name given a nested name specifier and the |
| 680 | /// name that is referred to as a template. |
| 681 | /// |
| 682 | /// By default, performs semantic analysis to determine whether the name can |
| 683 | /// be resolved to a specific template, then builds the appropriate kind of |
| 684 | /// template name. Subclasses may override this routine to provide different |
| 685 | /// behavior. |
| 686 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 687 | const IdentifierInfo &II, |
| 688 | QualType ObjectType); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 689 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 690 | /// \brief Build a new template name given a nested name specifier and the |
| 691 | /// overloaded operator name that is referred to as a template. |
| 692 | /// |
| 693 | /// By default, performs semantic analysis to determine whether the name can |
| 694 | /// be resolved to a specific template, then builds the appropriate kind of |
| 695 | /// template name. Subclasses may override this routine to provide different |
| 696 | /// behavior. |
| 697 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 698 | OverloadedOperatorKind Operator, |
| 699 | QualType ObjectType); |
| 700 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 701 | /// \brief Build a new compound statement. |
| 702 | /// |
| 703 | /// By default, performs semantic analysis to build the new statement. |
| 704 | /// Subclasses may override this routine to provide different behavior. |
| 705 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 706 | MultiStmtArg Statements, |
| 707 | SourceLocation RBraceLoc, |
| 708 | bool IsStmtExpr) { |
| 709 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 710 | IsStmtExpr); |
| 711 | } |
| 712 | |
| 713 | /// \brief Build a new case statement. |
| 714 | /// |
| 715 | /// By default, performs semantic analysis to build the new statement. |
| 716 | /// Subclasses may override this routine to provide different behavior. |
| 717 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 718 | ExprArg LHS, |
| 719 | SourceLocation EllipsisLoc, |
| 720 | ExprArg RHS, |
| 721 | SourceLocation ColonLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 722 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 723 | ColonLoc); |
| 724 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 725 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 726 | /// \brief Attach the body to a new case statement. |
| 727 | /// |
| 728 | /// By default, performs semantic analysis to build the new statement. |
| 729 | /// Subclasses may override this routine to provide different behavior. |
| 730 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 731 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 732 | return move(S); |
| 733 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 734 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 735 | /// \brief Build a new default statement. |
| 736 | /// |
| 737 | /// By default, performs semantic analysis to build the new statement. |
| 738 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 739 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 740 | SourceLocation ColonLoc, |
| 741 | StmtArg SubStmt) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 742 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 743 | /*CurScope=*/0); |
| 744 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 745 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 746 | /// \brief Build a new label statement. |
| 747 | /// |
| 748 | /// By default, performs semantic analysis to build the new statement. |
| 749 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 750 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 751 | IdentifierInfo *Id, |
| 752 | SourceLocation ColonLoc, |
| 753 | StmtArg SubStmt) { |
| 754 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 755 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 756 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 757 | /// \brief Build a new "if" statement. |
| 758 | /// |
| 759 | /// By default, performs semantic analysis to build the new statement. |
| 760 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 761 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 762 | VarDecl *CondVar, StmtArg Then, |
| 763 | SourceLocation ElseLoc, StmtArg Else) { |
| 764 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
| 765 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 766 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 767 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 768 | /// \brief Start building a new switch statement. |
| 769 | /// |
| 770 | /// By default, performs semantic analysis to build the new statement. |
| 771 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 772 | OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond, |
| 773 | VarDecl *CondVar) { |
| 774 | return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 775 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 776 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 777 | /// \brief Attach the body to the switch statement. |
| 778 | /// |
| 779 | /// By default, performs semantic analysis to build the new statement. |
| 780 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 781 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 782 | StmtArg Switch, StmtArg Body) { |
| 783 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 784 | move(Body)); |
| 785 | } |
| 786 | |
| 787 | /// \brief Build a new while statement. |
| 788 | /// |
| 789 | /// By default, performs semantic analysis to build the new statement. |
| 790 | /// Subclasses may override this routine to provide different behavior. |
| 791 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 792 | Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 793 | VarDecl *CondVar, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 794 | StmtArg Body) { |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 795 | return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar), |
| 796 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 797 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 798 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 799 | /// \brief Build a new do-while statement. |
| 800 | /// |
| 801 | /// By default, performs semantic analysis to build the new statement. |
| 802 | /// Subclasses may override this routine to provide different behavior. |
| 803 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 804 | SourceLocation WhileLoc, |
| 805 | SourceLocation LParenLoc, |
| 806 | ExprArg Cond, |
| 807 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 808 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 809 | move(Cond), RParenLoc); |
| 810 | } |
| 811 | |
| 812 | /// \brief Build a new for statement. |
| 813 | /// |
| 814 | /// By default, performs semantic analysis to build the new statement. |
| 815 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 816 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 817 | SourceLocation LParenLoc, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 818 | StmtArg Init, Sema::FullExprArg Cond, |
| 819 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 820 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 821 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
| 822 | DeclPtrTy::make(CondVar), |
| 823 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 824 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 825 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 826 | /// \brief Build a new goto statement. |
| 827 | /// |
| 828 | /// By default, performs semantic analysis to build the new statement. |
| 829 | /// Subclasses may override this routine to provide different behavior. |
| 830 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 831 | SourceLocation LabelLoc, |
| 832 | LabelStmt *Label) { |
| 833 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 834 | } |
| 835 | |
| 836 | /// \brief Build a new indirect goto statement. |
| 837 | /// |
| 838 | /// By default, performs semantic analysis to build the new statement. |
| 839 | /// Subclasses may override this routine to provide different behavior. |
| 840 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 841 | SourceLocation StarLoc, |
| 842 | ExprArg Target) { |
| 843 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 844 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 845 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 846 | /// \brief Build a new return statement. |
| 847 | /// |
| 848 | /// By default, performs semantic analysis to build the new statement. |
| 849 | /// Subclasses may override this routine to provide different behavior. |
| 850 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 851 | ExprArg Result) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 852 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 853 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 854 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 855 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 856 | /// \brief Build a new declaration statement. |
| 857 | /// |
| 858 | /// By default, performs semantic analysis to build the new statement. |
| 859 | /// Subclasses may override this routine to provide different behavior. |
| 860 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 861 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 862 | SourceLocation EndLoc) { |
| 863 | return getSema().Owned( |
| 864 | new (getSema().Context) DeclStmt( |
| 865 | DeclGroupRef::Create(getSema().Context, |
| 866 | Decls, NumDecls), |
| 867 | StartLoc, EndLoc)); |
| 868 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 869 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 870 | /// \brief Build a new inline asm statement. |
| 871 | /// |
| 872 | /// By default, performs semantic analysis to build the new statement. |
| 873 | /// Subclasses may override this routine to provide different behavior. |
| 874 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 875 | bool IsSimple, |
| 876 | bool IsVolatile, |
| 877 | unsigned NumOutputs, |
| 878 | unsigned NumInputs, |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 879 | IdentifierInfo **Names, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 880 | MultiExprArg Constraints, |
| 881 | MultiExprArg Exprs, |
| 882 | ExprArg AsmString, |
| 883 | MultiExprArg Clobbers, |
| 884 | SourceLocation RParenLoc, |
| 885 | bool MSAsm) { |
| 886 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 887 | NumInputs, Names, move(Constraints), |
| 888 | move(Exprs), move(AsmString), move(Clobbers), |
| 889 | RParenLoc, MSAsm); |
| 890 | } |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 891 | |
| 892 | /// \brief Build a new Objective-C @try statement. |
| 893 | /// |
| 894 | /// By default, performs semantic analysis to build the new statement. |
| 895 | /// Subclasses may override this routine to provide different behavior. |
| 896 | OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
| 897 | StmtArg TryBody, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 898 | MultiStmtArg CatchStmts, |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 899 | StmtArg Finally) { |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 900 | return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts), |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 901 | move(Finally)); |
| 902 | } |
| 903 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 904 | /// \brief Rebuild an Objective-C exception declaration. |
| 905 | /// |
| 906 | /// By default, performs semantic analysis to build the new declaration. |
| 907 | /// Subclasses may override this routine to provide different behavior. |
| 908 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 909 | TypeSourceInfo *TInfo, QualType T) { |
| 910 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 911 | ExceptionDecl->getIdentifier(), |
| 912 | ExceptionDecl->getLocation()); |
| 913 | } |
| 914 | |
| 915 | /// \brief Build a new Objective-C @catch statement. |
| 916 | /// |
| 917 | /// By default, performs semantic analysis to build the new statement. |
| 918 | /// Subclasses may override this routine to provide different behavior. |
| 919 | OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
| 920 | SourceLocation RParenLoc, |
| 921 | VarDecl *Var, |
| 922 | StmtArg Body) { |
| 923 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
| 924 | Sema::DeclPtrTy::make(Var), |
| 925 | move(Body)); |
| 926 | } |
| 927 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 928 | /// \brief Build a new Objective-C @finally statement. |
| 929 | /// |
| 930 | /// By default, performs semantic analysis to build the new statement. |
| 931 | /// Subclasses may override this routine to provide different behavior. |
| 932 | OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
| 933 | StmtArg Body) { |
| 934 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body)); |
| 935 | } |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 936 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 937 | /// \brief Build a new Objective-C @throw statement. |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 938 | /// |
| 939 | /// By default, performs semantic analysis to build the new statement. |
| 940 | /// Subclasses may override this routine to provide different behavior. |
| 941 | OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
| 942 | ExprArg Operand) { |
| 943 | return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand)); |
| 944 | } |
| 945 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 946 | /// \brief Build a new Objective-C @synchronized statement. |
| 947 | /// |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 948 | /// By default, performs semantic analysis to build the new statement. |
| 949 | /// Subclasses may override this routine to provide different behavior. |
| 950 | OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
| 951 | ExprArg Object, |
| 952 | StmtArg Body) { |
| 953 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object), |
| 954 | move(Body)); |
| 955 | } |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 956 | |
| 957 | /// \brief Build a new Objective-C fast enumeration statement. |
| 958 | /// |
| 959 | /// By default, performs semantic analysis to build the new statement. |
| 960 | /// Subclasses may override this routine to provide different behavior. |
| 961 | OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
| 962 | SourceLocation LParenLoc, |
| 963 | StmtArg Element, |
| 964 | ExprArg Collection, |
| 965 | SourceLocation RParenLoc, |
| 966 | StmtArg Body) { |
| 967 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
| 968 | move(Element), |
| 969 | move(Collection), |
| 970 | RParenLoc, |
| 971 | move(Body)); |
| 972 | } |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 973 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 974 | /// \brief Build a new C++ exception declaration. |
| 975 | /// |
| 976 | /// By default, performs semantic analysis to build the new decaration. |
| 977 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 978 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 979 | TypeSourceInfo *Declarator, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 980 | IdentifierInfo *Name, |
| 981 | SourceLocation Loc, |
| 982 | SourceRange TypeRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 983 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 984 | TypeRange); |
| 985 | } |
| 986 | |
| 987 | /// \brief Build a new C++ catch statement. |
| 988 | /// |
| 989 | /// By default, performs semantic analysis to build the new statement. |
| 990 | /// Subclasses may override this routine to provide different behavior. |
| 991 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 992 | VarDecl *ExceptionDecl, |
| 993 | StmtArg Handler) { |
| 994 | return getSema().Owned( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 995 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 996 | Handler.takeAs<Stmt>())); |
| 997 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 998 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 999 | /// \brief Build a new C++ try statement. |
| 1000 | /// |
| 1001 | /// By default, performs semantic analysis to build the new statement. |
| 1002 | /// Subclasses may override this routine to provide different behavior. |
| 1003 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 1004 | StmtArg TryBlock, |
| 1005 | MultiStmtArg Handlers) { |
| 1006 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 1007 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1008 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1009 | /// \brief Build a new expression that references a declaration. |
| 1010 | /// |
| 1011 | /// By default, performs semantic analysis to build the new expression. |
| 1012 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1013 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 1014 | LookupResult &R, |
| 1015 | bool RequiresADL) { |
| 1016 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1017 | } |
| 1018 | |
| 1019 | |
| 1020 | /// \brief Build a new expression that references a declaration. |
| 1021 | /// |
| 1022 | /// By default, performs semantic analysis to build the new expression. |
| 1023 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1024 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 1025 | SourceRange QualifierRange, |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1026 | ValueDecl *VD, SourceLocation Loc, |
| 1027 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1028 | CXXScopeSpec SS; |
| 1029 | SS.setScopeRep(Qualifier); |
| 1030 | SS.setRange(QualifierRange); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1031 | |
| 1032 | // FIXME: loses template args. |
| 1033 | |
| 1034 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1035 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1036 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1037 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1038 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1039 | /// By default, performs semantic analysis to build the new expression. |
| 1040 | /// Subclasses may override this routine to provide different behavior. |
| 1041 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 1042 | SourceLocation RParen) { |
| 1043 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 1044 | } |
| 1045 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1046 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1047 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1048 | /// By default, performs semantic analysis to build the new expression. |
| 1049 | /// Subclasses may override this routine to provide different behavior. |
| 1050 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 1051 | SourceLocation OperatorLoc, |
| 1052 | bool isArrow, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1053 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 1054 | SourceRange QualifierRange, |
| 1055 | TypeSourceInfo *ScopeType, |
| 1056 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 1057 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1058 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1059 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1060 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1061 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1062 | /// By default, performs semantic analysis to build the new expression. |
| 1063 | /// Subclasses may override this routine to provide different behavior. |
| 1064 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 1065 | UnaryOperator::Opcode Opc, |
| 1066 | ExprArg SubExpr) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1067 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1068 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1069 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1070 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1071 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1072 | /// By default, performs semantic analysis to build the new expression. |
| 1073 | /// Subclasses may override this routine to provide different behavior. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1074 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 1075 | SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1076 | bool isSizeOf, SourceRange R) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1077 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1080 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1081 | /// argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1082 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1083 | /// By default, performs semantic analysis to build the new expression. |
| 1084 | /// Subclasses may override this routine to provide different behavior. |
| 1085 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 1086 | bool isSizeOf, SourceRange R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1087 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1088 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 1089 | OpLoc, isSizeOf, R); |
| 1090 | if (Result.isInvalid()) |
| 1091 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1092 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1093 | SubExpr.release(); |
| 1094 | return move(Result); |
| 1095 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1096 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1097 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1098 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1099 | /// By default, performs semantic analysis to build the new expression. |
| 1100 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1101 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1102 | SourceLocation LBracketLoc, |
| 1103 | ExprArg RHS, |
| 1104 | SourceLocation RBracketLoc) { |
| 1105 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1106 | LBracketLoc, move(RHS), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1107 | RBracketLoc); |
| 1108 | } |
| 1109 | |
| 1110 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1111 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1112 | /// By default, performs semantic analysis to build the new expression. |
| 1113 | /// Subclasses may override this routine to provide different behavior. |
| 1114 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 1115 | MultiExprArg Args, |
| 1116 | SourceLocation *CommaLocs, |
| 1117 | SourceLocation RParenLoc) { |
| 1118 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 1119 | move(Args), CommaLocs, RParenLoc); |
| 1120 | } |
| 1121 | |
| 1122 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1123 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1124 | /// By default, performs semantic analysis to build the new expression. |
| 1125 | /// Subclasses may override this routine to provide different behavior. |
| 1126 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1127 | bool isArrow, |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1128 | NestedNameSpecifier *Qualifier, |
| 1129 | SourceRange QualifierRange, |
| 1130 | SourceLocation MemberLoc, |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 1131 | ValueDecl *Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1132 | NamedDecl *FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1133 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 1134 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1135 | if (!Member->getDeclName()) { |
| 1136 | // We have a reference to an unnamed field. |
| 1137 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1138 | |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1139 | Expr *BaseExpr = Base.takeAs<Expr>(); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1140 | if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, |
| 1141 | FoundDecl, Member)) |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1142 | return getSema().ExprError(); |
Douglas Gregor | 8aa5f40 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 1143 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1144 | MemberExpr *ME = |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1145 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1146 | Member, MemberLoc, |
| 1147 | cast<FieldDecl>(Member)->getType()); |
| 1148 | return getSema().Owned(ME); |
| 1149 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1150 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1151 | CXXScopeSpec SS; |
| 1152 | if (Qualifier) { |
| 1153 | SS.setRange(QualifierRange); |
| 1154 | SS.setScopeRep(Qualifier); |
| 1155 | } |
| 1156 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1157 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1158 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1159 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1160 | // cases; we should avoid this when possible. |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1161 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 1162 | Sema::LookupMemberName); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1163 | R.addDecl(FoundDecl); |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1164 | R.resolveKind(); |
| 1165 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1166 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 1167 | OpLoc, isArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1168 | SS, FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1169 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1170 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1171 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1172 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1173 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1174 | /// By default, performs semantic analysis to build the new expression. |
| 1175 | /// Subclasses may override this routine to provide different behavior. |
| 1176 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1177 | BinaryOperator::Opcode Opc, |
| 1178 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1179 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 1180 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1184 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1185 | /// By default, performs semantic analysis to build the new expression. |
| 1186 | /// Subclasses may override this routine to provide different behavior. |
| 1187 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1188 | SourceLocation QuestionLoc, |
| 1189 | ExprArg LHS, |
| 1190 | SourceLocation ColonLoc, |
| 1191 | ExprArg RHS) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1192 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1193 | move(LHS), move(RHS)); |
| 1194 | } |
| 1195 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1196 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1197 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1198 | /// By default, performs semantic analysis to build the new expression. |
| 1199 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1200 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1201 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1202 | SourceLocation RParenLoc, |
| 1203 | ExprArg SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1204 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1205 | move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1206 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1207 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1208 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1209 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1210 | /// By default, performs semantic analysis to build the new expression. |
| 1211 | /// Subclasses may override this routine to provide different behavior. |
| 1212 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1213 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1214 | SourceLocation RParenLoc, |
| 1215 | ExprArg Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1216 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1217 | move(Init)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1218 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1219 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1220 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1221 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1222 | /// By default, performs semantic analysis to build the new expression. |
| 1223 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1224 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1225 | SourceLocation OpLoc, |
| 1226 | SourceLocation AccessorLoc, |
| 1227 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1228 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1229 | CXXScopeSpec SS; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1230 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1231 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1232 | OpLoc, /*IsArrow*/ false, |
| 1233 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1234 | DeclarationName(&Accessor), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1235 | AccessorLoc, |
| 1236 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1237 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1238 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1239 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1240 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1241 | /// By default, performs semantic analysis to build the new expression. |
| 1242 | /// Subclasses may override this routine to provide different behavior. |
| 1243 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1244 | MultiExprArg Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1245 | SourceLocation RBraceLoc, |
| 1246 | QualType ResultTy) { |
| 1247 | OwningExprResult Result |
| 1248 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1249 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1250 | return move(Result); |
| 1251 | |
| 1252 | // Patch in the result type we were given, which may have been computed |
| 1253 | // when the initial InitListExpr was built. |
| 1254 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1255 | ILE->setType(ResultTy); |
| 1256 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1257 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1258 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1259 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1260 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1261 | /// By default, performs semantic analysis to build the new expression. |
| 1262 | /// Subclasses may override this routine to provide different behavior. |
| 1263 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1264 | MultiExprArg ArrayExprs, |
| 1265 | SourceLocation EqualOrColonLoc, |
| 1266 | bool GNUSyntax, |
| 1267 | ExprArg Init) { |
| 1268 | OwningExprResult Result |
| 1269 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1270 | move(Init)); |
| 1271 | if (Result.isInvalid()) |
| 1272 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1273 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1274 | ArrayExprs.release(); |
| 1275 | return move(Result); |
| 1276 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1277 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1278 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1279 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1280 | /// By default, builds the implicit value initialization without performing |
| 1281 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1282 | /// different behavior. |
| 1283 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1284 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1285 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1286 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1287 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1288 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1289 | /// By default, performs semantic analysis to build the new expression. |
| 1290 | /// Subclasses may override this routine to provide different behavior. |
| 1291 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1292 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1293 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1294 | RParenLoc); |
| 1295 | } |
| 1296 | |
| 1297 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1298 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1299 | /// By default, performs semantic analysis to build the new expression. |
| 1300 | /// Subclasses may override this routine to provide different behavior. |
| 1301 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1302 | MultiExprArg SubExprs, |
| 1303 | SourceLocation RParenLoc) { |
Fariborz Jahanian | f88f7ab | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1304 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1305 | move(SubExprs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1306 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1307 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1308 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1309 | /// |
| 1310 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1311 | /// rather than attempting to map the label statement itself. |
| 1312 | /// Subclasses may override this routine to provide different behavior. |
| 1313 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1314 | SourceLocation LabelLoc, |
| 1315 | LabelStmt *Label) { |
| 1316 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1317 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1318 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1319 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1320 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1321 | /// By default, performs semantic analysis to build the new expression. |
| 1322 | /// Subclasses may override this routine to provide different behavior. |
| 1323 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1324 | StmtArg SubStmt, |
| 1325 | SourceLocation RParenLoc) { |
| 1326 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1327 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1328 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1329 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1330 | /// |
| 1331 | /// By default, performs semantic analysis to build the new expression. |
| 1332 | /// Subclasses may override this routine to provide different behavior. |
| 1333 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1334 | QualType T1, QualType T2, |
| 1335 | SourceLocation RParenLoc) { |
| 1336 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1337 | T1.getAsOpaquePtr(), |
| 1338 | T2.getAsOpaquePtr(), |
| 1339 | RParenLoc); |
| 1340 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1341 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1342 | /// \brief Build a new __builtin_choose_expr expression. |
| 1343 | /// |
| 1344 | /// By default, performs semantic analysis to build the new expression. |
| 1345 | /// Subclasses may override this routine to provide different behavior. |
| 1346 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1347 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1348 | SourceLocation RParenLoc) { |
| 1349 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1350 | move(Cond), move(LHS), move(RHS), |
| 1351 | RParenLoc); |
| 1352 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1353 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1354 | /// \brief Build a new overloaded operator call expression. |
| 1355 | /// |
| 1356 | /// By default, performs semantic analysis to build the new expression. |
| 1357 | /// The semantic analysis provides the behavior of template instantiation, |
| 1358 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1359 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1360 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1361 | /// provide different behavior. |
| 1362 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1363 | SourceLocation OpLoc, |
| 1364 | ExprArg Callee, |
| 1365 | ExprArg First, |
| 1366 | ExprArg Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1367 | |
| 1368 | /// \brief Build a new C++ "named" cast expression, such as static_cast or |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1369 | /// reinterpret_cast. |
| 1370 | /// |
| 1371 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1372 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1373 | /// Subclasses may override this routine to provide different behavior. |
| 1374 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1375 | Stmt::StmtClass Class, |
| 1376 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1377 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1378 | SourceLocation RAngleLoc, |
| 1379 | SourceLocation LParenLoc, |
| 1380 | ExprArg SubExpr, |
| 1381 | SourceLocation RParenLoc) { |
| 1382 | switch (Class) { |
| 1383 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1384 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1385 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1386 | move(SubExpr), RParenLoc); |
| 1387 | |
| 1388 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1389 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1390 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1391 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1392 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1393 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1394 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1395 | RAngleLoc, LParenLoc, |
| 1396 | move(SubExpr), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1397 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1398 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1399 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1400 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1401 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1402 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1403 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1404 | default: |
| 1405 | assert(false && "Invalid C++ named cast"); |
| 1406 | break; |
| 1407 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1408 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1409 | return getSema().ExprError(); |
| 1410 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1411 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1412 | /// \brief Build a new C++ static_cast expression. |
| 1413 | /// |
| 1414 | /// By default, performs semantic analysis to build the new expression. |
| 1415 | /// Subclasses may override this routine to provide different behavior. |
| 1416 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1417 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1418 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1419 | SourceLocation RAngleLoc, |
| 1420 | SourceLocation LParenLoc, |
| 1421 | ExprArg SubExpr, |
| 1422 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1423 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1424 | TInfo, move(SubExpr), |
| 1425 | SourceRange(LAngleLoc, RAngleLoc), |
| 1426 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | /// \brief Build a new C++ dynamic_cast 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 RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1434 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1435 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1436 | SourceLocation RAngleLoc, |
| 1437 | SourceLocation LParenLoc, |
| 1438 | ExprArg SubExpr, |
| 1439 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1440 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1441 | TInfo, move(SubExpr), |
| 1442 | SourceRange(LAngleLoc, RAngleLoc), |
| 1443 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
| 1446 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1447 | /// |
| 1448 | /// By default, performs semantic analysis to build the new expression. |
| 1449 | /// Subclasses may override this routine to provide different behavior. |
| 1450 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1451 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1452 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1453 | SourceLocation RAngleLoc, |
| 1454 | SourceLocation LParenLoc, |
| 1455 | ExprArg SubExpr, |
| 1456 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1457 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1458 | TInfo, move(SubExpr), |
| 1459 | SourceRange(LAngleLoc, RAngleLoc), |
| 1460 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | /// \brief Build a new C++ const_cast expression. |
| 1464 | /// |
| 1465 | /// By default, performs semantic analysis to build the new expression. |
| 1466 | /// Subclasses may override this routine to provide different behavior. |
| 1467 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1468 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1469 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1470 | SourceLocation RAngleLoc, |
| 1471 | SourceLocation LParenLoc, |
| 1472 | ExprArg SubExpr, |
| 1473 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1474 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1475 | TInfo, move(SubExpr), |
| 1476 | SourceRange(LAngleLoc, RAngleLoc), |
| 1477 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1478 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1479 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1480 | /// \brief Build a new C++ functional-style cast expression. |
| 1481 | /// |
| 1482 | /// By default, performs semantic analysis to build the new expression. |
| 1483 | /// Subclasses may override this routine to provide different behavior. |
| 1484 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1485 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1486 | SourceLocation LParenLoc, |
| 1487 | ExprArg SubExpr, |
| 1488 | SourceLocation RParenLoc) { |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1489 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1490 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1491 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1492 | LParenLoc, |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1493 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1494 | /*CommaLocs=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1495 | RParenLoc); |
| 1496 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1497 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1498 | /// \brief Build a new C++ typeid(type) expression. |
| 1499 | /// |
| 1500 | /// By default, performs semantic analysis to build the new expression. |
| 1501 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1502 | OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 1503 | SourceLocation TypeidLoc, |
| 1504 | TypeSourceInfo *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1505 | SourceLocation RParenLoc) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1506 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
| 1507 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1508 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1509 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1510 | /// \brief Build a new C++ typeid(expr) expression. |
| 1511 | /// |
| 1512 | /// By default, performs semantic analysis to build the new expression. |
| 1513 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1514 | OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 1515 | SourceLocation TypeidLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1516 | ExprArg Operand, |
| 1517 | SourceLocation RParenLoc) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1518 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand), |
| 1519 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1522 | /// \brief Build a new C++ "this" expression. |
| 1523 | /// |
| 1524 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1525 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1526 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1527 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1528 | QualType ThisType, |
| 1529 | bool isImplicit) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1530 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1531 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1532 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | /// \brief Build a new C++ throw expression. |
| 1536 | /// |
| 1537 | /// By default, performs semantic analysis to build the new expression. |
| 1538 | /// Subclasses may override this routine to provide different behavior. |
| 1539 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1540 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1541 | } |
| 1542 | |
| 1543 | /// \brief Build a new C++ default-argument expression. |
| 1544 | /// |
| 1545 | /// By default, builds a new default-argument expression, which does not |
| 1546 | /// require any semantic analysis. Subclasses may override this routine to |
| 1547 | /// provide different behavior. |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1548 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
| 1549 | ParmVarDecl *Param) { |
| 1550 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1551 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | /// \brief Build a new C++ zero-initialization expression. |
| 1555 | /// |
| 1556 | /// By default, performs semantic analysis to build the new expression. |
| 1557 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1558 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1559 | SourceLocation LParenLoc, |
| 1560 | QualType T, |
| 1561 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1562 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1563 | T.getAsOpaquePtr(), LParenLoc, |
| 1564 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1565 | 0, RParenLoc); |
| 1566 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1567 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1568 | /// \brief Build a new C++ "new" expression. |
| 1569 | /// |
| 1570 | /// By default, performs semantic analysis to build the new expression. |
| 1571 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1572 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1573 | bool UseGlobal, |
| 1574 | SourceLocation PlacementLParen, |
| 1575 | MultiExprArg PlacementArgs, |
| 1576 | SourceLocation PlacementRParen, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1577 | bool ParenTypeId, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1578 | QualType AllocType, |
| 1579 | SourceLocation TypeLoc, |
| 1580 | SourceRange TypeRange, |
| 1581 | ExprArg ArraySize, |
| 1582 | SourceLocation ConstructorLParen, |
| 1583 | MultiExprArg ConstructorArgs, |
| 1584 | SourceLocation ConstructorRParen) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1585 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1586 | PlacementLParen, |
| 1587 | move(PlacementArgs), |
| 1588 | PlacementRParen, |
| 1589 | ParenTypeId, |
| 1590 | AllocType, |
| 1591 | TypeLoc, |
| 1592 | TypeRange, |
| 1593 | move(ArraySize), |
| 1594 | ConstructorLParen, |
| 1595 | move(ConstructorArgs), |
| 1596 | ConstructorRParen); |
| 1597 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1598 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1599 | /// \brief Build a new C++ "delete" 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 RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1604 | bool IsGlobalDelete, |
| 1605 | bool IsArrayForm, |
| 1606 | ExprArg Operand) { |
| 1607 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1608 | move(Operand)); |
| 1609 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1610 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1611 | /// \brief Build a new unary type trait expression. |
| 1612 | /// |
| 1613 | /// By default, performs semantic analysis to build the new expression. |
| 1614 | /// Subclasses may override this routine to provide different behavior. |
| 1615 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1616 | SourceLocation StartLoc, |
| 1617 | SourceLocation LParenLoc, |
| 1618 | QualType T, |
| 1619 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1620 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1621 | T.getAsOpaquePtr(), RParenLoc); |
| 1622 | } |
| 1623 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1624 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1625 | /// expression. |
| 1626 | /// |
| 1627 | /// By default, performs semantic analysis to build the new expression. |
| 1628 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1629 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1630 | SourceRange QualifierRange, |
| 1631 | DeclarationName Name, |
| 1632 | SourceLocation Location, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1633 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1634 | CXXScopeSpec SS; |
| 1635 | SS.setRange(QualifierRange); |
| 1636 | SS.setScopeRep(NNS); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1637 | |
| 1638 | if (TemplateArgs) |
| 1639 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1640 | *TemplateArgs); |
| 1641 | |
| 1642 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | /// \brief Build a new template-id expression. |
| 1646 | /// |
| 1647 | /// By default, performs semantic analysis to build the new expression. |
| 1648 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1649 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1650 | LookupResult &R, |
| 1651 | bool RequiresADL, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1652 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1653 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | /// \brief Build a new object-construction expression. |
| 1657 | /// |
| 1658 | /// By default, performs semantic analysis to build the new expression. |
| 1659 | /// Subclasses may override this routine to provide different behavior. |
| 1660 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1661 | SourceLocation Loc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1662 | CXXConstructorDecl *Constructor, |
| 1663 | bool IsElidable, |
| 1664 | MultiExprArg Args) { |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1665 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
| 1666 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
| 1667 | ConvertedArgs)) |
| 1668 | return getSema().ExprError(); |
| 1669 | |
| 1670 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1671 | move_arg(ConvertedArgs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | /// \brief Build a new object-construction expression. |
| 1675 | /// |
| 1676 | /// By default, performs semantic analysis to build the new expression. |
| 1677 | /// Subclasses may override this routine to provide different behavior. |
| 1678 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1679 | QualType T, |
| 1680 | SourceLocation LParenLoc, |
| 1681 | MultiExprArg Args, |
| 1682 | SourceLocation *Commas, |
| 1683 | SourceLocation RParenLoc) { |
| 1684 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1685 | T.getAsOpaquePtr(), |
| 1686 | LParenLoc, |
| 1687 | move(Args), |
| 1688 | Commas, |
| 1689 | RParenLoc); |
| 1690 | } |
| 1691 | |
| 1692 | /// \brief Build a new object-construction expression. |
| 1693 | /// |
| 1694 | /// By default, performs semantic analysis to build the new expression. |
| 1695 | /// Subclasses may override this routine to provide different behavior. |
| 1696 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1697 | QualType T, |
| 1698 | SourceLocation LParenLoc, |
| 1699 | MultiExprArg Args, |
| 1700 | SourceLocation *Commas, |
| 1701 | SourceLocation RParenLoc) { |
| 1702 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1703 | /*FIXME*/LParenLoc), |
| 1704 | T.getAsOpaquePtr(), |
| 1705 | LParenLoc, |
| 1706 | move(Args), |
| 1707 | Commas, |
| 1708 | RParenLoc); |
| 1709 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1710 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1711 | /// \brief Build a new member reference expression. |
| 1712 | /// |
| 1713 | /// By default, performs semantic analysis to build the new expression. |
| 1714 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1715 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1716 | QualType BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1717 | bool IsArrow, |
| 1718 | SourceLocation OperatorLoc, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1719 | NestedNameSpecifier *Qualifier, |
| 1720 | SourceRange QualifierRange, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1721 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1722 | DeclarationName Name, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1723 | SourceLocation MemberLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1724 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1725 | CXXScopeSpec SS; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1726 | SS.setRange(QualifierRange); |
| 1727 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1728 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1729 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1730 | OperatorLoc, IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1731 | SS, FirstQualifierInScope, |
| 1732 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1733 | } |
| 1734 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1735 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1736 | /// |
| 1737 | /// By default, performs semantic analysis to build the new expression. |
| 1738 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1739 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1740 | QualType BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1741 | SourceLocation OperatorLoc, |
| 1742 | bool IsArrow, |
| 1743 | NestedNameSpecifier *Qualifier, |
| 1744 | SourceRange QualifierRange, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1745 | NamedDecl *FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1746 | LookupResult &R, |
| 1747 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1748 | CXXScopeSpec SS; |
| 1749 | SS.setRange(QualifierRange); |
| 1750 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1751 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1752 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1753 | OperatorLoc, IsArrow, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1754 | SS, FirstQualifierInScope, |
| 1755 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1756 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1757 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1758 | /// \brief Build a new Objective-C @encode expression. |
| 1759 | /// |
| 1760 | /// By default, performs semantic analysis to build the new expression. |
| 1761 | /// Subclasses may override this routine to provide different behavior. |
| 1762 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1763 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1764 | SourceLocation RParenLoc) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1765 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1766 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1767 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1768 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1769 | /// \brief Build a new Objective-C class message. |
| 1770 | OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
| 1771 | Selector Sel, |
| 1772 | ObjCMethodDecl *Method, |
| 1773 | SourceLocation LBracLoc, |
| 1774 | MultiExprArg Args, |
| 1775 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1776 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 1777 | ReceiverTypeInfo->getType(), |
| 1778 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | f49bb08 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1779 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1780 | move(Args)); |
| 1781 | } |
| 1782 | |
| 1783 | /// \brief Build a new Objective-C instance message. |
| 1784 | OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver, |
| 1785 | Selector Sel, |
| 1786 | ObjCMethodDecl *Method, |
| 1787 | SourceLocation LBracLoc, |
| 1788 | MultiExprArg Args, |
| 1789 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1790 | QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType(); |
| 1791 | return SemaRef.BuildInstanceMessage(move(Receiver), |
| 1792 | ReceiverType, |
| 1793 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | f49bb08 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1794 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1795 | move(Args)); |
| 1796 | } |
| 1797 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1798 | /// \brief Build a new Objective-C ivar reference expression. |
| 1799 | /// |
| 1800 | /// By default, performs semantic analysis to build the new expression. |
| 1801 | /// Subclasses may override this routine to provide different behavior. |
| 1802 | OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar, |
| 1803 | SourceLocation IvarLoc, |
| 1804 | bool IsArrow, bool IsFreeIvar) { |
| 1805 | // FIXME: We lose track of the IsFreeIvar bit. |
| 1806 | CXXScopeSpec SS; |
| 1807 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1808 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 1809 | Sema::LookupMemberName); |
| 1810 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1811 | /*FIME:*/IvarLoc, |
| 1812 | SS, DeclPtrTy()); |
| 1813 | if (Result.isInvalid()) |
| 1814 | return getSema().ExprError(); |
| 1815 | |
| 1816 | if (Result.get()) |
| 1817 | return move(Result); |
| 1818 | |
| 1819 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
| 1820 | Base->getType(), |
| 1821 | /*FIXME:*/IvarLoc, IsArrow, SS, |
| 1822 | /*FirstQualifierInScope=*/0, |
| 1823 | R, |
| 1824 | /*TemplateArgs=*/0); |
| 1825 | } |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1826 | |
| 1827 | /// \brief Build a new Objective-C property reference expression. |
| 1828 | /// |
| 1829 | /// By default, performs semantic analysis to build the new expression. |
| 1830 | /// Subclasses may override this routine to provide different behavior. |
| 1831 | OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg, |
| 1832 | ObjCPropertyDecl *Property, |
| 1833 | SourceLocation PropertyLoc) { |
| 1834 | CXXScopeSpec SS; |
| 1835 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1836 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 1837 | Sema::LookupMemberName); |
| 1838 | bool IsArrow = false; |
| 1839 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1840 | /*FIME:*/PropertyLoc, |
| 1841 | SS, DeclPtrTy()); |
| 1842 | if (Result.isInvalid()) |
| 1843 | return getSema().ExprError(); |
| 1844 | |
| 1845 | if (Result.get()) |
| 1846 | return move(Result); |
| 1847 | |
| 1848 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
| 1849 | Base->getType(), |
| 1850 | /*FIXME:*/PropertyLoc, IsArrow, |
| 1851 | SS, |
| 1852 | /*FirstQualifierInScope=*/0, |
| 1853 | R, |
| 1854 | /*TemplateArgs=*/0); |
| 1855 | } |
| 1856 | |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 1857 | /// \brief Build a new Objective-C implicit setter/getter reference |
| 1858 | /// expression. |
| 1859 | /// |
| 1860 | /// By default, performs semantic analysis to build the new expression. |
| 1861 | /// Subclasses may override this routine to provide different behavior. |
| 1862 | OwningExprResult RebuildObjCImplicitSetterGetterRefExpr( |
| 1863 | ObjCMethodDecl *Getter, |
| 1864 | QualType T, |
| 1865 | ObjCMethodDecl *Setter, |
| 1866 | SourceLocation NameLoc, |
| 1867 | ExprArg Base) { |
| 1868 | // Since these expressions can only be value-dependent, we do not need to |
| 1869 | // perform semantic analysis again. |
| 1870 | return getSema().Owned( |
| 1871 | new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T, |
| 1872 | Setter, |
| 1873 | NameLoc, |
| 1874 | Base.takeAs<Expr>())); |
| 1875 | } |
| 1876 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1877 | /// \brief Build a new Objective-C "isa" expression. |
| 1878 | /// |
| 1879 | /// By default, performs semantic analysis to build the new expression. |
| 1880 | /// Subclasses may override this routine to provide different behavior. |
| 1881 | OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc, |
| 1882 | bool IsArrow) { |
| 1883 | CXXScopeSpec SS; |
| 1884 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1885 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 1886 | Sema::LookupMemberName); |
| 1887 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1888 | /*FIME:*/IsaLoc, |
| 1889 | SS, DeclPtrTy()); |
| 1890 | if (Result.isInvalid()) |
| 1891 | return getSema().ExprError(); |
| 1892 | |
| 1893 | if (Result.get()) |
| 1894 | return move(Result); |
| 1895 | |
| 1896 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
| 1897 | Base->getType(), |
| 1898 | /*FIXME:*/IsaLoc, IsArrow, SS, |
| 1899 | /*FirstQualifierInScope=*/0, |
| 1900 | R, |
| 1901 | /*TemplateArgs=*/0); |
| 1902 | } |
| 1903 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1904 | /// \brief Build a new shuffle vector expression. |
| 1905 | /// |
| 1906 | /// By default, performs semantic analysis to build the new expression. |
| 1907 | /// Subclasses may override this routine to provide different behavior. |
| 1908 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1909 | MultiExprArg SubExprs, |
| 1910 | SourceLocation RParenLoc) { |
| 1911 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1912 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1913 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1914 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1915 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1916 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1917 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1918 | // Build a reference to the __builtin_shufflevector builtin |
| 1919 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1920 | Expr *Callee |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1921 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1922 | BuiltinLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1923 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1924 | |
| 1925 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1926 | unsigned NumSubExprs = SubExprs.size(); |
| 1927 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1928 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1929 | Subs, NumSubExprs, |
| 1930 | Builtin->getResultType(), |
| 1931 | RParenLoc); |
| 1932 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1933 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1934 | // Type-check the __builtin_shufflevector expression. |
| 1935 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1936 | if (Result.isInvalid()) |
| 1937 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1938 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1939 | OwnedCall.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1940 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1941 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1942 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1943 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1944 | template<typename Derived> |
| 1945 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1946 | if (!S) |
| 1947 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1948 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1949 | switch (S->getStmtClass()) { |
| 1950 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1951 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1952 | // Transform individual statement nodes |
| 1953 | #define STMT(Node, Parent) \ |
| 1954 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1955 | #define EXPR(Node, Parent) |
| 1956 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1957 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1958 | // Transform expressions by calling TransformExpr. |
| 1959 | #define STMT(Node, Parent) |
John McCall | 09cc141 | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1960 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1961 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1962 | #include "clang/AST/StmtNodes.def" |
| 1963 | { |
| 1964 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1965 | if (E.isInvalid()) |
| 1966 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1967 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1968 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1969 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1970 | } |
| 1971 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1972 | return SemaRef.Owned(S->Retain()); |
| 1973 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1974 | |
| 1975 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1976 | template<typename Derived> |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1977 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1978 | if (!E) |
| 1979 | return SemaRef.Owned(E); |
| 1980 | |
| 1981 | switch (E->getStmtClass()) { |
| 1982 | case Stmt::NoStmtClass: break; |
| 1983 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
John McCall | 09cc141 | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1984 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1985 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1986 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1987 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1988 | } |
| 1989 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1990 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | template<typename Derived> |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1994 | NestedNameSpecifier * |
| 1995 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1996 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1997 | QualType ObjectType, |
| 1998 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 0979c80 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1999 | if (!NNS) |
| 2000 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2001 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2002 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2003 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 2004 | if (Prefix) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2005 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2006 | ObjectType, |
| 2007 | FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2008 | if (!Prefix) |
| 2009 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2010 | |
| 2011 | // Clear out the object type and the first qualifier in scope; they only |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2012 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2013 | ObjectType = QualType(); |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2014 | FirstQualifierInScope = 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2015 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2016 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2017 | switch (NNS->getKind()) { |
| 2018 | case NestedNameSpecifier::Identifier: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2019 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2020 | "Identifier nested-name-specifier with no prefix or object type"); |
| 2021 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 2022 | ObjectType.isNull()) |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2023 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2024 | |
| 2025 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2026 | *NNS->getAsIdentifier(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2027 | ObjectType, |
| 2028 | FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2029 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2030 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2031 | NamespaceDecl *NS |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2032 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2033 | getDerived().TransformDecl(Range.getBegin(), |
| 2034 | NNS->getAsNamespace())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2035 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2036 | Prefix == NNS->getPrefix() && |
| 2037 | NS == NNS->getAsNamespace()) |
| 2038 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2039 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2040 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 2041 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2042 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2043 | case NestedNameSpecifier::Global: |
| 2044 | // There is no meaningful transformation that one could perform on the |
| 2045 | // global scope. |
| 2046 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2047 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2048 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2049 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | fbf2c94 | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 2050 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2051 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 2052 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2053 | if (T.isNull()) |
| 2054 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2055 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2056 | if (!getDerived().AlwaysRebuild() && |
| 2057 | Prefix == NNS->getPrefix() && |
| 2058 | T == QualType(NNS->getAsType(), 0)) |
| 2059 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2060 | |
| 2061 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 2062 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 2063 | T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2064 | } |
| 2065 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2066 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2067 | // Required to silence a GCC warning |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2068 | return 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2072 | DeclarationName |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2073 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2074 | SourceLocation Loc, |
| 2075 | QualType ObjectType) { |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2076 | if (!Name) |
| 2077 | return Name; |
| 2078 | |
| 2079 | switch (Name.getNameKind()) { |
| 2080 | case DeclarationName::Identifier: |
| 2081 | case DeclarationName::ObjCZeroArgSelector: |
| 2082 | case DeclarationName::ObjCOneArgSelector: |
| 2083 | case DeclarationName::ObjCMultiArgSelector: |
| 2084 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2085 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2086 | case DeclarationName::CXXUsingDirective: |
| 2087 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2088 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2089 | case DeclarationName::CXXConstructorName: |
| 2090 | case DeclarationName::CXXDestructorName: |
| 2091 | case DeclarationName::CXXConversionFunctionName: { |
| 2092 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2093 | QualType T = getDerived().TransformType(Name.getCXXNameType(), |
| 2094 | ObjectType); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2095 | if (T.isNull()) |
| 2096 | return DeclarationName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2097 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2098 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2099 | Name.getNameKind(), |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2100 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2101 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2102 | } |
| 2103 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2104 | return DeclarationName(); |
| 2105 | } |
| 2106 | |
| 2107 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2108 | TemplateName |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2109 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 2110 | QualType ObjectType) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2111 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2112 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2113 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2114 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2115 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2116 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2117 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2118 | if (!NNS) |
| 2119 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2120 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2121 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2122 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2123 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2124 | if (!TransTemplate) |
| 2125 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2126 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2127 | if (!getDerived().AlwaysRebuild() && |
| 2128 | NNS == QTN->getQualifier() && |
| 2129 | TransTemplate == Template) |
| 2130 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2131 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2132 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 2133 | TransTemplate); |
| 2134 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2135 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2136 | // These should be getting filtered out before they make it into the AST. |
| 2137 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2138 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2139 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2140 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2141 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2142 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2143 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2144 | ObjectType); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2145 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2146 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2147 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2148 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2149 | NNS == DTN->getQualifier() && |
| 2150 | ObjectType.isNull()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2151 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2152 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2153 | if (DTN->isIdentifier()) |
| 2154 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 2155 | ObjectType); |
| 2156 | |
| 2157 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 2158 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2159 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2160 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2161 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2162 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2163 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2164 | if (!TransTemplate) |
| 2165 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2166 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2167 | if (!getDerived().AlwaysRebuild() && |
| 2168 | TransTemplate == Template) |
| 2169 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2170 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2171 | return TemplateName(TransTemplate); |
| 2172 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2173 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2174 | // These should be getting filtered out before they reach the AST. |
| 2175 | assert(false && "overloaded function decl survived to here"); |
| 2176 | return TemplateName(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2180 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2181 | const TemplateArgument &Arg, |
| 2182 | TemplateArgumentLoc &Output) { |
| 2183 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2184 | switch (Arg.getKind()) { |
| 2185 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2186 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2187 | break; |
| 2188 | |
| 2189 | case TemplateArgument::Type: |
| 2190 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2191 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2192 | |
| 2193 | break; |
| 2194 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2195 | case TemplateArgument::Template: |
| 2196 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 2197 | break; |
| 2198 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2199 | case TemplateArgument::Expression: |
| 2200 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2201 | break; |
| 2202 | |
| 2203 | case TemplateArgument::Declaration: |
| 2204 | case TemplateArgument::Integral: |
| 2205 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2206 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2207 | break; |
| 2208 | } |
| 2209 | } |
| 2210 | |
| 2211 | template<typename Derived> |
| 2212 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2213 | const TemplateArgumentLoc &Input, |
| 2214 | TemplateArgumentLoc &Output) { |
| 2215 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2216 | switch (Arg.getKind()) { |
| 2217 | case TemplateArgument::Null: |
| 2218 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2219 | Output = Input; |
| 2220 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2221 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2222 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2223 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2224 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2225 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2226 | |
| 2227 | DI = getDerived().TransformType(DI); |
| 2228 | if (!DI) return true; |
| 2229 | |
| 2230 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2231 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2232 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2233 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2234 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2235 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2236 | DeclarationName Name; |
| 2237 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2238 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2239 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2240 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2241 | if (!D) return true; |
| 2242 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2243 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2244 | if (SourceExpr) { |
| 2245 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 2246 | Action::Unevaluated); |
| 2247 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 2248 | if (E.isInvalid()) |
| 2249 | SourceExpr = NULL; |
| 2250 | else { |
| 2251 | SourceExpr = E.takeAs<Expr>(); |
| 2252 | SourceExpr->Retain(); |
| 2253 | } |
| 2254 | } |
| 2255 | |
| 2256 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2257 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2258 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2259 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2260 | case TemplateArgument::Template: { |
| 2261 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 2262 | TemplateName Template |
| 2263 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2264 | if (Template.isNull()) |
| 2265 | return true; |
| 2266 | |
| 2267 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2268 | Input.getTemplateQualifierRange(), |
| 2269 | Input.getTemplateNameLoc()); |
| 2270 | return false; |
| 2271 | } |
| 2272 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2273 | case TemplateArgument::Expression: { |
| 2274 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2275 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2276 | Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2277 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2278 | Expr *InputExpr = Input.getSourceExpression(); |
| 2279 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2280 | |
| 2281 | Sema::OwningExprResult E |
| 2282 | = getDerived().TransformExpr(InputExpr); |
| 2283 | if (E.isInvalid()) return true; |
| 2284 | |
| 2285 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2286 | ETaken->Retain(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2287 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2288 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2289 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2290 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2291 | case TemplateArgument::Pack: { |
| 2292 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2293 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2294 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2295 | AEnd = Arg.pack_end(); |
| 2296 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2297 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2298 | // FIXME: preserve source information here when we start |
| 2299 | // caring about parameter packs. |
| 2300 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2301 | TemplateArgumentLoc InputArg; |
| 2302 | TemplateArgumentLoc OutputArg; |
| 2303 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2304 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2305 | return true; |
| 2306 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2307 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2308 | } |
| 2309 | TemplateArgument Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2310 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2311 | true); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2312 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2313 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2314 | } |
| 2315 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2316 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2317 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2318 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2319 | } |
| 2320 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2321 | //===----------------------------------------------------------------------===// |
| 2322 | // Type transformation |
| 2323 | //===----------------------------------------------------------------------===// |
| 2324 | |
| 2325 | template<typename Derived> |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2326 | QualType TreeTransform<Derived>::TransformType(QualType T, |
| 2327 | QualType ObjectType) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2328 | if (getDerived().AlreadyTransformed(T)) |
| 2329 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2330 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2331 | // Temporary workaround. All of these transformations should |
| 2332 | // eventually turn into transformations on TypeLocs. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2333 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | 4802a31 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2334 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2335 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2336 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2337 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2338 | if (!NewDI) |
| 2339 | return QualType(); |
| 2340 | |
| 2341 | return NewDI->getType(); |
| 2342 | } |
| 2343 | |
| 2344 | template<typename Derived> |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2345 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2346 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2347 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2348 | return DI; |
| 2349 | |
| 2350 | TypeLocBuilder TLB; |
| 2351 | |
| 2352 | TypeLoc TL = DI->getTypeLoc(); |
| 2353 | TLB.reserve(TL.getFullDataSize()); |
| 2354 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2355 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2356 | if (Result.isNull()) |
| 2357 | return 0; |
| 2358 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2359 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2360 | } |
| 2361 | |
| 2362 | template<typename Derived> |
| 2363 | QualType |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2364 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2365 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2366 | switch (T.getTypeLocClass()) { |
| 2367 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2368 | #define TYPELOC(CLASS, PARENT) \ |
| 2369 | case TypeLoc::CLASS: \ |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2370 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2371 | ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2372 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2373 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2374 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2375 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2376 | return QualType(); |
| 2377 | } |
| 2378 | |
| 2379 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2380 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2381 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2382 | /// types). This is the right thing for template instantiation, but |
| 2383 | /// probably not for other clients. |
| 2384 | template<typename Derived> |
| 2385 | QualType |
| 2386 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2387 | QualifiedTypeLoc T, |
| 2388 | QualType ObjectType) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2389 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2390 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2391 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2392 | ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2393 | if (Result.isNull()) |
| 2394 | return QualType(); |
| 2395 | |
| 2396 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2397 | // FIXME: this is the right thing for template instantiation, but |
| 2398 | // probably not for other clients. |
| 2399 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2400 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2401 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2402 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2403 | |
| 2404 | TLB.push<QualifiedTypeLoc>(Result); |
| 2405 | |
| 2406 | // No location information to preserve. |
| 2407 | |
| 2408 | return Result; |
| 2409 | } |
| 2410 | |
| 2411 | template <class TyLoc> static inline |
| 2412 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2413 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2414 | NewT.setNameLoc(T.getNameLoc()); |
| 2415 | return T.getType(); |
| 2416 | } |
| 2417 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2418 | template<typename Derived> |
| 2419 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2420 | BuiltinTypeLoc T, |
| 2421 | QualType ObjectType) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2422 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2423 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2424 | if (T.needsExtraLocalData()) |
| 2425 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2426 | return T.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2427 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2428 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2429 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2430 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2431 | ComplexTypeLoc T, |
| 2432 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2433 | // FIXME: recurse? |
| 2434 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2435 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2436 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2437 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2438 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2439 | PointerTypeLoc TL, |
| 2440 | QualType ObjectType) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2441 | QualType PointeeType |
| 2442 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2443 | if (PointeeType.isNull()) |
| 2444 | return QualType(); |
| 2445 | |
| 2446 | QualType Result = TL.getType(); |
| 2447 | if (PointeeType->isObjCInterfaceType()) { |
| 2448 | // A dependent pointer type 'T *' has is being transformed such |
| 2449 | // that an Objective-C class type is being replaced for 'T'. The |
| 2450 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 2451 | // PointerType. |
| 2452 | const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>(); |
| 2453 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType, |
| 2454 | const_cast<ObjCProtocolDecl **>( |
| 2455 | IFace->qual_begin()), |
| 2456 | IFace->getNumProtocols()); |
| 2457 | |
| 2458 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 2459 | NewT.setStarLoc(TL.getSigilLoc()); |
| 2460 | NewT.setHasProtocolsAsWritten(false); |
| 2461 | NewT.setLAngleLoc(SourceLocation()); |
| 2462 | NewT.setRAngleLoc(SourceLocation()); |
| 2463 | NewT.setHasBaseTypeAsWritten(true); |
| 2464 | return Result; |
| 2465 | } |
| 2466 | |
| 2467 | if (getDerived().AlwaysRebuild() || |
| 2468 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2469 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 2470 | if (Result.isNull()) |
| 2471 | return QualType(); |
| 2472 | } |
| 2473 | |
| 2474 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 2475 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 2476 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2477 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2478 | |
| 2479 | template<typename Derived> |
| 2480 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2481 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2482 | BlockPointerTypeLoc TL, |
| 2483 | QualType ObjectType) { |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2484 | QualType PointeeType |
| 2485 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2486 | if (PointeeType.isNull()) |
| 2487 | return QualType(); |
| 2488 | |
| 2489 | QualType Result = TL.getType(); |
| 2490 | if (getDerived().AlwaysRebuild() || |
| 2491 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2492 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
| 2493 | TL.getSigilLoc()); |
| 2494 | if (Result.isNull()) |
| 2495 | return QualType(); |
| 2496 | } |
| 2497 | |
Douglas Gregor | 39968ad | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 2498 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2499 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 2500 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2501 | } |
| 2502 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2503 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2504 | /// don't care whether the type itself is an l-value type or an r-value |
| 2505 | /// type; we only care if the type was *written* as an l-value type |
| 2506 | /// or an r-value type. |
| 2507 | template<typename Derived> |
| 2508 | QualType |
| 2509 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2510 | ReferenceTypeLoc TL, |
| 2511 | QualType ObjectType) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2512 | const ReferenceType *T = TL.getTypePtr(); |
| 2513 | |
| 2514 | // Note that this works with the pointee-as-written. |
| 2515 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2516 | if (PointeeType.isNull()) |
| 2517 | return QualType(); |
| 2518 | |
| 2519 | QualType Result = TL.getType(); |
| 2520 | if (getDerived().AlwaysRebuild() || |
| 2521 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2522 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2523 | T->isSpelledAsLValue(), |
| 2524 | TL.getSigilLoc()); |
| 2525 | if (Result.isNull()) |
| 2526 | return QualType(); |
| 2527 | } |
| 2528 | |
| 2529 | // r-value references can be rebuilt as l-value references. |
| 2530 | ReferenceTypeLoc NewTL; |
| 2531 | if (isa<LValueReferenceType>(Result)) |
| 2532 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2533 | else |
| 2534 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2535 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2536 | |
| 2537 | return Result; |
| 2538 | } |
| 2539 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2540 | template<typename Derived> |
| 2541 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2542 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2543 | LValueReferenceTypeLoc TL, |
| 2544 | QualType ObjectType) { |
| 2545 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2546 | } |
| 2547 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2548 | template<typename Derived> |
| 2549 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2550 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2551 | RValueReferenceTypeLoc TL, |
| 2552 | QualType ObjectType) { |
| 2553 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2554 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2555 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2556 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2557 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2558 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2559 | MemberPointerTypeLoc TL, |
| 2560 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2561 | MemberPointerType *T = TL.getTypePtr(); |
| 2562 | |
| 2563 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2564 | if (PointeeType.isNull()) |
| 2565 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2566 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2567 | // TODO: preserve source information for this. |
| 2568 | QualType ClassType |
| 2569 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2570 | if (ClassType.isNull()) |
| 2571 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2572 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2573 | QualType Result = TL.getType(); |
| 2574 | if (getDerived().AlwaysRebuild() || |
| 2575 | PointeeType != T->getPointeeType() || |
| 2576 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2577 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2578 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2579 | if (Result.isNull()) |
| 2580 | return QualType(); |
| 2581 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2582 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2583 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2584 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2585 | |
| 2586 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2587 | } |
| 2588 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2589 | template<typename Derived> |
| 2590 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2591 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2592 | ConstantArrayTypeLoc TL, |
| 2593 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2594 | ConstantArrayType *T = TL.getTypePtr(); |
| 2595 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2596 | if (ElementType.isNull()) |
| 2597 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2598 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2599 | QualType Result = TL.getType(); |
| 2600 | if (getDerived().AlwaysRebuild() || |
| 2601 | ElementType != T->getElementType()) { |
| 2602 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2603 | T->getSizeModifier(), |
| 2604 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2605 | T->getIndexTypeCVRQualifiers(), |
| 2606 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2607 | if (Result.isNull()) |
| 2608 | return QualType(); |
| 2609 | } |
| 2610 | |
| 2611 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2612 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2613 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2614 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2615 | Expr *Size = TL.getSizeExpr(); |
| 2616 | if (Size) { |
| 2617 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2618 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2619 | } |
| 2620 | NewTL.setSizeExpr(Size); |
| 2621 | |
| 2622 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2623 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2624 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2625 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2626 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2627 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2628 | IncompleteArrayTypeLoc TL, |
| 2629 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2630 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2631 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2632 | if (ElementType.isNull()) |
| 2633 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2634 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2635 | QualType Result = TL.getType(); |
| 2636 | if (getDerived().AlwaysRebuild() || |
| 2637 | ElementType != T->getElementType()) { |
| 2638 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2639 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2640 | T->getIndexTypeCVRQualifiers(), |
| 2641 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2642 | if (Result.isNull()) |
| 2643 | return QualType(); |
| 2644 | } |
| 2645 | |
| 2646 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2647 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2648 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2649 | NewTL.setSizeExpr(0); |
| 2650 | |
| 2651 | return Result; |
| 2652 | } |
| 2653 | |
| 2654 | template<typename Derived> |
| 2655 | QualType |
| 2656 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2657 | VariableArrayTypeLoc TL, |
| 2658 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2659 | VariableArrayType *T = TL.getTypePtr(); |
| 2660 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2661 | if (ElementType.isNull()) |
| 2662 | return QualType(); |
| 2663 | |
| 2664 | // Array bounds are not potentially evaluated contexts |
| 2665 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2666 | |
| 2667 | Sema::OwningExprResult SizeResult |
| 2668 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2669 | if (SizeResult.isInvalid()) |
| 2670 | return QualType(); |
| 2671 | |
| 2672 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2673 | |
| 2674 | QualType Result = TL.getType(); |
| 2675 | if (getDerived().AlwaysRebuild() || |
| 2676 | ElementType != T->getElementType() || |
| 2677 | Size != T->getSizeExpr()) { |
| 2678 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2679 | T->getSizeModifier(), |
| 2680 | move(SizeResult), |
| 2681 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2682 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2683 | if (Result.isNull()) |
| 2684 | return QualType(); |
| 2685 | } |
| 2686 | else SizeResult.take(); |
| 2687 | |
| 2688 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2689 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2690 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2691 | NewTL.setSizeExpr(Size); |
| 2692 | |
| 2693 | return Result; |
| 2694 | } |
| 2695 | |
| 2696 | template<typename Derived> |
| 2697 | QualType |
| 2698 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2699 | DependentSizedArrayTypeLoc TL, |
| 2700 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2701 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2702 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2703 | if (ElementType.isNull()) |
| 2704 | return QualType(); |
| 2705 | |
| 2706 | // Array bounds are not potentially evaluated contexts |
| 2707 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2708 | |
| 2709 | Sema::OwningExprResult SizeResult |
| 2710 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2711 | if (SizeResult.isInvalid()) |
| 2712 | return QualType(); |
| 2713 | |
| 2714 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2715 | |
| 2716 | QualType Result = TL.getType(); |
| 2717 | if (getDerived().AlwaysRebuild() || |
| 2718 | ElementType != T->getElementType() || |
| 2719 | Size != T->getSizeExpr()) { |
| 2720 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2721 | T->getSizeModifier(), |
| 2722 | move(SizeResult), |
| 2723 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2724 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2725 | if (Result.isNull()) |
| 2726 | return QualType(); |
| 2727 | } |
| 2728 | else SizeResult.take(); |
| 2729 | |
| 2730 | // We might have any sort of array type now, but fortunately they |
| 2731 | // all have the same location layout. |
| 2732 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2733 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2734 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2735 | NewTL.setSizeExpr(Size); |
| 2736 | |
| 2737 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2738 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2739 | |
| 2740 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2741 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2742 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2743 | DependentSizedExtVectorTypeLoc TL, |
| 2744 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2745 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2746 | |
| 2747 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2748 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2749 | if (ElementType.isNull()) |
| 2750 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2751 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2752 | // Vector sizes are not potentially evaluated contexts |
| 2753 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2754 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2755 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2756 | if (Size.isInvalid()) |
| 2757 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2758 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2759 | QualType Result = TL.getType(); |
| 2760 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2761 | ElementType != T->getElementType() || |
| 2762 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2763 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2764 | move(Size), |
| 2765 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2766 | if (Result.isNull()) |
| 2767 | return QualType(); |
| 2768 | } |
| 2769 | else Size.take(); |
| 2770 | |
| 2771 | // Result might be dependent or not. |
| 2772 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2773 | DependentSizedExtVectorTypeLoc NewTL |
| 2774 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2775 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2776 | } else { |
| 2777 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2778 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2779 | } |
| 2780 | |
| 2781 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2782 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2783 | |
| 2784 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2785 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2786 | VectorTypeLoc TL, |
| 2787 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2788 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2789 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2790 | if (ElementType.isNull()) |
| 2791 | return QualType(); |
| 2792 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2793 | QualType Result = TL.getType(); |
| 2794 | if (getDerived().AlwaysRebuild() || |
| 2795 | ElementType != T->getElementType()) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2796 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 2797 | T->isAltiVec(), T->isPixel()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2798 | if (Result.isNull()) |
| 2799 | return QualType(); |
| 2800 | } |
| 2801 | |
| 2802 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2803 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2804 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2805 | return Result; |
| 2806 | } |
| 2807 | |
| 2808 | template<typename Derived> |
| 2809 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2810 | ExtVectorTypeLoc TL, |
| 2811 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2812 | VectorType *T = TL.getTypePtr(); |
| 2813 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2814 | if (ElementType.isNull()) |
| 2815 | return QualType(); |
| 2816 | |
| 2817 | QualType Result = TL.getType(); |
| 2818 | if (getDerived().AlwaysRebuild() || |
| 2819 | ElementType != T->getElementType()) { |
| 2820 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2821 | T->getNumElements(), |
| 2822 | /*FIXME*/ SourceLocation()); |
| 2823 | if (Result.isNull()) |
| 2824 | return QualType(); |
| 2825 | } |
| 2826 | |
| 2827 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2828 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2829 | |
| 2830 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2831 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2832 | |
| 2833 | template<typename Derived> |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2834 | ParmVarDecl * |
| 2835 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) { |
| 2836 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| 2837 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
| 2838 | if (!NewDI) |
| 2839 | return 0; |
| 2840 | |
| 2841 | if (NewDI == OldDI) |
| 2842 | return OldParm; |
| 2843 | else |
| 2844 | return ParmVarDecl::Create(SemaRef.Context, |
| 2845 | OldParm->getDeclContext(), |
| 2846 | OldParm->getLocation(), |
| 2847 | OldParm->getIdentifier(), |
| 2848 | NewDI->getType(), |
| 2849 | NewDI, |
| 2850 | OldParm->getStorageClass(), |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 2851 | OldParm->getStorageClassAsWritten(), |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2852 | /* DefArg */ NULL); |
| 2853 | } |
| 2854 | |
| 2855 | template<typename Derived> |
| 2856 | bool TreeTransform<Derived>:: |
| 2857 | TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 2858 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 2859 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars) { |
| 2860 | FunctionProtoType *T = TL.getTypePtr(); |
| 2861 | |
| 2862 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2863 | ParmVarDecl *OldParm = TL.getArg(i); |
| 2864 | |
| 2865 | QualType NewType; |
| 2866 | ParmVarDecl *NewParm; |
| 2867 | |
| 2868 | if (OldParm) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2869 | NewParm = getDerived().TransformFunctionTypeParam(OldParm); |
| 2870 | if (!NewParm) |
| 2871 | return true; |
| 2872 | NewType = NewParm->getType(); |
| 2873 | |
| 2874 | // Deal with the possibility that we don't have a parameter |
| 2875 | // declaration for this parameter. |
| 2876 | } else { |
| 2877 | NewParm = 0; |
| 2878 | |
| 2879 | QualType OldType = T->getArgType(i); |
| 2880 | NewType = getDerived().TransformType(OldType); |
| 2881 | if (NewType.isNull()) |
| 2882 | return true; |
| 2883 | } |
| 2884 | |
| 2885 | PTypes.push_back(NewType); |
| 2886 | PVars.push_back(NewParm); |
| 2887 | } |
| 2888 | |
| 2889 | return false; |
| 2890 | } |
| 2891 | |
| 2892 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2893 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2894 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2895 | FunctionProtoTypeLoc TL, |
| 2896 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2897 | FunctionProtoType *T = TL.getTypePtr(); |
| 2898 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2899 | if (ResultType.isNull()) |
| 2900 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2901 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2902 | // Transform the parameters. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2903 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2904 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2905 | if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls)) |
| 2906 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2907 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2908 | QualType Result = TL.getType(); |
| 2909 | if (getDerived().AlwaysRebuild() || |
| 2910 | ResultType != T->getResultType() || |
| 2911 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2912 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2913 | ParamTypes.data(), |
| 2914 | ParamTypes.size(), |
| 2915 | T->isVariadic(), |
| 2916 | T->getTypeQuals()); |
| 2917 | if (Result.isNull()) |
| 2918 | return QualType(); |
| 2919 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2920 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2921 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2922 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2923 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2924 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2925 | NewTL.setArg(i, ParamDecls[i]); |
| 2926 | |
| 2927 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2928 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2929 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2930 | template<typename Derived> |
| 2931 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2932 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2933 | FunctionNoProtoTypeLoc TL, |
| 2934 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2935 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2936 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2937 | if (ResultType.isNull()) |
| 2938 | return QualType(); |
| 2939 | |
| 2940 | QualType Result = TL.getType(); |
| 2941 | if (getDerived().AlwaysRebuild() || |
| 2942 | ResultType != T->getResultType()) |
| 2943 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2944 | |
| 2945 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2946 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2947 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2948 | |
| 2949 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2950 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2951 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2952 | template<typename Derived> QualType |
| 2953 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2954 | UnresolvedUsingTypeLoc TL, |
| 2955 | QualType ObjectType) { |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2956 | UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2957 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2958 | if (!D) |
| 2959 | return QualType(); |
| 2960 | |
| 2961 | QualType Result = TL.getType(); |
| 2962 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2963 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2964 | if (Result.isNull()) |
| 2965 | return QualType(); |
| 2966 | } |
| 2967 | |
| 2968 | // We might get an arbitrary type spec type back. We should at |
| 2969 | // least always get a type spec type, though. |
| 2970 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2971 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2972 | |
| 2973 | return Result; |
| 2974 | } |
| 2975 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2976 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2977 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2978 | TypedefTypeLoc TL, |
| 2979 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2980 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2981 | TypedefDecl *Typedef |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2982 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2983 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2984 | if (!Typedef) |
| 2985 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2986 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2987 | QualType Result = TL.getType(); |
| 2988 | if (getDerived().AlwaysRebuild() || |
| 2989 | Typedef != T->getDecl()) { |
| 2990 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2991 | if (Result.isNull()) |
| 2992 | return QualType(); |
| 2993 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2994 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2995 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2996 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2997 | |
| 2998 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2999 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3000 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3001 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3002 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3003 | TypeOfExprTypeLoc TL, |
| 3004 | QualType ObjectType) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3005 | // typeof expressions are not potentially evaluated contexts |
| 3006 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3007 | |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3008 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3009 | if (E.isInvalid()) |
| 3010 | return QualType(); |
| 3011 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3012 | QualType Result = TL.getType(); |
| 3013 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3014 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3015 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 3016 | if (Result.isNull()) |
| 3017 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3018 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3019 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3020 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3021 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3022 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3023 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3024 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3025 | |
| 3026 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3027 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3028 | |
| 3029 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3030 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3031 | TypeOfTypeLoc TL, |
| 3032 | QualType ObjectType) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3033 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 3034 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 3035 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3036 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3037 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3038 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3039 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 3040 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3041 | if (Result.isNull()) |
| 3042 | return QualType(); |
| 3043 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3044 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3045 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3046 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3047 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3048 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 3049 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3050 | |
| 3051 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3052 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3053 | |
| 3054 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3055 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3056 | DecltypeTypeLoc TL, |
| 3057 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3058 | DecltypeType *T = TL.getTypePtr(); |
| 3059 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3060 | // decltype expressions are not potentially evaluated contexts |
| 3061 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3062 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3063 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 3064 | if (E.isInvalid()) |
| 3065 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3066 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3067 | QualType Result = TL.getType(); |
| 3068 | if (getDerived().AlwaysRebuild() || |
| 3069 | E.get() != T->getUnderlyingExpr()) { |
| 3070 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 3071 | if (Result.isNull()) |
| 3072 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3073 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3074 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3075 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3076 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 3077 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3078 | |
| 3079 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3080 | } |
| 3081 | |
| 3082 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3083 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3084 | RecordTypeLoc TL, |
| 3085 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3086 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3087 | RecordDecl *Record |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3088 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3089 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3090 | if (!Record) |
| 3091 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3092 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3093 | QualType Result = TL.getType(); |
| 3094 | if (getDerived().AlwaysRebuild() || |
| 3095 | Record != T->getDecl()) { |
| 3096 | Result = getDerived().RebuildRecordType(Record); |
| 3097 | if (Result.isNull()) |
| 3098 | return QualType(); |
| 3099 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3100 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3101 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 3102 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3103 | |
| 3104 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3105 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3106 | |
| 3107 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3108 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3109 | EnumTypeLoc TL, |
| 3110 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3111 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3112 | EnumDecl *Enum |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3113 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3114 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3115 | if (!Enum) |
| 3116 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3117 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3118 | QualType Result = TL.getType(); |
| 3119 | if (getDerived().AlwaysRebuild() || |
| 3120 | Enum != T->getDecl()) { |
| 3121 | Result = getDerived().RebuildEnumType(Enum); |
| 3122 | if (Result.isNull()) |
| 3123 | return QualType(); |
| 3124 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3125 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3126 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 3127 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3128 | |
| 3129 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3130 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3131 | |
| 3132 | template <typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3133 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3134 | ElaboratedTypeLoc TL, |
| 3135 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3136 | ElaboratedType *T = TL.getTypePtr(); |
| 3137 | |
| 3138 | // FIXME: this should be a nested type. |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3139 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 3140 | if (Underlying.isNull()) |
| 3141 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3142 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3143 | QualType Result = TL.getType(); |
| 3144 | if (getDerived().AlwaysRebuild() || |
| 3145 | Underlying != T->getUnderlyingType()) { |
| 3146 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 3147 | if (Result.isNull()) |
| 3148 | return QualType(); |
| 3149 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3150 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3151 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 3152 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3153 | |
| 3154 | return Result; |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3155 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3156 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3157 | template<typename Derived> |
| 3158 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 3159 | TypeLocBuilder &TLB, |
| 3160 | InjectedClassNameTypeLoc TL, |
| 3161 | QualType ObjectType) { |
| 3162 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 3163 | TL.getTypePtr()->getDecl()); |
| 3164 | if (!D) return QualType(); |
| 3165 | |
| 3166 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 3167 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 3168 | return T; |
| 3169 | } |
| 3170 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3171 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3172 | template<typename Derived> |
| 3173 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3174 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3175 | TemplateTypeParmTypeLoc TL, |
| 3176 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3177 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3178 | } |
| 3179 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3180 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3181 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3182 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3183 | SubstTemplateTypeParmTypeLoc TL, |
| 3184 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3185 | return TransformTypeSpecType(TLB, TL); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3189 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 3190 | const TemplateSpecializationType *TST, |
| 3191 | QualType ObjectType) { |
| 3192 | // FIXME: this entire method is a temporary workaround; callers |
| 3193 | // should be rewritten to provide real type locs. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3194 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3195 | // Fake up a TemplateSpecializationTypeLoc. |
| 3196 | TypeLocBuilder TLB; |
| 3197 | TemplateSpecializationTypeLoc TL |
| 3198 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 3199 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3200 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 3201 | |
| 3202 | TL.setTemplateNameLoc(BaseLoc); |
| 3203 | TL.setLAngleLoc(BaseLoc); |
| 3204 | TL.setRAngleLoc(BaseLoc); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3205 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 3206 | const TemplateArgument &TA = TST->getArg(i); |
| 3207 | TemplateArgumentLoc TAL; |
| 3208 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 3209 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 3210 | } |
| 3211 | |
| 3212 | TypeLocBuilder IgnoredTLB; |
| 3213 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3217 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3218 | TypeLocBuilder &TLB, |
| 3219 | TemplateSpecializationTypeLoc TL, |
| 3220 | QualType ObjectType) { |
| 3221 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 3222 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3223 | TemplateName Template |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3224 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3225 | if (Template.isNull()) |
| 3226 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3227 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3228 | TemplateArgumentListInfo NewTemplateArgs; |
| 3229 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 3230 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 3231 | |
| 3232 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 3233 | TemplateArgumentLoc Loc; |
| 3234 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3235 | return QualType(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3236 | NewTemplateArgs.addArgument(Loc); |
| 3237 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3238 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3239 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 3240 | |
| 3241 | QualType Result = |
| 3242 | getDerived().RebuildTemplateSpecializationType(Template, |
| 3243 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3244 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3245 | |
| 3246 | if (!Result.isNull()) { |
| 3247 | TemplateSpecializationTypeLoc NewTL |
| 3248 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 3249 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 3250 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 3251 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 3252 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 3253 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3254 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3255 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3256 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3257 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3258 | |
| 3259 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3260 | QualType |
| 3261 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3262 | QualifiedNameTypeLoc TL, |
| 3263 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3264 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3265 | NestedNameSpecifier *NNS |
| 3266 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3267 | SourceRange(), |
| 3268 | ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3269 | if (!NNS) |
| 3270 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3271 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3272 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 3273 | if (Named.isNull()) |
| 3274 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3275 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3276 | QualType Result = TL.getType(); |
| 3277 | if (getDerived().AlwaysRebuild() || |
| 3278 | NNS != T->getQualifier() || |
| 3279 | Named != T->getNamedType()) { |
| 3280 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 3281 | if (Result.isNull()) |
| 3282 | return QualType(); |
| 3283 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3284 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3285 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 3286 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3287 | |
| 3288 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3289 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3290 | |
| 3291 | template<typename Derived> |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3292 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
| 3293 | DependentNameTypeLoc TL, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3294 | QualType ObjectType) { |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3295 | DependentNameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3296 | |
| 3297 | /* FIXME: preserve source information better than this */ |
| 3298 | SourceRange SR(TL.getNameLoc()); |
| 3299 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3300 | NestedNameSpecifier *NNS |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3301 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3302 | ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3303 | if (!NNS) |
| 3304 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3305 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3306 | QualType Result; |
| 3307 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3308 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3309 | QualType NewTemplateId |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3310 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 3311 | if (NewTemplateId.isNull()) |
| 3312 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3313 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3314 | if (!getDerived().AlwaysRebuild() && |
| 3315 | NNS == T->getQualifier() && |
| 3316 | NewTemplateId == QualType(TemplateId, 0)) |
| 3317 | return QualType(T, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3318 | |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3319 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 3320 | NewTemplateId); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3321 | } else { |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3322 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 3323 | T->getIdentifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3324 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3325 | if (Result.isNull()) |
| 3326 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3327 | |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3328 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3329 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3330 | |
| 3331 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3332 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3333 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3334 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3335 | QualType |
| 3336 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3337 | ObjCInterfaceTypeLoc TL, |
| 3338 | QualType ObjectType) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3339 | // ObjCInterfaceType is never dependent. |
| 3340 | return TL.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3341 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3342 | |
| 3343 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3344 | QualType |
| 3345 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3346 | ObjCObjectPointerTypeLoc TL, |
| 3347 | QualType ObjectType) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3348 | // ObjCObjectPointerType is never dependent. |
| 3349 | return TL.getType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3350 | } |
| 3351 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3352 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3353 | // Statement transformation |
| 3354 | //===----------------------------------------------------------------------===// |
| 3355 | template<typename Derived> |
| 3356 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3357 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3358 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3359 | } |
| 3360 | |
| 3361 | template<typename Derived> |
| 3362 | Sema::OwningStmtResult |
| 3363 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3364 | return getDerived().TransformCompoundStmt(S, false); |
| 3365 | } |
| 3366 | |
| 3367 | template<typename Derived> |
| 3368 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3369 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3370 | bool IsStmtExpr) { |
| 3371 | bool SubStmtChanged = false; |
| 3372 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3373 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3374 | B != BEnd; ++B) { |
| 3375 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3376 | if (Result.isInvalid()) |
| 3377 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3378 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3379 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3380 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3381 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3382 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3383 | if (!getDerived().AlwaysRebuild() && |
| 3384 | !SubStmtChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3385 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3386 | |
| 3387 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3388 | move_arg(Statements), |
| 3389 | S->getRBracLoc(), |
| 3390 | IsStmtExpr); |
| 3391 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3392 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3393 | template<typename Derived> |
| 3394 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3395 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3396 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3397 | { |
| 3398 | // The case value expressions are not potentially evaluated. |
| 3399 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3400 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3401 | // Transform the left-hand case value. |
| 3402 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3403 | if (LHS.isInvalid()) |
| 3404 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3405 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3406 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3407 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3408 | if (RHS.isInvalid()) |
| 3409 | return SemaRef.StmtError(); |
| 3410 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3411 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3412 | // Build the case statement. |
| 3413 | // Case statements are always rebuilt so that they will attached to their |
| 3414 | // transformed switch statement. |
| 3415 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3416 | move(LHS), |
| 3417 | S->getEllipsisLoc(), |
| 3418 | move(RHS), |
| 3419 | S->getColonLoc()); |
| 3420 | if (Case.isInvalid()) |
| 3421 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3422 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3423 | // Transform the statement following the case |
| 3424 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3425 | if (SubStmt.isInvalid()) |
| 3426 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3427 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3428 | // Attach the body to the case statement |
| 3429 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3430 | } |
| 3431 | |
| 3432 | template<typename Derived> |
| 3433 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3434 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3435 | // Transform the statement following the default case |
| 3436 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3437 | if (SubStmt.isInvalid()) |
| 3438 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3439 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3440 | // Default statements are always rebuilt |
| 3441 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3442 | move(SubStmt)); |
| 3443 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3444 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3445 | template<typename Derived> |
| 3446 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3447 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3448 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3449 | if (SubStmt.isInvalid()) |
| 3450 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3451 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3452 | // FIXME: Pass the real colon location in. |
| 3453 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3454 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3455 | move(SubStmt)); |
| 3456 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3457 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3458 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3459 | Sema::OwningStmtResult |
| 3460 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3461 | // Transform the condition |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3462 | OwningExprResult Cond(SemaRef); |
| 3463 | VarDecl *ConditionVar = 0; |
| 3464 | if (S->getConditionVariable()) { |
| 3465 | ConditionVar |
| 3466 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3467 | getDerived().TransformDefinition( |
| 3468 | S->getConditionVariable()->getLocation(), |
| 3469 | S->getConditionVariable())); |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3470 | if (!ConditionVar) |
| 3471 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3472 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3473 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3474 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3475 | if (Cond.isInvalid()) |
| 3476 | return SemaRef.StmtError(); |
| 3477 | } |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3478 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3479 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3480 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3481 | // Transform the "then" branch. |
| 3482 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3483 | if (Then.isInvalid()) |
| 3484 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3485 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3486 | // Transform the "else" branch. |
| 3487 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3488 | if (Else.isInvalid()) |
| 3489 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3490 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3491 | if (!getDerived().AlwaysRebuild() && |
| 3492 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3493 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3494 | Then.get() == S->getThen() && |
| 3495 | Else.get() == S->getElse()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3496 | return SemaRef.Owned(S->Retain()); |
| 3497 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3498 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3499 | move(Then), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3500 | S->getElseLoc(), move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | template<typename Derived> |
| 3504 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3505 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3506 | // Transform the condition. |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3507 | OwningExprResult Cond(SemaRef); |
| 3508 | VarDecl *ConditionVar = 0; |
| 3509 | if (S->getConditionVariable()) { |
| 3510 | ConditionVar |
| 3511 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3512 | getDerived().TransformDefinition( |
| 3513 | S->getConditionVariable()->getLocation(), |
| 3514 | S->getConditionVariable())); |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3515 | if (!ConditionVar) |
| 3516 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3517 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3518 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3519 | |
| 3520 | if (Cond.isInvalid()) |
| 3521 | return SemaRef.StmtError(); |
| 3522 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3523 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3524 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3525 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3526 | // Rebuild the switch statement. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3527 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3528 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3529 | if (Switch.isInvalid()) |
| 3530 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3531 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3532 | // Transform the body of the switch statement. |
| 3533 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3534 | if (Body.isInvalid()) |
| 3535 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3536 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3537 | // Complete the switch statement. |
| 3538 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3539 | move(Body)); |
| 3540 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3541 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3542 | template<typename Derived> |
| 3543 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3544 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3545 | // Transform the condition |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3546 | OwningExprResult Cond(SemaRef); |
| 3547 | VarDecl *ConditionVar = 0; |
| 3548 | if (S->getConditionVariable()) { |
| 3549 | ConditionVar |
| 3550 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3551 | getDerived().TransformDefinition( |
| 3552 | S->getConditionVariable()->getLocation(), |
| 3553 | S->getConditionVariable())); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3554 | if (!ConditionVar) |
| 3555 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3556 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3557 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3558 | |
| 3559 | if (Cond.isInvalid()) |
| 3560 | return SemaRef.StmtError(); |
| 3561 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3562 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3563 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3564 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3565 | // Transform the body |
| 3566 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3567 | if (Body.isInvalid()) |
| 3568 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3569 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3570 | if (!getDerived().AlwaysRebuild() && |
| 3571 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3572 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3573 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3574 | return SemaRef.Owned(S->Retain()); |
| 3575 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3576 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3577 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3578 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3579 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3580 | template<typename Derived> |
| 3581 | Sema::OwningStmtResult |
| 3582 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3583 | // Transform the condition |
| 3584 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3585 | if (Cond.isInvalid()) |
| 3586 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3587 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3588 | // Transform the body |
| 3589 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3590 | if (Body.isInvalid()) |
| 3591 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3592 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3593 | if (!getDerived().AlwaysRebuild() && |
| 3594 | Cond.get() == S->getCond() && |
| 3595 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3596 | return SemaRef.Owned(S->Retain()); |
| 3597 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3598 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3599 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3600 | S->getRParenLoc()); |
| 3601 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3602 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3603 | template<typename Derived> |
| 3604 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3605 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3606 | // Transform the initialization statement |
| 3607 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3608 | if (Init.isInvalid()) |
| 3609 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3610 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3611 | // Transform the condition |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3612 | OwningExprResult Cond(SemaRef); |
| 3613 | VarDecl *ConditionVar = 0; |
| 3614 | if (S->getConditionVariable()) { |
| 3615 | ConditionVar |
| 3616 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3617 | getDerived().TransformDefinition( |
| 3618 | S->getConditionVariable()->getLocation(), |
| 3619 | S->getConditionVariable())); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3620 | if (!ConditionVar) |
| 3621 | return SemaRef.StmtError(); |
| 3622 | } else { |
| 3623 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3624 | |
| 3625 | if (Cond.isInvalid()) |
| 3626 | return SemaRef.StmtError(); |
| 3627 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3628 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3629 | // Transform the increment |
| 3630 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3631 | if (Inc.isInvalid()) |
| 3632 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3633 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3634 | // Transform the body |
| 3635 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3636 | if (Body.isInvalid()) |
| 3637 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3638 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3639 | if (!getDerived().AlwaysRebuild() && |
| 3640 | Init.get() == S->getInit() && |
| 3641 | Cond.get() == S->getCond() && |
| 3642 | Inc.get() == S->getInc() && |
| 3643 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3644 | return SemaRef.Owned(S->Retain()); |
| 3645 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3646 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3647 | move(Init), getSema().MakeFullExpr(Cond), |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3648 | ConditionVar, |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3649 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3650 | S->getRParenLoc(), move(Body)); |
| 3651 | } |
| 3652 | |
| 3653 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3654 | Sema::OwningStmtResult |
| 3655 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3656 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3657 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3658 | S->getLabel()); |
| 3659 | } |
| 3660 | |
| 3661 | template<typename Derived> |
| 3662 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3663 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3664 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3665 | if (Target.isInvalid()) |
| 3666 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3667 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3668 | if (!getDerived().AlwaysRebuild() && |
| 3669 | Target.get() == S->getTarget()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3670 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3671 | |
| 3672 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3673 | move(Target)); |
| 3674 | } |
| 3675 | |
| 3676 | template<typename Derived> |
| 3677 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3678 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3679 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3680 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3681 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3682 | template<typename Derived> |
| 3683 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3684 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3685 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3686 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3687 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3688 | template<typename Derived> |
| 3689 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3690 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3691 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3692 | if (Result.isInvalid()) |
| 3693 | return SemaRef.StmtError(); |
| 3694 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3695 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3696 | // to tell whether the return type of the function has changed. |
| 3697 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3698 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3699 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3700 | template<typename Derived> |
| 3701 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3702 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3703 | bool DeclChanged = false; |
| 3704 | llvm::SmallVector<Decl *, 4> Decls; |
| 3705 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3706 | D != DEnd; ++D) { |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3707 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 3708 | *D); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3709 | if (!Transformed) |
| 3710 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3711 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3712 | if (Transformed != *D) |
| 3713 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3714 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3715 | Decls.push_back(Transformed); |
| 3716 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3717 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3718 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3719 | return SemaRef.Owned(S->Retain()); |
| 3720 | |
| 3721 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3722 | S->getStartLoc(), S->getEndLoc()); |
| 3723 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3724 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3725 | template<typename Derived> |
| 3726 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3727 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3728 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3729 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3730 | } |
| 3731 | |
| 3732 | template<typename Derived> |
| 3733 | Sema::OwningStmtResult |
| 3734 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3735 | |
| 3736 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3737 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3738 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3739 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3740 | OwningExprResult AsmString(SemaRef); |
| 3741 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3742 | |
| 3743 | bool ExprsChanged = false; |
| 3744 | |
| 3745 | // Go through the outputs. |
| 3746 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3747 | Names.push_back(S->getOutputIdentifier(I)); |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3748 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3749 | // No need to transform the constraint literal. |
| 3750 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
| 3751 | |
| 3752 | // Transform the output expr. |
| 3753 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3754 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3755 | if (Result.isInvalid()) |
| 3756 | return SemaRef.StmtError(); |
| 3757 | |
| 3758 | ExprsChanged |= Result.get() != OutputExpr; |
| 3759 | |
| 3760 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3761 | } |
| 3762 | |
| 3763 | // Go through the inputs. |
| 3764 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3765 | Names.push_back(S->getInputIdentifier(I)); |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3766 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3767 | // No need to transform the constraint literal. |
| 3768 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
| 3769 | |
| 3770 | // Transform the input expr. |
| 3771 | Expr *InputExpr = S->getInputExpr(I); |
| 3772 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3773 | if (Result.isInvalid()) |
| 3774 | return SemaRef.StmtError(); |
| 3775 | |
| 3776 | ExprsChanged |= Result.get() != InputExpr; |
| 3777 | |
| 3778 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3779 | } |
| 3780 | |
| 3781 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3782 | return SemaRef.Owned(S->Retain()); |
| 3783 | |
| 3784 | // Go through the clobbers. |
| 3785 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3786 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3787 | |
| 3788 | // No need to transform the asm string literal. |
| 3789 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3790 | |
| 3791 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3792 | S->isSimple(), |
| 3793 | S->isVolatile(), |
| 3794 | S->getNumOutputs(), |
| 3795 | S->getNumInputs(), |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3796 | Names.data(), |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3797 | move_arg(Constraints), |
| 3798 | move_arg(Exprs), |
| 3799 | move(AsmString), |
| 3800 | move_arg(Clobbers), |
| 3801 | S->getRParenLoc(), |
| 3802 | S->isMSAsm()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | |
| 3806 | template<typename Derived> |
| 3807 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3808 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3809 | // Transform the body of the @try. |
| 3810 | OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
| 3811 | if (TryBody.isInvalid()) |
| 3812 | return SemaRef.StmtError(); |
| 3813 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3814 | // Transform the @catch statements (if present). |
| 3815 | bool AnyCatchChanged = false; |
| 3816 | ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef); |
| 3817 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
| 3818 | OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3819 | if (Catch.isInvalid()) |
| 3820 | return SemaRef.StmtError(); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3821 | if (Catch.get() != S->getCatchStmt(I)) |
| 3822 | AnyCatchChanged = true; |
| 3823 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3824 | } |
| 3825 | |
| 3826 | // Transform the @finally statement (if present). |
| 3827 | OwningStmtResult Finally(SemaRef); |
| 3828 | if (S->getFinallyStmt()) { |
| 3829 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 3830 | if (Finally.isInvalid()) |
| 3831 | return SemaRef.StmtError(); |
| 3832 | } |
| 3833 | |
| 3834 | // If nothing changed, just retain this statement. |
| 3835 | if (!getDerived().AlwaysRebuild() && |
| 3836 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3837 | !AnyCatchChanged && |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3838 | Finally.get() == S->getFinallyStmt()) |
| 3839 | return SemaRef.Owned(S->Retain()); |
| 3840 | |
| 3841 | // Build a new statement. |
| 3842 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody), |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3843 | move_arg(CatchStmts), move(Finally)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3844 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3845 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3846 | template<typename Derived> |
| 3847 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3848 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3849 | // Transform the @catch parameter, if there is one. |
| 3850 | VarDecl *Var = 0; |
| 3851 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 3852 | TypeSourceInfo *TSInfo = 0; |
| 3853 | if (FromVar->getTypeSourceInfo()) { |
| 3854 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 3855 | if (!TSInfo) |
| 3856 | return SemaRef.StmtError(); |
| 3857 | } |
| 3858 | |
| 3859 | QualType T; |
| 3860 | if (TSInfo) |
| 3861 | T = TSInfo->getType(); |
| 3862 | else { |
| 3863 | T = getDerived().TransformType(FromVar->getType()); |
| 3864 | if (T.isNull()) |
| 3865 | return SemaRef.StmtError(); |
| 3866 | } |
| 3867 | |
| 3868 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 3869 | if (!Var) |
| 3870 | return SemaRef.StmtError(); |
| 3871 | } |
| 3872 | |
| 3873 | OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
| 3874 | if (Body.isInvalid()) |
| 3875 | return SemaRef.StmtError(); |
| 3876 | |
| 3877 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
| 3878 | S->getRParenLoc(), |
| 3879 | Var, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3880 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3881 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3882 | template<typename Derived> |
| 3883 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3884 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3885 | // Transform the body. |
| 3886 | OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
| 3887 | if (Body.isInvalid()) |
| 3888 | return SemaRef.StmtError(); |
| 3889 | |
| 3890 | // If nothing changed, just retain this statement. |
| 3891 | if (!getDerived().AlwaysRebuild() && |
| 3892 | Body.get() == S->getFinallyBody()) |
| 3893 | return SemaRef.Owned(S->Retain()); |
| 3894 | |
| 3895 | // Build a new statement. |
| 3896 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
| 3897 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3898 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3899 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3900 | template<typename Derived> |
| 3901 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3902 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 3903 | OwningExprResult Operand(SemaRef); |
| 3904 | if (S->getThrowExpr()) { |
| 3905 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 3906 | if (Operand.isInvalid()) |
| 3907 | return getSema().StmtError(); |
| 3908 | } |
| 3909 | |
| 3910 | if (!getDerived().AlwaysRebuild() && |
| 3911 | Operand.get() == S->getThrowExpr()) |
| 3912 | return getSema().Owned(S->Retain()); |
| 3913 | |
| 3914 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3915 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3916 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3917 | template<typename Derived> |
| 3918 | Sema::OwningStmtResult |
| 3919 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3920 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 3921 | // Transform the object we are locking. |
| 3922 | OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
| 3923 | if (Object.isInvalid()) |
| 3924 | return SemaRef.StmtError(); |
| 3925 | |
| 3926 | // Transform the body. |
| 3927 | OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
| 3928 | if (Body.isInvalid()) |
| 3929 | return SemaRef.StmtError(); |
| 3930 | |
| 3931 | // If nothing change, just retain the current statement. |
| 3932 | if (!getDerived().AlwaysRebuild() && |
| 3933 | Object.get() == S->getSynchExpr() && |
| 3934 | Body.get() == S->getSynchBody()) |
| 3935 | return SemaRef.Owned(S->Retain()); |
| 3936 | |
| 3937 | // Build a new statement. |
| 3938 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
| 3939 | move(Object), move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3940 | } |
| 3941 | |
| 3942 | template<typename Derived> |
| 3943 | Sema::OwningStmtResult |
| 3944 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3945 | ObjCForCollectionStmt *S) { |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 3946 | // Transform the element statement. |
| 3947 | OwningStmtResult Element = getDerived().TransformStmt(S->getElement()); |
| 3948 | if (Element.isInvalid()) |
| 3949 | return SemaRef.StmtError(); |
| 3950 | |
| 3951 | // Transform the collection expression. |
| 3952 | OwningExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
| 3953 | if (Collection.isInvalid()) |
| 3954 | return SemaRef.StmtError(); |
| 3955 | |
| 3956 | // Transform the body. |
| 3957 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3958 | if (Body.isInvalid()) |
| 3959 | return SemaRef.StmtError(); |
| 3960 | |
| 3961 | // If nothing changed, just retain this statement. |
| 3962 | if (!getDerived().AlwaysRebuild() && |
| 3963 | Element.get() == S->getElement() && |
| 3964 | Collection.get() == S->getCollection() && |
| 3965 | Body.get() == S->getBody()) |
| 3966 | return SemaRef.Owned(S->Retain()); |
| 3967 | |
| 3968 | // Build a new statement. |
| 3969 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 3970 | /*FIXME:*/S->getForLoc(), |
| 3971 | move(Element), |
| 3972 | move(Collection), |
| 3973 | S->getRParenLoc(), |
| 3974 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3975 | } |
| 3976 | |
| 3977 | |
| 3978 | template<typename Derived> |
| 3979 | Sema::OwningStmtResult |
| 3980 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3981 | // Transform the exception declaration, if any. |
| 3982 | VarDecl *Var = 0; |
| 3983 | if (S->getExceptionDecl()) { |
| 3984 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3985 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3986 | ExceptionDecl->getDeclName()); |
| 3987 | |
| 3988 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3989 | if (T.isNull()) |
| 3990 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3991 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3992 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3993 | T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3994 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3995 | ExceptionDecl->getIdentifier(), |
| 3996 | ExceptionDecl->getLocation(), |
| 3997 | /*FIXME: Inaccurate*/ |
| 3998 | SourceRange(ExceptionDecl->getLocation())); |
| 3999 | if (!Var || Var->isInvalidDecl()) { |
| 4000 | if (Var) |
| 4001 | Var->Destroy(SemaRef.Context); |
| 4002 | return SemaRef.StmtError(); |
| 4003 | } |
| 4004 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4005 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4006 | // Transform the actual exception handler. |
| 4007 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 4008 | if (Handler.isInvalid()) { |
| 4009 | if (Var) |
| 4010 | Var->Destroy(SemaRef.Context); |
| 4011 | return SemaRef.StmtError(); |
| 4012 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4013 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4014 | if (!getDerived().AlwaysRebuild() && |
| 4015 | !Var && |
| 4016 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4017 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4018 | |
| 4019 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 4020 | Var, |
| 4021 | move(Handler)); |
| 4022 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4023 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4024 | template<typename Derived> |
| 4025 | Sema::OwningStmtResult |
| 4026 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 4027 | // Transform the try block itself. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4028 | OwningStmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4029 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 4030 | if (TryBlock.isInvalid()) |
| 4031 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4032 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4033 | // Transform the handlers. |
| 4034 | bool HandlerChanged = false; |
| 4035 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 4036 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4037 | OwningStmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4038 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 4039 | if (Handler.isInvalid()) |
| 4040 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4041 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4042 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 4043 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 4044 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4045 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4046 | if (!getDerived().AlwaysRebuild() && |
| 4047 | TryBlock.get() == S->getTryBlock() && |
| 4048 | !HandlerChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4049 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4050 | |
| 4051 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4052 | move_arg(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4053 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4054 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4055 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4056 | // Expression transformation |
| 4057 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4058 | template<typename Derived> |
| 4059 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4060 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4061 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4062 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4063 | |
| 4064 | template<typename Derived> |
| 4065 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4066 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4067 | NestedNameSpecifier *Qualifier = 0; |
| 4068 | if (E->getQualifier()) { |
| 4069 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4070 | E->getQualifierRange()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4071 | if (!Qualifier) |
| 4072 | return SemaRef.ExprError(); |
| 4073 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4074 | |
| 4075 | ValueDecl *ND |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4076 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 4077 | E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4078 | if (!ND) |
| 4079 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4080 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4081 | if (!getDerived().AlwaysRebuild() && |
| 4082 | Qualifier == E->getQualifier() && |
| 4083 | ND == E->getDecl() && |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4084 | !E->hasExplicitTemplateArgumentList()) { |
| 4085 | |
| 4086 | // Mark it referenced in the new context regardless. |
| 4087 | // FIXME: this is a bit instantiation-specific. |
| 4088 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 4089 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4090 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4091 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4092 | |
| 4093 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 4094 | if (E->hasExplicitTemplateArgumentList()) { |
| 4095 | TemplateArgs = &TransArgs; |
| 4096 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4097 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 4098 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 4099 | TemplateArgumentLoc Loc; |
| 4100 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 4101 | return SemaRef.ExprError(); |
| 4102 | TransArgs.addArgument(Loc); |
| 4103 | } |
| 4104 | } |
| 4105 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4106 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4107 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4108 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4109 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4110 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4111 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4112 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4113 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4114 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4115 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4116 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4117 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4118 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4119 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4120 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4121 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4122 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4123 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4124 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4125 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4126 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4127 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4128 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4129 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4130 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4131 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4132 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4133 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4134 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4135 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4136 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4137 | return SemaRef.Owned(E->Retain()); |
| 4138 | } |
| 4139 | |
| 4140 | template<typename Derived> |
| 4141 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4142 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4143 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4144 | if (SubExpr.isInvalid()) |
| 4145 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4146 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4147 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4148 | return SemaRef.Owned(E->Retain()); |
| 4149 | |
| 4150 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4151 | E->getRParen()); |
| 4152 | } |
| 4153 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4154 | template<typename Derived> |
| 4155 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4156 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 4157 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4158 | if (SubExpr.isInvalid()) |
| 4159 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4160 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4161 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4162 | return SemaRef.Owned(E->Retain()); |
| 4163 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4164 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 4165 | E->getOpcode(), |
| 4166 | move(SubExpr)); |
| 4167 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4168 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4169 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4170 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4171 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4172 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4173 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4174 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4175 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4176 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4177 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4178 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4179 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4180 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4181 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4182 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4183 | E->isSizeOf(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4184 | E->getSourceRange()); |
| 4185 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4186 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4187 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4188 | { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4189 | // C++0x [expr.sizeof]p1: |
| 4190 | // The operand is either an expression, which is an unevaluated operand |
| 4191 | // [...] |
| 4192 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4193 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4194 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 4195 | if (SubExpr.isInvalid()) |
| 4196 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4197 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4198 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 4199 | return SemaRef.Owned(E->Retain()); |
| 4200 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4201 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4202 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 4203 | E->isSizeOf(), |
| 4204 | E->getSourceRange()); |
| 4205 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4206 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4207 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4208 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4209 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4210 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4211 | if (LHS.isInvalid()) |
| 4212 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4213 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4214 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4215 | if (RHS.isInvalid()) |
| 4216 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4217 | |
| 4218 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4219 | if (!getDerived().AlwaysRebuild() && |
| 4220 | LHS.get() == E->getLHS() && |
| 4221 | RHS.get() == E->getRHS()) |
| 4222 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4223 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4224 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 4225 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 4226 | move(RHS), |
| 4227 | E->getRBracketLoc()); |
| 4228 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4229 | |
| 4230 | template<typename Derived> |
| 4231 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4232 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4233 | // Transform the callee. |
| 4234 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4235 | if (Callee.isInvalid()) |
| 4236 | return SemaRef.ExprError(); |
| 4237 | |
| 4238 | // Transform arguments. |
| 4239 | bool ArgChanged = false; |
| 4240 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4241 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4242 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 4243 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4244 | if (Arg.isInvalid()) |
| 4245 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4246 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4247 | // FIXME: Wrong source location information for the ','. |
| 4248 | FakeCommaLocs.push_back( |
| 4249 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4250 | |
| 4251 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4252 | Args.push_back(Arg.takeAs<Expr>()); |
| 4253 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4254 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4255 | if (!getDerived().AlwaysRebuild() && |
| 4256 | Callee.get() == E->getCallee() && |
| 4257 | !ArgChanged) |
| 4258 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4259 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4260 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4261 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4262 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 4263 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 4264 | move_arg(Args), |
| 4265 | FakeCommaLocs.data(), |
| 4266 | E->getRParenLoc()); |
| 4267 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4268 | |
| 4269 | template<typename Derived> |
| 4270 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4271 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4272 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4273 | if (Base.isInvalid()) |
| 4274 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4275 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4276 | NestedNameSpecifier *Qualifier = 0; |
| 4277 | if (E->hasQualifier()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4278 | Qualifier |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4279 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4280 | E->getQualifierRange()); |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 4281 | if (Qualifier == 0) |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4282 | return SemaRef.ExprError(); |
| 4283 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4284 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 4285 | ValueDecl *Member |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4286 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 4287 | E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4288 | if (!Member) |
| 4289 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4290 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4291 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 4292 | if (FoundDecl == E->getMemberDecl()) { |
| 4293 | FoundDecl = Member; |
| 4294 | } else { |
| 4295 | FoundDecl = cast_or_null<NamedDecl>( |
| 4296 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 4297 | if (!FoundDecl) |
| 4298 | return SemaRef.ExprError(); |
| 4299 | } |
| 4300 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4301 | if (!getDerived().AlwaysRebuild() && |
| 4302 | Base.get() == E->getBase() && |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4303 | Qualifier == E->getQualifier() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4304 | Member == E->getMemberDecl() && |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4305 | FoundDecl == E->getFoundDecl() && |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4306 | !E->hasExplicitTemplateArgumentList()) { |
| 4307 | |
| 4308 | // Mark it referenced in the new context regardless. |
| 4309 | // FIXME: this is a bit instantiation-specific. |
| 4310 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4311 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4312 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4313 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4314 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4315 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4316 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4317 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4318 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4319 | TemplateArgumentLoc Loc; |
| 4320 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4321 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4322 | TransArgs.addArgument(Loc); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4323 | } |
| 4324 | } |
| 4325 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4326 | // FIXME: Bogus source location for the operator |
| 4327 | SourceLocation FakeOperatorLoc |
| 4328 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 4329 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4330 | // FIXME: to do this check properly, we will need to preserve the |
| 4331 | // first-qualifier-in-scope here, just in case we had a dependent |
| 4332 | // base (and therefore couldn't do the check) and a |
| 4333 | // nested-name-qualifier (and therefore could do the lookup). |
| 4334 | NamedDecl *FirstQualifierInScope = 0; |
| 4335 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4336 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 4337 | E->isArrow(), |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4338 | Qualifier, |
| 4339 | E->getQualifierRange(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4340 | E->getMemberLoc(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4341 | Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4342 | FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4343 | (E->hasExplicitTemplateArgumentList() |
| 4344 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4345 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4346 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4347 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4348 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4349 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4350 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4351 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4352 | if (LHS.isInvalid()) |
| 4353 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4354 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4355 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4356 | if (RHS.isInvalid()) |
| 4357 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4358 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4359 | if (!getDerived().AlwaysRebuild() && |
| 4360 | LHS.get() == E->getLHS() && |
| 4361 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4362 | return SemaRef.Owned(E->Retain()); |
| 4363 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4364 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 4365 | move(LHS), move(RHS)); |
| 4366 | } |
| 4367 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4368 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4369 | Sema::OwningExprResult |
| 4370 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4371 | CompoundAssignOperator *E) { |
| 4372 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4373 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4374 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4375 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4376 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4377 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4378 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4379 | if (Cond.isInvalid()) |
| 4380 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4381 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4382 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4383 | if (LHS.isInvalid()) |
| 4384 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4385 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4386 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4387 | if (RHS.isInvalid()) |
| 4388 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4389 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4390 | if (!getDerived().AlwaysRebuild() && |
| 4391 | Cond.get() == E->getCond() && |
| 4392 | LHS.get() == E->getLHS() && |
| 4393 | RHS.get() == E->getRHS()) |
| 4394 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4395 | |
| 4396 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4397 | E->getQuestionLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4398 | move(LHS), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4399 | E->getColonLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4400 | move(RHS)); |
| 4401 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4402 | |
| 4403 | template<typename Derived> |
| 4404 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4405 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4406 | // Implicit casts are eliminated during transformation, since they |
| 4407 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4408 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4409 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4410 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4411 | template<typename Derived> |
| 4412 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4413 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4414 | TypeSourceInfo *OldT; |
| 4415 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4416 | { |
| 4417 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4418 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4419 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 4420 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4421 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4422 | OldT = E->getTypeInfoAsWritten(); |
| 4423 | NewT = getDerived().TransformType(OldT); |
| 4424 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4425 | return SemaRef.ExprError(); |
| 4426 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4427 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4428 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4429 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4430 | if (SubExpr.isInvalid()) |
| 4431 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4432 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4433 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4434 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4435 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4436 | return SemaRef.Owned(E->Retain()); |
| 4437 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4438 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 4439 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4440 | E->getRParenLoc(), |
| 4441 | move(SubExpr)); |
| 4442 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4443 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4444 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4445 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4446 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4447 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 4448 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 4449 | if (!NewT) |
| 4450 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4451 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4452 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 4453 | if (Init.isInvalid()) |
| 4454 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4455 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4456 | if (!getDerived().AlwaysRebuild() && |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4457 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4458 | Init.get() == E->getInitializer()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4459 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4460 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 4461 | // Note: the expression type doesn't necessarily match the |
| 4462 | // type-as-written, but that's okay, because it should always be |
| 4463 | // derivable from the initializer. |
| 4464 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4465 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4466 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 4467 | move(Init)); |
| 4468 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4469 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4470 | template<typename Derived> |
| 4471 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4472 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4473 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4474 | if (Base.isInvalid()) |
| 4475 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4476 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4477 | if (!getDerived().AlwaysRebuild() && |
| 4478 | Base.get() == E->getBase()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4479 | return SemaRef.Owned(E->Retain()); |
| 4480 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4481 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4482 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4483 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 4484 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 4485 | E->getAccessorLoc(), |
| 4486 | E->getAccessor()); |
| 4487 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4488 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4489 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4490 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4491 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4492 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4493 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4494 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4495 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4496 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4497 | if (Init.isInvalid()) |
| 4498 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4499 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4500 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4501 | Inits.push_back(Init.takeAs<Expr>()); |
| 4502 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4503 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4504 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4505 | return SemaRef.Owned(E->Retain()); |
| 4506 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4507 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4508 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4509 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4510 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4511 | template<typename Derived> |
| 4512 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4513 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4514 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4515 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4516 | // transform the initializer value |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4517 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4518 | if (Init.isInvalid()) |
| 4519 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4520 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4521 | // transform the designators. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4522 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4523 | bool ExprChanged = false; |
| 4524 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4525 | DEnd = E->designators_end(); |
| 4526 | D != DEnd; ++D) { |
| 4527 | if (D->isFieldDesignator()) { |
| 4528 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4529 | D->getDotLoc(), |
| 4530 | D->getFieldLoc())); |
| 4531 | continue; |
| 4532 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4533 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4534 | if (D->isArrayDesignator()) { |
| 4535 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4536 | if (Index.isInvalid()) |
| 4537 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4538 | |
| 4539 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4540 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4541 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4542 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4543 | ArrayExprs.push_back(Index.release()); |
| 4544 | continue; |
| 4545 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4546 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4547 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4548 | OwningExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4549 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4550 | if (Start.isInvalid()) |
| 4551 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4552 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4553 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4554 | if (End.isInvalid()) |
| 4555 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4556 | |
| 4557 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4558 | End.get(), |
| 4559 | D->getLBracketLoc(), |
| 4560 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4561 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4562 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4563 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4564 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4565 | ArrayExprs.push_back(Start.release()); |
| 4566 | ArrayExprs.push_back(End.release()); |
| 4567 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4568 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4569 | if (!getDerived().AlwaysRebuild() && |
| 4570 | Init.get() == E->getInit() && |
| 4571 | !ExprChanged) |
| 4572 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4573 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4574 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4575 | E->getEqualOrColonLoc(), |
| 4576 | E->usesGNUSyntax(), move(Init)); |
| 4577 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4578 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4579 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4580 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4581 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4582 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4583 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4584 | |
| 4585 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4586 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4587 | QualType T = getDerived().TransformType(E->getType()); |
| 4588 | if (T.isNull()) |
| 4589 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4590 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4591 | if (!getDerived().AlwaysRebuild() && |
| 4592 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4593 | return SemaRef.Owned(E->Retain()); |
| 4594 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4595 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4596 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4597 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4598 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4599 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4600 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4601 | // FIXME: Do we want the type as written? |
| 4602 | QualType T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4603 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4604 | { |
| 4605 | // FIXME: Source location isn't quite accurate. |
| 4606 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4607 | T = getDerived().TransformType(E->getType()); |
| 4608 | if (T.isNull()) |
| 4609 | return SemaRef.ExprError(); |
| 4610 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4611 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4612 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4613 | if (SubExpr.isInvalid()) |
| 4614 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4615 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4616 | if (!getDerived().AlwaysRebuild() && |
| 4617 | T == E->getType() && |
| 4618 | SubExpr.get() == E->getSubExpr()) |
| 4619 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4620 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4621 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4622 | T, E->getRParenLoc()); |
| 4623 | } |
| 4624 | |
| 4625 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4626 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4627 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4628 | bool ArgumentChanged = false; |
| 4629 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4630 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4631 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4632 | if (Init.isInvalid()) |
| 4633 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4634 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4635 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4636 | Inits.push_back(Init.takeAs<Expr>()); |
| 4637 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4638 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4639 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4640 | move_arg(Inits), |
| 4641 | E->getRParenLoc()); |
| 4642 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4643 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4644 | /// \brief Transform an address-of-label expression. |
| 4645 | /// |
| 4646 | /// By default, the transformation of an address-of-label expression always |
| 4647 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4648 | /// the corresponding label statement by semantic analysis. |
| 4649 | template<typename Derived> |
| 4650 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4651 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4652 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4653 | E->getLabel()); |
| 4654 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4655 | |
| 4656 | template<typename Derived> |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4657 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4658 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4659 | OwningStmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4660 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4661 | if (SubStmt.isInvalid()) |
| 4662 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4663 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4664 | if (!getDerived().AlwaysRebuild() && |
| 4665 | SubStmt.get() == E->getSubStmt()) |
| 4666 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4667 | |
| 4668 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4669 | move(SubStmt), |
| 4670 | E->getRParenLoc()); |
| 4671 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4672 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4673 | template<typename Derived> |
| 4674 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4675 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4676 | QualType T1, T2; |
| 4677 | { |
| 4678 | // FIXME: Source location isn't quite accurate. |
| 4679 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4680 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4681 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4682 | if (T1.isNull()) |
| 4683 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4684 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4685 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4686 | if (T2.isNull()) |
| 4687 | return SemaRef.ExprError(); |
| 4688 | } |
| 4689 | |
| 4690 | if (!getDerived().AlwaysRebuild() && |
| 4691 | T1 == E->getArgType1() && |
| 4692 | T2 == E->getArgType2()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4693 | return SemaRef.Owned(E->Retain()); |
| 4694 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4695 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4696 | T1, T2, E->getRParenLoc()); |
| 4697 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4698 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4699 | template<typename Derived> |
| 4700 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4701 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4702 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4703 | if (Cond.isInvalid()) |
| 4704 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4705 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4706 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4707 | if (LHS.isInvalid()) |
| 4708 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4709 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4710 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4711 | if (RHS.isInvalid()) |
| 4712 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4713 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4714 | if (!getDerived().AlwaysRebuild() && |
| 4715 | Cond.get() == E->getCond() && |
| 4716 | LHS.get() == E->getLHS() && |
| 4717 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4718 | return SemaRef.Owned(E->Retain()); |
| 4719 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4720 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4721 | move(Cond), move(LHS), move(RHS), |
| 4722 | E->getRParenLoc()); |
| 4723 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4724 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4725 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4726 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4727 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4728 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4729 | } |
| 4730 | |
| 4731 | template<typename Derived> |
| 4732 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4733 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4734 | switch (E->getOperator()) { |
| 4735 | case OO_New: |
| 4736 | case OO_Delete: |
| 4737 | case OO_Array_New: |
| 4738 | case OO_Array_Delete: |
| 4739 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4740 | return SemaRef.ExprError(); |
| 4741 | |
| 4742 | case OO_Call: { |
| 4743 | // This is a call to an object's operator(). |
| 4744 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4745 | |
| 4746 | // Transform the object itself. |
| 4747 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4748 | if (Object.isInvalid()) |
| 4749 | return SemaRef.ExprError(); |
| 4750 | |
| 4751 | // FIXME: Poor location information |
| 4752 | SourceLocation FakeLParenLoc |
| 4753 | = SemaRef.PP.getLocForEndOfToken( |
| 4754 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4755 | |
| 4756 | // Transform the call arguments. |
| 4757 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4758 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4759 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4760 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4761 | break; |
| 4762 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4763 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4764 | if (Arg.isInvalid()) |
| 4765 | return SemaRef.ExprError(); |
| 4766 | |
| 4767 | // FIXME: Poor source location information. |
| 4768 | SourceLocation FakeCommaLoc |
| 4769 | = SemaRef.PP.getLocForEndOfToken( |
| 4770 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4771 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4772 | Args.push_back(Arg.release()); |
| 4773 | } |
| 4774 | |
| 4775 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4776 | move_arg(Args), |
| 4777 | FakeCommaLocs.data(), |
| 4778 | E->getLocEnd()); |
| 4779 | } |
| 4780 | |
| 4781 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4782 | case OO_##Name: |
| 4783 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4784 | #include "clang/Basic/OperatorKinds.def" |
| 4785 | case OO_Subscript: |
| 4786 | // Handled below. |
| 4787 | break; |
| 4788 | |
| 4789 | case OO_Conditional: |
| 4790 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4791 | return SemaRef.ExprError(); |
| 4792 | |
| 4793 | case OO_None: |
| 4794 | case NUM_OVERLOADED_OPERATORS: |
| 4795 | llvm_unreachable("not an overloaded operator?"); |
| 4796 | return SemaRef.ExprError(); |
| 4797 | } |
| 4798 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4799 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4800 | if (Callee.isInvalid()) |
| 4801 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4802 | |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4803 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4804 | if (First.isInvalid()) |
| 4805 | return SemaRef.ExprError(); |
| 4806 | |
| 4807 | OwningExprResult Second(SemaRef); |
| 4808 | if (E->getNumArgs() == 2) { |
| 4809 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4810 | if (Second.isInvalid()) |
| 4811 | return SemaRef.ExprError(); |
| 4812 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4813 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4814 | if (!getDerived().AlwaysRebuild() && |
| 4815 | Callee.get() == E->getCallee() && |
| 4816 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4817 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4818 | return SemaRef.Owned(E->Retain()); |
| 4819 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4820 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4821 | E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4822 | move(Callee), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4823 | move(First), |
| 4824 | move(Second)); |
| 4825 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4826 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4827 | template<typename Derived> |
| 4828 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4829 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4830 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4831 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4832 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4833 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4834 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4835 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4836 | TypeSourceInfo *OldT; |
| 4837 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4838 | { |
| 4839 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4840 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4841 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4842 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4843 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4844 | OldT = E->getTypeInfoAsWritten(); |
| 4845 | NewT = getDerived().TransformType(OldT); |
| 4846 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4847 | return SemaRef.ExprError(); |
| 4848 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4849 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4850 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4851 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4852 | if (SubExpr.isInvalid()) |
| 4853 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4854 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4855 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4856 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4857 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4858 | return SemaRef.Owned(E->Retain()); |
| 4859 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4860 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4861 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4862 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4863 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4864 | SourceLocation FakeRParenLoc |
| 4865 | = SemaRef.PP.getLocForEndOfToken( |
| 4866 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4867 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4868 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4869 | FakeLAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4870 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4871 | FakeRAngleLoc, |
| 4872 | FakeRAngleLoc, |
| 4873 | move(SubExpr), |
| 4874 | FakeRParenLoc); |
| 4875 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4876 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4877 | template<typename Derived> |
| 4878 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4879 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4880 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4881 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4882 | |
| 4883 | template<typename Derived> |
| 4884 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4885 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4886 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4887 | } |
| 4888 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4889 | template<typename Derived> |
| 4890 | Sema::OwningExprResult |
| 4891 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4892 | CXXReinterpretCastExpr *E) { |
| 4893 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4894 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4895 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4896 | template<typename Derived> |
| 4897 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4898 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4899 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4900 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4901 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4902 | template<typename Derived> |
| 4903 | Sema::OwningExprResult |
| 4904 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4905 | CXXFunctionalCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4906 | TypeSourceInfo *OldT; |
| 4907 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4908 | { |
| 4909 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4910 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4911 | OldT = E->getTypeInfoAsWritten(); |
| 4912 | NewT = getDerived().TransformType(OldT); |
| 4913 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4914 | return SemaRef.ExprError(); |
| 4915 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4916 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4917 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4918 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4919 | if (SubExpr.isInvalid()) |
| 4920 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4921 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4922 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4923 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4924 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4925 | return SemaRef.Owned(E->Retain()); |
| 4926 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4927 | // FIXME: The end of the type's source range is wrong |
| 4928 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4929 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4930 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4931 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4932 | move(SubExpr), |
| 4933 | E->getRParenLoc()); |
| 4934 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4935 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4936 | template<typename Derived> |
| 4937 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4938 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4939 | if (E->isTypeOperand()) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 4940 | TypeSourceInfo *TInfo |
| 4941 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 4942 | if (!TInfo) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4943 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4944 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4945 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 4946 | TInfo == E->getTypeOperandSourceInfo()) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4947 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4948 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 4949 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 4950 | E->getLocStart(), |
| 4951 | TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4952 | E->getLocEnd()); |
| 4953 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4954 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4955 | // We don't know whether the expression is potentially evaluated until |
| 4956 | // after we perform semantic analysis, so the expression is potentially |
| 4957 | // potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4958 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4959 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4960 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4961 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4962 | if (SubExpr.isInvalid()) |
| 4963 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4964 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4965 | if (!getDerived().AlwaysRebuild() && |
| 4966 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4967 | return SemaRef.Owned(E->Retain()); |
| 4968 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 4969 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 4970 | E->getLocStart(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4971 | move(SubExpr), |
| 4972 | E->getLocEnd()); |
| 4973 | } |
| 4974 | |
| 4975 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4976 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4977 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4978 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4979 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4980 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4981 | template<typename Derived> |
| 4982 | Sema::OwningExprResult |
| 4983 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4984 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4985 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4986 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4987 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4988 | template<typename Derived> |
| 4989 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4990 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4991 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4992 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4993 | QualType T = getDerived().TransformType(E->getType()); |
| 4994 | if (T.isNull()) |
| 4995 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4996 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4997 | if (!getDerived().AlwaysRebuild() && |
| 4998 | T == E->getType()) |
| 4999 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5000 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 5001 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5002 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5003 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5004 | template<typename Derived> |
| 5005 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5006 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5007 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 5008 | if (SubExpr.isInvalid()) |
| 5009 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5010 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5011 | if (!getDerived().AlwaysRebuild() && |
| 5012 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5013 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5014 | |
| 5015 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 5016 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5017 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5018 | template<typename Derived> |
| 5019 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5020 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5021 | ParmVarDecl *Param |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5022 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 5023 | E->getParam())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5024 | if (!Param) |
| 5025 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5026 | |
Chandler Carruth | 53cb6f8 | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 5027 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5028 | Param == E->getParam()) |
| 5029 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5030 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 5031 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5032 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5033 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5034 | template<typename Derived> |
| 5035 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5036 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5037 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5038 | |
| 5039 | QualType T = getDerived().TransformType(E->getType()); |
| 5040 | if (T.isNull()) |
| 5041 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5042 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5043 | if (!getDerived().AlwaysRebuild() && |
| 5044 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5045 | return SemaRef.Owned(E->Retain()); |
| 5046 | |
| 5047 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5048 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5049 | T, |
| 5050 | E->getRParenLoc()); |
| 5051 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5052 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5053 | template<typename Derived> |
| 5054 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5055 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5056 | // Transform the type that we're allocating |
| 5057 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 5058 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 5059 | if (AllocType.isNull()) |
| 5060 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5061 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5062 | // Transform the size of the array we're allocating (if any). |
| 5063 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 5064 | if (ArraySize.isInvalid()) |
| 5065 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5066 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5067 | // Transform the placement arguments (if any). |
| 5068 | bool ArgumentChanged = false; |
| 5069 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 5070 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 5071 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 5072 | if (Arg.isInvalid()) |
| 5073 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5074 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5075 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 5076 | PlacementArgs.push_back(Arg.take()); |
| 5077 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5078 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5079 | // transform the constructor arguments (if any). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5080 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 5081 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 5082 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 5083 | if (Arg.isInvalid()) |
| 5084 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5085 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5086 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 5087 | ConstructorArgs.push_back(Arg.take()); |
| 5088 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5089 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5090 | // Transform constructor, new operator, and delete operator. |
| 5091 | CXXConstructorDecl *Constructor = 0; |
| 5092 | if (E->getConstructor()) { |
| 5093 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5094 | getDerived().TransformDecl(E->getLocStart(), |
| 5095 | E->getConstructor())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5096 | if (!Constructor) |
| 5097 | return SemaRef.ExprError(); |
| 5098 | } |
| 5099 | |
| 5100 | FunctionDecl *OperatorNew = 0; |
| 5101 | if (E->getOperatorNew()) { |
| 5102 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5103 | getDerived().TransformDecl(E->getLocStart(), |
| 5104 | E->getOperatorNew())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5105 | if (!OperatorNew) |
| 5106 | return SemaRef.ExprError(); |
| 5107 | } |
| 5108 | |
| 5109 | FunctionDecl *OperatorDelete = 0; |
| 5110 | if (E->getOperatorDelete()) { |
| 5111 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5112 | getDerived().TransformDecl(E->getLocStart(), |
| 5113 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5114 | if (!OperatorDelete) |
| 5115 | return SemaRef.ExprError(); |
| 5116 | } |
| 5117 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5118 | if (!getDerived().AlwaysRebuild() && |
| 5119 | AllocType == E->getAllocatedType() && |
| 5120 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5121 | Constructor == E->getConstructor() && |
| 5122 | OperatorNew == E->getOperatorNew() && |
| 5123 | OperatorDelete == E->getOperatorDelete() && |
| 5124 | !ArgumentChanged) { |
| 5125 | // Mark any declarations we need as referenced. |
| 5126 | // FIXME: instantiation-specific. |
| 5127 | if (Constructor) |
| 5128 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 5129 | if (OperatorNew) |
| 5130 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 5131 | if (OperatorDelete) |
| 5132 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5133 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5134 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5135 | |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5136 | if (!ArraySize.get()) { |
| 5137 | // If no array size was specified, but the new expression was |
| 5138 | // instantiated with an array type (e.g., "new T" where T is |
| 5139 | // instantiated with "int[4]"), extract the outer bound from the |
| 5140 | // array type as our array size. We do this with constant and |
| 5141 | // dependently-sized array types. |
| 5142 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 5143 | if (!ArrayT) { |
| 5144 | // Do nothing |
| 5145 | } else if (const ConstantArrayType *ConsArrayT |
| 5146 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 5147 | ArraySize |
| 5148 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 5149 | ConsArrayT->getSize(), |
| 5150 | SemaRef.Context.getSizeType(), |
| 5151 | /*FIXME:*/E->getLocStart())); |
| 5152 | AllocType = ConsArrayT->getElementType(); |
| 5153 | } else if (const DependentSizedArrayType *DepArrayT |
| 5154 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 5155 | if (DepArrayT->getSizeExpr()) { |
| 5156 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 5157 | AllocType = DepArrayT->getElementType(); |
| 5158 | } |
| 5159 | } |
| 5160 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5161 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 5162 | E->isGlobalNew(), |
| 5163 | /*FIXME:*/E->getLocStart(), |
| 5164 | move_arg(PlacementArgs), |
| 5165 | /*FIXME:*/E->getLocStart(), |
| 5166 | E->isParenTypeId(), |
| 5167 | AllocType, |
| 5168 | /*FIXME:*/E->getLocStart(), |
| 5169 | /*FIXME:*/SourceRange(), |
| 5170 | move(ArraySize), |
| 5171 | /*FIXME:*/E->getLocStart(), |
| 5172 | move_arg(ConstructorArgs), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5173 | E->getLocEnd()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5174 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5175 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5176 | template<typename Derived> |
| 5177 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5178 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5179 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 5180 | if (Operand.isInvalid()) |
| 5181 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5182 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5183 | // Transform the delete operator, if known. |
| 5184 | FunctionDecl *OperatorDelete = 0; |
| 5185 | if (E->getOperatorDelete()) { |
| 5186 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5187 | getDerived().TransformDecl(E->getLocStart(), |
| 5188 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5189 | if (!OperatorDelete) |
| 5190 | return SemaRef.ExprError(); |
| 5191 | } |
| 5192 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5193 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5194 | Operand.get() == E->getArgument() && |
| 5195 | OperatorDelete == E->getOperatorDelete()) { |
| 5196 | // Mark any declarations we need as referenced. |
| 5197 | // FIXME: instantiation-specific. |
| 5198 | if (OperatorDelete) |
| 5199 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5200 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5201 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5202 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5203 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 5204 | E->isGlobalDelete(), |
| 5205 | E->isArrayForm(), |
| 5206 | move(Operand)); |
| 5207 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5208 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5209 | template<typename Derived> |
| 5210 | Sema::OwningExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5211 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5212 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5213 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 5214 | if (Base.isInvalid()) |
| 5215 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5216 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5217 | Sema::TypeTy *ObjectTypePtr = 0; |
| 5218 | bool MayBePseudoDestructor = false; |
| 5219 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5220 | E->getOperatorLoc(), |
| 5221 | E->isArrow()? tok::arrow : tok::period, |
| 5222 | ObjectTypePtr, |
| 5223 | MayBePseudoDestructor); |
| 5224 | if (Base.isInvalid()) |
| 5225 | return SemaRef.ExprError(); |
| 5226 | |
| 5227 | QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5228 | NestedNameSpecifier *Qualifier |
| 5229 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | b10cd04 | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 5230 | E->getQualifierRange(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5231 | ObjectType); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5232 | if (E->getQualifier() && !Qualifier) |
| 5233 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5234 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5235 | PseudoDestructorTypeStorage Destroyed; |
| 5236 | if (E->getDestroyedTypeInfo()) { |
| 5237 | TypeSourceInfo *DestroyedTypeInfo |
| 5238 | = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType); |
| 5239 | if (!DestroyedTypeInfo) |
| 5240 | return SemaRef.ExprError(); |
| 5241 | Destroyed = DestroyedTypeInfo; |
| 5242 | } else if (ObjectType->isDependentType()) { |
| 5243 | // We aren't likely to be able to resolve the identifier down to a type |
| 5244 | // now anyway, so just retain the identifier. |
| 5245 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 5246 | E->getDestroyedTypeLoc()); |
| 5247 | } else { |
| 5248 | // Look for a destructor known with the given name. |
| 5249 | CXXScopeSpec SS; |
| 5250 | if (Qualifier) { |
| 5251 | SS.setScopeRep(Qualifier); |
| 5252 | SS.setRange(E->getQualifierRange()); |
| 5253 | } |
| 5254 | |
| 5255 | Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(), |
| 5256 | *E->getDestroyedTypeIdentifier(), |
| 5257 | E->getDestroyedTypeLoc(), |
| 5258 | /*Scope=*/0, |
| 5259 | SS, ObjectTypePtr, |
| 5260 | false); |
| 5261 | if (!T) |
| 5262 | return SemaRef.ExprError(); |
| 5263 | |
| 5264 | Destroyed |
| 5265 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 5266 | E->getDestroyedTypeLoc()); |
| 5267 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5268 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5269 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 5270 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5271 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(), |
| 5272 | ObjectType); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5273 | if (!ScopeTypeInfo) |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5274 | return SemaRef.ExprError(); |
| 5275 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5276 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5277 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 5278 | E->getOperatorLoc(), |
| 5279 | E->isArrow(), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5280 | Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5281 | E->getQualifierRange(), |
| 5282 | ScopeTypeInfo, |
| 5283 | E->getColonColonLoc(), |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 5284 | E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5285 | Destroyed); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5286 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5287 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5288 | template<typename Derived> |
| 5289 | Sema::OwningExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5290 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5291 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5292 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 5293 | |
| 5294 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 5295 | Sema::LookupOrdinaryName); |
| 5296 | |
| 5297 | // Transform all the decls. |
| 5298 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 5299 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5300 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5301 | getDerived().TransformDecl(Old->getNameLoc(), |
| 5302 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5303 | if (!InstD) { |
| 5304 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5305 | // This can happen because of dependent hiding. |
| 5306 | if (isa<UsingShadowDecl>(*I)) |
| 5307 | continue; |
| 5308 | else |
| 5309 | return SemaRef.ExprError(); |
| 5310 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5311 | |
| 5312 | // Expand using declarations. |
| 5313 | if (isa<UsingDecl>(InstD)) { |
| 5314 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5315 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5316 | E = UD->shadow_end(); I != E; ++I) |
| 5317 | R.addDecl(*I); |
| 5318 | continue; |
| 5319 | } |
| 5320 | |
| 5321 | R.addDecl(InstD); |
| 5322 | } |
| 5323 | |
| 5324 | // Resolve a kind, but don't do any further analysis. If it's |
| 5325 | // ambiguous, the callee needs to deal with it. |
| 5326 | R.resolveKind(); |
| 5327 | |
| 5328 | // Rebuild the nested-name qualifier, if present. |
| 5329 | CXXScopeSpec SS; |
| 5330 | NestedNameSpecifier *Qualifier = 0; |
| 5331 | if (Old->getQualifier()) { |
| 5332 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5333 | Old->getQualifierRange()); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5334 | if (!Qualifier) |
| 5335 | return SemaRef.ExprError(); |
| 5336 | |
| 5337 | SS.setScopeRep(Qualifier); |
| 5338 | SS.setRange(Old->getQualifierRange()); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame^] | 5339 | } |
| 5340 | |
| 5341 | if (Old->getNamingClass()) { |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5342 | CXXRecordDecl *NamingClass |
| 5343 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 5344 | Old->getNameLoc(), |
| 5345 | Old->getNamingClass())); |
| 5346 | if (!NamingClass) |
| 5347 | return SemaRef.ExprError(); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame^] | 5348 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5349 | R.setNamingClass(NamingClass); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5350 | } |
| 5351 | |
| 5352 | // If we have no template arguments, it's a normal declaration name. |
| 5353 | if (!Old->hasExplicitTemplateArgs()) |
| 5354 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 5355 | |
| 5356 | // If we have template arguments, rebuild them, then rebuild the |
| 5357 | // templateid expression. |
| 5358 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 5359 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5360 | TemplateArgumentLoc Loc; |
| 5361 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 5362 | return SemaRef.ExprError(); |
| 5363 | TransArgs.addArgument(Loc); |
| 5364 | } |
| 5365 | |
| 5366 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 5367 | TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5368 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5369 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5370 | template<typename Derived> |
| 5371 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5372 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5373 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5374 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5375 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 5376 | if (T.isNull()) |
| 5377 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5378 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5379 | if (!getDerived().AlwaysRebuild() && |
| 5380 | T == E->getQueriedType()) |
| 5381 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5382 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5383 | // FIXME: Bad location information |
| 5384 | SourceLocation FakeLParenLoc |
| 5385 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5386 | |
| 5387 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5388 | E->getLocStart(), |
| 5389 | /*FIXME:*/FakeLParenLoc, |
| 5390 | T, |
| 5391 | E->getLocEnd()); |
| 5392 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5393 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5394 | template<typename Derived> |
| 5395 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5396 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5397 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5398 | NestedNameSpecifier *NNS |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5399 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5400 | E->getQualifierRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5401 | if (!NNS) |
| 5402 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5403 | |
| 5404 | DeclarationName Name |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5405 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 5406 | if (!Name) |
| 5407 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5408 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5409 | if (!E->hasExplicitTemplateArgs()) { |
| 5410 | if (!getDerived().AlwaysRebuild() && |
| 5411 | NNS == E->getQualifier() && |
| 5412 | Name == E->getDeclName()) |
| 5413 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5414 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5415 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5416 | E->getQualifierRange(), |
| 5417 | Name, E->getLocation(), |
| 5418 | /*TemplateArgs*/ 0); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5419 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5420 | |
| 5421 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5422 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5423 | TemplateArgumentLoc Loc; |
| 5424 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5425 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5426 | TransArgs.addArgument(Loc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5427 | } |
| 5428 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5429 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5430 | E->getQualifierRange(), |
| 5431 | Name, E->getLocation(), |
| 5432 | &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5433 | } |
| 5434 | |
| 5435 | template<typename Derived> |
| 5436 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5437 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 5438 | // CXXConstructExprs are always implicit, so when we have a |
| 5439 | // 1-argument construction we just transform that argument. |
| 5440 | if (E->getNumArgs() == 1 || |
| 5441 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 5442 | return getDerived().TransformExpr(E->getArg(0)); |
| 5443 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5444 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 5445 | |
| 5446 | QualType T = getDerived().TransformType(E->getType()); |
| 5447 | if (T.isNull()) |
| 5448 | return SemaRef.ExprError(); |
| 5449 | |
| 5450 | CXXConstructorDecl *Constructor |
| 5451 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5452 | getDerived().TransformDecl(E->getLocStart(), |
| 5453 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5454 | if (!Constructor) |
| 5455 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5456 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5457 | bool ArgumentChanged = false; |
| 5458 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5459 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5460 | ArgEnd = E->arg_end(); |
| 5461 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5462 | if (getDerived().DropCallArgument(*Arg)) { |
| 5463 | ArgumentChanged = true; |
| 5464 | break; |
| 5465 | } |
| 5466 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5467 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5468 | if (TransArg.isInvalid()) |
| 5469 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5470 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5471 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5472 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5473 | } |
| 5474 | |
| 5475 | if (!getDerived().AlwaysRebuild() && |
| 5476 | T == E->getType() && |
| 5477 | Constructor == E->getConstructor() && |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5478 | !ArgumentChanged) { |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5479 | // Mark the constructor as referenced. |
| 5480 | // FIXME: Instantiation-specific |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5481 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5482 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5483 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5484 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 5485 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 5486 | Constructor, E->isElidable(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5487 | move_arg(Args)); |
| 5488 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5489 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5490 | /// \brief Transform a C++ temporary-binding expression. |
| 5491 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5492 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 5493 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5494 | template<typename Derived> |
| 5495 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5496 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5497 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5498 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5499 | |
Anders Carlsson | eb60edf | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 5500 | /// \brief Transform a C++ reference-binding expression. |
| 5501 | /// |
| 5502 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 5503 | /// transform the subexpression and return that. |
| 5504 | template<typename Derived> |
| 5505 | Sema::OwningExprResult |
| 5506 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 5507 | return getDerived().TransformExpr(E->getSubExpr()); |
| 5508 | } |
| 5509 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5510 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5511 | /// be destroyed after the expression is evaluated. |
| 5512 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5513 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 5514 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5515 | template<typename Derived> |
| 5516 | Sema::OwningExprResult |
| 5517 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5518 | CXXExprWithTemporaries *E) { |
| 5519 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5520 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5521 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5522 | template<typename Derived> |
| 5523 | Sema::OwningExprResult |
| 5524 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5525 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5526 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5527 | QualType T = getDerived().TransformType(E->getType()); |
| 5528 | if (T.isNull()) |
| 5529 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5530 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5531 | CXXConstructorDecl *Constructor |
| 5532 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5533 | getDerived().TransformDecl(E->getLocStart(), |
| 5534 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5535 | if (!Constructor) |
| 5536 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5537 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5538 | bool ArgumentChanged = false; |
| 5539 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5540 | Args.reserve(E->getNumArgs()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5541 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5542 | ArgEnd = E->arg_end(); |
| 5543 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5544 | if (getDerived().DropCallArgument(*Arg)) { |
| 5545 | ArgumentChanged = true; |
| 5546 | break; |
| 5547 | } |
| 5548 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5549 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5550 | if (TransArg.isInvalid()) |
| 5551 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5552 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5553 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5554 | Args.push_back((Expr *)TransArg.release()); |
| 5555 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5556 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5557 | if (!getDerived().AlwaysRebuild() && |
| 5558 | T == E->getType() && |
| 5559 | Constructor == E->getConstructor() && |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5560 | !ArgumentChanged) { |
| 5561 | // FIXME: Instantiation-specific |
| 5562 | SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor); |
Chandler Carruth | a3ce8ae | 2010-03-31 18:34:58 +0000 | [diff] [blame] | 5563 | return SemaRef.MaybeBindToTemporary(E->Retain()); |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5564 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5565 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5566 | // FIXME: Bogus location information |
| 5567 | SourceLocation CommaLoc; |
| 5568 | if (Args.size() > 1) { |
| 5569 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5570 | CommaLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5571 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 5572 | } |
| 5573 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 5574 | T, |
| 5575 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5576 | move_arg(Args), |
| 5577 | &CommaLoc, |
| 5578 | E->getLocEnd()); |
| 5579 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5580 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5581 | template<typename Derived> |
| 5582 | Sema::OwningExprResult |
| 5583 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5584 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5585 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5586 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 5587 | if (T.isNull()) |
| 5588 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5589 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5590 | bool ArgumentChanged = false; |
| 5591 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5592 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 5593 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 5594 | ArgEnd = E->arg_end(); |
| 5595 | Arg != ArgEnd; ++Arg) { |
| 5596 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5597 | if (TransArg.isInvalid()) |
| 5598 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5599 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5600 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5601 | FakeCommaLocs.push_back( |
| 5602 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 5603 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5604 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5605 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5606 | if (!getDerived().AlwaysRebuild() && |
| 5607 | T == E->getTypeAsWritten() && |
| 5608 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5609 | return SemaRef.Owned(E->Retain()); |
| 5610 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5611 | // FIXME: we're faking the locations of the commas |
| 5612 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5613 | T, |
| 5614 | E->getLParenLoc(), |
| 5615 | move_arg(Args), |
| 5616 | FakeCommaLocs.data(), |
| 5617 | E->getRParenLoc()); |
| 5618 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5619 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5620 | template<typename Derived> |
| 5621 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5622 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5623 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5624 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5625 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5626 | Expr *OldBase; |
| 5627 | QualType BaseType; |
| 5628 | QualType ObjectType; |
| 5629 | if (!E->isImplicitAccess()) { |
| 5630 | OldBase = E->getBase(); |
| 5631 | Base = getDerived().TransformExpr(OldBase); |
| 5632 | if (Base.isInvalid()) |
| 5633 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5634 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5635 | // Start the member reference and compute the object's type. |
| 5636 | Sema::TypeTy *ObjectTy = 0; |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5637 | bool MayBePseudoDestructor = false; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5638 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5639 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5640 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5641 | ObjectTy, |
| 5642 | MayBePseudoDestructor); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5643 | if (Base.isInvalid()) |
| 5644 | return SemaRef.ExprError(); |
| 5645 | |
| 5646 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5647 | BaseType = ((Expr*) Base.get())->getType(); |
| 5648 | } else { |
| 5649 | OldBase = 0; |
| 5650 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5651 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5652 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5653 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5654 | // Transform the first part of the nested-name-specifier that qualifies |
| 5655 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5656 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5657 | = getDerived().TransformFirstQualifierInScope( |
| 5658 | E->getFirstQualifierFoundInScope(), |
| 5659 | E->getQualifierRange().getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5660 | |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5661 | NestedNameSpecifier *Qualifier = 0; |
| 5662 | if (E->getQualifier()) { |
| 5663 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5664 | E->getQualifierRange(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5665 | ObjectType, |
| 5666 | FirstQualifierInScope); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5667 | if (!Qualifier) |
| 5668 | return SemaRef.ExprError(); |
| 5669 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5670 | |
| 5671 | DeclarationName Name |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5672 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5673 | ObjectType); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5674 | if (!Name) |
| 5675 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5676 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5677 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5678 | // This is a reference to a member without an explicitly-specified |
| 5679 | // template argument list. Optimize for this common case. |
| 5680 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5681 | Base.get() == OldBase && |
| 5682 | BaseType == E->getBaseType() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5683 | Qualifier == E->getQualifier() && |
| 5684 | Name == E->getMember() && |
| 5685 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5686 | return SemaRef.Owned(E->Retain()); |
| 5687 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5688 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5689 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5690 | E->isArrow(), |
| 5691 | E->getOperatorLoc(), |
| 5692 | Qualifier, |
| 5693 | E->getQualifierRange(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5694 | FirstQualifierInScope, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5695 | Name, |
| 5696 | E->getMemberLoc(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5697 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5698 | } |
| 5699 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5700 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5701 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5702 | TemplateArgumentLoc Loc; |
| 5703 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5704 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5705 | TransArgs.addArgument(Loc); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5706 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5707 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5708 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5709 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5710 | E->isArrow(), |
| 5711 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5712 | Qualifier, |
| 5713 | E->getQualifierRange(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5714 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5715 | Name, |
| 5716 | E->getMemberLoc(), |
| 5717 | &TransArgs); |
| 5718 | } |
| 5719 | |
| 5720 | template<typename Derived> |
| 5721 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5722 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5723 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5724 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5725 | QualType BaseType; |
| 5726 | if (!Old->isImplicitAccess()) { |
| 5727 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5728 | if (Base.isInvalid()) |
| 5729 | return SemaRef.ExprError(); |
| 5730 | BaseType = ((Expr*) Base.get())->getType(); |
| 5731 | } else { |
| 5732 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5733 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5734 | |
| 5735 | NestedNameSpecifier *Qualifier = 0; |
| 5736 | if (Old->getQualifier()) { |
| 5737 | Qualifier |
| 5738 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5739 | Old->getQualifierRange()); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5740 | if (Qualifier == 0) |
| 5741 | return SemaRef.ExprError(); |
| 5742 | } |
| 5743 | |
| 5744 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5745 | Sema::LookupOrdinaryName); |
| 5746 | |
| 5747 | // Transform all the decls. |
| 5748 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5749 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5750 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5751 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 5752 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5753 | if (!InstD) { |
| 5754 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5755 | // This can happen because of dependent hiding. |
| 5756 | if (isa<UsingShadowDecl>(*I)) |
| 5757 | continue; |
| 5758 | else |
| 5759 | return SemaRef.ExprError(); |
| 5760 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5761 | |
| 5762 | // Expand using declarations. |
| 5763 | if (isa<UsingDecl>(InstD)) { |
| 5764 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5765 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5766 | E = UD->shadow_end(); I != E; ++I) |
| 5767 | R.addDecl(*I); |
| 5768 | continue; |
| 5769 | } |
| 5770 | |
| 5771 | R.addDecl(InstD); |
| 5772 | } |
| 5773 | |
| 5774 | R.resolveKind(); |
| 5775 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame^] | 5776 | // Determine the naming class. |
| 5777 | if (!Old->getNamingClass()) { |
| 5778 | CXXRecordDecl *NamingClass |
| 5779 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5780 | Old->getMemberLoc(), |
| 5781 | Old->getNamingClass())); |
| 5782 | if (!NamingClass) |
| 5783 | return SemaRef.ExprError(); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame^] | 5784 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5785 | R.setNamingClass(NamingClass); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame^] | 5786 | } |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5787 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5788 | TemplateArgumentListInfo TransArgs; |
| 5789 | if (Old->hasExplicitTemplateArgs()) { |
| 5790 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5791 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5792 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5793 | TemplateArgumentLoc Loc; |
| 5794 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5795 | Loc)) |
| 5796 | return SemaRef.ExprError(); |
| 5797 | TransArgs.addArgument(Loc); |
| 5798 | } |
| 5799 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5800 | |
| 5801 | // FIXME: to do this check properly, we will need to preserve the |
| 5802 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5803 | // base (and therefore couldn't do the check) and a |
| 5804 | // nested-name-qualifier (and therefore could do the lookup). |
| 5805 | NamedDecl *FirstQualifierInScope = 0; |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5806 | |
| 5807 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5808 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5809 | Old->getOperatorLoc(), |
| 5810 | Old->isArrow(), |
| 5811 | Qualifier, |
| 5812 | Old->getQualifierRange(), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5813 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5814 | R, |
| 5815 | (Old->hasExplicitTemplateArgs() |
| 5816 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5817 | } |
| 5818 | |
| 5819 | template<typename Derived> |
| 5820 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5821 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5822 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5823 | } |
| 5824 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5825 | template<typename Derived> |
| 5826 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5827 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5828 | TypeSourceInfo *EncodedTypeInfo |
| 5829 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 5830 | if (!EncodedTypeInfo) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5831 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5832 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5833 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5834 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5835 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5836 | |
| 5837 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5838 | EncodedTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5839 | E->getRParenLoc()); |
| 5840 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5841 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5842 | template<typename Derived> |
| 5843 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5844 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5845 | // Transform arguments. |
| 5846 | bool ArgChanged = false; |
| 5847 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5848 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 5849 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 5850 | if (Arg.isInvalid()) |
| 5851 | return SemaRef.ExprError(); |
| 5852 | |
| 5853 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
| 5854 | Args.push_back(Arg.takeAs<Expr>()); |
| 5855 | } |
| 5856 | |
| 5857 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 5858 | // Class message: transform the receiver type. |
| 5859 | TypeSourceInfo *ReceiverTypeInfo |
| 5860 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 5861 | if (!ReceiverTypeInfo) |
| 5862 | return SemaRef.ExprError(); |
| 5863 | |
| 5864 | // If nothing changed, just retain the existing message send. |
| 5865 | if (!getDerived().AlwaysRebuild() && |
| 5866 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
| 5867 | return SemaRef.Owned(E->Retain()); |
| 5868 | |
| 5869 | // Build a new class message send. |
| 5870 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 5871 | E->getSelector(), |
| 5872 | E->getMethodDecl(), |
| 5873 | E->getLeftLoc(), |
| 5874 | move_arg(Args), |
| 5875 | E->getRightLoc()); |
| 5876 | } |
| 5877 | |
| 5878 | // Instance message: transform the receiver |
| 5879 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 5880 | "Only class and instance messages may be instantiated"); |
| 5881 | OwningExprResult Receiver |
| 5882 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 5883 | if (Receiver.isInvalid()) |
| 5884 | return SemaRef.ExprError(); |
| 5885 | |
| 5886 | // If nothing changed, just retain the existing message send. |
| 5887 | if (!getDerived().AlwaysRebuild() && |
| 5888 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
| 5889 | return SemaRef.Owned(E->Retain()); |
| 5890 | |
| 5891 | // Build a new instance message send. |
| 5892 | return getDerived().RebuildObjCMessageExpr(move(Receiver), |
| 5893 | E->getSelector(), |
| 5894 | E->getMethodDecl(), |
| 5895 | E->getLeftLoc(), |
| 5896 | move_arg(Args), |
| 5897 | E->getRightLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5898 | } |
| 5899 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5900 | template<typename Derived> |
| 5901 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5902 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5903 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5904 | } |
| 5905 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5906 | template<typename Derived> |
| 5907 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5908 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5909 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5910 | } |
| 5911 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5912 | template<typename Derived> |
| 5913 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5914 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 5915 | // Transform the base expression. |
| 5916 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 5917 | if (Base.isInvalid()) |
| 5918 | return SemaRef.ExprError(); |
| 5919 | |
| 5920 | // We don't need to transform the ivar; it will never change. |
| 5921 | |
| 5922 | // If nothing changed, just retain the existing expression. |
| 5923 | if (!getDerived().AlwaysRebuild() && |
| 5924 | Base.get() == E->getBase()) |
| 5925 | return SemaRef.Owned(E->Retain()); |
| 5926 | |
| 5927 | return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(), |
| 5928 | E->getLocation(), |
| 5929 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5930 | } |
| 5931 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5932 | template<typename Derived> |
| 5933 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5934 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 5935 | // Transform the base expression. |
| 5936 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 5937 | if (Base.isInvalid()) |
| 5938 | return SemaRef.ExprError(); |
| 5939 | |
| 5940 | // We don't need to transform the property; it will never change. |
| 5941 | |
| 5942 | // If nothing changed, just retain the existing expression. |
| 5943 | if (!getDerived().AlwaysRebuild() && |
| 5944 | Base.get() == E->getBase()) |
| 5945 | return SemaRef.Owned(E->Retain()); |
| 5946 | |
| 5947 | return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(), |
| 5948 | E->getLocation()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5949 | } |
| 5950 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5951 | template<typename Derived> |
| 5952 | Sema::OwningExprResult |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5953 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5954 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 5955 | // If this implicit setter/getter refers to class methods, it cannot have any |
| 5956 | // dependent parts. Just retain the existing declaration. |
| 5957 | if (E->getInterfaceDecl()) |
| 5958 | return SemaRef.Owned(E->Retain()); |
| 5959 | |
| 5960 | // Transform the base expression. |
| 5961 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 5962 | if (Base.isInvalid()) |
| 5963 | return SemaRef.ExprError(); |
| 5964 | |
| 5965 | // We don't need to transform the getters/setters; they will never change. |
| 5966 | |
| 5967 | // If nothing changed, just retain the existing expression. |
| 5968 | if (!getDerived().AlwaysRebuild() && |
| 5969 | Base.get() == E->getBase()) |
| 5970 | return SemaRef.Owned(E->Retain()); |
| 5971 | |
| 5972 | return getDerived().RebuildObjCImplicitSetterGetterRefExpr( |
| 5973 | E->getGetterMethod(), |
| 5974 | E->getType(), |
| 5975 | E->getSetterMethod(), |
| 5976 | E->getLocation(), |
| 5977 | move(Base)); |
| 5978 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5979 | } |
| 5980 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5981 | template<typename Derived> |
| 5982 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5983 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5984 | // Can never occur in a dependent context. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5985 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5986 | } |
| 5987 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5988 | template<typename Derived> |
| 5989 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5990 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 5991 | // Transform the base expression. |
| 5992 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 5993 | if (Base.isInvalid()) |
| 5994 | return SemaRef.ExprError(); |
| 5995 | |
| 5996 | // If nothing changed, just retain the existing expression. |
| 5997 | if (!getDerived().AlwaysRebuild() && |
| 5998 | Base.get() == E->getBase()) |
| 5999 | return SemaRef.Owned(E->Retain()); |
| 6000 | |
| 6001 | return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(), |
| 6002 | E->isArrow()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6003 | } |
| 6004 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6005 | template<typename Derived> |
| 6006 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6007 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6008 | bool ArgumentChanged = false; |
| 6009 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 6010 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 6011 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 6012 | if (SubExpr.isInvalid()) |
| 6013 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6014 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6015 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 6016 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 6017 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6018 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6019 | if (!getDerived().AlwaysRebuild() && |
| 6020 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6021 | return SemaRef.Owned(E->Retain()); |
| 6022 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6023 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 6024 | move_arg(SubExprs), |
| 6025 | E->getRParenLoc()); |
| 6026 | } |
| 6027 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6028 | template<typename Derived> |
| 6029 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6030 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6031 | // FIXME: Implement this! |
| 6032 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6033 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6034 | } |
| 6035 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6036 | template<typename Derived> |
| 6037 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6038 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6039 | // FIXME: Implement this! |
| 6040 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6041 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6042 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6043 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6044 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6045 | // Type reconstruction |
| 6046 | //===----------------------------------------------------------------------===// |
| 6047 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6048 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6049 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 6050 | SourceLocation Star) { |
| 6051 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6052 | getDerived().getBaseEntity()); |
| 6053 | } |
| 6054 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6055 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6056 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 6057 | SourceLocation Star) { |
| 6058 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6059 | getDerived().getBaseEntity()); |
| 6060 | } |
| 6061 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6062 | template<typename Derived> |
| 6063 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6064 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 6065 | bool WrittenAsLValue, |
| 6066 | SourceLocation Sigil) { |
| 6067 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 6068 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6069 | } |
| 6070 | |
| 6071 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6072 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6073 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 6074 | QualType ClassType, |
| 6075 | SourceLocation Sigil) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 6076 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6077 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6078 | } |
| 6079 | |
| 6080 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6081 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6082 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 6083 | ArrayType::ArraySizeModifier SizeMod, |
| 6084 | const llvm::APInt *Size, |
| 6085 | Expr *SizeExpr, |
| 6086 | unsigned IndexTypeQuals, |
| 6087 | SourceRange BracketsRange) { |
| 6088 | if (SizeExpr || !Size) |
| 6089 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 6090 | IndexTypeQuals, BracketsRange, |
| 6091 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6092 | |
| 6093 | QualType Types[] = { |
| 6094 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 6095 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 6096 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6097 | }; |
| 6098 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 6099 | QualType SizeType; |
| 6100 | for (unsigned I = 0; I != NumTypes; ++I) |
| 6101 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 6102 | SizeType = Types[I]; |
| 6103 | break; |
| 6104 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6105 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6106 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6107 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6108 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6109 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6110 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6111 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6112 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6113 | QualType |
| 6114 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6115 | ArrayType::ArraySizeModifier SizeMod, |
| 6116 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6117 | unsigned IndexTypeQuals, |
| 6118 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6119 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6120 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6121 | } |
| 6122 | |
| 6123 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6124 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6125 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6126 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6127 | unsigned IndexTypeQuals, |
| 6128 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6129 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6130 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6131 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6132 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6133 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6134 | QualType |
| 6135 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6136 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6137 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6138 | unsigned IndexTypeQuals, |
| 6139 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6140 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6141 | SizeExpr.takeAs<Expr>(), |
| 6142 | IndexTypeQuals, BracketsRange); |
| 6143 | } |
| 6144 | |
| 6145 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6146 | QualType |
| 6147 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6148 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6149 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6150 | unsigned IndexTypeQuals, |
| 6151 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6152 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6153 | SizeExpr.takeAs<Expr>(), |
| 6154 | IndexTypeQuals, BracketsRange); |
| 6155 | } |
| 6156 | |
| 6157 | template<typename Derived> |
| 6158 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 6159 | unsigned NumElements, |
| 6160 | bool IsAltiVec, bool IsPixel) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6161 | // FIXME: semantic checking! |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 6162 | return SemaRef.Context.getVectorType(ElementType, NumElements, |
| 6163 | IsAltiVec, IsPixel); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6164 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6165 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6166 | template<typename Derived> |
| 6167 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 6168 | unsigned NumElements, |
| 6169 | SourceLocation AttributeLoc) { |
| 6170 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 6171 | NumElements, true); |
| 6172 | IntegerLiteral *VectorSize |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6173 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6174 | AttributeLoc); |
| 6175 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 6176 | AttributeLoc); |
| 6177 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6178 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6179 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6180 | QualType |
| 6181 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6182 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6183 | SourceLocation AttributeLoc) { |
| 6184 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 6185 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6186 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6187 | template<typename Derived> |
| 6188 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6189 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6190 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6191 | bool Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6192 | unsigned Quals) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6193 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6194 | Quals, |
| 6195 | getDerived().getBaseLocation(), |
| 6196 | getDerived().getBaseEntity()); |
| 6197 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6198 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6199 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6200 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 6201 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 6202 | } |
| 6203 | |
| 6204 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6205 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 6206 | assert(D && "no decl found"); |
| 6207 | if (D->isInvalidDecl()) return QualType(); |
| 6208 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6209 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6210 | TypeDecl *Ty; |
| 6211 | if (isa<UsingDecl>(D)) { |
| 6212 | UsingDecl *Using = cast<UsingDecl>(D); |
| 6213 | assert(Using->isTypeName() && |
| 6214 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 6215 | |
| 6216 | // A valid resolved using typename decl points to exactly one type decl. |
| 6217 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 6218 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 6219 | |
| 6220 | } else { |
| 6221 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 6222 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 6223 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 6224 | } |
| 6225 | |
| 6226 | return SemaRef.Context.getTypeDeclType(Ty); |
| 6227 | } |
| 6228 | |
| 6229 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6230 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6231 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 6232 | } |
| 6233 | |
| 6234 | template<typename Derived> |
| 6235 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 6236 | return SemaRef.Context.getTypeOfType(Underlying); |
| 6237 | } |
| 6238 | |
| 6239 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6240 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6241 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 6242 | } |
| 6243 | |
| 6244 | template<typename Derived> |
| 6245 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6246 | TemplateName Template, |
| 6247 | SourceLocation TemplateNameLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6248 | const TemplateArgumentListInfo &TemplateArgs) { |
| 6249 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6250 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6251 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6252 | template<typename Derived> |
| 6253 | NestedNameSpecifier * |
| 6254 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6255 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6256 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6257 | QualType ObjectType, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6258 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6259 | CXXScopeSpec SS; |
| 6260 | // FIXME: The source location information is all wrong. |
| 6261 | SS.setRange(Range); |
| 6262 | SS.setScopeRep(Prefix); |
| 6263 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6264 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 6265 | Range.getEnd(), II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6266 | ObjectType, |
| 6267 | FirstQualifierInScope, |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 6268 | false, false)); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6269 | } |
| 6270 | |
| 6271 | template<typename Derived> |
| 6272 | NestedNameSpecifier * |
| 6273 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6274 | SourceRange Range, |
| 6275 | NamespaceDecl *NS) { |
| 6276 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 6277 | } |
| 6278 | |
| 6279 | template<typename Derived> |
| 6280 | NestedNameSpecifier * |
| 6281 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6282 | SourceRange Range, |
| 6283 | bool TemplateKW, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 6284 | QualType T) { |
| 6285 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6286 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 6287 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6288 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 6289 | T.getTypePtr()); |
| 6290 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6291 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6292 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 6293 | return 0; |
| 6294 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6295 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6296 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6297 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6298 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6299 | bool TemplateKW, |
| 6300 | TemplateDecl *Template) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6301 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6302 | Template); |
| 6303 | } |
| 6304 | |
| 6305 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6306 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6307 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6308 | const IdentifierInfo &II, |
| 6309 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6310 | CXXScopeSpec SS; |
| 6311 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6312 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 6313 | UnqualifiedId Name; |
| 6314 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6315 | return getSema().ActOnDependentTemplateName( |
| 6316 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6317 | SS, |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 6318 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 6319 | ObjectType.getAsOpaquePtr(), |
| 6320 | /*EnteringContext=*/false) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6321 | .template getAsVal<TemplateName>(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6322 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6323 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6324 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6325 | TemplateName |
| 6326 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6327 | OverloadedOperatorKind Operator, |
| 6328 | QualType ObjectType) { |
| 6329 | CXXScopeSpec SS; |
| 6330 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 6331 | SS.setScopeRep(Qualifier); |
| 6332 | UnqualifiedId Name; |
| 6333 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 6334 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 6335 | Operator, SymbolLocations); |
| 6336 | return getSema().ActOnDependentTemplateName( |
| 6337 | /*FIXME:*/getDerived().getBaseLocation(), |
| 6338 | SS, |
| 6339 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 6340 | ObjectType.getAsOpaquePtr(), |
| 6341 | /*EnteringContext=*/false) |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6342 | .template getAsVal<TemplateName>(); |
| 6343 | } |
| 6344 | |
| 6345 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6346 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6347 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 6348 | SourceLocation OpLoc, |
| 6349 | ExprArg Callee, |
| 6350 | ExprArg First, |
| 6351 | ExprArg Second) { |
| 6352 | Expr *FirstExpr = (Expr *)First.get(); |
| 6353 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6354 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6355 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6356 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6357 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6358 | if (Op == OO_Subscript) { |
| 6359 | if (!FirstExpr->getType()->isOverloadableType() && |
| 6360 | !SecondExpr->getType()->isOverloadableType()) |
| 6361 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6362 | CalleeExpr->getLocStart(), |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6363 | move(Second), OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 6364 | } else if (Op == OO_Arrow) { |
| 6365 | // -> is never a builtin operation. |
| 6366 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6367 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6368 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 6369 | // The argument is not of overloadable type, so try to create a |
| 6370 | // built-in unary operation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6371 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6372 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6373 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6374 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 6375 | } |
| 6376 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6377 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6378 | !SecondExpr->getType()->isOverloadableType()) { |
| 6379 | // Neither of the arguments is an overloadable type, so try to |
| 6380 | // create a built-in binary operation. |
| 6381 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6382 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6383 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 6384 | if (Result.isInvalid()) |
| 6385 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6386 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6387 | First.release(); |
| 6388 | Second.release(); |
| 6389 | return move(Result); |
| 6390 | } |
| 6391 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6392 | |
| 6393 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6394 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6395 | UnresolvedSet<16> Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6396 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6397 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 6398 | assert(ULE->requiresADL()); |
| 6399 | |
| 6400 | // FIXME: Do we have to check |
| 6401 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6402 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6403 | } else { |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6404 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6405 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6406 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6407 | // Add any functions found via argument-dependent lookup. |
| 6408 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 6409 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6410 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6411 | // Create the overloaded operator invocation for unary operators. |
| 6412 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6413 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6414 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 6415 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 6416 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6417 | |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6418 | if (Op == OO_Subscript) |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6419 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 6420 | OpLoc, |
| 6421 | move(First), |
| 6422 | move(Second)); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6423 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6424 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6425 | BinaryOperator::Opcode Opc = |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6426 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6427 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6428 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 6429 | if (Result.isInvalid()) |
| 6430 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6431 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6432 | First.release(); |
| 6433 | Second.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6434 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6435 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6436 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6437 | template<typename Derived> |
| 6438 | Sema::OwningExprResult |
| 6439 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 6440 | SourceLocation OperatorLoc, |
| 6441 | bool isArrow, |
| 6442 | NestedNameSpecifier *Qualifier, |
| 6443 | SourceRange QualifierRange, |
| 6444 | TypeSourceInfo *ScopeType, |
| 6445 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6446 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6447 | PseudoDestructorTypeStorage Destroyed) { |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6448 | CXXScopeSpec SS; |
| 6449 | if (Qualifier) { |
| 6450 | SS.setRange(QualifierRange); |
| 6451 | SS.setScopeRep(Qualifier); |
| 6452 | } |
| 6453 | |
| 6454 | Expr *BaseE = (Expr *)Base.get(); |
| 6455 | QualType BaseType = BaseE->getType(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6456 | if (BaseE->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6457 | (!isArrow && !BaseType->getAs<RecordType>()) || |
| 6458 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | bf2ca2f | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 6459 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 6460 | ->template getAs<RecordType>())){ |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6461 | // This pseudo-destructor expression is still a pseudo-destructor. |
| 6462 | return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc, |
| 6463 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6464 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6465 | Destroyed, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6466 | /*FIXME?*/true); |
| 6467 | } |
| 6468 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6469 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6470 | DeclarationName Name |
| 6471 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 6472 | SemaRef.Context.getCanonicalType(DestroyedType->getType())); |
| 6473 | |
| 6474 | // FIXME: the ScopeType should be tacked onto SS. |
| 6475 | |
| 6476 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 6477 | OperatorLoc, isArrow, |
| 6478 | SS, /*FIXME: FirstQualifier*/ 0, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6479 | Name, Destroyed.getLocation(), |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6480 | /*TemplateArgs*/ 0); |
| 6481 | } |
| 6482 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6483 | } // end namespace clang |
| 6484 | |
| 6485 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |