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 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 318 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL, |
| 319 | QualType ObjectType); |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 320 | |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 321 | QualType |
| 322 | TransformTemplateSpecializationType(const TemplateSpecializationType *T, |
| 323 | QualType ObjectType); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 324 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 325 | OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 326 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 327 | #define STMT(Node, Parent) \ |
| 328 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 329 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 330 | OwningExprResult Transform##Node(Node *E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 331 | #define ABSTRACT_EXPR(Node, Parent) |
| 332 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 333 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 334 | /// \brief Build a new pointer type given its pointee type. |
| 335 | /// |
| 336 | /// By default, performs semantic analysis when building the pointer type. |
| 337 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 338 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 339 | |
| 340 | /// \brief Build a new block pointer type given its pointee type. |
| 341 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 342 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 343 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 344 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 345 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 346 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 347 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 348 | /// By default, performs semantic analysis when building the |
| 349 | /// reference type. Subclasses may override this routine to provide |
| 350 | /// different behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 351 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 352 | /// \param LValue whether the type was written with an lvalue sigil |
| 353 | /// or an rvalue sigil. |
| 354 | QualType RebuildReferenceType(QualType ReferentType, |
| 355 | bool LValue, |
| 356 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 357 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 358 | /// \brief Build a new member pointer type given the pointee type and the |
| 359 | /// class type it refers into. |
| 360 | /// |
| 361 | /// By default, performs semantic analysis when building the member pointer |
| 362 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 363 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 364 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 365 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 366 | /// \brief Build a new Objective C object pointer type. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 367 | QualType RebuildObjCObjectPointerType(QualType PointeeType, |
| 368 | SourceLocation Sigil); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 369 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 370 | /// \brief Build a new array type given the element type, size |
| 371 | /// modifier, size of the array (if known), size expression, and index type |
| 372 | /// qualifiers. |
| 373 | /// |
| 374 | /// By default, performs semantic analysis when building the array type. |
| 375 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 376 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 377 | QualType RebuildArrayType(QualType ElementType, |
| 378 | ArrayType::ArraySizeModifier SizeMod, |
| 379 | const llvm::APInt *Size, |
| 380 | Expr *SizeExpr, |
| 381 | unsigned IndexTypeQuals, |
| 382 | SourceRange BracketsRange); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 383 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 384 | /// \brief Build a new constant array type given the element type, size |
| 385 | /// modifier, (known) size of the array, and index type qualifiers. |
| 386 | /// |
| 387 | /// By default, performs semantic analysis when building the array type. |
| 388 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 389 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 390 | ArrayType::ArraySizeModifier SizeMod, |
| 391 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 392 | unsigned IndexTypeQuals, |
| 393 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 394 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 395 | /// \brief Build a new incomplete array type given the element type, size |
| 396 | /// modifier, and index type qualifiers. |
| 397 | /// |
| 398 | /// By default, performs semantic analysis when building the array type. |
| 399 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 400 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 401 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 402 | unsigned IndexTypeQuals, |
| 403 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 404 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 405 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 406 | /// size modifier, size expression, and index type qualifiers. |
| 407 | /// |
| 408 | /// By default, performs semantic analysis when building the array type. |
| 409 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 410 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 411 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 412 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 413 | unsigned IndexTypeQuals, |
| 414 | SourceRange BracketsRange); |
| 415 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 416 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 417 | /// size modifier, size expression, and index type qualifiers. |
| 418 | /// |
| 419 | /// By default, performs semantic analysis when building the array type. |
| 420 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 421 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 422 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 423 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 424 | unsigned IndexTypeQuals, |
| 425 | SourceRange BracketsRange); |
| 426 | |
| 427 | /// \brief Build a new vector type given the element type and |
| 428 | /// number of elements. |
| 429 | /// |
| 430 | /// By default, performs semantic analysis when building the vector type. |
| 431 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 432 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
| 433 | bool IsAltiVec, bool IsPixel); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 434 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 435 | /// \brief Build a new extended vector type given the element type and |
| 436 | /// number of elements. |
| 437 | /// |
| 438 | /// By default, performs semantic analysis when building the vector type. |
| 439 | /// Subclasses may override this routine to provide different behavior. |
| 440 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 441 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 442 | |
| 443 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 444 | /// given the element type and number of elements. |
| 445 | /// |
| 446 | /// By default, performs semantic analysis when building the vector type. |
| 447 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 448 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 449 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 450 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 451 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 452 | /// \brief Build a new function type. |
| 453 | /// |
| 454 | /// By default, performs semantic analysis when building the function type. |
| 455 | /// Subclasses may override this routine to provide different behavior. |
| 456 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 457 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 458 | unsigned NumParamTypes, |
| 459 | bool Variadic, unsigned Quals); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 460 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 461 | /// \brief Build a new unprototyped function type. |
| 462 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 463 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 464 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 465 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 466 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 467 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 468 | /// \brief Build a new typedef type. |
| 469 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 470 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 471 | } |
| 472 | |
| 473 | /// \brief Build a new class/struct/union type. |
| 474 | QualType RebuildRecordType(RecordDecl *Record) { |
| 475 | return SemaRef.Context.getTypeDeclType(Record); |
| 476 | } |
| 477 | |
| 478 | /// \brief Build a new Enum type. |
| 479 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 480 | return SemaRef.Context.getTypeDeclType(Enum); |
| 481 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 482 | |
| 483 | /// \brief Build a new elaborated type. |
| 484 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) { |
| 485 | return SemaRef.Context.getElaboratedType(T, Tag); |
| 486 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 487 | |
| 488 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 489 | /// |
| 490 | /// By default, performs semantic analysis when building the typeof type. |
| 491 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 492 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 493 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 494 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 495 | /// |
| 496 | /// By default, builds a new TypeOfType with the given underlying type. |
| 497 | QualType RebuildTypeOfType(QualType Underlying); |
| 498 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 499 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 500 | /// |
| 501 | /// By default, performs semantic analysis when building the decltype type. |
| 502 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 503 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 504 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 505 | /// \brief Build a new template specialization type. |
| 506 | /// |
| 507 | /// By default, performs semantic analysis when building the template |
| 508 | /// specialization type. Subclasses may override this routine to provide |
| 509 | /// different behavior. |
| 510 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 511 | SourceLocation TemplateLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 512 | const TemplateArgumentListInfo &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 513 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 514 | /// \brief Build a new qualified name type. |
| 515 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 516 | /// By default, builds a new QualifiedNameType type from the |
| 517 | /// nested-name-specifier and the named type. Subclasses may override |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 518 | /// this routine to provide different behavior. |
| 519 | QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) { |
| 520 | return SemaRef.Context.getQualifiedNameType(NNS, Named); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 521 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 522 | |
| 523 | /// \brief Build a new typename type that refers to a template-id. |
| 524 | /// |
| 525 | /// By default, builds a new TypenameType type from the nested-name-specifier |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 526 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 527 | /// different behavior. |
| 528 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) { |
Douglas Gregor | ae62889 | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 529 | if (NNS->isDependent()) { |
| 530 | CXXScopeSpec SS; |
| 531 | SS.setScopeRep(NNS); |
| 532 | if (!SemaRef.computeDeclContext(SS)) |
| 533 | return SemaRef.Context.getTypenameType(NNS, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 534 | cast<TemplateSpecializationType>(T)); |
Douglas Gregor | ae62889 | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 535 | } |
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 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 538 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 539 | |
| 540 | /// \brief Build a new typename type that refers to an identifier. |
| 541 | /// |
| 542 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 543 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 544 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 545 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 546 | const IdentifierInfo *Id, |
| 547 | SourceRange SR) { |
| 548 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 549 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 550 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 551 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 552 | /// identifier that names the next step in the nested-name-specifier. |
| 553 | /// |
| 554 | /// By default, performs semantic analysis when building the new |
| 555 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 556 | /// different behavior. |
| 557 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 558 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 559 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 560 | QualType ObjectType, |
| 561 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 562 | |
| 563 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 564 | /// namespace named in the next step in the nested-name-specifier. |
| 565 | /// |
| 566 | /// By default, performs semantic analysis when building the new |
| 567 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 568 | /// different behavior. |
| 569 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 570 | SourceRange Range, |
| 571 | NamespaceDecl *NS); |
| 572 | |
| 573 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 574 | /// type named in the next step in the nested-name-specifier. |
| 575 | /// |
| 576 | /// By default, performs semantic analysis when building the new |
| 577 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 578 | /// different behavior. |
| 579 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 580 | SourceRange Range, |
| 581 | bool TemplateKW, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 582 | QualType T); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 583 | |
| 584 | /// \brief Build a new template name given a nested name specifier, a flag |
| 585 | /// indicating whether the "template" keyword was provided, and the template |
| 586 | /// that the template name refers to. |
| 587 | /// |
| 588 | /// By default, builds the new template name directly. Subclasses may override |
| 589 | /// this routine to provide different behavior. |
| 590 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 591 | bool TemplateKW, |
| 592 | TemplateDecl *Template); |
| 593 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 594 | /// \brief Build a new template name given a nested name specifier and the |
| 595 | /// name that is referred to as a template. |
| 596 | /// |
| 597 | /// By default, performs semantic analysis to determine whether the name can |
| 598 | /// be resolved to a specific template, then builds the appropriate kind of |
| 599 | /// template name. Subclasses may override this routine to provide different |
| 600 | /// behavior. |
| 601 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 602 | const IdentifierInfo &II, |
| 603 | QualType ObjectType); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 604 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 605 | /// \brief Build a new template name given a nested name specifier and the |
| 606 | /// overloaded operator name that is referred to as a template. |
| 607 | /// |
| 608 | /// By default, performs semantic analysis to determine whether the name can |
| 609 | /// be resolved to a specific template, then builds the appropriate kind of |
| 610 | /// template name. Subclasses may override this routine to provide different |
| 611 | /// behavior. |
| 612 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 613 | OverloadedOperatorKind Operator, |
| 614 | QualType ObjectType); |
| 615 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 616 | /// \brief Build a new compound statement. |
| 617 | /// |
| 618 | /// By default, performs semantic analysis to build the new statement. |
| 619 | /// Subclasses may override this routine to provide different behavior. |
| 620 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 621 | MultiStmtArg Statements, |
| 622 | SourceLocation RBraceLoc, |
| 623 | bool IsStmtExpr) { |
| 624 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 625 | IsStmtExpr); |
| 626 | } |
| 627 | |
| 628 | /// \brief Build a new case statement. |
| 629 | /// |
| 630 | /// By default, performs semantic analysis to build the new statement. |
| 631 | /// Subclasses may override this routine to provide different behavior. |
| 632 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 633 | ExprArg LHS, |
| 634 | SourceLocation EllipsisLoc, |
| 635 | ExprArg RHS, |
| 636 | SourceLocation ColonLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 637 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 638 | ColonLoc); |
| 639 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 640 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 641 | /// \brief Attach the body to a new case statement. |
| 642 | /// |
| 643 | /// By default, performs semantic analysis to build the new statement. |
| 644 | /// Subclasses may override this routine to provide different behavior. |
| 645 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 646 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 647 | return move(S); |
| 648 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 649 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 650 | /// \brief Build a new default statement. |
| 651 | /// |
| 652 | /// By default, performs semantic analysis to build the new statement. |
| 653 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 654 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 655 | SourceLocation ColonLoc, |
| 656 | StmtArg SubStmt) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 657 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 658 | /*CurScope=*/0); |
| 659 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 660 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 661 | /// \brief Build a new label statement. |
| 662 | /// |
| 663 | /// By default, performs semantic analysis to build the new statement. |
| 664 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 665 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 666 | IdentifierInfo *Id, |
| 667 | SourceLocation ColonLoc, |
| 668 | StmtArg SubStmt) { |
| 669 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 670 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 671 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 672 | /// \brief Build a new "if" statement. |
| 673 | /// |
| 674 | /// By default, performs semantic analysis to build the new statement. |
| 675 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 676 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 677 | VarDecl *CondVar, StmtArg Then, |
| 678 | SourceLocation ElseLoc, StmtArg Else) { |
| 679 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
| 680 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 681 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 682 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 683 | /// \brief Start building a new switch statement. |
| 684 | /// |
| 685 | /// By default, performs semantic analysis to build the new statement. |
| 686 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 687 | OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond, |
| 688 | VarDecl *CondVar) { |
| 689 | return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 690 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 691 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 692 | /// \brief Attach the body to the switch statement. |
| 693 | /// |
| 694 | /// By default, performs semantic analysis to build the new statement. |
| 695 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 696 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 697 | StmtArg Switch, StmtArg Body) { |
| 698 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 699 | move(Body)); |
| 700 | } |
| 701 | |
| 702 | /// \brief Build a new while statement. |
| 703 | /// |
| 704 | /// By default, performs semantic analysis to build the new statement. |
| 705 | /// Subclasses may override this routine to provide different behavior. |
| 706 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 707 | Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 708 | VarDecl *CondVar, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 709 | StmtArg Body) { |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 710 | return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar), |
| 711 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 712 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 713 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 714 | /// \brief Build a new do-while statement. |
| 715 | /// |
| 716 | /// By default, performs semantic analysis to build the new statement. |
| 717 | /// Subclasses may override this routine to provide different behavior. |
| 718 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 719 | SourceLocation WhileLoc, |
| 720 | SourceLocation LParenLoc, |
| 721 | ExprArg Cond, |
| 722 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 723 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 724 | move(Cond), RParenLoc); |
| 725 | } |
| 726 | |
| 727 | /// \brief Build a new for statement. |
| 728 | /// |
| 729 | /// By default, performs semantic analysis to build the new statement. |
| 730 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 731 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 732 | SourceLocation LParenLoc, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 733 | StmtArg Init, Sema::FullExprArg Cond, |
| 734 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 735 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 736 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
| 737 | DeclPtrTy::make(CondVar), |
| 738 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 739 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 740 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 741 | /// \brief Build a new goto statement. |
| 742 | /// |
| 743 | /// By default, performs semantic analysis to build the new statement. |
| 744 | /// Subclasses may override this routine to provide different behavior. |
| 745 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 746 | SourceLocation LabelLoc, |
| 747 | LabelStmt *Label) { |
| 748 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 749 | } |
| 750 | |
| 751 | /// \brief Build a new indirect goto statement. |
| 752 | /// |
| 753 | /// By default, performs semantic analysis to build the new statement. |
| 754 | /// Subclasses may override this routine to provide different behavior. |
| 755 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 756 | SourceLocation StarLoc, |
| 757 | ExprArg Target) { |
| 758 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 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 return statement. |
| 762 | /// |
| 763 | /// By default, performs semantic analysis to build the new statement. |
| 764 | /// Subclasses may override this routine to provide different behavior. |
| 765 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 766 | ExprArg Result) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 767 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 768 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 769 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 770 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 771 | /// \brief Build a new declaration statement. |
| 772 | /// |
| 773 | /// By default, performs semantic analysis to build the new statement. |
| 774 | /// Subclasses may override this routine to provide different behavior. |
| 775 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 776 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 777 | SourceLocation EndLoc) { |
| 778 | return getSema().Owned( |
| 779 | new (getSema().Context) DeclStmt( |
| 780 | DeclGroupRef::Create(getSema().Context, |
| 781 | Decls, NumDecls), |
| 782 | StartLoc, EndLoc)); |
| 783 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 784 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 785 | /// \brief Build a new inline asm statement. |
| 786 | /// |
| 787 | /// By default, performs semantic analysis to build the new statement. |
| 788 | /// Subclasses may override this routine to provide different behavior. |
| 789 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 790 | bool IsSimple, |
| 791 | bool IsVolatile, |
| 792 | unsigned NumOutputs, |
| 793 | unsigned NumInputs, |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 794 | IdentifierInfo **Names, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 795 | MultiExprArg Constraints, |
| 796 | MultiExprArg Exprs, |
| 797 | ExprArg AsmString, |
| 798 | MultiExprArg Clobbers, |
| 799 | SourceLocation RParenLoc, |
| 800 | bool MSAsm) { |
| 801 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 802 | NumInputs, Names, move(Constraints), |
| 803 | move(Exprs), move(AsmString), move(Clobbers), |
| 804 | RParenLoc, MSAsm); |
| 805 | } |
| 806 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 807 | /// \brief Build a new C++ exception declaration. |
| 808 | /// |
| 809 | /// By default, performs semantic analysis to build the new decaration. |
| 810 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 811 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 812 | TypeSourceInfo *Declarator, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 813 | IdentifierInfo *Name, |
| 814 | SourceLocation Loc, |
| 815 | SourceRange TypeRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 816 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 817 | TypeRange); |
| 818 | } |
| 819 | |
| 820 | /// \brief Build a new C++ catch statement. |
| 821 | /// |
| 822 | /// By default, performs semantic analysis to build the new statement. |
| 823 | /// Subclasses may override this routine to provide different behavior. |
| 824 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 825 | VarDecl *ExceptionDecl, |
| 826 | StmtArg Handler) { |
| 827 | return getSema().Owned( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 828 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 829 | Handler.takeAs<Stmt>())); |
| 830 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 831 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 832 | /// \brief Build a new C++ try statement. |
| 833 | /// |
| 834 | /// By default, performs semantic analysis to build the new statement. |
| 835 | /// Subclasses may override this routine to provide different behavior. |
| 836 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 837 | StmtArg TryBlock, |
| 838 | MultiStmtArg Handlers) { |
| 839 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 840 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 841 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 842 | /// \brief Build a new expression that references a declaration. |
| 843 | /// |
| 844 | /// By default, performs semantic analysis to build the new expression. |
| 845 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 846 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 847 | LookupResult &R, |
| 848 | bool RequiresADL) { |
| 849 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 850 | } |
| 851 | |
| 852 | |
| 853 | /// \brief Build a new expression that references a declaration. |
| 854 | /// |
| 855 | /// By default, performs semantic analysis to build the new expression. |
| 856 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 857 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 858 | SourceRange QualifierRange, |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 859 | ValueDecl *VD, SourceLocation Loc, |
| 860 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 861 | CXXScopeSpec SS; |
| 862 | SS.setScopeRep(Qualifier); |
| 863 | SS.setRange(QualifierRange); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 864 | |
| 865 | // FIXME: loses template args. |
| 866 | |
| 867 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 868 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 869 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 870 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 871 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 872 | /// By default, performs semantic analysis to build the new expression. |
| 873 | /// Subclasses may override this routine to provide different behavior. |
| 874 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 875 | SourceLocation RParen) { |
| 876 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 877 | } |
| 878 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 879 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 880 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 881 | /// By default, performs semantic analysis to build the new expression. |
| 882 | /// Subclasses may override this routine to provide different behavior. |
| 883 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 884 | SourceLocation OperatorLoc, |
| 885 | bool isArrow, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 886 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 887 | SourceRange QualifierRange, |
| 888 | TypeSourceInfo *ScopeType, |
| 889 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 890 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 891 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 892 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 893 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 894 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 895 | /// By default, performs semantic analysis to build the new expression. |
| 896 | /// Subclasses may override this routine to provide different behavior. |
| 897 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 898 | UnaryOperator::Opcode Opc, |
| 899 | ExprArg SubExpr) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 900 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 901 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 902 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 903 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 904 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 905 | /// By default, performs semantic analysis to build the new expression. |
| 906 | /// Subclasses may override this routine to provide different behavior. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 907 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 908 | SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 909 | bool isSizeOf, SourceRange R) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 910 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 911 | } |
| 912 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 913 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 914 | /// argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 915 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 916 | /// By default, performs semantic analysis to build the new expression. |
| 917 | /// Subclasses may override this routine to provide different behavior. |
| 918 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 919 | bool isSizeOf, SourceRange R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 920 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 921 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 922 | OpLoc, isSizeOf, R); |
| 923 | if (Result.isInvalid()) |
| 924 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 925 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 926 | SubExpr.release(); |
| 927 | return move(Result); |
| 928 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 929 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 930 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 931 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 932 | /// By default, performs semantic analysis to build the new expression. |
| 933 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 934 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 935 | SourceLocation LBracketLoc, |
| 936 | ExprArg RHS, |
| 937 | SourceLocation RBracketLoc) { |
| 938 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 939 | LBracketLoc, move(RHS), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 940 | RBracketLoc); |
| 941 | } |
| 942 | |
| 943 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 944 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 945 | /// By default, performs semantic analysis to build the new expression. |
| 946 | /// Subclasses may override this routine to provide different behavior. |
| 947 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 948 | MultiExprArg Args, |
| 949 | SourceLocation *CommaLocs, |
| 950 | SourceLocation RParenLoc) { |
| 951 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 952 | move(Args), CommaLocs, RParenLoc); |
| 953 | } |
| 954 | |
| 955 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 956 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 957 | /// By default, performs semantic analysis to build the new expression. |
| 958 | /// Subclasses may override this routine to provide different behavior. |
| 959 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 960 | bool isArrow, |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 961 | NestedNameSpecifier *Qualifier, |
| 962 | SourceRange QualifierRange, |
| 963 | SourceLocation MemberLoc, |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 964 | ValueDecl *Member, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 965 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 966 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 967 | if (!Member->getDeclName()) { |
| 968 | // We have a reference to an unnamed field. |
| 969 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 970 | |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 971 | Expr *BaseExpr = Base.takeAs<Expr>(); |
Douglas Gregor | 5fccd36 | 2010-03-03 23:55:11 +0000 | [diff] [blame^] | 972 | if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, Member)) |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 973 | return getSema().ExprError(); |
Douglas Gregor | 8aa5f40 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 974 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 975 | MemberExpr *ME = |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 976 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 977 | Member, MemberLoc, |
| 978 | cast<FieldDecl>(Member)->getType()); |
| 979 | return getSema().Owned(ME); |
| 980 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 981 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 982 | CXXScopeSpec SS; |
| 983 | if (Qualifier) { |
| 984 | SS.setRange(QualifierRange); |
| 985 | SS.setScopeRep(Qualifier); |
| 986 | } |
| 987 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 988 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 989 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 990 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 991 | Sema::LookupMemberName); |
| 992 | R.addDecl(Member); |
| 993 | R.resolveKind(); |
| 994 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 995 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 996 | OpLoc, isArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 997 | SS, FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 998 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 999 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1000 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1001 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1002 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1003 | /// By default, performs semantic analysis to build the new expression. |
| 1004 | /// Subclasses may override this routine to provide different behavior. |
| 1005 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1006 | BinaryOperator::Opcode Opc, |
| 1007 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1008 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 1009 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1013 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1014 | /// By default, performs semantic analysis to build the new expression. |
| 1015 | /// Subclasses may override this routine to provide different behavior. |
| 1016 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1017 | SourceLocation QuestionLoc, |
| 1018 | ExprArg LHS, |
| 1019 | SourceLocation ColonLoc, |
| 1020 | ExprArg RHS) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1021 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1022 | move(LHS), move(RHS)); |
| 1023 | } |
| 1024 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1025 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1026 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1027 | /// By default, performs semantic analysis to build the new expression. |
| 1028 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1029 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1030 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1031 | SourceLocation RParenLoc, |
| 1032 | ExprArg SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1033 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1034 | move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1035 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1036 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1037 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1038 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1039 | /// By default, performs semantic analysis to build the new expression. |
| 1040 | /// Subclasses may override this routine to provide different behavior. |
| 1041 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1042 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1043 | SourceLocation RParenLoc, |
| 1044 | ExprArg Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1045 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1046 | move(Init)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1047 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1048 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1049 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1050 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1051 | /// By default, performs semantic analysis to build the new expression. |
| 1052 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1053 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1054 | SourceLocation OpLoc, |
| 1055 | SourceLocation AccessorLoc, |
| 1056 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1057 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1058 | CXXScopeSpec SS; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1059 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1060 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1061 | OpLoc, /*IsArrow*/ false, |
| 1062 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1063 | DeclarationName(&Accessor), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1064 | AccessorLoc, |
| 1065 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1066 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1067 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1068 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1069 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1070 | /// By default, performs semantic analysis to build the new expression. |
| 1071 | /// Subclasses may override this routine to provide different behavior. |
| 1072 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1073 | MultiExprArg Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1074 | SourceLocation RBraceLoc, |
| 1075 | QualType ResultTy) { |
| 1076 | OwningExprResult Result |
| 1077 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1078 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1079 | return move(Result); |
| 1080 | |
| 1081 | // Patch in the result type we were given, which may have been computed |
| 1082 | // when the initial InitListExpr was built. |
| 1083 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1084 | ILE->setType(ResultTy); |
| 1085 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1086 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1087 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1088 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1089 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1090 | /// By default, performs semantic analysis to build the new expression. |
| 1091 | /// Subclasses may override this routine to provide different behavior. |
| 1092 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1093 | MultiExprArg ArrayExprs, |
| 1094 | SourceLocation EqualOrColonLoc, |
| 1095 | bool GNUSyntax, |
| 1096 | ExprArg Init) { |
| 1097 | OwningExprResult Result |
| 1098 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1099 | move(Init)); |
| 1100 | if (Result.isInvalid()) |
| 1101 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1102 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1103 | ArrayExprs.release(); |
| 1104 | return move(Result); |
| 1105 | } |
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 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1108 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1109 | /// By default, builds the implicit value initialization without performing |
| 1110 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1111 | /// different behavior. |
| 1112 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1113 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1114 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1115 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1116 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1117 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1118 | /// By default, performs semantic analysis to build the new expression. |
| 1119 | /// Subclasses may override this routine to provide different behavior. |
| 1120 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1121 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1122 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1123 | RParenLoc); |
| 1124 | } |
| 1125 | |
| 1126 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1127 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1128 | /// By default, performs semantic analysis to build the new expression. |
| 1129 | /// Subclasses may override this routine to provide different behavior. |
| 1130 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1131 | MultiExprArg SubExprs, |
| 1132 | SourceLocation RParenLoc) { |
Fariborz Jahanian | f88f7ab | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1133 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1134 | move(SubExprs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1135 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1136 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1137 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1138 | /// |
| 1139 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1140 | /// rather than attempting to map the label statement itself. |
| 1141 | /// Subclasses may override this routine to provide different behavior. |
| 1142 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1143 | SourceLocation LabelLoc, |
| 1144 | LabelStmt *Label) { |
| 1145 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1146 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1147 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1148 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1149 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1150 | /// By default, performs semantic analysis to build the new expression. |
| 1151 | /// Subclasses may override this routine to provide different behavior. |
| 1152 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1153 | StmtArg SubStmt, |
| 1154 | SourceLocation RParenLoc) { |
| 1155 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1156 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1157 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1158 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1159 | /// |
| 1160 | /// By default, performs semantic analysis to build the new expression. |
| 1161 | /// Subclasses may override this routine to provide different behavior. |
| 1162 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1163 | QualType T1, QualType T2, |
| 1164 | SourceLocation RParenLoc) { |
| 1165 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1166 | T1.getAsOpaquePtr(), |
| 1167 | T2.getAsOpaquePtr(), |
| 1168 | RParenLoc); |
| 1169 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1170 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1171 | /// \brief Build a new __builtin_choose_expr expression. |
| 1172 | /// |
| 1173 | /// By default, performs semantic analysis to build the new expression. |
| 1174 | /// Subclasses may override this routine to provide different behavior. |
| 1175 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1176 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1177 | SourceLocation RParenLoc) { |
| 1178 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1179 | move(Cond), move(LHS), move(RHS), |
| 1180 | RParenLoc); |
| 1181 | } |
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 | /// \brief Build a new overloaded operator call expression. |
| 1184 | /// |
| 1185 | /// By default, performs semantic analysis to build the new expression. |
| 1186 | /// The semantic analysis provides the behavior of template instantiation, |
| 1187 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1188 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1189 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1190 | /// provide different behavior. |
| 1191 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1192 | SourceLocation OpLoc, |
| 1193 | ExprArg Callee, |
| 1194 | ExprArg First, |
| 1195 | ExprArg Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1196 | |
| 1197 | /// \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] | 1198 | /// reinterpret_cast. |
| 1199 | /// |
| 1200 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1201 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1202 | /// Subclasses may override this routine to provide different behavior. |
| 1203 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1204 | Stmt::StmtClass Class, |
| 1205 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1206 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1207 | SourceLocation RAngleLoc, |
| 1208 | SourceLocation LParenLoc, |
| 1209 | ExprArg SubExpr, |
| 1210 | SourceLocation RParenLoc) { |
| 1211 | switch (Class) { |
| 1212 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1213 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1214 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1215 | move(SubExpr), RParenLoc); |
| 1216 | |
| 1217 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1218 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1219 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1220 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1221 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1222 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1223 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1224 | RAngleLoc, LParenLoc, |
| 1225 | move(SubExpr), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1226 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1227 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1228 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1229 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1230 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1231 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1232 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1233 | default: |
| 1234 | assert(false && "Invalid C++ named cast"); |
| 1235 | break; |
| 1236 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1237 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1238 | return getSema().ExprError(); |
| 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 C++ static_cast expression. |
| 1242 | /// |
| 1243 | /// By default, performs semantic analysis to build the new expression. |
| 1244 | /// Subclasses may override this routine to provide different behavior. |
| 1245 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1246 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1247 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1248 | SourceLocation RAngleLoc, |
| 1249 | SourceLocation LParenLoc, |
| 1250 | ExprArg SubExpr, |
| 1251 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1252 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1253 | TInfo, move(SubExpr), |
| 1254 | SourceRange(LAngleLoc, RAngleLoc), |
| 1255 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | /// \brief Build a new C++ dynamic_cast expression. |
| 1259 | /// |
| 1260 | /// By default, performs semantic analysis to build the new expression. |
| 1261 | /// Subclasses may override this routine to provide different behavior. |
| 1262 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1263 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1264 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1265 | SourceLocation RAngleLoc, |
| 1266 | SourceLocation LParenLoc, |
| 1267 | ExprArg SubExpr, |
| 1268 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1269 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1270 | TInfo, move(SubExpr), |
| 1271 | SourceRange(LAngleLoc, RAngleLoc), |
| 1272 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1276 | /// |
| 1277 | /// By default, performs semantic analysis to build the new expression. |
| 1278 | /// Subclasses may override this routine to provide different behavior. |
| 1279 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1280 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1281 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1282 | SourceLocation RAngleLoc, |
| 1283 | SourceLocation LParenLoc, |
| 1284 | ExprArg SubExpr, |
| 1285 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1286 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1287 | TInfo, move(SubExpr), |
| 1288 | SourceRange(LAngleLoc, RAngleLoc), |
| 1289 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | /// \brief Build a new C++ const_cast expression. |
| 1293 | /// |
| 1294 | /// By default, performs semantic analysis to build the new expression. |
| 1295 | /// Subclasses may override this routine to provide different behavior. |
| 1296 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1297 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1298 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1299 | SourceLocation RAngleLoc, |
| 1300 | SourceLocation LParenLoc, |
| 1301 | ExprArg SubExpr, |
| 1302 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1303 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1304 | TInfo, move(SubExpr), |
| 1305 | SourceRange(LAngleLoc, RAngleLoc), |
| 1306 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1307 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1308 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1309 | /// \brief Build a new C++ functional-style cast expression. |
| 1310 | /// |
| 1311 | /// By default, performs semantic analysis to build the new expression. |
| 1312 | /// Subclasses may override this routine to provide different behavior. |
| 1313 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1314 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1315 | SourceLocation LParenLoc, |
| 1316 | ExprArg SubExpr, |
| 1317 | SourceLocation RParenLoc) { |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1318 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1319 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1320 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1321 | LParenLoc, |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1322 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1323 | /*CommaLocs=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1324 | RParenLoc); |
| 1325 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1326 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1327 | /// \brief Build a new C++ typeid(type) expression. |
| 1328 | /// |
| 1329 | /// By default, performs semantic analysis to build the new expression. |
| 1330 | /// Subclasses may override this routine to provide different behavior. |
| 1331 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1332 | SourceLocation LParenLoc, |
| 1333 | QualType T, |
| 1334 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1335 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1336 | T.getAsOpaquePtr(), RParenLoc); |
| 1337 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1338 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1339 | /// \brief Build a new C++ typeid(expr) expression. |
| 1340 | /// |
| 1341 | /// By default, performs semantic analysis to build the new expression. |
| 1342 | /// Subclasses may override this routine to provide different behavior. |
| 1343 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1344 | SourceLocation LParenLoc, |
| 1345 | ExprArg Operand, |
| 1346 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1347 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1348 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1349 | RParenLoc); |
| 1350 | if (Result.isInvalid()) |
| 1351 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1352 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1353 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1354 | return move(Result); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1357 | /// \brief Build a new C++ "this" expression. |
| 1358 | /// |
| 1359 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1360 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1361 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1362 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1363 | QualType ThisType, |
| 1364 | bool isImplicit) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1365 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1366 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1367 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | /// \brief Build a new C++ throw expression. |
| 1371 | /// |
| 1372 | /// By default, performs semantic analysis to build the new expression. |
| 1373 | /// Subclasses may override this routine to provide different behavior. |
| 1374 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1375 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1376 | } |
| 1377 | |
| 1378 | /// \brief Build a new C++ default-argument expression. |
| 1379 | /// |
| 1380 | /// By default, builds a new default-argument expression, which does not |
| 1381 | /// require any semantic analysis. Subclasses may override this routine to |
| 1382 | /// provide different behavior. |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1383 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
| 1384 | ParmVarDecl *Param) { |
| 1385 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1386 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | /// \brief Build a new C++ zero-initialization expression. |
| 1390 | /// |
| 1391 | /// By default, performs semantic analysis to build the new expression. |
| 1392 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1393 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1394 | SourceLocation LParenLoc, |
| 1395 | QualType T, |
| 1396 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1397 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1398 | T.getAsOpaquePtr(), LParenLoc, |
| 1399 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1400 | 0, RParenLoc); |
| 1401 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1402 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1403 | /// \brief Build a new C++ "new" expression. |
| 1404 | /// |
| 1405 | /// By default, performs semantic analysis to build the new expression. |
| 1406 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1407 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1408 | bool UseGlobal, |
| 1409 | SourceLocation PlacementLParen, |
| 1410 | MultiExprArg PlacementArgs, |
| 1411 | SourceLocation PlacementRParen, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1412 | bool ParenTypeId, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1413 | QualType AllocType, |
| 1414 | SourceLocation TypeLoc, |
| 1415 | SourceRange TypeRange, |
| 1416 | ExprArg ArraySize, |
| 1417 | SourceLocation ConstructorLParen, |
| 1418 | MultiExprArg ConstructorArgs, |
| 1419 | SourceLocation ConstructorRParen) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1420 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1421 | PlacementLParen, |
| 1422 | move(PlacementArgs), |
| 1423 | PlacementRParen, |
| 1424 | ParenTypeId, |
| 1425 | AllocType, |
| 1426 | TypeLoc, |
| 1427 | TypeRange, |
| 1428 | move(ArraySize), |
| 1429 | ConstructorLParen, |
| 1430 | move(ConstructorArgs), |
| 1431 | ConstructorRParen); |
| 1432 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1433 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1434 | /// \brief Build a new C++ "delete" expression. |
| 1435 | /// |
| 1436 | /// By default, performs semantic analysis to build the new expression. |
| 1437 | /// Subclasses may override this routine to provide different behavior. |
| 1438 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1439 | bool IsGlobalDelete, |
| 1440 | bool IsArrayForm, |
| 1441 | ExprArg Operand) { |
| 1442 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1443 | move(Operand)); |
| 1444 | } |
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 | /// \brief Build a new unary type trait expression. |
| 1447 | /// |
| 1448 | /// By default, performs semantic analysis to build the new expression. |
| 1449 | /// Subclasses may override this routine to provide different behavior. |
| 1450 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1451 | SourceLocation StartLoc, |
| 1452 | SourceLocation LParenLoc, |
| 1453 | QualType T, |
| 1454 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1455 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1456 | T.getAsOpaquePtr(), RParenLoc); |
| 1457 | } |
| 1458 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1459 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1460 | /// expression. |
| 1461 | /// |
| 1462 | /// By default, performs semantic analysis to build the new expression. |
| 1463 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1464 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1465 | SourceRange QualifierRange, |
| 1466 | DeclarationName Name, |
| 1467 | SourceLocation Location, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1468 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1469 | CXXScopeSpec SS; |
| 1470 | SS.setRange(QualifierRange); |
| 1471 | SS.setScopeRep(NNS); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1472 | |
| 1473 | if (TemplateArgs) |
| 1474 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1475 | *TemplateArgs); |
| 1476 | |
| 1477 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | /// \brief Build a new template-id expression. |
| 1481 | /// |
| 1482 | /// By default, performs semantic analysis to build the new expression. |
| 1483 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1484 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1485 | LookupResult &R, |
| 1486 | bool RequiresADL, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1487 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1488 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | /// \brief Build a new object-construction expression. |
| 1492 | /// |
| 1493 | /// By default, performs semantic analysis to build the new expression. |
| 1494 | /// Subclasses may override this routine to provide different behavior. |
| 1495 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1496 | SourceLocation Loc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1497 | CXXConstructorDecl *Constructor, |
| 1498 | bool IsElidable, |
| 1499 | MultiExprArg Args) { |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1500 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
| 1501 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
| 1502 | ConvertedArgs)) |
| 1503 | return getSema().ExprError(); |
| 1504 | |
| 1505 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1506 | move_arg(ConvertedArgs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | /// \brief Build a new object-construction expression. |
| 1510 | /// |
| 1511 | /// By default, performs semantic analysis to build the new expression. |
| 1512 | /// Subclasses may override this routine to provide different behavior. |
| 1513 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1514 | QualType T, |
| 1515 | SourceLocation LParenLoc, |
| 1516 | MultiExprArg Args, |
| 1517 | SourceLocation *Commas, |
| 1518 | SourceLocation RParenLoc) { |
| 1519 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1520 | T.getAsOpaquePtr(), |
| 1521 | LParenLoc, |
| 1522 | move(Args), |
| 1523 | Commas, |
| 1524 | RParenLoc); |
| 1525 | } |
| 1526 | |
| 1527 | /// \brief Build a new object-construction 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 RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1532 | QualType T, |
| 1533 | SourceLocation LParenLoc, |
| 1534 | MultiExprArg Args, |
| 1535 | SourceLocation *Commas, |
| 1536 | SourceLocation RParenLoc) { |
| 1537 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1538 | /*FIXME*/LParenLoc), |
| 1539 | T.getAsOpaquePtr(), |
| 1540 | LParenLoc, |
| 1541 | move(Args), |
| 1542 | Commas, |
| 1543 | RParenLoc); |
| 1544 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1545 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1546 | /// \brief Build a new member reference expression. |
| 1547 | /// |
| 1548 | /// By default, performs semantic analysis to build the new expression. |
| 1549 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1550 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1551 | QualType BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1552 | bool IsArrow, |
| 1553 | SourceLocation OperatorLoc, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1554 | NestedNameSpecifier *Qualifier, |
| 1555 | SourceRange QualifierRange, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1556 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1557 | DeclarationName Name, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1558 | SourceLocation MemberLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1559 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1560 | CXXScopeSpec SS; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1561 | SS.setRange(QualifierRange); |
| 1562 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1563 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1564 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1565 | OperatorLoc, IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1566 | SS, FirstQualifierInScope, |
| 1567 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1570 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1571 | /// |
| 1572 | /// By default, performs semantic analysis to build the new expression. |
| 1573 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1574 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1575 | QualType BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1576 | SourceLocation OperatorLoc, |
| 1577 | bool IsArrow, |
| 1578 | NestedNameSpecifier *Qualifier, |
| 1579 | SourceRange QualifierRange, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1580 | NamedDecl *FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1581 | LookupResult &R, |
| 1582 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1583 | CXXScopeSpec SS; |
| 1584 | SS.setRange(QualifierRange); |
| 1585 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1586 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1587 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1588 | OperatorLoc, IsArrow, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1589 | SS, FirstQualifierInScope, |
| 1590 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1591 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1592 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1593 | /// \brief Build a new Objective-C @encode expression. |
| 1594 | /// |
| 1595 | /// By default, performs semantic analysis to build the new expression. |
| 1596 | /// Subclasses may override this routine to provide different behavior. |
| 1597 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 1598 | QualType T, |
| 1599 | SourceLocation RParenLoc) { |
| 1600 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T, |
| 1601 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1602 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1603 | |
| 1604 | /// \brief Build a new Objective-C protocol expression. |
| 1605 | /// |
| 1606 | /// By default, performs semantic analysis to build the new expression. |
| 1607 | /// Subclasses may override this routine to provide different behavior. |
| 1608 | OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol, |
| 1609 | SourceLocation AtLoc, |
| 1610 | SourceLocation ProtoLoc, |
| 1611 | SourceLocation LParenLoc, |
| 1612 | SourceLocation RParenLoc) { |
| 1613 | return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression( |
| 1614 | Protocol->getIdentifier(), |
| 1615 | AtLoc, |
| 1616 | ProtoLoc, |
| 1617 | LParenLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1618 | RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1619 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1620 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1621 | /// \brief Build a new shuffle vector expression. |
| 1622 | /// |
| 1623 | /// By default, performs semantic analysis to build the new expression. |
| 1624 | /// Subclasses may override this routine to provide different behavior. |
| 1625 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1626 | MultiExprArg SubExprs, |
| 1627 | SourceLocation RParenLoc) { |
| 1628 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1629 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1630 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1631 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1632 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1633 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1634 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1635 | // Build a reference to the __builtin_shufflevector builtin |
| 1636 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1637 | Expr *Callee |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1638 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1639 | BuiltinLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1640 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1641 | |
| 1642 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1643 | unsigned NumSubExprs = SubExprs.size(); |
| 1644 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1645 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1646 | Subs, NumSubExprs, |
| 1647 | Builtin->getResultType(), |
| 1648 | RParenLoc); |
| 1649 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1650 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1651 | // Type-check the __builtin_shufflevector expression. |
| 1652 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1653 | if (Result.isInvalid()) |
| 1654 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1655 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1656 | OwnedCall.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1657 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1658 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1659 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1660 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1661 | template<typename Derived> |
| 1662 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1663 | if (!S) |
| 1664 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1665 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1666 | switch (S->getStmtClass()) { |
| 1667 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1668 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1669 | // Transform individual statement nodes |
| 1670 | #define STMT(Node, Parent) \ |
| 1671 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1672 | #define EXPR(Node, Parent) |
| 1673 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1674 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1675 | // Transform expressions by calling TransformExpr. |
| 1676 | #define STMT(Node, Parent) |
John McCall | 09cc141 | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1677 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1678 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1679 | #include "clang/AST/StmtNodes.def" |
| 1680 | { |
| 1681 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1682 | if (E.isInvalid()) |
| 1683 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1684 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1685 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1686 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1687 | } |
| 1688 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1689 | return SemaRef.Owned(S->Retain()); |
| 1690 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1691 | |
| 1692 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1693 | template<typename Derived> |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1694 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1695 | if (!E) |
| 1696 | return SemaRef.Owned(E); |
| 1697 | |
| 1698 | switch (E->getStmtClass()) { |
| 1699 | case Stmt::NoStmtClass: break; |
| 1700 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
John McCall | 09cc141 | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1701 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1702 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1703 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1704 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1705 | } |
| 1706 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1707 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | template<typename Derived> |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1711 | NestedNameSpecifier * |
| 1712 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1713 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1714 | QualType ObjectType, |
| 1715 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 0979c80 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1716 | if (!NNS) |
| 1717 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1718 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1719 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1720 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1721 | if (Prefix) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1722 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1723 | ObjectType, |
| 1724 | FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1725 | if (!Prefix) |
| 1726 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1727 | |
| 1728 | // 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] | 1729 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1730 | ObjectType = QualType(); |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1731 | FirstQualifierInScope = 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1732 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1733 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1734 | switch (NNS->getKind()) { |
| 1735 | case NestedNameSpecifier::Identifier: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1736 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1737 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1738 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1739 | ObjectType.isNull()) |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1740 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1741 | |
| 1742 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1743 | *NNS->getAsIdentifier(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1744 | ObjectType, |
| 1745 | FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1746 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1747 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1748 | NamespaceDecl *NS |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1749 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1750 | getDerived().TransformDecl(Range.getBegin(), |
| 1751 | NNS->getAsNamespace())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1752 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1753 | Prefix == NNS->getPrefix() && |
| 1754 | NS == NNS->getAsNamespace()) |
| 1755 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1756 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1757 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1758 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1759 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1760 | case NestedNameSpecifier::Global: |
| 1761 | // There is no meaningful transformation that one could perform on the |
| 1762 | // global scope. |
| 1763 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1764 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1765 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1766 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | fbf2c94 | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1767 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1768 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 1769 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1770 | if (T.isNull()) |
| 1771 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1772 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1773 | if (!getDerived().AlwaysRebuild() && |
| 1774 | Prefix == NNS->getPrefix() && |
| 1775 | T == QualType(NNS->getAsType(), 0)) |
| 1776 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1777 | |
| 1778 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1779 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 1780 | T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1781 | } |
| 1782 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1783 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1784 | // Required to silence a GCC warning |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1785 | return 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1789 | DeclarationName |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1790 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1791 | SourceLocation Loc, |
| 1792 | QualType ObjectType) { |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1793 | if (!Name) |
| 1794 | return Name; |
| 1795 | |
| 1796 | switch (Name.getNameKind()) { |
| 1797 | case DeclarationName::Identifier: |
| 1798 | case DeclarationName::ObjCZeroArgSelector: |
| 1799 | case DeclarationName::ObjCOneArgSelector: |
| 1800 | case DeclarationName::ObjCMultiArgSelector: |
| 1801 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 1802 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1803 | case DeclarationName::CXXUsingDirective: |
| 1804 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1805 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1806 | case DeclarationName::CXXConstructorName: |
| 1807 | case DeclarationName::CXXDestructorName: |
| 1808 | case DeclarationName::CXXConversionFunctionName: { |
| 1809 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1810 | QualType T = getDerived().TransformType(Name.getCXXNameType(), |
| 1811 | ObjectType); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1812 | if (T.isNull()) |
| 1813 | return DeclarationName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1814 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1815 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1816 | Name.getNameKind(), |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1817 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1818 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1819 | } |
| 1820 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1821 | return DeclarationName(); |
| 1822 | } |
| 1823 | |
| 1824 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1825 | TemplateName |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1826 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1827 | QualType ObjectType) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1828 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1829 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1830 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1831 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1832 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1833 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 1834 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1835 | if (!NNS) |
| 1836 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1837 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1838 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1839 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1840 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1841 | if (!TransTemplate) |
| 1842 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1843 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1844 | if (!getDerived().AlwaysRebuild() && |
| 1845 | NNS == QTN->getQualifier() && |
| 1846 | TransTemplate == Template) |
| 1847 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1848 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1849 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1850 | TransTemplate); |
| 1851 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1852 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1853 | // These should be getting filtered out before they make it into the AST. |
| 1854 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1855 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1856 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1857 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1858 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1859 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1860 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 1861 | ObjectType); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1862 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1863 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1864 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1865 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1866 | NNS == DTN->getQualifier() && |
| 1867 | ObjectType.isNull()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1868 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1869 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1870 | if (DTN->isIdentifier()) |
| 1871 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 1872 | ObjectType); |
| 1873 | |
| 1874 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 1875 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1876 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1877 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1878 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1879 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1880 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1881 | if (!TransTemplate) |
| 1882 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1883 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1884 | if (!getDerived().AlwaysRebuild() && |
| 1885 | TransTemplate == Template) |
| 1886 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1887 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1888 | return TemplateName(TransTemplate); |
| 1889 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1890 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1891 | // These should be getting filtered out before they reach the AST. |
| 1892 | assert(false && "overloaded function decl survived to here"); |
| 1893 | return TemplateName(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1897 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 1898 | const TemplateArgument &Arg, |
| 1899 | TemplateArgumentLoc &Output) { |
| 1900 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1901 | switch (Arg.getKind()) { |
| 1902 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 1903 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1904 | break; |
| 1905 | |
| 1906 | case TemplateArgument::Type: |
| 1907 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1908 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1909 | |
| 1910 | break; |
| 1911 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1912 | case TemplateArgument::Template: |
| 1913 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 1914 | break; |
| 1915 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1916 | case TemplateArgument::Expression: |
| 1917 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 1918 | break; |
| 1919 | |
| 1920 | case TemplateArgument::Declaration: |
| 1921 | case TemplateArgument::Integral: |
| 1922 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1923 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1924 | break; |
| 1925 | } |
| 1926 | } |
| 1927 | |
| 1928 | template<typename Derived> |
| 1929 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 1930 | const TemplateArgumentLoc &Input, |
| 1931 | TemplateArgumentLoc &Output) { |
| 1932 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1933 | switch (Arg.getKind()) { |
| 1934 | case TemplateArgument::Null: |
| 1935 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1936 | Output = Input; |
| 1937 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1938 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1939 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1940 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1941 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1942 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1943 | |
| 1944 | DI = getDerived().TransformType(DI); |
| 1945 | if (!DI) return true; |
| 1946 | |
| 1947 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 1948 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1949 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1950 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1951 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1952 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 1953 | DeclarationName Name; |
| 1954 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 1955 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1956 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1957 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1958 | if (!D) return true; |
| 1959 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1960 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 1961 | if (SourceExpr) { |
| 1962 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 1963 | Action::Unevaluated); |
| 1964 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 1965 | if (E.isInvalid()) |
| 1966 | SourceExpr = NULL; |
| 1967 | else { |
| 1968 | SourceExpr = E.takeAs<Expr>(); |
| 1969 | SourceExpr->Retain(); |
| 1970 | } |
| 1971 | } |
| 1972 | |
| 1973 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1974 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1975 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1976 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1977 | case TemplateArgument::Template: { |
| 1978 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 1979 | TemplateName Template |
| 1980 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 1981 | if (Template.isNull()) |
| 1982 | return true; |
| 1983 | |
| 1984 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 1985 | Input.getTemplateQualifierRange(), |
| 1986 | Input.getTemplateNameLoc()); |
| 1987 | return false; |
| 1988 | } |
| 1989 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1990 | case TemplateArgument::Expression: { |
| 1991 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1992 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1993 | Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1994 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1995 | Expr *InputExpr = Input.getSourceExpression(); |
| 1996 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 1997 | |
| 1998 | Sema::OwningExprResult E |
| 1999 | = getDerived().TransformExpr(InputExpr); |
| 2000 | if (E.isInvalid()) return true; |
| 2001 | |
| 2002 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2003 | ETaken->Retain(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2004 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2005 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2006 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2007 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2008 | case TemplateArgument::Pack: { |
| 2009 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2010 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2011 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2012 | AEnd = Arg.pack_end(); |
| 2013 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2014 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2015 | // FIXME: preserve source information here when we start |
| 2016 | // caring about parameter packs. |
| 2017 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2018 | TemplateArgumentLoc InputArg; |
| 2019 | TemplateArgumentLoc OutputArg; |
| 2020 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2021 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2022 | return true; |
| 2023 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2024 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2025 | } |
| 2026 | TemplateArgument Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2027 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2028 | true); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2029 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2030 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2031 | } |
| 2032 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2033 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2034 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2035 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2036 | } |
| 2037 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2038 | //===----------------------------------------------------------------------===// |
| 2039 | // Type transformation |
| 2040 | //===----------------------------------------------------------------------===// |
| 2041 | |
| 2042 | template<typename Derived> |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2043 | QualType TreeTransform<Derived>::TransformType(QualType T, |
| 2044 | QualType ObjectType) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2045 | if (getDerived().AlreadyTransformed(T)) |
| 2046 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2047 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2048 | // Temporary workaround. All of these transformations should |
| 2049 | // eventually turn into transformations on TypeLocs. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2050 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | 4802a31 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2051 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2052 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2053 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2054 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2055 | if (!NewDI) |
| 2056 | return QualType(); |
| 2057 | |
| 2058 | return NewDI->getType(); |
| 2059 | } |
| 2060 | |
| 2061 | template<typename Derived> |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2062 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2063 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2064 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2065 | return DI; |
| 2066 | |
| 2067 | TypeLocBuilder TLB; |
| 2068 | |
| 2069 | TypeLoc TL = DI->getTypeLoc(); |
| 2070 | TLB.reserve(TL.getFullDataSize()); |
| 2071 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2072 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2073 | if (Result.isNull()) |
| 2074 | return 0; |
| 2075 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2076 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | template<typename Derived> |
| 2080 | QualType |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2081 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2082 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2083 | switch (T.getTypeLocClass()) { |
| 2084 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2085 | #define TYPELOC(CLASS, PARENT) \ |
| 2086 | case TypeLoc::CLASS: \ |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2087 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2088 | ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2089 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2090 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2091 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2092 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2093 | return QualType(); |
| 2094 | } |
| 2095 | |
| 2096 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2097 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2098 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2099 | /// types). This is the right thing for template instantiation, but |
| 2100 | /// probably not for other clients. |
| 2101 | template<typename Derived> |
| 2102 | QualType |
| 2103 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2104 | QualifiedTypeLoc T, |
| 2105 | QualType ObjectType) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2106 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2107 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2108 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2109 | ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2110 | if (Result.isNull()) |
| 2111 | return QualType(); |
| 2112 | |
| 2113 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2114 | // FIXME: this is the right thing for template instantiation, but |
| 2115 | // probably not for other clients. |
| 2116 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2117 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2118 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2119 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2120 | |
| 2121 | TLB.push<QualifiedTypeLoc>(Result); |
| 2122 | |
| 2123 | // No location information to preserve. |
| 2124 | |
| 2125 | return Result; |
| 2126 | } |
| 2127 | |
| 2128 | template <class TyLoc> static inline |
| 2129 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2130 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2131 | NewT.setNameLoc(T.getNameLoc()); |
| 2132 | return T.getType(); |
| 2133 | } |
| 2134 | |
| 2135 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2136 | // the equivalent template version work. |
| 2137 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2138 | QualType PointeeType \ |
| 2139 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2140 | if (PointeeType.isNull()) \ |
| 2141 | return QualType(); \ |
| 2142 | \ |
| 2143 | QualType Result = TL.getType(); \ |
| 2144 | if (getDerived().AlwaysRebuild() || \ |
| 2145 | PointeeType != TL.getPointeeLoc().getType()) { \ |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2146 | Result = getDerived().Rebuild##TypeClass(PointeeType, \ |
| 2147 | TL.getSigilLoc()); \ |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2148 | if (Result.isNull()) \ |
| 2149 | return QualType(); \ |
| 2150 | } \ |
| 2151 | \ |
| 2152 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2153 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2154 | \ |
| 2155 | return Result; \ |
| 2156 | } while(0) |
| 2157 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2158 | template<typename Derived> |
| 2159 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2160 | BuiltinTypeLoc T, |
| 2161 | QualType ObjectType) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2162 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2163 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2164 | if (T.needsExtraLocalData()) |
| 2165 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2166 | return T.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2167 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2168 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2169 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2170 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2171 | ComplexTypeLoc T, |
| 2172 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2173 | // FIXME: recurse? |
| 2174 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2175 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2176 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2177 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2178 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2179 | PointerTypeLoc TL, |
| 2180 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2181 | TransformPointerLikeType(PointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2182 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2183 | |
| 2184 | template<typename Derived> |
| 2185 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2186 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2187 | BlockPointerTypeLoc TL, |
| 2188 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2189 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2190 | } |
| 2191 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2192 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2193 | /// don't care whether the type itself is an l-value type or an r-value |
| 2194 | /// type; we only care if the type was *written* as an l-value type |
| 2195 | /// or an r-value type. |
| 2196 | template<typename Derived> |
| 2197 | QualType |
| 2198 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2199 | ReferenceTypeLoc TL, |
| 2200 | QualType ObjectType) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2201 | const ReferenceType *T = TL.getTypePtr(); |
| 2202 | |
| 2203 | // Note that this works with the pointee-as-written. |
| 2204 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2205 | if (PointeeType.isNull()) |
| 2206 | return QualType(); |
| 2207 | |
| 2208 | QualType Result = TL.getType(); |
| 2209 | if (getDerived().AlwaysRebuild() || |
| 2210 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2211 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2212 | T->isSpelledAsLValue(), |
| 2213 | TL.getSigilLoc()); |
| 2214 | if (Result.isNull()) |
| 2215 | return QualType(); |
| 2216 | } |
| 2217 | |
| 2218 | // r-value references can be rebuilt as l-value references. |
| 2219 | ReferenceTypeLoc NewTL; |
| 2220 | if (isa<LValueReferenceType>(Result)) |
| 2221 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2222 | else |
| 2223 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2224 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2225 | |
| 2226 | return Result; |
| 2227 | } |
| 2228 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2229 | template<typename Derived> |
| 2230 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2231 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2232 | LValueReferenceTypeLoc TL, |
| 2233 | QualType ObjectType) { |
| 2234 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2235 | } |
| 2236 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2237 | template<typename Derived> |
| 2238 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2239 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2240 | RValueReferenceTypeLoc TL, |
| 2241 | QualType ObjectType) { |
| 2242 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2243 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2244 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2245 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2246 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2247 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2248 | MemberPointerTypeLoc TL, |
| 2249 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2250 | MemberPointerType *T = TL.getTypePtr(); |
| 2251 | |
| 2252 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2253 | if (PointeeType.isNull()) |
| 2254 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2255 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2256 | // TODO: preserve source information for this. |
| 2257 | QualType ClassType |
| 2258 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2259 | if (ClassType.isNull()) |
| 2260 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2261 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2262 | QualType Result = TL.getType(); |
| 2263 | if (getDerived().AlwaysRebuild() || |
| 2264 | PointeeType != T->getPointeeType() || |
| 2265 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2266 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2267 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2268 | if (Result.isNull()) |
| 2269 | return QualType(); |
| 2270 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2271 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2272 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2273 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2274 | |
| 2275 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2276 | } |
| 2277 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2278 | template<typename Derived> |
| 2279 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2280 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2281 | ConstantArrayTypeLoc TL, |
| 2282 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2283 | ConstantArrayType *T = TL.getTypePtr(); |
| 2284 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2285 | if (ElementType.isNull()) |
| 2286 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2287 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2288 | QualType Result = TL.getType(); |
| 2289 | if (getDerived().AlwaysRebuild() || |
| 2290 | ElementType != T->getElementType()) { |
| 2291 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2292 | T->getSizeModifier(), |
| 2293 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2294 | T->getIndexTypeCVRQualifiers(), |
| 2295 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2296 | if (Result.isNull()) |
| 2297 | return QualType(); |
| 2298 | } |
| 2299 | |
| 2300 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2301 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2302 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2303 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2304 | Expr *Size = TL.getSizeExpr(); |
| 2305 | if (Size) { |
| 2306 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2307 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2308 | } |
| 2309 | NewTL.setSizeExpr(Size); |
| 2310 | |
| 2311 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2312 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2313 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2314 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2315 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2316 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2317 | IncompleteArrayTypeLoc TL, |
| 2318 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2319 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2320 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2321 | if (ElementType.isNull()) |
| 2322 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2323 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2324 | QualType Result = TL.getType(); |
| 2325 | if (getDerived().AlwaysRebuild() || |
| 2326 | ElementType != T->getElementType()) { |
| 2327 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2328 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2329 | T->getIndexTypeCVRQualifiers(), |
| 2330 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2331 | if (Result.isNull()) |
| 2332 | return QualType(); |
| 2333 | } |
| 2334 | |
| 2335 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2336 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2337 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2338 | NewTL.setSizeExpr(0); |
| 2339 | |
| 2340 | return Result; |
| 2341 | } |
| 2342 | |
| 2343 | template<typename Derived> |
| 2344 | QualType |
| 2345 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2346 | VariableArrayTypeLoc TL, |
| 2347 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2348 | VariableArrayType *T = TL.getTypePtr(); |
| 2349 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2350 | if (ElementType.isNull()) |
| 2351 | return QualType(); |
| 2352 | |
| 2353 | // Array bounds are not potentially evaluated contexts |
| 2354 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2355 | |
| 2356 | Sema::OwningExprResult SizeResult |
| 2357 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2358 | if (SizeResult.isInvalid()) |
| 2359 | return QualType(); |
| 2360 | |
| 2361 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2362 | |
| 2363 | QualType Result = TL.getType(); |
| 2364 | if (getDerived().AlwaysRebuild() || |
| 2365 | ElementType != T->getElementType() || |
| 2366 | Size != T->getSizeExpr()) { |
| 2367 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2368 | T->getSizeModifier(), |
| 2369 | move(SizeResult), |
| 2370 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2371 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2372 | if (Result.isNull()) |
| 2373 | return QualType(); |
| 2374 | } |
| 2375 | else SizeResult.take(); |
| 2376 | |
| 2377 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2378 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2379 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2380 | NewTL.setSizeExpr(Size); |
| 2381 | |
| 2382 | return Result; |
| 2383 | } |
| 2384 | |
| 2385 | template<typename Derived> |
| 2386 | QualType |
| 2387 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2388 | DependentSizedArrayTypeLoc TL, |
| 2389 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2390 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2391 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2392 | if (ElementType.isNull()) |
| 2393 | return QualType(); |
| 2394 | |
| 2395 | // Array bounds are not potentially evaluated contexts |
| 2396 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2397 | |
| 2398 | Sema::OwningExprResult SizeResult |
| 2399 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2400 | if (SizeResult.isInvalid()) |
| 2401 | return QualType(); |
| 2402 | |
| 2403 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2404 | |
| 2405 | QualType Result = TL.getType(); |
| 2406 | if (getDerived().AlwaysRebuild() || |
| 2407 | ElementType != T->getElementType() || |
| 2408 | Size != T->getSizeExpr()) { |
| 2409 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2410 | T->getSizeModifier(), |
| 2411 | move(SizeResult), |
| 2412 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2413 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2414 | if (Result.isNull()) |
| 2415 | return QualType(); |
| 2416 | } |
| 2417 | else SizeResult.take(); |
| 2418 | |
| 2419 | // We might have any sort of array type now, but fortunately they |
| 2420 | // all have the same location layout. |
| 2421 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2422 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2423 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2424 | NewTL.setSizeExpr(Size); |
| 2425 | |
| 2426 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2427 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2428 | |
| 2429 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2430 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2431 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2432 | DependentSizedExtVectorTypeLoc TL, |
| 2433 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2434 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2435 | |
| 2436 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2437 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2438 | if (ElementType.isNull()) |
| 2439 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2440 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2441 | // Vector sizes are not potentially evaluated contexts |
| 2442 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2443 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2444 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2445 | if (Size.isInvalid()) |
| 2446 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2447 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2448 | QualType Result = TL.getType(); |
| 2449 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2450 | ElementType != T->getElementType() || |
| 2451 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2452 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2453 | move(Size), |
| 2454 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2455 | if (Result.isNull()) |
| 2456 | return QualType(); |
| 2457 | } |
| 2458 | else Size.take(); |
| 2459 | |
| 2460 | // Result might be dependent or not. |
| 2461 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2462 | DependentSizedExtVectorTypeLoc NewTL |
| 2463 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2464 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2465 | } else { |
| 2466 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2467 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2468 | } |
| 2469 | |
| 2470 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2471 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2472 | |
| 2473 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2474 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2475 | VectorTypeLoc TL, |
| 2476 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2477 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2478 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2479 | if (ElementType.isNull()) |
| 2480 | return QualType(); |
| 2481 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2482 | QualType Result = TL.getType(); |
| 2483 | if (getDerived().AlwaysRebuild() || |
| 2484 | ElementType != T->getElementType()) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2485 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 2486 | T->isAltiVec(), T->isPixel()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2487 | if (Result.isNull()) |
| 2488 | return QualType(); |
| 2489 | } |
| 2490 | |
| 2491 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2492 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2493 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2494 | return Result; |
| 2495 | } |
| 2496 | |
| 2497 | template<typename Derived> |
| 2498 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2499 | ExtVectorTypeLoc TL, |
| 2500 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2501 | VectorType *T = TL.getTypePtr(); |
| 2502 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2503 | if (ElementType.isNull()) |
| 2504 | return QualType(); |
| 2505 | |
| 2506 | QualType Result = TL.getType(); |
| 2507 | if (getDerived().AlwaysRebuild() || |
| 2508 | ElementType != T->getElementType()) { |
| 2509 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2510 | T->getNumElements(), |
| 2511 | /*FIXME*/ SourceLocation()); |
| 2512 | if (Result.isNull()) |
| 2513 | return QualType(); |
| 2514 | } |
| 2515 | |
| 2516 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2517 | NewTL.setNameLoc(TL.getNameLoc()); |
| 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> |
| 2523 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2524 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2525 | FunctionProtoTypeLoc TL, |
| 2526 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2527 | FunctionProtoType *T = TL.getTypePtr(); |
| 2528 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2529 | if (ResultType.isNull()) |
| 2530 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2531 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2532 | // Transform the parameters. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2533 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2534 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
| 2535 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2536 | ParmVarDecl *OldParm = TL.getArg(i); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2537 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2538 | QualType NewType; |
| 2539 | ParmVarDecl *NewParm; |
| 2540 | |
| 2541 | if (OldParm) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2542 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2543 | assert(OldDI->getType() == T->getArgType(i)); |
| 2544 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2545 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2546 | if (!NewDI) |
| 2547 | return QualType(); |
| 2548 | |
| 2549 | if (NewDI == OldDI) |
| 2550 | NewParm = OldParm; |
| 2551 | else |
| 2552 | NewParm = ParmVarDecl::Create(SemaRef.Context, |
| 2553 | OldParm->getDeclContext(), |
| 2554 | OldParm->getLocation(), |
| 2555 | OldParm->getIdentifier(), |
| 2556 | NewDI->getType(), |
| 2557 | NewDI, |
| 2558 | OldParm->getStorageClass(), |
| 2559 | /* DefArg */ NULL); |
| 2560 | NewType = NewParm->getType(); |
| 2561 | |
| 2562 | // Deal with the possibility that we don't have a parameter |
| 2563 | // declaration for this parameter. |
| 2564 | } else { |
| 2565 | NewParm = 0; |
| 2566 | |
| 2567 | QualType OldType = T->getArgType(i); |
| 2568 | NewType = getDerived().TransformType(OldType); |
| 2569 | if (NewType.isNull()) |
| 2570 | return QualType(); |
| 2571 | } |
| 2572 | |
| 2573 | ParamTypes.push_back(NewType); |
| 2574 | ParamDecls.push_back(NewParm); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2575 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2576 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2577 | QualType Result = TL.getType(); |
| 2578 | if (getDerived().AlwaysRebuild() || |
| 2579 | ResultType != T->getResultType() || |
| 2580 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2581 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2582 | ParamTypes.data(), |
| 2583 | ParamTypes.size(), |
| 2584 | T->isVariadic(), |
| 2585 | T->getTypeQuals()); |
| 2586 | if (Result.isNull()) |
| 2587 | return QualType(); |
| 2588 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2589 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2590 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2591 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2592 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2593 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2594 | NewTL.setArg(i, ParamDecls[i]); |
| 2595 | |
| 2596 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2597 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2598 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2599 | template<typename Derived> |
| 2600 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2601 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2602 | FunctionNoProtoTypeLoc TL, |
| 2603 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2604 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2605 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2606 | if (ResultType.isNull()) |
| 2607 | return QualType(); |
| 2608 | |
| 2609 | QualType Result = TL.getType(); |
| 2610 | if (getDerived().AlwaysRebuild() || |
| 2611 | ResultType != T->getResultType()) |
| 2612 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2613 | |
| 2614 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2615 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2616 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2617 | |
| 2618 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2619 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2620 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2621 | template<typename Derived> QualType |
| 2622 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2623 | UnresolvedUsingTypeLoc TL, |
| 2624 | QualType ObjectType) { |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2625 | UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2626 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2627 | if (!D) |
| 2628 | return QualType(); |
| 2629 | |
| 2630 | QualType Result = TL.getType(); |
| 2631 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2632 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2633 | if (Result.isNull()) |
| 2634 | return QualType(); |
| 2635 | } |
| 2636 | |
| 2637 | // We might get an arbitrary type spec type back. We should at |
| 2638 | // least always get a type spec type, though. |
| 2639 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2640 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2641 | |
| 2642 | return Result; |
| 2643 | } |
| 2644 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2645 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2646 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2647 | TypedefTypeLoc TL, |
| 2648 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2649 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2650 | TypedefDecl *Typedef |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2651 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2652 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2653 | if (!Typedef) |
| 2654 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2655 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2656 | QualType Result = TL.getType(); |
| 2657 | if (getDerived().AlwaysRebuild() || |
| 2658 | Typedef != T->getDecl()) { |
| 2659 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2660 | if (Result.isNull()) |
| 2661 | return QualType(); |
| 2662 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2663 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2664 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2665 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2666 | |
| 2667 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2668 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2669 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2670 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2671 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2672 | TypeOfExprTypeLoc TL, |
| 2673 | QualType ObjectType) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2674 | // typeof expressions are not potentially evaluated contexts |
| 2675 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2676 | |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2677 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2678 | if (E.isInvalid()) |
| 2679 | return QualType(); |
| 2680 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2681 | QualType Result = TL.getType(); |
| 2682 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2683 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2684 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2685 | if (Result.isNull()) |
| 2686 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2687 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2688 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2689 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2690 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2691 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2692 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2693 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2694 | |
| 2695 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2696 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2697 | |
| 2698 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2699 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2700 | TypeOfTypeLoc TL, |
| 2701 | QualType ObjectType) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2702 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 2703 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 2704 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2705 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2706 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2707 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2708 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 2709 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2710 | if (Result.isNull()) |
| 2711 | return QualType(); |
| 2712 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2713 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2714 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2715 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2716 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2717 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2718 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2719 | |
| 2720 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2721 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2722 | |
| 2723 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2724 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2725 | DecltypeTypeLoc TL, |
| 2726 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2727 | DecltypeType *T = TL.getTypePtr(); |
| 2728 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2729 | // decltype expressions are not potentially evaluated contexts |
| 2730 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2731 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2732 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2733 | if (E.isInvalid()) |
| 2734 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2735 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2736 | QualType Result = TL.getType(); |
| 2737 | if (getDerived().AlwaysRebuild() || |
| 2738 | E.get() != T->getUnderlyingExpr()) { |
| 2739 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2740 | if (Result.isNull()) |
| 2741 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2742 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2743 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2744 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2745 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2746 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2747 | |
| 2748 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2749 | } |
| 2750 | |
| 2751 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2752 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2753 | RecordTypeLoc TL, |
| 2754 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2755 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2756 | RecordDecl *Record |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2757 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2758 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2759 | if (!Record) |
| 2760 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2761 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2762 | QualType Result = TL.getType(); |
| 2763 | if (getDerived().AlwaysRebuild() || |
| 2764 | Record != T->getDecl()) { |
| 2765 | Result = getDerived().RebuildRecordType(Record); |
| 2766 | if (Result.isNull()) |
| 2767 | return QualType(); |
| 2768 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2769 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2770 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2771 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2772 | |
| 2773 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2774 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2775 | |
| 2776 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2777 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2778 | EnumTypeLoc TL, |
| 2779 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2780 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2781 | EnumDecl *Enum |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2782 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2783 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2784 | if (!Enum) |
| 2785 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2786 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2787 | QualType Result = TL.getType(); |
| 2788 | if (getDerived().AlwaysRebuild() || |
| 2789 | Enum != T->getDecl()) { |
| 2790 | Result = getDerived().RebuildEnumType(Enum); |
| 2791 | if (Result.isNull()) |
| 2792 | return QualType(); |
| 2793 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2794 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2795 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2796 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2797 | |
| 2798 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2799 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2800 | |
| 2801 | template <typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2802 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2803 | ElaboratedTypeLoc TL, |
| 2804 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2805 | ElaboratedType *T = TL.getTypePtr(); |
| 2806 | |
| 2807 | // FIXME: this should be a nested type. |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2808 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2809 | if (Underlying.isNull()) |
| 2810 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2811 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2812 | QualType Result = TL.getType(); |
| 2813 | if (getDerived().AlwaysRebuild() || |
| 2814 | Underlying != T->getUnderlyingType()) { |
| 2815 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2816 | if (Result.isNull()) |
| 2817 | return QualType(); |
| 2818 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2819 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2820 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2821 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2822 | |
| 2823 | return Result; |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2824 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2825 | |
| 2826 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2827 | template<typename Derived> |
| 2828 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2829 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2830 | TemplateTypeParmTypeLoc TL, |
| 2831 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2832 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2833 | } |
| 2834 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2835 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2836 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2837 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2838 | SubstTemplateTypeParmTypeLoc TL, |
| 2839 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2840 | return TransformTypeSpecType(TLB, TL); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2841 | } |
| 2842 | |
| 2843 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2844 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2845 | const TemplateSpecializationType *TST, |
| 2846 | QualType ObjectType) { |
| 2847 | // FIXME: this entire method is a temporary workaround; callers |
| 2848 | // should be rewritten to provide real type locs. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2849 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2850 | // Fake up a TemplateSpecializationTypeLoc. |
| 2851 | TypeLocBuilder TLB; |
| 2852 | TemplateSpecializationTypeLoc TL |
| 2853 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2854 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2855 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 2856 | |
| 2857 | TL.setTemplateNameLoc(BaseLoc); |
| 2858 | TL.setLAngleLoc(BaseLoc); |
| 2859 | TL.setRAngleLoc(BaseLoc); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2860 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2861 | const TemplateArgument &TA = TST->getArg(i); |
| 2862 | TemplateArgumentLoc TAL; |
| 2863 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2864 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2865 | } |
| 2866 | |
| 2867 | TypeLocBuilder IgnoredTLB; |
| 2868 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2869 | } |
| 2870 | |
| 2871 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2872 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2873 | TypeLocBuilder &TLB, |
| 2874 | TemplateSpecializationTypeLoc TL, |
| 2875 | QualType ObjectType) { |
| 2876 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 2877 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2878 | TemplateName Template |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2879 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2880 | if (Template.isNull()) |
| 2881 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2882 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2883 | TemplateArgumentListInfo NewTemplateArgs; |
| 2884 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 2885 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 2886 | |
| 2887 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 2888 | TemplateArgumentLoc Loc; |
| 2889 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2890 | return QualType(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2891 | NewTemplateArgs.addArgument(Loc); |
| 2892 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2893 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2894 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 2895 | |
| 2896 | QualType Result = |
| 2897 | getDerived().RebuildTemplateSpecializationType(Template, |
| 2898 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2899 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2900 | |
| 2901 | if (!Result.isNull()) { |
| 2902 | TemplateSpecializationTypeLoc NewTL |
| 2903 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 2904 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 2905 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 2906 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 2907 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 2908 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2909 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2910 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2911 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2912 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2913 | |
| 2914 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2915 | QualType |
| 2916 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2917 | QualifiedNameTypeLoc TL, |
| 2918 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2919 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2920 | NestedNameSpecifier *NNS |
| 2921 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2922 | SourceRange(), |
| 2923 | ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2924 | if (!NNS) |
| 2925 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2926 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2927 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 2928 | if (Named.isNull()) |
| 2929 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2930 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2931 | QualType Result = TL.getType(); |
| 2932 | if (getDerived().AlwaysRebuild() || |
| 2933 | NNS != T->getQualifier() || |
| 2934 | Named != T->getNamedType()) { |
| 2935 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 2936 | if (Result.isNull()) |
| 2937 | return QualType(); |
| 2938 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2939 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2940 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 2941 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2942 | |
| 2943 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2944 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2945 | |
| 2946 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2947 | QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2948 | TypenameTypeLoc TL, |
| 2949 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2950 | TypenameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2951 | |
| 2952 | /* FIXME: preserve source information better than this */ |
| 2953 | SourceRange SR(TL.getNameLoc()); |
| 2954 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2955 | NestedNameSpecifier *NNS |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2956 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 2957 | ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2958 | if (!NNS) |
| 2959 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2960 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2961 | QualType Result; |
| 2962 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2963 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2964 | QualType NewTemplateId |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2965 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 2966 | if (NewTemplateId.isNull()) |
| 2967 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2968 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2969 | if (!getDerived().AlwaysRebuild() && |
| 2970 | NNS == T->getQualifier() && |
| 2971 | NewTemplateId == QualType(TemplateId, 0)) |
| 2972 | return QualType(T, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2973 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2974 | Result = getDerived().RebuildTypenameType(NNS, NewTemplateId); |
| 2975 | } else { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2976 | Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2977 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2978 | if (Result.isNull()) |
| 2979 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2980 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2981 | TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result); |
| 2982 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2983 | |
| 2984 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2985 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2986 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2987 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2988 | QualType |
| 2989 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2990 | ObjCInterfaceTypeLoc TL, |
| 2991 | QualType ObjectType) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2992 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 2993 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2994 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2995 | |
| 2996 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2997 | QualType |
| 2998 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2999 | ObjCObjectPointerTypeLoc TL, |
| 3000 | QualType ObjectType) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3001 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 3002 | return QualType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3003 | } |
| 3004 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3005 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3006 | // Statement transformation |
| 3007 | //===----------------------------------------------------------------------===// |
| 3008 | template<typename Derived> |
| 3009 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3010 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3011 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3012 | } |
| 3013 | |
| 3014 | template<typename Derived> |
| 3015 | Sema::OwningStmtResult |
| 3016 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3017 | return getDerived().TransformCompoundStmt(S, false); |
| 3018 | } |
| 3019 | |
| 3020 | template<typename Derived> |
| 3021 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3022 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3023 | bool IsStmtExpr) { |
| 3024 | bool SubStmtChanged = false; |
| 3025 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3026 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3027 | B != BEnd; ++B) { |
| 3028 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3029 | if (Result.isInvalid()) |
| 3030 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3031 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3032 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3033 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3034 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3035 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3036 | if (!getDerived().AlwaysRebuild() && |
| 3037 | !SubStmtChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3038 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3039 | |
| 3040 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3041 | move_arg(Statements), |
| 3042 | S->getRBracLoc(), |
| 3043 | IsStmtExpr); |
| 3044 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3045 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3046 | template<typename Derived> |
| 3047 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3048 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3049 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3050 | { |
| 3051 | // The case value expressions are not potentially evaluated. |
| 3052 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3053 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3054 | // Transform the left-hand case value. |
| 3055 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3056 | if (LHS.isInvalid()) |
| 3057 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3058 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3059 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3060 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3061 | if (RHS.isInvalid()) |
| 3062 | return SemaRef.StmtError(); |
| 3063 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3064 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3065 | // Build the case statement. |
| 3066 | // Case statements are always rebuilt so that they will attached to their |
| 3067 | // transformed switch statement. |
| 3068 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3069 | move(LHS), |
| 3070 | S->getEllipsisLoc(), |
| 3071 | move(RHS), |
| 3072 | S->getColonLoc()); |
| 3073 | if (Case.isInvalid()) |
| 3074 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3075 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3076 | // Transform the statement following the case |
| 3077 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3078 | if (SubStmt.isInvalid()) |
| 3079 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3080 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3081 | // Attach the body to the case statement |
| 3082 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3083 | } |
| 3084 | |
| 3085 | template<typename Derived> |
| 3086 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3087 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3088 | // Transform the statement following the default case |
| 3089 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3090 | if (SubStmt.isInvalid()) |
| 3091 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3092 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3093 | // Default statements are always rebuilt |
| 3094 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3095 | move(SubStmt)); |
| 3096 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3097 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3098 | template<typename Derived> |
| 3099 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3100 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3101 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3102 | if (SubStmt.isInvalid()) |
| 3103 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3104 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3105 | // FIXME: Pass the real colon location in. |
| 3106 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3107 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3108 | move(SubStmt)); |
| 3109 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3110 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3111 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3112 | Sema::OwningStmtResult |
| 3113 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3114 | // Transform the condition |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3115 | OwningExprResult Cond(SemaRef); |
| 3116 | VarDecl *ConditionVar = 0; |
| 3117 | if (S->getConditionVariable()) { |
| 3118 | ConditionVar |
| 3119 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3120 | getDerived().TransformDefinition( |
| 3121 | S->getConditionVariable()->getLocation(), |
| 3122 | S->getConditionVariable())); |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3123 | if (!ConditionVar) |
| 3124 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3125 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3126 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3127 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3128 | if (Cond.isInvalid()) |
| 3129 | return SemaRef.StmtError(); |
| 3130 | } |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3131 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3132 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3133 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3134 | // Transform the "then" branch. |
| 3135 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3136 | if (Then.isInvalid()) |
| 3137 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3138 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3139 | // Transform the "else" branch. |
| 3140 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3141 | if (Else.isInvalid()) |
| 3142 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3143 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3144 | if (!getDerived().AlwaysRebuild() && |
| 3145 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3146 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3147 | Then.get() == S->getThen() && |
| 3148 | Else.get() == S->getElse()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3149 | return SemaRef.Owned(S->Retain()); |
| 3150 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3151 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3152 | move(Then), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3153 | S->getElseLoc(), move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | template<typename Derived> |
| 3157 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3158 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3159 | // Transform the condition. |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3160 | OwningExprResult Cond(SemaRef); |
| 3161 | VarDecl *ConditionVar = 0; |
| 3162 | if (S->getConditionVariable()) { |
| 3163 | ConditionVar |
| 3164 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3165 | getDerived().TransformDefinition( |
| 3166 | S->getConditionVariable()->getLocation(), |
| 3167 | S->getConditionVariable())); |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3168 | if (!ConditionVar) |
| 3169 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3170 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3171 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3172 | |
| 3173 | if (Cond.isInvalid()) |
| 3174 | return SemaRef.StmtError(); |
| 3175 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3176 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3177 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3178 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3179 | // Rebuild the switch statement. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3180 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3181 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3182 | if (Switch.isInvalid()) |
| 3183 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3184 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3185 | // Transform the body of the switch statement. |
| 3186 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3187 | if (Body.isInvalid()) |
| 3188 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3189 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3190 | // Complete the switch statement. |
| 3191 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3192 | move(Body)); |
| 3193 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3194 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3195 | template<typename Derived> |
| 3196 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3197 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3198 | // Transform the condition |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3199 | OwningExprResult Cond(SemaRef); |
| 3200 | VarDecl *ConditionVar = 0; |
| 3201 | if (S->getConditionVariable()) { |
| 3202 | ConditionVar |
| 3203 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3204 | getDerived().TransformDefinition( |
| 3205 | S->getConditionVariable()->getLocation(), |
| 3206 | S->getConditionVariable())); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3207 | if (!ConditionVar) |
| 3208 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3209 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3210 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3211 | |
| 3212 | if (Cond.isInvalid()) |
| 3213 | return SemaRef.StmtError(); |
| 3214 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3215 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3216 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3217 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3218 | // Transform the body |
| 3219 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3220 | if (Body.isInvalid()) |
| 3221 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3222 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3223 | if (!getDerived().AlwaysRebuild() && |
| 3224 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3225 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3226 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3227 | return SemaRef.Owned(S->Retain()); |
| 3228 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3229 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3230 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3231 | } |
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 | template<typename Derived> |
| 3234 | Sema::OwningStmtResult |
| 3235 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3236 | // Transform the condition |
| 3237 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3238 | if (Cond.isInvalid()) |
| 3239 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3240 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3241 | // Transform the body |
| 3242 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3243 | if (Body.isInvalid()) |
| 3244 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3245 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3246 | if (!getDerived().AlwaysRebuild() && |
| 3247 | Cond.get() == S->getCond() && |
| 3248 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3249 | return SemaRef.Owned(S->Retain()); |
| 3250 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3251 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3252 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3253 | S->getRParenLoc()); |
| 3254 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3255 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3256 | template<typename Derived> |
| 3257 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3258 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3259 | // Transform the initialization statement |
| 3260 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3261 | if (Init.isInvalid()) |
| 3262 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3263 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3264 | // Transform the condition |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3265 | OwningExprResult Cond(SemaRef); |
| 3266 | VarDecl *ConditionVar = 0; |
| 3267 | if (S->getConditionVariable()) { |
| 3268 | ConditionVar |
| 3269 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3270 | getDerived().TransformDefinition( |
| 3271 | S->getConditionVariable()->getLocation(), |
| 3272 | S->getConditionVariable())); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3273 | if (!ConditionVar) |
| 3274 | return SemaRef.StmtError(); |
| 3275 | } else { |
| 3276 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3277 | |
| 3278 | if (Cond.isInvalid()) |
| 3279 | return SemaRef.StmtError(); |
| 3280 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3281 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3282 | // Transform the increment |
| 3283 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3284 | if (Inc.isInvalid()) |
| 3285 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3286 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3287 | // Transform the body |
| 3288 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3289 | if (Body.isInvalid()) |
| 3290 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3291 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3292 | if (!getDerived().AlwaysRebuild() && |
| 3293 | Init.get() == S->getInit() && |
| 3294 | Cond.get() == S->getCond() && |
| 3295 | Inc.get() == S->getInc() && |
| 3296 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3297 | return SemaRef.Owned(S->Retain()); |
| 3298 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3299 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3300 | move(Init), getSema().MakeFullExpr(Cond), |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3301 | ConditionVar, |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3302 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3303 | S->getRParenLoc(), move(Body)); |
| 3304 | } |
| 3305 | |
| 3306 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3307 | Sema::OwningStmtResult |
| 3308 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3309 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3310 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3311 | S->getLabel()); |
| 3312 | } |
| 3313 | |
| 3314 | template<typename Derived> |
| 3315 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3316 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3317 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3318 | if (Target.isInvalid()) |
| 3319 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3320 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3321 | if (!getDerived().AlwaysRebuild() && |
| 3322 | Target.get() == S->getTarget()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3323 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3324 | |
| 3325 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3326 | move(Target)); |
| 3327 | } |
| 3328 | |
| 3329 | template<typename Derived> |
| 3330 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3331 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3332 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3333 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3334 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3335 | template<typename Derived> |
| 3336 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3337 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3338 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3339 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3340 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3341 | template<typename Derived> |
| 3342 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3343 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3344 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3345 | if (Result.isInvalid()) |
| 3346 | return SemaRef.StmtError(); |
| 3347 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3348 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3349 | // to tell whether the return type of the function has changed. |
| 3350 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3351 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3352 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3353 | template<typename Derived> |
| 3354 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3355 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3356 | bool DeclChanged = false; |
| 3357 | llvm::SmallVector<Decl *, 4> Decls; |
| 3358 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3359 | D != DEnd; ++D) { |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3360 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 3361 | *D); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3362 | if (!Transformed) |
| 3363 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3364 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3365 | if (Transformed != *D) |
| 3366 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3367 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3368 | Decls.push_back(Transformed); |
| 3369 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3370 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3371 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3372 | return SemaRef.Owned(S->Retain()); |
| 3373 | |
| 3374 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3375 | S->getStartLoc(), S->getEndLoc()); |
| 3376 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3377 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3378 | template<typename Derived> |
| 3379 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3380 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3381 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3382 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3383 | } |
| 3384 | |
| 3385 | template<typename Derived> |
| 3386 | Sema::OwningStmtResult |
| 3387 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3388 | |
| 3389 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3390 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3391 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3392 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3393 | OwningExprResult AsmString(SemaRef); |
| 3394 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3395 | |
| 3396 | bool ExprsChanged = false; |
| 3397 | |
| 3398 | // Go through the outputs. |
| 3399 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3400 | Names.push_back(S->getOutputIdentifier(I)); |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3401 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3402 | // No need to transform the constraint literal. |
| 3403 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
| 3404 | |
| 3405 | // Transform the output expr. |
| 3406 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3407 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3408 | if (Result.isInvalid()) |
| 3409 | return SemaRef.StmtError(); |
| 3410 | |
| 3411 | ExprsChanged |= Result.get() != OutputExpr; |
| 3412 | |
| 3413 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3414 | } |
| 3415 | |
| 3416 | // Go through the inputs. |
| 3417 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3418 | Names.push_back(S->getInputIdentifier(I)); |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3419 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3420 | // No need to transform the constraint literal. |
| 3421 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
| 3422 | |
| 3423 | // Transform the input expr. |
| 3424 | Expr *InputExpr = S->getInputExpr(I); |
| 3425 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3426 | if (Result.isInvalid()) |
| 3427 | return SemaRef.StmtError(); |
| 3428 | |
| 3429 | ExprsChanged |= Result.get() != InputExpr; |
| 3430 | |
| 3431 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3432 | } |
| 3433 | |
| 3434 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3435 | return SemaRef.Owned(S->Retain()); |
| 3436 | |
| 3437 | // Go through the clobbers. |
| 3438 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3439 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3440 | |
| 3441 | // No need to transform the asm string literal. |
| 3442 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3443 | |
| 3444 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3445 | S->isSimple(), |
| 3446 | S->isVolatile(), |
| 3447 | S->getNumOutputs(), |
| 3448 | S->getNumInputs(), |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3449 | Names.data(), |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3450 | move_arg(Constraints), |
| 3451 | move_arg(Exprs), |
| 3452 | move(AsmString), |
| 3453 | move_arg(Clobbers), |
| 3454 | S->getRParenLoc(), |
| 3455 | S->isMSAsm()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3456 | } |
| 3457 | |
| 3458 | |
| 3459 | template<typename Derived> |
| 3460 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3461 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3462 | // FIXME: Implement this |
| 3463 | assert(false && "Cannot transform an Objective-C @try statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3464 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3465 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3466 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3467 | template<typename Derived> |
| 3468 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3469 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3470 | // FIXME: Implement this |
| 3471 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3472 | return SemaRef.Owned(S->Retain()); |
| 3473 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3474 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3475 | template<typename Derived> |
| 3476 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3477 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3478 | // FIXME: Implement this |
| 3479 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3480 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3481 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3482 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3483 | template<typename Derived> |
| 3484 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3485 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3486 | // FIXME: Implement this |
| 3487 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3488 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3489 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3490 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3491 | template<typename Derived> |
| 3492 | Sema::OwningStmtResult |
| 3493 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3494 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3495 | // FIXME: Implement this |
| 3496 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3497 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3498 | } |
| 3499 | |
| 3500 | template<typename Derived> |
| 3501 | Sema::OwningStmtResult |
| 3502 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3503 | ObjCForCollectionStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3504 | // FIXME: Implement this |
| 3505 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3506 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | |
| 3510 | template<typename Derived> |
| 3511 | Sema::OwningStmtResult |
| 3512 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3513 | // Transform the exception declaration, if any. |
| 3514 | VarDecl *Var = 0; |
| 3515 | if (S->getExceptionDecl()) { |
| 3516 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3517 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3518 | ExceptionDecl->getDeclName()); |
| 3519 | |
| 3520 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3521 | if (T.isNull()) |
| 3522 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3523 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3524 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3525 | T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3526 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3527 | ExceptionDecl->getIdentifier(), |
| 3528 | ExceptionDecl->getLocation(), |
| 3529 | /*FIXME: Inaccurate*/ |
| 3530 | SourceRange(ExceptionDecl->getLocation())); |
| 3531 | if (!Var || Var->isInvalidDecl()) { |
| 3532 | if (Var) |
| 3533 | Var->Destroy(SemaRef.Context); |
| 3534 | return SemaRef.StmtError(); |
| 3535 | } |
| 3536 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3537 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3538 | // Transform the actual exception handler. |
| 3539 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3540 | if (Handler.isInvalid()) { |
| 3541 | if (Var) |
| 3542 | Var->Destroy(SemaRef.Context); |
| 3543 | return SemaRef.StmtError(); |
| 3544 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3545 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3546 | if (!getDerived().AlwaysRebuild() && |
| 3547 | !Var && |
| 3548 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3549 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3550 | |
| 3551 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3552 | Var, |
| 3553 | move(Handler)); |
| 3554 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3555 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3556 | template<typename Derived> |
| 3557 | Sema::OwningStmtResult |
| 3558 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3559 | // Transform the try block itself. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3560 | OwningStmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3561 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3562 | if (TryBlock.isInvalid()) |
| 3563 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3564 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3565 | // Transform the handlers. |
| 3566 | bool HandlerChanged = false; |
| 3567 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3568 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3569 | OwningStmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3570 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3571 | if (Handler.isInvalid()) |
| 3572 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3573 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3574 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3575 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3576 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3577 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3578 | if (!getDerived().AlwaysRebuild() && |
| 3579 | TryBlock.get() == S->getTryBlock() && |
| 3580 | !HandlerChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3581 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3582 | |
| 3583 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3584 | move_arg(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3585 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3586 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3587 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3588 | // Expression transformation |
| 3589 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3590 | template<typename Derived> |
| 3591 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3592 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3593 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3594 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3595 | |
| 3596 | template<typename Derived> |
| 3597 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3598 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3599 | NestedNameSpecifier *Qualifier = 0; |
| 3600 | if (E->getQualifier()) { |
| 3601 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3602 | E->getQualifierRange()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3603 | if (!Qualifier) |
| 3604 | return SemaRef.ExprError(); |
| 3605 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3606 | |
| 3607 | ValueDecl *ND |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3608 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 3609 | E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3610 | if (!ND) |
| 3611 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3612 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3613 | if (!getDerived().AlwaysRebuild() && |
| 3614 | Qualifier == E->getQualifier() && |
| 3615 | ND == E->getDecl() && |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3616 | !E->hasExplicitTemplateArgumentList()) { |
| 3617 | |
| 3618 | // Mark it referenced in the new context regardless. |
| 3619 | // FIXME: this is a bit instantiation-specific. |
| 3620 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 3621 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3622 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3623 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3624 | |
| 3625 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 3626 | if (E->hasExplicitTemplateArgumentList()) { |
| 3627 | TemplateArgs = &TransArgs; |
| 3628 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3629 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 3630 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3631 | TemplateArgumentLoc Loc; |
| 3632 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 3633 | return SemaRef.ExprError(); |
| 3634 | TransArgs.addArgument(Loc); |
| 3635 | } |
| 3636 | } |
| 3637 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3638 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3639 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3640 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3641 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3642 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3643 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3644 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3645 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3646 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3647 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3648 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3649 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3650 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3651 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3652 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3653 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3654 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3655 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3656 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3657 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3658 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3659 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3660 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3661 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3662 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3663 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3664 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3665 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3666 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3667 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3668 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3669 | return SemaRef.Owned(E->Retain()); |
| 3670 | } |
| 3671 | |
| 3672 | template<typename Derived> |
| 3673 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3674 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3675 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3676 | if (SubExpr.isInvalid()) |
| 3677 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3678 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3679 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3680 | return SemaRef.Owned(E->Retain()); |
| 3681 | |
| 3682 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3683 | E->getRParen()); |
| 3684 | } |
| 3685 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3686 | template<typename Derived> |
| 3687 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3688 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 3689 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3690 | if (SubExpr.isInvalid()) |
| 3691 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3692 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3693 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3694 | return SemaRef.Owned(E->Retain()); |
| 3695 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3696 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3697 | E->getOpcode(), |
| 3698 | move(SubExpr)); |
| 3699 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3700 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3701 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3702 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3703 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3704 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3705 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3706 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3707 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3708 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3709 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3710 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3711 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3712 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3713 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3714 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3715 | E->isSizeOf(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3716 | E->getSourceRange()); |
| 3717 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3718 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3719 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3720 | { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3721 | // C++0x [expr.sizeof]p1: |
| 3722 | // The operand is either an expression, which is an unevaluated operand |
| 3723 | // [...] |
| 3724 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3725 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3726 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3727 | if (SubExpr.isInvalid()) |
| 3728 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3729 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3730 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3731 | return SemaRef.Owned(E->Retain()); |
| 3732 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3733 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3734 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3735 | E->isSizeOf(), |
| 3736 | E->getSourceRange()); |
| 3737 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3738 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3739 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3740 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3741 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3742 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3743 | if (LHS.isInvalid()) |
| 3744 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3745 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3746 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3747 | if (RHS.isInvalid()) |
| 3748 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3749 | |
| 3750 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3751 | if (!getDerived().AlwaysRebuild() && |
| 3752 | LHS.get() == E->getLHS() && |
| 3753 | RHS.get() == E->getRHS()) |
| 3754 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3755 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3756 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3757 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3758 | move(RHS), |
| 3759 | E->getRBracketLoc()); |
| 3760 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3761 | |
| 3762 | template<typename Derived> |
| 3763 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3764 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3765 | // Transform the callee. |
| 3766 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3767 | if (Callee.isInvalid()) |
| 3768 | return SemaRef.ExprError(); |
| 3769 | |
| 3770 | // Transform arguments. |
| 3771 | bool ArgChanged = false; |
| 3772 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3773 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3774 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3775 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3776 | if (Arg.isInvalid()) |
| 3777 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3778 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3779 | // FIXME: Wrong source location information for the ','. |
| 3780 | FakeCommaLocs.push_back( |
| 3781 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3782 | |
| 3783 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3784 | Args.push_back(Arg.takeAs<Expr>()); |
| 3785 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3786 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3787 | if (!getDerived().AlwaysRebuild() && |
| 3788 | Callee.get() == E->getCallee() && |
| 3789 | !ArgChanged) |
| 3790 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3791 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3792 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3793 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3794 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3795 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3796 | move_arg(Args), |
| 3797 | FakeCommaLocs.data(), |
| 3798 | E->getRParenLoc()); |
| 3799 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3800 | |
| 3801 | template<typename Derived> |
| 3802 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3803 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3804 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3805 | if (Base.isInvalid()) |
| 3806 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3807 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3808 | NestedNameSpecifier *Qualifier = 0; |
| 3809 | if (E->hasQualifier()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3810 | Qualifier |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3811 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3812 | E->getQualifierRange()); |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3813 | if (Qualifier == 0) |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3814 | return SemaRef.ExprError(); |
| 3815 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3816 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 3817 | ValueDecl *Member |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3818 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 3819 | E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3820 | if (!Member) |
| 3821 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3822 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3823 | if (!getDerived().AlwaysRebuild() && |
| 3824 | Base.get() == E->getBase() && |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3825 | Qualifier == E->getQualifier() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3826 | Member == E->getMemberDecl() && |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3827 | !E->hasExplicitTemplateArgumentList()) { |
| 3828 | |
| 3829 | // Mark it referenced in the new context regardless. |
| 3830 | // FIXME: this is a bit instantiation-specific. |
| 3831 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3832 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3833 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3834 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3835 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3836 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3837 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3838 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3839 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3840 | TemplateArgumentLoc Loc; |
| 3841 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3842 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3843 | TransArgs.addArgument(Loc); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3844 | } |
| 3845 | } |
| 3846 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3847 | // FIXME: Bogus source location for the operator |
| 3848 | SourceLocation FakeOperatorLoc |
| 3849 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3850 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3851 | // FIXME: to do this check properly, we will need to preserve the |
| 3852 | // first-qualifier-in-scope here, just in case we had a dependent |
| 3853 | // base (and therefore couldn't do the check) and a |
| 3854 | // nested-name-qualifier (and therefore could do the lookup). |
| 3855 | NamedDecl *FirstQualifierInScope = 0; |
| 3856 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3857 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3858 | E->isArrow(), |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3859 | Qualifier, |
| 3860 | E->getQualifierRange(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3861 | E->getMemberLoc(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3862 | Member, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3863 | (E->hasExplicitTemplateArgumentList() |
| 3864 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3865 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3866 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3867 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3868 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3869 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3870 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3871 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3872 | if (LHS.isInvalid()) |
| 3873 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3874 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3875 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3876 | if (RHS.isInvalid()) |
| 3877 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 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()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3882 | return SemaRef.Owned(E->Retain()); |
| 3883 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3884 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 3885 | move(LHS), move(RHS)); |
| 3886 | } |
| 3887 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3888 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3889 | Sema::OwningExprResult |
| 3890 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3891 | CompoundAssignOperator *E) { |
| 3892 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3893 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3894 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3895 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3896 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3897 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3898 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3899 | if (Cond.isInvalid()) |
| 3900 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3901 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3902 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3903 | if (LHS.isInvalid()) |
| 3904 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3905 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3906 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3907 | if (RHS.isInvalid()) |
| 3908 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3909 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3910 | if (!getDerived().AlwaysRebuild() && |
| 3911 | Cond.get() == E->getCond() && |
| 3912 | LHS.get() == E->getLHS() && |
| 3913 | RHS.get() == E->getRHS()) |
| 3914 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3915 | |
| 3916 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3917 | E->getQuestionLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3918 | move(LHS), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3919 | E->getColonLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3920 | move(RHS)); |
| 3921 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3922 | |
| 3923 | template<typename Derived> |
| 3924 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3925 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3926 | // Implicit casts are eliminated during transformation, since they |
| 3927 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3928 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3929 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3930 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3931 | template<typename Derived> |
| 3932 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3933 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3934 | TypeSourceInfo *OldT; |
| 3935 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3936 | { |
| 3937 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3938 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3939 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3940 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3941 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3942 | OldT = E->getTypeInfoAsWritten(); |
| 3943 | NewT = getDerived().TransformType(OldT); |
| 3944 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3945 | return SemaRef.ExprError(); |
| 3946 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3947 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3948 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3949 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3950 | if (SubExpr.isInvalid()) |
| 3951 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3952 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3953 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3954 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3955 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3956 | return SemaRef.Owned(E->Retain()); |
| 3957 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3958 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 3959 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3960 | E->getRParenLoc(), |
| 3961 | move(SubExpr)); |
| 3962 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3963 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3964 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3965 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3966 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3967 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 3968 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 3969 | if (!NewT) |
| 3970 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3971 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3972 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 3973 | if (Init.isInvalid()) |
| 3974 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3975 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3976 | if (!getDerived().AlwaysRebuild() && |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3977 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3978 | Init.get() == E->getInitializer()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3979 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3980 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 3981 | // Note: the expression type doesn't necessarily match the |
| 3982 | // type-as-written, but that's okay, because it should always be |
| 3983 | // derivable from the initializer. |
| 3984 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3985 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3986 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 3987 | move(Init)); |
| 3988 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3989 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3990 | template<typename Derived> |
| 3991 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3992 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3993 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3994 | if (Base.isInvalid()) |
| 3995 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3996 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3997 | if (!getDerived().AlwaysRebuild() && |
| 3998 | Base.get() == E->getBase()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3999 | return SemaRef.Owned(E->Retain()); |
| 4000 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4001 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4002 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4003 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 4004 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 4005 | E->getAccessorLoc(), |
| 4006 | E->getAccessor()); |
| 4007 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4008 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4009 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4010 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4011 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4012 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4013 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4014 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4015 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4016 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4017 | if (Init.isInvalid()) |
| 4018 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4019 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4020 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4021 | Inits.push_back(Init.takeAs<Expr>()); |
| 4022 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4023 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4024 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4025 | return SemaRef.Owned(E->Retain()); |
| 4026 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4027 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4028 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4029 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4030 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4031 | template<typename Derived> |
| 4032 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4033 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4034 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4035 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4036 | // transform the initializer value |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4037 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4038 | if (Init.isInvalid()) |
| 4039 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4040 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4041 | // transform the designators. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4042 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4043 | bool ExprChanged = false; |
| 4044 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4045 | DEnd = E->designators_end(); |
| 4046 | D != DEnd; ++D) { |
| 4047 | if (D->isFieldDesignator()) { |
| 4048 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4049 | D->getDotLoc(), |
| 4050 | D->getFieldLoc())); |
| 4051 | continue; |
| 4052 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4053 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4054 | if (D->isArrayDesignator()) { |
| 4055 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4056 | if (Index.isInvalid()) |
| 4057 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4058 | |
| 4059 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4060 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4061 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4062 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4063 | ArrayExprs.push_back(Index.release()); |
| 4064 | continue; |
| 4065 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4066 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4067 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4068 | OwningExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4069 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4070 | if (Start.isInvalid()) |
| 4071 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4072 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4073 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4074 | if (End.isInvalid()) |
| 4075 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4076 | |
| 4077 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4078 | End.get(), |
| 4079 | D->getLBracketLoc(), |
| 4080 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4081 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4082 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4083 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4084 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4085 | ArrayExprs.push_back(Start.release()); |
| 4086 | ArrayExprs.push_back(End.release()); |
| 4087 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4088 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4089 | if (!getDerived().AlwaysRebuild() && |
| 4090 | Init.get() == E->getInit() && |
| 4091 | !ExprChanged) |
| 4092 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4093 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4094 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4095 | E->getEqualOrColonLoc(), |
| 4096 | E->usesGNUSyntax(), move(Init)); |
| 4097 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4098 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4099 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4100 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4101 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4102 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4103 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4104 | |
| 4105 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4106 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4107 | QualType T = getDerived().TransformType(E->getType()); |
| 4108 | if (T.isNull()) |
| 4109 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4110 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4111 | if (!getDerived().AlwaysRebuild() && |
| 4112 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4113 | return SemaRef.Owned(E->Retain()); |
| 4114 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4115 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4116 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4117 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4118 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4119 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4120 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4121 | // FIXME: Do we want the type as written? |
| 4122 | QualType T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4123 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4124 | { |
| 4125 | // FIXME: Source location isn't quite accurate. |
| 4126 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4127 | T = getDerived().TransformType(E->getType()); |
| 4128 | if (T.isNull()) |
| 4129 | return SemaRef.ExprError(); |
| 4130 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4131 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4132 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4133 | if (SubExpr.isInvalid()) |
| 4134 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4135 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4136 | if (!getDerived().AlwaysRebuild() && |
| 4137 | T == E->getType() && |
| 4138 | SubExpr.get() == E->getSubExpr()) |
| 4139 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4140 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4141 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4142 | T, E->getRParenLoc()); |
| 4143 | } |
| 4144 | |
| 4145 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4146 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4147 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4148 | bool ArgumentChanged = false; |
| 4149 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4150 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4151 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4152 | if (Init.isInvalid()) |
| 4153 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4154 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4155 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4156 | Inits.push_back(Init.takeAs<Expr>()); |
| 4157 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4158 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4159 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4160 | move_arg(Inits), |
| 4161 | E->getRParenLoc()); |
| 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 | /// \brief Transform an address-of-label expression. |
| 4165 | /// |
| 4166 | /// By default, the transformation of an address-of-label expression always |
| 4167 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4168 | /// the corresponding label statement by semantic analysis. |
| 4169 | template<typename Derived> |
| 4170 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4171 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4172 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4173 | E->getLabel()); |
| 4174 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4175 | |
| 4176 | template<typename Derived> |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4177 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4178 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4179 | OwningStmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4180 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4181 | if (SubStmt.isInvalid()) |
| 4182 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4183 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4184 | if (!getDerived().AlwaysRebuild() && |
| 4185 | SubStmt.get() == E->getSubStmt()) |
| 4186 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4187 | |
| 4188 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4189 | move(SubStmt), |
| 4190 | E->getRParenLoc()); |
| 4191 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4192 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4193 | template<typename Derived> |
| 4194 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4195 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4196 | QualType T1, T2; |
| 4197 | { |
| 4198 | // FIXME: Source location isn't quite accurate. |
| 4199 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4200 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4201 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4202 | if (T1.isNull()) |
| 4203 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4204 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4205 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4206 | if (T2.isNull()) |
| 4207 | return SemaRef.ExprError(); |
| 4208 | } |
| 4209 | |
| 4210 | if (!getDerived().AlwaysRebuild() && |
| 4211 | T1 == E->getArgType1() && |
| 4212 | T2 == E->getArgType2()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4213 | return SemaRef.Owned(E->Retain()); |
| 4214 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4215 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4216 | T1, T2, E->getRParenLoc()); |
| 4217 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4218 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4219 | template<typename Derived> |
| 4220 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4221 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4222 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4223 | if (Cond.isInvalid()) |
| 4224 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4225 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4226 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4227 | if (LHS.isInvalid()) |
| 4228 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4229 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4230 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4231 | if (RHS.isInvalid()) |
| 4232 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 4235 | Cond.get() == E->getCond() && |
| 4236 | LHS.get() == E->getLHS() && |
| 4237 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4238 | return SemaRef.Owned(E->Retain()); |
| 4239 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4240 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4241 | move(Cond), move(LHS), move(RHS), |
| 4242 | E->getRParenLoc()); |
| 4243 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4244 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4245 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4246 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4247 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4248 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4249 | } |
| 4250 | |
| 4251 | template<typename Derived> |
| 4252 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4253 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4254 | switch (E->getOperator()) { |
| 4255 | case OO_New: |
| 4256 | case OO_Delete: |
| 4257 | case OO_Array_New: |
| 4258 | case OO_Array_Delete: |
| 4259 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4260 | return SemaRef.ExprError(); |
| 4261 | |
| 4262 | case OO_Call: { |
| 4263 | // This is a call to an object's operator(). |
| 4264 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4265 | |
| 4266 | // Transform the object itself. |
| 4267 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4268 | if (Object.isInvalid()) |
| 4269 | return SemaRef.ExprError(); |
| 4270 | |
| 4271 | // FIXME: Poor location information |
| 4272 | SourceLocation FakeLParenLoc |
| 4273 | = SemaRef.PP.getLocForEndOfToken( |
| 4274 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4275 | |
| 4276 | // Transform the call arguments. |
| 4277 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4278 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4279 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4280 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4281 | break; |
| 4282 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4283 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4284 | if (Arg.isInvalid()) |
| 4285 | return SemaRef.ExprError(); |
| 4286 | |
| 4287 | // FIXME: Poor source location information. |
| 4288 | SourceLocation FakeCommaLoc |
| 4289 | = SemaRef.PP.getLocForEndOfToken( |
| 4290 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4291 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4292 | Args.push_back(Arg.release()); |
| 4293 | } |
| 4294 | |
| 4295 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4296 | move_arg(Args), |
| 4297 | FakeCommaLocs.data(), |
| 4298 | E->getLocEnd()); |
| 4299 | } |
| 4300 | |
| 4301 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4302 | case OO_##Name: |
| 4303 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4304 | #include "clang/Basic/OperatorKinds.def" |
| 4305 | case OO_Subscript: |
| 4306 | // Handled below. |
| 4307 | break; |
| 4308 | |
| 4309 | case OO_Conditional: |
| 4310 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4311 | return SemaRef.ExprError(); |
| 4312 | |
| 4313 | case OO_None: |
| 4314 | case NUM_OVERLOADED_OPERATORS: |
| 4315 | llvm_unreachable("not an overloaded operator?"); |
| 4316 | return SemaRef.ExprError(); |
| 4317 | } |
| 4318 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4319 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4320 | if (Callee.isInvalid()) |
| 4321 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4322 | |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4323 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4324 | if (First.isInvalid()) |
| 4325 | return SemaRef.ExprError(); |
| 4326 | |
| 4327 | OwningExprResult Second(SemaRef); |
| 4328 | if (E->getNumArgs() == 2) { |
| 4329 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4330 | if (Second.isInvalid()) |
| 4331 | return SemaRef.ExprError(); |
| 4332 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4333 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4334 | if (!getDerived().AlwaysRebuild() && |
| 4335 | Callee.get() == E->getCallee() && |
| 4336 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4337 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4338 | return SemaRef.Owned(E->Retain()); |
| 4339 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4340 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4341 | E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4342 | move(Callee), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4343 | move(First), |
| 4344 | move(Second)); |
| 4345 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4346 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4347 | template<typename Derived> |
| 4348 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4349 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4350 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4351 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4352 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4353 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4354 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4355 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4356 | TypeSourceInfo *OldT; |
| 4357 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4358 | { |
| 4359 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4360 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4361 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4362 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4363 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4364 | OldT = E->getTypeInfoAsWritten(); |
| 4365 | NewT = getDerived().TransformType(OldT); |
| 4366 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4367 | return SemaRef.ExprError(); |
| 4368 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4369 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4370 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4371 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4372 | if (SubExpr.isInvalid()) |
| 4373 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4374 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4375 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4376 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4377 | SubExpr.get() == E->getSubExpr()) |
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 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4381 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4382 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4383 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4384 | SourceLocation FakeRParenLoc |
| 4385 | = SemaRef.PP.getLocForEndOfToken( |
| 4386 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4387 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4388 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4389 | FakeLAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4390 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4391 | FakeRAngleLoc, |
| 4392 | FakeRAngleLoc, |
| 4393 | move(SubExpr), |
| 4394 | FakeRParenLoc); |
| 4395 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4396 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4397 | template<typename Derived> |
| 4398 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4399 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4400 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4401 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4402 | |
| 4403 | template<typename Derived> |
| 4404 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4405 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4406 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4407 | } |
| 4408 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4409 | template<typename Derived> |
| 4410 | Sema::OwningExprResult |
| 4411 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4412 | CXXReinterpretCastExpr *E) { |
| 4413 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4414 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4415 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4416 | template<typename Derived> |
| 4417 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4418 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4419 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4420 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4421 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4422 | template<typename Derived> |
| 4423 | Sema::OwningExprResult |
| 4424 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4425 | CXXFunctionalCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4426 | TypeSourceInfo *OldT; |
| 4427 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4428 | { |
| 4429 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4430 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4431 | OldT = E->getTypeInfoAsWritten(); |
| 4432 | NewT = getDerived().TransformType(OldT); |
| 4433 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4434 | return SemaRef.ExprError(); |
| 4435 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4436 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4437 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4438 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4439 | if (SubExpr.isInvalid()) |
| 4440 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4441 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4442 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4443 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4444 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4445 | return SemaRef.Owned(E->Retain()); |
| 4446 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4447 | // FIXME: The end of the type's source range is wrong |
| 4448 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4449 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4450 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4451 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4452 | move(SubExpr), |
| 4453 | E->getRParenLoc()); |
| 4454 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4455 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4456 | template<typename Derived> |
| 4457 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4458 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4459 | if (E->isTypeOperand()) { |
| 4460 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4461 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4462 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4463 | if (T.isNull()) |
| 4464 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4465 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4466 | if (!getDerived().AlwaysRebuild() && |
| 4467 | T == E->getTypeOperand()) |
| 4468 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4469 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4470 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4471 | /*FIXME:*/E->getLocStart(), |
| 4472 | T, |
| 4473 | E->getLocEnd()); |
| 4474 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4475 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4476 | // We don't know whether the expression is potentially evaluated until |
| 4477 | // after we perform semantic analysis, so the expression is potentially |
| 4478 | // potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4479 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4480 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4481 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4482 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4483 | if (SubExpr.isInvalid()) |
| 4484 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4485 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4486 | if (!getDerived().AlwaysRebuild() && |
| 4487 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4488 | return SemaRef.Owned(E->Retain()); |
| 4489 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4490 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4491 | /*FIXME:*/E->getLocStart(), |
| 4492 | move(SubExpr), |
| 4493 | E->getLocEnd()); |
| 4494 | } |
| 4495 | |
| 4496 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4497 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4498 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4499 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4500 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4501 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4502 | template<typename Derived> |
| 4503 | Sema::OwningExprResult |
| 4504 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4505 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4506 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4507 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4508 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4509 | template<typename Derived> |
| 4510 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4511 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4512 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4513 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4514 | QualType T = getDerived().TransformType(E->getType()); |
| 4515 | if (T.isNull()) |
| 4516 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4517 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4518 | if (!getDerived().AlwaysRebuild() && |
| 4519 | T == E->getType()) |
| 4520 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4521 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 4522 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4523 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4524 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4525 | template<typename Derived> |
| 4526 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4527 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4528 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4529 | if (SubExpr.isInvalid()) |
| 4530 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4531 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4532 | if (!getDerived().AlwaysRebuild() && |
| 4533 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4534 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4535 | |
| 4536 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4537 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4538 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4539 | template<typename Derived> |
| 4540 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4541 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4542 | ParmVarDecl *Param |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4543 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 4544 | E->getParam())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4545 | if (!Param) |
| 4546 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4547 | |
Chandler Carruth | 53cb6f8 | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 4548 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4549 | Param == E->getParam()) |
| 4550 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4551 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 4552 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4553 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4554 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4555 | template<typename Derived> |
| 4556 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4557 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4558 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4559 | |
| 4560 | QualType T = getDerived().TransformType(E->getType()); |
| 4561 | if (T.isNull()) |
| 4562 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4563 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4564 | if (!getDerived().AlwaysRebuild() && |
| 4565 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4566 | return SemaRef.Owned(E->Retain()); |
| 4567 | |
| 4568 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4569 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4570 | T, |
| 4571 | E->getRParenLoc()); |
| 4572 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4573 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4574 | template<typename Derived> |
| 4575 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4576 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4577 | // Transform the type that we're allocating |
| 4578 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4579 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4580 | if (AllocType.isNull()) |
| 4581 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4582 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4583 | // Transform the size of the array we're allocating (if any). |
| 4584 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4585 | if (ArraySize.isInvalid()) |
| 4586 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4587 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4588 | // Transform the placement arguments (if any). |
| 4589 | bool ArgumentChanged = false; |
| 4590 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4591 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4592 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4593 | if (Arg.isInvalid()) |
| 4594 | return SemaRef.ExprError(); |
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 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4597 | PlacementArgs.push_back(Arg.take()); |
| 4598 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4599 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4600 | // transform the constructor arguments (if any). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4601 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4602 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4603 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4604 | if (Arg.isInvalid()) |
| 4605 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4606 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4607 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4608 | ConstructorArgs.push_back(Arg.take()); |
| 4609 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4610 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4611 | // Transform constructor, new operator, and delete operator. |
| 4612 | CXXConstructorDecl *Constructor = 0; |
| 4613 | if (E->getConstructor()) { |
| 4614 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4615 | getDerived().TransformDecl(E->getLocStart(), |
| 4616 | E->getConstructor())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4617 | if (!Constructor) |
| 4618 | return SemaRef.ExprError(); |
| 4619 | } |
| 4620 | |
| 4621 | FunctionDecl *OperatorNew = 0; |
| 4622 | if (E->getOperatorNew()) { |
| 4623 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4624 | getDerived().TransformDecl(E->getLocStart(), |
| 4625 | E->getOperatorNew())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4626 | if (!OperatorNew) |
| 4627 | return SemaRef.ExprError(); |
| 4628 | } |
| 4629 | |
| 4630 | FunctionDecl *OperatorDelete = 0; |
| 4631 | if (E->getOperatorDelete()) { |
| 4632 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4633 | getDerived().TransformDecl(E->getLocStart(), |
| 4634 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4635 | if (!OperatorDelete) |
| 4636 | return SemaRef.ExprError(); |
| 4637 | } |
| 4638 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4639 | if (!getDerived().AlwaysRebuild() && |
| 4640 | AllocType == E->getAllocatedType() && |
| 4641 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4642 | Constructor == E->getConstructor() && |
| 4643 | OperatorNew == E->getOperatorNew() && |
| 4644 | OperatorDelete == E->getOperatorDelete() && |
| 4645 | !ArgumentChanged) { |
| 4646 | // Mark any declarations we need as referenced. |
| 4647 | // FIXME: instantiation-specific. |
| 4648 | if (Constructor) |
| 4649 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 4650 | if (OperatorNew) |
| 4651 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 4652 | if (OperatorDelete) |
| 4653 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4654 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4655 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4656 | |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 4657 | if (!ArraySize.get()) { |
| 4658 | // If no array size was specified, but the new expression was |
| 4659 | // instantiated with an array type (e.g., "new T" where T is |
| 4660 | // instantiated with "int[4]"), extract the outer bound from the |
| 4661 | // array type as our array size. We do this with constant and |
| 4662 | // dependently-sized array types. |
| 4663 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 4664 | if (!ArrayT) { |
| 4665 | // Do nothing |
| 4666 | } else if (const ConstantArrayType *ConsArrayT |
| 4667 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 4668 | ArraySize |
| 4669 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 4670 | ConsArrayT->getSize(), |
| 4671 | SemaRef.Context.getSizeType(), |
| 4672 | /*FIXME:*/E->getLocStart())); |
| 4673 | AllocType = ConsArrayT->getElementType(); |
| 4674 | } else if (const DependentSizedArrayType *DepArrayT |
| 4675 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 4676 | if (DepArrayT->getSizeExpr()) { |
| 4677 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 4678 | AllocType = DepArrayT->getElementType(); |
| 4679 | } |
| 4680 | } |
| 4681 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4682 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4683 | E->isGlobalNew(), |
| 4684 | /*FIXME:*/E->getLocStart(), |
| 4685 | move_arg(PlacementArgs), |
| 4686 | /*FIXME:*/E->getLocStart(), |
| 4687 | E->isParenTypeId(), |
| 4688 | AllocType, |
| 4689 | /*FIXME:*/E->getLocStart(), |
| 4690 | /*FIXME:*/SourceRange(), |
| 4691 | move(ArraySize), |
| 4692 | /*FIXME:*/E->getLocStart(), |
| 4693 | move_arg(ConstructorArgs), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4694 | E->getLocEnd()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4695 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4696 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4697 | template<typename Derived> |
| 4698 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4699 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4700 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4701 | if (Operand.isInvalid()) |
| 4702 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4703 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4704 | // Transform the delete operator, if known. |
| 4705 | FunctionDecl *OperatorDelete = 0; |
| 4706 | if (E->getOperatorDelete()) { |
| 4707 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4708 | getDerived().TransformDecl(E->getLocStart(), |
| 4709 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4710 | if (!OperatorDelete) |
| 4711 | return SemaRef.ExprError(); |
| 4712 | } |
| 4713 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4714 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4715 | Operand.get() == E->getArgument() && |
| 4716 | OperatorDelete == E->getOperatorDelete()) { |
| 4717 | // Mark any declarations we need as referenced. |
| 4718 | // FIXME: instantiation-specific. |
| 4719 | if (OperatorDelete) |
| 4720 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4721 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4722 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4723 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4724 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4725 | E->isGlobalDelete(), |
| 4726 | E->isArrayForm(), |
| 4727 | move(Operand)); |
| 4728 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4729 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4730 | template<typename Derived> |
| 4731 | Sema::OwningExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4732 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4733 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4734 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4735 | if (Base.isInvalid()) |
| 4736 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4737 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4738 | Sema::TypeTy *ObjectTypePtr = 0; |
| 4739 | bool MayBePseudoDestructor = false; |
| 4740 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 4741 | E->getOperatorLoc(), |
| 4742 | E->isArrow()? tok::arrow : tok::period, |
| 4743 | ObjectTypePtr, |
| 4744 | MayBePseudoDestructor); |
| 4745 | if (Base.isInvalid()) |
| 4746 | return SemaRef.ExprError(); |
| 4747 | |
| 4748 | QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4749 | NestedNameSpecifier *Qualifier |
| 4750 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | b10cd04 | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 4751 | E->getQualifierRange(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4752 | ObjectType); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4753 | if (E->getQualifier() && !Qualifier) |
| 4754 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4755 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4756 | PseudoDestructorTypeStorage Destroyed; |
| 4757 | if (E->getDestroyedTypeInfo()) { |
| 4758 | TypeSourceInfo *DestroyedTypeInfo |
| 4759 | = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType); |
| 4760 | if (!DestroyedTypeInfo) |
| 4761 | return SemaRef.ExprError(); |
| 4762 | Destroyed = DestroyedTypeInfo; |
| 4763 | } else if (ObjectType->isDependentType()) { |
| 4764 | // We aren't likely to be able to resolve the identifier down to a type |
| 4765 | // now anyway, so just retain the identifier. |
| 4766 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 4767 | E->getDestroyedTypeLoc()); |
| 4768 | } else { |
| 4769 | // Look for a destructor known with the given name. |
| 4770 | CXXScopeSpec SS; |
| 4771 | if (Qualifier) { |
| 4772 | SS.setScopeRep(Qualifier); |
| 4773 | SS.setRange(E->getQualifierRange()); |
| 4774 | } |
| 4775 | |
| 4776 | Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(), |
| 4777 | *E->getDestroyedTypeIdentifier(), |
| 4778 | E->getDestroyedTypeLoc(), |
| 4779 | /*Scope=*/0, |
| 4780 | SS, ObjectTypePtr, |
| 4781 | false); |
| 4782 | if (!T) |
| 4783 | return SemaRef.ExprError(); |
| 4784 | |
| 4785 | Destroyed |
| 4786 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 4787 | E->getDestroyedTypeLoc()); |
| 4788 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4789 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4790 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 4791 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4792 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(), |
| 4793 | ObjectType); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4794 | if (!ScopeTypeInfo) |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4795 | return SemaRef.ExprError(); |
| 4796 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4797 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4798 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4799 | E->getOperatorLoc(), |
| 4800 | E->isArrow(), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4801 | Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4802 | E->getQualifierRange(), |
| 4803 | ScopeTypeInfo, |
| 4804 | E->getColonColonLoc(), |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 4805 | E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4806 | Destroyed); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4807 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4808 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4809 | template<typename Derived> |
| 4810 | Sema::OwningExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 4811 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4812 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4813 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 4814 | |
| 4815 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 4816 | Sema::LookupOrdinaryName); |
| 4817 | |
| 4818 | // Transform all the decls. |
| 4819 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 4820 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4821 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 4822 | getDerived().TransformDecl(Old->getNameLoc(), |
| 4823 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 4824 | if (!InstD) { |
| 4825 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 4826 | // This can happen because of dependent hiding. |
| 4827 | if (isa<UsingShadowDecl>(*I)) |
| 4828 | continue; |
| 4829 | else |
| 4830 | return SemaRef.ExprError(); |
| 4831 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4832 | |
| 4833 | // Expand using declarations. |
| 4834 | if (isa<UsingDecl>(InstD)) { |
| 4835 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 4836 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 4837 | E = UD->shadow_end(); I != E; ++I) |
| 4838 | R.addDecl(*I); |
| 4839 | continue; |
| 4840 | } |
| 4841 | |
| 4842 | R.addDecl(InstD); |
| 4843 | } |
| 4844 | |
| 4845 | // Resolve a kind, but don't do any further analysis. If it's |
| 4846 | // ambiguous, the callee needs to deal with it. |
| 4847 | R.resolveKind(); |
| 4848 | |
| 4849 | // Rebuild the nested-name qualifier, if present. |
| 4850 | CXXScopeSpec SS; |
| 4851 | NestedNameSpecifier *Qualifier = 0; |
| 4852 | if (Old->getQualifier()) { |
| 4853 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4854 | Old->getQualifierRange()); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4855 | if (!Qualifier) |
| 4856 | return SemaRef.ExprError(); |
| 4857 | |
| 4858 | SS.setScopeRep(Qualifier); |
| 4859 | SS.setRange(Old->getQualifierRange()); |
| 4860 | } |
| 4861 | |
| 4862 | // If we have no template arguments, it's a normal declaration name. |
| 4863 | if (!Old->hasExplicitTemplateArgs()) |
| 4864 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 4865 | |
| 4866 | // If we have template arguments, rebuild them, then rebuild the |
| 4867 | // templateid expression. |
| 4868 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 4869 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 4870 | TemplateArgumentLoc Loc; |
| 4871 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 4872 | return SemaRef.ExprError(); |
| 4873 | TransArgs.addArgument(Loc); |
| 4874 | } |
| 4875 | |
| 4876 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 4877 | TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4878 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4879 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4880 | template<typename Derived> |
| 4881 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4882 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4883 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4884 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4885 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 4886 | if (T.isNull()) |
| 4887 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4888 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4889 | if (!getDerived().AlwaysRebuild() && |
| 4890 | T == E->getQueriedType()) |
| 4891 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4892 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4893 | // FIXME: Bad location information |
| 4894 | SourceLocation FakeLParenLoc |
| 4895 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4896 | |
| 4897 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4898 | E->getLocStart(), |
| 4899 | /*FIXME:*/FakeLParenLoc, |
| 4900 | T, |
| 4901 | E->getLocEnd()); |
| 4902 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4903 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4904 | template<typename Derived> |
| 4905 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4906 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4907 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4908 | NestedNameSpecifier *NNS |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4909 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4910 | E->getQualifierRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4911 | if (!NNS) |
| 4912 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4913 | |
| 4914 | DeclarationName Name |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4915 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 4916 | if (!Name) |
| 4917 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4918 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4919 | if (!E->hasExplicitTemplateArgs()) { |
| 4920 | if (!getDerived().AlwaysRebuild() && |
| 4921 | NNS == E->getQualifier() && |
| 4922 | Name == E->getDeclName()) |
| 4923 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4924 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4925 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4926 | E->getQualifierRange(), |
| 4927 | Name, E->getLocation(), |
| 4928 | /*TemplateArgs*/ 0); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4929 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4930 | |
| 4931 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4932 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4933 | TemplateArgumentLoc Loc; |
| 4934 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4935 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4936 | TransArgs.addArgument(Loc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4937 | } |
| 4938 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4939 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4940 | E->getQualifierRange(), |
| 4941 | Name, E->getLocation(), |
| 4942 | &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4943 | } |
| 4944 | |
| 4945 | template<typename Derived> |
| 4946 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4947 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 4948 | // CXXConstructExprs are always implicit, so when we have a |
| 4949 | // 1-argument construction we just transform that argument. |
| 4950 | if (E->getNumArgs() == 1 || |
| 4951 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 4952 | return getDerived().TransformExpr(E->getArg(0)); |
| 4953 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4954 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 4955 | |
| 4956 | QualType T = getDerived().TransformType(E->getType()); |
| 4957 | if (T.isNull()) |
| 4958 | return SemaRef.ExprError(); |
| 4959 | |
| 4960 | CXXConstructorDecl *Constructor |
| 4961 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4962 | getDerived().TransformDecl(E->getLocStart(), |
| 4963 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4964 | if (!Constructor) |
| 4965 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4966 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4967 | bool ArgumentChanged = false; |
| 4968 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4969 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4970 | ArgEnd = E->arg_end(); |
| 4971 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4972 | if (getDerived().DropCallArgument(*Arg)) { |
| 4973 | ArgumentChanged = true; |
| 4974 | break; |
| 4975 | } |
| 4976 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4977 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4978 | if (TransArg.isInvalid()) |
| 4979 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4980 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4981 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4982 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4983 | } |
| 4984 | |
| 4985 | if (!getDerived().AlwaysRebuild() && |
| 4986 | T == E->getType() && |
| 4987 | Constructor == E->getConstructor() && |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 4988 | !ArgumentChanged) { |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4989 | // Mark the constructor as referenced. |
| 4990 | // FIXME: Instantiation-specific |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 4991 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4992 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 4993 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4994 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 4995 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 4996 | Constructor, E->isElidable(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4997 | move_arg(Args)); |
| 4998 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4999 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5000 | /// \brief Transform a C++ temporary-binding expression. |
| 5001 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5002 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 5003 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5004 | template<typename Derived> |
| 5005 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5006 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5007 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5008 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5009 | |
Anders Carlsson | eb60edf | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 5010 | /// \brief Transform a C++ reference-binding expression. |
| 5011 | /// |
| 5012 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 5013 | /// transform the subexpression and return that. |
| 5014 | template<typename Derived> |
| 5015 | Sema::OwningExprResult |
| 5016 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 5017 | return getDerived().TransformExpr(E->getSubExpr()); |
| 5018 | } |
| 5019 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5020 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5021 | /// be destroyed after the expression is evaluated. |
| 5022 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5023 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 5024 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5025 | template<typename Derived> |
| 5026 | Sema::OwningExprResult |
| 5027 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5028 | CXXExprWithTemporaries *E) { |
| 5029 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5030 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5031 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5032 | template<typename Derived> |
| 5033 | Sema::OwningExprResult |
| 5034 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5035 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5036 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5037 | QualType T = getDerived().TransformType(E->getType()); |
| 5038 | if (T.isNull()) |
| 5039 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5040 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5041 | CXXConstructorDecl *Constructor |
| 5042 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5043 | getDerived().TransformDecl(E->getLocStart(), |
| 5044 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5045 | if (!Constructor) |
| 5046 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5047 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5048 | bool ArgumentChanged = false; |
| 5049 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5050 | Args.reserve(E->getNumArgs()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5051 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5052 | ArgEnd = E->arg_end(); |
| 5053 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5054 | if (getDerived().DropCallArgument(*Arg)) { |
| 5055 | ArgumentChanged = true; |
| 5056 | break; |
| 5057 | } |
| 5058 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5059 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5060 | if (TransArg.isInvalid()) |
| 5061 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5062 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5063 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5064 | Args.push_back((Expr *)TransArg.release()); |
| 5065 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5066 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5067 | if (!getDerived().AlwaysRebuild() && |
| 5068 | T == E->getType() && |
| 5069 | Constructor == E->getConstructor() && |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5070 | !ArgumentChanged) { |
| 5071 | // FIXME: Instantiation-specific |
| 5072 | SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5073 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5074 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5075 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5076 | // FIXME: Bogus location information |
| 5077 | SourceLocation CommaLoc; |
| 5078 | if (Args.size() > 1) { |
| 5079 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5080 | CommaLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5081 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 5082 | } |
| 5083 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 5084 | T, |
| 5085 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5086 | move_arg(Args), |
| 5087 | &CommaLoc, |
| 5088 | E->getLocEnd()); |
| 5089 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5090 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5091 | template<typename Derived> |
| 5092 | Sema::OwningExprResult |
| 5093 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5094 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5095 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5096 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 5097 | if (T.isNull()) |
| 5098 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5099 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5100 | bool ArgumentChanged = false; |
| 5101 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5102 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 5103 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 5104 | ArgEnd = E->arg_end(); |
| 5105 | Arg != ArgEnd; ++Arg) { |
| 5106 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5107 | if (TransArg.isInvalid()) |
| 5108 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5109 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5110 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5111 | FakeCommaLocs.push_back( |
| 5112 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 5113 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5114 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5115 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5116 | if (!getDerived().AlwaysRebuild() && |
| 5117 | T == E->getTypeAsWritten() && |
| 5118 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5119 | return SemaRef.Owned(E->Retain()); |
| 5120 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5121 | // FIXME: we're faking the locations of the commas |
| 5122 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5123 | T, |
| 5124 | E->getLParenLoc(), |
| 5125 | move_arg(Args), |
| 5126 | FakeCommaLocs.data(), |
| 5127 | E->getRParenLoc()); |
| 5128 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5129 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5130 | template<typename Derived> |
| 5131 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5132 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5133 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5134 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5135 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5136 | Expr *OldBase; |
| 5137 | QualType BaseType; |
| 5138 | QualType ObjectType; |
| 5139 | if (!E->isImplicitAccess()) { |
| 5140 | OldBase = E->getBase(); |
| 5141 | Base = getDerived().TransformExpr(OldBase); |
| 5142 | if (Base.isInvalid()) |
| 5143 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5144 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5145 | // Start the member reference and compute the object's type. |
| 5146 | Sema::TypeTy *ObjectTy = 0; |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5147 | bool MayBePseudoDestructor = false; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5148 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5149 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5150 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5151 | ObjectTy, |
| 5152 | MayBePseudoDestructor); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5153 | if (Base.isInvalid()) |
| 5154 | return SemaRef.ExprError(); |
| 5155 | |
| 5156 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5157 | BaseType = ((Expr*) Base.get())->getType(); |
| 5158 | } else { |
| 5159 | OldBase = 0; |
| 5160 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5161 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5162 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5163 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5164 | // Transform the first part of the nested-name-specifier that qualifies |
| 5165 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5166 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5167 | = getDerived().TransformFirstQualifierInScope( |
| 5168 | E->getFirstQualifierFoundInScope(), |
| 5169 | E->getQualifierRange().getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5170 | |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5171 | NestedNameSpecifier *Qualifier = 0; |
| 5172 | if (E->getQualifier()) { |
| 5173 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5174 | E->getQualifierRange(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5175 | ObjectType, |
| 5176 | FirstQualifierInScope); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5177 | if (!Qualifier) |
| 5178 | return SemaRef.ExprError(); |
| 5179 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5180 | |
| 5181 | DeclarationName Name |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5182 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5183 | ObjectType); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5184 | if (!Name) |
| 5185 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5186 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5187 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5188 | // This is a reference to a member without an explicitly-specified |
| 5189 | // template argument list. Optimize for this common case. |
| 5190 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5191 | Base.get() == OldBase && |
| 5192 | BaseType == E->getBaseType() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5193 | Qualifier == E->getQualifier() && |
| 5194 | Name == E->getMember() && |
| 5195 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5196 | return SemaRef.Owned(E->Retain()); |
| 5197 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5198 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5199 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5200 | E->isArrow(), |
| 5201 | E->getOperatorLoc(), |
| 5202 | Qualifier, |
| 5203 | E->getQualifierRange(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5204 | FirstQualifierInScope, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5205 | Name, |
| 5206 | E->getMemberLoc(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5207 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5208 | } |
| 5209 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5210 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5211 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5212 | TemplateArgumentLoc Loc; |
| 5213 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5214 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5215 | TransArgs.addArgument(Loc); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5216 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5217 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5218 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5219 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5220 | E->isArrow(), |
| 5221 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5222 | Qualifier, |
| 5223 | E->getQualifierRange(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5224 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5225 | Name, |
| 5226 | E->getMemberLoc(), |
| 5227 | &TransArgs); |
| 5228 | } |
| 5229 | |
| 5230 | template<typename Derived> |
| 5231 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5232 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5233 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5234 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5235 | QualType BaseType; |
| 5236 | if (!Old->isImplicitAccess()) { |
| 5237 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5238 | if (Base.isInvalid()) |
| 5239 | return SemaRef.ExprError(); |
| 5240 | BaseType = ((Expr*) Base.get())->getType(); |
| 5241 | } else { |
| 5242 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5243 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5244 | |
| 5245 | NestedNameSpecifier *Qualifier = 0; |
| 5246 | if (Old->getQualifier()) { |
| 5247 | Qualifier |
| 5248 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5249 | Old->getQualifierRange()); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5250 | if (Qualifier == 0) |
| 5251 | return SemaRef.ExprError(); |
| 5252 | } |
| 5253 | |
| 5254 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5255 | Sema::LookupOrdinaryName); |
| 5256 | |
| 5257 | // Transform all the decls. |
| 5258 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5259 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5260 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5261 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 5262 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5263 | if (!InstD) { |
| 5264 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5265 | // This can happen because of dependent hiding. |
| 5266 | if (isa<UsingShadowDecl>(*I)) |
| 5267 | continue; |
| 5268 | else |
| 5269 | return SemaRef.ExprError(); |
| 5270 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5271 | |
| 5272 | // Expand using declarations. |
| 5273 | if (isa<UsingDecl>(InstD)) { |
| 5274 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5275 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5276 | E = UD->shadow_end(); I != E; ++I) |
| 5277 | R.addDecl(*I); |
| 5278 | continue; |
| 5279 | } |
| 5280 | |
| 5281 | R.addDecl(InstD); |
| 5282 | } |
| 5283 | |
| 5284 | R.resolveKind(); |
| 5285 | |
| 5286 | TemplateArgumentListInfo TransArgs; |
| 5287 | if (Old->hasExplicitTemplateArgs()) { |
| 5288 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5289 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5290 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5291 | TemplateArgumentLoc Loc; |
| 5292 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5293 | Loc)) |
| 5294 | return SemaRef.ExprError(); |
| 5295 | TransArgs.addArgument(Loc); |
| 5296 | } |
| 5297 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5298 | |
| 5299 | // FIXME: to do this check properly, we will need to preserve the |
| 5300 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5301 | // base (and therefore couldn't do the check) and a |
| 5302 | // nested-name-qualifier (and therefore could do the lookup). |
| 5303 | NamedDecl *FirstQualifierInScope = 0; |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5304 | |
| 5305 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5306 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5307 | Old->getOperatorLoc(), |
| 5308 | Old->isArrow(), |
| 5309 | Qualifier, |
| 5310 | Old->getQualifierRange(), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5311 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5312 | R, |
| 5313 | (Old->hasExplicitTemplateArgs() |
| 5314 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5315 | } |
| 5316 | |
| 5317 | template<typename Derived> |
| 5318 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5319 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5320 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5321 | } |
| 5322 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5323 | template<typename Derived> |
| 5324 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5325 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5326 | // FIXME: poor source location |
| 5327 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 5328 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 5329 | if (EncodedType.isNull()) |
| 5330 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5331 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5332 | if (!getDerived().AlwaysRebuild() && |
| 5333 | EncodedType == E->getEncodedType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5334 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5335 | |
| 5336 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 5337 | EncodedType, |
| 5338 | E->getRParenLoc()); |
| 5339 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5340 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5341 | template<typename Derived> |
| 5342 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5343 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5344 | // FIXME: Implement this! |
| 5345 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5346 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5347 | } |
| 5348 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5349 | template<typename Derived> |
| 5350 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5351 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5352 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5353 | } |
| 5354 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5355 | template<typename Derived> |
| 5356 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5357 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5358 | ObjCProtocolDecl *Protocol |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5359 | = cast_or_null<ObjCProtocolDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5360 | getDerived().TransformDecl(E->getLocStart(), |
| 5361 | E->getProtocol())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5362 | if (!Protocol) |
| 5363 | return SemaRef.ExprError(); |
| 5364 | |
| 5365 | if (!getDerived().AlwaysRebuild() && |
| 5366 | Protocol == E->getProtocol()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5367 | return SemaRef.Owned(E->Retain()); |
| 5368 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5369 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 5370 | E->getAtLoc(), |
| 5371 | /*FIXME:*/E->getAtLoc(), |
| 5372 | /*FIXME:*/E->getAtLoc(), |
| 5373 | E->getRParenLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5374 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5375 | } |
| 5376 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5377 | template<typename Derived> |
| 5378 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5379 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5380 | // FIXME: Implement this! |
| 5381 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5382 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5383 | } |
| 5384 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5385 | template<typename Derived> |
| 5386 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5387 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5388 | // FIXME: Implement this! |
| 5389 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5390 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5391 | } |
| 5392 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5393 | template<typename Derived> |
| 5394 | Sema::OwningExprResult |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5395 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5396 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5397 | // FIXME: Implement this! |
| 5398 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5399 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5400 | } |
| 5401 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5402 | template<typename Derived> |
| 5403 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5404 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5405 | // FIXME: Implement this! |
| 5406 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5407 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5408 | } |
| 5409 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5410 | template<typename Derived> |
| 5411 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5412 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5413 | // FIXME: Implement this! |
| 5414 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5415 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5416 | } |
| 5417 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5418 | template<typename Derived> |
| 5419 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5420 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5421 | bool ArgumentChanged = false; |
| 5422 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5423 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5424 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5425 | if (SubExpr.isInvalid()) |
| 5426 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5427 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5428 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5429 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5430 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5431 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5432 | if (!getDerived().AlwaysRebuild() && |
| 5433 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5434 | return SemaRef.Owned(E->Retain()); |
| 5435 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5436 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5437 | move_arg(SubExprs), |
| 5438 | E->getRParenLoc()); |
| 5439 | } |
| 5440 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5441 | template<typename Derived> |
| 5442 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5443 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5444 | // FIXME: Implement this! |
| 5445 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5446 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5447 | } |
| 5448 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5449 | template<typename Derived> |
| 5450 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5451 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5452 | // FIXME: Implement this! |
| 5453 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5454 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5455 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5456 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5457 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5458 | // Type reconstruction |
| 5459 | //===----------------------------------------------------------------------===// |
| 5460 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5461 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5462 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5463 | SourceLocation Star) { |
| 5464 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5465 | getDerived().getBaseEntity()); |
| 5466 | } |
| 5467 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5468 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5469 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5470 | SourceLocation Star) { |
| 5471 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5472 | getDerived().getBaseEntity()); |
| 5473 | } |
| 5474 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5475 | template<typename Derived> |
| 5476 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5477 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5478 | bool WrittenAsLValue, |
| 5479 | SourceLocation Sigil) { |
| 5480 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5481 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5482 | } |
| 5483 | |
| 5484 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5485 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5486 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5487 | QualType ClassType, |
| 5488 | SourceLocation Sigil) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5489 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5490 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5491 | } |
| 5492 | |
| 5493 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5494 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5495 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType, |
| 5496 | SourceLocation Sigil) { |
| 5497 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5498 | getDerived().getBaseEntity()); |
| 5499 | } |
| 5500 | |
| 5501 | template<typename Derived> |
| 5502 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5503 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5504 | ArrayType::ArraySizeModifier SizeMod, |
| 5505 | const llvm::APInt *Size, |
| 5506 | Expr *SizeExpr, |
| 5507 | unsigned IndexTypeQuals, |
| 5508 | SourceRange BracketsRange) { |
| 5509 | if (SizeExpr || !Size) |
| 5510 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5511 | IndexTypeQuals, BracketsRange, |
| 5512 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5513 | |
| 5514 | QualType Types[] = { |
| 5515 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5516 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5517 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5518 | }; |
| 5519 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5520 | QualType SizeType; |
| 5521 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5522 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5523 | SizeType = Types[I]; |
| 5524 | break; |
| 5525 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5526 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5527 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5528 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5529 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5530 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5531 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5532 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5533 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5534 | QualType |
| 5535 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5536 | ArrayType::ArraySizeModifier SizeMod, |
| 5537 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5538 | unsigned IndexTypeQuals, |
| 5539 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5540 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5541 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5542 | } |
| 5543 | |
| 5544 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5545 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5546 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5547 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5548 | unsigned IndexTypeQuals, |
| 5549 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5550 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5551 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5552 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5553 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5554 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5555 | QualType |
| 5556 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5557 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5558 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5559 | unsigned IndexTypeQuals, |
| 5560 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5561 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5562 | SizeExpr.takeAs<Expr>(), |
| 5563 | IndexTypeQuals, BracketsRange); |
| 5564 | } |
| 5565 | |
| 5566 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5567 | QualType |
| 5568 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5569 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5570 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5571 | unsigned IndexTypeQuals, |
| 5572 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5573 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5574 | SizeExpr.takeAs<Expr>(), |
| 5575 | IndexTypeQuals, BracketsRange); |
| 5576 | } |
| 5577 | |
| 5578 | template<typename Derived> |
| 5579 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5580 | unsigned NumElements, |
| 5581 | bool IsAltiVec, bool IsPixel) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5582 | // FIXME: semantic checking! |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5583 | return SemaRef.Context.getVectorType(ElementType, NumElements, |
| 5584 | IsAltiVec, IsPixel); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5585 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5586 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5587 | template<typename Derived> |
| 5588 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5589 | unsigned NumElements, |
| 5590 | SourceLocation AttributeLoc) { |
| 5591 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5592 | NumElements, true); |
| 5593 | IntegerLiteral *VectorSize |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5594 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5595 | AttributeLoc); |
| 5596 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5597 | AttributeLoc); |
| 5598 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5599 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5600 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5601 | QualType |
| 5602 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5603 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5604 | SourceLocation AttributeLoc) { |
| 5605 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5606 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5607 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5608 | template<typename Derived> |
| 5609 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5610 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5611 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5612 | bool Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5613 | unsigned Quals) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5614 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5615 | Quals, |
| 5616 | getDerived().getBaseLocation(), |
| 5617 | getDerived().getBaseEntity()); |
| 5618 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5619 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5620 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5621 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5622 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5623 | } |
| 5624 | |
| 5625 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5626 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 5627 | assert(D && "no decl found"); |
| 5628 | if (D->isInvalidDecl()) return QualType(); |
| 5629 | |
| 5630 | TypeDecl *Ty; |
| 5631 | if (isa<UsingDecl>(D)) { |
| 5632 | UsingDecl *Using = cast<UsingDecl>(D); |
| 5633 | assert(Using->isTypeName() && |
| 5634 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 5635 | |
| 5636 | // A valid resolved using typename decl points to exactly one type decl. |
| 5637 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 5638 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 5639 | |
| 5640 | } else { |
| 5641 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 5642 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 5643 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 5644 | } |
| 5645 | |
| 5646 | return SemaRef.Context.getTypeDeclType(Ty); |
| 5647 | } |
| 5648 | |
| 5649 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5650 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5651 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5652 | } |
| 5653 | |
| 5654 | template<typename Derived> |
| 5655 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5656 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5657 | } |
| 5658 | |
| 5659 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5660 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5661 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5662 | } |
| 5663 | |
| 5664 | template<typename Derived> |
| 5665 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5666 | TemplateName Template, |
| 5667 | SourceLocation TemplateNameLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5668 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5669 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5670 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5671 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5672 | template<typename Derived> |
| 5673 | NestedNameSpecifier * |
| 5674 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5675 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5676 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5677 | QualType ObjectType, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5678 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5679 | CXXScopeSpec SS; |
| 5680 | // FIXME: The source location information is all wrong. |
| 5681 | SS.setRange(Range); |
| 5682 | SS.setScopeRep(Prefix); |
| 5683 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5684 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5685 | Range.getEnd(), II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5686 | ObjectType, |
| 5687 | FirstQualifierInScope, |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 5688 | false, false)); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5689 | } |
| 5690 | |
| 5691 | template<typename Derived> |
| 5692 | NestedNameSpecifier * |
| 5693 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5694 | SourceRange Range, |
| 5695 | NamespaceDecl *NS) { |
| 5696 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5697 | } |
| 5698 | |
| 5699 | template<typename Derived> |
| 5700 | NestedNameSpecifier * |
| 5701 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5702 | SourceRange Range, |
| 5703 | bool TemplateKW, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5704 | QualType T) { |
| 5705 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5706 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5707 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5708 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5709 | T.getTypePtr()); |
| 5710 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5711 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5712 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5713 | return 0; |
| 5714 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5715 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5716 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5717 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5718 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5719 | bool TemplateKW, |
| 5720 | TemplateDecl *Template) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5721 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5722 | Template); |
| 5723 | } |
| 5724 | |
| 5725 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5726 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5727 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5728 | const IdentifierInfo &II, |
| 5729 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5730 | CXXScopeSpec SS; |
| 5731 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5732 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5733 | UnqualifiedId Name; |
| 5734 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5735 | return getSema().ActOnDependentTemplateName( |
| 5736 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5737 | SS, |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5738 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5739 | ObjectType.getAsOpaquePtr(), |
| 5740 | /*EnteringContext=*/false) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5741 | .template getAsVal<TemplateName>(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5742 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5743 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5744 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5745 | TemplateName |
| 5746 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5747 | OverloadedOperatorKind Operator, |
| 5748 | QualType ObjectType) { |
| 5749 | CXXScopeSpec SS; |
| 5750 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5751 | SS.setScopeRep(Qualifier); |
| 5752 | UnqualifiedId Name; |
| 5753 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5754 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5755 | Operator, SymbolLocations); |
| 5756 | return getSema().ActOnDependentTemplateName( |
| 5757 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5758 | SS, |
| 5759 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5760 | ObjectType.getAsOpaquePtr(), |
| 5761 | /*EnteringContext=*/false) |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5762 | .template getAsVal<TemplateName>(); |
| 5763 | } |
| 5764 | |
| 5765 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5766 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5767 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5768 | SourceLocation OpLoc, |
| 5769 | ExprArg Callee, |
| 5770 | ExprArg First, |
| 5771 | ExprArg Second) { |
| 5772 | Expr *FirstExpr = (Expr *)First.get(); |
| 5773 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5774 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5775 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5776 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5777 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5778 | if (Op == OO_Subscript) { |
| 5779 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5780 | !SecondExpr->getType()->isOverloadableType()) |
| 5781 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5782 | CalleeExpr->getLocStart(), |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5783 | move(Second), OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 5784 | } else if (Op == OO_Arrow) { |
| 5785 | // -> is never a builtin operation. |
| 5786 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5787 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5788 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5789 | // The argument is not of overloadable type, so try to create a |
| 5790 | // built-in unary operation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5791 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5792 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5793 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5794 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5795 | } |
| 5796 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5797 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5798 | !SecondExpr->getType()->isOverloadableType()) { |
| 5799 | // Neither of the arguments is an overloadable type, so try to |
| 5800 | // create a built-in binary operation. |
| 5801 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5802 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5803 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5804 | if (Result.isInvalid()) |
| 5805 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5806 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5807 | First.release(); |
| 5808 | Second.release(); |
| 5809 | return move(Result); |
| 5810 | } |
| 5811 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5812 | |
| 5813 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5814 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5815 | UnresolvedSet<16> Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5816 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5817 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 5818 | assert(ULE->requiresADL()); |
| 5819 | |
| 5820 | // FIXME: Do we have to check |
| 5821 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5822 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5823 | } else { |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5824 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5825 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5826 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5827 | // Add any functions found via argument-dependent lookup. |
| 5828 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5829 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5830 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5831 | // Create the overloaded operator invocation for unary operators. |
| 5832 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5833 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5834 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5835 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5836 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5837 | |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5838 | if (Op == OO_Subscript) |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5839 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 5840 | OpLoc, |
| 5841 | move(First), |
| 5842 | move(Second)); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5843 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5844 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5845 | BinaryOperator::Opcode Opc = |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5846 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5847 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5848 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5849 | if (Result.isInvalid()) |
| 5850 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5851 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5852 | First.release(); |
| 5853 | Second.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5854 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5855 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5856 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5857 | template<typename Derived> |
| 5858 | Sema::OwningExprResult |
| 5859 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 5860 | SourceLocation OperatorLoc, |
| 5861 | bool isArrow, |
| 5862 | NestedNameSpecifier *Qualifier, |
| 5863 | SourceRange QualifierRange, |
| 5864 | TypeSourceInfo *ScopeType, |
| 5865 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 5866 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5867 | PseudoDestructorTypeStorage Destroyed) { |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5868 | CXXScopeSpec SS; |
| 5869 | if (Qualifier) { |
| 5870 | SS.setRange(QualifierRange); |
| 5871 | SS.setScopeRep(Qualifier); |
| 5872 | } |
| 5873 | |
| 5874 | Expr *BaseE = (Expr *)Base.get(); |
| 5875 | QualType BaseType = BaseE->getType(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5876 | if (BaseE->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5877 | (!isArrow && !BaseType->getAs<RecordType>()) || |
| 5878 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | bf2ca2f | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 5879 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 5880 | ->template getAs<RecordType>())){ |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5881 | // This pseudo-destructor expression is still a pseudo-destructor. |
| 5882 | return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc, |
| 5883 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 5884 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5885 | Destroyed, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5886 | /*FIXME?*/true); |
| 5887 | } |
| 5888 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5889 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5890 | DeclarationName Name |
| 5891 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 5892 | SemaRef.Context.getCanonicalType(DestroyedType->getType())); |
| 5893 | |
| 5894 | // FIXME: the ScopeType should be tacked onto SS. |
| 5895 | |
| 5896 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 5897 | OperatorLoc, isArrow, |
| 5898 | SS, /*FIXME: FirstQualifier*/ 0, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5899 | Name, Destroyed.getLocation(), |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5900 | /*TemplateArgs*/ 0); |
| 5901 | } |
| 5902 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5903 | } // end namespace clang |
| 5904 | |
| 5905 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |