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: |
| 577 | // FIXME: Note the lack of the "typename" specifier! |
| 578 | // Fall through |
| 579 | case ETK_Typename: |
| 580 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
| 581 | |
| 582 | case ETK_Class: Kind = TagDecl::TK_class; break; |
| 583 | case ETK_Struct: Kind = TagDecl::TK_struct; break; |
| 584 | case ETK_Union: Kind = TagDecl::TK_union; break; |
| 585 | case ETK_Enum: Kind = TagDecl::TK_enum; break; |
| 586 | } |
| 587 | |
| 588 | // We had a dependent elaborated-type-specifier that as been transformed |
| 589 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 590 | // referring to. |
| 591 | LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName); |
| 592 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 593 | if (!DC) |
| 594 | return QualType(); |
| 595 | |
| 596 | TagDecl *Tag = 0; |
| 597 | SemaRef.LookupQualifiedName(Result, DC); |
| 598 | switch (Result.getResultKind()) { |
| 599 | case LookupResult::NotFound: |
| 600 | case LookupResult::NotFoundInCurrentInstantiation: |
| 601 | break; |
| 602 | |
| 603 | case LookupResult::Found: |
| 604 | Tag = Result.getAsSingle<TagDecl>(); |
| 605 | break; |
| 606 | |
| 607 | case LookupResult::FoundOverloaded: |
| 608 | case LookupResult::FoundUnresolvedValue: |
| 609 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 610 | return QualType(); |
| 611 | |
| 612 | case LookupResult::Ambiguous: |
| 613 | // Let the LookupResult structure handle ambiguities. |
| 614 | return QualType(); |
| 615 | } |
| 616 | |
| 617 | if (!Tag) { |
Douglas Gregor | 1eabb7d | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 618 | // FIXME: Would be nice to highlight just the source range. |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 619 | SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope) |
Douglas Gregor | 1eabb7d | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 620 | << Kind << Id << DC; |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 621 | return QualType(); |
| 622 | } |
| 623 | |
| 624 | // FIXME: Terrible location information |
| 625 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) { |
| 626 | SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id; |
| 627 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 628 | return QualType(); |
| 629 | } |
| 630 | |
| 631 | // Build the elaborated-type-specifier type. |
| 632 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
| 633 | T = SemaRef.Context.getQualifiedNameType(NNS, T); |
| 634 | return SemaRef.Context.getElaboratedType(T, Kind); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 635 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 636 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 637 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 638 | /// identifier that names the next step in the nested-name-specifier. |
| 639 | /// |
| 640 | /// By default, performs semantic analysis when building the new |
| 641 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 642 | /// different behavior. |
| 643 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 644 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 645 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 646 | QualType ObjectType, |
| 647 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 648 | |
| 649 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 650 | /// namespace named in the next step in the nested-name-specifier. |
| 651 | /// |
| 652 | /// By default, performs semantic analysis when building the new |
| 653 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 654 | /// different behavior. |
| 655 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 656 | SourceRange Range, |
| 657 | NamespaceDecl *NS); |
| 658 | |
| 659 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 660 | /// type named in the next step in the nested-name-specifier. |
| 661 | /// |
| 662 | /// By default, performs semantic analysis when building the new |
| 663 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 664 | /// different behavior. |
| 665 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 666 | SourceRange Range, |
| 667 | bool TemplateKW, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 668 | QualType T); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 669 | |
| 670 | /// \brief Build a new template name given a nested name specifier, a flag |
| 671 | /// indicating whether the "template" keyword was provided, and the template |
| 672 | /// that the template name refers to. |
| 673 | /// |
| 674 | /// By default, builds the new template name directly. Subclasses may override |
| 675 | /// this routine to provide different behavior. |
| 676 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 677 | bool TemplateKW, |
| 678 | TemplateDecl *Template); |
| 679 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 680 | /// \brief Build a new template name given a nested name specifier and the |
| 681 | /// name that is referred to as a template. |
| 682 | /// |
| 683 | /// By default, performs semantic analysis to determine whether the name can |
| 684 | /// be resolved to a specific template, then builds the appropriate kind of |
| 685 | /// template name. Subclasses may override this routine to provide different |
| 686 | /// behavior. |
| 687 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 688 | const IdentifierInfo &II, |
| 689 | QualType ObjectType); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 690 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 691 | /// \brief Build a new template name given a nested name specifier and the |
| 692 | /// overloaded operator name that is referred to as a template. |
| 693 | /// |
| 694 | /// By default, performs semantic analysis to determine whether the name can |
| 695 | /// be resolved to a specific template, then builds the appropriate kind of |
| 696 | /// template name. Subclasses may override this routine to provide different |
| 697 | /// behavior. |
| 698 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 699 | OverloadedOperatorKind Operator, |
| 700 | QualType ObjectType); |
| 701 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 702 | /// \brief Build a new compound statement. |
| 703 | /// |
| 704 | /// By default, performs semantic analysis to build the new statement. |
| 705 | /// Subclasses may override this routine to provide different behavior. |
| 706 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 707 | MultiStmtArg Statements, |
| 708 | SourceLocation RBraceLoc, |
| 709 | bool IsStmtExpr) { |
| 710 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 711 | IsStmtExpr); |
| 712 | } |
| 713 | |
| 714 | /// \brief Build a new case statement. |
| 715 | /// |
| 716 | /// By default, performs semantic analysis to build the new statement. |
| 717 | /// Subclasses may override this routine to provide different behavior. |
| 718 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 719 | ExprArg LHS, |
| 720 | SourceLocation EllipsisLoc, |
| 721 | ExprArg RHS, |
| 722 | SourceLocation ColonLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 723 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 724 | ColonLoc); |
| 725 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 726 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 727 | /// \brief Attach the body to a new case statement. |
| 728 | /// |
| 729 | /// By default, performs semantic analysis to build the new statement. |
| 730 | /// Subclasses may override this routine to provide different behavior. |
| 731 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 732 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 733 | return move(S); |
| 734 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 735 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 736 | /// \brief Build a new default statement. |
| 737 | /// |
| 738 | /// By default, performs semantic analysis to build the new statement. |
| 739 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 740 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 741 | SourceLocation ColonLoc, |
| 742 | StmtArg SubStmt) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 743 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 744 | /*CurScope=*/0); |
| 745 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 746 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 747 | /// \brief Build a new label statement. |
| 748 | /// |
| 749 | /// By default, performs semantic analysis to build the new statement. |
| 750 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 751 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 752 | IdentifierInfo *Id, |
| 753 | SourceLocation ColonLoc, |
| 754 | StmtArg SubStmt) { |
| 755 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 756 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 757 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 758 | /// \brief Build a new "if" statement. |
| 759 | /// |
| 760 | /// By default, performs semantic analysis to build the new statement. |
| 761 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 762 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 763 | VarDecl *CondVar, StmtArg Then, |
| 764 | SourceLocation ElseLoc, StmtArg Else) { |
| 765 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
| 766 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 767 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 768 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 769 | /// \brief Start building a new switch statement. |
| 770 | /// |
| 771 | /// By default, performs semantic analysis to build the new statement. |
| 772 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 773 | OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond, |
| 774 | VarDecl *CondVar) { |
| 775 | return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 776 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 777 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 778 | /// \brief Attach the body to the switch statement. |
| 779 | /// |
| 780 | /// By default, performs semantic analysis to build the new statement. |
| 781 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 782 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 783 | StmtArg Switch, StmtArg Body) { |
| 784 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 785 | move(Body)); |
| 786 | } |
| 787 | |
| 788 | /// \brief Build a new while statement. |
| 789 | /// |
| 790 | /// By default, performs semantic analysis to build the new statement. |
| 791 | /// Subclasses may override this routine to provide different behavior. |
| 792 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 793 | Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 794 | VarDecl *CondVar, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 795 | StmtArg Body) { |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 796 | return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar), |
| 797 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 798 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 799 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 800 | /// \brief Build a new do-while statement. |
| 801 | /// |
| 802 | /// By default, performs semantic analysis to build the new statement. |
| 803 | /// Subclasses may override this routine to provide different behavior. |
| 804 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 805 | SourceLocation WhileLoc, |
| 806 | SourceLocation LParenLoc, |
| 807 | ExprArg Cond, |
| 808 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 809 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 810 | move(Cond), RParenLoc); |
| 811 | } |
| 812 | |
| 813 | /// \brief Build a new for statement. |
| 814 | /// |
| 815 | /// By default, performs semantic analysis to build the new statement. |
| 816 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 817 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 818 | SourceLocation LParenLoc, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 819 | StmtArg Init, Sema::FullExprArg Cond, |
| 820 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 821 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 822 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
| 823 | DeclPtrTy::make(CondVar), |
| 824 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 825 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 826 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 827 | /// \brief Build a new goto statement. |
| 828 | /// |
| 829 | /// By default, performs semantic analysis to build the new statement. |
| 830 | /// Subclasses may override this routine to provide different behavior. |
| 831 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 832 | SourceLocation LabelLoc, |
| 833 | LabelStmt *Label) { |
| 834 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 835 | } |
| 836 | |
| 837 | /// \brief Build a new indirect goto statement. |
| 838 | /// |
| 839 | /// By default, performs semantic analysis to build the new statement. |
| 840 | /// Subclasses may override this routine to provide different behavior. |
| 841 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 842 | SourceLocation StarLoc, |
| 843 | ExprArg Target) { |
| 844 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 845 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 846 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 847 | /// \brief Build a new return statement. |
| 848 | /// |
| 849 | /// By default, performs semantic analysis to build the new statement. |
| 850 | /// Subclasses may override this routine to provide different behavior. |
| 851 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 852 | ExprArg Result) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 853 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 854 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 855 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 856 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 857 | /// \brief Build a new declaration statement. |
| 858 | /// |
| 859 | /// By default, performs semantic analysis to build the new statement. |
| 860 | /// Subclasses may override this routine to provide different behavior. |
| 861 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 862 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 863 | SourceLocation EndLoc) { |
| 864 | return getSema().Owned( |
| 865 | new (getSema().Context) DeclStmt( |
| 866 | DeclGroupRef::Create(getSema().Context, |
| 867 | Decls, NumDecls), |
| 868 | StartLoc, EndLoc)); |
| 869 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 870 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 871 | /// \brief Build a new inline asm statement. |
| 872 | /// |
| 873 | /// By default, performs semantic analysis to build the new statement. |
| 874 | /// Subclasses may override this routine to provide different behavior. |
| 875 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 876 | bool IsSimple, |
| 877 | bool IsVolatile, |
| 878 | unsigned NumOutputs, |
| 879 | unsigned NumInputs, |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 880 | IdentifierInfo **Names, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 881 | MultiExprArg Constraints, |
| 882 | MultiExprArg Exprs, |
| 883 | ExprArg AsmString, |
| 884 | MultiExprArg Clobbers, |
| 885 | SourceLocation RParenLoc, |
| 886 | bool MSAsm) { |
| 887 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 888 | NumInputs, Names, move(Constraints), |
| 889 | move(Exprs), move(AsmString), move(Clobbers), |
| 890 | RParenLoc, MSAsm); |
| 891 | } |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame^] | 892 | |
| 893 | /// \brief Build a new Objective-C @try statement. |
| 894 | /// |
| 895 | /// By default, performs semantic analysis to build the new statement. |
| 896 | /// Subclasses may override this routine to provide different behavior. |
| 897 | OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
| 898 | StmtArg TryBody, |
| 899 | StmtArg Catch, |
| 900 | StmtArg Finally) { |
| 901 | return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(Catch), |
| 902 | move(Finally)); |
| 903 | } |
| 904 | |
| 905 | /// \brief Build a new Objective-C @finally statement. |
| 906 | /// |
| 907 | /// By default, performs semantic analysis to build the new statement. |
| 908 | /// Subclasses may override this routine to provide different behavior. |
| 909 | OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
| 910 | StmtArg Body) { |
| 911 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body)); |
| 912 | } |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 913 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 914 | /// \brief Build a new Objective-C @throw statement. |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 915 | /// |
| 916 | /// By default, performs semantic analysis to build the new statement. |
| 917 | /// Subclasses may override this routine to provide different behavior. |
| 918 | OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
| 919 | ExprArg Operand) { |
| 920 | return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand)); |
| 921 | } |
| 922 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 923 | /// \brief Build a new Objective-C @synchronized statement. |
| 924 | /// |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 925 | /// By default, performs semantic analysis to build the new statement. |
| 926 | /// Subclasses may override this routine to provide different behavior. |
| 927 | OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
| 928 | ExprArg Object, |
| 929 | StmtArg Body) { |
| 930 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object), |
| 931 | move(Body)); |
| 932 | } |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 933 | |
| 934 | /// \brief Build a new Objective-C fast enumeration statement. |
| 935 | /// |
| 936 | /// By default, performs semantic analysis to build the new statement. |
| 937 | /// Subclasses may override this routine to provide different behavior. |
| 938 | OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
| 939 | SourceLocation LParenLoc, |
| 940 | StmtArg Element, |
| 941 | ExprArg Collection, |
| 942 | SourceLocation RParenLoc, |
| 943 | StmtArg Body) { |
| 944 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
| 945 | move(Element), |
| 946 | move(Collection), |
| 947 | RParenLoc, |
| 948 | move(Body)); |
| 949 | } |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 950 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 951 | /// \brief Build a new C++ exception declaration. |
| 952 | /// |
| 953 | /// By default, performs semantic analysis to build the new decaration. |
| 954 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 955 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 956 | TypeSourceInfo *Declarator, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 957 | IdentifierInfo *Name, |
| 958 | SourceLocation Loc, |
| 959 | SourceRange TypeRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 960 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 961 | TypeRange); |
| 962 | } |
| 963 | |
| 964 | /// \brief Build a new C++ catch statement. |
| 965 | /// |
| 966 | /// By default, performs semantic analysis to build the new statement. |
| 967 | /// Subclasses may override this routine to provide different behavior. |
| 968 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 969 | VarDecl *ExceptionDecl, |
| 970 | StmtArg Handler) { |
| 971 | return getSema().Owned( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 972 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 973 | Handler.takeAs<Stmt>())); |
| 974 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 975 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 976 | /// \brief Build a new C++ try statement. |
| 977 | /// |
| 978 | /// By default, performs semantic analysis to build the new statement. |
| 979 | /// Subclasses may override this routine to provide different behavior. |
| 980 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 981 | StmtArg TryBlock, |
| 982 | MultiStmtArg Handlers) { |
| 983 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 984 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 985 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 986 | /// \brief Build a new expression that references a declaration. |
| 987 | /// |
| 988 | /// By default, performs semantic analysis to build the new expression. |
| 989 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 990 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 991 | LookupResult &R, |
| 992 | bool RequiresADL) { |
| 993 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 994 | } |
| 995 | |
| 996 | |
| 997 | /// \brief Build a new expression that references a declaration. |
| 998 | /// |
| 999 | /// By default, performs semantic analysis to build the new expression. |
| 1000 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1001 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 1002 | SourceRange QualifierRange, |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1003 | ValueDecl *VD, SourceLocation Loc, |
| 1004 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1005 | CXXScopeSpec SS; |
| 1006 | SS.setScopeRep(Qualifier); |
| 1007 | SS.setRange(QualifierRange); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1008 | |
| 1009 | // FIXME: loses template args. |
| 1010 | |
| 1011 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1012 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1013 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1014 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1015 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1016 | /// By default, performs semantic analysis to build the new expression. |
| 1017 | /// Subclasses may override this routine to provide different behavior. |
| 1018 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 1019 | SourceLocation RParen) { |
| 1020 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 1021 | } |
| 1022 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1023 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1024 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1025 | /// By default, performs semantic analysis to build the new expression. |
| 1026 | /// Subclasses may override this routine to provide different behavior. |
| 1027 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 1028 | SourceLocation OperatorLoc, |
| 1029 | bool isArrow, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1030 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 1031 | SourceRange QualifierRange, |
| 1032 | TypeSourceInfo *ScopeType, |
| 1033 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 1034 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1035 | PseudoDestructorTypeStorage Destroyed); |
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 unary operator expression. |
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 RebuildUnaryOperator(SourceLocation OpLoc, |
| 1042 | UnaryOperator::Opcode Opc, |
| 1043 | ExprArg SubExpr) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1044 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1045 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1046 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1047 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1048 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1049 | /// By default, performs semantic analysis to build the new expression. |
| 1050 | /// Subclasses may override this routine to provide different behavior. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1051 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 1052 | SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1053 | bool isSizeOf, SourceRange R) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1054 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1057 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1058 | /// argument. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1061 | /// Subclasses may override this routine to provide different behavior. |
| 1062 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 1063 | bool isSizeOf, SourceRange R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1064 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1065 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 1066 | OpLoc, isSizeOf, R); |
| 1067 | if (Result.isInvalid()) |
| 1068 | return getSema().ExprError(); |
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 | SubExpr.release(); |
| 1071 | return move(Result); |
| 1072 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1073 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1074 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1075 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1076 | /// By default, performs semantic analysis to build the new expression. |
| 1077 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1078 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1079 | SourceLocation LBracketLoc, |
| 1080 | ExprArg RHS, |
| 1081 | SourceLocation RBracketLoc) { |
| 1082 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1083 | LBracketLoc, move(RHS), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1084 | RBracketLoc); |
| 1085 | } |
| 1086 | |
| 1087 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1088 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1089 | /// By default, performs semantic analysis to build the new expression. |
| 1090 | /// Subclasses may override this routine to provide different behavior. |
| 1091 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 1092 | MultiExprArg Args, |
| 1093 | SourceLocation *CommaLocs, |
| 1094 | SourceLocation RParenLoc) { |
| 1095 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 1096 | move(Args), CommaLocs, RParenLoc); |
| 1097 | } |
| 1098 | |
| 1099 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1100 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1101 | /// By default, performs semantic analysis to build the new expression. |
| 1102 | /// Subclasses may override this routine to provide different behavior. |
| 1103 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1104 | bool isArrow, |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1105 | NestedNameSpecifier *Qualifier, |
| 1106 | SourceRange QualifierRange, |
| 1107 | SourceLocation MemberLoc, |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 1108 | ValueDecl *Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1109 | NamedDecl *FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1110 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 1111 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1112 | if (!Member->getDeclName()) { |
| 1113 | // We have a reference to an unnamed field. |
| 1114 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1115 | |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1116 | Expr *BaseExpr = Base.takeAs<Expr>(); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1117 | if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, |
| 1118 | FoundDecl, Member)) |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1119 | return getSema().ExprError(); |
Douglas Gregor | 8aa5f40 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 1120 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1121 | MemberExpr *ME = |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1122 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1123 | Member, MemberLoc, |
| 1124 | cast<FieldDecl>(Member)->getType()); |
| 1125 | return getSema().Owned(ME); |
| 1126 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1127 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1128 | CXXScopeSpec SS; |
| 1129 | if (Qualifier) { |
| 1130 | SS.setRange(QualifierRange); |
| 1131 | SS.setScopeRep(Qualifier); |
| 1132 | } |
| 1133 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1134 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1135 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1136 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1137 | // cases; we should avoid this when possible. |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1138 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 1139 | Sema::LookupMemberName); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1140 | R.addDecl(FoundDecl); |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1141 | R.resolveKind(); |
| 1142 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1143 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 1144 | OpLoc, isArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1145 | SS, FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1146 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1147 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1148 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1149 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1150 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1151 | /// By default, performs semantic analysis to build the new expression. |
| 1152 | /// Subclasses may override this routine to provide different behavior. |
| 1153 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1154 | BinaryOperator::Opcode Opc, |
| 1155 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1156 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 1157 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1161 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1162 | /// By default, performs semantic analysis to build the new expression. |
| 1163 | /// Subclasses may override this routine to provide different behavior. |
| 1164 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1165 | SourceLocation QuestionLoc, |
| 1166 | ExprArg LHS, |
| 1167 | SourceLocation ColonLoc, |
| 1168 | ExprArg RHS) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1169 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1170 | move(LHS), move(RHS)); |
| 1171 | } |
| 1172 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1173 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1174 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1175 | /// By default, performs semantic analysis to build the new expression. |
| 1176 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1177 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1178 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1179 | SourceLocation RParenLoc, |
| 1180 | ExprArg SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1181 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1182 | move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1183 | } |
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 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1186 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1187 | /// By default, performs semantic analysis to build the new expression. |
| 1188 | /// Subclasses may override this routine to provide different behavior. |
| 1189 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1190 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1191 | SourceLocation RParenLoc, |
| 1192 | ExprArg Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1193 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1194 | move(Init)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1195 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1196 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1197 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1198 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1199 | /// By default, performs semantic analysis to build the new expression. |
| 1200 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1201 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1202 | SourceLocation OpLoc, |
| 1203 | SourceLocation AccessorLoc, |
| 1204 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1205 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1206 | CXXScopeSpec SS; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1207 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1208 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1209 | OpLoc, /*IsArrow*/ false, |
| 1210 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1211 | DeclarationName(&Accessor), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1212 | AccessorLoc, |
| 1213 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1214 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1215 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1216 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1217 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1218 | /// By default, performs semantic analysis to build the new expression. |
| 1219 | /// Subclasses may override this routine to provide different behavior. |
| 1220 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1221 | MultiExprArg Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1222 | SourceLocation RBraceLoc, |
| 1223 | QualType ResultTy) { |
| 1224 | OwningExprResult Result |
| 1225 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1226 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1227 | return move(Result); |
| 1228 | |
| 1229 | // Patch in the result type we were given, which may have been computed |
| 1230 | // when the initial InitListExpr was built. |
| 1231 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1232 | ILE->setType(ResultTy); |
| 1233 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1234 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1235 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1236 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1237 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1238 | /// By default, performs semantic analysis to build the new expression. |
| 1239 | /// Subclasses may override this routine to provide different behavior. |
| 1240 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1241 | MultiExprArg ArrayExprs, |
| 1242 | SourceLocation EqualOrColonLoc, |
| 1243 | bool GNUSyntax, |
| 1244 | ExprArg Init) { |
| 1245 | OwningExprResult Result |
| 1246 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1247 | move(Init)); |
| 1248 | if (Result.isInvalid()) |
| 1249 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1250 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1251 | ArrayExprs.release(); |
| 1252 | return move(Result); |
| 1253 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1254 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1255 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1256 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1257 | /// By default, builds the implicit value initialization without performing |
| 1258 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1259 | /// different behavior. |
| 1260 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1261 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1262 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1263 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1264 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1265 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1266 | /// By default, performs semantic analysis to build the new expression. |
| 1267 | /// Subclasses may override this routine to provide different behavior. |
| 1268 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1269 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1270 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1271 | RParenLoc); |
| 1272 | } |
| 1273 | |
| 1274 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1275 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1276 | /// By default, performs semantic analysis to build the new expression. |
| 1277 | /// Subclasses may override this routine to provide different behavior. |
| 1278 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1279 | MultiExprArg SubExprs, |
| 1280 | SourceLocation RParenLoc) { |
Fariborz Jahanian | f88f7ab | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1281 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1282 | move(SubExprs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1283 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1284 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1285 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1286 | /// |
| 1287 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1288 | /// rather than attempting to map the label statement itself. |
| 1289 | /// Subclasses may override this routine to provide different behavior. |
| 1290 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1291 | SourceLocation LabelLoc, |
| 1292 | LabelStmt *Label) { |
| 1293 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1294 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1295 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1296 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1297 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1298 | /// By default, performs semantic analysis to build the new expression. |
| 1299 | /// Subclasses may override this routine to provide different behavior. |
| 1300 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1301 | StmtArg SubStmt, |
| 1302 | SourceLocation RParenLoc) { |
| 1303 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1304 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1305 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1306 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1307 | /// |
| 1308 | /// By default, performs semantic analysis to build the new expression. |
| 1309 | /// Subclasses may override this routine to provide different behavior. |
| 1310 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1311 | QualType T1, QualType T2, |
| 1312 | SourceLocation RParenLoc) { |
| 1313 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1314 | T1.getAsOpaquePtr(), |
| 1315 | T2.getAsOpaquePtr(), |
| 1316 | RParenLoc); |
| 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 __builtin_choose_expr expression. |
| 1320 | /// |
| 1321 | /// By default, performs semantic analysis to build the new expression. |
| 1322 | /// Subclasses may override this routine to provide different behavior. |
| 1323 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1324 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1325 | SourceLocation RParenLoc) { |
| 1326 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1327 | move(Cond), move(LHS), move(RHS), |
| 1328 | RParenLoc); |
| 1329 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1330 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1331 | /// \brief Build a new overloaded operator call expression. |
| 1332 | /// |
| 1333 | /// By default, performs semantic analysis to build the new expression. |
| 1334 | /// The semantic analysis provides the behavior of template instantiation, |
| 1335 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1336 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1337 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1338 | /// provide different behavior. |
| 1339 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1340 | SourceLocation OpLoc, |
| 1341 | ExprArg Callee, |
| 1342 | ExprArg First, |
| 1343 | ExprArg Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1344 | |
| 1345 | /// \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] | 1346 | /// reinterpret_cast. |
| 1347 | /// |
| 1348 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1349 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1350 | /// Subclasses may override this routine to provide different behavior. |
| 1351 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1352 | Stmt::StmtClass Class, |
| 1353 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1354 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1355 | SourceLocation RAngleLoc, |
| 1356 | SourceLocation LParenLoc, |
| 1357 | ExprArg SubExpr, |
| 1358 | SourceLocation RParenLoc) { |
| 1359 | switch (Class) { |
| 1360 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1361 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1362 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1363 | move(SubExpr), RParenLoc); |
| 1364 | |
| 1365 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1366 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1367 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1368 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1369 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1370 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1371 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1372 | RAngleLoc, LParenLoc, |
| 1373 | move(SubExpr), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1374 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1375 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1376 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1377 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1378 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1379 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1380 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1381 | default: |
| 1382 | assert(false && "Invalid C++ named cast"); |
| 1383 | break; |
| 1384 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1385 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1386 | return getSema().ExprError(); |
| 1387 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1388 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1389 | /// \brief Build a new C++ static_cast expression. |
| 1390 | /// |
| 1391 | /// By default, performs semantic analysis to build the new expression. |
| 1392 | /// Subclasses may override this routine to provide different behavior. |
| 1393 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1394 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1395 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1396 | SourceLocation RAngleLoc, |
| 1397 | SourceLocation LParenLoc, |
| 1398 | ExprArg SubExpr, |
| 1399 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1400 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1401 | TInfo, move(SubExpr), |
| 1402 | SourceRange(LAngleLoc, RAngleLoc), |
| 1403 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | /// \brief Build a new C++ dynamic_cast expression. |
| 1407 | /// |
| 1408 | /// By default, performs semantic analysis to build the new expression. |
| 1409 | /// Subclasses may override this routine to provide different behavior. |
| 1410 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1411 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1412 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1413 | SourceLocation RAngleLoc, |
| 1414 | SourceLocation LParenLoc, |
| 1415 | ExprArg SubExpr, |
| 1416 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1417 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1418 | TInfo, move(SubExpr), |
| 1419 | SourceRange(LAngleLoc, RAngleLoc), |
| 1420 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1424 | /// |
| 1425 | /// By default, performs semantic analysis to build the new expression. |
| 1426 | /// Subclasses may override this routine to provide different behavior. |
| 1427 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1428 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1429 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1430 | SourceLocation RAngleLoc, |
| 1431 | SourceLocation LParenLoc, |
| 1432 | ExprArg SubExpr, |
| 1433 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1434 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1435 | TInfo, move(SubExpr), |
| 1436 | SourceRange(LAngleLoc, RAngleLoc), |
| 1437 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | /// \brief Build a new C++ const_cast expression. |
| 1441 | /// |
| 1442 | /// By default, performs semantic analysis to build the new expression. |
| 1443 | /// Subclasses may override this routine to provide different behavior. |
| 1444 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1445 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1446 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1447 | SourceLocation RAngleLoc, |
| 1448 | SourceLocation LParenLoc, |
| 1449 | ExprArg SubExpr, |
| 1450 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1451 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1452 | TInfo, move(SubExpr), |
| 1453 | SourceRange(LAngleLoc, RAngleLoc), |
| 1454 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1455 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1456 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1457 | /// \brief Build a new C++ functional-style cast expression. |
| 1458 | /// |
| 1459 | /// By default, performs semantic analysis to build the new expression. |
| 1460 | /// Subclasses may override this routine to provide different behavior. |
| 1461 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1462 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1463 | SourceLocation LParenLoc, |
| 1464 | ExprArg SubExpr, |
| 1465 | SourceLocation RParenLoc) { |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1466 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1467 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1468 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1469 | LParenLoc, |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1470 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1471 | /*CommaLocs=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1472 | RParenLoc); |
| 1473 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1474 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1475 | /// \brief Build a new C++ typeid(type) expression. |
| 1476 | /// |
| 1477 | /// By default, performs semantic analysis to build the new expression. |
| 1478 | /// Subclasses may override this routine to provide different behavior. |
| 1479 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1480 | SourceLocation LParenLoc, |
| 1481 | QualType T, |
| 1482 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1483 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1484 | T.getAsOpaquePtr(), RParenLoc); |
| 1485 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1486 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1487 | /// \brief Build a new C++ typeid(expr) expression. |
| 1488 | /// |
| 1489 | /// By default, performs semantic analysis to build the new expression. |
| 1490 | /// Subclasses may override this routine to provide different behavior. |
| 1491 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1492 | SourceLocation LParenLoc, |
| 1493 | ExprArg Operand, |
| 1494 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1495 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1496 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1497 | RParenLoc); |
| 1498 | if (Result.isInvalid()) |
| 1499 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1500 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1501 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1502 | return move(Result); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1505 | /// \brief Build a new C++ "this" expression. |
| 1506 | /// |
| 1507 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1508 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1509 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1510 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1511 | QualType ThisType, |
| 1512 | bool isImplicit) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1513 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1514 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1515 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | /// \brief Build a new C++ throw expression. |
| 1519 | /// |
| 1520 | /// By default, performs semantic analysis to build the new expression. |
| 1521 | /// Subclasses may override this routine to provide different behavior. |
| 1522 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1523 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1524 | } |
| 1525 | |
| 1526 | /// \brief Build a new C++ default-argument expression. |
| 1527 | /// |
| 1528 | /// By default, builds a new default-argument expression, which does not |
| 1529 | /// require any semantic analysis. Subclasses may override this routine to |
| 1530 | /// provide different behavior. |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1531 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
| 1532 | ParmVarDecl *Param) { |
| 1533 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1534 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | /// \brief Build a new C++ zero-initialization expression. |
| 1538 | /// |
| 1539 | /// By default, performs semantic analysis to build the new expression. |
| 1540 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1541 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1542 | SourceLocation LParenLoc, |
| 1543 | QualType T, |
| 1544 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1545 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1546 | T.getAsOpaquePtr(), LParenLoc, |
| 1547 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1548 | 0, RParenLoc); |
| 1549 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1550 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1551 | /// \brief Build a new C++ "new" expression. |
| 1552 | /// |
| 1553 | /// By default, performs semantic analysis to build the new expression. |
| 1554 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1555 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1556 | bool UseGlobal, |
| 1557 | SourceLocation PlacementLParen, |
| 1558 | MultiExprArg PlacementArgs, |
| 1559 | SourceLocation PlacementRParen, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1560 | bool ParenTypeId, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1561 | QualType AllocType, |
| 1562 | SourceLocation TypeLoc, |
| 1563 | SourceRange TypeRange, |
| 1564 | ExprArg ArraySize, |
| 1565 | SourceLocation ConstructorLParen, |
| 1566 | MultiExprArg ConstructorArgs, |
| 1567 | SourceLocation ConstructorRParen) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1568 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1569 | PlacementLParen, |
| 1570 | move(PlacementArgs), |
| 1571 | PlacementRParen, |
| 1572 | ParenTypeId, |
| 1573 | AllocType, |
| 1574 | TypeLoc, |
| 1575 | TypeRange, |
| 1576 | move(ArraySize), |
| 1577 | ConstructorLParen, |
| 1578 | move(ConstructorArgs), |
| 1579 | ConstructorRParen); |
| 1580 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1581 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1582 | /// \brief Build a new C++ "delete" expression. |
| 1583 | /// |
| 1584 | /// By default, performs semantic analysis to build the new expression. |
| 1585 | /// Subclasses may override this routine to provide different behavior. |
| 1586 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1587 | bool IsGlobalDelete, |
| 1588 | bool IsArrayForm, |
| 1589 | ExprArg Operand) { |
| 1590 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1591 | move(Operand)); |
| 1592 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1593 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1594 | /// \brief Build a new unary type trait expression. |
| 1595 | /// |
| 1596 | /// By default, performs semantic analysis to build the new expression. |
| 1597 | /// Subclasses may override this routine to provide different behavior. |
| 1598 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1599 | SourceLocation StartLoc, |
| 1600 | SourceLocation LParenLoc, |
| 1601 | QualType T, |
| 1602 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1603 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1604 | T.getAsOpaquePtr(), RParenLoc); |
| 1605 | } |
| 1606 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1607 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1608 | /// expression. |
| 1609 | /// |
| 1610 | /// By default, performs semantic analysis to build the new expression. |
| 1611 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1612 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1613 | SourceRange QualifierRange, |
| 1614 | DeclarationName Name, |
| 1615 | SourceLocation Location, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1616 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1617 | CXXScopeSpec SS; |
| 1618 | SS.setRange(QualifierRange); |
| 1619 | SS.setScopeRep(NNS); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1620 | |
| 1621 | if (TemplateArgs) |
| 1622 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1623 | *TemplateArgs); |
| 1624 | |
| 1625 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | /// \brief Build a new template-id expression. |
| 1629 | /// |
| 1630 | /// By default, performs semantic analysis to build the new expression. |
| 1631 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1632 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1633 | LookupResult &R, |
| 1634 | bool RequiresADL, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1635 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1636 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | /// \brief Build a new object-construction expression. |
| 1640 | /// |
| 1641 | /// By default, performs semantic analysis to build the new expression. |
| 1642 | /// Subclasses may override this routine to provide different behavior. |
| 1643 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1644 | SourceLocation Loc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1645 | CXXConstructorDecl *Constructor, |
| 1646 | bool IsElidable, |
| 1647 | MultiExprArg Args) { |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1648 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
| 1649 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
| 1650 | ConvertedArgs)) |
| 1651 | return getSema().ExprError(); |
| 1652 | |
| 1653 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1654 | move_arg(ConvertedArgs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | /// \brief Build a new object-construction expression. |
| 1658 | /// |
| 1659 | /// By default, performs semantic analysis to build the new expression. |
| 1660 | /// Subclasses may override this routine to provide different behavior. |
| 1661 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1662 | QualType T, |
| 1663 | SourceLocation LParenLoc, |
| 1664 | MultiExprArg Args, |
| 1665 | SourceLocation *Commas, |
| 1666 | SourceLocation RParenLoc) { |
| 1667 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1668 | T.getAsOpaquePtr(), |
| 1669 | LParenLoc, |
| 1670 | move(Args), |
| 1671 | Commas, |
| 1672 | RParenLoc); |
| 1673 | } |
| 1674 | |
| 1675 | /// \brief Build a new object-construction expression. |
| 1676 | /// |
| 1677 | /// By default, performs semantic analysis to build the new expression. |
| 1678 | /// Subclasses may override this routine to provide different behavior. |
| 1679 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1680 | QualType T, |
| 1681 | SourceLocation LParenLoc, |
| 1682 | MultiExprArg Args, |
| 1683 | SourceLocation *Commas, |
| 1684 | SourceLocation RParenLoc) { |
| 1685 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1686 | /*FIXME*/LParenLoc), |
| 1687 | T.getAsOpaquePtr(), |
| 1688 | LParenLoc, |
| 1689 | move(Args), |
| 1690 | Commas, |
| 1691 | RParenLoc); |
| 1692 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1693 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1694 | /// \brief Build a new member reference expression. |
| 1695 | /// |
| 1696 | /// By default, performs semantic analysis to build the new expression. |
| 1697 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1698 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1699 | QualType BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1700 | bool IsArrow, |
| 1701 | SourceLocation OperatorLoc, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1702 | NestedNameSpecifier *Qualifier, |
| 1703 | SourceRange QualifierRange, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1704 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1705 | DeclarationName Name, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1706 | SourceLocation MemberLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1707 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1708 | CXXScopeSpec SS; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1709 | SS.setRange(QualifierRange); |
| 1710 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1711 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1712 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1713 | OperatorLoc, IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1714 | SS, FirstQualifierInScope, |
| 1715 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1716 | } |
| 1717 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1718 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1719 | /// |
| 1720 | /// By default, performs semantic analysis to build the new expression. |
| 1721 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1722 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1723 | QualType BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1724 | SourceLocation OperatorLoc, |
| 1725 | bool IsArrow, |
| 1726 | NestedNameSpecifier *Qualifier, |
| 1727 | SourceRange QualifierRange, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1728 | NamedDecl *FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1729 | LookupResult &R, |
| 1730 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1731 | CXXScopeSpec SS; |
| 1732 | SS.setRange(QualifierRange); |
| 1733 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1734 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1735 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1736 | OperatorLoc, IsArrow, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1737 | SS, FirstQualifierInScope, |
| 1738 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1739 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1740 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1741 | /// \brief Build a new Objective-C @encode expression. |
| 1742 | /// |
| 1743 | /// By default, performs semantic analysis to build the new expression. |
| 1744 | /// Subclasses may override this routine to provide different behavior. |
| 1745 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1746 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1747 | SourceLocation RParenLoc) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1748 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1749 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1750 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1751 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1752 | /// \brief Build a new Objective-C class message. |
| 1753 | OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
| 1754 | Selector Sel, |
| 1755 | ObjCMethodDecl *Method, |
| 1756 | SourceLocation LBracLoc, |
| 1757 | MultiExprArg Args, |
| 1758 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1759 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 1760 | ReceiverTypeInfo->getType(), |
| 1761 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | f49bb08 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1762 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1763 | move(Args)); |
| 1764 | } |
| 1765 | |
| 1766 | /// \brief Build a new Objective-C instance message. |
| 1767 | OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver, |
| 1768 | Selector Sel, |
| 1769 | ObjCMethodDecl *Method, |
| 1770 | SourceLocation LBracLoc, |
| 1771 | MultiExprArg Args, |
| 1772 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1773 | QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType(); |
| 1774 | return SemaRef.BuildInstanceMessage(move(Receiver), |
| 1775 | ReceiverType, |
| 1776 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | f49bb08 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1777 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1778 | move(Args)); |
| 1779 | } |
| 1780 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1781 | /// \brief Build a new shuffle vector expression. |
| 1782 | /// |
| 1783 | /// By default, performs semantic analysis to build the new expression. |
| 1784 | /// Subclasses may override this routine to provide different behavior. |
| 1785 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1786 | MultiExprArg SubExprs, |
| 1787 | SourceLocation RParenLoc) { |
| 1788 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1789 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1790 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1791 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1792 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1793 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1794 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1795 | // Build a reference to the __builtin_shufflevector builtin |
| 1796 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1797 | Expr *Callee |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1798 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1799 | BuiltinLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1800 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1801 | |
| 1802 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1803 | unsigned NumSubExprs = SubExprs.size(); |
| 1804 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1805 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1806 | Subs, NumSubExprs, |
| 1807 | Builtin->getResultType(), |
| 1808 | RParenLoc); |
| 1809 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1810 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1811 | // Type-check the __builtin_shufflevector expression. |
| 1812 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1813 | if (Result.isInvalid()) |
| 1814 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1815 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1816 | OwnedCall.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1817 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1818 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1819 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1820 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1821 | template<typename Derived> |
| 1822 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1823 | if (!S) |
| 1824 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1825 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1826 | switch (S->getStmtClass()) { |
| 1827 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1828 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1829 | // Transform individual statement nodes |
| 1830 | #define STMT(Node, Parent) \ |
| 1831 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1832 | #define EXPR(Node, Parent) |
| 1833 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1834 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1835 | // Transform expressions by calling TransformExpr. |
| 1836 | #define STMT(Node, Parent) |
John McCall | 09cc141 | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1837 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1838 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1839 | #include "clang/AST/StmtNodes.def" |
| 1840 | { |
| 1841 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1842 | if (E.isInvalid()) |
| 1843 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1844 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1845 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1846 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1847 | } |
| 1848 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1849 | return SemaRef.Owned(S->Retain()); |
| 1850 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1851 | |
| 1852 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1853 | template<typename Derived> |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1854 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1855 | if (!E) |
| 1856 | return SemaRef.Owned(E); |
| 1857 | |
| 1858 | switch (E->getStmtClass()) { |
| 1859 | case Stmt::NoStmtClass: break; |
| 1860 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
John McCall | 09cc141 | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1861 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1862 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1863 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1864 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1865 | } |
| 1866 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1867 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | template<typename Derived> |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1871 | NestedNameSpecifier * |
| 1872 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1873 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1874 | QualType ObjectType, |
| 1875 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 0979c80 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1876 | if (!NNS) |
| 1877 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1878 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1879 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1880 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1881 | if (Prefix) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1882 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1883 | ObjectType, |
| 1884 | FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1885 | if (!Prefix) |
| 1886 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1887 | |
| 1888 | // 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] | 1889 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1890 | ObjectType = QualType(); |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1891 | FirstQualifierInScope = 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1892 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1893 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1894 | switch (NNS->getKind()) { |
| 1895 | case NestedNameSpecifier::Identifier: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1896 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1897 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1898 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1899 | ObjectType.isNull()) |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1900 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1901 | |
| 1902 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1903 | *NNS->getAsIdentifier(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1904 | ObjectType, |
| 1905 | FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1906 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1907 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1908 | NamespaceDecl *NS |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1909 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1910 | getDerived().TransformDecl(Range.getBegin(), |
| 1911 | NNS->getAsNamespace())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1912 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1913 | Prefix == NNS->getPrefix() && |
| 1914 | NS == NNS->getAsNamespace()) |
| 1915 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1916 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1917 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1918 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1919 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1920 | case NestedNameSpecifier::Global: |
| 1921 | // There is no meaningful transformation that one could perform on the |
| 1922 | // global scope. |
| 1923 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1924 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1925 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1926 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | fbf2c94 | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1927 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1928 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 1929 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1930 | if (T.isNull()) |
| 1931 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1932 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1933 | if (!getDerived().AlwaysRebuild() && |
| 1934 | Prefix == NNS->getPrefix() && |
| 1935 | T == QualType(NNS->getAsType(), 0)) |
| 1936 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1937 | |
| 1938 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1939 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 1940 | T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1941 | } |
| 1942 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1943 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1944 | // Required to silence a GCC warning |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1945 | return 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1949 | DeclarationName |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1950 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1951 | SourceLocation Loc, |
| 1952 | QualType ObjectType) { |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1953 | if (!Name) |
| 1954 | return Name; |
| 1955 | |
| 1956 | switch (Name.getNameKind()) { |
| 1957 | case DeclarationName::Identifier: |
| 1958 | case DeclarationName::ObjCZeroArgSelector: |
| 1959 | case DeclarationName::ObjCOneArgSelector: |
| 1960 | case DeclarationName::ObjCMultiArgSelector: |
| 1961 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 1962 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1963 | case DeclarationName::CXXUsingDirective: |
| 1964 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1965 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1966 | case DeclarationName::CXXConstructorName: |
| 1967 | case DeclarationName::CXXDestructorName: |
| 1968 | case DeclarationName::CXXConversionFunctionName: { |
| 1969 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1970 | QualType T = getDerived().TransformType(Name.getCXXNameType(), |
| 1971 | ObjectType); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1972 | if (T.isNull()) |
| 1973 | return DeclarationName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1974 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1975 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1976 | Name.getNameKind(), |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1977 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1978 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1979 | } |
| 1980 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1981 | return DeclarationName(); |
| 1982 | } |
| 1983 | |
| 1984 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1985 | TemplateName |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1986 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1987 | QualType ObjectType) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1988 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1989 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1990 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1991 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1992 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1993 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 1994 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1995 | if (!NNS) |
| 1996 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1997 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1998 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1999 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2000 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2001 | if (!TransTemplate) |
| 2002 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2003 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2004 | if (!getDerived().AlwaysRebuild() && |
| 2005 | NNS == QTN->getQualifier() && |
| 2006 | TransTemplate == Template) |
| 2007 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2008 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2009 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 2010 | TransTemplate); |
| 2011 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2012 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2013 | // These should be getting filtered out before they make it into the AST. |
| 2014 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2015 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2016 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2017 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2018 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2019 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2020 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2021 | ObjectType); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2022 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2023 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2024 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2025 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2026 | NNS == DTN->getQualifier() && |
| 2027 | ObjectType.isNull()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2028 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2029 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2030 | if (DTN->isIdentifier()) |
| 2031 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 2032 | ObjectType); |
| 2033 | |
| 2034 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 2035 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2036 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2037 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2038 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2039 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2040 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2041 | if (!TransTemplate) |
| 2042 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2043 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2044 | if (!getDerived().AlwaysRebuild() && |
| 2045 | TransTemplate == Template) |
| 2046 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2047 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2048 | return TemplateName(TransTemplate); |
| 2049 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2050 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2051 | // These should be getting filtered out before they reach the AST. |
| 2052 | assert(false && "overloaded function decl survived to here"); |
| 2053 | return TemplateName(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2054 | } |
| 2055 | |
| 2056 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2057 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2058 | const TemplateArgument &Arg, |
| 2059 | TemplateArgumentLoc &Output) { |
| 2060 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2061 | switch (Arg.getKind()) { |
| 2062 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2063 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2064 | break; |
| 2065 | |
| 2066 | case TemplateArgument::Type: |
| 2067 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2068 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2069 | |
| 2070 | break; |
| 2071 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2072 | case TemplateArgument::Template: |
| 2073 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 2074 | break; |
| 2075 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2076 | case TemplateArgument::Expression: |
| 2077 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2078 | break; |
| 2079 | |
| 2080 | case TemplateArgument::Declaration: |
| 2081 | case TemplateArgument::Integral: |
| 2082 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2083 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2084 | break; |
| 2085 | } |
| 2086 | } |
| 2087 | |
| 2088 | template<typename Derived> |
| 2089 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2090 | const TemplateArgumentLoc &Input, |
| 2091 | TemplateArgumentLoc &Output) { |
| 2092 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2093 | switch (Arg.getKind()) { |
| 2094 | case TemplateArgument::Null: |
| 2095 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2096 | Output = Input; |
| 2097 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2098 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2099 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2100 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2101 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2102 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2103 | |
| 2104 | DI = getDerived().TransformType(DI); |
| 2105 | if (!DI) return true; |
| 2106 | |
| 2107 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2108 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2109 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2110 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2111 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2112 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2113 | DeclarationName Name; |
| 2114 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2115 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2116 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2117 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2118 | if (!D) return true; |
| 2119 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2120 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2121 | if (SourceExpr) { |
| 2122 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 2123 | Action::Unevaluated); |
| 2124 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 2125 | if (E.isInvalid()) |
| 2126 | SourceExpr = NULL; |
| 2127 | else { |
| 2128 | SourceExpr = E.takeAs<Expr>(); |
| 2129 | SourceExpr->Retain(); |
| 2130 | } |
| 2131 | } |
| 2132 | |
| 2133 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2134 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2135 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2136 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2137 | case TemplateArgument::Template: { |
| 2138 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 2139 | TemplateName Template |
| 2140 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2141 | if (Template.isNull()) |
| 2142 | return true; |
| 2143 | |
| 2144 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2145 | Input.getTemplateQualifierRange(), |
| 2146 | Input.getTemplateNameLoc()); |
| 2147 | return false; |
| 2148 | } |
| 2149 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2150 | case TemplateArgument::Expression: { |
| 2151 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2152 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2153 | Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2154 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2155 | Expr *InputExpr = Input.getSourceExpression(); |
| 2156 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2157 | |
| 2158 | Sema::OwningExprResult E |
| 2159 | = getDerived().TransformExpr(InputExpr); |
| 2160 | if (E.isInvalid()) return true; |
| 2161 | |
| 2162 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2163 | ETaken->Retain(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2164 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2165 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2166 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2167 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2168 | case TemplateArgument::Pack: { |
| 2169 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2170 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2171 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2172 | AEnd = Arg.pack_end(); |
| 2173 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2174 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2175 | // FIXME: preserve source information here when we start |
| 2176 | // caring about parameter packs. |
| 2177 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2178 | TemplateArgumentLoc InputArg; |
| 2179 | TemplateArgumentLoc OutputArg; |
| 2180 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2181 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2182 | return true; |
| 2183 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2184 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2185 | } |
| 2186 | TemplateArgument Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2187 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2188 | true); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2189 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2190 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2191 | } |
| 2192 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2193 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2194 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2195 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2196 | } |
| 2197 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2198 | //===----------------------------------------------------------------------===// |
| 2199 | // Type transformation |
| 2200 | //===----------------------------------------------------------------------===// |
| 2201 | |
| 2202 | template<typename Derived> |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2203 | QualType TreeTransform<Derived>::TransformType(QualType T, |
| 2204 | QualType ObjectType) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2205 | if (getDerived().AlreadyTransformed(T)) |
| 2206 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2207 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2208 | // Temporary workaround. All of these transformations should |
| 2209 | // eventually turn into transformations on TypeLocs. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2210 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | 4802a31 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2211 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2212 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2213 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2214 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2215 | if (!NewDI) |
| 2216 | return QualType(); |
| 2217 | |
| 2218 | return NewDI->getType(); |
| 2219 | } |
| 2220 | |
| 2221 | template<typename Derived> |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2222 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2223 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2224 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2225 | return DI; |
| 2226 | |
| 2227 | TypeLocBuilder TLB; |
| 2228 | |
| 2229 | TypeLoc TL = DI->getTypeLoc(); |
| 2230 | TLB.reserve(TL.getFullDataSize()); |
| 2231 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2232 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2233 | if (Result.isNull()) |
| 2234 | return 0; |
| 2235 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2236 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | template<typename Derived> |
| 2240 | QualType |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2241 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2242 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2243 | switch (T.getTypeLocClass()) { |
| 2244 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2245 | #define TYPELOC(CLASS, PARENT) \ |
| 2246 | case TypeLoc::CLASS: \ |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2247 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2248 | ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2249 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2250 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2251 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2252 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2253 | return QualType(); |
| 2254 | } |
| 2255 | |
| 2256 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2257 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2258 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2259 | /// types). This is the right thing for template instantiation, but |
| 2260 | /// probably not for other clients. |
| 2261 | template<typename Derived> |
| 2262 | QualType |
| 2263 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2264 | QualifiedTypeLoc T, |
| 2265 | QualType ObjectType) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2266 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2267 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2268 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2269 | ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2270 | if (Result.isNull()) |
| 2271 | return QualType(); |
| 2272 | |
| 2273 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2274 | // FIXME: this is the right thing for template instantiation, but |
| 2275 | // probably not for other clients. |
| 2276 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2277 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2278 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2279 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2280 | |
| 2281 | TLB.push<QualifiedTypeLoc>(Result); |
| 2282 | |
| 2283 | // No location information to preserve. |
| 2284 | |
| 2285 | return Result; |
| 2286 | } |
| 2287 | |
| 2288 | template <class TyLoc> static inline |
| 2289 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2290 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2291 | NewT.setNameLoc(T.getNameLoc()); |
| 2292 | return T.getType(); |
| 2293 | } |
| 2294 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2295 | template<typename Derived> |
| 2296 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2297 | BuiltinTypeLoc T, |
| 2298 | QualType ObjectType) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2299 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2300 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2301 | if (T.needsExtraLocalData()) |
| 2302 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2303 | return T.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2304 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2305 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2306 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2307 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2308 | ComplexTypeLoc T, |
| 2309 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2310 | // FIXME: recurse? |
| 2311 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2312 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2313 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2314 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2315 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2316 | PointerTypeLoc TL, |
| 2317 | QualType ObjectType) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2318 | QualType PointeeType |
| 2319 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2320 | if (PointeeType.isNull()) |
| 2321 | return QualType(); |
| 2322 | |
| 2323 | QualType Result = TL.getType(); |
| 2324 | if (PointeeType->isObjCInterfaceType()) { |
| 2325 | // A dependent pointer type 'T *' has is being transformed such |
| 2326 | // that an Objective-C class type is being replaced for 'T'. The |
| 2327 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 2328 | // PointerType. |
| 2329 | const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>(); |
| 2330 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType, |
| 2331 | const_cast<ObjCProtocolDecl **>( |
| 2332 | IFace->qual_begin()), |
| 2333 | IFace->getNumProtocols()); |
| 2334 | |
| 2335 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 2336 | NewT.setStarLoc(TL.getSigilLoc()); |
| 2337 | NewT.setHasProtocolsAsWritten(false); |
| 2338 | NewT.setLAngleLoc(SourceLocation()); |
| 2339 | NewT.setRAngleLoc(SourceLocation()); |
| 2340 | NewT.setHasBaseTypeAsWritten(true); |
| 2341 | return Result; |
| 2342 | } |
| 2343 | |
| 2344 | if (getDerived().AlwaysRebuild() || |
| 2345 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2346 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 2347 | if (Result.isNull()) |
| 2348 | return QualType(); |
| 2349 | } |
| 2350 | |
| 2351 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 2352 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 2353 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2354 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2355 | |
| 2356 | template<typename Derived> |
| 2357 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2358 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2359 | BlockPointerTypeLoc TL, |
| 2360 | QualType ObjectType) { |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2361 | QualType PointeeType |
| 2362 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2363 | if (PointeeType.isNull()) |
| 2364 | return QualType(); |
| 2365 | |
| 2366 | QualType Result = TL.getType(); |
| 2367 | if (getDerived().AlwaysRebuild() || |
| 2368 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2369 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
| 2370 | TL.getSigilLoc()); |
| 2371 | if (Result.isNull()) |
| 2372 | return QualType(); |
| 2373 | } |
| 2374 | |
Douglas Gregor | 39968ad | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 2375 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2376 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 2377 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2378 | } |
| 2379 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2380 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2381 | /// don't care whether the type itself is an l-value type or an r-value |
| 2382 | /// type; we only care if the type was *written* as an l-value type |
| 2383 | /// or an r-value type. |
| 2384 | template<typename Derived> |
| 2385 | QualType |
| 2386 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2387 | ReferenceTypeLoc TL, |
| 2388 | QualType ObjectType) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2389 | const ReferenceType *T = TL.getTypePtr(); |
| 2390 | |
| 2391 | // Note that this works with the pointee-as-written. |
| 2392 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2393 | if (PointeeType.isNull()) |
| 2394 | return QualType(); |
| 2395 | |
| 2396 | QualType Result = TL.getType(); |
| 2397 | if (getDerived().AlwaysRebuild() || |
| 2398 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2399 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2400 | T->isSpelledAsLValue(), |
| 2401 | TL.getSigilLoc()); |
| 2402 | if (Result.isNull()) |
| 2403 | return QualType(); |
| 2404 | } |
| 2405 | |
| 2406 | // r-value references can be rebuilt as l-value references. |
| 2407 | ReferenceTypeLoc NewTL; |
| 2408 | if (isa<LValueReferenceType>(Result)) |
| 2409 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2410 | else |
| 2411 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2412 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2413 | |
| 2414 | return Result; |
| 2415 | } |
| 2416 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2417 | template<typename Derived> |
| 2418 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2419 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2420 | LValueReferenceTypeLoc TL, |
| 2421 | QualType ObjectType) { |
| 2422 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2423 | } |
| 2424 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2425 | template<typename Derived> |
| 2426 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2427 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2428 | RValueReferenceTypeLoc TL, |
| 2429 | QualType ObjectType) { |
| 2430 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2431 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2432 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2433 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2434 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2435 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2436 | MemberPointerTypeLoc TL, |
| 2437 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2438 | MemberPointerType *T = TL.getTypePtr(); |
| 2439 | |
| 2440 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2441 | if (PointeeType.isNull()) |
| 2442 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2443 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2444 | // TODO: preserve source information for this. |
| 2445 | QualType ClassType |
| 2446 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2447 | if (ClassType.isNull()) |
| 2448 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2449 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2450 | QualType Result = TL.getType(); |
| 2451 | if (getDerived().AlwaysRebuild() || |
| 2452 | PointeeType != T->getPointeeType() || |
| 2453 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2454 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2455 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2456 | if (Result.isNull()) |
| 2457 | return QualType(); |
| 2458 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2459 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2460 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2461 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2462 | |
| 2463 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2464 | } |
| 2465 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2466 | template<typename Derived> |
| 2467 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2468 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2469 | ConstantArrayTypeLoc TL, |
| 2470 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2471 | ConstantArrayType *T = TL.getTypePtr(); |
| 2472 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2473 | if (ElementType.isNull()) |
| 2474 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2475 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2476 | QualType Result = TL.getType(); |
| 2477 | if (getDerived().AlwaysRebuild() || |
| 2478 | ElementType != T->getElementType()) { |
| 2479 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2480 | T->getSizeModifier(), |
| 2481 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2482 | T->getIndexTypeCVRQualifiers(), |
| 2483 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2484 | if (Result.isNull()) |
| 2485 | return QualType(); |
| 2486 | } |
| 2487 | |
| 2488 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2489 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2490 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2491 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2492 | Expr *Size = TL.getSizeExpr(); |
| 2493 | if (Size) { |
| 2494 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2495 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2496 | } |
| 2497 | NewTL.setSizeExpr(Size); |
| 2498 | |
| 2499 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2500 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2501 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2502 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2503 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2504 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2505 | IncompleteArrayTypeLoc TL, |
| 2506 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2507 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2508 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2509 | if (ElementType.isNull()) |
| 2510 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2511 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2512 | QualType Result = TL.getType(); |
| 2513 | if (getDerived().AlwaysRebuild() || |
| 2514 | ElementType != T->getElementType()) { |
| 2515 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2516 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2517 | T->getIndexTypeCVRQualifiers(), |
| 2518 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2519 | if (Result.isNull()) |
| 2520 | return QualType(); |
| 2521 | } |
| 2522 | |
| 2523 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2524 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2525 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2526 | NewTL.setSizeExpr(0); |
| 2527 | |
| 2528 | return Result; |
| 2529 | } |
| 2530 | |
| 2531 | template<typename Derived> |
| 2532 | QualType |
| 2533 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2534 | VariableArrayTypeLoc TL, |
| 2535 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2536 | VariableArrayType *T = TL.getTypePtr(); |
| 2537 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2538 | if (ElementType.isNull()) |
| 2539 | return QualType(); |
| 2540 | |
| 2541 | // Array bounds are not potentially evaluated contexts |
| 2542 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2543 | |
| 2544 | Sema::OwningExprResult SizeResult |
| 2545 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2546 | if (SizeResult.isInvalid()) |
| 2547 | return QualType(); |
| 2548 | |
| 2549 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2550 | |
| 2551 | QualType Result = TL.getType(); |
| 2552 | if (getDerived().AlwaysRebuild() || |
| 2553 | ElementType != T->getElementType() || |
| 2554 | Size != T->getSizeExpr()) { |
| 2555 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2556 | T->getSizeModifier(), |
| 2557 | move(SizeResult), |
| 2558 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2559 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2560 | if (Result.isNull()) |
| 2561 | return QualType(); |
| 2562 | } |
| 2563 | else SizeResult.take(); |
| 2564 | |
| 2565 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2566 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2567 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2568 | NewTL.setSizeExpr(Size); |
| 2569 | |
| 2570 | return Result; |
| 2571 | } |
| 2572 | |
| 2573 | template<typename Derived> |
| 2574 | QualType |
| 2575 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2576 | DependentSizedArrayTypeLoc TL, |
| 2577 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2578 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2579 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2580 | if (ElementType.isNull()) |
| 2581 | return QualType(); |
| 2582 | |
| 2583 | // Array bounds are not potentially evaluated contexts |
| 2584 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2585 | |
| 2586 | Sema::OwningExprResult SizeResult |
| 2587 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2588 | if (SizeResult.isInvalid()) |
| 2589 | return QualType(); |
| 2590 | |
| 2591 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2592 | |
| 2593 | QualType Result = TL.getType(); |
| 2594 | if (getDerived().AlwaysRebuild() || |
| 2595 | ElementType != T->getElementType() || |
| 2596 | Size != T->getSizeExpr()) { |
| 2597 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2598 | T->getSizeModifier(), |
| 2599 | move(SizeResult), |
| 2600 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2601 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2602 | if (Result.isNull()) |
| 2603 | return QualType(); |
| 2604 | } |
| 2605 | else SizeResult.take(); |
| 2606 | |
| 2607 | // We might have any sort of array type now, but fortunately they |
| 2608 | // all have the same location layout. |
| 2609 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2610 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2611 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2612 | NewTL.setSizeExpr(Size); |
| 2613 | |
| 2614 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2615 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2616 | |
| 2617 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2618 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2619 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2620 | DependentSizedExtVectorTypeLoc TL, |
| 2621 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2622 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2623 | |
| 2624 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2625 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2626 | if (ElementType.isNull()) |
| 2627 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2628 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2629 | // Vector sizes are not potentially evaluated contexts |
| 2630 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2631 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2632 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2633 | if (Size.isInvalid()) |
| 2634 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2635 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2636 | QualType Result = TL.getType(); |
| 2637 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2638 | ElementType != T->getElementType() || |
| 2639 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2640 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2641 | move(Size), |
| 2642 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2643 | if (Result.isNull()) |
| 2644 | return QualType(); |
| 2645 | } |
| 2646 | else Size.take(); |
| 2647 | |
| 2648 | // Result might be dependent or not. |
| 2649 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2650 | DependentSizedExtVectorTypeLoc NewTL |
| 2651 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2652 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2653 | } else { |
| 2654 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2655 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2656 | } |
| 2657 | |
| 2658 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2659 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2660 | |
| 2661 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2662 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2663 | VectorTypeLoc TL, |
| 2664 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2665 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2666 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2667 | if (ElementType.isNull()) |
| 2668 | return QualType(); |
| 2669 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2670 | QualType Result = TL.getType(); |
| 2671 | if (getDerived().AlwaysRebuild() || |
| 2672 | ElementType != T->getElementType()) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2673 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 2674 | T->isAltiVec(), T->isPixel()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2675 | if (Result.isNull()) |
| 2676 | return QualType(); |
| 2677 | } |
| 2678 | |
| 2679 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2680 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2681 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2682 | return Result; |
| 2683 | } |
| 2684 | |
| 2685 | template<typename Derived> |
| 2686 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2687 | ExtVectorTypeLoc TL, |
| 2688 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2689 | VectorType *T = TL.getTypePtr(); |
| 2690 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2691 | if (ElementType.isNull()) |
| 2692 | return QualType(); |
| 2693 | |
| 2694 | QualType Result = TL.getType(); |
| 2695 | if (getDerived().AlwaysRebuild() || |
| 2696 | ElementType != T->getElementType()) { |
| 2697 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2698 | T->getNumElements(), |
| 2699 | /*FIXME*/ SourceLocation()); |
| 2700 | if (Result.isNull()) |
| 2701 | return QualType(); |
| 2702 | } |
| 2703 | |
| 2704 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2705 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2706 | |
| 2707 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2708 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2709 | |
| 2710 | template<typename Derived> |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2711 | ParmVarDecl * |
| 2712 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) { |
| 2713 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| 2714 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
| 2715 | if (!NewDI) |
| 2716 | return 0; |
| 2717 | |
| 2718 | if (NewDI == OldDI) |
| 2719 | return OldParm; |
| 2720 | else |
| 2721 | return ParmVarDecl::Create(SemaRef.Context, |
| 2722 | OldParm->getDeclContext(), |
| 2723 | OldParm->getLocation(), |
| 2724 | OldParm->getIdentifier(), |
| 2725 | NewDI->getType(), |
| 2726 | NewDI, |
| 2727 | OldParm->getStorageClass(), |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 2728 | OldParm->getStorageClassAsWritten(), |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2729 | /* DefArg */ NULL); |
| 2730 | } |
| 2731 | |
| 2732 | template<typename Derived> |
| 2733 | bool TreeTransform<Derived>:: |
| 2734 | TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 2735 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 2736 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars) { |
| 2737 | FunctionProtoType *T = TL.getTypePtr(); |
| 2738 | |
| 2739 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2740 | ParmVarDecl *OldParm = TL.getArg(i); |
| 2741 | |
| 2742 | QualType NewType; |
| 2743 | ParmVarDecl *NewParm; |
| 2744 | |
| 2745 | if (OldParm) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2746 | NewParm = getDerived().TransformFunctionTypeParam(OldParm); |
| 2747 | if (!NewParm) |
| 2748 | return true; |
| 2749 | NewType = NewParm->getType(); |
| 2750 | |
| 2751 | // Deal with the possibility that we don't have a parameter |
| 2752 | // declaration for this parameter. |
| 2753 | } else { |
| 2754 | NewParm = 0; |
| 2755 | |
| 2756 | QualType OldType = T->getArgType(i); |
| 2757 | NewType = getDerived().TransformType(OldType); |
| 2758 | if (NewType.isNull()) |
| 2759 | return true; |
| 2760 | } |
| 2761 | |
| 2762 | PTypes.push_back(NewType); |
| 2763 | PVars.push_back(NewParm); |
| 2764 | } |
| 2765 | |
| 2766 | return false; |
| 2767 | } |
| 2768 | |
| 2769 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2770 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2771 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2772 | FunctionProtoTypeLoc TL, |
| 2773 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2774 | FunctionProtoType *T = TL.getTypePtr(); |
| 2775 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2776 | if (ResultType.isNull()) |
| 2777 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2778 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2779 | // Transform the parameters. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2780 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2781 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2782 | if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls)) |
| 2783 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2784 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2785 | QualType Result = TL.getType(); |
| 2786 | if (getDerived().AlwaysRebuild() || |
| 2787 | ResultType != T->getResultType() || |
| 2788 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2789 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2790 | ParamTypes.data(), |
| 2791 | ParamTypes.size(), |
| 2792 | T->isVariadic(), |
| 2793 | T->getTypeQuals()); |
| 2794 | if (Result.isNull()) |
| 2795 | return QualType(); |
| 2796 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2797 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2798 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2799 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2800 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2801 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2802 | NewTL.setArg(i, ParamDecls[i]); |
| 2803 | |
| 2804 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2805 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2806 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2807 | template<typename Derived> |
| 2808 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2809 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2810 | FunctionNoProtoTypeLoc TL, |
| 2811 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2812 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2813 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2814 | if (ResultType.isNull()) |
| 2815 | return QualType(); |
| 2816 | |
| 2817 | QualType Result = TL.getType(); |
| 2818 | if (getDerived().AlwaysRebuild() || |
| 2819 | ResultType != T->getResultType()) |
| 2820 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2821 | |
| 2822 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2823 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2824 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2825 | |
| 2826 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2827 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2828 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2829 | template<typename Derived> QualType |
| 2830 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2831 | UnresolvedUsingTypeLoc TL, |
| 2832 | QualType ObjectType) { |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2833 | UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2834 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2835 | if (!D) |
| 2836 | return QualType(); |
| 2837 | |
| 2838 | QualType Result = TL.getType(); |
| 2839 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2840 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2841 | if (Result.isNull()) |
| 2842 | return QualType(); |
| 2843 | } |
| 2844 | |
| 2845 | // We might get an arbitrary type spec type back. We should at |
| 2846 | // least always get a type spec type, though. |
| 2847 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2848 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2849 | |
| 2850 | return Result; |
| 2851 | } |
| 2852 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2853 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2854 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2855 | TypedefTypeLoc TL, |
| 2856 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2857 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2858 | TypedefDecl *Typedef |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2859 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2860 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2861 | if (!Typedef) |
| 2862 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2863 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2864 | QualType Result = TL.getType(); |
| 2865 | if (getDerived().AlwaysRebuild() || |
| 2866 | Typedef != T->getDecl()) { |
| 2867 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2868 | if (Result.isNull()) |
| 2869 | return QualType(); |
| 2870 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2871 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2872 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2873 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2874 | |
| 2875 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2876 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2877 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2878 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2879 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2880 | TypeOfExprTypeLoc TL, |
| 2881 | QualType ObjectType) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2882 | // typeof expressions are not potentially evaluated contexts |
| 2883 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2884 | |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2885 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2886 | if (E.isInvalid()) |
| 2887 | return QualType(); |
| 2888 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2889 | QualType Result = TL.getType(); |
| 2890 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2891 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2892 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2893 | if (Result.isNull()) |
| 2894 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2895 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2896 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2897 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2898 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2899 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2900 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2901 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2902 | |
| 2903 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2904 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2905 | |
| 2906 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2907 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2908 | TypeOfTypeLoc TL, |
| 2909 | QualType ObjectType) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2910 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 2911 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 2912 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2913 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2914 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2915 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2916 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 2917 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2918 | if (Result.isNull()) |
| 2919 | return QualType(); |
| 2920 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2921 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2922 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2923 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2924 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2925 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2926 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2927 | |
| 2928 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2929 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2930 | |
| 2931 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2932 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2933 | DecltypeTypeLoc TL, |
| 2934 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2935 | DecltypeType *T = TL.getTypePtr(); |
| 2936 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2937 | // decltype expressions are not potentially evaluated contexts |
| 2938 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2939 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2940 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2941 | if (E.isInvalid()) |
| 2942 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2943 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2944 | QualType Result = TL.getType(); |
| 2945 | if (getDerived().AlwaysRebuild() || |
| 2946 | E.get() != T->getUnderlyingExpr()) { |
| 2947 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2948 | if (Result.isNull()) |
| 2949 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2950 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2951 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2952 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2953 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2954 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2955 | |
| 2956 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2957 | } |
| 2958 | |
| 2959 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2960 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2961 | RecordTypeLoc TL, |
| 2962 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2963 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2964 | RecordDecl *Record |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2965 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2966 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2967 | if (!Record) |
| 2968 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2969 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2970 | QualType Result = TL.getType(); |
| 2971 | if (getDerived().AlwaysRebuild() || |
| 2972 | Record != T->getDecl()) { |
| 2973 | Result = getDerived().RebuildRecordType(Record); |
| 2974 | if (Result.isNull()) |
| 2975 | return QualType(); |
| 2976 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2977 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2978 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2979 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2980 | |
| 2981 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2982 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2983 | |
| 2984 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2985 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2986 | EnumTypeLoc TL, |
| 2987 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2988 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2989 | EnumDecl *Enum |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2990 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2991 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2992 | if (!Enum) |
| 2993 | return QualType(); |
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 | QualType Result = TL.getType(); |
| 2996 | if (getDerived().AlwaysRebuild() || |
| 2997 | Enum != T->getDecl()) { |
| 2998 | Result = getDerived().RebuildEnumType(Enum); |
| 2999 | if (Result.isNull()) |
| 3000 | return QualType(); |
| 3001 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3002 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3003 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 3004 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3005 | |
| 3006 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3007 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3008 | |
| 3009 | template <typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3010 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3011 | ElaboratedTypeLoc TL, |
| 3012 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3013 | ElaboratedType *T = TL.getTypePtr(); |
| 3014 | |
| 3015 | // FIXME: this should be a nested type. |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3016 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 3017 | if (Underlying.isNull()) |
| 3018 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3019 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3020 | QualType Result = TL.getType(); |
| 3021 | if (getDerived().AlwaysRebuild() || |
| 3022 | Underlying != T->getUnderlyingType()) { |
| 3023 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 3024 | if (Result.isNull()) |
| 3025 | return QualType(); |
| 3026 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3027 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3028 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 3029 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3030 | |
| 3031 | return Result; |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3032 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3033 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3034 | template<typename Derived> |
| 3035 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 3036 | TypeLocBuilder &TLB, |
| 3037 | InjectedClassNameTypeLoc TL, |
| 3038 | QualType ObjectType) { |
| 3039 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 3040 | TL.getTypePtr()->getDecl()); |
| 3041 | if (!D) return QualType(); |
| 3042 | |
| 3043 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 3044 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 3045 | return T; |
| 3046 | } |
| 3047 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3048 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3049 | template<typename Derived> |
| 3050 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3051 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3052 | TemplateTypeParmTypeLoc TL, |
| 3053 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3054 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3055 | } |
| 3056 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3057 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3058 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3059 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3060 | SubstTemplateTypeParmTypeLoc TL, |
| 3061 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3062 | return TransformTypeSpecType(TLB, TL); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3063 | } |
| 3064 | |
| 3065 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3066 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 3067 | const TemplateSpecializationType *TST, |
| 3068 | QualType ObjectType) { |
| 3069 | // FIXME: this entire method is a temporary workaround; callers |
| 3070 | // should be rewritten to provide real type locs. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3071 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3072 | // Fake up a TemplateSpecializationTypeLoc. |
| 3073 | TypeLocBuilder TLB; |
| 3074 | TemplateSpecializationTypeLoc TL |
| 3075 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 3076 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3077 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 3078 | |
| 3079 | TL.setTemplateNameLoc(BaseLoc); |
| 3080 | TL.setLAngleLoc(BaseLoc); |
| 3081 | TL.setRAngleLoc(BaseLoc); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3082 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 3083 | const TemplateArgument &TA = TST->getArg(i); |
| 3084 | TemplateArgumentLoc TAL; |
| 3085 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 3086 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 3087 | } |
| 3088 | |
| 3089 | TypeLocBuilder IgnoredTLB; |
| 3090 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3091 | } |
| 3092 | |
| 3093 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3094 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3095 | TypeLocBuilder &TLB, |
| 3096 | TemplateSpecializationTypeLoc TL, |
| 3097 | QualType ObjectType) { |
| 3098 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 3099 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3100 | TemplateName Template |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3101 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3102 | if (Template.isNull()) |
| 3103 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3104 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3105 | TemplateArgumentListInfo NewTemplateArgs; |
| 3106 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 3107 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 3108 | |
| 3109 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 3110 | TemplateArgumentLoc Loc; |
| 3111 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3112 | return QualType(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3113 | NewTemplateArgs.addArgument(Loc); |
| 3114 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3115 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3116 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 3117 | |
| 3118 | QualType Result = |
| 3119 | getDerived().RebuildTemplateSpecializationType(Template, |
| 3120 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3121 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3122 | |
| 3123 | if (!Result.isNull()) { |
| 3124 | TemplateSpecializationTypeLoc NewTL |
| 3125 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 3126 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 3127 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 3128 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 3129 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 3130 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3131 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3132 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3133 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3134 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3135 | |
| 3136 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3137 | QualType |
| 3138 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3139 | QualifiedNameTypeLoc TL, |
| 3140 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3141 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3142 | NestedNameSpecifier *NNS |
| 3143 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3144 | SourceRange(), |
| 3145 | ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3146 | if (!NNS) |
| 3147 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3148 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3149 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 3150 | if (Named.isNull()) |
| 3151 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3152 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3153 | QualType Result = TL.getType(); |
| 3154 | if (getDerived().AlwaysRebuild() || |
| 3155 | NNS != T->getQualifier() || |
| 3156 | Named != T->getNamedType()) { |
| 3157 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 3158 | if (Result.isNull()) |
| 3159 | return QualType(); |
| 3160 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3161 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3162 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 3163 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3164 | |
| 3165 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3166 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3167 | |
| 3168 | template<typename Derived> |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3169 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
| 3170 | DependentNameTypeLoc TL, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3171 | QualType ObjectType) { |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3172 | DependentNameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3173 | |
| 3174 | /* FIXME: preserve source information better than this */ |
| 3175 | SourceRange SR(TL.getNameLoc()); |
| 3176 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3177 | NestedNameSpecifier *NNS |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3178 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3179 | ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3180 | if (!NNS) |
| 3181 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3182 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3183 | QualType Result; |
| 3184 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3185 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3186 | QualType NewTemplateId |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3187 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 3188 | if (NewTemplateId.isNull()) |
| 3189 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3190 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3191 | if (!getDerived().AlwaysRebuild() && |
| 3192 | NNS == T->getQualifier() && |
| 3193 | NewTemplateId == QualType(TemplateId, 0)) |
| 3194 | return QualType(T, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3195 | |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3196 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 3197 | NewTemplateId); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3198 | } else { |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3199 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 3200 | T->getIdentifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3201 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3202 | if (Result.isNull()) |
| 3203 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3204 | |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3205 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3206 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3207 | |
| 3208 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3209 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3210 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3211 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3212 | QualType |
| 3213 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3214 | ObjCInterfaceTypeLoc TL, |
| 3215 | QualType ObjectType) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3216 | // ObjCInterfaceType is never dependent. |
| 3217 | return TL.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3218 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3219 | |
| 3220 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3221 | QualType |
| 3222 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3223 | ObjCObjectPointerTypeLoc TL, |
| 3224 | QualType ObjectType) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3225 | // ObjCObjectPointerType is never dependent. |
| 3226 | return TL.getType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3227 | } |
| 3228 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3229 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3230 | // Statement transformation |
| 3231 | //===----------------------------------------------------------------------===// |
| 3232 | template<typename Derived> |
| 3233 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3234 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3235 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3236 | } |
| 3237 | |
| 3238 | template<typename Derived> |
| 3239 | Sema::OwningStmtResult |
| 3240 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3241 | return getDerived().TransformCompoundStmt(S, false); |
| 3242 | } |
| 3243 | |
| 3244 | template<typename Derived> |
| 3245 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3246 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3247 | bool IsStmtExpr) { |
| 3248 | bool SubStmtChanged = false; |
| 3249 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3250 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3251 | B != BEnd; ++B) { |
| 3252 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3253 | if (Result.isInvalid()) |
| 3254 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3255 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3256 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3257 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3258 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3259 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3260 | if (!getDerived().AlwaysRebuild() && |
| 3261 | !SubStmtChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3262 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3263 | |
| 3264 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3265 | move_arg(Statements), |
| 3266 | S->getRBracLoc(), |
| 3267 | IsStmtExpr); |
| 3268 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3269 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3270 | template<typename Derived> |
| 3271 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3272 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3273 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3274 | { |
| 3275 | // The case value expressions are not potentially evaluated. |
| 3276 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3277 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3278 | // Transform the left-hand case value. |
| 3279 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3280 | if (LHS.isInvalid()) |
| 3281 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3282 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3283 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3284 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3285 | if (RHS.isInvalid()) |
| 3286 | return SemaRef.StmtError(); |
| 3287 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3288 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3289 | // Build the case statement. |
| 3290 | // Case statements are always rebuilt so that they will attached to their |
| 3291 | // transformed switch statement. |
| 3292 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3293 | move(LHS), |
| 3294 | S->getEllipsisLoc(), |
| 3295 | move(RHS), |
| 3296 | S->getColonLoc()); |
| 3297 | if (Case.isInvalid()) |
| 3298 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3299 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3300 | // Transform the statement following the case |
| 3301 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3302 | if (SubStmt.isInvalid()) |
| 3303 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3304 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3305 | // Attach the body to the case statement |
| 3306 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3307 | } |
| 3308 | |
| 3309 | template<typename Derived> |
| 3310 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3311 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3312 | // Transform the statement following the default case |
| 3313 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3314 | if (SubStmt.isInvalid()) |
| 3315 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3316 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3317 | // Default statements are always rebuilt |
| 3318 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3319 | move(SubStmt)); |
| 3320 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3321 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3322 | template<typename Derived> |
| 3323 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3324 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3325 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3326 | if (SubStmt.isInvalid()) |
| 3327 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3328 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3329 | // FIXME: Pass the real colon location in. |
| 3330 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3331 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3332 | move(SubStmt)); |
| 3333 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3334 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3335 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3336 | Sema::OwningStmtResult |
| 3337 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3338 | // Transform the condition |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3339 | OwningExprResult Cond(SemaRef); |
| 3340 | VarDecl *ConditionVar = 0; |
| 3341 | if (S->getConditionVariable()) { |
| 3342 | ConditionVar |
| 3343 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3344 | getDerived().TransformDefinition( |
| 3345 | S->getConditionVariable()->getLocation(), |
| 3346 | S->getConditionVariable())); |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3347 | if (!ConditionVar) |
| 3348 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3349 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3350 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3351 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3352 | if (Cond.isInvalid()) |
| 3353 | return SemaRef.StmtError(); |
| 3354 | } |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3355 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3356 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3357 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3358 | // Transform the "then" branch. |
| 3359 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3360 | if (Then.isInvalid()) |
| 3361 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3362 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3363 | // Transform the "else" branch. |
| 3364 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3365 | if (Else.isInvalid()) |
| 3366 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3367 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3368 | if (!getDerived().AlwaysRebuild() && |
| 3369 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3370 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3371 | Then.get() == S->getThen() && |
| 3372 | Else.get() == S->getElse()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3373 | return SemaRef.Owned(S->Retain()); |
| 3374 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3375 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3376 | move(Then), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3377 | S->getElseLoc(), move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3378 | } |
| 3379 | |
| 3380 | template<typename Derived> |
| 3381 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3382 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3383 | // Transform the condition. |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3384 | OwningExprResult Cond(SemaRef); |
| 3385 | VarDecl *ConditionVar = 0; |
| 3386 | if (S->getConditionVariable()) { |
| 3387 | ConditionVar |
| 3388 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3389 | getDerived().TransformDefinition( |
| 3390 | S->getConditionVariable()->getLocation(), |
| 3391 | S->getConditionVariable())); |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3392 | if (!ConditionVar) |
| 3393 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3394 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3395 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3396 | |
| 3397 | if (Cond.isInvalid()) |
| 3398 | return SemaRef.StmtError(); |
| 3399 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3400 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3401 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3402 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3403 | // Rebuild the switch statement. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3404 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3405 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3406 | if (Switch.isInvalid()) |
| 3407 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3408 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3409 | // Transform the body of the switch statement. |
| 3410 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3411 | if (Body.isInvalid()) |
| 3412 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3413 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3414 | // Complete the switch statement. |
| 3415 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3416 | move(Body)); |
| 3417 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3418 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3419 | template<typename Derived> |
| 3420 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3421 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3422 | // Transform the condition |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3423 | OwningExprResult Cond(SemaRef); |
| 3424 | VarDecl *ConditionVar = 0; |
| 3425 | if (S->getConditionVariable()) { |
| 3426 | ConditionVar |
| 3427 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3428 | getDerived().TransformDefinition( |
| 3429 | S->getConditionVariable()->getLocation(), |
| 3430 | S->getConditionVariable())); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3431 | if (!ConditionVar) |
| 3432 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3433 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3434 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3435 | |
| 3436 | if (Cond.isInvalid()) |
| 3437 | return SemaRef.StmtError(); |
| 3438 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3439 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3440 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3441 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3442 | // Transform the body |
| 3443 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3444 | if (Body.isInvalid()) |
| 3445 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3446 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3447 | if (!getDerived().AlwaysRebuild() && |
| 3448 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3449 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3450 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3451 | return SemaRef.Owned(S->Retain()); |
| 3452 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3453 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3454 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3455 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3456 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3457 | template<typename Derived> |
| 3458 | Sema::OwningStmtResult |
| 3459 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3460 | // Transform the condition |
| 3461 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3462 | if (Cond.isInvalid()) |
| 3463 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3464 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3465 | // Transform the body |
| 3466 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3467 | if (Body.isInvalid()) |
| 3468 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3469 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3470 | if (!getDerived().AlwaysRebuild() && |
| 3471 | Cond.get() == S->getCond() && |
| 3472 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3473 | return SemaRef.Owned(S->Retain()); |
| 3474 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3475 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3476 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3477 | S->getRParenLoc()); |
| 3478 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3479 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3480 | template<typename Derived> |
| 3481 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3482 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3483 | // Transform the initialization statement |
| 3484 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3485 | if (Init.isInvalid()) |
| 3486 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3487 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3488 | // Transform the condition |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3489 | OwningExprResult Cond(SemaRef); |
| 3490 | VarDecl *ConditionVar = 0; |
| 3491 | if (S->getConditionVariable()) { |
| 3492 | ConditionVar |
| 3493 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3494 | getDerived().TransformDefinition( |
| 3495 | S->getConditionVariable()->getLocation(), |
| 3496 | S->getConditionVariable())); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3497 | if (!ConditionVar) |
| 3498 | return SemaRef.StmtError(); |
| 3499 | } else { |
| 3500 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3501 | |
| 3502 | if (Cond.isInvalid()) |
| 3503 | return SemaRef.StmtError(); |
| 3504 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3505 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3506 | // Transform the increment |
| 3507 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3508 | if (Inc.isInvalid()) |
| 3509 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3510 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3511 | // Transform the body |
| 3512 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3513 | if (Body.isInvalid()) |
| 3514 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3515 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3516 | if (!getDerived().AlwaysRebuild() && |
| 3517 | Init.get() == S->getInit() && |
| 3518 | Cond.get() == S->getCond() && |
| 3519 | Inc.get() == S->getInc() && |
| 3520 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3521 | return SemaRef.Owned(S->Retain()); |
| 3522 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3523 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3524 | move(Init), getSema().MakeFullExpr(Cond), |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3525 | ConditionVar, |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3526 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3527 | S->getRParenLoc(), move(Body)); |
| 3528 | } |
| 3529 | |
| 3530 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3531 | Sema::OwningStmtResult |
| 3532 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3533 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3534 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3535 | S->getLabel()); |
| 3536 | } |
| 3537 | |
| 3538 | template<typename Derived> |
| 3539 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3540 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3541 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3542 | if (Target.isInvalid()) |
| 3543 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3544 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3545 | if (!getDerived().AlwaysRebuild() && |
| 3546 | Target.get() == S->getTarget()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3547 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3548 | |
| 3549 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3550 | move(Target)); |
| 3551 | } |
| 3552 | |
| 3553 | template<typename Derived> |
| 3554 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3555 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3556 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3557 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3558 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3559 | template<typename Derived> |
| 3560 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3561 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3562 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3563 | } |
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 | template<typename Derived> |
| 3566 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3567 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3568 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3569 | if (Result.isInvalid()) |
| 3570 | return SemaRef.StmtError(); |
| 3571 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3572 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3573 | // to tell whether the return type of the function has changed. |
| 3574 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3575 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3576 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3577 | template<typename Derived> |
| 3578 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3579 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3580 | bool DeclChanged = false; |
| 3581 | llvm::SmallVector<Decl *, 4> Decls; |
| 3582 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3583 | D != DEnd; ++D) { |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3584 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 3585 | *D); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3586 | if (!Transformed) |
| 3587 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3588 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3589 | if (Transformed != *D) |
| 3590 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3591 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3592 | Decls.push_back(Transformed); |
| 3593 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3594 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3595 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3596 | return SemaRef.Owned(S->Retain()); |
| 3597 | |
| 3598 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3599 | S->getStartLoc(), S->getEndLoc()); |
| 3600 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3601 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3602 | template<typename Derived> |
| 3603 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3604 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3605 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3606 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3607 | } |
| 3608 | |
| 3609 | template<typename Derived> |
| 3610 | Sema::OwningStmtResult |
| 3611 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3612 | |
| 3613 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3614 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3615 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3616 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3617 | OwningExprResult AsmString(SemaRef); |
| 3618 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3619 | |
| 3620 | bool ExprsChanged = false; |
| 3621 | |
| 3622 | // Go through the outputs. |
| 3623 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3624 | Names.push_back(S->getOutputIdentifier(I)); |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3625 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3626 | // No need to transform the constraint literal. |
| 3627 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
| 3628 | |
| 3629 | // Transform the output expr. |
| 3630 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3631 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3632 | if (Result.isInvalid()) |
| 3633 | return SemaRef.StmtError(); |
| 3634 | |
| 3635 | ExprsChanged |= Result.get() != OutputExpr; |
| 3636 | |
| 3637 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3638 | } |
| 3639 | |
| 3640 | // Go through the inputs. |
| 3641 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3642 | Names.push_back(S->getInputIdentifier(I)); |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3643 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3644 | // No need to transform the constraint literal. |
| 3645 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
| 3646 | |
| 3647 | // Transform the input expr. |
| 3648 | Expr *InputExpr = S->getInputExpr(I); |
| 3649 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3650 | if (Result.isInvalid()) |
| 3651 | return SemaRef.StmtError(); |
| 3652 | |
| 3653 | ExprsChanged |= Result.get() != InputExpr; |
| 3654 | |
| 3655 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3656 | } |
| 3657 | |
| 3658 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3659 | return SemaRef.Owned(S->Retain()); |
| 3660 | |
| 3661 | // Go through the clobbers. |
| 3662 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3663 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3664 | |
| 3665 | // No need to transform the asm string literal. |
| 3666 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3667 | |
| 3668 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3669 | S->isSimple(), |
| 3670 | S->isVolatile(), |
| 3671 | S->getNumOutputs(), |
| 3672 | S->getNumInputs(), |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3673 | Names.data(), |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3674 | move_arg(Constraints), |
| 3675 | move_arg(Exprs), |
| 3676 | move(AsmString), |
| 3677 | move_arg(Clobbers), |
| 3678 | S->getRParenLoc(), |
| 3679 | S->isMSAsm()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3680 | } |
| 3681 | |
| 3682 | |
| 3683 | template<typename Derived> |
| 3684 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3685 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame^] | 3686 | // Transform the body of the @try. |
| 3687 | OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
| 3688 | if (TryBody.isInvalid()) |
| 3689 | return SemaRef.StmtError(); |
| 3690 | |
| 3691 | // Transform the @catch statement (if present). |
| 3692 | OwningStmtResult Catch(SemaRef); |
| 3693 | if (S->getCatchStmts()) { |
| 3694 | Catch = getDerived().TransformStmt(S->getCatchStmts()); |
| 3695 | if (Catch.isInvalid()) |
| 3696 | return SemaRef.StmtError(); |
| 3697 | } |
| 3698 | |
| 3699 | // Transform the @finally statement (if present). |
| 3700 | OwningStmtResult Finally(SemaRef); |
| 3701 | if (S->getFinallyStmt()) { |
| 3702 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 3703 | if (Finally.isInvalid()) |
| 3704 | return SemaRef.StmtError(); |
| 3705 | } |
| 3706 | |
| 3707 | // If nothing changed, just retain this statement. |
| 3708 | if (!getDerived().AlwaysRebuild() && |
| 3709 | TryBody.get() == S->getTryBody() && |
| 3710 | Catch.get() == S->getCatchStmts() && |
| 3711 | Finally.get() == S->getFinallyStmt()) |
| 3712 | return SemaRef.Owned(S->Retain()); |
| 3713 | |
| 3714 | // Build a new statement. |
| 3715 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody), |
| 3716 | move(Catch), move(Finally)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3717 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3718 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3719 | template<typename Derived> |
| 3720 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3721 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3722 | // FIXME: Implement this |
| 3723 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3724 | return SemaRef.Owned(S->Retain()); |
| 3725 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3726 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3727 | template<typename Derived> |
| 3728 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3729 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame^] | 3730 | // Transform the body. |
| 3731 | OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
| 3732 | if (Body.isInvalid()) |
| 3733 | return SemaRef.StmtError(); |
| 3734 | |
| 3735 | // If nothing changed, just retain this statement. |
| 3736 | if (!getDerived().AlwaysRebuild() && |
| 3737 | Body.get() == S->getFinallyBody()) |
| 3738 | return SemaRef.Owned(S->Retain()); |
| 3739 | |
| 3740 | // Build a new statement. |
| 3741 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
| 3742 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3743 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3744 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3745 | template<typename Derived> |
| 3746 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3747 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 3748 | OwningExprResult Operand(SemaRef); |
| 3749 | if (S->getThrowExpr()) { |
| 3750 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 3751 | if (Operand.isInvalid()) |
| 3752 | return getSema().StmtError(); |
| 3753 | } |
| 3754 | |
| 3755 | if (!getDerived().AlwaysRebuild() && |
| 3756 | Operand.get() == S->getThrowExpr()) |
| 3757 | return getSema().Owned(S->Retain()); |
| 3758 | |
| 3759 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3760 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3761 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3762 | template<typename Derived> |
| 3763 | Sema::OwningStmtResult |
| 3764 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3765 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 3766 | // Transform the object we are locking. |
| 3767 | OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
| 3768 | if (Object.isInvalid()) |
| 3769 | return SemaRef.StmtError(); |
| 3770 | |
| 3771 | // Transform the body. |
| 3772 | OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
| 3773 | if (Body.isInvalid()) |
| 3774 | return SemaRef.StmtError(); |
| 3775 | |
| 3776 | // If nothing change, just retain the current statement. |
| 3777 | if (!getDerived().AlwaysRebuild() && |
| 3778 | Object.get() == S->getSynchExpr() && |
| 3779 | Body.get() == S->getSynchBody()) |
| 3780 | return SemaRef.Owned(S->Retain()); |
| 3781 | |
| 3782 | // Build a new statement. |
| 3783 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
| 3784 | move(Object), move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3785 | } |
| 3786 | |
| 3787 | template<typename Derived> |
| 3788 | Sema::OwningStmtResult |
| 3789 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3790 | ObjCForCollectionStmt *S) { |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 3791 | // Transform the element statement. |
| 3792 | OwningStmtResult Element = getDerived().TransformStmt(S->getElement()); |
| 3793 | if (Element.isInvalid()) |
| 3794 | return SemaRef.StmtError(); |
| 3795 | |
| 3796 | // Transform the collection expression. |
| 3797 | OwningExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
| 3798 | if (Collection.isInvalid()) |
| 3799 | return SemaRef.StmtError(); |
| 3800 | |
| 3801 | // Transform the body. |
| 3802 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3803 | if (Body.isInvalid()) |
| 3804 | return SemaRef.StmtError(); |
| 3805 | |
| 3806 | // If nothing changed, just retain this statement. |
| 3807 | if (!getDerived().AlwaysRebuild() && |
| 3808 | Element.get() == S->getElement() && |
| 3809 | Collection.get() == S->getCollection() && |
| 3810 | Body.get() == S->getBody()) |
| 3811 | return SemaRef.Owned(S->Retain()); |
| 3812 | |
| 3813 | // Build a new statement. |
| 3814 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 3815 | /*FIXME:*/S->getForLoc(), |
| 3816 | move(Element), |
| 3817 | move(Collection), |
| 3818 | S->getRParenLoc(), |
| 3819 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3820 | } |
| 3821 | |
| 3822 | |
| 3823 | template<typename Derived> |
| 3824 | Sema::OwningStmtResult |
| 3825 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3826 | // Transform the exception declaration, if any. |
| 3827 | VarDecl *Var = 0; |
| 3828 | if (S->getExceptionDecl()) { |
| 3829 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3830 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3831 | ExceptionDecl->getDeclName()); |
| 3832 | |
| 3833 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3834 | if (T.isNull()) |
| 3835 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3836 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3837 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3838 | T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3839 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3840 | ExceptionDecl->getIdentifier(), |
| 3841 | ExceptionDecl->getLocation(), |
| 3842 | /*FIXME: Inaccurate*/ |
| 3843 | SourceRange(ExceptionDecl->getLocation())); |
| 3844 | if (!Var || Var->isInvalidDecl()) { |
| 3845 | if (Var) |
| 3846 | Var->Destroy(SemaRef.Context); |
| 3847 | return SemaRef.StmtError(); |
| 3848 | } |
| 3849 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3850 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3851 | // Transform the actual exception handler. |
| 3852 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3853 | if (Handler.isInvalid()) { |
| 3854 | if (Var) |
| 3855 | Var->Destroy(SemaRef.Context); |
| 3856 | return SemaRef.StmtError(); |
| 3857 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3858 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3859 | if (!getDerived().AlwaysRebuild() && |
| 3860 | !Var && |
| 3861 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3862 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3863 | |
| 3864 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3865 | Var, |
| 3866 | move(Handler)); |
| 3867 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3868 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3869 | template<typename Derived> |
| 3870 | Sema::OwningStmtResult |
| 3871 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3872 | // Transform the try block itself. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3873 | OwningStmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3874 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3875 | if (TryBlock.isInvalid()) |
| 3876 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3877 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3878 | // Transform the handlers. |
| 3879 | bool HandlerChanged = false; |
| 3880 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3881 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3882 | OwningStmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3883 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3884 | if (Handler.isInvalid()) |
| 3885 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3886 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3887 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3888 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3889 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3890 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3891 | if (!getDerived().AlwaysRebuild() && |
| 3892 | TryBlock.get() == S->getTryBlock() && |
| 3893 | !HandlerChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3894 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3895 | |
| 3896 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3897 | move_arg(Handlers)); |
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 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3901 | // Expression transformation |
| 3902 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3903 | template<typename Derived> |
| 3904 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3905 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3906 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3907 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3908 | |
| 3909 | template<typename Derived> |
| 3910 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3911 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3912 | NestedNameSpecifier *Qualifier = 0; |
| 3913 | if (E->getQualifier()) { |
| 3914 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3915 | E->getQualifierRange()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3916 | if (!Qualifier) |
| 3917 | return SemaRef.ExprError(); |
| 3918 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3919 | |
| 3920 | ValueDecl *ND |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3921 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 3922 | E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3923 | if (!ND) |
| 3924 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3925 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3926 | if (!getDerived().AlwaysRebuild() && |
| 3927 | Qualifier == E->getQualifier() && |
| 3928 | ND == E->getDecl() && |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3929 | !E->hasExplicitTemplateArgumentList()) { |
| 3930 | |
| 3931 | // Mark it referenced in the new context regardless. |
| 3932 | // FIXME: this is a bit instantiation-specific. |
| 3933 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 3934 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3935 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3936 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3937 | |
| 3938 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 3939 | if (E->hasExplicitTemplateArgumentList()) { |
| 3940 | TemplateArgs = &TransArgs; |
| 3941 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3942 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 3943 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3944 | TemplateArgumentLoc Loc; |
| 3945 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 3946 | return SemaRef.ExprError(); |
| 3947 | TransArgs.addArgument(Loc); |
| 3948 | } |
| 3949 | } |
| 3950 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3951 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3952 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3953 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3954 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3955 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3956 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3957 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3958 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3959 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3960 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3961 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3962 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3963 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3964 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3965 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3966 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3967 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3968 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3969 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3970 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3971 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3972 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3973 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3974 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3975 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3976 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3977 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3978 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3979 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3980 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3981 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3982 | return SemaRef.Owned(E->Retain()); |
| 3983 | } |
| 3984 | |
| 3985 | template<typename Derived> |
| 3986 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3987 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3988 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3989 | if (SubExpr.isInvalid()) |
| 3990 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3991 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3992 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3993 | return SemaRef.Owned(E->Retain()); |
| 3994 | |
| 3995 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3996 | E->getRParen()); |
| 3997 | } |
| 3998 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3999 | template<typename Derived> |
| 4000 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4001 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 4002 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4003 | if (SubExpr.isInvalid()) |
| 4004 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4005 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4006 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4007 | return SemaRef.Owned(E->Retain()); |
| 4008 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4009 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 4010 | E->getOpcode(), |
| 4011 | move(SubExpr)); |
| 4012 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4013 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4014 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4015 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4016 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4017 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4018 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4019 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4020 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4021 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4022 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4023 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4024 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4025 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4026 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4027 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4028 | E->isSizeOf(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4029 | E->getSourceRange()); |
| 4030 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4031 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4032 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4033 | { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4034 | // C++0x [expr.sizeof]p1: |
| 4035 | // The operand is either an expression, which is an unevaluated operand |
| 4036 | // [...] |
| 4037 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4038 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4039 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 4040 | if (SubExpr.isInvalid()) |
| 4041 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4042 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4043 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 4044 | return SemaRef.Owned(E->Retain()); |
| 4045 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4046 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4047 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 4048 | E->isSizeOf(), |
| 4049 | E->getSourceRange()); |
| 4050 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4051 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4052 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4053 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4054 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4055 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4056 | if (LHS.isInvalid()) |
| 4057 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4058 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4059 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4060 | if (RHS.isInvalid()) |
| 4061 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4062 | |
| 4063 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4064 | if (!getDerived().AlwaysRebuild() && |
| 4065 | LHS.get() == E->getLHS() && |
| 4066 | RHS.get() == E->getRHS()) |
| 4067 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4068 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4069 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 4070 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 4071 | move(RHS), |
| 4072 | E->getRBracketLoc()); |
| 4073 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4074 | |
| 4075 | template<typename Derived> |
| 4076 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4077 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4078 | // Transform the callee. |
| 4079 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4080 | if (Callee.isInvalid()) |
| 4081 | return SemaRef.ExprError(); |
| 4082 | |
| 4083 | // Transform arguments. |
| 4084 | bool ArgChanged = false; |
| 4085 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4086 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4087 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 4088 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4089 | if (Arg.isInvalid()) |
| 4090 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4091 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4092 | // FIXME: Wrong source location information for the ','. |
| 4093 | FakeCommaLocs.push_back( |
| 4094 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4095 | |
| 4096 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4097 | Args.push_back(Arg.takeAs<Expr>()); |
| 4098 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4099 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4100 | if (!getDerived().AlwaysRebuild() && |
| 4101 | Callee.get() == E->getCallee() && |
| 4102 | !ArgChanged) |
| 4103 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4104 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4105 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4106 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4107 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 4108 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 4109 | move_arg(Args), |
| 4110 | FakeCommaLocs.data(), |
| 4111 | E->getRParenLoc()); |
| 4112 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4113 | |
| 4114 | template<typename Derived> |
| 4115 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4116 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4117 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4118 | if (Base.isInvalid()) |
| 4119 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4120 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4121 | NestedNameSpecifier *Qualifier = 0; |
| 4122 | if (E->hasQualifier()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4123 | Qualifier |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4124 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4125 | E->getQualifierRange()); |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 4126 | if (Qualifier == 0) |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4127 | return SemaRef.ExprError(); |
| 4128 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4129 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 4130 | ValueDecl *Member |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4131 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 4132 | E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4133 | if (!Member) |
| 4134 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4135 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4136 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 4137 | if (FoundDecl == E->getMemberDecl()) { |
| 4138 | FoundDecl = Member; |
| 4139 | } else { |
| 4140 | FoundDecl = cast_or_null<NamedDecl>( |
| 4141 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 4142 | if (!FoundDecl) |
| 4143 | return SemaRef.ExprError(); |
| 4144 | } |
| 4145 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4146 | if (!getDerived().AlwaysRebuild() && |
| 4147 | Base.get() == E->getBase() && |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4148 | Qualifier == E->getQualifier() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4149 | Member == E->getMemberDecl() && |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4150 | FoundDecl == E->getFoundDecl() && |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4151 | !E->hasExplicitTemplateArgumentList()) { |
| 4152 | |
| 4153 | // Mark it referenced in the new context regardless. |
| 4154 | // FIXME: this is a bit instantiation-specific. |
| 4155 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4156 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4157 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4158 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4159 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4160 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4161 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4162 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4163 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4164 | TemplateArgumentLoc Loc; |
| 4165 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4166 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4167 | TransArgs.addArgument(Loc); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4168 | } |
| 4169 | } |
| 4170 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4171 | // FIXME: Bogus source location for the operator |
| 4172 | SourceLocation FakeOperatorLoc |
| 4173 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 4174 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4175 | // FIXME: to do this check properly, we will need to preserve the |
| 4176 | // first-qualifier-in-scope here, just in case we had a dependent |
| 4177 | // base (and therefore couldn't do the check) and a |
| 4178 | // nested-name-qualifier (and therefore could do the lookup). |
| 4179 | NamedDecl *FirstQualifierInScope = 0; |
| 4180 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4181 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 4182 | E->isArrow(), |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4183 | Qualifier, |
| 4184 | E->getQualifierRange(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4185 | E->getMemberLoc(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4186 | Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4187 | FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4188 | (E->hasExplicitTemplateArgumentList() |
| 4189 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4190 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4191 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4192 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4193 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4194 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4195 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4196 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4197 | if (LHS.isInvalid()) |
| 4198 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4199 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4200 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4201 | if (RHS.isInvalid()) |
| 4202 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4203 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4204 | if (!getDerived().AlwaysRebuild() && |
| 4205 | LHS.get() == E->getLHS() && |
| 4206 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4207 | return SemaRef.Owned(E->Retain()); |
| 4208 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4209 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 4210 | move(LHS), move(RHS)); |
| 4211 | } |
| 4212 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4213 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4214 | Sema::OwningExprResult |
| 4215 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4216 | CompoundAssignOperator *E) { |
| 4217 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4218 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4219 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4220 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4221 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4222 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4223 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4224 | if (Cond.isInvalid()) |
| 4225 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4226 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4227 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4228 | if (LHS.isInvalid()) |
| 4229 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4230 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4231 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4232 | if (RHS.isInvalid()) |
| 4233 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4234 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4235 | if (!getDerived().AlwaysRebuild() && |
| 4236 | Cond.get() == E->getCond() && |
| 4237 | LHS.get() == E->getLHS() && |
| 4238 | RHS.get() == E->getRHS()) |
| 4239 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4240 | |
| 4241 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4242 | E->getQuestionLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4243 | move(LHS), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4244 | E->getColonLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4245 | move(RHS)); |
| 4246 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4247 | |
| 4248 | template<typename Derived> |
| 4249 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4250 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4251 | // Implicit casts are eliminated during transformation, since they |
| 4252 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4253 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4254 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4255 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4256 | template<typename Derived> |
| 4257 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4258 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4259 | TypeSourceInfo *OldT; |
| 4260 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4261 | { |
| 4262 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4263 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4264 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 4265 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4266 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4267 | OldT = E->getTypeInfoAsWritten(); |
| 4268 | NewT = getDerived().TransformType(OldT); |
| 4269 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4270 | return SemaRef.ExprError(); |
| 4271 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4272 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4273 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4274 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4275 | if (SubExpr.isInvalid()) |
| 4276 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4277 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4278 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4279 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4280 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4281 | return SemaRef.Owned(E->Retain()); |
| 4282 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4283 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 4284 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4285 | E->getRParenLoc(), |
| 4286 | move(SubExpr)); |
| 4287 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4288 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4289 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4290 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4291 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4292 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 4293 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 4294 | if (!NewT) |
| 4295 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4296 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4297 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 4298 | if (Init.isInvalid()) |
| 4299 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4300 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4301 | if (!getDerived().AlwaysRebuild() && |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4302 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4303 | Init.get() == E->getInitializer()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4304 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4305 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 4306 | // Note: the expression type doesn't necessarily match the |
| 4307 | // type-as-written, but that's okay, because it should always be |
| 4308 | // derivable from the initializer. |
| 4309 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4310 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4311 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 4312 | move(Init)); |
| 4313 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4314 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4315 | template<typename Derived> |
| 4316 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4317 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4318 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4319 | if (Base.isInvalid()) |
| 4320 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4321 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4322 | if (!getDerived().AlwaysRebuild() && |
| 4323 | Base.get() == E->getBase()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4324 | return SemaRef.Owned(E->Retain()); |
| 4325 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4326 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4327 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4328 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 4329 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 4330 | E->getAccessorLoc(), |
| 4331 | E->getAccessor()); |
| 4332 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4333 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4334 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4335 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4336 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4337 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4338 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4339 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4340 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4341 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4342 | if (Init.isInvalid()) |
| 4343 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4344 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4345 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4346 | Inits.push_back(Init.takeAs<Expr>()); |
| 4347 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4348 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4349 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4350 | return SemaRef.Owned(E->Retain()); |
| 4351 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4352 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4353 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4354 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4355 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4356 | template<typename Derived> |
| 4357 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4358 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4359 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4360 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4361 | // transform the initializer value |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4362 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4363 | if (Init.isInvalid()) |
| 4364 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4365 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4366 | // transform the designators. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4367 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4368 | bool ExprChanged = false; |
| 4369 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4370 | DEnd = E->designators_end(); |
| 4371 | D != DEnd; ++D) { |
| 4372 | if (D->isFieldDesignator()) { |
| 4373 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4374 | D->getDotLoc(), |
| 4375 | D->getFieldLoc())); |
| 4376 | continue; |
| 4377 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4378 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4379 | if (D->isArrayDesignator()) { |
| 4380 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4381 | if (Index.isInvalid()) |
| 4382 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4383 | |
| 4384 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4385 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4386 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4387 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4388 | ArrayExprs.push_back(Index.release()); |
| 4389 | continue; |
| 4390 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4391 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4392 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4393 | OwningExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4394 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4395 | if (Start.isInvalid()) |
| 4396 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4397 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4398 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4399 | if (End.isInvalid()) |
| 4400 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4401 | |
| 4402 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4403 | End.get(), |
| 4404 | D->getLBracketLoc(), |
| 4405 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4406 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4407 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4408 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4409 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4410 | ArrayExprs.push_back(Start.release()); |
| 4411 | ArrayExprs.push_back(End.release()); |
| 4412 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4413 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4414 | if (!getDerived().AlwaysRebuild() && |
| 4415 | Init.get() == E->getInit() && |
| 4416 | !ExprChanged) |
| 4417 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4418 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4419 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4420 | E->getEqualOrColonLoc(), |
| 4421 | E->usesGNUSyntax(), move(Init)); |
| 4422 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4423 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4424 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4425 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4426 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4427 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4428 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4429 | |
| 4430 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4431 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4432 | QualType T = getDerived().TransformType(E->getType()); |
| 4433 | if (T.isNull()) |
| 4434 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4435 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4436 | if (!getDerived().AlwaysRebuild() && |
| 4437 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4438 | return SemaRef.Owned(E->Retain()); |
| 4439 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4440 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4441 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4442 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4443 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4444 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4445 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4446 | // FIXME: Do we want the type as written? |
| 4447 | QualType T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4448 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4449 | { |
| 4450 | // FIXME: Source location isn't quite accurate. |
| 4451 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4452 | T = getDerived().TransformType(E->getType()); |
| 4453 | if (T.isNull()) |
| 4454 | return SemaRef.ExprError(); |
| 4455 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4456 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4457 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4458 | if (SubExpr.isInvalid()) |
| 4459 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4460 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4461 | if (!getDerived().AlwaysRebuild() && |
| 4462 | T == E->getType() && |
| 4463 | SubExpr.get() == E->getSubExpr()) |
| 4464 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4465 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4466 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4467 | T, E->getRParenLoc()); |
| 4468 | } |
| 4469 | |
| 4470 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4471 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4472 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4473 | bool ArgumentChanged = false; |
| 4474 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4475 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4476 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4477 | if (Init.isInvalid()) |
| 4478 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4479 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4480 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4481 | Inits.push_back(Init.takeAs<Expr>()); |
| 4482 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4483 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4484 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4485 | move_arg(Inits), |
| 4486 | E->getRParenLoc()); |
| 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 | /// \brief Transform an address-of-label expression. |
| 4490 | /// |
| 4491 | /// By default, the transformation of an address-of-label expression always |
| 4492 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4493 | /// the corresponding label statement by semantic analysis. |
| 4494 | template<typename Derived> |
| 4495 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4496 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4497 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4498 | E->getLabel()); |
| 4499 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4500 | |
| 4501 | template<typename Derived> |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4502 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4503 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4504 | OwningStmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4505 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4506 | if (SubStmt.isInvalid()) |
| 4507 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4508 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4509 | if (!getDerived().AlwaysRebuild() && |
| 4510 | SubStmt.get() == E->getSubStmt()) |
| 4511 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4512 | |
| 4513 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4514 | move(SubStmt), |
| 4515 | E->getRParenLoc()); |
| 4516 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4517 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4518 | template<typename Derived> |
| 4519 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4520 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4521 | QualType T1, T2; |
| 4522 | { |
| 4523 | // FIXME: Source location isn't quite accurate. |
| 4524 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4525 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4526 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4527 | if (T1.isNull()) |
| 4528 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4529 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4530 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4531 | if (T2.isNull()) |
| 4532 | return SemaRef.ExprError(); |
| 4533 | } |
| 4534 | |
| 4535 | if (!getDerived().AlwaysRebuild() && |
| 4536 | T1 == E->getArgType1() && |
| 4537 | T2 == E->getArgType2()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4538 | return SemaRef.Owned(E->Retain()); |
| 4539 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4540 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4541 | T1, T2, E->getRParenLoc()); |
| 4542 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4543 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4544 | template<typename Derived> |
| 4545 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4546 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4547 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4548 | if (Cond.isInvalid()) |
| 4549 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4550 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4551 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4552 | if (LHS.isInvalid()) |
| 4553 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4554 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4555 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4556 | if (RHS.isInvalid()) |
| 4557 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4558 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4559 | if (!getDerived().AlwaysRebuild() && |
| 4560 | Cond.get() == E->getCond() && |
| 4561 | LHS.get() == E->getLHS() && |
| 4562 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4563 | return SemaRef.Owned(E->Retain()); |
| 4564 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4565 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4566 | move(Cond), move(LHS), move(RHS), |
| 4567 | E->getRParenLoc()); |
| 4568 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4569 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4570 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4571 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4572 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4573 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4574 | } |
| 4575 | |
| 4576 | template<typename Derived> |
| 4577 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4578 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4579 | switch (E->getOperator()) { |
| 4580 | case OO_New: |
| 4581 | case OO_Delete: |
| 4582 | case OO_Array_New: |
| 4583 | case OO_Array_Delete: |
| 4584 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4585 | return SemaRef.ExprError(); |
| 4586 | |
| 4587 | case OO_Call: { |
| 4588 | // This is a call to an object's operator(). |
| 4589 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4590 | |
| 4591 | // Transform the object itself. |
| 4592 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4593 | if (Object.isInvalid()) |
| 4594 | return SemaRef.ExprError(); |
| 4595 | |
| 4596 | // FIXME: Poor location information |
| 4597 | SourceLocation FakeLParenLoc |
| 4598 | = SemaRef.PP.getLocForEndOfToken( |
| 4599 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4600 | |
| 4601 | // Transform the call arguments. |
| 4602 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4603 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4604 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4605 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4606 | break; |
| 4607 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4608 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4609 | if (Arg.isInvalid()) |
| 4610 | return SemaRef.ExprError(); |
| 4611 | |
| 4612 | // FIXME: Poor source location information. |
| 4613 | SourceLocation FakeCommaLoc |
| 4614 | = SemaRef.PP.getLocForEndOfToken( |
| 4615 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4616 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4617 | Args.push_back(Arg.release()); |
| 4618 | } |
| 4619 | |
| 4620 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4621 | move_arg(Args), |
| 4622 | FakeCommaLocs.data(), |
| 4623 | E->getLocEnd()); |
| 4624 | } |
| 4625 | |
| 4626 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4627 | case OO_##Name: |
| 4628 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4629 | #include "clang/Basic/OperatorKinds.def" |
| 4630 | case OO_Subscript: |
| 4631 | // Handled below. |
| 4632 | break; |
| 4633 | |
| 4634 | case OO_Conditional: |
| 4635 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4636 | return SemaRef.ExprError(); |
| 4637 | |
| 4638 | case OO_None: |
| 4639 | case NUM_OVERLOADED_OPERATORS: |
| 4640 | llvm_unreachable("not an overloaded operator?"); |
| 4641 | return SemaRef.ExprError(); |
| 4642 | } |
| 4643 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4644 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4645 | if (Callee.isInvalid()) |
| 4646 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4647 | |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4648 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4649 | if (First.isInvalid()) |
| 4650 | return SemaRef.ExprError(); |
| 4651 | |
| 4652 | OwningExprResult Second(SemaRef); |
| 4653 | if (E->getNumArgs() == 2) { |
| 4654 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4655 | if (Second.isInvalid()) |
| 4656 | return SemaRef.ExprError(); |
| 4657 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4658 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4659 | if (!getDerived().AlwaysRebuild() && |
| 4660 | Callee.get() == E->getCallee() && |
| 4661 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4662 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4663 | return SemaRef.Owned(E->Retain()); |
| 4664 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4665 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4666 | E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4667 | move(Callee), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4668 | move(First), |
| 4669 | move(Second)); |
| 4670 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4671 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4672 | template<typename Derived> |
| 4673 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4674 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4675 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4676 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4677 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4678 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4679 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4680 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4681 | TypeSourceInfo *OldT; |
| 4682 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4683 | { |
| 4684 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4685 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4686 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4687 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4688 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4689 | OldT = E->getTypeInfoAsWritten(); |
| 4690 | NewT = getDerived().TransformType(OldT); |
| 4691 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4692 | return SemaRef.ExprError(); |
| 4693 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4694 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4695 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4696 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4697 | if (SubExpr.isInvalid()) |
| 4698 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4699 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4700 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4701 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4702 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4703 | return SemaRef.Owned(E->Retain()); |
| 4704 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4705 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4706 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4707 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4708 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4709 | SourceLocation FakeRParenLoc |
| 4710 | = SemaRef.PP.getLocForEndOfToken( |
| 4711 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4712 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4713 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4714 | FakeLAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4715 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4716 | FakeRAngleLoc, |
| 4717 | FakeRAngleLoc, |
| 4718 | move(SubExpr), |
| 4719 | FakeRParenLoc); |
| 4720 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4721 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4722 | template<typename Derived> |
| 4723 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4724 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4725 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4726 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4727 | |
| 4728 | template<typename Derived> |
| 4729 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4730 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4731 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4732 | } |
| 4733 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4734 | template<typename Derived> |
| 4735 | Sema::OwningExprResult |
| 4736 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4737 | CXXReinterpretCastExpr *E) { |
| 4738 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4739 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4740 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4741 | template<typename Derived> |
| 4742 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4743 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4744 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4745 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4746 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4747 | template<typename Derived> |
| 4748 | Sema::OwningExprResult |
| 4749 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4750 | CXXFunctionalCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4751 | TypeSourceInfo *OldT; |
| 4752 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4753 | { |
| 4754 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4755 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4756 | OldT = E->getTypeInfoAsWritten(); |
| 4757 | NewT = getDerived().TransformType(OldT); |
| 4758 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4759 | return SemaRef.ExprError(); |
| 4760 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4761 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4762 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4763 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4764 | if (SubExpr.isInvalid()) |
| 4765 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4766 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4767 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4768 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4769 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4770 | return SemaRef.Owned(E->Retain()); |
| 4771 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4772 | // FIXME: The end of the type's source range is wrong |
| 4773 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4774 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4775 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4776 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4777 | move(SubExpr), |
| 4778 | E->getRParenLoc()); |
| 4779 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4780 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4781 | template<typename Derived> |
| 4782 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4783 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4784 | if (E->isTypeOperand()) { |
| 4785 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4786 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4787 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4788 | if (T.isNull()) |
| 4789 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4790 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4791 | if (!getDerived().AlwaysRebuild() && |
| 4792 | T == E->getTypeOperand()) |
| 4793 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4794 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4795 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4796 | /*FIXME:*/E->getLocStart(), |
| 4797 | T, |
| 4798 | E->getLocEnd()); |
| 4799 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4800 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4801 | // We don't know whether the expression is potentially evaluated until |
| 4802 | // after we perform semantic analysis, so the expression is potentially |
| 4803 | // potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4804 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4805 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4806 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4807 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4808 | if (SubExpr.isInvalid()) |
| 4809 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4810 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4811 | if (!getDerived().AlwaysRebuild() && |
| 4812 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4813 | return SemaRef.Owned(E->Retain()); |
| 4814 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4815 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4816 | /*FIXME:*/E->getLocStart(), |
| 4817 | move(SubExpr), |
| 4818 | E->getLocEnd()); |
| 4819 | } |
| 4820 | |
| 4821 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4822 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4823 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4824 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 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 |
| 4829 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4830 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4831 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4832 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4833 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4834 | template<typename Derived> |
| 4835 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4836 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4837 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4838 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4839 | QualType T = getDerived().TransformType(E->getType()); |
| 4840 | if (T.isNull()) |
| 4841 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4842 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4843 | if (!getDerived().AlwaysRebuild() && |
| 4844 | T == E->getType()) |
| 4845 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4846 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 4847 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4848 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4849 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4850 | template<typename Derived> |
| 4851 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4852 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4853 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4854 | if (SubExpr.isInvalid()) |
| 4855 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4856 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4857 | if (!getDerived().AlwaysRebuild() && |
| 4858 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4859 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4860 | |
| 4861 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4862 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4863 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4864 | template<typename Derived> |
| 4865 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4866 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4867 | ParmVarDecl *Param |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4868 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 4869 | E->getParam())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4870 | if (!Param) |
| 4871 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4872 | |
Chandler Carruth | 53cb6f8 | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 4873 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4874 | Param == E->getParam()) |
| 4875 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4876 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 4877 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4878 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4879 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4880 | template<typename Derived> |
| 4881 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4882 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4883 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4884 | |
| 4885 | QualType T = getDerived().TransformType(E->getType()); |
| 4886 | if (T.isNull()) |
| 4887 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4888 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4889 | if (!getDerived().AlwaysRebuild() && |
| 4890 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4891 | return SemaRef.Owned(E->Retain()); |
| 4892 | |
| 4893 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4894 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4895 | T, |
| 4896 | E->getRParenLoc()); |
| 4897 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4898 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4899 | template<typename Derived> |
| 4900 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4901 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4902 | // Transform the type that we're allocating |
| 4903 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4904 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4905 | if (AllocType.isNull()) |
| 4906 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4907 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4908 | // Transform the size of the array we're allocating (if any). |
| 4909 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4910 | if (ArraySize.isInvalid()) |
| 4911 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4912 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4913 | // Transform the placement arguments (if any). |
| 4914 | bool ArgumentChanged = false; |
| 4915 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4916 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4917 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4918 | if (Arg.isInvalid()) |
| 4919 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4920 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4921 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4922 | PlacementArgs.push_back(Arg.take()); |
| 4923 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4924 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4925 | // transform the constructor arguments (if any). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4926 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4927 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4928 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4929 | if (Arg.isInvalid()) |
| 4930 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4931 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4932 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4933 | ConstructorArgs.push_back(Arg.take()); |
| 4934 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4935 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4936 | // Transform constructor, new operator, and delete operator. |
| 4937 | CXXConstructorDecl *Constructor = 0; |
| 4938 | if (E->getConstructor()) { |
| 4939 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4940 | getDerived().TransformDecl(E->getLocStart(), |
| 4941 | E->getConstructor())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4942 | if (!Constructor) |
| 4943 | return SemaRef.ExprError(); |
| 4944 | } |
| 4945 | |
| 4946 | FunctionDecl *OperatorNew = 0; |
| 4947 | if (E->getOperatorNew()) { |
| 4948 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4949 | getDerived().TransformDecl(E->getLocStart(), |
| 4950 | E->getOperatorNew())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4951 | if (!OperatorNew) |
| 4952 | return SemaRef.ExprError(); |
| 4953 | } |
| 4954 | |
| 4955 | FunctionDecl *OperatorDelete = 0; |
| 4956 | if (E->getOperatorDelete()) { |
| 4957 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4958 | getDerived().TransformDecl(E->getLocStart(), |
| 4959 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4960 | if (!OperatorDelete) |
| 4961 | return SemaRef.ExprError(); |
| 4962 | } |
| 4963 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4964 | if (!getDerived().AlwaysRebuild() && |
| 4965 | AllocType == E->getAllocatedType() && |
| 4966 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4967 | Constructor == E->getConstructor() && |
| 4968 | OperatorNew == E->getOperatorNew() && |
| 4969 | OperatorDelete == E->getOperatorDelete() && |
| 4970 | !ArgumentChanged) { |
| 4971 | // Mark any declarations we need as referenced. |
| 4972 | // FIXME: instantiation-specific. |
| 4973 | if (Constructor) |
| 4974 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 4975 | if (OperatorNew) |
| 4976 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 4977 | if (OperatorDelete) |
| 4978 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4979 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4980 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4981 | |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 4982 | if (!ArraySize.get()) { |
| 4983 | // If no array size was specified, but the new expression was |
| 4984 | // instantiated with an array type (e.g., "new T" where T is |
| 4985 | // instantiated with "int[4]"), extract the outer bound from the |
| 4986 | // array type as our array size. We do this with constant and |
| 4987 | // dependently-sized array types. |
| 4988 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 4989 | if (!ArrayT) { |
| 4990 | // Do nothing |
| 4991 | } else if (const ConstantArrayType *ConsArrayT |
| 4992 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 4993 | ArraySize |
| 4994 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 4995 | ConsArrayT->getSize(), |
| 4996 | SemaRef.Context.getSizeType(), |
| 4997 | /*FIXME:*/E->getLocStart())); |
| 4998 | AllocType = ConsArrayT->getElementType(); |
| 4999 | } else if (const DependentSizedArrayType *DepArrayT |
| 5000 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 5001 | if (DepArrayT->getSizeExpr()) { |
| 5002 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 5003 | AllocType = DepArrayT->getElementType(); |
| 5004 | } |
| 5005 | } |
| 5006 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5007 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 5008 | E->isGlobalNew(), |
| 5009 | /*FIXME:*/E->getLocStart(), |
| 5010 | move_arg(PlacementArgs), |
| 5011 | /*FIXME:*/E->getLocStart(), |
| 5012 | E->isParenTypeId(), |
| 5013 | AllocType, |
| 5014 | /*FIXME:*/E->getLocStart(), |
| 5015 | /*FIXME:*/SourceRange(), |
| 5016 | move(ArraySize), |
| 5017 | /*FIXME:*/E->getLocStart(), |
| 5018 | move_arg(ConstructorArgs), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5019 | E->getLocEnd()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5020 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5021 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5022 | template<typename Derived> |
| 5023 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5024 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5025 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 5026 | if (Operand.isInvalid()) |
| 5027 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5028 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5029 | // Transform the delete operator, if known. |
| 5030 | FunctionDecl *OperatorDelete = 0; |
| 5031 | if (E->getOperatorDelete()) { |
| 5032 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5033 | getDerived().TransformDecl(E->getLocStart(), |
| 5034 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5035 | if (!OperatorDelete) |
| 5036 | return SemaRef.ExprError(); |
| 5037 | } |
| 5038 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5039 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5040 | Operand.get() == E->getArgument() && |
| 5041 | OperatorDelete == E->getOperatorDelete()) { |
| 5042 | // Mark any declarations we need as referenced. |
| 5043 | // FIXME: instantiation-specific. |
| 5044 | if (OperatorDelete) |
| 5045 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5046 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5047 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5048 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5049 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 5050 | E->isGlobalDelete(), |
| 5051 | E->isArrayForm(), |
| 5052 | move(Operand)); |
| 5053 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5054 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5055 | template<typename Derived> |
| 5056 | Sema::OwningExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5057 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5058 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5059 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 5060 | if (Base.isInvalid()) |
| 5061 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5062 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5063 | Sema::TypeTy *ObjectTypePtr = 0; |
| 5064 | bool MayBePseudoDestructor = false; |
| 5065 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5066 | E->getOperatorLoc(), |
| 5067 | E->isArrow()? tok::arrow : tok::period, |
| 5068 | ObjectTypePtr, |
| 5069 | MayBePseudoDestructor); |
| 5070 | if (Base.isInvalid()) |
| 5071 | return SemaRef.ExprError(); |
| 5072 | |
| 5073 | QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5074 | NestedNameSpecifier *Qualifier |
| 5075 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | b10cd04 | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 5076 | E->getQualifierRange(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5077 | ObjectType); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5078 | if (E->getQualifier() && !Qualifier) |
| 5079 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5080 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5081 | PseudoDestructorTypeStorage Destroyed; |
| 5082 | if (E->getDestroyedTypeInfo()) { |
| 5083 | TypeSourceInfo *DestroyedTypeInfo |
| 5084 | = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType); |
| 5085 | if (!DestroyedTypeInfo) |
| 5086 | return SemaRef.ExprError(); |
| 5087 | Destroyed = DestroyedTypeInfo; |
| 5088 | } else if (ObjectType->isDependentType()) { |
| 5089 | // We aren't likely to be able to resolve the identifier down to a type |
| 5090 | // now anyway, so just retain the identifier. |
| 5091 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 5092 | E->getDestroyedTypeLoc()); |
| 5093 | } else { |
| 5094 | // Look for a destructor known with the given name. |
| 5095 | CXXScopeSpec SS; |
| 5096 | if (Qualifier) { |
| 5097 | SS.setScopeRep(Qualifier); |
| 5098 | SS.setRange(E->getQualifierRange()); |
| 5099 | } |
| 5100 | |
| 5101 | Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(), |
| 5102 | *E->getDestroyedTypeIdentifier(), |
| 5103 | E->getDestroyedTypeLoc(), |
| 5104 | /*Scope=*/0, |
| 5105 | SS, ObjectTypePtr, |
| 5106 | false); |
| 5107 | if (!T) |
| 5108 | return SemaRef.ExprError(); |
| 5109 | |
| 5110 | Destroyed |
| 5111 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 5112 | E->getDestroyedTypeLoc()); |
| 5113 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5114 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5115 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 5116 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5117 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(), |
| 5118 | ObjectType); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5119 | if (!ScopeTypeInfo) |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5120 | return SemaRef.ExprError(); |
| 5121 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5122 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5123 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 5124 | E->getOperatorLoc(), |
| 5125 | E->isArrow(), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5126 | Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5127 | E->getQualifierRange(), |
| 5128 | ScopeTypeInfo, |
| 5129 | E->getColonColonLoc(), |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 5130 | E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5131 | Destroyed); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5132 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5133 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5134 | template<typename Derived> |
| 5135 | Sema::OwningExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5136 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5137 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5138 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 5139 | |
| 5140 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 5141 | Sema::LookupOrdinaryName); |
| 5142 | |
| 5143 | // Transform all the decls. |
| 5144 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 5145 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5146 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5147 | getDerived().TransformDecl(Old->getNameLoc(), |
| 5148 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5149 | if (!InstD) { |
| 5150 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5151 | // This can happen because of dependent hiding. |
| 5152 | if (isa<UsingShadowDecl>(*I)) |
| 5153 | continue; |
| 5154 | else |
| 5155 | return SemaRef.ExprError(); |
| 5156 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5157 | |
| 5158 | // Expand using declarations. |
| 5159 | if (isa<UsingDecl>(InstD)) { |
| 5160 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5161 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5162 | E = UD->shadow_end(); I != E; ++I) |
| 5163 | R.addDecl(*I); |
| 5164 | continue; |
| 5165 | } |
| 5166 | |
| 5167 | R.addDecl(InstD); |
| 5168 | } |
| 5169 | |
| 5170 | // Resolve a kind, but don't do any further analysis. If it's |
| 5171 | // ambiguous, the callee needs to deal with it. |
| 5172 | R.resolveKind(); |
| 5173 | |
| 5174 | // Rebuild the nested-name qualifier, if present. |
| 5175 | CXXScopeSpec SS; |
| 5176 | NestedNameSpecifier *Qualifier = 0; |
| 5177 | if (Old->getQualifier()) { |
| 5178 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5179 | Old->getQualifierRange()); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5180 | if (!Qualifier) |
| 5181 | return SemaRef.ExprError(); |
| 5182 | |
| 5183 | SS.setScopeRep(Qualifier); |
| 5184 | SS.setRange(Old->getQualifierRange()); |
| 5185 | } |
| 5186 | |
| 5187 | // If we have no template arguments, it's a normal declaration name. |
| 5188 | if (!Old->hasExplicitTemplateArgs()) |
| 5189 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 5190 | |
| 5191 | // If we have template arguments, rebuild them, then rebuild the |
| 5192 | // templateid expression. |
| 5193 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 5194 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5195 | TemplateArgumentLoc Loc; |
| 5196 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 5197 | return SemaRef.ExprError(); |
| 5198 | TransArgs.addArgument(Loc); |
| 5199 | } |
| 5200 | |
| 5201 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 5202 | TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5203 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5204 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5205 | template<typename Derived> |
| 5206 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5207 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5208 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5209 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5210 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 5211 | if (T.isNull()) |
| 5212 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5213 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5214 | if (!getDerived().AlwaysRebuild() && |
| 5215 | T == E->getQueriedType()) |
| 5216 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5217 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5218 | // FIXME: Bad location information |
| 5219 | SourceLocation FakeLParenLoc |
| 5220 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5221 | |
| 5222 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5223 | E->getLocStart(), |
| 5224 | /*FIXME:*/FakeLParenLoc, |
| 5225 | T, |
| 5226 | E->getLocEnd()); |
| 5227 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5228 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5229 | template<typename Derived> |
| 5230 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5231 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5232 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5233 | NestedNameSpecifier *NNS |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5234 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5235 | E->getQualifierRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5236 | if (!NNS) |
| 5237 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5238 | |
| 5239 | DeclarationName Name |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5240 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 5241 | if (!Name) |
| 5242 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5243 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5244 | if (!E->hasExplicitTemplateArgs()) { |
| 5245 | if (!getDerived().AlwaysRebuild() && |
| 5246 | NNS == E->getQualifier() && |
| 5247 | Name == E->getDeclName()) |
| 5248 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5249 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5250 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5251 | E->getQualifierRange(), |
| 5252 | Name, E->getLocation(), |
| 5253 | /*TemplateArgs*/ 0); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5254 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5255 | |
| 5256 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5257 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5258 | TemplateArgumentLoc Loc; |
| 5259 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5260 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5261 | TransArgs.addArgument(Loc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5262 | } |
| 5263 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5264 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5265 | E->getQualifierRange(), |
| 5266 | Name, E->getLocation(), |
| 5267 | &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5268 | } |
| 5269 | |
| 5270 | template<typename Derived> |
| 5271 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5272 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 5273 | // CXXConstructExprs are always implicit, so when we have a |
| 5274 | // 1-argument construction we just transform that argument. |
| 5275 | if (E->getNumArgs() == 1 || |
| 5276 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 5277 | return getDerived().TransformExpr(E->getArg(0)); |
| 5278 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5279 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 5280 | |
| 5281 | QualType T = getDerived().TransformType(E->getType()); |
| 5282 | if (T.isNull()) |
| 5283 | return SemaRef.ExprError(); |
| 5284 | |
| 5285 | CXXConstructorDecl *Constructor |
| 5286 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5287 | getDerived().TransformDecl(E->getLocStart(), |
| 5288 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5289 | if (!Constructor) |
| 5290 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5291 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5292 | bool ArgumentChanged = false; |
| 5293 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5294 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5295 | ArgEnd = E->arg_end(); |
| 5296 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5297 | if (getDerived().DropCallArgument(*Arg)) { |
| 5298 | ArgumentChanged = true; |
| 5299 | break; |
| 5300 | } |
| 5301 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5302 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5303 | if (TransArg.isInvalid()) |
| 5304 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5305 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5306 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5307 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5308 | } |
| 5309 | |
| 5310 | if (!getDerived().AlwaysRebuild() && |
| 5311 | T == E->getType() && |
| 5312 | Constructor == E->getConstructor() && |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5313 | !ArgumentChanged) { |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5314 | // Mark the constructor as referenced. |
| 5315 | // FIXME: Instantiation-specific |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5316 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5317 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5318 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5319 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 5320 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 5321 | Constructor, E->isElidable(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5322 | move_arg(Args)); |
| 5323 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5324 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5325 | /// \brief Transform a C++ temporary-binding expression. |
| 5326 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5327 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 5328 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5329 | template<typename Derived> |
| 5330 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5331 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5332 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5333 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5334 | |
Anders Carlsson | eb60edf | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 5335 | /// \brief Transform a C++ reference-binding expression. |
| 5336 | /// |
| 5337 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 5338 | /// transform the subexpression and return that. |
| 5339 | template<typename Derived> |
| 5340 | Sema::OwningExprResult |
| 5341 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 5342 | return getDerived().TransformExpr(E->getSubExpr()); |
| 5343 | } |
| 5344 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5345 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5346 | /// be destroyed after the expression is evaluated. |
| 5347 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5348 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 5349 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5350 | template<typename Derived> |
| 5351 | Sema::OwningExprResult |
| 5352 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5353 | CXXExprWithTemporaries *E) { |
| 5354 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5355 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5356 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5357 | template<typename Derived> |
| 5358 | Sema::OwningExprResult |
| 5359 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5360 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5361 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5362 | QualType T = getDerived().TransformType(E->getType()); |
| 5363 | if (T.isNull()) |
| 5364 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5365 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5366 | CXXConstructorDecl *Constructor |
| 5367 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5368 | getDerived().TransformDecl(E->getLocStart(), |
| 5369 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5370 | if (!Constructor) |
| 5371 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5372 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5373 | bool ArgumentChanged = false; |
| 5374 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5375 | Args.reserve(E->getNumArgs()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5376 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5377 | ArgEnd = E->arg_end(); |
| 5378 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5379 | if (getDerived().DropCallArgument(*Arg)) { |
| 5380 | ArgumentChanged = true; |
| 5381 | break; |
| 5382 | } |
| 5383 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5384 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5385 | if (TransArg.isInvalid()) |
| 5386 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5387 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5388 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5389 | Args.push_back((Expr *)TransArg.release()); |
| 5390 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5391 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5392 | if (!getDerived().AlwaysRebuild() && |
| 5393 | T == E->getType() && |
| 5394 | Constructor == E->getConstructor() && |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5395 | !ArgumentChanged) { |
| 5396 | // FIXME: Instantiation-specific |
| 5397 | SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor); |
Chandler Carruth | a3ce8ae | 2010-03-31 18:34:58 +0000 | [diff] [blame] | 5398 | return SemaRef.MaybeBindToTemporary(E->Retain()); |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5399 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5400 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5401 | // FIXME: Bogus location information |
| 5402 | SourceLocation CommaLoc; |
| 5403 | if (Args.size() > 1) { |
| 5404 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5405 | CommaLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5406 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 5407 | } |
| 5408 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 5409 | T, |
| 5410 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5411 | move_arg(Args), |
| 5412 | &CommaLoc, |
| 5413 | E->getLocEnd()); |
| 5414 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5415 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5416 | template<typename Derived> |
| 5417 | Sema::OwningExprResult |
| 5418 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5419 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5420 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5421 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 5422 | if (T.isNull()) |
| 5423 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5424 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5425 | bool ArgumentChanged = false; |
| 5426 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5427 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 5428 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 5429 | ArgEnd = E->arg_end(); |
| 5430 | Arg != ArgEnd; ++Arg) { |
| 5431 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5432 | if (TransArg.isInvalid()) |
| 5433 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5434 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5435 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5436 | FakeCommaLocs.push_back( |
| 5437 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 5438 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5439 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5440 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5441 | if (!getDerived().AlwaysRebuild() && |
| 5442 | T == E->getTypeAsWritten() && |
| 5443 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5444 | return SemaRef.Owned(E->Retain()); |
| 5445 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5446 | // FIXME: we're faking the locations of the commas |
| 5447 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5448 | T, |
| 5449 | E->getLParenLoc(), |
| 5450 | move_arg(Args), |
| 5451 | FakeCommaLocs.data(), |
| 5452 | E->getRParenLoc()); |
| 5453 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5454 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5455 | template<typename Derived> |
| 5456 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5457 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5458 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5459 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5460 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5461 | Expr *OldBase; |
| 5462 | QualType BaseType; |
| 5463 | QualType ObjectType; |
| 5464 | if (!E->isImplicitAccess()) { |
| 5465 | OldBase = E->getBase(); |
| 5466 | Base = getDerived().TransformExpr(OldBase); |
| 5467 | if (Base.isInvalid()) |
| 5468 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5469 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5470 | // Start the member reference and compute the object's type. |
| 5471 | Sema::TypeTy *ObjectTy = 0; |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5472 | bool MayBePseudoDestructor = false; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5473 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5474 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5475 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5476 | ObjectTy, |
| 5477 | MayBePseudoDestructor); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5478 | if (Base.isInvalid()) |
| 5479 | return SemaRef.ExprError(); |
| 5480 | |
| 5481 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5482 | BaseType = ((Expr*) Base.get())->getType(); |
| 5483 | } else { |
| 5484 | OldBase = 0; |
| 5485 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5486 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5487 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5488 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5489 | // Transform the first part of the nested-name-specifier that qualifies |
| 5490 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5491 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5492 | = getDerived().TransformFirstQualifierInScope( |
| 5493 | E->getFirstQualifierFoundInScope(), |
| 5494 | E->getQualifierRange().getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5495 | |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5496 | NestedNameSpecifier *Qualifier = 0; |
| 5497 | if (E->getQualifier()) { |
| 5498 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5499 | E->getQualifierRange(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5500 | ObjectType, |
| 5501 | FirstQualifierInScope); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5502 | if (!Qualifier) |
| 5503 | return SemaRef.ExprError(); |
| 5504 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5505 | |
| 5506 | DeclarationName Name |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5507 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5508 | ObjectType); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5509 | if (!Name) |
| 5510 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5511 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5512 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5513 | // This is a reference to a member without an explicitly-specified |
| 5514 | // template argument list. Optimize for this common case. |
| 5515 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5516 | Base.get() == OldBase && |
| 5517 | BaseType == E->getBaseType() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5518 | Qualifier == E->getQualifier() && |
| 5519 | Name == E->getMember() && |
| 5520 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5521 | return SemaRef.Owned(E->Retain()); |
| 5522 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5523 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5524 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5525 | E->isArrow(), |
| 5526 | E->getOperatorLoc(), |
| 5527 | Qualifier, |
| 5528 | E->getQualifierRange(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5529 | FirstQualifierInScope, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5530 | Name, |
| 5531 | E->getMemberLoc(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5532 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5533 | } |
| 5534 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5535 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5536 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5537 | TemplateArgumentLoc Loc; |
| 5538 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5539 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5540 | TransArgs.addArgument(Loc); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5541 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5542 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5543 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5544 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5545 | E->isArrow(), |
| 5546 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5547 | Qualifier, |
| 5548 | E->getQualifierRange(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5549 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5550 | Name, |
| 5551 | E->getMemberLoc(), |
| 5552 | &TransArgs); |
| 5553 | } |
| 5554 | |
| 5555 | template<typename Derived> |
| 5556 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5557 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5558 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5559 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5560 | QualType BaseType; |
| 5561 | if (!Old->isImplicitAccess()) { |
| 5562 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5563 | if (Base.isInvalid()) |
| 5564 | return SemaRef.ExprError(); |
| 5565 | BaseType = ((Expr*) Base.get())->getType(); |
| 5566 | } else { |
| 5567 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5568 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5569 | |
| 5570 | NestedNameSpecifier *Qualifier = 0; |
| 5571 | if (Old->getQualifier()) { |
| 5572 | Qualifier |
| 5573 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5574 | Old->getQualifierRange()); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5575 | if (Qualifier == 0) |
| 5576 | return SemaRef.ExprError(); |
| 5577 | } |
| 5578 | |
| 5579 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5580 | Sema::LookupOrdinaryName); |
| 5581 | |
| 5582 | // Transform all the decls. |
| 5583 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5584 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5585 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5586 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 5587 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5588 | if (!InstD) { |
| 5589 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5590 | // This can happen because of dependent hiding. |
| 5591 | if (isa<UsingShadowDecl>(*I)) |
| 5592 | continue; |
| 5593 | else |
| 5594 | return SemaRef.ExprError(); |
| 5595 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5596 | |
| 5597 | // Expand using declarations. |
| 5598 | if (isa<UsingDecl>(InstD)) { |
| 5599 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5600 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5601 | E = UD->shadow_end(); I != E; ++I) |
| 5602 | R.addDecl(*I); |
| 5603 | continue; |
| 5604 | } |
| 5605 | |
| 5606 | R.addDecl(InstD); |
| 5607 | } |
| 5608 | |
| 5609 | R.resolveKind(); |
| 5610 | |
| 5611 | TemplateArgumentListInfo TransArgs; |
| 5612 | if (Old->hasExplicitTemplateArgs()) { |
| 5613 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5614 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5615 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5616 | TemplateArgumentLoc Loc; |
| 5617 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5618 | Loc)) |
| 5619 | return SemaRef.ExprError(); |
| 5620 | TransArgs.addArgument(Loc); |
| 5621 | } |
| 5622 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5623 | |
| 5624 | // FIXME: to do this check properly, we will need to preserve the |
| 5625 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5626 | // base (and therefore couldn't do the check) and a |
| 5627 | // nested-name-qualifier (and therefore could do the lookup). |
| 5628 | NamedDecl *FirstQualifierInScope = 0; |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5629 | |
| 5630 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5631 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5632 | Old->getOperatorLoc(), |
| 5633 | Old->isArrow(), |
| 5634 | Qualifier, |
| 5635 | Old->getQualifierRange(), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5636 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5637 | R, |
| 5638 | (Old->hasExplicitTemplateArgs() |
| 5639 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5640 | } |
| 5641 | |
| 5642 | template<typename Derived> |
| 5643 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5644 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5645 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5646 | } |
| 5647 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5648 | template<typename Derived> |
| 5649 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5650 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5651 | TypeSourceInfo *EncodedTypeInfo |
| 5652 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 5653 | if (!EncodedTypeInfo) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5654 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5655 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5656 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5657 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5658 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5659 | |
| 5660 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5661 | EncodedTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5662 | E->getRParenLoc()); |
| 5663 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5664 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5665 | template<typename Derived> |
| 5666 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5667 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5668 | // Transform arguments. |
| 5669 | bool ArgChanged = false; |
| 5670 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5671 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 5672 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 5673 | if (Arg.isInvalid()) |
| 5674 | return SemaRef.ExprError(); |
| 5675 | |
| 5676 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
| 5677 | Args.push_back(Arg.takeAs<Expr>()); |
| 5678 | } |
| 5679 | |
| 5680 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 5681 | // Class message: transform the receiver type. |
| 5682 | TypeSourceInfo *ReceiverTypeInfo |
| 5683 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 5684 | if (!ReceiverTypeInfo) |
| 5685 | return SemaRef.ExprError(); |
| 5686 | |
| 5687 | // If nothing changed, just retain the existing message send. |
| 5688 | if (!getDerived().AlwaysRebuild() && |
| 5689 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
| 5690 | return SemaRef.Owned(E->Retain()); |
| 5691 | |
| 5692 | // Build a new class message send. |
| 5693 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 5694 | E->getSelector(), |
| 5695 | E->getMethodDecl(), |
| 5696 | E->getLeftLoc(), |
| 5697 | move_arg(Args), |
| 5698 | E->getRightLoc()); |
| 5699 | } |
| 5700 | |
| 5701 | // Instance message: transform the receiver |
| 5702 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 5703 | "Only class and instance messages may be instantiated"); |
| 5704 | OwningExprResult Receiver |
| 5705 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 5706 | if (Receiver.isInvalid()) |
| 5707 | return SemaRef.ExprError(); |
| 5708 | |
| 5709 | // If nothing changed, just retain the existing message send. |
| 5710 | if (!getDerived().AlwaysRebuild() && |
| 5711 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
| 5712 | return SemaRef.Owned(E->Retain()); |
| 5713 | |
| 5714 | // Build a new instance message send. |
| 5715 | return getDerived().RebuildObjCMessageExpr(move(Receiver), |
| 5716 | E->getSelector(), |
| 5717 | E->getMethodDecl(), |
| 5718 | E->getLeftLoc(), |
| 5719 | move_arg(Args), |
| 5720 | E->getRightLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5721 | } |
| 5722 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5723 | template<typename Derived> |
| 5724 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5725 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5726 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5727 | } |
| 5728 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5729 | template<typename Derived> |
| 5730 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5731 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5732 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5733 | } |
| 5734 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5735 | template<typename Derived> |
| 5736 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5737 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5738 | // FIXME: Implement this! |
| 5739 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5740 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5741 | } |
| 5742 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5743 | template<typename Derived> |
| 5744 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5745 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5746 | // FIXME: Implement this! |
| 5747 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5748 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5749 | } |
| 5750 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5751 | template<typename Derived> |
| 5752 | Sema::OwningExprResult |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5753 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5754 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5755 | // FIXME: Implement this! |
| 5756 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5757 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5758 | } |
| 5759 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5760 | template<typename Derived> |
| 5761 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5762 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5763 | // Can never occur in a dependent context. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5764 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5765 | } |
| 5766 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5767 | template<typename Derived> |
| 5768 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5769 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5770 | // FIXME: Implement this! |
| 5771 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5772 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5773 | } |
| 5774 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5775 | template<typename Derived> |
| 5776 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5777 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5778 | bool ArgumentChanged = false; |
| 5779 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5780 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5781 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5782 | if (SubExpr.isInvalid()) |
| 5783 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5784 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5785 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5786 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5787 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5788 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5789 | if (!getDerived().AlwaysRebuild() && |
| 5790 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5791 | return SemaRef.Owned(E->Retain()); |
| 5792 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5793 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5794 | move_arg(SubExprs), |
| 5795 | E->getRParenLoc()); |
| 5796 | } |
| 5797 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5798 | template<typename Derived> |
| 5799 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5800 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5801 | // FIXME: Implement this! |
| 5802 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5803 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5804 | } |
| 5805 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5806 | template<typename Derived> |
| 5807 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5808 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5809 | // FIXME: Implement this! |
| 5810 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5811 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5812 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5813 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5814 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5815 | // Type reconstruction |
| 5816 | //===----------------------------------------------------------------------===// |
| 5817 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5818 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5819 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5820 | SourceLocation Star) { |
| 5821 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5822 | getDerived().getBaseEntity()); |
| 5823 | } |
| 5824 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5825 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5826 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5827 | SourceLocation Star) { |
| 5828 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5829 | getDerived().getBaseEntity()); |
| 5830 | } |
| 5831 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5832 | template<typename Derived> |
| 5833 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5834 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5835 | bool WrittenAsLValue, |
| 5836 | SourceLocation Sigil) { |
| 5837 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5838 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5839 | } |
| 5840 | |
| 5841 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5842 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5843 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5844 | QualType ClassType, |
| 5845 | SourceLocation Sigil) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5846 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5847 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5848 | } |
| 5849 | |
| 5850 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5851 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5852 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5853 | ArrayType::ArraySizeModifier SizeMod, |
| 5854 | const llvm::APInt *Size, |
| 5855 | Expr *SizeExpr, |
| 5856 | unsigned IndexTypeQuals, |
| 5857 | SourceRange BracketsRange) { |
| 5858 | if (SizeExpr || !Size) |
| 5859 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5860 | IndexTypeQuals, BracketsRange, |
| 5861 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5862 | |
| 5863 | QualType Types[] = { |
| 5864 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5865 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5866 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5867 | }; |
| 5868 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5869 | QualType SizeType; |
| 5870 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5871 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5872 | SizeType = Types[I]; |
| 5873 | break; |
| 5874 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5875 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5876 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5877 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5878 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5879 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5880 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5881 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5882 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5883 | QualType |
| 5884 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5885 | ArrayType::ArraySizeModifier SizeMod, |
| 5886 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5887 | unsigned IndexTypeQuals, |
| 5888 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5889 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5890 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5891 | } |
| 5892 | |
| 5893 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5894 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5895 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5896 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5897 | unsigned IndexTypeQuals, |
| 5898 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5899 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5900 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5901 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5902 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5903 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5904 | QualType |
| 5905 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5906 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5907 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5908 | unsigned IndexTypeQuals, |
| 5909 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5910 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5911 | SizeExpr.takeAs<Expr>(), |
| 5912 | IndexTypeQuals, BracketsRange); |
| 5913 | } |
| 5914 | |
| 5915 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5916 | QualType |
| 5917 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5918 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5919 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5920 | unsigned IndexTypeQuals, |
| 5921 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5922 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5923 | SizeExpr.takeAs<Expr>(), |
| 5924 | IndexTypeQuals, BracketsRange); |
| 5925 | } |
| 5926 | |
| 5927 | template<typename Derived> |
| 5928 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5929 | unsigned NumElements, |
| 5930 | bool IsAltiVec, bool IsPixel) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5931 | // FIXME: semantic checking! |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5932 | return SemaRef.Context.getVectorType(ElementType, NumElements, |
| 5933 | IsAltiVec, IsPixel); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5934 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5935 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5936 | template<typename Derived> |
| 5937 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5938 | unsigned NumElements, |
| 5939 | SourceLocation AttributeLoc) { |
| 5940 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5941 | NumElements, true); |
| 5942 | IntegerLiteral *VectorSize |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5943 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5944 | AttributeLoc); |
| 5945 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5946 | AttributeLoc); |
| 5947 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5948 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5949 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5950 | QualType |
| 5951 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5952 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5953 | SourceLocation AttributeLoc) { |
| 5954 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5955 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5956 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5957 | template<typename Derived> |
| 5958 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5959 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5960 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5961 | bool Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5962 | unsigned Quals) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5963 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5964 | Quals, |
| 5965 | getDerived().getBaseLocation(), |
| 5966 | getDerived().getBaseEntity()); |
| 5967 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5968 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5969 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5970 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5971 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5972 | } |
| 5973 | |
| 5974 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5975 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 5976 | assert(D && "no decl found"); |
| 5977 | if (D->isInvalidDecl()) return QualType(); |
| 5978 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5979 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5980 | TypeDecl *Ty; |
| 5981 | if (isa<UsingDecl>(D)) { |
| 5982 | UsingDecl *Using = cast<UsingDecl>(D); |
| 5983 | assert(Using->isTypeName() && |
| 5984 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 5985 | |
| 5986 | // A valid resolved using typename decl points to exactly one type decl. |
| 5987 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 5988 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 5989 | |
| 5990 | } else { |
| 5991 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 5992 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 5993 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 5994 | } |
| 5995 | |
| 5996 | return SemaRef.Context.getTypeDeclType(Ty); |
| 5997 | } |
| 5998 | |
| 5999 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6000 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6001 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 6002 | } |
| 6003 | |
| 6004 | template<typename Derived> |
| 6005 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 6006 | return SemaRef.Context.getTypeOfType(Underlying); |
| 6007 | } |
| 6008 | |
| 6009 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6010 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6011 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 6012 | } |
| 6013 | |
| 6014 | template<typename Derived> |
| 6015 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6016 | TemplateName Template, |
| 6017 | SourceLocation TemplateNameLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6018 | const TemplateArgumentListInfo &TemplateArgs) { |
| 6019 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6020 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6021 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6022 | template<typename Derived> |
| 6023 | NestedNameSpecifier * |
| 6024 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6025 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6026 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6027 | QualType ObjectType, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6028 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6029 | CXXScopeSpec SS; |
| 6030 | // FIXME: The source location information is all wrong. |
| 6031 | SS.setRange(Range); |
| 6032 | SS.setScopeRep(Prefix); |
| 6033 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6034 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 6035 | Range.getEnd(), II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6036 | ObjectType, |
| 6037 | FirstQualifierInScope, |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 6038 | false, false)); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6039 | } |
| 6040 | |
| 6041 | template<typename Derived> |
| 6042 | NestedNameSpecifier * |
| 6043 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6044 | SourceRange Range, |
| 6045 | NamespaceDecl *NS) { |
| 6046 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 6047 | } |
| 6048 | |
| 6049 | template<typename Derived> |
| 6050 | NestedNameSpecifier * |
| 6051 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6052 | SourceRange Range, |
| 6053 | bool TemplateKW, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 6054 | QualType T) { |
| 6055 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6056 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 6057 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6058 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 6059 | T.getTypePtr()); |
| 6060 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6061 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6062 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 6063 | return 0; |
| 6064 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6065 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6066 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6067 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6068 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6069 | bool TemplateKW, |
| 6070 | TemplateDecl *Template) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6071 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6072 | Template); |
| 6073 | } |
| 6074 | |
| 6075 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6076 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6077 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6078 | const IdentifierInfo &II, |
| 6079 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6080 | CXXScopeSpec SS; |
| 6081 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6082 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 6083 | UnqualifiedId Name; |
| 6084 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6085 | return getSema().ActOnDependentTemplateName( |
| 6086 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6087 | SS, |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 6088 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 6089 | ObjectType.getAsOpaquePtr(), |
| 6090 | /*EnteringContext=*/false) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6091 | .template getAsVal<TemplateName>(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6092 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6093 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6094 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6095 | TemplateName |
| 6096 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6097 | OverloadedOperatorKind Operator, |
| 6098 | QualType ObjectType) { |
| 6099 | CXXScopeSpec SS; |
| 6100 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 6101 | SS.setScopeRep(Qualifier); |
| 6102 | UnqualifiedId Name; |
| 6103 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 6104 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 6105 | Operator, SymbolLocations); |
| 6106 | return getSema().ActOnDependentTemplateName( |
| 6107 | /*FIXME:*/getDerived().getBaseLocation(), |
| 6108 | SS, |
| 6109 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 6110 | ObjectType.getAsOpaquePtr(), |
| 6111 | /*EnteringContext=*/false) |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6112 | .template getAsVal<TemplateName>(); |
| 6113 | } |
| 6114 | |
| 6115 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6116 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6117 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 6118 | SourceLocation OpLoc, |
| 6119 | ExprArg Callee, |
| 6120 | ExprArg First, |
| 6121 | ExprArg Second) { |
| 6122 | Expr *FirstExpr = (Expr *)First.get(); |
| 6123 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6124 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6125 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6126 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6127 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6128 | if (Op == OO_Subscript) { |
| 6129 | if (!FirstExpr->getType()->isOverloadableType() && |
| 6130 | !SecondExpr->getType()->isOverloadableType()) |
| 6131 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6132 | CalleeExpr->getLocStart(), |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6133 | move(Second), OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 6134 | } else if (Op == OO_Arrow) { |
| 6135 | // -> is never a builtin operation. |
| 6136 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6137 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6138 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 6139 | // The argument is not of overloadable type, so try to create a |
| 6140 | // built-in unary operation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6141 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6142 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6143 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6144 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 6145 | } |
| 6146 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6147 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6148 | !SecondExpr->getType()->isOverloadableType()) { |
| 6149 | // Neither of the arguments is an overloadable type, so try to |
| 6150 | // create a built-in binary operation. |
| 6151 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6152 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6153 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 6154 | if (Result.isInvalid()) |
| 6155 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6156 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6157 | First.release(); |
| 6158 | Second.release(); |
| 6159 | return move(Result); |
| 6160 | } |
| 6161 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6162 | |
| 6163 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6164 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6165 | UnresolvedSet<16> Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6166 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6167 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 6168 | assert(ULE->requiresADL()); |
| 6169 | |
| 6170 | // FIXME: Do we have to check |
| 6171 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6172 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6173 | } else { |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6174 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6175 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6176 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6177 | // Add any functions found via argument-dependent lookup. |
| 6178 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 6179 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6180 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6181 | // Create the overloaded operator invocation for unary operators. |
| 6182 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6183 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6184 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 6185 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 6186 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6187 | |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6188 | if (Op == OO_Subscript) |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6189 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 6190 | OpLoc, |
| 6191 | move(First), |
| 6192 | move(Second)); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6193 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6194 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6195 | BinaryOperator::Opcode Opc = |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6196 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6197 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6198 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 6199 | if (Result.isInvalid()) |
| 6200 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6201 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6202 | First.release(); |
| 6203 | Second.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6204 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6205 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6206 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6207 | template<typename Derived> |
| 6208 | Sema::OwningExprResult |
| 6209 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 6210 | SourceLocation OperatorLoc, |
| 6211 | bool isArrow, |
| 6212 | NestedNameSpecifier *Qualifier, |
| 6213 | SourceRange QualifierRange, |
| 6214 | TypeSourceInfo *ScopeType, |
| 6215 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6216 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6217 | PseudoDestructorTypeStorage Destroyed) { |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6218 | CXXScopeSpec SS; |
| 6219 | if (Qualifier) { |
| 6220 | SS.setRange(QualifierRange); |
| 6221 | SS.setScopeRep(Qualifier); |
| 6222 | } |
| 6223 | |
| 6224 | Expr *BaseE = (Expr *)Base.get(); |
| 6225 | QualType BaseType = BaseE->getType(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6226 | if (BaseE->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6227 | (!isArrow && !BaseType->getAs<RecordType>()) || |
| 6228 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | bf2ca2f | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 6229 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 6230 | ->template getAs<RecordType>())){ |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6231 | // This pseudo-destructor expression is still a pseudo-destructor. |
| 6232 | return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc, |
| 6233 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6234 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6235 | Destroyed, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6236 | /*FIXME?*/true); |
| 6237 | } |
| 6238 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6239 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6240 | DeclarationName Name |
| 6241 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 6242 | SemaRef.Context.getCanonicalType(DestroyedType->getType())); |
| 6243 | |
| 6244 | // FIXME: the ScopeType should be tacked onto SS. |
| 6245 | |
| 6246 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 6247 | OperatorLoc, isArrow, |
| 6248 | SS, /*FIXME: FirstQualifier*/ 0, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6249 | Name, Destroyed.getLocation(), |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6250 | /*TemplateArgs*/ 0); |
| 6251 | } |
| 6252 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6253 | } // end namespace clang |
| 6254 | |
| 6255 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |