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); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 341 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 342 | #define STMT(Node, Parent) \ |
| 343 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 344 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 345 | OwningExprResult Transform##Node(Node *E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 346 | #define ABSTRACT_EXPR(Node, Parent) |
| 347 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 348 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 349 | /// \brief Build a new pointer type given its pointee type. |
| 350 | /// |
| 351 | /// By default, performs semantic analysis when building the pointer type. |
| 352 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 353 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 354 | |
| 355 | /// \brief Build a new block pointer type given its pointee type. |
| 356 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 357 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 358 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 359 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 360 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 361 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 362 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 363 | /// By default, performs semantic analysis when building the |
| 364 | /// reference type. Subclasses may override this routine to provide |
| 365 | /// different behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 366 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 367 | /// \param LValue whether the type was written with an lvalue sigil |
| 368 | /// or an rvalue sigil. |
| 369 | QualType RebuildReferenceType(QualType ReferentType, |
| 370 | bool LValue, |
| 371 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 372 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 373 | /// \brief Build a new member pointer type given the pointee type and the |
| 374 | /// class type it refers into. |
| 375 | /// |
| 376 | /// By default, performs semantic analysis when building the member pointer |
| 377 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 378 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 379 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 380 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 381 | /// \brief Build a new Objective C object pointer type. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 382 | QualType RebuildObjCObjectPointerType(QualType PointeeType, |
| 383 | SourceLocation Sigil); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 384 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 385 | /// \brief Build a new array type given the element type, size |
| 386 | /// modifier, size of the array (if known), size expression, and index type |
| 387 | /// qualifiers. |
| 388 | /// |
| 389 | /// By default, performs semantic analysis when building the array type. |
| 390 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 391 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 392 | QualType RebuildArrayType(QualType ElementType, |
| 393 | ArrayType::ArraySizeModifier SizeMod, |
| 394 | const llvm::APInt *Size, |
| 395 | Expr *SizeExpr, |
| 396 | unsigned IndexTypeQuals, |
| 397 | SourceRange BracketsRange); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 398 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 399 | /// \brief Build a new constant array type given the element type, size |
| 400 | /// modifier, (known) size of the array, and index type qualifiers. |
| 401 | /// |
| 402 | /// By default, performs semantic analysis when building the array type. |
| 403 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 404 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 405 | ArrayType::ArraySizeModifier SizeMod, |
| 406 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 407 | unsigned IndexTypeQuals, |
| 408 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 409 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 410 | /// \brief Build a new incomplete array type given the element type, size |
| 411 | /// modifier, and index type qualifiers. |
| 412 | /// |
| 413 | /// By default, performs semantic analysis when building the array type. |
| 414 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 415 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 416 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 417 | unsigned IndexTypeQuals, |
| 418 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 419 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 420 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 421 | /// size modifier, size expression, and index type qualifiers. |
| 422 | /// |
| 423 | /// By default, performs semantic analysis when building the array type. |
| 424 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 425 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 426 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 427 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 428 | unsigned IndexTypeQuals, |
| 429 | SourceRange BracketsRange); |
| 430 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 431 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 432 | /// size modifier, size expression, and index type qualifiers. |
| 433 | /// |
| 434 | /// By default, performs semantic analysis when building the array type. |
| 435 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 436 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 437 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 438 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 439 | unsigned IndexTypeQuals, |
| 440 | SourceRange BracketsRange); |
| 441 | |
| 442 | /// \brief Build a new vector type given the element type and |
| 443 | /// number of elements. |
| 444 | /// |
| 445 | /// By default, performs semantic analysis when building the vector type. |
| 446 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 447 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
| 448 | bool IsAltiVec, bool IsPixel); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 449 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 450 | /// \brief Build a new extended vector type given the element type and |
| 451 | /// number of elements. |
| 452 | /// |
| 453 | /// By default, performs semantic analysis when building the vector type. |
| 454 | /// Subclasses may override this routine to provide different behavior. |
| 455 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 456 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 457 | |
| 458 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 459 | /// given the element type and number of elements. |
| 460 | /// |
| 461 | /// By default, performs semantic analysis when building the vector type. |
| 462 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 463 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 464 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 465 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 466 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 467 | /// \brief Build a new function type. |
| 468 | /// |
| 469 | /// By default, performs semantic analysis when building the function type. |
| 470 | /// Subclasses may override this routine to provide different behavior. |
| 471 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 472 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 473 | unsigned NumParamTypes, |
| 474 | bool Variadic, unsigned Quals); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 475 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 476 | /// \brief Build a new unprototyped function type. |
| 477 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 478 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 479 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 480 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 481 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 482 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 483 | /// \brief Build a new typedef type. |
| 484 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 485 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 486 | } |
| 487 | |
| 488 | /// \brief Build a new class/struct/union type. |
| 489 | QualType RebuildRecordType(RecordDecl *Record) { |
| 490 | return SemaRef.Context.getTypeDeclType(Record); |
| 491 | } |
| 492 | |
| 493 | /// \brief Build a new Enum type. |
| 494 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 495 | return SemaRef.Context.getTypeDeclType(Enum); |
| 496 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 497 | |
| 498 | /// \brief Build a new elaborated type. |
| 499 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) { |
| 500 | return SemaRef.Context.getElaboratedType(T, Tag); |
| 501 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 502 | |
| 503 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 504 | /// |
| 505 | /// By default, performs semantic analysis when building the typeof type. |
| 506 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 507 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 508 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 509 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 510 | /// |
| 511 | /// By default, builds a new TypeOfType with the given underlying type. |
| 512 | QualType RebuildTypeOfType(QualType Underlying); |
| 513 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 514 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 515 | /// |
| 516 | /// By default, performs semantic analysis when building the decltype type. |
| 517 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 518 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 519 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 520 | /// \brief Build a new template specialization type. |
| 521 | /// |
| 522 | /// By default, performs semantic analysis when building the template |
| 523 | /// specialization type. Subclasses may override this routine to provide |
| 524 | /// different behavior. |
| 525 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 526 | SourceLocation TemplateLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 527 | const TemplateArgumentListInfo &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 529 | /// \brief Build a new qualified name type. |
| 530 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 531 | /// By default, builds a new QualifiedNameType type from the |
| 532 | /// nested-name-specifier and the named type. Subclasses may override |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 533 | /// this routine to provide different behavior. |
| 534 | QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) { |
| 535 | return SemaRef.Context.getQualifiedNameType(NNS, Named); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 536 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 537 | |
| 538 | /// \brief Build a new typename type that refers to a template-id. |
| 539 | /// |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 540 | /// By default, builds a new DependentNameType type from the |
| 541 | /// nested-name-specifier |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 542 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 543 | /// different behavior. |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 544 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
| 545 | NestedNameSpecifier *NNS, QualType T) { |
Douglas Gregor | ae62889 | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 546 | if (NNS->isDependent()) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 547 | // 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] | 548 | CXXScopeSpec SS; |
| 549 | SS.setScopeRep(NNS); |
| 550 | if (!SemaRef.computeDeclContext(SS)) |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 551 | return SemaRef.Context.getDependentNameType(Keyword, NNS, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 552 | cast<TemplateSpecializationType>(T)); |
Douglas Gregor | ae62889 | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 553 | } |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 554 | |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 555 | // FIXME: Handle elaborated-type-specifiers separately. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 556 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 557 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 558 | |
| 559 | /// \brief Build a new typename type that refers to an identifier. |
| 560 | /// |
| 561 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 562 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 563 | /// different behavior. |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 564 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
| 565 | NestedNameSpecifier *NNS, |
| 566 | const IdentifierInfo *Id, |
| 567 | SourceRange SR) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 568 | CXXScopeSpec SS; |
| 569 | SS.setScopeRep(NNS); |
| 570 | |
| 571 | if (NNS->isDependent()) { |
| 572 | // If the name is still dependent, just build a new dependent name type. |
| 573 | if (!SemaRef.computeDeclContext(SS)) |
| 574 | return SemaRef.Context.getDependentNameType(Keyword, NNS, Id); |
| 575 | } |
| 576 | |
| 577 | TagDecl::TagKind Kind = TagDecl::TK_enum; |
| 578 | switch (Keyword) { |
| 579 | case ETK_None: |
| 580 | // FIXME: Note the lack of the "typename" specifier! |
| 581 | // Fall through |
| 582 | case ETK_Typename: |
| 583 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
| 584 | |
| 585 | case ETK_Class: Kind = TagDecl::TK_class; break; |
| 586 | case ETK_Struct: Kind = TagDecl::TK_struct; break; |
| 587 | case ETK_Union: Kind = TagDecl::TK_union; break; |
| 588 | case ETK_Enum: Kind = TagDecl::TK_enum; break; |
| 589 | } |
| 590 | |
| 591 | // We had a dependent elaborated-type-specifier that as been transformed |
| 592 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 593 | // referring to. |
| 594 | LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName); |
| 595 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 596 | if (!DC) |
| 597 | return QualType(); |
| 598 | |
| 599 | TagDecl *Tag = 0; |
| 600 | SemaRef.LookupQualifiedName(Result, DC); |
| 601 | switch (Result.getResultKind()) { |
| 602 | case LookupResult::NotFound: |
| 603 | case LookupResult::NotFoundInCurrentInstantiation: |
| 604 | break; |
| 605 | |
| 606 | case LookupResult::Found: |
| 607 | Tag = Result.getAsSingle<TagDecl>(); |
| 608 | break; |
| 609 | |
| 610 | case LookupResult::FoundOverloaded: |
| 611 | case LookupResult::FoundUnresolvedValue: |
| 612 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 613 | return QualType(); |
| 614 | |
| 615 | case LookupResult::Ambiguous: |
| 616 | // Let the LookupResult structure handle ambiguities. |
| 617 | return QualType(); |
| 618 | } |
| 619 | |
| 620 | if (!Tag) { |
Douglas Gregor | 1eabb7d | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 621 | // FIXME: Would be nice to highlight just the source range. |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 622 | SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope) |
Douglas Gregor | 1eabb7d | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 623 | << Kind << Id << DC; |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 624 | return QualType(); |
| 625 | } |
| 626 | |
| 627 | // FIXME: Terrible location information |
| 628 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) { |
| 629 | SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id; |
| 630 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 631 | return QualType(); |
| 632 | } |
| 633 | |
| 634 | // Build the elaborated-type-specifier type. |
| 635 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
| 636 | T = SemaRef.Context.getQualifiedNameType(NNS, T); |
| 637 | return SemaRef.Context.getElaboratedType(T, Kind); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 638 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 639 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 640 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 641 | /// identifier that names the next step in the nested-name-specifier. |
| 642 | /// |
| 643 | /// By default, performs semantic analysis when building the new |
| 644 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 645 | /// different behavior. |
| 646 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 647 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 648 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 649 | QualType ObjectType, |
| 650 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 651 | |
| 652 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 653 | /// namespace named in the next step in the nested-name-specifier. |
| 654 | /// |
| 655 | /// By default, performs semantic analysis when building the new |
| 656 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 657 | /// different behavior. |
| 658 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 659 | SourceRange Range, |
| 660 | NamespaceDecl *NS); |
| 661 | |
| 662 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 663 | /// type named in the next step in the nested-name-specifier. |
| 664 | /// |
| 665 | /// By default, performs semantic analysis when building the new |
| 666 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 667 | /// different behavior. |
| 668 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 669 | SourceRange Range, |
| 670 | bool TemplateKW, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 671 | QualType T); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 672 | |
| 673 | /// \brief Build a new template name given a nested name specifier, a flag |
| 674 | /// indicating whether the "template" keyword was provided, and the template |
| 675 | /// that the template name refers to. |
| 676 | /// |
| 677 | /// By default, builds the new template name directly. Subclasses may override |
| 678 | /// this routine to provide different behavior. |
| 679 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 680 | bool TemplateKW, |
| 681 | TemplateDecl *Template); |
| 682 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 683 | /// \brief Build a new template name given a nested name specifier and the |
| 684 | /// name that is referred to as a template. |
| 685 | /// |
| 686 | /// By default, performs semantic analysis to determine whether the name can |
| 687 | /// be resolved to a specific template, then builds the appropriate kind of |
| 688 | /// template name. Subclasses may override this routine to provide different |
| 689 | /// behavior. |
| 690 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 691 | const IdentifierInfo &II, |
| 692 | QualType ObjectType); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 693 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 694 | /// \brief Build a new template name given a nested name specifier and the |
| 695 | /// overloaded operator name that is referred to as a template. |
| 696 | /// |
| 697 | /// By default, performs semantic analysis to determine whether the name can |
| 698 | /// be resolved to a specific template, then builds the appropriate kind of |
| 699 | /// template name. Subclasses may override this routine to provide different |
| 700 | /// behavior. |
| 701 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 702 | OverloadedOperatorKind Operator, |
| 703 | QualType ObjectType); |
| 704 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 705 | /// \brief Build a new compound statement. |
| 706 | /// |
| 707 | /// By default, performs semantic analysis to build the new statement. |
| 708 | /// Subclasses may override this routine to provide different behavior. |
| 709 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 710 | MultiStmtArg Statements, |
| 711 | SourceLocation RBraceLoc, |
| 712 | bool IsStmtExpr) { |
| 713 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 714 | IsStmtExpr); |
| 715 | } |
| 716 | |
| 717 | /// \brief Build a new case statement. |
| 718 | /// |
| 719 | /// By default, performs semantic analysis to build the new statement. |
| 720 | /// Subclasses may override this routine to provide different behavior. |
| 721 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 722 | ExprArg LHS, |
| 723 | SourceLocation EllipsisLoc, |
| 724 | ExprArg RHS, |
| 725 | SourceLocation ColonLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 726 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 727 | ColonLoc); |
| 728 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 729 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 730 | /// \brief Attach the body to a new case statement. |
| 731 | /// |
| 732 | /// By default, performs semantic analysis to build the new statement. |
| 733 | /// Subclasses may override this routine to provide different behavior. |
| 734 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 735 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 736 | return move(S); |
| 737 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 738 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 739 | /// \brief Build a new default statement. |
| 740 | /// |
| 741 | /// By default, performs semantic analysis to build the new statement. |
| 742 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 743 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 744 | SourceLocation ColonLoc, |
| 745 | StmtArg SubStmt) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 746 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 747 | /*CurScope=*/0); |
| 748 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 749 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 750 | /// \brief Build a new label statement. |
| 751 | /// |
| 752 | /// By default, performs semantic analysis to build the new statement. |
| 753 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 754 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 755 | IdentifierInfo *Id, |
| 756 | SourceLocation ColonLoc, |
| 757 | StmtArg SubStmt) { |
| 758 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 759 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 760 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 761 | /// \brief Build a new "if" statement. |
| 762 | /// |
| 763 | /// By default, performs semantic analysis to build the new statement. |
| 764 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 765 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 766 | VarDecl *CondVar, StmtArg Then, |
| 767 | SourceLocation ElseLoc, StmtArg Else) { |
| 768 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
| 769 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 770 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 771 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 772 | /// \brief Start building a new switch statement. |
| 773 | /// |
| 774 | /// By default, performs semantic analysis to build the new statement. |
| 775 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 776 | OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond, |
| 777 | VarDecl *CondVar) { |
| 778 | return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 779 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 780 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 781 | /// \brief Attach the body to the switch statement. |
| 782 | /// |
| 783 | /// By default, performs semantic analysis to build the new statement. |
| 784 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 785 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 786 | StmtArg Switch, StmtArg Body) { |
| 787 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 788 | move(Body)); |
| 789 | } |
| 790 | |
| 791 | /// \brief Build a new while statement. |
| 792 | /// |
| 793 | /// By default, performs semantic analysis to build the new statement. |
| 794 | /// Subclasses may override this routine to provide different behavior. |
| 795 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 796 | Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 797 | VarDecl *CondVar, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 798 | StmtArg Body) { |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 799 | return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar), |
| 800 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 801 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 802 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 803 | /// \brief Build a new do-while statement. |
| 804 | /// |
| 805 | /// By default, performs semantic analysis to build the new statement. |
| 806 | /// Subclasses may override this routine to provide different behavior. |
| 807 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 808 | SourceLocation WhileLoc, |
| 809 | SourceLocation LParenLoc, |
| 810 | ExprArg Cond, |
| 811 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 812 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 813 | move(Cond), RParenLoc); |
| 814 | } |
| 815 | |
| 816 | /// \brief Build a new for statement. |
| 817 | /// |
| 818 | /// By default, performs semantic analysis to build the new statement. |
| 819 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 820 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 821 | SourceLocation LParenLoc, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 822 | StmtArg Init, Sema::FullExprArg Cond, |
| 823 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 824 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 825 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
| 826 | DeclPtrTy::make(CondVar), |
| 827 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 828 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 829 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 830 | /// \brief Build a new goto statement. |
| 831 | /// |
| 832 | /// By default, performs semantic analysis to build the new statement. |
| 833 | /// Subclasses may override this routine to provide different behavior. |
| 834 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 835 | SourceLocation LabelLoc, |
| 836 | LabelStmt *Label) { |
| 837 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 838 | } |
| 839 | |
| 840 | /// \brief Build a new indirect goto statement. |
| 841 | /// |
| 842 | /// By default, performs semantic analysis to build the new statement. |
| 843 | /// Subclasses may override this routine to provide different behavior. |
| 844 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 845 | SourceLocation StarLoc, |
| 846 | ExprArg Target) { |
| 847 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 848 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 849 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 850 | /// \brief Build a new return statement. |
| 851 | /// |
| 852 | /// By default, performs semantic analysis to build the new statement. |
| 853 | /// Subclasses may override this routine to provide different behavior. |
| 854 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 855 | ExprArg Result) { |
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 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 858 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 859 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 860 | /// \brief Build a new declaration statement. |
| 861 | /// |
| 862 | /// By default, performs semantic analysis to build the new statement. |
| 863 | /// Subclasses may override this routine to provide different behavior. |
| 864 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 865 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 866 | SourceLocation EndLoc) { |
| 867 | return getSema().Owned( |
| 868 | new (getSema().Context) DeclStmt( |
| 869 | DeclGroupRef::Create(getSema().Context, |
| 870 | Decls, NumDecls), |
| 871 | StartLoc, EndLoc)); |
| 872 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 873 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 874 | /// \brief Build a new inline asm statement. |
| 875 | /// |
| 876 | /// By default, performs semantic analysis to build the new statement. |
| 877 | /// Subclasses may override this routine to provide different behavior. |
| 878 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 879 | bool IsSimple, |
| 880 | bool IsVolatile, |
| 881 | unsigned NumOutputs, |
| 882 | unsigned NumInputs, |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 883 | IdentifierInfo **Names, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 884 | MultiExprArg Constraints, |
| 885 | MultiExprArg Exprs, |
| 886 | ExprArg AsmString, |
| 887 | MultiExprArg Clobbers, |
| 888 | SourceLocation RParenLoc, |
| 889 | bool MSAsm) { |
| 890 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 891 | NumInputs, Names, move(Constraints), |
| 892 | move(Exprs), move(AsmString), move(Clobbers), |
| 893 | RParenLoc, MSAsm); |
| 894 | } |
| 895 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 896 | /// \brief Build a new C++ exception declaration. |
| 897 | /// |
| 898 | /// By default, performs semantic analysis to build the new decaration. |
| 899 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 900 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 901 | TypeSourceInfo *Declarator, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 902 | IdentifierInfo *Name, |
| 903 | SourceLocation Loc, |
| 904 | SourceRange TypeRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 905 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 906 | TypeRange); |
| 907 | } |
| 908 | |
| 909 | /// \brief Build a new C++ catch statement. |
| 910 | /// |
| 911 | /// By default, performs semantic analysis to build the new statement. |
| 912 | /// Subclasses may override this routine to provide different behavior. |
| 913 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 914 | VarDecl *ExceptionDecl, |
| 915 | StmtArg Handler) { |
| 916 | return getSema().Owned( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 917 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 918 | Handler.takeAs<Stmt>())); |
| 919 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 920 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 921 | /// \brief Build a new C++ try statement. |
| 922 | /// |
| 923 | /// By default, performs semantic analysis to build the new statement. |
| 924 | /// Subclasses may override this routine to provide different behavior. |
| 925 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 926 | StmtArg TryBlock, |
| 927 | MultiStmtArg Handlers) { |
| 928 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 929 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 930 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 931 | /// \brief Build a new expression that references a declaration. |
| 932 | /// |
| 933 | /// By default, performs semantic analysis to build the new expression. |
| 934 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 935 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 936 | LookupResult &R, |
| 937 | bool RequiresADL) { |
| 938 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 939 | } |
| 940 | |
| 941 | |
| 942 | /// \brief Build a new expression that references a declaration. |
| 943 | /// |
| 944 | /// By default, performs semantic analysis to build the new expression. |
| 945 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 946 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 947 | SourceRange QualifierRange, |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 948 | ValueDecl *VD, SourceLocation Loc, |
| 949 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 950 | CXXScopeSpec SS; |
| 951 | SS.setScopeRep(Qualifier); |
| 952 | SS.setRange(QualifierRange); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 953 | |
| 954 | // FIXME: loses template args. |
| 955 | |
| 956 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 957 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 958 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 959 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 960 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 961 | /// By default, performs semantic analysis to build the new expression. |
| 962 | /// Subclasses may override this routine to provide different behavior. |
| 963 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 964 | SourceLocation RParen) { |
| 965 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 966 | } |
| 967 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 968 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 969 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 970 | /// By default, performs semantic analysis to build the new expression. |
| 971 | /// Subclasses may override this routine to provide different behavior. |
| 972 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 973 | SourceLocation OperatorLoc, |
| 974 | bool isArrow, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 975 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 976 | SourceRange QualifierRange, |
| 977 | TypeSourceInfo *ScopeType, |
| 978 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 979 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 980 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 981 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 982 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 983 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 984 | /// By default, performs semantic analysis to build the new expression. |
| 985 | /// Subclasses may override this routine to provide different behavior. |
| 986 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 987 | UnaryOperator::Opcode Opc, |
| 988 | ExprArg SubExpr) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 989 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 990 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 991 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 992 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 993 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 994 | /// By default, performs semantic analysis to build the new expression. |
| 995 | /// Subclasses may override this routine to provide different behavior. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 996 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 997 | SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 998 | bool isSizeOf, SourceRange R) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 999 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1002 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1003 | /// argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1004 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1005 | /// By default, performs semantic analysis to build the new expression. |
| 1006 | /// Subclasses may override this routine to provide different behavior. |
| 1007 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 1008 | bool isSizeOf, SourceRange R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1009 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1010 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 1011 | OpLoc, isSizeOf, R); |
| 1012 | if (Result.isInvalid()) |
| 1013 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1014 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1015 | SubExpr.release(); |
| 1016 | return move(Result); |
| 1017 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1018 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1019 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1020 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1021 | /// By default, performs semantic analysis to build the new expression. |
| 1022 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1023 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1024 | SourceLocation LBracketLoc, |
| 1025 | ExprArg RHS, |
| 1026 | SourceLocation RBracketLoc) { |
| 1027 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1028 | LBracketLoc, move(RHS), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1029 | RBracketLoc); |
| 1030 | } |
| 1031 | |
| 1032 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1033 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1034 | /// By default, performs semantic analysis to build the new expression. |
| 1035 | /// Subclasses may override this routine to provide different behavior. |
| 1036 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 1037 | MultiExprArg Args, |
| 1038 | SourceLocation *CommaLocs, |
| 1039 | SourceLocation RParenLoc) { |
| 1040 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 1041 | move(Args), CommaLocs, RParenLoc); |
| 1042 | } |
| 1043 | |
| 1044 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1045 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1046 | /// By default, performs semantic analysis to build the new expression. |
| 1047 | /// Subclasses may override this routine to provide different behavior. |
| 1048 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1049 | bool isArrow, |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1050 | NestedNameSpecifier *Qualifier, |
| 1051 | SourceRange QualifierRange, |
| 1052 | SourceLocation MemberLoc, |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 1053 | ValueDecl *Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1054 | NamedDecl *FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1055 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 1056 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1057 | if (!Member->getDeclName()) { |
| 1058 | // We have a reference to an unnamed field. |
| 1059 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1060 | |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1061 | Expr *BaseExpr = Base.takeAs<Expr>(); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1062 | if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, |
| 1063 | FoundDecl, Member)) |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1064 | return getSema().ExprError(); |
Douglas Gregor | 8aa5f40 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 1065 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1066 | MemberExpr *ME = |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1067 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1068 | Member, MemberLoc, |
| 1069 | cast<FieldDecl>(Member)->getType()); |
| 1070 | return getSema().Owned(ME); |
| 1071 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1072 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1073 | CXXScopeSpec SS; |
| 1074 | if (Qualifier) { |
| 1075 | SS.setRange(QualifierRange); |
| 1076 | SS.setScopeRep(Qualifier); |
| 1077 | } |
| 1078 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1079 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1080 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1081 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1082 | // cases; we should avoid this when possible. |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1083 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 1084 | Sema::LookupMemberName); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1085 | R.addDecl(FoundDecl); |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1086 | R.resolveKind(); |
| 1087 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1088 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 1089 | OpLoc, isArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1090 | SS, FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1091 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1092 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1093 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1094 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1095 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1096 | /// By default, performs semantic analysis to build the new expression. |
| 1097 | /// Subclasses may override this routine to provide different behavior. |
| 1098 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1099 | BinaryOperator::Opcode Opc, |
| 1100 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1101 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 1102 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1106 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1107 | /// By default, performs semantic analysis to build the new expression. |
| 1108 | /// Subclasses may override this routine to provide different behavior. |
| 1109 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1110 | SourceLocation QuestionLoc, |
| 1111 | ExprArg LHS, |
| 1112 | SourceLocation ColonLoc, |
| 1113 | ExprArg RHS) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1114 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1115 | move(LHS), move(RHS)); |
| 1116 | } |
| 1117 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1118 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1119 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1120 | /// By default, performs semantic analysis to build the new expression. |
| 1121 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1122 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1123 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1124 | SourceLocation RParenLoc, |
| 1125 | ExprArg SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1126 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1127 | move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1128 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1129 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1130 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1131 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1132 | /// By default, performs semantic analysis to build the new expression. |
| 1133 | /// Subclasses may override this routine to provide different behavior. |
| 1134 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1135 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1136 | SourceLocation RParenLoc, |
| 1137 | ExprArg Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1138 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1139 | move(Init)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1140 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1141 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1142 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1143 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1144 | /// By default, performs semantic analysis to build the new expression. |
| 1145 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1146 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1147 | SourceLocation OpLoc, |
| 1148 | SourceLocation AccessorLoc, |
| 1149 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1150 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1151 | CXXScopeSpec SS; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1152 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1153 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1154 | OpLoc, /*IsArrow*/ false, |
| 1155 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1156 | DeclarationName(&Accessor), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1157 | AccessorLoc, |
| 1158 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1159 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1160 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1161 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1162 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1163 | /// By default, performs semantic analysis to build the new expression. |
| 1164 | /// Subclasses may override this routine to provide different behavior. |
| 1165 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1166 | MultiExprArg Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1167 | SourceLocation RBraceLoc, |
| 1168 | QualType ResultTy) { |
| 1169 | OwningExprResult Result |
| 1170 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1171 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1172 | return move(Result); |
| 1173 | |
| 1174 | // Patch in the result type we were given, which may have been computed |
| 1175 | // when the initial InitListExpr was built. |
| 1176 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1177 | ILE->setType(ResultTy); |
| 1178 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1179 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1180 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1181 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1182 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1183 | /// By default, performs semantic analysis to build the new expression. |
| 1184 | /// Subclasses may override this routine to provide different behavior. |
| 1185 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1186 | MultiExprArg ArrayExprs, |
| 1187 | SourceLocation EqualOrColonLoc, |
| 1188 | bool GNUSyntax, |
| 1189 | ExprArg Init) { |
| 1190 | OwningExprResult Result |
| 1191 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1192 | move(Init)); |
| 1193 | if (Result.isInvalid()) |
| 1194 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1195 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1196 | ArrayExprs.release(); |
| 1197 | return move(Result); |
| 1198 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1199 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1200 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1201 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1202 | /// By default, builds the implicit value initialization without performing |
| 1203 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1204 | /// different behavior. |
| 1205 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1206 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1207 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1208 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1209 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1210 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1211 | /// By default, performs semantic analysis to build the new expression. |
| 1212 | /// Subclasses may override this routine to provide different behavior. |
| 1213 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1214 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1215 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1216 | RParenLoc); |
| 1217 | } |
| 1218 | |
| 1219 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1220 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1221 | /// By default, performs semantic analysis to build the new expression. |
| 1222 | /// Subclasses may override this routine to provide different behavior. |
| 1223 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1224 | MultiExprArg SubExprs, |
| 1225 | SourceLocation RParenLoc) { |
Fariborz Jahanian | f88f7ab | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1226 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1227 | move(SubExprs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1228 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1229 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1230 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1231 | /// |
| 1232 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1233 | /// rather than attempting to map the label statement itself. |
| 1234 | /// Subclasses may override this routine to provide different behavior. |
| 1235 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1236 | SourceLocation LabelLoc, |
| 1237 | LabelStmt *Label) { |
| 1238 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1239 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1240 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1241 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1242 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1243 | /// By default, performs semantic analysis to build the new expression. |
| 1244 | /// Subclasses may override this routine to provide different behavior. |
| 1245 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1246 | StmtArg SubStmt, |
| 1247 | SourceLocation RParenLoc) { |
| 1248 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1249 | } |
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 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1252 | /// |
| 1253 | /// By default, performs semantic analysis to build the new expression. |
| 1254 | /// Subclasses may override this routine to provide different behavior. |
| 1255 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1256 | QualType T1, QualType T2, |
| 1257 | SourceLocation RParenLoc) { |
| 1258 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1259 | T1.getAsOpaquePtr(), |
| 1260 | T2.getAsOpaquePtr(), |
| 1261 | RParenLoc); |
| 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 __builtin_choose_expr expression. |
| 1265 | /// |
| 1266 | /// By default, performs semantic analysis to build the new expression. |
| 1267 | /// Subclasses may override this routine to provide different behavior. |
| 1268 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1269 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1270 | SourceLocation RParenLoc) { |
| 1271 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1272 | move(Cond), move(LHS), move(RHS), |
| 1273 | RParenLoc); |
| 1274 | } |
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 | /// \brief Build a new overloaded operator call expression. |
| 1277 | /// |
| 1278 | /// By default, performs semantic analysis to build the new expression. |
| 1279 | /// The semantic analysis provides the behavior of template instantiation, |
| 1280 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1281 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1282 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1283 | /// provide different behavior. |
| 1284 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1285 | SourceLocation OpLoc, |
| 1286 | ExprArg Callee, |
| 1287 | ExprArg First, |
| 1288 | ExprArg Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1289 | |
| 1290 | /// \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] | 1291 | /// reinterpret_cast. |
| 1292 | /// |
| 1293 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1294 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1295 | /// Subclasses may override this routine to provide different behavior. |
| 1296 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1297 | Stmt::StmtClass Class, |
| 1298 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1299 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1300 | SourceLocation RAngleLoc, |
| 1301 | SourceLocation LParenLoc, |
| 1302 | ExprArg SubExpr, |
| 1303 | SourceLocation RParenLoc) { |
| 1304 | switch (Class) { |
| 1305 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1306 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1307 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1308 | move(SubExpr), RParenLoc); |
| 1309 | |
| 1310 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1311 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1312 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1313 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1314 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1315 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1316 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1317 | RAngleLoc, LParenLoc, |
| 1318 | move(SubExpr), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1319 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1320 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1321 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1322 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1323 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1324 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1325 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1326 | default: |
| 1327 | assert(false && "Invalid C++ named cast"); |
| 1328 | break; |
| 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 | return getSema().ExprError(); |
| 1332 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1333 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1334 | /// \brief Build a new C++ static_cast expression. |
| 1335 | /// |
| 1336 | /// By default, performs semantic analysis to build the new expression. |
| 1337 | /// Subclasses may override this routine to provide different behavior. |
| 1338 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1339 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1340 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1341 | SourceLocation RAngleLoc, |
| 1342 | SourceLocation LParenLoc, |
| 1343 | ExprArg SubExpr, |
| 1344 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1345 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1346 | TInfo, move(SubExpr), |
| 1347 | SourceRange(LAngleLoc, RAngleLoc), |
| 1348 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | /// \brief Build a new C++ dynamic_cast expression. |
| 1352 | /// |
| 1353 | /// By default, performs semantic analysis to build the new expression. |
| 1354 | /// Subclasses may override this routine to provide different behavior. |
| 1355 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1356 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1357 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1358 | SourceLocation RAngleLoc, |
| 1359 | SourceLocation LParenLoc, |
| 1360 | ExprArg SubExpr, |
| 1361 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1362 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1363 | TInfo, move(SubExpr), |
| 1364 | SourceRange(LAngleLoc, RAngleLoc), |
| 1365 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1369 | /// |
| 1370 | /// By default, performs semantic analysis to build the new expression. |
| 1371 | /// Subclasses may override this routine to provide different behavior. |
| 1372 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1373 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1374 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1375 | SourceLocation RAngleLoc, |
| 1376 | SourceLocation LParenLoc, |
| 1377 | ExprArg SubExpr, |
| 1378 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1379 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1380 | TInfo, move(SubExpr), |
| 1381 | SourceRange(LAngleLoc, RAngleLoc), |
| 1382 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | /// \brief Build a new C++ const_cast expression. |
| 1386 | /// |
| 1387 | /// By default, performs semantic analysis to build the new expression. |
| 1388 | /// Subclasses may override this routine to provide different behavior. |
| 1389 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1390 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1391 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1392 | SourceLocation RAngleLoc, |
| 1393 | SourceLocation LParenLoc, |
| 1394 | ExprArg SubExpr, |
| 1395 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1396 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1397 | TInfo, move(SubExpr), |
| 1398 | SourceRange(LAngleLoc, RAngleLoc), |
| 1399 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1400 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1401 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1402 | /// \brief Build a new C++ functional-style cast expression. |
| 1403 | /// |
| 1404 | /// By default, performs semantic analysis to build the new expression. |
| 1405 | /// Subclasses may override this routine to provide different behavior. |
| 1406 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1407 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1408 | SourceLocation LParenLoc, |
| 1409 | ExprArg SubExpr, |
| 1410 | SourceLocation RParenLoc) { |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1411 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1412 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1413 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1414 | LParenLoc, |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1415 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1416 | /*CommaLocs=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1417 | RParenLoc); |
| 1418 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1419 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1420 | /// \brief Build a new C++ typeid(type) expression. |
| 1421 | /// |
| 1422 | /// By default, performs semantic analysis to build the new expression. |
| 1423 | /// Subclasses may override this routine to provide different behavior. |
| 1424 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1425 | SourceLocation LParenLoc, |
| 1426 | QualType T, |
| 1427 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1428 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1429 | T.getAsOpaquePtr(), RParenLoc); |
| 1430 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1431 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1432 | /// \brief Build a new C++ typeid(expr) expression. |
| 1433 | /// |
| 1434 | /// By default, performs semantic analysis to build the new expression. |
| 1435 | /// Subclasses may override this routine to provide different behavior. |
| 1436 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1437 | SourceLocation LParenLoc, |
| 1438 | ExprArg Operand, |
| 1439 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1440 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1441 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1442 | RParenLoc); |
| 1443 | if (Result.isInvalid()) |
| 1444 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1445 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1446 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1447 | return move(Result); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1448 | } |
| 1449 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1450 | /// \brief Build a new C++ "this" expression. |
| 1451 | /// |
| 1452 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1453 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1454 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1455 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1456 | QualType ThisType, |
| 1457 | bool isImplicit) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1458 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1459 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1460 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | /// \brief Build a new C++ throw expression. |
| 1464 | /// |
| 1465 | /// By default, performs semantic analysis to build the new expression. |
| 1466 | /// Subclasses may override this routine to provide different behavior. |
| 1467 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1468 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1469 | } |
| 1470 | |
| 1471 | /// \brief Build a new C++ default-argument expression. |
| 1472 | /// |
| 1473 | /// By default, builds a new default-argument expression, which does not |
| 1474 | /// require any semantic analysis. Subclasses may override this routine to |
| 1475 | /// provide different behavior. |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1476 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
| 1477 | ParmVarDecl *Param) { |
| 1478 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1479 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | /// \brief Build a new C++ zero-initialization expression. |
| 1483 | /// |
| 1484 | /// By default, performs semantic analysis to build the new expression. |
| 1485 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1486 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1487 | SourceLocation LParenLoc, |
| 1488 | QualType T, |
| 1489 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1490 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1491 | T.getAsOpaquePtr(), LParenLoc, |
| 1492 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1493 | 0, RParenLoc); |
| 1494 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1495 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1496 | /// \brief Build a new C++ "new" expression. |
| 1497 | /// |
| 1498 | /// By default, performs semantic analysis to build the new expression. |
| 1499 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1500 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1501 | bool UseGlobal, |
| 1502 | SourceLocation PlacementLParen, |
| 1503 | MultiExprArg PlacementArgs, |
| 1504 | SourceLocation PlacementRParen, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1505 | bool ParenTypeId, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1506 | QualType AllocType, |
| 1507 | SourceLocation TypeLoc, |
| 1508 | SourceRange TypeRange, |
| 1509 | ExprArg ArraySize, |
| 1510 | SourceLocation ConstructorLParen, |
| 1511 | MultiExprArg ConstructorArgs, |
| 1512 | SourceLocation ConstructorRParen) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1513 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1514 | PlacementLParen, |
| 1515 | move(PlacementArgs), |
| 1516 | PlacementRParen, |
| 1517 | ParenTypeId, |
| 1518 | AllocType, |
| 1519 | TypeLoc, |
| 1520 | TypeRange, |
| 1521 | move(ArraySize), |
| 1522 | ConstructorLParen, |
| 1523 | move(ConstructorArgs), |
| 1524 | ConstructorRParen); |
| 1525 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1526 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1527 | /// \brief Build a new C++ "delete" expression. |
| 1528 | /// |
| 1529 | /// By default, performs semantic analysis to build the new expression. |
| 1530 | /// Subclasses may override this routine to provide different behavior. |
| 1531 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1532 | bool IsGlobalDelete, |
| 1533 | bool IsArrayForm, |
| 1534 | ExprArg Operand) { |
| 1535 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1536 | move(Operand)); |
| 1537 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1538 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1539 | /// \brief Build a new unary type trait expression. |
| 1540 | /// |
| 1541 | /// By default, performs semantic analysis to build the new expression. |
| 1542 | /// Subclasses may override this routine to provide different behavior. |
| 1543 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1544 | SourceLocation StartLoc, |
| 1545 | SourceLocation LParenLoc, |
| 1546 | QualType T, |
| 1547 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1548 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1549 | T.getAsOpaquePtr(), RParenLoc); |
| 1550 | } |
| 1551 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1552 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1553 | /// expression. |
| 1554 | /// |
| 1555 | /// By default, performs semantic analysis to build the new expression. |
| 1556 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1557 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1558 | SourceRange QualifierRange, |
| 1559 | DeclarationName Name, |
| 1560 | SourceLocation Location, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1561 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1562 | CXXScopeSpec SS; |
| 1563 | SS.setRange(QualifierRange); |
| 1564 | SS.setScopeRep(NNS); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1565 | |
| 1566 | if (TemplateArgs) |
| 1567 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1568 | *TemplateArgs); |
| 1569 | |
| 1570 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | /// \brief Build a new template-id expression. |
| 1574 | /// |
| 1575 | /// By default, performs semantic analysis to build the new expression. |
| 1576 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1577 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1578 | LookupResult &R, |
| 1579 | bool RequiresADL, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1580 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1581 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | /// \brief Build a new object-construction expression. |
| 1585 | /// |
| 1586 | /// By default, performs semantic analysis to build the new expression. |
| 1587 | /// Subclasses may override this routine to provide different behavior. |
| 1588 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1589 | SourceLocation Loc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1590 | CXXConstructorDecl *Constructor, |
| 1591 | bool IsElidable, |
| 1592 | MultiExprArg Args) { |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1593 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
| 1594 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
| 1595 | ConvertedArgs)) |
| 1596 | return getSema().ExprError(); |
| 1597 | |
| 1598 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1599 | move_arg(ConvertedArgs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | /// \brief Build a new object-construction expression. |
| 1603 | /// |
| 1604 | /// By default, performs semantic analysis to build the new expression. |
| 1605 | /// Subclasses may override this routine to provide different behavior. |
| 1606 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1607 | QualType T, |
| 1608 | SourceLocation LParenLoc, |
| 1609 | MultiExprArg Args, |
| 1610 | SourceLocation *Commas, |
| 1611 | SourceLocation RParenLoc) { |
| 1612 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1613 | T.getAsOpaquePtr(), |
| 1614 | LParenLoc, |
| 1615 | move(Args), |
| 1616 | Commas, |
| 1617 | RParenLoc); |
| 1618 | } |
| 1619 | |
| 1620 | /// \brief Build a new object-construction expression. |
| 1621 | /// |
| 1622 | /// By default, performs semantic analysis to build the new expression. |
| 1623 | /// Subclasses may override this routine to provide different behavior. |
| 1624 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1625 | QualType T, |
| 1626 | SourceLocation LParenLoc, |
| 1627 | MultiExprArg Args, |
| 1628 | SourceLocation *Commas, |
| 1629 | SourceLocation RParenLoc) { |
| 1630 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1631 | /*FIXME*/LParenLoc), |
| 1632 | T.getAsOpaquePtr(), |
| 1633 | LParenLoc, |
| 1634 | move(Args), |
| 1635 | Commas, |
| 1636 | RParenLoc); |
| 1637 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1638 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1639 | /// \brief Build a new member reference expression. |
| 1640 | /// |
| 1641 | /// By default, performs semantic analysis to build the new expression. |
| 1642 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1643 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1644 | QualType BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1645 | bool IsArrow, |
| 1646 | SourceLocation OperatorLoc, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1647 | NestedNameSpecifier *Qualifier, |
| 1648 | SourceRange QualifierRange, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1649 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1650 | DeclarationName Name, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1651 | SourceLocation MemberLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1652 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1653 | CXXScopeSpec SS; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1654 | SS.setRange(QualifierRange); |
| 1655 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1656 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1657 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1658 | OperatorLoc, IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1659 | SS, FirstQualifierInScope, |
| 1660 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1661 | } |
| 1662 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1663 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1664 | /// |
| 1665 | /// By default, performs semantic analysis to build the new expression. |
| 1666 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1667 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1668 | QualType BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1669 | SourceLocation OperatorLoc, |
| 1670 | bool IsArrow, |
| 1671 | NestedNameSpecifier *Qualifier, |
| 1672 | SourceRange QualifierRange, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1673 | NamedDecl *FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1674 | LookupResult &R, |
| 1675 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1676 | CXXScopeSpec SS; |
| 1677 | SS.setRange(QualifierRange); |
| 1678 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1679 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1680 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1681 | OperatorLoc, IsArrow, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1682 | SS, FirstQualifierInScope, |
| 1683 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1684 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1685 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1686 | /// \brief Build a new Objective-C @encode expression. |
| 1687 | /// |
| 1688 | /// By default, performs semantic analysis to build the new expression. |
| 1689 | /// Subclasses may override this routine to provide different behavior. |
| 1690 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 1691 | QualType T, |
| 1692 | SourceLocation RParenLoc) { |
| 1693 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T, |
| 1694 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1695 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1696 | |
| 1697 | /// \brief Build a new Objective-C protocol expression. |
| 1698 | /// |
| 1699 | /// By default, performs semantic analysis to build the new expression. |
| 1700 | /// Subclasses may override this routine to provide different behavior. |
| 1701 | OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol, |
| 1702 | SourceLocation AtLoc, |
| 1703 | SourceLocation ProtoLoc, |
| 1704 | SourceLocation LParenLoc, |
| 1705 | SourceLocation RParenLoc) { |
| 1706 | return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression( |
| 1707 | Protocol->getIdentifier(), |
| 1708 | AtLoc, |
| 1709 | ProtoLoc, |
| 1710 | LParenLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1711 | RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1712 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1713 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1714 | /// \brief Build a new shuffle vector expression. |
| 1715 | /// |
| 1716 | /// By default, performs semantic analysis to build the new expression. |
| 1717 | /// Subclasses may override this routine to provide different behavior. |
| 1718 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1719 | MultiExprArg SubExprs, |
| 1720 | SourceLocation RParenLoc) { |
| 1721 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1722 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1723 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1724 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1725 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1726 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1727 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1728 | // Build a reference to the __builtin_shufflevector builtin |
| 1729 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1730 | Expr *Callee |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1731 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1732 | BuiltinLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1733 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1734 | |
| 1735 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1736 | unsigned NumSubExprs = SubExprs.size(); |
| 1737 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1738 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1739 | Subs, NumSubExprs, |
| 1740 | Builtin->getResultType(), |
| 1741 | RParenLoc); |
| 1742 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1743 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1744 | // Type-check the __builtin_shufflevector expression. |
| 1745 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1746 | if (Result.isInvalid()) |
| 1747 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1748 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1749 | OwnedCall.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1750 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1751 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1752 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1753 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1754 | template<typename Derived> |
| 1755 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1756 | if (!S) |
| 1757 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1758 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1759 | switch (S->getStmtClass()) { |
| 1760 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1761 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1762 | // Transform individual statement nodes |
| 1763 | #define STMT(Node, Parent) \ |
| 1764 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1765 | #define EXPR(Node, Parent) |
| 1766 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1767 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1768 | // Transform expressions by calling TransformExpr. |
| 1769 | #define STMT(Node, Parent) |
John McCall | 09cc141 | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1770 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1771 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1772 | #include "clang/AST/StmtNodes.def" |
| 1773 | { |
| 1774 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1775 | if (E.isInvalid()) |
| 1776 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1777 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1778 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1779 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1780 | } |
| 1781 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1782 | return SemaRef.Owned(S->Retain()); |
| 1783 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1784 | |
| 1785 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1786 | template<typename Derived> |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1787 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1788 | if (!E) |
| 1789 | return SemaRef.Owned(E); |
| 1790 | |
| 1791 | switch (E->getStmtClass()) { |
| 1792 | case Stmt::NoStmtClass: break; |
| 1793 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
John McCall | 09cc141 | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1794 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1795 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1796 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1797 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1798 | } |
| 1799 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1800 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | template<typename Derived> |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1804 | NestedNameSpecifier * |
| 1805 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1806 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1807 | QualType ObjectType, |
| 1808 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 0979c80 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1809 | if (!NNS) |
| 1810 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1811 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1812 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1813 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1814 | if (Prefix) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1815 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1816 | ObjectType, |
| 1817 | FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1818 | if (!Prefix) |
| 1819 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1820 | |
| 1821 | // 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] | 1822 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1823 | ObjectType = QualType(); |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1824 | FirstQualifierInScope = 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1825 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1826 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1827 | switch (NNS->getKind()) { |
| 1828 | case NestedNameSpecifier::Identifier: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1829 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1830 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1831 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1832 | ObjectType.isNull()) |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1833 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1834 | |
| 1835 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1836 | *NNS->getAsIdentifier(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1837 | ObjectType, |
| 1838 | FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1839 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1840 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1841 | NamespaceDecl *NS |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1842 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1843 | getDerived().TransformDecl(Range.getBegin(), |
| 1844 | NNS->getAsNamespace())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1845 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1846 | Prefix == NNS->getPrefix() && |
| 1847 | NS == NNS->getAsNamespace()) |
| 1848 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1849 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1850 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1851 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1852 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1853 | case NestedNameSpecifier::Global: |
| 1854 | // There is no meaningful transformation that one could perform on the |
| 1855 | // global scope. |
| 1856 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1857 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1858 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1859 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | fbf2c94 | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1860 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1861 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 1862 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1863 | if (T.isNull()) |
| 1864 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1865 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1866 | if (!getDerived().AlwaysRebuild() && |
| 1867 | Prefix == NNS->getPrefix() && |
| 1868 | T == QualType(NNS->getAsType(), 0)) |
| 1869 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1870 | |
| 1871 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1872 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 1873 | T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1874 | } |
| 1875 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1876 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1877 | // Required to silence a GCC warning |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1878 | return 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1882 | DeclarationName |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1883 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1884 | SourceLocation Loc, |
| 1885 | QualType ObjectType) { |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1886 | if (!Name) |
| 1887 | return Name; |
| 1888 | |
| 1889 | switch (Name.getNameKind()) { |
| 1890 | case DeclarationName::Identifier: |
| 1891 | case DeclarationName::ObjCZeroArgSelector: |
| 1892 | case DeclarationName::ObjCOneArgSelector: |
| 1893 | case DeclarationName::ObjCMultiArgSelector: |
| 1894 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 1895 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1896 | case DeclarationName::CXXUsingDirective: |
| 1897 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1898 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1899 | case DeclarationName::CXXConstructorName: |
| 1900 | case DeclarationName::CXXDestructorName: |
| 1901 | case DeclarationName::CXXConversionFunctionName: { |
| 1902 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1903 | QualType T = getDerived().TransformType(Name.getCXXNameType(), |
| 1904 | ObjectType); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1905 | if (T.isNull()) |
| 1906 | return DeclarationName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1907 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1908 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1909 | Name.getNameKind(), |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1910 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1911 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1912 | } |
| 1913 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1914 | return DeclarationName(); |
| 1915 | } |
| 1916 | |
| 1917 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1918 | TemplateName |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1919 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1920 | QualType ObjectType) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1921 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1922 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1923 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1924 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1925 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1926 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 1927 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1928 | if (!NNS) |
| 1929 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1930 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1931 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1932 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1933 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1934 | if (!TransTemplate) |
| 1935 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1936 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1937 | if (!getDerived().AlwaysRebuild() && |
| 1938 | NNS == QTN->getQualifier() && |
| 1939 | TransTemplate == Template) |
| 1940 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1941 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1942 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1943 | TransTemplate); |
| 1944 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1945 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1946 | // These should be getting filtered out before they make it into the AST. |
| 1947 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1948 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1949 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1950 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1951 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1952 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1953 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 1954 | ObjectType); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1955 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1956 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1957 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1958 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1959 | NNS == DTN->getQualifier() && |
| 1960 | ObjectType.isNull()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1961 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1962 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1963 | if (DTN->isIdentifier()) |
| 1964 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 1965 | ObjectType); |
| 1966 | |
| 1967 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 1968 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1969 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1970 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1971 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1972 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1973 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1974 | if (!TransTemplate) |
| 1975 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1976 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1977 | if (!getDerived().AlwaysRebuild() && |
| 1978 | TransTemplate == Template) |
| 1979 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1980 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1981 | return TemplateName(TransTemplate); |
| 1982 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1983 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1984 | // These should be getting filtered out before they reach the AST. |
| 1985 | assert(false && "overloaded function decl survived to here"); |
| 1986 | return TemplateName(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1990 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 1991 | const TemplateArgument &Arg, |
| 1992 | TemplateArgumentLoc &Output) { |
| 1993 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1994 | switch (Arg.getKind()) { |
| 1995 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 1996 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1997 | break; |
| 1998 | |
| 1999 | case TemplateArgument::Type: |
| 2000 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2001 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2002 | |
| 2003 | break; |
| 2004 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2005 | case TemplateArgument::Template: |
| 2006 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 2007 | break; |
| 2008 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2009 | case TemplateArgument::Expression: |
| 2010 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2011 | break; |
| 2012 | |
| 2013 | case TemplateArgument::Declaration: |
| 2014 | case TemplateArgument::Integral: |
| 2015 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2016 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2017 | break; |
| 2018 | } |
| 2019 | } |
| 2020 | |
| 2021 | template<typename Derived> |
| 2022 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2023 | const TemplateArgumentLoc &Input, |
| 2024 | TemplateArgumentLoc &Output) { |
| 2025 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2026 | switch (Arg.getKind()) { |
| 2027 | case TemplateArgument::Null: |
| 2028 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2029 | Output = Input; |
| 2030 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2031 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2032 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2033 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2034 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2035 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2036 | |
| 2037 | DI = getDerived().TransformType(DI); |
| 2038 | if (!DI) return true; |
| 2039 | |
| 2040 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2041 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2042 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2043 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2044 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2045 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2046 | DeclarationName Name; |
| 2047 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2048 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2049 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2050 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2051 | if (!D) return true; |
| 2052 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2053 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2054 | if (SourceExpr) { |
| 2055 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 2056 | Action::Unevaluated); |
| 2057 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 2058 | if (E.isInvalid()) |
| 2059 | SourceExpr = NULL; |
| 2060 | else { |
| 2061 | SourceExpr = E.takeAs<Expr>(); |
| 2062 | SourceExpr->Retain(); |
| 2063 | } |
| 2064 | } |
| 2065 | |
| 2066 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2067 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2068 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2069 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2070 | case TemplateArgument::Template: { |
| 2071 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 2072 | TemplateName Template |
| 2073 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2074 | if (Template.isNull()) |
| 2075 | return true; |
| 2076 | |
| 2077 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2078 | Input.getTemplateQualifierRange(), |
| 2079 | Input.getTemplateNameLoc()); |
| 2080 | return false; |
| 2081 | } |
| 2082 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2083 | case TemplateArgument::Expression: { |
| 2084 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2085 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2086 | Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2087 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2088 | Expr *InputExpr = Input.getSourceExpression(); |
| 2089 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2090 | |
| 2091 | Sema::OwningExprResult E |
| 2092 | = getDerived().TransformExpr(InputExpr); |
| 2093 | if (E.isInvalid()) return true; |
| 2094 | |
| 2095 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2096 | ETaken->Retain(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2097 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2098 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2099 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2100 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2101 | case TemplateArgument::Pack: { |
| 2102 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2103 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2104 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2105 | AEnd = Arg.pack_end(); |
| 2106 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2107 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2108 | // FIXME: preserve source information here when we start |
| 2109 | // caring about parameter packs. |
| 2110 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2111 | TemplateArgumentLoc InputArg; |
| 2112 | TemplateArgumentLoc OutputArg; |
| 2113 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2114 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2115 | return true; |
| 2116 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2117 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2118 | } |
| 2119 | TemplateArgument Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2120 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2121 | true); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2122 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2123 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2124 | } |
| 2125 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2126 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2127 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2128 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2129 | } |
| 2130 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2131 | //===----------------------------------------------------------------------===// |
| 2132 | // Type transformation |
| 2133 | //===----------------------------------------------------------------------===// |
| 2134 | |
| 2135 | template<typename Derived> |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2136 | QualType TreeTransform<Derived>::TransformType(QualType T, |
| 2137 | QualType ObjectType) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2138 | if (getDerived().AlreadyTransformed(T)) |
| 2139 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2140 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2141 | // Temporary workaround. All of these transformations should |
| 2142 | // eventually turn into transformations on TypeLocs. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2143 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | 4802a31 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2144 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2145 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2146 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2147 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2148 | if (!NewDI) |
| 2149 | return QualType(); |
| 2150 | |
| 2151 | return NewDI->getType(); |
| 2152 | } |
| 2153 | |
| 2154 | template<typename Derived> |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2155 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2156 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2157 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2158 | return DI; |
| 2159 | |
| 2160 | TypeLocBuilder TLB; |
| 2161 | |
| 2162 | TypeLoc TL = DI->getTypeLoc(); |
| 2163 | TLB.reserve(TL.getFullDataSize()); |
| 2164 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2165 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2166 | if (Result.isNull()) |
| 2167 | return 0; |
| 2168 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2169 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | template<typename Derived> |
| 2173 | QualType |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2174 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2175 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2176 | switch (T.getTypeLocClass()) { |
| 2177 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2178 | #define TYPELOC(CLASS, PARENT) \ |
| 2179 | case TypeLoc::CLASS: \ |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2180 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2181 | ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2182 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2183 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2184 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2185 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2186 | return QualType(); |
| 2187 | } |
| 2188 | |
| 2189 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2190 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2191 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2192 | /// types). This is the right thing for template instantiation, but |
| 2193 | /// probably not for other clients. |
| 2194 | template<typename Derived> |
| 2195 | QualType |
| 2196 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2197 | QualifiedTypeLoc T, |
| 2198 | QualType ObjectType) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2199 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2200 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2201 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2202 | ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2203 | if (Result.isNull()) |
| 2204 | return QualType(); |
| 2205 | |
| 2206 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2207 | // FIXME: this is the right thing for template instantiation, but |
| 2208 | // probably not for other clients. |
| 2209 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2210 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2211 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2212 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2213 | |
| 2214 | TLB.push<QualifiedTypeLoc>(Result); |
| 2215 | |
| 2216 | // No location information to preserve. |
| 2217 | |
| 2218 | return Result; |
| 2219 | } |
| 2220 | |
| 2221 | template <class TyLoc> static inline |
| 2222 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2223 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2224 | NewT.setNameLoc(T.getNameLoc()); |
| 2225 | return T.getType(); |
| 2226 | } |
| 2227 | |
| 2228 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2229 | // the equivalent template version work. |
| 2230 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2231 | QualType PointeeType \ |
| 2232 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2233 | if (PointeeType.isNull()) \ |
| 2234 | return QualType(); \ |
| 2235 | \ |
| 2236 | QualType Result = TL.getType(); \ |
| 2237 | if (getDerived().AlwaysRebuild() || \ |
| 2238 | PointeeType != TL.getPointeeLoc().getType()) { \ |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2239 | Result = getDerived().Rebuild##TypeClass(PointeeType, \ |
| 2240 | TL.getSigilLoc()); \ |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2241 | if (Result.isNull()) \ |
| 2242 | return QualType(); \ |
| 2243 | } \ |
| 2244 | \ |
| 2245 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2246 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2247 | \ |
| 2248 | return Result; \ |
| 2249 | } while(0) |
| 2250 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2251 | template<typename Derived> |
| 2252 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2253 | BuiltinTypeLoc T, |
| 2254 | QualType ObjectType) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2255 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2256 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2257 | if (T.needsExtraLocalData()) |
| 2258 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2259 | return T.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2260 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2261 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2262 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2263 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2264 | ComplexTypeLoc T, |
| 2265 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2266 | // FIXME: recurse? |
| 2267 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2268 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2269 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2270 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2271 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2272 | PointerTypeLoc TL, |
| 2273 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2274 | TransformPointerLikeType(PointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2275 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2276 | |
| 2277 | template<typename Derived> |
| 2278 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2279 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2280 | BlockPointerTypeLoc TL, |
| 2281 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2282 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2283 | } |
| 2284 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2285 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2286 | /// don't care whether the type itself is an l-value type or an r-value |
| 2287 | /// type; we only care if the type was *written* as an l-value type |
| 2288 | /// or an r-value type. |
| 2289 | template<typename Derived> |
| 2290 | QualType |
| 2291 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2292 | ReferenceTypeLoc TL, |
| 2293 | QualType ObjectType) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2294 | const ReferenceType *T = TL.getTypePtr(); |
| 2295 | |
| 2296 | // Note that this works with the pointee-as-written. |
| 2297 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2298 | if (PointeeType.isNull()) |
| 2299 | return QualType(); |
| 2300 | |
| 2301 | QualType Result = TL.getType(); |
| 2302 | if (getDerived().AlwaysRebuild() || |
| 2303 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2304 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2305 | T->isSpelledAsLValue(), |
| 2306 | TL.getSigilLoc()); |
| 2307 | if (Result.isNull()) |
| 2308 | return QualType(); |
| 2309 | } |
| 2310 | |
| 2311 | // r-value references can be rebuilt as l-value references. |
| 2312 | ReferenceTypeLoc NewTL; |
| 2313 | if (isa<LValueReferenceType>(Result)) |
| 2314 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2315 | else |
| 2316 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2317 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2318 | |
| 2319 | return Result; |
| 2320 | } |
| 2321 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2322 | template<typename Derived> |
| 2323 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2324 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2325 | LValueReferenceTypeLoc TL, |
| 2326 | QualType ObjectType) { |
| 2327 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2328 | } |
| 2329 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2330 | template<typename Derived> |
| 2331 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2332 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2333 | RValueReferenceTypeLoc TL, |
| 2334 | QualType ObjectType) { |
| 2335 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2336 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2337 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2338 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2339 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2340 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2341 | MemberPointerTypeLoc TL, |
| 2342 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2343 | MemberPointerType *T = TL.getTypePtr(); |
| 2344 | |
| 2345 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2346 | if (PointeeType.isNull()) |
| 2347 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2348 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2349 | // TODO: preserve source information for this. |
| 2350 | QualType ClassType |
| 2351 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2352 | if (ClassType.isNull()) |
| 2353 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2354 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2355 | QualType Result = TL.getType(); |
| 2356 | if (getDerived().AlwaysRebuild() || |
| 2357 | PointeeType != T->getPointeeType() || |
| 2358 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2359 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2360 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2361 | if (Result.isNull()) |
| 2362 | return QualType(); |
| 2363 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2364 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2365 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2366 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2367 | |
| 2368 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2369 | } |
| 2370 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2371 | template<typename Derived> |
| 2372 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2373 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2374 | ConstantArrayTypeLoc TL, |
| 2375 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2376 | ConstantArrayType *T = TL.getTypePtr(); |
| 2377 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2378 | if (ElementType.isNull()) |
| 2379 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2380 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2381 | QualType Result = TL.getType(); |
| 2382 | if (getDerived().AlwaysRebuild() || |
| 2383 | ElementType != T->getElementType()) { |
| 2384 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2385 | T->getSizeModifier(), |
| 2386 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2387 | T->getIndexTypeCVRQualifiers(), |
| 2388 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2389 | if (Result.isNull()) |
| 2390 | return QualType(); |
| 2391 | } |
| 2392 | |
| 2393 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2394 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2395 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2396 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2397 | Expr *Size = TL.getSizeExpr(); |
| 2398 | if (Size) { |
| 2399 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2400 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2401 | } |
| 2402 | NewTL.setSizeExpr(Size); |
| 2403 | |
| 2404 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2405 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2406 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2407 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2408 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2409 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2410 | IncompleteArrayTypeLoc TL, |
| 2411 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2412 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2413 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2414 | if (ElementType.isNull()) |
| 2415 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2416 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2417 | QualType Result = TL.getType(); |
| 2418 | if (getDerived().AlwaysRebuild() || |
| 2419 | ElementType != T->getElementType()) { |
| 2420 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2421 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2422 | T->getIndexTypeCVRQualifiers(), |
| 2423 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2424 | if (Result.isNull()) |
| 2425 | return QualType(); |
| 2426 | } |
| 2427 | |
| 2428 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2429 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2430 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2431 | NewTL.setSizeExpr(0); |
| 2432 | |
| 2433 | return Result; |
| 2434 | } |
| 2435 | |
| 2436 | template<typename Derived> |
| 2437 | QualType |
| 2438 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2439 | VariableArrayTypeLoc TL, |
| 2440 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2441 | VariableArrayType *T = TL.getTypePtr(); |
| 2442 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2443 | if (ElementType.isNull()) |
| 2444 | return QualType(); |
| 2445 | |
| 2446 | // Array bounds are not potentially evaluated contexts |
| 2447 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2448 | |
| 2449 | Sema::OwningExprResult SizeResult |
| 2450 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2451 | if (SizeResult.isInvalid()) |
| 2452 | return QualType(); |
| 2453 | |
| 2454 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2455 | |
| 2456 | QualType Result = TL.getType(); |
| 2457 | if (getDerived().AlwaysRebuild() || |
| 2458 | ElementType != T->getElementType() || |
| 2459 | Size != T->getSizeExpr()) { |
| 2460 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2461 | T->getSizeModifier(), |
| 2462 | move(SizeResult), |
| 2463 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2464 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2465 | if (Result.isNull()) |
| 2466 | return QualType(); |
| 2467 | } |
| 2468 | else SizeResult.take(); |
| 2469 | |
| 2470 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2471 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2472 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2473 | NewTL.setSizeExpr(Size); |
| 2474 | |
| 2475 | return Result; |
| 2476 | } |
| 2477 | |
| 2478 | template<typename Derived> |
| 2479 | QualType |
| 2480 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2481 | DependentSizedArrayTypeLoc TL, |
| 2482 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2483 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2484 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2485 | if (ElementType.isNull()) |
| 2486 | return QualType(); |
| 2487 | |
| 2488 | // Array bounds are not potentially evaluated contexts |
| 2489 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2490 | |
| 2491 | Sema::OwningExprResult SizeResult |
| 2492 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2493 | if (SizeResult.isInvalid()) |
| 2494 | return QualType(); |
| 2495 | |
| 2496 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2497 | |
| 2498 | QualType Result = TL.getType(); |
| 2499 | if (getDerived().AlwaysRebuild() || |
| 2500 | ElementType != T->getElementType() || |
| 2501 | Size != T->getSizeExpr()) { |
| 2502 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2503 | T->getSizeModifier(), |
| 2504 | move(SizeResult), |
| 2505 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2506 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2507 | if (Result.isNull()) |
| 2508 | return QualType(); |
| 2509 | } |
| 2510 | else SizeResult.take(); |
| 2511 | |
| 2512 | // We might have any sort of array type now, but fortunately they |
| 2513 | // all have the same location layout. |
| 2514 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2515 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2516 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2517 | NewTL.setSizeExpr(Size); |
| 2518 | |
| 2519 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2520 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2521 | |
| 2522 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2523 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2524 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2525 | DependentSizedExtVectorTypeLoc TL, |
| 2526 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2527 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2528 | |
| 2529 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2530 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2531 | if (ElementType.isNull()) |
| 2532 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2533 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2534 | // Vector sizes are not potentially evaluated contexts |
| 2535 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2536 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2537 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2538 | if (Size.isInvalid()) |
| 2539 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2540 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2541 | QualType Result = TL.getType(); |
| 2542 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2543 | ElementType != T->getElementType() || |
| 2544 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2545 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2546 | move(Size), |
| 2547 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2548 | if (Result.isNull()) |
| 2549 | return QualType(); |
| 2550 | } |
| 2551 | else Size.take(); |
| 2552 | |
| 2553 | // Result might be dependent or not. |
| 2554 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2555 | DependentSizedExtVectorTypeLoc NewTL |
| 2556 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2557 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2558 | } else { |
| 2559 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2560 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2561 | } |
| 2562 | |
| 2563 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2564 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2565 | |
| 2566 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2567 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2568 | VectorTypeLoc TL, |
| 2569 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2570 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2571 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2572 | if (ElementType.isNull()) |
| 2573 | return QualType(); |
| 2574 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2575 | QualType Result = TL.getType(); |
| 2576 | if (getDerived().AlwaysRebuild() || |
| 2577 | ElementType != T->getElementType()) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2578 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 2579 | T->isAltiVec(), T->isPixel()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2580 | if (Result.isNull()) |
| 2581 | return QualType(); |
| 2582 | } |
| 2583 | |
| 2584 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2585 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2586 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2587 | return Result; |
| 2588 | } |
| 2589 | |
| 2590 | template<typename Derived> |
| 2591 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2592 | ExtVectorTypeLoc TL, |
| 2593 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2594 | VectorType *T = TL.getTypePtr(); |
| 2595 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2596 | if (ElementType.isNull()) |
| 2597 | return QualType(); |
| 2598 | |
| 2599 | QualType Result = TL.getType(); |
| 2600 | if (getDerived().AlwaysRebuild() || |
| 2601 | ElementType != T->getElementType()) { |
| 2602 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2603 | T->getNumElements(), |
| 2604 | /*FIXME*/ SourceLocation()); |
| 2605 | if (Result.isNull()) |
| 2606 | return QualType(); |
| 2607 | } |
| 2608 | |
| 2609 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2610 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2611 | |
| 2612 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2613 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2614 | |
| 2615 | template<typename Derived> |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2616 | ParmVarDecl * |
| 2617 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) { |
| 2618 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| 2619 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
| 2620 | if (!NewDI) |
| 2621 | return 0; |
| 2622 | |
| 2623 | if (NewDI == OldDI) |
| 2624 | return OldParm; |
| 2625 | else |
| 2626 | return ParmVarDecl::Create(SemaRef.Context, |
| 2627 | OldParm->getDeclContext(), |
| 2628 | OldParm->getLocation(), |
| 2629 | OldParm->getIdentifier(), |
| 2630 | NewDI->getType(), |
| 2631 | NewDI, |
| 2632 | OldParm->getStorageClass(), |
| 2633 | /* DefArg */ NULL); |
| 2634 | } |
| 2635 | |
| 2636 | template<typename Derived> |
| 2637 | bool TreeTransform<Derived>:: |
| 2638 | TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 2639 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 2640 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars) { |
| 2641 | FunctionProtoType *T = TL.getTypePtr(); |
| 2642 | |
| 2643 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2644 | ParmVarDecl *OldParm = TL.getArg(i); |
| 2645 | |
| 2646 | QualType NewType; |
| 2647 | ParmVarDecl *NewParm; |
| 2648 | |
| 2649 | if (OldParm) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2650 | NewParm = getDerived().TransformFunctionTypeParam(OldParm); |
| 2651 | if (!NewParm) |
| 2652 | return true; |
| 2653 | NewType = NewParm->getType(); |
| 2654 | |
| 2655 | // Deal with the possibility that we don't have a parameter |
| 2656 | // declaration for this parameter. |
| 2657 | } else { |
| 2658 | NewParm = 0; |
| 2659 | |
| 2660 | QualType OldType = T->getArgType(i); |
| 2661 | NewType = getDerived().TransformType(OldType); |
| 2662 | if (NewType.isNull()) |
| 2663 | return true; |
| 2664 | } |
| 2665 | |
| 2666 | PTypes.push_back(NewType); |
| 2667 | PVars.push_back(NewParm); |
| 2668 | } |
| 2669 | |
| 2670 | return false; |
| 2671 | } |
| 2672 | |
| 2673 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2674 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2675 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2676 | FunctionProtoTypeLoc TL, |
| 2677 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2678 | FunctionProtoType *T = TL.getTypePtr(); |
| 2679 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2680 | if (ResultType.isNull()) |
| 2681 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2682 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2683 | // Transform the parameters. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2684 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2685 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2686 | if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls)) |
| 2687 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2688 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2689 | QualType Result = TL.getType(); |
| 2690 | if (getDerived().AlwaysRebuild() || |
| 2691 | ResultType != T->getResultType() || |
| 2692 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2693 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2694 | ParamTypes.data(), |
| 2695 | ParamTypes.size(), |
| 2696 | T->isVariadic(), |
| 2697 | T->getTypeQuals()); |
| 2698 | if (Result.isNull()) |
| 2699 | return QualType(); |
| 2700 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2701 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2702 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2703 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2704 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2705 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2706 | NewTL.setArg(i, ParamDecls[i]); |
| 2707 | |
| 2708 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2709 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2710 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2711 | template<typename Derived> |
| 2712 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2713 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2714 | FunctionNoProtoTypeLoc TL, |
| 2715 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2716 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2717 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2718 | if (ResultType.isNull()) |
| 2719 | return QualType(); |
| 2720 | |
| 2721 | QualType Result = TL.getType(); |
| 2722 | if (getDerived().AlwaysRebuild() || |
| 2723 | ResultType != T->getResultType()) |
| 2724 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2725 | |
| 2726 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2727 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2728 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2729 | |
| 2730 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2731 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2732 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2733 | template<typename Derived> QualType |
| 2734 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2735 | UnresolvedUsingTypeLoc TL, |
| 2736 | QualType ObjectType) { |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2737 | UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2738 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2739 | if (!D) |
| 2740 | return QualType(); |
| 2741 | |
| 2742 | QualType Result = TL.getType(); |
| 2743 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2744 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2745 | if (Result.isNull()) |
| 2746 | return QualType(); |
| 2747 | } |
| 2748 | |
| 2749 | // We might get an arbitrary type spec type back. We should at |
| 2750 | // least always get a type spec type, though. |
| 2751 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2752 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2753 | |
| 2754 | return Result; |
| 2755 | } |
| 2756 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2757 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2758 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2759 | TypedefTypeLoc TL, |
| 2760 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2761 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2762 | TypedefDecl *Typedef |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2763 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2764 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2765 | if (!Typedef) |
| 2766 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2767 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2768 | QualType Result = TL.getType(); |
| 2769 | if (getDerived().AlwaysRebuild() || |
| 2770 | Typedef != T->getDecl()) { |
| 2771 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2772 | if (Result.isNull()) |
| 2773 | return QualType(); |
| 2774 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2775 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2776 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2777 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2778 | |
| 2779 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2780 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2781 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2782 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2783 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2784 | TypeOfExprTypeLoc TL, |
| 2785 | QualType ObjectType) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2786 | // typeof expressions are not potentially evaluated contexts |
| 2787 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2788 | |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2789 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2790 | if (E.isInvalid()) |
| 2791 | return QualType(); |
| 2792 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2793 | QualType Result = TL.getType(); |
| 2794 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2795 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2796 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2797 | if (Result.isNull()) |
| 2798 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2799 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2800 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2801 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2802 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2803 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2804 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2805 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2806 | |
| 2807 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2808 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2809 | |
| 2810 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2811 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2812 | TypeOfTypeLoc TL, |
| 2813 | QualType ObjectType) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2814 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 2815 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 2816 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2817 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2818 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2819 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2820 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 2821 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2822 | if (Result.isNull()) |
| 2823 | return QualType(); |
| 2824 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2825 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2826 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2827 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2828 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2829 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2830 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2831 | |
| 2832 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2833 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2834 | |
| 2835 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2836 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2837 | DecltypeTypeLoc TL, |
| 2838 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2839 | DecltypeType *T = TL.getTypePtr(); |
| 2840 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2841 | // decltype expressions are not potentially evaluated contexts |
| 2842 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2843 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2844 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2845 | if (E.isInvalid()) |
| 2846 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2847 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2848 | QualType Result = TL.getType(); |
| 2849 | if (getDerived().AlwaysRebuild() || |
| 2850 | E.get() != T->getUnderlyingExpr()) { |
| 2851 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2852 | if (Result.isNull()) |
| 2853 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2854 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2855 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2856 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2857 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2858 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2859 | |
| 2860 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2861 | } |
| 2862 | |
| 2863 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2864 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2865 | RecordTypeLoc TL, |
| 2866 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2867 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2868 | RecordDecl *Record |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2869 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2870 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2871 | if (!Record) |
| 2872 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2873 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2874 | QualType Result = TL.getType(); |
| 2875 | if (getDerived().AlwaysRebuild() || |
| 2876 | Record != T->getDecl()) { |
| 2877 | Result = getDerived().RebuildRecordType(Record); |
| 2878 | if (Result.isNull()) |
| 2879 | return QualType(); |
| 2880 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2881 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2882 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2883 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2884 | |
| 2885 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2886 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2887 | |
| 2888 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2889 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2890 | EnumTypeLoc TL, |
| 2891 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2892 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2893 | EnumDecl *Enum |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2894 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2895 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2896 | if (!Enum) |
| 2897 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2898 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2899 | QualType Result = TL.getType(); |
| 2900 | if (getDerived().AlwaysRebuild() || |
| 2901 | Enum != T->getDecl()) { |
| 2902 | Result = getDerived().RebuildEnumType(Enum); |
| 2903 | if (Result.isNull()) |
| 2904 | return QualType(); |
| 2905 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2906 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2907 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2908 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2909 | |
| 2910 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2911 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2912 | |
| 2913 | template <typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2914 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2915 | ElaboratedTypeLoc TL, |
| 2916 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2917 | ElaboratedType *T = TL.getTypePtr(); |
| 2918 | |
| 2919 | // FIXME: this should be a nested type. |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2920 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2921 | if (Underlying.isNull()) |
| 2922 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2923 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2924 | QualType Result = TL.getType(); |
| 2925 | if (getDerived().AlwaysRebuild() || |
| 2926 | Underlying != T->getUnderlyingType()) { |
| 2927 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2928 | if (Result.isNull()) |
| 2929 | return QualType(); |
| 2930 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2931 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2932 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2933 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2934 | |
| 2935 | return Result; |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2936 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2937 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 2938 | template<typename Derived> |
| 2939 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 2940 | TypeLocBuilder &TLB, |
| 2941 | InjectedClassNameTypeLoc TL, |
| 2942 | QualType ObjectType) { |
| 2943 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 2944 | TL.getTypePtr()->getDecl()); |
| 2945 | if (!D) return QualType(); |
| 2946 | |
| 2947 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 2948 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 2949 | return T; |
| 2950 | } |
| 2951 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2952 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2953 | template<typename Derived> |
| 2954 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2955 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2956 | TemplateTypeParmTypeLoc TL, |
| 2957 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2958 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2959 | } |
| 2960 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2961 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2962 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2963 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2964 | SubstTemplateTypeParmTypeLoc TL, |
| 2965 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2966 | return TransformTypeSpecType(TLB, TL); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2970 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2971 | const TemplateSpecializationType *TST, |
| 2972 | QualType ObjectType) { |
| 2973 | // FIXME: this entire method is a temporary workaround; callers |
| 2974 | // should be rewritten to provide real type locs. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2975 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2976 | // Fake up a TemplateSpecializationTypeLoc. |
| 2977 | TypeLocBuilder TLB; |
| 2978 | TemplateSpecializationTypeLoc TL |
| 2979 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2980 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2981 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 2982 | |
| 2983 | TL.setTemplateNameLoc(BaseLoc); |
| 2984 | TL.setLAngleLoc(BaseLoc); |
| 2985 | TL.setRAngleLoc(BaseLoc); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2986 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2987 | const TemplateArgument &TA = TST->getArg(i); |
| 2988 | TemplateArgumentLoc TAL; |
| 2989 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2990 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2991 | } |
| 2992 | |
| 2993 | TypeLocBuilder IgnoredTLB; |
| 2994 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2995 | } |
| 2996 | |
| 2997 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2998 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2999 | TypeLocBuilder &TLB, |
| 3000 | TemplateSpecializationTypeLoc TL, |
| 3001 | QualType ObjectType) { |
| 3002 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 3003 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3004 | TemplateName Template |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3005 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3006 | if (Template.isNull()) |
| 3007 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3008 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3009 | TemplateArgumentListInfo NewTemplateArgs; |
| 3010 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 3011 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 3012 | |
| 3013 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 3014 | TemplateArgumentLoc Loc; |
| 3015 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3016 | return QualType(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3017 | NewTemplateArgs.addArgument(Loc); |
| 3018 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3019 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3020 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 3021 | |
| 3022 | QualType Result = |
| 3023 | getDerived().RebuildTemplateSpecializationType(Template, |
| 3024 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3025 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3026 | |
| 3027 | if (!Result.isNull()) { |
| 3028 | TemplateSpecializationTypeLoc NewTL |
| 3029 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 3030 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 3031 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 3032 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 3033 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 3034 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3035 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3036 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3037 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3038 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3039 | |
| 3040 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3041 | QualType |
| 3042 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3043 | QualifiedNameTypeLoc TL, |
| 3044 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3045 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3046 | NestedNameSpecifier *NNS |
| 3047 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3048 | SourceRange(), |
| 3049 | ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3050 | if (!NNS) |
| 3051 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3052 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3053 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 3054 | if (Named.isNull()) |
| 3055 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3056 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3057 | QualType Result = TL.getType(); |
| 3058 | if (getDerived().AlwaysRebuild() || |
| 3059 | NNS != T->getQualifier() || |
| 3060 | Named != T->getNamedType()) { |
| 3061 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 3062 | if (Result.isNull()) |
| 3063 | return QualType(); |
| 3064 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3065 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3066 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 3067 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3068 | |
| 3069 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3070 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3071 | |
| 3072 | template<typename Derived> |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3073 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
| 3074 | DependentNameTypeLoc TL, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3075 | QualType ObjectType) { |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3076 | DependentNameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3077 | |
| 3078 | /* FIXME: preserve source information better than this */ |
| 3079 | SourceRange SR(TL.getNameLoc()); |
| 3080 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3081 | NestedNameSpecifier *NNS |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3082 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3083 | ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3084 | if (!NNS) |
| 3085 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3086 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3087 | QualType Result; |
| 3088 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3089 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3090 | QualType NewTemplateId |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3091 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 3092 | if (NewTemplateId.isNull()) |
| 3093 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3094 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3095 | if (!getDerived().AlwaysRebuild() && |
| 3096 | NNS == T->getQualifier() && |
| 3097 | NewTemplateId == QualType(TemplateId, 0)) |
| 3098 | return QualType(T, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3099 | |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3100 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 3101 | NewTemplateId); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3102 | } else { |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3103 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 3104 | T->getIdentifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3105 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3106 | if (Result.isNull()) |
| 3107 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3108 | |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3109 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3110 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3111 | |
| 3112 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3113 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3114 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3115 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3116 | QualType |
| 3117 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3118 | ObjCInterfaceTypeLoc TL, |
| 3119 | QualType ObjectType) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3120 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 3121 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3122 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3123 | |
| 3124 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3125 | QualType |
| 3126 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3127 | ObjCObjectPointerTypeLoc TL, |
| 3128 | QualType ObjectType) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3129 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 3130 | return QualType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3131 | } |
| 3132 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3133 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3134 | // Statement transformation |
| 3135 | //===----------------------------------------------------------------------===// |
| 3136 | template<typename Derived> |
| 3137 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3138 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3139 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | template<typename Derived> |
| 3143 | Sema::OwningStmtResult |
| 3144 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3145 | return getDerived().TransformCompoundStmt(S, false); |
| 3146 | } |
| 3147 | |
| 3148 | template<typename Derived> |
| 3149 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3150 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3151 | bool IsStmtExpr) { |
| 3152 | bool SubStmtChanged = false; |
| 3153 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3154 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3155 | B != BEnd; ++B) { |
| 3156 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3157 | if (Result.isInvalid()) |
| 3158 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3159 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3160 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3161 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3162 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3163 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3164 | if (!getDerived().AlwaysRebuild() && |
| 3165 | !SubStmtChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3166 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3167 | |
| 3168 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3169 | move_arg(Statements), |
| 3170 | S->getRBracLoc(), |
| 3171 | IsStmtExpr); |
| 3172 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3173 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3174 | template<typename Derived> |
| 3175 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3176 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3177 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3178 | { |
| 3179 | // The case value expressions are not potentially evaluated. |
| 3180 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3181 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3182 | // Transform the left-hand case value. |
| 3183 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3184 | if (LHS.isInvalid()) |
| 3185 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3186 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3187 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3188 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3189 | if (RHS.isInvalid()) |
| 3190 | return SemaRef.StmtError(); |
| 3191 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3192 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3193 | // Build the case statement. |
| 3194 | // Case statements are always rebuilt so that they will attached to their |
| 3195 | // transformed switch statement. |
| 3196 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3197 | move(LHS), |
| 3198 | S->getEllipsisLoc(), |
| 3199 | move(RHS), |
| 3200 | S->getColonLoc()); |
| 3201 | if (Case.isInvalid()) |
| 3202 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3203 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3204 | // Transform the statement following the case |
| 3205 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3206 | if (SubStmt.isInvalid()) |
| 3207 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3208 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3209 | // Attach the body to the case statement |
| 3210 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3211 | } |
| 3212 | |
| 3213 | template<typename Derived> |
| 3214 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3215 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3216 | // Transform the statement following the default case |
| 3217 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3218 | if (SubStmt.isInvalid()) |
| 3219 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3220 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3221 | // Default statements are always rebuilt |
| 3222 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3223 | move(SubStmt)); |
| 3224 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3225 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3226 | template<typename Derived> |
| 3227 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3228 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3229 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3230 | if (SubStmt.isInvalid()) |
| 3231 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3232 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3233 | // FIXME: Pass the real colon location in. |
| 3234 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3235 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3236 | move(SubStmt)); |
| 3237 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3238 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3239 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3240 | Sema::OwningStmtResult |
| 3241 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3242 | // Transform the condition |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3243 | OwningExprResult Cond(SemaRef); |
| 3244 | VarDecl *ConditionVar = 0; |
| 3245 | if (S->getConditionVariable()) { |
| 3246 | ConditionVar |
| 3247 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3248 | getDerived().TransformDefinition( |
| 3249 | S->getConditionVariable()->getLocation(), |
| 3250 | S->getConditionVariable())); |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3251 | if (!ConditionVar) |
| 3252 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3253 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3254 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3255 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3256 | if (Cond.isInvalid()) |
| 3257 | return SemaRef.StmtError(); |
| 3258 | } |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3259 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3260 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3261 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3262 | // Transform the "then" branch. |
| 3263 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3264 | if (Then.isInvalid()) |
| 3265 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3266 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3267 | // Transform the "else" branch. |
| 3268 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3269 | if (Else.isInvalid()) |
| 3270 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3271 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3272 | if (!getDerived().AlwaysRebuild() && |
| 3273 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3274 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3275 | Then.get() == S->getThen() && |
| 3276 | Else.get() == S->getElse()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3277 | return SemaRef.Owned(S->Retain()); |
| 3278 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3279 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3280 | move(Then), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3281 | S->getElseLoc(), move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | template<typename Derived> |
| 3285 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3286 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3287 | // Transform the condition. |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3288 | OwningExprResult Cond(SemaRef); |
| 3289 | VarDecl *ConditionVar = 0; |
| 3290 | if (S->getConditionVariable()) { |
| 3291 | ConditionVar |
| 3292 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3293 | getDerived().TransformDefinition( |
| 3294 | S->getConditionVariable()->getLocation(), |
| 3295 | S->getConditionVariable())); |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3296 | if (!ConditionVar) |
| 3297 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3298 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3299 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3300 | |
| 3301 | if (Cond.isInvalid()) |
| 3302 | return SemaRef.StmtError(); |
| 3303 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3304 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3305 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3306 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3307 | // Rebuild the switch statement. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3308 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3309 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3310 | if (Switch.isInvalid()) |
| 3311 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3312 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3313 | // Transform the body of the switch statement. |
| 3314 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3315 | if (Body.isInvalid()) |
| 3316 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3317 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3318 | // Complete the switch statement. |
| 3319 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3320 | move(Body)); |
| 3321 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3322 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3323 | template<typename Derived> |
| 3324 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3325 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3326 | // Transform the condition |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3327 | OwningExprResult Cond(SemaRef); |
| 3328 | VarDecl *ConditionVar = 0; |
| 3329 | if (S->getConditionVariable()) { |
| 3330 | ConditionVar |
| 3331 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3332 | getDerived().TransformDefinition( |
| 3333 | S->getConditionVariable()->getLocation(), |
| 3334 | S->getConditionVariable())); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3335 | if (!ConditionVar) |
| 3336 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3337 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3338 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3339 | |
| 3340 | if (Cond.isInvalid()) |
| 3341 | return SemaRef.StmtError(); |
| 3342 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3343 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3344 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3345 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3346 | // Transform the body |
| 3347 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3348 | if (Body.isInvalid()) |
| 3349 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3350 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3351 | if (!getDerived().AlwaysRebuild() && |
| 3352 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3353 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3354 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3355 | return SemaRef.Owned(S->Retain()); |
| 3356 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3357 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3358 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3359 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3360 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3361 | template<typename Derived> |
| 3362 | Sema::OwningStmtResult |
| 3363 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3364 | // Transform the condition |
| 3365 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3366 | if (Cond.isInvalid()) |
| 3367 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3368 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3369 | // Transform the body |
| 3370 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3371 | if (Body.isInvalid()) |
| 3372 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3373 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3374 | if (!getDerived().AlwaysRebuild() && |
| 3375 | Cond.get() == S->getCond() && |
| 3376 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3377 | return SemaRef.Owned(S->Retain()); |
| 3378 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3379 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3380 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3381 | S->getRParenLoc()); |
| 3382 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3383 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3384 | template<typename Derived> |
| 3385 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3386 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3387 | // Transform the initialization statement |
| 3388 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3389 | if (Init.isInvalid()) |
| 3390 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3391 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3392 | // Transform the condition |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3393 | OwningExprResult Cond(SemaRef); |
| 3394 | VarDecl *ConditionVar = 0; |
| 3395 | if (S->getConditionVariable()) { |
| 3396 | ConditionVar |
| 3397 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3398 | getDerived().TransformDefinition( |
| 3399 | S->getConditionVariable()->getLocation(), |
| 3400 | S->getConditionVariable())); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3401 | if (!ConditionVar) |
| 3402 | return SemaRef.StmtError(); |
| 3403 | } else { |
| 3404 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3405 | |
| 3406 | if (Cond.isInvalid()) |
| 3407 | return SemaRef.StmtError(); |
| 3408 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3409 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3410 | // Transform the increment |
| 3411 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3412 | if (Inc.isInvalid()) |
| 3413 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3414 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3415 | // Transform the body |
| 3416 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3417 | if (Body.isInvalid()) |
| 3418 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3419 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3420 | if (!getDerived().AlwaysRebuild() && |
| 3421 | Init.get() == S->getInit() && |
| 3422 | Cond.get() == S->getCond() && |
| 3423 | Inc.get() == S->getInc() && |
| 3424 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3425 | return SemaRef.Owned(S->Retain()); |
| 3426 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3427 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3428 | move(Init), getSema().MakeFullExpr(Cond), |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3429 | ConditionVar, |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3430 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3431 | S->getRParenLoc(), move(Body)); |
| 3432 | } |
| 3433 | |
| 3434 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3435 | Sema::OwningStmtResult |
| 3436 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3437 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3438 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3439 | S->getLabel()); |
| 3440 | } |
| 3441 | |
| 3442 | template<typename Derived> |
| 3443 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3444 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3445 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3446 | if (Target.isInvalid()) |
| 3447 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3448 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3449 | if (!getDerived().AlwaysRebuild() && |
| 3450 | Target.get() == S->getTarget()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3451 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3452 | |
| 3453 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3454 | move(Target)); |
| 3455 | } |
| 3456 | |
| 3457 | template<typename Derived> |
| 3458 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3459 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3460 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3461 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3462 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3463 | template<typename Derived> |
| 3464 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3465 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3466 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3467 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3468 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3469 | template<typename Derived> |
| 3470 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3471 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3472 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3473 | if (Result.isInvalid()) |
| 3474 | return SemaRef.StmtError(); |
| 3475 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3476 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3477 | // to tell whether the return type of the function has changed. |
| 3478 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3479 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3480 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3481 | template<typename Derived> |
| 3482 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3483 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3484 | bool DeclChanged = false; |
| 3485 | llvm::SmallVector<Decl *, 4> Decls; |
| 3486 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3487 | D != DEnd; ++D) { |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3488 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 3489 | *D); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3490 | if (!Transformed) |
| 3491 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3492 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3493 | if (Transformed != *D) |
| 3494 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3495 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3496 | Decls.push_back(Transformed); |
| 3497 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3498 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3499 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3500 | return SemaRef.Owned(S->Retain()); |
| 3501 | |
| 3502 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3503 | S->getStartLoc(), S->getEndLoc()); |
| 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 | template<typename Derived> |
| 3507 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3508 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3509 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3510 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | template<typename Derived> |
| 3514 | Sema::OwningStmtResult |
| 3515 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3516 | |
| 3517 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3518 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3519 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3520 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3521 | OwningExprResult AsmString(SemaRef); |
| 3522 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3523 | |
| 3524 | bool ExprsChanged = false; |
| 3525 | |
| 3526 | // Go through the outputs. |
| 3527 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3528 | Names.push_back(S->getOutputIdentifier(I)); |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3529 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3530 | // No need to transform the constraint literal. |
| 3531 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
| 3532 | |
| 3533 | // Transform the output expr. |
| 3534 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3535 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3536 | if (Result.isInvalid()) |
| 3537 | return SemaRef.StmtError(); |
| 3538 | |
| 3539 | ExprsChanged |= Result.get() != OutputExpr; |
| 3540 | |
| 3541 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3542 | } |
| 3543 | |
| 3544 | // Go through the inputs. |
| 3545 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3546 | Names.push_back(S->getInputIdentifier(I)); |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3547 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3548 | // No need to transform the constraint literal. |
| 3549 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
| 3550 | |
| 3551 | // Transform the input expr. |
| 3552 | Expr *InputExpr = S->getInputExpr(I); |
| 3553 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3554 | if (Result.isInvalid()) |
| 3555 | return SemaRef.StmtError(); |
| 3556 | |
| 3557 | ExprsChanged |= Result.get() != InputExpr; |
| 3558 | |
| 3559 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3560 | } |
| 3561 | |
| 3562 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3563 | return SemaRef.Owned(S->Retain()); |
| 3564 | |
| 3565 | // Go through the clobbers. |
| 3566 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3567 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3568 | |
| 3569 | // No need to transform the asm string literal. |
| 3570 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3571 | |
| 3572 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3573 | S->isSimple(), |
| 3574 | S->isVolatile(), |
| 3575 | S->getNumOutputs(), |
| 3576 | S->getNumInputs(), |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3577 | Names.data(), |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3578 | move_arg(Constraints), |
| 3579 | move_arg(Exprs), |
| 3580 | move(AsmString), |
| 3581 | move_arg(Clobbers), |
| 3582 | S->getRParenLoc(), |
| 3583 | S->isMSAsm()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3584 | } |
| 3585 | |
| 3586 | |
| 3587 | template<typename Derived> |
| 3588 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3589 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3590 | // FIXME: Implement this |
| 3591 | assert(false && "Cannot transform an Objective-C @try statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3592 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 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 | template<typename Derived> |
| 3596 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3597 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3598 | // FIXME: Implement this |
| 3599 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3600 | return SemaRef.Owned(S->Retain()); |
| 3601 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3602 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3603 | template<typename Derived> |
| 3604 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3605 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3606 | // FIXME: Implement this |
| 3607 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3608 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3609 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3610 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3611 | template<typename Derived> |
| 3612 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3613 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3614 | // FIXME: Implement this |
| 3615 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3616 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3617 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3618 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3619 | template<typename Derived> |
| 3620 | Sema::OwningStmtResult |
| 3621 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3622 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3623 | // FIXME: Implement this |
| 3624 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3625 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3626 | } |
| 3627 | |
| 3628 | template<typename Derived> |
| 3629 | Sema::OwningStmtResult |
| 3630 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3631 | ObjCForCollectionStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3632 | // FIXME: Implement this |
| 3633 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3634 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3635 | } |
| 3636 | |
| 3637 | |
| 3638 | template<typename Derived> |
| 3639 | Sema::OwningStmtResult |
| 3640 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3641 | // Transform the exception declaration, if any. |
| 3642 | VarDecl *Var = 0; |
| 3643 | if (S->getExceptionDecl()) { |
| 3644 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3645 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3646 | ExceptionDecl->getDeclName()); |
| 3647 | |
| 3648 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3649 | if (T.isNull()) |
| 3650 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3651 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3652 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3653 | T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3654 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3655 | ExceptionDecl->getIdentifier(), |
| 3656 | ExceptionDecl->getLocation(), |
| 3657 | /*FIXME: Inaccurate*/ |
| 3658 | SourceRange(ExceptionDecl->getLocation())); |
| 3659 | if (!Var || Var->isInvalidDecl()) { |
| 3660 | if (Var) |
| 3661 | Var->Destroy(SemaRef.Context); |
| 3662 | return SemaRef.StmtError(); |
| 3663 | } |
| 3664 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3665 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3666 | // Transform the actual exception handler. |
| 3667 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3668 | if (Handler.isInvalid()) { |
| 3669 | if (Var) |
| 3670 | Var->Destroy(SemaRef.Context); |
| 3671 | return SemaRef.StmtError(); |
| 3672 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3673 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3674 | if (!getDerived().AlwaysRebuild() && |
| 3675 | !Var && |
| 3676 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3677 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3678 | |
| 3679 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3680 | Var, |
| 3681 | move(Handler)); |
| 3682 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3683 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3684 | template<typename Derived> |
| 3685 | Sema::OwningStmtResult |
| 3686 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3687 | // Transform the try block itself. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3688 | OwningStmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3689 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3690 | if (TryBlock.isInvalid()) |
| 3691 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3692 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3693 | // Transform the handlers. |
| 3694 | bool HandlerChanged = false; |
| 3695 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3696 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3697 | OwningStmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3698 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3699 | if (Handler.isInvalid()) |
| 3700 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3701 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3702 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3703 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3704 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3705 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3706 | if (!getDerived().AlwaysRebuild() && |
| 3707 | TryBlock.get() == S->getTryBlock() && |
| 3708 | !HandlerChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3709 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3710 | |
| 3711 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3712 | move_arg(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3713 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3714 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3715 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3716 | // Expression transformation |
| 3717 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3718 | template<typename Derived> |
| 3719 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3720 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3721 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3722 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3723 | |
| 3724 | template<typename Derived> |
| 3725 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3726 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3727 | NestedNameSpecifier *Qualifier = 0; |
| 3728 | if (E->getQualifier()) { |
| 3729 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3730 | E->getQualifierRange()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3731 | if (!Qualifier) |
| 3732 | return SemaRef.ExprError(); |
| 3733 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3734 | |
| 3735 | ValueDecl *ND |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3736 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 3737 | E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3738 | if (!ND) |
| 3739 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3740 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3741 | if (!getDerived().AlwaysRebuild() && |
| 3742 | Qualifier == E->getQualifier() && |
| 3743 | ND == E->getDecl() && |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3744 | !E->hasExplicitTemplateArgumentList()) { |
| 3745 | |
| 3746 | // Mark it referenced in the new context regardless. |
| 3747 | // FIXME: this is a bit instantiation-specific. |
| 3748 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 3749 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3750 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3751 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3752 | |
| 3753 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 3754 | if (E->hasExplicitTemplateArgumentList()) { |
| 3755 | TemplateArgs = &TransArgs; |
| 3756 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3757 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 3758 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3759 | TemplateArgumentLoc Loc; |
| 3760 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 3761 | return SemaRef.ExprError(); |
| 3762 | TransArgs.addArgument(Loc); |
| 3763 | } |
| 3764 | } |
| 3765 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3766 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3767 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3768 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3769 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3770 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3771 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3772 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3773 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3774 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3775 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3776 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3777 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3778 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3779 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3780 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3781 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3782 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3783 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3784 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3785 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3786 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3787 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3788 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3789 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3790 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3791 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3792 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3793 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3794 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3795 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3796 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3797 | return SemaRef.Owned(E->Retain()); |
| 3798 | } |
| 3799 | |
| 3800 | template<typename Derived> |
| 3801 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3802 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3803 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3804 | if (SubExpr.isInvalid()) |
| 3805 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3806 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3807 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3808 | return SemaRef.Owned(E->Retain()); |
| 3809 | |
| 3810 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3811 | E->getRParen()); |
| 3812 | } |
| 3813 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3814 | template<typename Derived> |
| 3815 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3816 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 3817 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3818 | if (SubExpr.isInvalid()) |
| 3819 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3820 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3821 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3822 | return SemaRef.Owned(E->Retain()); |
| 3823 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3824 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3825 | E->getOpcode(), |
| 3826 | move(SubExpr)); |
| 3827 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3828 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3829 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3830 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3831 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3832 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3833 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3834 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3835 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3836 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3837 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3838 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3839 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3840 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3841 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3842 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3843 | E->isSizeOf(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3844 | E->getSourceRange()); |
| 3845 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3846 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3847 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3848 | { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3849 | // C++0x [expr.sizeof]p1: |
| 3850 | // The operand is either an expression, which is an unevaluated operand |
| 3851 | // [...] |
| 3852 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3853 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3854 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3855 | if (SubExpr.isInvalid()) |
| 3856 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3857 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3858 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3859 | return SemaRef.Owned(E->Retain()); |
| 3860 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3861 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3862 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3863 | E->isSizeOf(), |
| 3864 | E->getSourceRange()); |
| 3865 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3866 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3867 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3868 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3869 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3870 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3871 | if (LHS.isInvalid()) |
| 3872 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3873 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3874 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3875 | if (RHS.isInvalid()) |
| 3876 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3877 | |
| 3878 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3879 | if (!getDerived().AlwaysRebuild() && |
| 3880 | LHS.get() == E->getLHS() && |
| 3881 | RHS.get() == E->getRHS()) |
| 3882 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3883 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3884 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3885 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3886 | move(RHS), |
| 3887 | E->getRBracketLoc()); |
| 3888 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3889 | |
| 3890 | template<typename Derived> |
| 3891 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3892 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3893 | // Transform the callee. |
| 3894 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3895 | if (Callee.isInvalid()) |
| 3896 | return SemaRef.ExprError(); |
| 3897 | |
| 3898 | // Transform arguments. |
| 3899 | bool ArgChanged = false; |
| 3900 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3901 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3902 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3903 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3904 | if (Arg.isInvalid()) |
| 3905 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3906 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3907 | // FIXME: Wrong source location information for the ','. |
| 3908 | FakeCommaLocs.push_back( |
| 3909 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3910 | |
| 3911 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3912 | Args.push_back(Arg.takeAs<Expr>()); |
| 3913 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3914 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3915 | if (!getDerived().AlwaysRebuild() && |
| 3916 | Callee.get() == E->getCallee() && |
| 3917 | !ArgChanged) |
| 3918 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3919 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3920 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3921 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3922 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3923 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3924 | move_arg(Args), |
| 3925 | FakeCommaLocs.data(), |
| 3926 | E->getRParenLoc()); |
| 3927 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3928 | |
| 3929 | template<typename Derived> |
| 3930 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3931 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3932 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3933 | if (Base.isInvalid()) |
| 3934 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3935 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3936 | NestedNameSpecifier *Qualifier = 0; |
| 3937 | if (E->hasQualifier()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3938 | Qualifier |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3939 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3940 | E->getQualifierRange()); |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3941 | if (Qualifier == 0) |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3942 | return SemaRef.ExprError(); |
| 3943 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3944 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 3945 | ValueDecl *Member |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3946 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 3947 | E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3948 | if (!Member) |
| 3949 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3950 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 3951 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 3952 | if (FoundDecl == E->getMemberDecl()) { |
| 3953 | FoundDecl = Member; |
| 3954 | } else { |
| 3955 | FoundDecl = cast_or_null<NamedDecl>( |
| 3956 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 3957 | if (!FoundDecl) |
| 3958 | return SemaRef.ExprError(); |
| 3959 | } |
| 3960 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3961 | if (!getDerived().AlwaysRebuild() && |
| 3962 | Base.get() == E->getBase() && |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3963 | Qualifier == E->getQualifier() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3964 | Member == E->getMemberDecl() && |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 3965 | FoundDecl == E->getFoundDecl() && |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3966 | !E->hasExplicitTemplateArgumentList()) { |
| 3967 | |
| 3968 | // Mark it referenced in the new context regardless. |
| 3969 | // FIXME: this is a bit instantiation-specific. |
| 3970 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3971 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3972 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3973 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3974 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3975 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3976 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3977 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3978 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3979 | TemplateArgumentLoc Loc; |
| 3980 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3981 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3982 | TransArgs.addArgument(Loc); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3983 | } |
| 3984 | } |
| 3985 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3986 | // FIXME: Bogus source location for the operator |
| 3987 | SourceLocation FakeOperatorLoc |
| 3988 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3989 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3990 | // FIXME: to do this check properly, we will need to preserve the |
| 3991 | // first-qualifier-in-scope here, just in case we had a dependent |
| 3992 | // base (and therefore couldn't do the check) and a |
| 3993 | // nested-name-qualifier (and therefore could do the lookup). |
| 3994 | NamedDecl *FirstQualifierInScope = 0; |
| 3995 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3996 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3997 | E->isArrow(), |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3998 | Qualifier, |
| 3999 | E->getQualifierRange(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4000 | E->getMemberLoc(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4001 | Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4002 | FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4003 | (E->hasExplicitTemplateArgumentList() |
| 4004 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4005 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4006 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4007 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4008 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4009 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4010 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4011 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4012 | if (LHS.isInvalid()) |
| 4013 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4014 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4015 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4016 | if (RHS.isInvalid()) |
| 4017 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4018 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4019 | if (!getDerived().AlwaysRebuild() && |
| 4020 | LHS.get() == E->getLHS() && |
| 4021 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4022 | return SemaRef.Owned(E->Retain()); |
| 4023 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4024 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 4025 | move(LHS), move(RHS)); |
| 4026 | } |
| 4027 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4028 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4029 | Sema::OwningExprResult |
| 4030 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4031 | CompoundAssignOperator *E) { |
| 4032 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4033 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4034 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4035 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4036 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4037 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4038 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4039 | if (Cond.isInvalid()) |
| 4040 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4041 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4042 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4043 | if (LHS.isInvalid()) |
| 4044 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4045 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4046 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4047 | if (RHS.isInvalid()) |
| 4048 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4049 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4050 | if (!getDerived().AlwaysRebuild() && |
| 4051 | Cond.get() == E->getCond() && |
| 4052 | LHS.get() == E->getLHS() && |
| 4053 | RHS.get() == E->getRHS()) |
| 4054 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4055 | |
| 4056 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4057 | E->getQuestionLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4058 | move(LHS), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4059 | E->getColonLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4060 | move(RHS)); |
| 4061 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4062 | |
| 4063 | template<typename Derived> |
| 4064 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4065 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4066 | // Implicit casts are eliminated during transformation, since they |
| 4067 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4068 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4069 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4070 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4071 | template<typename Derived> |
| 4072 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4073 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4074 | TypeSourceInfo *OldT; |
| 4075 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4076 | { |
| 4077 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4078 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4079 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 4080 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4081 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4082 | OldT = E->getTypeInfoAsWritten(); |
| 4083 | NewT = getDerived().TransformType(OldT); |
| 4084 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4085 | return SemaRef.ExprError(); |
| 4086 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4087 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4088 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4089 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4090 | if (SubExpr.isInvalid()) |
| 4091 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4092 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4093 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4094 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4095 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4096 | return SemaRef.Owned(E->Retain()); |
| 4097 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4098 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 4099 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4100 | E->getRParenLoc(), |
| 4101 | move(SubExpr)); |
| 4102 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4103 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4104 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4105 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4106 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4107 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 4108 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 4109 | if (!NewT) |
| 4110 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4111 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4112 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 4113 | if (Init.isInvalid()) |
| 4114 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4115 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4116 | if (!getDerived().AlwaysRebuild() && |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4117 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4118 | Init.get() == E->getInitializer()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4119 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4120 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 4121 | // Note: the expression type doesn't necessarily match the |
| 4122 | // type-as-written, but that's okay, because it should always be |
| 4123 | // derivable from the initializer. |
| 4124 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4125 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4126 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 4127 | move(Init)); |
| 4128 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4129 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4130 | template<typename Derived> |
| 4131 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4132 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4133 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4134 | if (Base.isInvalid()) |
| 4135 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4136 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4137 | if (!getDerived().AlwaysRebuild() && |
| 4138 | Base.get() == E->getBase()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4139 | return SemaRef.Owned(E->Retain()); |
| 4140 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4141 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4142 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4143 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 4144 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 4145 | E->getAccessorLoc(), |
| 4146 | E->getAccessor()); |
| 4147 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4148 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4149 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4150 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4151 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4152 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4153 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4154 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4155 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4156 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4157 | if (Init.isInvalid()) |
| 4158 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4159 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4160 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4161 | Inits.push_back(Init.takeAs<Expr>()); |
| 4162 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4163 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4164 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4165 | return SemaRef.Owned(E->Retain()); |
| 4166 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4167 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4168 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4169 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4170 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4171 | template<typename Derived> |
| 4172 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4173 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4174 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4175 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4176 | // transform the initializer value |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4177 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4178 | if (Init.isInvalid()) |
| 4179 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4180 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4181 | // transform the designators. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4182 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4183 | bool ExprChanged = false; |
| 4184 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4185 | DEnd = E->designators_end(); |
| 4186 | D != DEnd; ++D) { |
| 4187 | if (D->isFieldDesignator()) { |
| 4188 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4189 | D->getDotLoc(), |
| 4190 | D->getFieldLoc())); |
| 4191 | continue; |
| 4192 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4193 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4194 | if (D->isArrayDesignator()) { |
| 4195 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4196 | if (Index.isInvalid()) |
| 4197 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4198 | |
| 4199 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4200 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4201 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4202 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4203 | ArrayExprs.push_back(Index.release()); |
| 4204 | continue; |
| 4205 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4206 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4207 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4208 | OwningExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4209 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4210 | if (Start.isInvalid()) |
| 4211 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4212 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4213 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4214 | if (End.isInvalid()) |
| 4215 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4216 | |
| 4217 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4218 | End.get(), |
| 4219 | D->getLBracketLoc(), |
| 4220 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4221 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4222 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4223 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4224 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4225 | ArrayExprs.push_back(Start.release()); |
| 4226 | ArrayExprs.push_back(End.release()); |
| 4227 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4228 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4229 | if (!getDerived().AlwaysRebuild() && |
| 4230 | Init.get() == E->getInit() && |
| 4231 | !ExprChanged) |
| 4232 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4233 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4234 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4235 | E->getEqualOrColonLoc(), |
| 4236 | E->usesGNUSyntax(), move(Init)); |
| 4237 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4238 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4239 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4240 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4241 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4242 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4243 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4244 | |
| 4245 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4246 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4247 | QualType T = getDerived().TransformType(E->getType()); |
| 4248 | if (T.isNull()) |
| 4249 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4250 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4251 | if (!getDerived().AlwaysRebuild() && |
| 4252 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4253 | return SemaRef.Owned(E->Retain()); |
| 4254 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4255 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4256 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4257 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4258 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4259 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4260 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4261 | // FIXME: Do we want the type as written? |
| 4262 | QualType T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4263 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4264 | { |
| 4265 | // FIXME: Source location isn't quite accurate. |
| 4266 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4267 | T = getDerived().TransformType(E->getType()); |
| 4268 | if (T.isNull()) |
| 4269 | return SemaRef.ExprError(); |
| 4270 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4271 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4272 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4273 | if (SubExpr.isInvalid()) |
| 4274 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4275 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4276 | if (!getDerived().AlwaysRebuild() && |
| 4277 | T == E->getType() && |
| 4278 | SubExpr.get() == E->getSubExpr()) |
| 4279 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4280 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4281 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4282 | T, E->getRParenLoc()); |
| 4283 | } |
| 4284 | |
| 4285 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4286 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4287 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4288 | bool ArgumentChanged = false; |
| 4289 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4290 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4291 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4292 | if (Init.isInvalid()) |
| 4293 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4294 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4295 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4296 | Inits.push_back(Init.takeAs<Expr>()); |
| 4297 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4298 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4299 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4300 | move_arg(Inits), |
| 4301 | E->getRParenLoc()); |
| 4302 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4303 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4304 | /// \brief Transform an address-of-label expression. |
| 4305 | /// |
| 4306 | /// By default, the transformation of an address-of-label expression always |
| 4307 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4308 | /// the corresponding label statement by semantic analysis. |
| 4309 | template<typename Derived> |
| 4310 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4311 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4312 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4313 | E->getLabel()); |
| 4314 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4315 | |
| 4316 | template<typename Derived> |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4317 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4318 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4319 | OwningStmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4320 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4321 | if (SubStmt.isInvalid()) |
| 4322 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4323 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4324 | if (!getDerived().AlwaysRebuild() && |
| 4325 | SubStmt.get() == E->getSubStmt()) |
| 4326 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4327 | |
| 4328 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4329 | move(SubStmt), |
| 4330 | E->getRParenLoc()); |
| 4331 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4332 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4333 | template<typename Derived> |
| 4334 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4335 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4336 | QualType T1, T2; |
| 4337 | { |
| 4338 | // FIXME: Source location isn't quite accurate. |
| 4339 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4340 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4341 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4342 | if (T1.isNull()) |
| 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 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4346 | if (T2.isNull()) |
| 4347 | return SemaRef.ExprError(); |
| 4348 | } |
| 4349 | |
| 4350 | if (!getDerived().AlwaysRebuild() && |
| 4351 | T1 == E->getArgType1() && |
| 4352 | T2 == E->getArgType2()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4353 | return SemaRef.Owned(E->Retain()); |
| 4354 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4355 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4356 | T1, T2, E->getRParenLoc()); |
| 4357 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4358 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4359 | template<typename Derived> |
| 4360 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4361 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4362 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4363 | if (Cond.isInvalid()) |
| 4364 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4365 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4366 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4367 | if (LHS.isInvalid()) |
| 4368 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4369 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4370 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4371 | if (RHS.isInvalid()) |
| 4372 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4373 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4374 | if (!getDerived().AlwaysRebuild() && |
| 4375 | Cond.get() == E->getCond() && |
| 4376 | LHS.get() == E->getLHS() && |
| 4377 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4378 | return SemaRef.Owned(E->Retain()); |
| 4379 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4380 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4381 | move(Cond), move(LHS), move(RHS), |
| 4382 | E->getRParenLoc()); |
| 4383 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4384 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4385 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4386 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4387 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4388 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4389 | } |
| 4390 | |
| 4391 | template<typename Derived> |
| 4392 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4393 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4394 | switch (E->getOperator()) { |
| 4395 | case OO_New: |
| 4396 | case OO_Delete: |
| 4397 | case OO_Array_New: |
| 4398 | case OO_Array_Delete: |
| 4399 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4400 | return SemaRef.ExprError(); |
| 4401 | |
| 4402 | case OO_Call: { |
| 4403 | // This is a call to an object's operator(). |
| 4404 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4405 | |
| 4406 | // Transform the object itself. |
| 4407 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4408 | if (Object.isInvalid()) |
| 4409 | return SemaRef.ExprError(); |
| 4410 | |
| 4411 | // FIXME: Poor location information |
| 4412 | SourceLocation FakeLParenLoc |
| 4413 | = SemaRef.PP.getLocForEndOfToken( |
| 4414 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4415 | |
| 4416 | // Transform the call arguments. |
| 4417 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4418 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4419 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4420 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4421 | break; |
| 4422 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4423 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4424 | if (Arg.isInvalid()) |
| 4425 | return SemaRef.ExprError(); |
| 4426 | |
| 4427 | // FIXME: Poor source location information. |
| 4428 | SourceLocation FakeCommaLoc |
| 4429 | = SemaRef.PP.getLocForEndOfToken( |
| 4430 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4431 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4432 | Args.push_back(Arg.release()); |
| 4433 | } |
| 4434 | |
| 4435 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4436 | move_arg(Args), |
| 4437 | FakeCommaLocs.data(), |
| 4438 | E->getLocEnd()); |
| 4439 | } |
| 4440 | |
| 4441 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4442 | case OO_##Name: |
| 4443 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4444 | #include "clang/Basic/OperatorKinds.def" |
| 4445 | case OO_Subscript: |
| 4446 | // Handled below. |
| 4447 | break; |
| 4448 | |
| 4449 | case OO_Conditional: |
| 4450 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4451 | return SemaRef.ExprError(); |
| 4452 | |
| 4453 | case OO_None: |
| 4454 | case NUM_OVERLOADED_OPERATORS: |
| 4455 | llvm_unreachable("not an overloaded operator?"); |
| 4456 | return SemaRef.ExprError(); |
| 4457 | } |
| 4458 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4459 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4460 | if (Callee.isInvalid()) |
| 4461 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4462 | |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4463 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4464 | if (First.isInvalid()) |
| 4465 | return SemaRef.ExprError(); |
| 4466 | |
| 4467 | OwningExprResult Second(SemaRef); |
| 4468 | if (E->getNumArgs() == 2) { |
| 4469 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4470 | if (Second.isInvalid()) |
| 4471 | return SemaRef.ExprError(); |
| 4472 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4473 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4474 | if (!getDerived().AlwaysRebuild() && |
| 4475 | Callee.get() == E->getCallee() && |
| 4476 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4477 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4478 | return SemaRef.Owned(E->Retain()); |
| 4479 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4480 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4481 | E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4482 | move(Callee), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4483 | move(First), |
| 4484 | move(Second)); |
| 4485 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4486 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4487 | template<typename Derived> |
| 4488 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4489 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4490 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4491 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4492 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4493 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4494 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4495 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4496 | TypeSourceInfo *OldT; |
| 4497 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4498 | { |
| 4499 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4500 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4501 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4502 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4503 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4504 | OldT = E->getTypeInfoAsWritten(); |
| 4505 | NewT = getDerived().TransformType(OldT); |
| 4506 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4507 | return SemaRef.ExprError(); |
| 4508 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4509 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4510 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4511 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4512 | if (SubExpr.isInvalid()) |
| 4513 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4514 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4515 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4516 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4517 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4518 | return SemaRef.Owned(E->Retain()); |
| 4519 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4520 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4521 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4522 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4523 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4524 | SourceLocation FakeRParenLoc |
| 4525 | = SemaRef.PP.getLocForEndOfToken( |
| 4526 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4527 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4528 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4529 | FakeLAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4530 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4531 | FakeRAngleLoc, |
| 4532 | FakeRAngleLoc, |
| 4533 | move(SubExpr), |
| 4534 | FakeRParenLoc); |
| 4535 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4536 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4537 | template<typename Derived> |
| 4538 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4539 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4540 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4541 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4542 | |
| 4543 | template<typename Derived> |
| 4544 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4545 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4546 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4547 | } |
| 4548 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4549 | template<typename Derived> |
| 4550 | Sema::OwningExprResult |
| 4551 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4552 | CXXReinterpretCastExpr *E) { |
| 4553 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4554 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4555 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4556 | template<typename Derived> |
| 4557 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4558 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4559 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4560 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4561 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4562 | template<typename Derived> |
| 4563 | Sema::OwningExprResult |
| 4564 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4565 | CXXFunctionalCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4566 | TypeSourceInfo *OldT; |
| 4567 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4568 | { |
| 4569 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4570 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4571 | OldT = E->getTypeInfoAsWritten(); |
| 4572 | NewT = getDerived().TransformType(OldT); |
| 4573 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4574 | return SemaRef.ExprError(); |
| 4575 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4576 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4577 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4578 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4579 | if (SubExpr.isInvalid()) |
| 4580 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4581 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4582 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4583 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4584 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4585 | return SemaRef.Owned(E->Retain()); |
| 4586 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4587 | // FIXME: The end of the type's source range is wrong |
| 4588 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4589 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4590 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4591 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4592 | move(SubExpr), |
| 4593 | E->getRParenLoc()); |
| 4594 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4595 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4596 | template<typename Derived> |
| 4597 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4598 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4599 | if (E->isTypeOperand()) { |
| 4600 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4601 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4602 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4603 | if (T.isNull()) |
| 4604 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4605 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4606 | if (!getDerived().AlwaysRebuild() && |
| 4607 | T == E->getTypeOperand()) |
| 4608 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4609 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4610 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4611 | /*FIXME:*/E->getLocStart(), |
| 4612 | T, |
| 4613 | E->getLocEnd()); |
| 4614 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4615 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4616 | // We don't know whether the expression is potentially evaluated until |
| 4617 | // after we perform semantic analysis, so the expression is potentially |
| 4618 | // potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4619 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4620 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4621 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4622 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4623 | if (SubExpr.isInvalid()) |
| 4624 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4625 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4626 | if (!getDerived().AlwaysRebuild() && |
| 4627 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4628 | return SemaRef.Owned(E->Retain()); |
| 4629 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4630 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4631 | /*FIXME:*/E->getLocStart(), |
| 4632 | move(SubExpr), |
| 4633 | E->getLocEnd()); |
| 4634 | } |
| 4635 | |
| 4636 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4637 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4638 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4639 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4640 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4641 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4642 | template<typename Derived> |
| 4643 | Sema::OwningExprResult |
| 4644 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4645 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4646 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4647 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4648 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4649 | template<typename Derived> |
| 4650 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4651 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4652 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4653 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4654 | QualType T = getDerived().TransformType(E->getType()); |
| 4655 | if (T.isNull()) |
| 4656 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4657 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4658 | if (!getDerived().AlwaysRebuild() && |
| 4659 | T == E->getType()) |
| 4660 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4661 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 4662 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4663 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4664 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4665 | template<typename Derived> |
| 4666 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4667 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4668 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4669 | if (SubExpr.isInvalid()) |
| 4670 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 4673 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4674 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4675 | |
| 4676 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4677 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4678 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4679 | template<typename Derived> |
| 4680 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4681 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4682 | ParmVarDecl *Param |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4683 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 4684 | E->getParam())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4685 | if (!Param) |
| 4686 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4687 | |
Chandler Carruth | 53cb6f8 | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 4688 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4689 | Param == E->getParam()) |
| 4690 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4691 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 4692 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4693 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4694 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4695 | template<typename Derived> |
| 4696 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4697 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4698 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4699 | |
| 4700 | QualType T = getDerived().TransformType(E->getType()); |
| 4701 | if (T.isNull()) |
| 4702 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4703 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4704 | if (!getDerived().AlwaysRebuild() && |
| 4705 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4706 | return SemaRef.Owned(E->Retain()); |
| 4707 | |
| 4708 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4709 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4710 | T, |
| 4711 | E->getRParenLoc()); |
| 4712 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4713 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4714 | template<typename Derived> |
| 4715 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4716 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4717 | // Transform the type that we're allocating |
| 4718 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4719 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4720 | if (AllocType.isNull()) |
| 4721 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4722 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4723 | // Transform the size of the array we're allocating (if any). |
| 4724 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4725 | if (ArraySize.isInvalid()) |
| 4726 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4727 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4728 | // Transform the placement arguments (if any). |
| 4729 | bool ArgumentChanged = false; |
| 4730 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4731 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4732 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4733 | if (Arg.isInvalid()) |
| 4734 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4735 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4736 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4737 | PlacementArgs.push_back(Arg.take()); |
| 4738 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4739 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4740 | // transform the constructor arguments (if any). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4741 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4742 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4743 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4744 | if (Arg.isInvalid()) |
| 4745 | return SemaRef.ExprError(); |
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 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4748 | ConstructorArgs.push_back(Arg.take()); |
| 4749 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4750 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4751 | // Transform constructor, new operator, and delete operator. |
| 4752 | CXXConstructorDecl *Constructor = 0; |
| 4753 | if (E->getConstructor()) { |
| 4754 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4755 | getDerived().TransformDecl(E->getLocStart(), |
| 4756 | E->getConstructor())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4757 | if (!Constructor) |
| 4758 | return SemaRef.ExprError(); |
| 4759 | } |
| 4760 | |
| 4761 | FunctionDecl *OperatorNew = 0; |
| 4762 | if (E->getOperatorNew()) { |
| 4763 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4764 | getDerived().TransformDecl(E->getLocStart(), |
| 4765 | E->getOperatorNew())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4766 | if (!OperatorNew) |
| 4767 | return SemaRef.ExprError(); |
| 4768 | } |
| 4769 | |
| 4770 | FunctionDecl *OperatorDelete = 0; |
| 4771 | if (E->getOperatorDelete()) { |
| 4772 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4773 | getDerived().TransformDecl(E->getLocStart(), |
| 4774 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4775 | if (!OperatorDelete) |
| 4776 | return SemaRef.ExprError(); |
| 4777 | } |
| 4778 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4779 | if (!getDerived().AlwaysRebuild() && |
| 4780 | AllocType == E->getAllocatedType() && |
| 4781 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4782 | Constructor == E->getConstructor() && |
| 4783 | OperatorNew == E->getOperatorNew() && |
| 4784 | OperatorDelete == E->getOperatorDelete() && |
| 4785 | !ArgumentChanged) { |
| 4786 | // Mark any declarations we need as referenced. |
| 4787 | // FIXME: instantiation-specific. |
| 4788 | if (Constructor) |
| 4789 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 4790 | if (OperatorNew) |
| 4791 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 4792 | if (OperatorDelete) |
| 4793 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4794 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4795 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4796 | |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 4797 | if (!ArraySize.get()) { |
| 4798 | // If no array size was specified, but the new expression was |
| 4799 | // instantiated with an array type (e.g., "new T" where T is |
| 4800 | // instantiated with "int[4]"), extract the outer bound from the |
| 4801 | // array type as our array size. We do this with constant and |
| 4802 | // dependently-sized array types. |
| 4803 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 4804 | if (!ArrayT) { |
| 4805 | // Do nothing |
| 4806 | } else if (const ConstantArrayType *ConsArrayT |
| 4807 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 4808 | ArraySize |
| 4809 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 4810 | ConsArrayT->getSize(), |
| 4811 | SemaRef.Context.getSizeType(), |
| 4812 | /*FIXME:*/E->getLocStart())); |
| 4813 | AllocType = ConsArrayT->getElementType(); |
| 4814 | } else if (const DependentSizedArrayType *DepArrayT |
| 4815 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 4816 | if (DepArrayT->getSizeExpr()) { |
| 4817 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 4818 | AllocType = DepArrayT->getElementType(); |
| 4819 | } |
| 4820 | } |
| 4821 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4822 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4823 | E->isGlobalNew(), |
| 4824 | /*FIXME:*/E->getLocStart(), |
| 4825 | move_arg(PlacementArgs), |
| 4826 | /*FIXME:*/E->getLocStart(), |
| 4827 | E->isParenTypeId(), |
| 4828 | AllocType, |
| 4829 | /*FIXME:*/E->getLocStart(), |
| 4830 | /*FIXME:*/SourceRange(), |
| 4831 | move(ArraySize), |
| 4832 | /*FIXME:*/E->getLocStart(), |
| 4833 | move_arg(ConstructorArgs), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4834 | E->getLocEnd()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4835 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4836 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4837 | template<typename Derived> |
| 4838 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4839 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4840 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4841 | if (Operand.isInvalid()) |
| 4842 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4843 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4844 | // Transform the delete operator, if known. |
| 4845 | FunctionDecl *OperatorDelete = 0; |
| 4846 | if (E->getOperatorDelete()) { |
| 4847 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4848 | getDerived().TransformDecl(E->getLocStart(), |
| 4849 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4850 | if (!OperatorDelete) |
| 4851 | return SemaRef.ExprError(); |
| 4852 | } |
| 4853 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4854 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4855 | Operand.get() == E->getArgument() && |
| 4856 | OperatorDelete == E->getOperatorDelete()) { |
| 4857 | // Mark any declarations we need as referenced. |
| 4858 | // FIXME: instantiation-specific. |
| 4859 | if (OperatorDelete) |
| 4860 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4861 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 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 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4865 | E->isGlobalDelete(), |
| 4866 | E->isArrayForm(), |
| 4867 | move(Operand)); |
| 4868 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4869 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4870 | template<typename Derived> |
| 4871 | Sema::OwningExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4872 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4873 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4874 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4875 | if (Base.isInvalid()) |
| 4876 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4877 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4878 | Sema::TypeTy *ObjectTypePtr = 0; |
| 4879 | bool MayBePseudoDestructor = false; |
| 4880 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 4881 | E->getOperatorLoc(), |
| 4882 | E->isArrow()? tok::arrow : tok::period, |
| 4883 | ObjectTypePtr, |
| 4884 | MayBePseudoDestructor); |
| 4885 | if (Base.isInvalid()) |
| 4886 | return SemaRef.ExprError(); |
| 4887 | |
| 4888 | QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4889 | NestedNameSpecifier *Qualifier |
| 4890 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | b10cd04 | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 4891 | E->getQualifierRange(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4892 | ObjectType); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4893 | if (E->getQualifier() && !Qualifier) |
| 4894 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4895 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4896 | PseudoDestructorTypeStorage Destroyed; |
| 4897 | if (E->getDestroyedTypeInfo()) { |
| 4898 | TypeSourceInfo *DestroyedTypeInfo |
| 4899 | = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType); |
| 4900 | if (!DestroyedTypeInfo) |
| 4901 | return SemaRef.ExprError(); |
| 4902 | Destroyed = DestroyedTypeInfo; |
| 4903 | } else if (ObjectType->isDependentType()) { |
| 4904 | // We aren't likely to be able to resolve the identifier down to a type |
| 4905 | // now anyway, so just retain the identifier. |
| 4906 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 4907 | E->getDestroyedTypeLoc()); |
| 4908 | } else { |
| 4909 | // Look for a destructor known with the given name. |
| 4910 | CXXScopeSpec SS; |
| 4911 | if (Qualifier) { |
| 4912 | SS.setScopeRep(Qualifier); |
| 4913 | SS.setRange(E->getQualifierRange()); |
| 4914 | } |
| 4915 | |
| 4916 | Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(), |
| 4917 | *E->getDestroyedTypeIdentifier(), |
| 4918 | E->getDestroyedTypeLoc(), |
| 4919 | /*Scope=*/0, |
| 4920 | SS, ObjectTypePtr, |
| 4921 | false); |
| 4922 | if (!T) |
| 4923 | return SemaRef.ExprError(); |
| 4924 | |
| 4925 | Destroyed |
| 4926 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 4927 | E->getDestroyedTypeLoc()); |
| 4928 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4929 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4930 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 4931 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4932 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(), |
| 4933 | ObjectType); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4934 | if (!ScopeTypeInfo) |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4935 | return SemaRef.ExprError(); |
| 4936 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4937 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4938 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4939 | E->getOperatorLoc(), |
| 4940 | E->isArrow(), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4941 | Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4942 | E->getQualifierRange(), |
| 4943 | ScopeTypeInfo, |
| 4944 | E->getColonColonLoc(), |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 4945 | E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4946 | Destroyed); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4947 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4948 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4949 | template<typename Derived> |
| 4950 | Sema::OwningExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 4951 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4952 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4953 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 4954 | |
| 4955 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 4956 | Sema::LookupOrdinaryName); |
| 4957 | |
| 4958 | // Transform all the decls. |
| 4959 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 4960 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4961 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 4962 | getDerived().TransformDecl(Old->getNameLoc(), |
| 4963 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 4964 | if (!InstD) { |
| 4965 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 4966 | // This can happen because of dependent hiding. |
| 4967 | if (isa<UsingShadowDecl>(*I)) |
| 4968 | continue; |
| 4969 | else |
| 4970 | return SemaRef.ExprError(); |
| 4971 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4972 | |
| 4973 | // Expand using declarations. |
| 4974 | if (isa<UsingDecl>(InstD)) { |
| 4975 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 4976 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 4977 | E = UD->shadow_end(); I != E; ++I) |
| 4978 | R.addDecl(*I); |
| 4979 | continue; |
| 4980 | } |
| 4981 | |
| 4982 | R.addDecl(InstD); |
| 4983 | } |
| 4984 | |
| 4985 | // Resolve a kind, but don't do any further analysis. If it's |
| 4986 | // ambiguous, the callee needs to deal with it. |
| 4987 | R.resolveKind(); |
| 4988 | |
| 4989 | // Rebuild the nested-name qualifier, if present. |
| 4990 | CXXScopeSpec SS; |
| 4991 | NestedNameSpecifier *Qualifier = 0; |
| 4992 | if (Old->getQualifier()) { |
| 4993 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4994 | Old->getQualifierRange()); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4995 | if (!Qualifier) |
| 4996 | return SemaRef.ExprError(); |
| 4997 | |
| 4998 | SS.setScopeRep(Qualifier); |
| 4999 | SS.setRange(Old->getQualifierRange()); |
| 5000 | } |
| 5001 | |
| 5002 | // If we have no template arguments, it's a normal declaration name. |
| 5003 | if (!Old->hasExplicitTemplateArgs()) |
| 5004 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 5005 | |
| 5006 | // If we have template arguments, rebuild them, then rebuild the |
| 5007 | // templateid expression. |
| 5008 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 5009 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5010 | TemplateArgumentLoc Loc; |
| 5011 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 5012 | return SemaRef.ExprError(); |
| 5013 | TransArgs.addArgument(Loc); |
| 5014 | } |
| 5015 | |
| 5016 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 5017 | TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5018 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5019 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5020 | template<typename Derived> |
| 5021 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5022 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5023 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5024 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5025 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 5026 | if (T.isNull()) |
| 5027 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5028 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5029 | if (!getDerived().AlwaysRebuild() && |
| 5030 | T == E->getQueriedType()) |
| 5031 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5032 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5033 | // FIXME: Bad location information |
| 5034 | SourceLocation FakeLParenLoc |
| 5035 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5036 | |
| 5037 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5038 | E->getLocStart(), |
| 5039 | /*FIXME:*/FakeLParenLoc, |
| 5040 | T, |
| 5041 | E->getLocEnd()); |
| 5042 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5043 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5044 | template<typename Derived> |
| 5045 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5046 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5047 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5048 | NestedNameSpecifier *NNS |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5049 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5050 | E->getQualifierRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5051 | if (!NNS) |
| 5052 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5053 | |
| 5054 | DeclarationName Name |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5055 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 5056 | if (!Name) |
| 5057 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5058 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5059 | if (!E->hasExplicitTemplateArgs()) { |
| 5060 | if (!getDerived().AlwaysRebuild() && |
| 5061 | NNS == E->getQualifier() && |
| 5062 | Name == E->getDeclName()) |
| 5063 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5064 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5065 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5066 | E->getQualifierRange(), |
| 5067 | Name, E->getLocation(), |
| 5068 | /*TemplateArgs*/ 0); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5069 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5070 | |
| 5071 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5072 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5073 | TemplateArgumentLoc Loc; |
| 5074 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5075 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5076 | TransArgs.addArgument(Loc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5077 | } |
| 5078 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5079 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5080 | E->getQualifierRange(), |
| 5081 | Name, E->getLocation(), |
| 5082 | &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5083 | } |
| 5084 | |
| 5085 | template<typename Derived> |
| 5086 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5087 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 5088 | // CXXConstructExprs are always implicit, so when we have a |
| 5089 | // 1-argument construction we just transform that argument. |
| 5090 | if (E->getNumArgs() == 1 || |
| 5091 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 5092 | return getDerived().TransformExpr(E->getArg(0)); |
| 5093 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5094 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 5095 | |
| 5096 | QualType T = getDerived().TransformType(E->getType()); |
| 5097 | if (T.isNull()) |
| 5098 | return SemaRef.ExprError(); |
| 5099 | |
| 5100 | CXXConstructorDecl *Constructor |
| 5101 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5102 | getDerived().TransformDecl(E->getLocStart(), |
| 5103 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5104 | if (!Constructor) |
| 5105 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5106 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5107 | bool ArgumentChanged = false; |
| 5108 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5109 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5110 | ArgEnd = E->arg_end(); |
| 5111 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5112 | if (getDerived().DropCallArgument(*Arg)) { |
| 5113 | ArgumentChanged = true; |
| 5114 | break; |
| 5115 | } |
| 5116 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5117 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5118 | if (TransArg.isInvalid()) |
| 5119 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5120 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5121 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5122 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5123 | } |
| 5124 | |
| 5125 | if (!getDerived().AlwaysRebuild() && |
| 5126 | T == E->getType() && |
| 5127 | Constructor == E->getConstructor() && |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5128 | !ArgumentChanged) { |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5129 | // Mark the constructor as referenced. |
| 5130 | // FIXME: Instantiation-specific |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5131 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5132 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5133 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5134 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 5135 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 5136 | Constructor, E->isElidable(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5137 | move_arg(Args)); |
| 5138 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5139 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5140 | /// \brief Transform a C++ temporary-binding expression. |
| 5141 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5142 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 5143 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5144 | template<typename Derived> |
| 5145 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5146 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5147 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5148 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5149 | |
Anders Carlsson | eb60edf | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 5150 | /// \brief Transform a C++ reference-binding expression. |
| 5151 | /// |
| 5152 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 5153 | /// transform the subexpression and return that. |
| 5154 | template<typename Derived> |
| 5155 | Sema::OwningExprResult |
| 5156 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 5157 | return getDerived().TransformExpr(E->getSubExpr()); |
| 5158 | } |
| 5159 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5160 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5161 | /// be destroyed after the expression is evaluated. |
| 5162 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5163 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 5164 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5165 | template<typename Derived> |
| 5166 | Sema::OwningExprResult |
| 5167 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5168 | CXXExprWithTemporaries *E) { |
| 5169 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5170 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5171 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5172 | template<typename Derived> |
| 5173 | Sema::OwningExprResult |
| 5174 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5175 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5176 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5177 | QualType T = getDerived().TransformType(E->getType()); |
| 5178 | if (T.isNull()) |
| 5179 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5180 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5181 | CXXConstructorDecl *Constructor |
| 5182 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5183 | getDerived().TransformDecl(E->getLocStart(), |
| 5184 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5185 | if (!Constructor) |
| 5186 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5187 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5188 | bool ArgumentChanged = false; |
| 5189 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5190 | Args.reserve(E->getNumArgs()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5191 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5192 | ArgEnd = E->arg_end(); |
| 5193 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5194 | if (getDerived().DropCallArgument(*Arg)) { |
| 5195 | ArgumentChanged = true; |
| 5196 | break; |
| 5197 | } |
| 5198 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5199 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5200 | if (TransArg.isInvalid()) |
| 5201 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5202 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5203 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5204 | Args.push_back((Expr *)TransArg.release()); |
| 5205 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5206 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5207 | if (!getDerived().AlwaysRebuild() && |
| 5208 | T == E->getType() && |
| 5209 | Constructor == E->getConstructor() && |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5210 | !ArgumentChanged) { |
| 5211 | // FIXME: Instantiation-specific |
| 5212 | SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor); |
Chandler Carruth | a3ce8ae | 2010-03-31 18:34:58 +0000 | [diff] [blame] | 5213 | return SemaRef.MaybeBindToTemporary(E->Retain()); |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5214 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5215 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5216 | // FIXME: Bogus location information |
| 5217 | SourceLocation CommaLoc; |
| 5218 | if (Args.size() > 1) { |
| 5219 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5220 | CommaLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5221 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 5222 | } |
| 5223 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 5224 | T, |
| 5225 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5226 | move_arg(Args), |
| 5227 | &CommaLoc, |
| 5228 | E->getLocEnd()); |
| 5229 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5230 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5231 | template<typename Derived> |
| 5232 | Sema::OwningExprResult |
| 5233 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5234 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5235 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5236 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 5237 | if (T.isNull()) |
| 5238 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5239 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5240 | bool ArgumentChanged = false; |
| 5241 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5242 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 5243 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 5244 | ArgEnd = E->arg_end(); |
| 5245 | Arg != ArgEnd; ++Arg) { |
| 5246 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5247 | if (TransArg.isInvalid()) |
| 5248 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5249 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5250 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5251 | FakeCommaLocs.push_back( |
| 5252 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 5253 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5254 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5255 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5256 | if (!getDerived().AlwaysRebuild() && |
| 5257 | T == E->getTypeAsWritten() && |
| 5258 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5259 | return SemaRef.Owned(E->Retain()); |
| 5260 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5261 | // FIXME: we're faking the locations of the commas |
| 5262 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5263 | T, |
| 5264 | E->getLParenLoc(), |
| 5265 | move_arg(Args), |
| 5266 | FakeCommaLocs.data(), |
| 5267 | E->getRParenLoc()); |
| 5268 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5269 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5270 | template<typename Derived> |
| 5271 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5272 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5273 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5274 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5275 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5276 | Expr *OldBase; |
| 5277 | QualType BaseType; |
| 5278 | QualType ObjectType; |
| 5279 | if (!E->isImplicitAccess()) { |
| 5280 | OldBase = E->getBase(); |
| 5281 | Base = getDerived().TransformExpr(OldBase); |
| 5282 | if (Base.isInvalid()) |
| 5283 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5284 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5285 | // Start the member reference and compute the object's type. |
| 5286 | Sema::TypeTy *ObjectTy = 0; |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5287 | bool MayBePseudoDestructor = false; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5288 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5289 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5290 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5291 | ObjectTy, |
| 5292 | MayBePseudoDestructor); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5293 | if (Base.isInvalid()) |
| 5294 | return SemaRef.ExprError(); |
| 5295 | |
| 5296 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5297 | BaseType = ((Expr*) Base.get())->getType(); |
| 5298 | } else { |
| 5299 | OldBase = 0; |
| 5300 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5301 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5302 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5303 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5304 | // Transform the first part of the nested-name-specifier that qualifies |
| 5305 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5306 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5307 | = getDerived().TransformFirstQualifierInScope( |
| 5308 | E->getFirstQualifierFoundInScope(), |
| 5309 | E->getQualifierRange().getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5310 | |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5311 | NestedNameSpecifier *Qualifier = 0; |
| 5312 | if (E->getQualifier()) { |
| 5313 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5314 | E->getQualifierRange(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5315 | ObjectType, |
| 5316 | FirstQualifierInScope); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5317 | if (!Qualifier) |
| 5318 | return SemaRef.ExprError(); |
| 5319 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5320 | |
| 5321 | DeclarationName Name |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5322 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5323 | ObjectType); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5324 | if (!Name) |
| 5325 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5326 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5327 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5328 | // This is a reference to a member without an explicitly-specified |
| 5329 | // template argument list. Optimize for this common case. |
| 5330 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5331 | Base.get() == OldBase && |
| 5332 | BaseType == E->getBaseType() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5333 | Qualifier == E->getQualifier() && |
| 5334 | Name == E->getMember() && |
| 5335 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5336 | return SemaRef.Owned(E->Retain()); |
| 5337 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5338 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5339 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5340 | E->isArrow(), |
| 5341 | E->getOperatorLoc(), |
| 5342 | Qualifier, |
| 5343 | E->getQualifierRange(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5344 | FirstQualifierInScope, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5345 | Name, |
| 5346 | E->getMemberLoc(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5347 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5348 | } |
| 5349 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5350 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5351 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5352 | TemplateArgumentLoc Loc; |
| 5353 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5354 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5355 | TransArgs.addArgument(Loc); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5356 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5357 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5358 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5359 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5360 | E->isArrow(), |
| 5361 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5362 | Qualifier, |
| 5363 | E->getQualifierRange(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5364 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5365 | Name, |
| 5366 | E->getMemberLoc(), |
| 5367 | &TransArgs); |
| 5368 | } |
| 5369 | |
| 5370 | template<typename Derived> |
| 5371 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5372 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5373 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5374 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5375 | QualType BaseType; |
| 5376 | if (!Old->isImplicitAccess()) { |
| 5377 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5378 | if (Base.isInvalid()) |
| 5379 | return SemaRef.ExprError(); |
| 5380 | BaseType = ((Expr*) Base.get())->getType(); |
| 5381 | } else { |
| 5382 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5383 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5384 | |
| 5385 | NestedNameSpecifier *Qualifier = 0; |
| 5386 | if (Old->getQualifier()) { |
| 5387 | Qualifier |
| 5388 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5389 | Old->getQualifierRange()); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5390 | if (Qualifier == 0) |
| 5391 | return SemaRef.ExprError(); |
| 5392 | } |
| 5393 | |
| 5394 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5395 | Sema::LookupOrdinaryName); |
| 5396 | |
| 5397 | // Transform all the decls. |
| 5398 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5399 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5400 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5401 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 5402 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5403 | if (!InstD) { |
| 5404 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5405 | // This can happen because of dependent hiding. |
| 5406 | if (isa<UsingShadowDecl>(*I)) |
| 5407 | continue; |
| 5408 | else |
| 5409 | return SemaRef.ExprError(); |
| 5410 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5411 | |
| 5412 | // Expand using declarations. |
| 5413 | if (isa<UsingDecl>(InstD)) { |
| 5414 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5415 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5416 | E = UD->shadow_end(); I != E; ++I) |
| 5417 | R.addDecl(*I); |
| 5418 | continue; |
| 5419 | } |
| 5420 | |
| 5421 | R.addDecl(InstD); |
| 5422 | } |
| 5423 | |
| 5424 | R.resolveKind(); |
| 5425 | |
| 5426 | TemplateArgumentListInfo TransArgs; |
| 5427 | if (Old->hasExplicitTemplateArgs()) { |
| 5428 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5429 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5430 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5431 | TemplateArgumentLoc Loc; |
| 5432 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5433 | Loc)) |
| 5434 | return SemaRef.ExprError(); |
| 5435 | TransArgs.addArgument(Loc); |
| 5436 | } |
| 5437 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5438 | |
| 5439 | // FIXME: to do this check properly, we will need to preserve the |
| 5440 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5441 | // base (and therefore couldn't do the check) and a |
| 5442 | // nested-name-qualifier (and therefore could do the lookup). |
| 5443 | NamedDecl *FirstQualifierInScope = 0; |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5444 | |
| 5445 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5446 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5447 | Old->getOperatorLoc(), |
| 5448 | Old->isArrow(), |
| 5449 | Qualifier, |
| 5450 | Old->getQualifierRange(), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5451 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5452 | R, |
| 5453 | (Old->hasExplicitTemplateArgs() |
| 5454 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5455 | } |
| 5456 | |
| 5457 | template<typename Derived> |
| 5458 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5459 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5460 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5461 | } |
| 5462 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5463 | template<typename Derived> |
| 5464 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5465 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5466 | // FIXME: poor source location |
| 5467 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 5468 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 5469 | if (EncodedType.isNull()) |
| 5470 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5471 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5472 | if (!getDerived().AlwaysRebuild() && |
| 5473 | EncodedType == E->getEncodedType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5474 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5475 | |
| 5476 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 5477 | EncodedType, |
| 5478 | E->getRParenLoc()); |
| 5479 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5480 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5481 | template<typename Derived> |
| 5482 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5483 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5484 | // FIXME: Implement this! |
| 5485 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5486 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5487 | } |
| 5488 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5489 | template<typename Derived> |
| 5490 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5491 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5492 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5493 | } |
| 5494 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5495 | template<typename Derived> |
| 5496 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5497 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5498 | ObjCProtocolDecl *Protocol |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5499 | = cast_or_null<ObjCProtocolDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5500 | getDerived().TransformDecl(E->getLocStart(), |
| 5501 | E->getProtocol())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5502 | if (!Protocol) |
| 5503 | return SemaRef.ExprError(); |
| 5504 | |
| 5505 | if (!getDerived().AlwaysRebuild() && |
| 5506 | Protocol == E->getProtocol()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5507 | return SemaRef.Owned(E->Retain()); |
| 5508 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5509 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 5510 | E->getAtLoc(), |
| 5511 | /*FIXME:*/E->getAtLoc(), |
| 5512 | /*FIXME:*/E->getAtLoc(), |
| 5513 | E->getRParenLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5514 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5515 | } |
| 5516 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5517 | template<typename Derived> |
| 5518 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5519 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5520 | // FIXME: Implement this! |
| 5521 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5522 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5523 | } |
| 5524 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5525 | template<typename Derived> |
| 5526 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5527 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5528 | // FIXME: Implement this! |
| 5529 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5530 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5531 | } |
| 5532 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5533 | template<typename Derived> |
| 5534 | Sema::OwningExprResult |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5535 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5536 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5537 | // FIXME: Implement this! |
| 5538 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5539 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5540 | } |
| 5541 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5542 | template<typename Derived> |
| 5543 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5544 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5545 | // FIXME: Implement this! |
| 5546 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5547 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5548 | } |
| 5549 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5550 | template<typename Derived> |
| 5551 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5552 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5553 | // FIXME: Implement this! |
| 5554 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5555 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5556 | } |
| 5557 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5558 | template<typename Derived> |
| 5559 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5560 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5561 | bool ArgumentChanged = false; |
| 5562 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5563 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5564 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5565 | if (SubExpr.isInvalid()) |
| 5566 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5567 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5568 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5569 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5570 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5571 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5572 | if (!getDerived().AlwaysRebuild() && |
| 5573 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5574 | return SemaRef.Owned(E->Retain()); |
| 5575 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5576 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5577 | move_arg(SubExprs), |
| 5578 | E->getRParenLoc()); |
| 5579 | } |
| 5580 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5581 | template<typename Derived> |
| 5582 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5583 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5584 | // FIXME: Implement this! |
| 5585 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5586 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5587 | } |
| 5588 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5589 | template<typename Derived> |
| 5590 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5591 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5592 | // FIXME: Implement this! |
| 5593 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5594 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5595 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5596 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5597 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5598 | // Type reconstruction |
| 5599 | //===----------------------------------------------------------------------===// |
| 5600 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5601 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5602 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5603 | SourceLocation Star) { |
| 5604 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5605 | getDerived().getBaseEntity()); |
| 5606 | } |
| 5607 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5608 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5609 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5610 | SourceLocation Star) { |
| 5611 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5612 | getDerived().getBaseEntity()); |
| 5613 | } |
| 5614 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5615 | template<typename Derived> |
| 5616 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5617 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5618 | bool WrittenAsLValue, |
| 5619 | SourceLocation Sigil) { |
| 5620 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5621 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5622 | } |
| 5623 | |
| 5624 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5625 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5626 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5627 | QualType ClassType, |
| 5628 | SourceLocation Sigil) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5629 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5630 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5631 | } |
| 5632 | |
| 5633 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5634 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5635 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType, |
| 5636 | SourceLocation Sigil) { |
| 5637 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5638 | getDerived().getBaseEntity()); |
| 5639 | } |
| 5640 | |
| 5641 | template<typename Derived> |
| 5642 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5643 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5644 | ArrayType::ArraySizeModifier SizeMod, |
| 5645 | const llvm::APInt *Size, |
| 5646 | Expr *SizeExpr, |
| 5647 | unsigned IndexTypeQuals, |
| 5648 | SourceRange BracketsRange) { |
| 5649 | if (SizeExpr || !Size) |
| 5650 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5651 | IndexTypeQuals, BracketsRange, |
| 5652 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5653 | |
| 5654 | QualType Types[] = { |
| 5655 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5656 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5657 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5658 | }; |
| 5659 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5660 | QualType SizeType; |
| 5661 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5662 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5663 | SizeType = Types[I]; |
| 5664 | break; |
| 5665 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5666 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5667 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5668 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5669 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5670 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5671 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5672 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5673 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5674 | QualType |
| 5675 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5676 | ArrayType::ArraySizeModifier SizeMod, |
| 5677 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5678 | unsigned IndexTypeQuals, |
| 5679 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5680 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5681 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5682 | } |
| 5683 | |
| 5684 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5685 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5686 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5687 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5688 | unsigned IndexTypeQuals, |
| 5689 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5690 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5691 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5692 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5693 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5694 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5695 | QualType |
| 5696 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5697 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5698 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5699 | unsigned IndexTypeQuals, |
| 5700 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5701 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5702 | SizeExpr.takeAs<Expr>(), |
| 5703 | IndexTypeQuals, BracketsRange); |
| 5704 | } |
| 5705 | |
| 5706 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5707 | QualType |
| 5708 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5709 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5710 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5711 | unsigned IndexTypeQuals, |
| 5712 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5713 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5714 | SizeExpr.takeAs<Expr>(), |
| 5715 | IndexTypeQuals, BracketsRange); |
| 5716 | } |
| 5717 | |
| 5718 | template<typename Derived> |
| 5719 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5720 | unsigned NumElements, |
| 5721 | bool IsAltiVec, bool IsPixel) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5722 | // FIXME: semantic checking! |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5723 | return SemaRef.Context.getVectorType(ElementType, NumElements, |
| 5724 | IsAltiVec, IsPixel); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5725 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5726 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5727 | template<typename Derived> |
| 5728 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5729 | unsigned NumElements, |
| 5730 | SourceLocation AttributeLoc) { |
| 5731 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5732 | NumElements, true); |
| 5733 | IntegerLiteral *VectorSize |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5734 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5735 | AttributeLoc); |
| 5736 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5737 | AttributeLoc); |
| 5738 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5739 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5740 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5741 | QualType |
| 5742 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5743 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5744 | SourceLocation AttributeLoc) { |
| 5745 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5746 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5747 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5748 | template<typename Derived> |
| 5749 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5750 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5751 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5752 | bool Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5753 | unsigned Quals) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5754 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5755 | Quals, |
| 5756 | getDerived().getBaseLocation(), |
| 5757 | getDerived().getBaseEntity()); |
| 5758 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5759 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5760 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5761 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5762 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5763 | } |
| 5764 | |
| 5765 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5766 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 5767 | assert(D && "no decl found"); |
| 5768 | if (D->isInvalidDecl()) return QualType(); |
| 5769 | |
| 5770 | TypeDecl *Ty; |
| 5771 | if (isa<UsingDecl>(D)) { |
| 5772 | UsingDecl *Using = cast<UsingDecl>(D); |
| 5773 | assert(Using->isTypeName() && |
| 5774 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 5775 | |
| 5776 | // A valid resolved using typename decl points to exactly one type decl. |
| 5777 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 5778 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 5779 | |
| 5780 | } else { |
| 5781 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 5782 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 5783 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 5784 | } |
| 5785 | |
| 5786 | return SemaRef.Context.getTypeDeclType(Ty); |
| 5787 | } |
| 5788 | |
| 5789 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5790 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5791 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5792 | } |
| 5793 | |
| 5794 | template<typename Derived> |
| 5795 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5796 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5797 | } |
| 5798 | |
| 5799 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5800 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5801 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5802 | } |
| 5803 | |
| 5804 | template<typename Derived> |
| 5805 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5806 | TemplateName Template, |
| 5807 | SourceLocation TemplateNameLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5808 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5809 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5810 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5811 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5812 | template<typename Derived> |
| 5813 | NestedNameSpecifier * |
| 5814 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5815 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5816 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5817 | QualType ObjectType, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5818 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5819 | CXXScopeSpec SS; |
| 5820 | // FIXME: The source location information is all wrong. |
| 5821 | SS.setRange(Range); |
| 5822 | SS.setScopeRep(Prefix); |
| 5823 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5824 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5825 | Range.getEnd(), II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5826 | ObjectType, |
| 5827 | FirstQualifierInScope, |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 5828 | false, false)); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5829 | } |
| 5830 | |
| 5831 | template<typename Derived> |
| 5832 | NestedNameSpecifier * |
| 5833 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5834 | SourceRange Range, |
| 5835 | NamespaceDecl *NS) { |
| 5836 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5837 | } |
| 5838 | |
| 5839 | template<typename Derived> |
| 5840 | NestedNameSpecifier * |
| 5841 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5842 | SourceRange Range, |
| 5843 | bool TemplateKW, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5844 | QualType T) { |
| 5845 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5846 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5847 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5848 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5849 | T.getTypePtr()); |
| 5850 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5851 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5852 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5853 | return 0; |
| 5854 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5855 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5856 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5857 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5858 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5859 | bool TemplateKW, |
| 5860 | TemplateDecl *Template) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5861 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5862 | Template); |
| 5863 | } |
| 5864 | |
| 5865 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5866 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5867 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5868 | const IdentifierInfo &II, |
| 5869 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5870 | CXXScopeSpec SS; |
| 5871 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5872 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5873 | UnqualifiedId Name; |
| 5874 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5875 | return getSema().ActOnDependentTemplateName( |
| 5876 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5877 | SS, |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5878 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5879 | ObjectType.getAsOpaquePtr(), |
| 5880 | /*EnteringContext=*/false) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5881 | .template getAsVal<TemplateName>(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5882 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5883 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5884 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5885 | TemplateName |
| 5886 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5887 | OverloadedOperatorKind Operator, |
| 5888 | QualType ObjectType) { |
| 5889 | CXXScopeSpec SS; |
| 5890 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5891 | SS.setScopeRep(Qualifier); |
| 5892 | UnqualifiedId Name; |
| 5893 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5894 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5895 | Operator, SymbolLocations); |
| 5896 | return getSema().ActOnDependentTemplateName( |
| 5897 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5898 | SS, |
| 5899 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5900 | ObjectType.getAsOpaquePtr(), |
| 5901 | /*EnteringContext=*/false) |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5902 | .template getAsVal<TemplateName>(); |
| 5903 | } |
| 5904 | |
| 5905 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5906 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5907 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5908 | SourceLocation OpLoc, |
| 5909 | ExprArg Callee, |
| 5910 | ExprArg First, |
| 5911 | ExprArg Second) { |
| 5912 | Expr *FirstExpr = (Expr *)First.get(); |
| 5913 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5914 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5915 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5916 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5917 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5918 | if (Op == OO_Subscript) { |
| 5919 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5920 | !SecondExpr->getType()->isOverloadableType()) |
| 5921 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5922 | CalleeExpr->getLocStart(), |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5923 | move(Second), OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 5924 | } else if (Op == OO_Arrow) { |
| 5925 | // -> is never a builtin operation. |
| 5926 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5927 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5928 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5929 | // The argument is not of overloadable type, so try to create a |
| 5930 | // built-in unary operation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5931 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5932 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5933 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5934 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5935 | } |
| 5936 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5937 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5938 | !SecondExpr->getType()->isOverloadableType()) { |
| 5939 | // Neither of the arguments is an overloadable type, so try to |
| 5940 | // create a built-in binary operation. |
| 5941 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5942 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5943 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5944 | if (Result.isInvalid()) |
| 5945 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5946 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5947 | First.release(); |
| 5948 | Second.release(); |
| 5949 | return move(Result); |
| 5950 | } |
| 5951 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5952 | |
| 5953 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5954 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5955 | UnresolvedSet<16> Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5956 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5957 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 5958 | assert(ULE->requiresADL()); |
| 5959 | |
| 5960 | // FIXME: Do we have to check |
| 5961 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5962 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5963 | } else { |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5964 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5965 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5966 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5967 | // Add any functions found via argument-dependent lookup. |
| 5968 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5969 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5970 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5971 | // Create the overloaded operator invocation for unary operators. |
| 5972 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5973 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5974 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5975 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5976 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5977 | |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5978 | if (Op == OO_Subscript) |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5979 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 5980 | OpLoc, |
| 5981 | move(First), |
| 5982 | move(Second)); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5983 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5984 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5985 | BinaryOperator::Opcode Opc = |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5986 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5987 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5988 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5989 | if (Result.isInvalid()) |
| 5990 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5991 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5992 | First.release(); |
| 5993 | Second.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5994 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5995 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5996 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5997 | template<typename Derived> |
| 5998 | Sema::OwningExprResult |
| 5999 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 6000 | SourceLocation OperatorLoc, |
| 6001 | bool isArrow, |
| 6002 | NestedNameSpecifier *Qualifier, |
| 6003 | SourceRange QualifierRange, |
| 6004 | TypeSourceInfo *ScopeType, |
| 6005 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6006 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6007 | PseudoDestructorTypeStorage Destroyed) { |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6008 | CXXScopeSpec SS; |
| 6009 | if (Qualifier) { |
| 6010 | SS.setRange(QualifierRange); |
| 6011 | SS.setScopeRep(Qualifier); |
| 6012 | } |
| 6013 | |
| 6014 | Expr *BaseE = (Expr *)Base.get(); |
| 6015 | QualType BaseType = BaseE->getType(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6016 | if (BaseE->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6017 | (!isArrow && !BaseType->getAs<RecordType>()) || |
| 6018 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | bf2ca2f | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 6019 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 6020 | ->template getAs<RecordType>())){ |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6021 | // This pseudo-destructor expression is still a pseudo-destructor. |
| 6022 | return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc, |
| 6023 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6024 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6025 | Destroyed, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6026 | /*FIXME?*/true); |
| 6027 | } |
| 6028 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6029 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6030 | DeclarationName Name |
| 6031 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 6032 | SemaRef.Context.getCanonicalType(DestroyedType->getType())); |
| 6033 | |
| 6034 | // FIXME: the ScopeType should be tacked onto SS. |
| 6035 | |
| 6036 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 6037 | OperatorLoc, isArrow, |
| 6038 | SS, /*FIXME: FirstQualifier*/ 0, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6039 | Name, Destroyed.getLocation(), |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6040 | /*TemplateArgs*/ 0); |
| 6041 | } |
| 6042 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6043 | } // end namespace clang |
| 6044 | |
| 6045 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |