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; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 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 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 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. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 204 | TypeSourceInfo *TransformType(TypeSourceInfo *DI, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 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 | /// |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 211 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 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. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 246 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 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 | /// |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 253 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 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. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 259 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 260 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 261 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 262 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 263 | /// \brief Transform the given nested-name-specifier. |
| 264 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 265 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 266 | /// nested-name-specifier. Subclasses may override this function to provide |
| 267 | /// alternate behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 268 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 269 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 270 | QualType ObjectType = QualType(), |
| 271 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 272 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 273 | /// \brief Transform the given declaration name. |
| 274 | /// |
| 275 | /// By default, transforms the types of conversion function, constructor, |
| 276 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 277 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 278 | /// override this function to provide alternate behavior. |
| 279 | DeclarationName TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 280 | SourceLocation Loc, |
| 281 | QualType ObjectType = QualType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 283 | /// \brief Transform the given template name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 284 | /// |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 285 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 286 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 287 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 288 | TemplateName TransformTemplateName(TemplateName Name, |
| 289 | QualType ObjectType = QualType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 290 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 291 | /// \brief Transform the given template argument. |
| 292 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 293 | /// By default, this operation transforms the type, expression, or |
| 294 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 295 | /// new template argument from the transformed result. Subclasses may |
| 296 | /// override this function to provide alternate behavior. |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 297 | /// |
| 298 | /// Returns true if there was an error. |
| 299 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 300 | TemplateArgumentLoc &Output); |
| 301 | |
| 302 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 303 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 304 | TemplateArgumentLoc &ArgLoc); |
| 305 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 306 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 307 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 308 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 309 | getDerived().getBaseLocation()); |
| 310 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 311 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 312 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 313 | #define TYPELOC(CLASS, PARENT) \ |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 314 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \ |
| 315 | QualType ObjectType = QualType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 316 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 317 | |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 318 | /// \brief Transforms the parameters of a function type into the |
| 319 | /// given vectors. |
| 320 | /// |
| 321 | /// The result vectors should be kept in sync; null entries in the |
| 322 | /// variables vector are acceptable. |
| 323 | /// |
| 324 | /// Return true on error. |
| 325 | bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 326 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 327 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars); |
| 328 | |
| 329 | /// \brief Transforms a single function-type parameter. Return null |
| 330 | /// on error. |
| 331 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm); |
| 332 | |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 333 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 334 | QualType ObjectType); |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 335 | |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 336 | QualType |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 337 | TransformTemplateSpecializationType(const TemplateSpecializationType *T, |
| 338 | QualType ObjectType); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 339 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 340 | OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
Zhongxing Xu | d8383d4 | 2010-04-21 06:32:25 +0000 | [diff] [blame] | 341 | OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 342 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 343 | #define STMT(Node, Parent) \ |
| 344 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 345 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 346 | OwningExprResult Transform##Node(Node *E); |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 347 | #define ABSTRACT_STMT(Stmt) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 348 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 349 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 350 | /// \brief Build a new pointer type given its pointee type. |
| 351 | /// |
| 352 | /// By default, performs semantic analysis when building the pointer type. |
| 353 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 354 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 355 | |
| 356 | /// \brief Build a new block pointer type given its pointee type. |
| 357 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 358 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 359 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 360 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 361 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 362 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 363 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 364 | /// By default, performs semantic analysis when building the |
| 365 | /// reference type. Subclasses may override this routine to provide |
| 366 | /// different behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 367 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 368 | /// \param LValue whether the type was written with an lvalue sigil |
| 369 | /// or an rvalue sigil. |
| 370 | QualType RebuildReferenceType(QualType ReferentType, |
| 371 | bool LValue, |
| 372 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 373 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 374 | /// \brief Build a new member pointer type given the pointee type and the |
| 375 | /// class type it refers into. |
| 376 | /// |
| 377 | /// By default, performs semantic analysis when building the member pointer |
| 378 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 379 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 380 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 382 | /// \brief Build a new array type given the element type, size |
| 383 | /// modifier, size of the array (if known), size expression, and index type |
| 384 | /// qualifiers. |
| 385 | /// |
| 386 | /// By default, performs semantic analysis when building the array type. |
| 387 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 389 | QualType RebuildArrayType(QualType ElementType, |
| 390 | ArrayType::ArraySizeModifier SizeMod, |
| 391 | const llvm::APInt *Size, |
| 392 | Expr *SizeExpr, |
| 393 | unsigned IndexTypeQuals, |
| 394 | SourceRange BracketsRange); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 395 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 396 | /// \brief Build a new constant array type given the element type, size |
| 397 | /// modifier, (known) size of the array, and index type qualifiers. |
| 398 | /// |
| 399 | /// By default, performs semantic analysis when building the array type. |
| 400 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 401 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 402 | ArrayType::ArraySizeModifier SizeMod, |
| 403 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 404 | unsigned IndexTypeQuals, |
| 405 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 406 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 407 | /// \brief Build a new incomplete array type given the element type, size |
| 408 | /// modifier, and index type qualifiers. |
| 409 | /// |
| 410 | /// By default, performs semantic analysis when building the array type. |
| 411 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 412 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 413 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 414 | unsigned IndexTypeQuals, |
| 415 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 416 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 417 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 418 | /// size modifier, size expression, and index type qualifiers. |
| 419 | /// |
| 420 | /// By default, performs semantic analysis when building the array type. |
| 421 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 422 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 423 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 424 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 425 | unsigned IndexTypeQuals, |
| 426 | SourceRange BracketsRange); |
| 427 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 428 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 429 | /// size modifier, size expression, and index type qualifiers. |
| 430 | /// |
| 431 | /// By default, performs semantic analysis when building the array type. |
| 432 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 433 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 434 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 435 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 436 | unsigned IndexTypeQuals, |
| 437 | SourceRange BracketsRange); |
| 438 | |
| 439 | /// \brief Build a new vector type given the element type and |
| 440 | /// number of elements. |
| 441 | /// |
| 442 | /// By default, performs semantic analysis when building the vector type. |
| 443 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 444 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
| 445 | bool IsAltiVec, bool IsPixel); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 447 | /// \brief Build a new extended vector type given the element type and |
| 448 | /// number of elements. |
| 449 | /// |
| 450 | /// By default, performs semantic analysis when building the vector type. |
| 451 | /// Subclasses may override this routine to provide different behavior. |
| 452 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 453 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 454 | |
| 455 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 456 | /// given the element type and number of elements. |
| 457 | /// |
| 458 | /// By default, performs semantic analysis when building the vector type. |
| 459 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 460 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 461 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 462 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 463 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 464 | /// \brief Build a new function type. |
| 465 | /// |
| 466 | /// By default, performs semantic analysis when building the function type. |
| 467 | /// Subclasses may override this routine to provide different behavior. |
| 468 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 469 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 470 | unsigned NumParamTypes, |
| 471 | bool Variadic, unsigned Quals); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 472 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 473 | /// \brief Build a new unprototyped function type. |
| 474 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 475 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 476 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 477 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 478 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 479 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 480 | /// \brief Build a new typedef type. |
| 481 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 482 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 483 | } |
| 484 | |
| 485 | /// \brief Build a new class/struct/union type. |
| 486 | QualType RebuildRecordType(RecordDecl *Record) { |
| 487 | return SemaRef.Context.getTypeDeclType(Record); |
| 488 | } |
| 489 | |
| 490 | /// \brief Build a new Enum type. |
| 491 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 492 | return SemaRef.Context.getTypeDeclType(Enum); |
| 493 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 494 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 495 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 496 | /// |
| 497 | /// By default, performs semantic analysis when building the typeof type. |
| 498 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 499 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 500 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 501 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 502 | /// |
| 503 | /// By default, builds a new TypeOfType with the given underlying type. |
| 504 | QualType RebuildTypeOfType(QualType Underlying); |
| 505 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 506 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 507 | /// |
| 508 | /// By default, performs semantic analysis when building the decltype type. |
| 509 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 510 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 512 | /// \brief Build a new template specialization type. |
| 513 | /// |
| 514 | /// By default, performs semantic analysis when building the template |
| 515 | /// specialization type. Subclasses may override this routine to provide |
| 516 | /// different behavior. |
| 517 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 518 | SourceLocation TemplateLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 519 | const TemplateArgumentListInfo &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 520 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 521 | /// \brief Build a new qualified name type. |
| 522 | /// |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 523 | /// By default, builds a new ElaboratedType type from the keyword, |
| 524 | /// the nested-name-specifier and the named type. |
| 525 | /// Subclasses may override this routine to provide different behavior. |
| 526 | QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword, |
| 527 | NestedNameSpecifier *NNS, QualType Named) { |
| 528 | return SemaRef.Context.getElaboratedType(Keyword, NNS, Named); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 529 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 530 | |
| 531 | /// \brief Build a new typename type that refers to a template-id. |
| 532 | /// |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 533 | /// By default, builds a new DependentNameType type from the |
| 534 | /// nested-name-specifier and the given type. Subclasses may override |
| 535 | /// this routine to provide different behavior. |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 536 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
| 537 | NestedNameSpecifier *NNS, QualType T) { |
Douglas Gregor | ae62889 | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 538 | if (NNS->isDependent()) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 539 | // If the name is still dependent, just build a new dependent name type. |
Douglas Gregor | ae62889 | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 540 | CXXScopeSpec SS; |
| 541 | SS.setScopeRep(NNS); |
| 542 | if (!SemaRef.computeDeclContext(SS)) |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 543 | return SemaRef.Context.getDependentNameType(Keyword, NNS, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 544 | cast<TemplateSpecializationType>(T)); |
Douglas Gregor | ae62889 | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 545 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 546 | |
| 547 | return SemaRef.Context.getElaboratedType(Keyword, NNS, T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 548 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 549 | |
| 550 | /// \brief Build a new typename type that refers to an identifier. |
| 551 | /// |
| 552 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 553 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 554 | /// different behavior. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 555 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 556 | NestedNameSpecifier *NNS, |
| 557 | const IdentifierInfo *Id, |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 558 | SourceLocation KeywordLoc, |
| 559 | SourceRange NNSRange, |
| 560 | SourceLocation IdLoc) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 561 | CXXScopeSpec SS; |
| 562 | SS.setScopeRep(NNS); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 563 | SS.setRange(NNSRange); |
| 564 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 565 | if (NNS->isDependent()) { |
| 566 | // If the name is still dependent, just build a new dependent name type. |
| 567 | if (!SemaRef.computeDeclContext(SS)) |
| 568 | return SemaRef.Context.getDependentNameType(Keyword, NNS, Id); |
| 569 | } |
| 570 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 571 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 572 | return SemaRef.CheckTypenameType(Keyword, NNS, *Id, |
| 573 | KeywordLoc, NNSRange, IdLoc); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 574 | |
| 575 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 576 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 577 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 578 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 579 | // referring to. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 580 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 581 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 582 | if (!DC) |
| 583 | return QualType(); |
| 584 | |
John McCall | 5613876 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 585 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 586 | return QualType(); |
| 587 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 588 | TagDecl *Tag = 0; |
| 589 | SemaRef.LookupQualifiedName(Result, DC); |
| 590 | switch (Result.getResultKind()) { |
| 591 | case LookupResult::NotFound: |
| 592 | case LookupResult::NotFoundInCurrentInstantiation: |
| 593 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 594 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 595 | case LookupResult::Found: |
| 596 | Tag = Result.getAsSingle<TagDecl>(); |
| 597 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 598 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 599 | case LookupResult::FoundOverloaded: |
| 600 | case LookupResult::FoundUnresolvedValue: |
| 601 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 602 | return QualType(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 603 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 604 | case LookupResult::Ambiguous: |
| 605 | // Let the LookupResult structure handle ambiguities. |
| 606 | return QualType(); |
| 607 | } |
| 608 | |
| 609 | if (!Tag) { |
Douglas Gregor | 1eabb7d | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 610 | // FIXME: Would be nice to highlight just the source range. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 611 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
Douglas Gregor | 1eabb7d | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 612 | << Kind << Id << DC; |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 613 | return QualType(); |
| 614 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 615 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 616 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) { |
| 617 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 618 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 619 | return QualType(); |
| 620 | } |
| 621 | |
| 622 | // Build the elaborated-type-specifier type. |
| 623 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 624 | return SemaRef.Context.getElaboratedType(Keyword, NNS, T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 625 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 626 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 627 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 628 | /// identifier that names the next step in the nested-name-specifier. |
| 629 | /// |
| 630 | /// By default, performs semantic analysis when building the new |
| 631 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 632 | /// different behavior. |
| 633 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 634 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 635 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 636 | QualType ObjectType, |
| 637 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 638 | |
| 639 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 640 | /// namespace named in the next step in the nested-name-specifier. |
| 641 | /// |
| 642 | /// By default, performs semantic analysis when building the new |
| 643 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 644 | /// different behavior. |
| 645 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 646 | SourceRange Range, |
| 647 | NamespaceDecl *NS); |
| 648 | |
| 649 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 650 | /// type named in the next step in the nested-name-specifier. |
| 651 | /// |
| 652 | /// By default, performs semantic analysis when building the new |
| 653 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 654 | /// different behavior. |
| 655 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 656 | SourceRange Range, |
| 657 | bool TemplateKW, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 658 | QualType T); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 659 | |
| 660 | /// \brief Build a new template name given a nested name specifier, a flag |
| 661 | /// indicating whether the "template" keyword was provided, and the template |
| 662 | /// that the template name refers to. |
| 663 | /// |
| 664 | /// By default, builds the new template name directly. Subclasses may override |
| 665 | /// this routine to provide different behavior. |
| 666 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 667 | bool TemplateKW, |
| 668 | TemplateDecl *Template); |
| 669 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 670 | /// \brief Build a new template name given a nested name specifier and the |
| 671 | /// name that is referred to as a template. |
| 672 | /// |
| 673 | /// By default, performs semantic analysis to determine whether the name can |
| 674 | /// be resolved to a specific template, then builds the appropriate kind of |
| 675 | /// template name. Subclasses may override this routine to provide different |
| 676 | /// behavior. |
| 677 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 678 | const IdentifierInfo &II, |
| 679 | QualType ObjectType); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 680 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 681 | /// \brief Build a new template name given a nested name specifier and the |
| 682 | /// overloaded operator name that is referred to as a template. |
| 683 | /// |
| 684 | /// By default, performs semantic analysis to determine whether the name can |
| 685 | /// be resolved to a specific template, then builds the appropriate kind of |
| 686 | /// template name. Subclasses may override this routine to provide different |
| 687 | /// behavior. |
| 688 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 689 | OverloadedOperatorKind Operator, |
| 690 | QualType ObjectType); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 691 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 692 | /// \brief Build a new compound statement. |
| 693 | /// |
| 694 | /// By default, performs semantic analysis to build the new statement. |
| 695 | /// Subclasses may override this routine to provide different behavior. |
| 696 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 697 | MultiStmtArg Statements, |
| 698 | SourceLocation RBraceLoc, |
| 699 | bool IsStmtExpr) { |
| 700 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 701 | IsStmtExpr); |
| 702 | } |
| 703 | |
| 704 | /// \brief Build a new case statement. |
| 705 | /// |
| 706 | /// By default, performs semantic analysis to build the new statement. |
| 707 | /// Subclasses may override this routine to provide different behavior. |
| 708 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 709 | ExprArg LHS, |
| 710 | SourceLocation EllipsisLoc, |
| 711 | ExprArg RHS, |
| 712 | SourceLocation ColonLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 713 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 714 | ColonLoc); |
| 715 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 716 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 717 | /// \brief Attach the body to a new case statement. |
| 718 | /// |
| 719 | /// By default, performs semantic analysis to build the new statement. |
| 720 | /// Subclasses may override this routine to provide different behavior. |
| 721 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 722 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 723 | return move(S); |
| 724 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 725 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 726 | /// \brief Build a new default statement. |
| 727 | /// |
| 728 | /// By default, performs semantic analysis to build the new statement. |
| 729 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 730 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 731 | SourceLocation ColonLoc, |
| 732 | StmtArg SubStmt) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 733 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 734 | /*CurScope=*/0); |
| 735 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 736 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 737 | /// \brief Build a new label statement. |
| 738 | /// |
| 739 | /// By default, performs semantic analysis to build the new statement. |
| 740 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 741 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 742 | IdentifierInfo *Id, |
| 743 | SourceLocation ColonLoc, |
| 744 | StmtArg SubStmt) { |
| 745 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 746 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 747 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 748 | /// \brief Build a new "if" statement. |
| 749 | /// |
| 750 | /// By default, performs semantic analysis to build the new statement. |
| 751 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 752 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 753 | VarDecl *CondVar, StmtArg Then, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 754 | SourceLocation ElseLoc, StmtArg Else) { |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 755 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 756 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 757 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 758 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 759 | /// \brief Start building a new switch statement. |
| 760 | /// |
| 761 | /// By default, performs semantic analysis to build the new statement. |
| 762 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 763 | OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
| 764 | Sema::ExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 765 | VarDecl *CondVar) { |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 766 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond), |
| 767 | DeclPtrTy::make(CondVar)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 768 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 769 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 770 | /// \brief Attach the body to the switch statement. |
| 771 | /// |
| 772 | /// By default, performs semantic analysis to build the new statement. |
| 773 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 774 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 775 | StmtArg Switch, StmtArg Body) { |
| 776 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 777 | move(Body)); |
| 778 | } |
| 779 | |
| 780 | /// \brief Build a new while statement. |
| 781 | /// |
| 782 | /// By default, performs semantic analysis to build the new statement. |
| 783 | /// Subclasses may override this routine to provide different behavior. |
| 784 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 785 | Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 786 | VarDecl *CondVar, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 787 | StmtArg Body) { |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 788 | return getSema().ActOnWhileStmt(WhileLoc, Cond, |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 789 | DeclPtrTy::make(CondVar), move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 790 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 791 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 792 | /// \brief Build a new do-while statement. |
| 793 | /// |
| 794 | /// By default, performs semantic analysis to build the new statement. |
| 795 | /// Subclasses may override this routine to provide different behavior. |
| 796 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 797 | SourceLocation WhileLoc, |
| 798 | SourceLocation LParenLoc, |
| 799 | ExprArg Cond, |
| 800 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 801 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 802 | move(Cond), RParenLoc); |
| 803 | } |
| 804 | |
| 805 | /// \brief Build a new for statement. |
| 806 | /// |
| 807 | /// By default, performs semantic analysis to build the new statement. |
| 808 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 809 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 810 | SourceLocation LParenLoc, |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 811 | StmtArg Init, Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 812 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 813 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 814 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 815 | DeclPtrTy::make(CondVar), |
| 816 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 817 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 818 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 819 | /// \brief Build a new goto statement. |
| 820 | /// |
| 821 | /// By default, performs semantic analysis to build the new statement. |
| 822 | /// Subclasses may override this routine to provide different behavior. |
| 823 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 824 | SourceLocation LabelLoc, |
| 825 | LabelStmt *Label) { |
| 826 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 827 | } |
| 828 | |
| 829 | /// \brief Build a new indirect goto statement. |
| 830 | /// |
| 831 | /// By default, performs semantic analysis to build the new statement. |
| 832 | /// Subclasses may override this routine to provide different behavior. |
| 833 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 834 | SourceLocation StarLoc, |
| 835 | ExprArg Target) { |
| 836 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 837 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 838 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 839 | /// \brief Build a new return statement. |
| 840 | /// |
| 841 | /// By default, performs semantic analysis to build the new statement. |
| 842 | /// Subclasses may override this routine to provide different behavior. |
| 843 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 844 | ExprArg Result) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 845 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 846 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 847 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 848 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 849 | /// \brief Build a new declaration statement. |
| 850 | /// |
| 851 | /// By default, performs semantic analysis to build the new statement. |
| 852 | /// Subclasses may override this routine to provide different behavior. |
| 853 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 854 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 855 | SourceLocation EndLoc) { |
| 856 | return getSema().Owned( |
| 857 | new (getSema().Context) DeclStmt( |
| 858 | DeclGroupRef::Create(getSema().Context, |
| 859 | Decls, NumDecls), |
| 860 | StartLoc, EndLoc)); |
| 861 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 862 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 863 | /// \brief Build a new inline asm statement. |
| 864 | /// |
| 865 | /// By default, performs semantic analysis to build the new statement. |
| 866 | /// Subclasses may override this routine to provide different behavior. |
| 867 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 868 | bool IsSimple, |
| 869 | bool IsVolatile, |
| 870 | unsigned NumOutputs, |
| 871 | unsigned NumInputs, |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 872 | IdentifierInfo **Names, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 873 | MultiExprArg Constraints, |
| 874 | MultiExprArg Exprs, |
| 875 | ExprArg AsmString, |
| 876 | MultiExprArg Clobbers, |
| 877 | SourceLocation RParenLoc, |
| 878 | bool MSAsm) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 879 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 880 | NumInputs, Names, move(Constraints), |
| 881 | move(Exprs), move(AsmString), move(Clobbers), |
| 882 | RParenLoc, MSAsm); |
| 883 | } |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 884 | |
| 885 | /// \brief Build a new Objective-C @try statement. |
| 886 | /// |
| 887 | /// By default, performs semantic analysis to build the new statement. |
| 888 | /// Subclasses may override this routine to provide different behavior. |
| 889 | OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
| 890 | StmtArg TryBody, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 891 | MultiStmtArg CatchStmts, |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 892 | StmtArg Finally) { |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 893 | return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts), |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 894 | move(Finally)); |
| 895 | } |
| 896 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 897 | /// \brief Rebuild an Objective-C exception declaration. |
| 898 | /// |
| 899 | /// By default, performs semantic analysis to build the new declaration. |
| 900 | /// Subclasses may override this routine to provide different behavior. |
| 901 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 902 | TypeSourceInfo *TInfo, QualType T) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 903 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 904 | ExceptionDecl->getIdentifier(), |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 905 | ExceptionDecl->getLocation()); |
| 906 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 907 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 908 | /// \brief Build a new Objective-C @catch statement. |
| 909 | /// |
| 910 | /// By default, performs semantic analysis to build the new statement. |
| 911 | /// Subclasses may override this routine to provide different behavior. |
| 912 | OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
| 913 | SourceLocation RParenLoc, |
| 914 | VarDecl *Var, |
| 915 | StmtArg Body) { |
| 916 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
| 917 | Sema::DeclPtrTy::make(Var), |
| 918 | move(Body)); |
| 919 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 920 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 921 | /// \brief Build a new Objective-C @finally statement. |
| 922 | /// |
| 923 | /// By default, performs semantic analysis to build the new statement. |
| 924 | /// Subclasses may override this routine to provide different behavior. |
| 925 | OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
| 926 | StmtArg Body) { |
| 927 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body)); |
| 928 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 929 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 930 | /// \brief Build a new Objective-C @throw statement. |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 931 | /// |
| 932 | /// By default, performs semantic analysis to build the new statement. |
| 933 | /// Subclasses may override this routine to provide different behavior. |
| 934 | OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
| 935 | ExprArg Operand) { |
| 936 | return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand)); |
| 937 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 938 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 939 | /// \brief Build a new Objective-C @synchronized statement. |
| 940 | /// |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 941 | /// By default, performs semantic analysis to build the new statement. |
| 942 | /// Subclasses may override this routine to provide different behavior. |
| 943 | OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
| 944 | ExprArg Object, |
| 945 | StmtArg Body) { |
| 946 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object), |
| 947 | move(Body)); |
| 948 | } |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 949 | |
| 950 | /// \brief Build a new Objective-C fast enumeration statement. |
| 951 | /// |
| 952 | /// By default, performs semantic analysis to build the new statement. |
| 953 | /// Subclasses may override this routine to provide different behavior. |
| 954 | OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
| 955 | SourceLocation LParenLoc, |
| 956 | StmtArg Element, |
| 957 | ExprArg Collection, |
| 958 | SourceLocation RParenLoc, |
| 959 | StmtArg Body) { |
| 960 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 961 | move(Element), |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 962 | move(Collection), |
| 963 | RParenLoc, |
| 964 | move(Body)); |
| 965 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 966 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 967 | /// \brief Build a new C++ exception declaration. |
| 968 | /// |
| 969 | /// By default, performs semantic analysis to build the new decaration. |
| 970 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 971 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 972 | TypeSourceInfo *Declarator, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 973 | IdentifierInfo *Name, |
| 974 | SourceLocation Loc, |
| 975 | SourceRange TypeRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 976 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 977 | TypeRange); |
| 978 | } |
| 979 | |
| 980 | /// \brief Build a new C++ catch statement. |
| 981 | /// |
| 982 | /// By default, performs semantic analysis to build the new statement. |
| 983 | /// Subclasses may override this routine to provide different behavior. |
| 984 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 985 | VarDecl *ExceptionDecl, |
| 986 | StmtArg Handler) { |
| 987 | return getSema().Owned( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 988 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 989 | Handler.takeAs<Stmt>())); |
| 990 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 991 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 992 | /// \brief Build a new C++ try statement. |
| 993 | /// |
| 994 | /// By default, performs semantic analysis to build the new statement. |
| 995 | /// Subclasses may override this routine to provide different behavior. |
| 996 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 997 | StmtArg TryBlock, |
| 998 | MultiStmtArg Handlers) { |
| 999 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 1000 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1001 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1002 | /// \brief Build a new expression that references a declaration. |
| 1003 | /// |
| 1004 | /// By default, performs semantic analysis to build the new expression. |
| 1005 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1006 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 1007 | LookupResult &R, |
| 1008 | bool RequiresADL) { |
| 1009 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1010 | } |
| 1011 | |
| 1012 | |
| 1013 | /// \brief Build a new expression that references a declaration. |
| 1014 | /// |
| 1015 | /// By default, performs semantic analysis to build the new expression. |
| 1016 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1017 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 1018 | SourceRange QualifierRange, |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1019 | ValueDecl *VD, SourceLocation Loc, |
| 1020 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1021 | CXXScopeSpec SS; |
| 1022 | SS.setScopeRep(Qualifier); |
| 1023 | SS.setRange(QualifierRange); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1024 | |
| 1025 | // FIXME: loses template args. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1026 | |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1027 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1028 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1029 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1030 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1031 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1032 | /// By default, performs semantic analysis to build the new expression. |
| 1033 | /// Subclasses may override this routine to provide different behavior. |
| 1034 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 1035 | SourceLocation RParen) { |
| 1036 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 1037 | } |
| 1038 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1039 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1040 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1041 | /// By default, performs semantic analysis to build the new expression. |
| 1042 | /// Subclasses may override this routine to provide different behavior. |
| 1043 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 1044 | SourceLocation OperatorLoc, |
| 1045 | bool isArrow, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1046 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 1047 | SourceRange QualifierRange, |
| 1048 | TypeSourceInfo *ScopeType, |
| 1049 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 1050 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1051 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1052 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1053 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1054 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1055 | /// By default, performs semantic analysis to build the new expression. |
| 1056 | /// Subclasses may override this routine to provide different behavior. |
| 1057 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 1058 | UnaryOperator::Opcode Opc, |
| 1059 | ExprArg SubExpr) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1060 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1061 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1062 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1063 | /// \brief Build a new builtin offsetof expression. |
| 1064 | /// |
| 1065 | /// By default, performs semantic analysis to build the new expression. |
| 1066 | /// Subclasses may override this routine to provide different behavior. |
| 1067 | OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
| 1068 | TypeSourceInfo *Type, |
| 1069 | Action::OffsetOfComponent *Components, |
| 1070 | unsigned NumComponents, |
| 1071 | SourceLocation RParenLoc) { |
| 1072 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1073 | NumComponents, RParenLoc); |
| 1074 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1075 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1076 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1077 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1078 | /// By default, performs semantic analysis to build the new expression. |
| 1079 | /// Subclasses may override this routine to provide different behavior. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1080 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 1081 | SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1082 | bool isSizeOf, SourceRange R) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1083 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1084 | } |
| 1085 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1086 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1087 | /// argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1088 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1089 | /// By default, performs semantic analysis to build the new expression. |
| 1090 | /// Subclasses may override this routine to provide different behavior. |
| 1091 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 1092 | bool isSizeOf, SourceRange R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1093 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1094 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 1095 | OpLoc, isSizeOf, R); |
| 1096 | if (Result.isInvalid()) |
| 1097 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1098 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1099 | SubExpr.release(); |
| 1100 | return move(Result); |
| 1101 | } |
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 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1104 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1105 | /// By default, performs semantic analysis to build the new expression. |
| 1106 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1107 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1108 | SourceLocation LBracketLoc, |
| 1109 | ExprArg RHS, |
| 1110 | SourceLocation RBracketLoc) { |
| 1111 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1112 | LBracketLoc, move(RHS), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1113 | RBracketLoc); |
| 1114 | } |
| 1115 | |
| 1116 | /// \brief Build a new call 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 RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 1121 | MultiExprArg Args, |
| 1122 | SourceLocation *CommaLocs, |
| 1123 | SourceLocation RParenLoc) { |
| 1124 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 1125 | move(Args), CommaLocs, RParenLoc); |
| 1126 | } |
| 1127 | |
| 1128 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1129 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1130 | /// By default, performs semantic analysis to build the new expression. |
| 1131 | /// Subclasses may override this routine to provide different behavior. |
| 1132 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1133 | bool isArrow, |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1134 | NestedNameSpecifier *Qualifier, |
| 1135 | SourceRange QualifierRange, |
| 1136 | SourceLocation MemberLoc, |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 1137 | ValueDecl *Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1138 | NamedDecl *FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1139 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 1140 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1141 | if (!Member->getDeclName()) { |
| 1142 | // We have a reference to an unnamed field. |
| 1143 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1144 | |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1145 | Expr *BaseExpr = Base.takeAs<Expr>(); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1146 | if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, |
| 1147 | FoundDecl, Member)) |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1148 | return getSema().ExprError(); |
Douglas Gregor | 8aa5f40 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 1149 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1150 | MemberExpr *ME = |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1151 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1152 | Member, MemberLoc, |
| 1153 | cast<FieldDecl>(Member)->getType()); |
| 1154 | return getSema().Owned(ME); |
| 1155 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1156 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1157 | CXXScopeSpec SS; |
| 1158 | if (Qualifier) { |
| 1159 | SS.setRange(QualifierRange); |
| 1160 | SS.setScopeRep(Qualifier); |
| 1161 | } |
| 1162 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1163 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1164 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1165 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1166 | // cases; we should avoid this when possible. |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1167 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 1168 | Sema::LookupMemberName); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1169 | R.addDecl(FoundDecl); |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1170 | R.resolveKind(); |
| 1171 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1172 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 1173 | OpLoc, isArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1174 | SS, FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1175 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1176 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1177 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1178 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1179 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1180 | /// By default, performs semantic analysis to build the new expression. |
| 1181 | /// Subclasses may override this routine to provide different behavior. |
| 1182 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1183 | BinaryOperator::Opcode Opc, |
| 1184 | ExprArg LHS, ExprArg RHS) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1185 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1186 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1190 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1191 | /// By default, performs semantic analysis to build the new expression. |
| 1192 | /// Subclasses may override this routine to provide different behavior. |
| 1193 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1194 | SourceLocation QuestionLoc, |
| 1195 | ExprArg LHS, |
| 1196 | SourceLocation ColonLoc, |
| 1197 | ExprArg RHS) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1198 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1199 | move(LHS), move(RHS)); |
| 1200 | } |
| 1201 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1202 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1203 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1204 | /// By default, performs semantic analysis to build the new expression. |
| 1205 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1206 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1207 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1208 | SourceLocation RParenLoc, |
| 1209 | ExprArg SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1210 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1211 | move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1212 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1213 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1214 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1215 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1216 | /// By default, performs semantic analysis to build the new expression. |
| 1217 | /// Subclasses may override this routine to provide different behavior. |
| 1218 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1219 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1220 | SourceLocation RParenLoc, |
| 1221 | ExprArg Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1222 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1223 | move(Init)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1224 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1225 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1226 | /// \brief Build a new extended vector element access expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1229 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1230 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1231 | SourceLocation OpLoc, |
| 1232 | SourceLocation AccessorLoc, |
| 1233 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1234 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1235 | CXXScopeSpec SS; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1236 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1237 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1238 | OpLoc, /*IsArrow*/ false, |
| 1239 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1240 | DeclarationName(&Accessor), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1241 | AccessorLoc, |
| 1242 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1243 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1244 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1245 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1246 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1247 | /// By default, performs semantic analysis to build the new expression. |
| 1248 | /// Subclasses may override this routine to provide different behavior. |
| 1249 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1250 | MultiExprArg Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1251 | SourceLocation RBraceLoc, |
| 1252 | QualType ResultTy) { |
| 1253 | OwningExprResult Result |
| 1254 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1255 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1256 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1257 | |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1258 | // Patch in the result type we were given, which may have been computed |
| 1259 | // when the initial InitListExpr was built. |
| 1260 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1261 | ILE->setType(ResultTy); |
| 1262 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1263 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1264 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1265 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1266 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1267 | /// By default, performs semantic analysis to build the new expression. |
| 1268 | /// Subclasses may override this routine to provide different behavior. |
| 1269 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1270 | MultiExprArg ArrayExprs, |
| 1271 | SourceLocation EqualOrColonLoc, |
| 1272 | bool GNUSyntax, |
| 1273 | ExprArg Init) { |
| 1274 | OwningExprResult Result |
| 1275 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1276 | move(Init)); |
| 1277 | if (Result.isInvalid()) |
| 1278 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1279 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1280 | ArrayExprs.release(); |
| 1281 | return move(Result); |
| 1282 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1283 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1284 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1285 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1286 | /// By default, builds the implicit value initialization without performing |
| 1287 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1288 | /// different behavior. |
| 1289 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1290 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1291 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1292 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1293 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1294 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1295 | /// By default, performs semantic analysis to build the new expression. |
| 1296 | /// Subclasses may override this routine to provide different behavior. |
| 1297 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1298 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1299 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1300 | RParenLoc); |
| 1301 | } |
| 1302 | |
| 1303 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1304 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1305 | /// By default, performs semantic analysis to build the new expression. |
| 1306 | /// Subclasses may override this routine to provide different behavior. |
| 1307 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1308 | MultiExprArg SubExprs, |
| 1309 | SourceLocation RParenLoc) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1310 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
Fariborz Jahanian | f88f7ab | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1311 | move(SubExprs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1312 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1313 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1314 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1315 | /// |
| 1316 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1317 | /// rather than attempting to map the label statement itself. |
| 1318 | /// Subclasses may override this routine to provide different behavior. |
| 1319 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1320 | SourceLocation LabelLoc, |
| 1321 | LabelStmt *Label) { |
| 1322 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1323 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1324 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1325 | /// \brief Build a new GNU statement expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1328 | /// Subclasses may override this routine to provide different behavior. |
| 1329 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1330 | StmtArg SubStmt, |
| 1331 | SourceLocation RParenLoc) { |
| 1332 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1333 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1334 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1335 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1336 | /// |
| 1337 | /// By default, performs semantic analysis to build the new expression. |
| 1338 | /// Subclasses may override this routine to provide different behavior. |
| 1339 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1340 | QualType T1, QualType T2, |
| 1341 | SourceLocation RParenLoc) { |
| 1342 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1343 | T1.getAsOpaquePtr(), |
| 1344 | T2.getAsOpaquePtr(), |
| 1345 | RParenLoc); |
| 1346 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1347 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1348 | /// \brief Build a new __builtin_choose_expr expression. |
| 1349 | /// |
| 1350 | /// By default, performs semantic analysis to build the new expression. |
| 1351 | /// Subclasses may override this routine to provide different behavior. |
| 1352 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1353 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1354 | SourceLocation RParenLoc) { |
| 1355 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1356 | move(Cond), move(LHS), move(RHS), |
| 1357 | RParenLoc); |
| 1358 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1359 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1360 | /// \brief Build a new overloaded operator call expression. |
| 1361 | /// |
| 1362 | /// By default, performs semantic analysis to build the new expression. |
| 1363 | /// The semantic analysis provides the behavior of template instantiation, |
| 1364 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1365 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1366 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1367 | /// provide different behavior. |
| 1368 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1369 | SourceLocation OpLoc, |
| 1370 | ExprArg Callee, |
| 1371 | ExprArg First, |
| 1372 | ExprArg Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1373 | |
| 1374 | /// \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] | 1375 | /// reinterpret_cast. |
| 1376 | /// |
| 1377 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1378 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1379 | /// Subclasses may override this routine to provide different behavior. |
| 1380 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1381 | Stmt::StmtClass Class, |
| 1382 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1383 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1384 | SourceLocation RAngleLoc, |
| 1385 | SourceLocation LParenLoc, |
| 1386 | ExprArg SubExpr, |
| 1387 | SourceLocation RParenLoc) { |
| 1388 | switch (Class) { |
| 1389 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1390 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1391 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1392 | move(SubExpr), RParenLoc); |
| 1393 | |
| 1394 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1395 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1396 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1397 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1398 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1399 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1400 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1401 | RAngleLoc, LParenLoc, |
| 1402 | move(SubExpr), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1403 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1404 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1405 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1406 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1407 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1408 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1409 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1410 | default: |
| 1411 | assert(false && "Invalid C++ named cast"); |
| 1412 | break; |
| 1413 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1414 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1415 | return getSema().ExprError(); |
| 1416 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1417 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1418 | /// \brief Build a new C++ static_cast expression. |
| 1419 | /// |
| 1420 | /// By default, performs semantic analysis to build the new expression. |
| 1421 | /// Subclasses may override this routine to provide different behavior. |
| 1422 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1423 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1424 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1425 | SourceLocation RAngleLoc, |
| 1426 | SourceLocation LParenLoc, |
| 1427 | ExprArg SubExpr, |
| 1428 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1429 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1430 | TInfo, move(SubExpr), |
| 1431 | SourceRange(LAngleLoc, RAngleLoc), |
| 1432 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | /// \brief Build a new C++ dynamic_cast expression. |
| 1436 | /// |
| 1437 | /// By default, performs semantic analysis to build the new expression. |
| 1438 | /// Subclasses may override this routine to provide different behavior. |
| 1439 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1440 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1441 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1442 | SourceLocation RAngleLoc, |
| 1443 | SourceLocation LParenLoc, |
| 1444 | ExprArg SubExpr, |
| 1445 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1446 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1447 | TInfo, move(SubExpr), |
| 1448 | SourceRange(LAngleLoc, RAngleLoc), |
| 1449 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1453 | /// |
| 1454 | /// By default, performs semantic analysis to build the new expression. |
| 1455 | /// Subclasses may override this routine to provide different behavior. |
| 1456 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1457 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1458 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1459 | SourceLocation RAngleLoc, |
| 1460 | SourceLocation LParenLoc, |
| 1461 | ExprArg SubExpr, |
| 1462 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1463 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1464 | TInfo, move(SubExpr), |
| 1465 | SourceRange(LAngleLoc, RAngleLoc), |
| 1466 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | /// \brief Build a new C++ const_cast expression. |
| 1470 | /// |
| 1471 | /// By default, performs semantic analysis to build the new expression. |
| 1472 | /// Subclasses may override this routine to provide different behavior. |
| 1473 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1474 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1475 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1476 | SourceLocation RAngleLoc, |
| 1477 | SourceLocation LParenLoc, |
| 1478 | ExprArg SubExpr, |
| 1479 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1480 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1481 | TInfo, move(SubExpr), |
| 1482 | SourceRange(LAngleLoc, RAngleLoc), |
| 1483 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1484 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1485 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1486 | /// \brief Build a new C++ functional-style cast expression. |
| 1487 | /// |
| 1488 | /// By default, performs semantic analysis to build the new expression. |
| 1489 | /// Subclasses may override this routine to provide different behavior. |
| 1490 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1491 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1492 | SourceLocation LParenLoc, |
| 1493 | ExprArg SubExpr, |
| 1494 | SourceLocation RParenLoc) { |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1495 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1496 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1497 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1498 | LParenLoc, |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1499 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1500 | /*CommaLocs=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1501 | RParenLoc); |
| 1502 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1503 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1504 | /// \brief Build a new C++ typeid(type) expression. |
| 1505 | /// |
| 1506 | /// By default, performs semantic analysis to build the new expression. |
| 1507 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1508 | OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 1509 | SourceLocation TypeidLoc, |
| 1510 | TypeSourceInfo *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1511 | SourceLocation RParenLoc) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1512 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1513 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1514 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1515 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1516 | /// \brief Build a new C++ typeid(expr) expression. |
| 1517 | /// |
| 1518 | /// By default, performs semantic analysis to build the new expression. |
| 1519 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1520 | OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 1521 | SourceLocation TypeidLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1522 | ExprArg Operand, |
| 1523 | SourceLocation RParenLoc) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1524 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand), |
| 1525 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1528 | /// \brief Build a new C++ "this" expression. |
| 1529 | /// |
| 1530 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1531 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1532 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1533 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1534 | QualType ThisType, |
| 1535 | bool isImplicit) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1536 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1537 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1538 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | /// \brief Build a new C++ throw expression. |
| 1542 | /// |
| 1543 | /// By default, performs semantic analysis to build the new expression. |
| 1544 | /// Subclasses may override this routine to provide different behavior. |
| 1545 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1546 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1547 | } |
| 1548 | |
| 1549 | /// \brief Build a new C++ default-argument expression. |
| 1550 | /// |
| 1551 | /// By default, builds a new default-argument expression, which does not |
| 1552 | /// require any semantic analysis. Subclasses may override this routine to |
| 1553 | /// provide different behavior. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1554 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1555 | ParmVarDecl *Param) { |
| 1556 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1557 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | /// \brief Build a new C++ zero-initialization expression. |
| 1561 | /// |
| 1562 | /// By default, performs semantic analysis to build the new expression. |
| 1563 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1564 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1565 | SourceLocation LParenLoc, |
| 1566 | QualType T, |
| 1567 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1568 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1569 | T.getAsOpaquePtr(), LParenLoc, |
| 1570 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1571 | 0, RParenLoc); |
| 1572 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1573 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1574 | /// \brief Build a new C++ "new" expression. |
| 1575 | /// |
| 1576 | /// By default, performs semantic analysis to build the new expression. |
| 1577 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1578 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1579 | bool UseGlobal, |
| 1580 | SourceLocation PlacementLParen, |
| 1581 | MultiExprArg PlacementArgs, |
| 1582 | SourceLocation PlacementRParen, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1583 | bool ParenTypeId, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1584 | QualType AllocType, |
| 1585 | SourceLocation TypeLoc, |
| 1586 | SourceRange TypeRange, |
| 1587 | ExprArg ArraySize, |
| 1588 | SourceLocation ConstructorLParen, |
| 1589 | MultiExprArg ConstructorArgs, |
| 1590 | SourceLocation ConstructorRParen) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1591 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1592 | PlacementLParen, |
| 1593 | move(PlacementArgs), |
| 1594 | PlacementRParen, |
| 1595 | ParenTypeId, |
| 1596 | AllocType, |
| 1597 | TypeLoc, |
| 1598 | TypeRange, |
| 1599 | move(ArraySize), |
| 1600 | ConstructorLParen, |
| 1601 | move(ConstructorArgs), |
| 1602 | ConstructorRParen); |
| 1603 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1604 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1605 | /// \brief Build a new C++ "delete" expression. |
| 1606 | /// |
| 1607 | /// By default, performs semantic analysis to build the new expression. |
| 1608 | /// Subclasses may override this routine to provide different behavior. |
| 1609 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1610 | bool IsGlobalDelete, |
| 1611 | bool IsArrayForm, |
| 1612 | ExprArg Operand) { |
| 1613 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1614 | move(Operand)); |
| 1615 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1616 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1617 | /// \brief Build a new unary type trait expression. |
| 1618 | /// |
| 1619 | /// By default, performs semantic analysis to build the new expression. |
| 1620 | /// Subclasses may override this routine to provide different behavior. |
| 1621 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1622 | SourceLocation StartLoc, |
| 1623 | SourceLocation LParenLoc, |
| 1624 | QualType T, |
| 1625 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1626 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1627 | T.getAsOpaquePtr(), RParenLoc); |
| 1628 | } |
| 1629 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1630 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1631 | /// expression. |
| 1632 | /// |
| 1633 | /// By default, performs semantic analysis to build the new expression. |
| 1634 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1635 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1636 | SourceRange QualifierRange, |
| 1637 | DeclarationName Name, |
| 1638 | SourceLocation Location, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1639 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1640 | CXXScopeSpec SS; |
| 1641 | SS.setRange(QualifierRange); |
| 1642 | SS.setScopeRep(NNS); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1643 | |
| 1644 | if (TemplateArgs) |
| 1645 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1646 | *TemplateArgs); |
| 1647 | |
| 1648 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | /// \brief Build a new template-id expression. |
| 1652 | /// |
| 1653 | /// By default, performs semantic analysis to build the new expression. |
| 1654 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1655 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1656 | LookupResult &R, |
| 1657 | bool RequiresADL, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1658 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1659 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | /// \brief Build a new object-construction expression. |
| 1663 | /// |
| 1664 | /// By default, performs semantic analysis to build the new expression. |
| 1665 | /// Subclasses may override this routine to provide different behavior. |
| 1666 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1667 | SourceLocation Loc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1668 | CXXConstructorDecl *Constructor, |
| 1669 | bool IsElidable, |
| 1670 | MultiExprArg Args) { |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1671 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1672 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1673 | ConvertedArgs)) |
| 1674 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1675 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1676 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1677 | move_arg(ConvertedArgs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | /// \brief Build a new object-construction expression. |
| 1681 | /// |
| 1682 | /// By default, performs semantic analysis to build the new expression. |
| 1683 | /// Subclasses may override this routine to provide different behavior. |
| 1684 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1685 | QualType T, |
| 1686 | SourceLocation LParenLoc, |
| 1687 | MultiExprArg Args, |
| 1688 | SourceLocation *Commas, |
| 1689 | SourceLocation RParenLoc) { |
| 1690 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1691 | T.getAsOpaquePtr(), |
| 1692 | LParenLoc, |
| 1693 | move(Args), |
| 1694 | Commas, |
| 1695 | RParenLoc); |
| 1696 | } |
| 1697 | |
| 1698 | /// \brief Build a new object-construction expression. |
| 1699 | /// |
| 1700 | /// By default, performs semantic analysis to build the new expression. |
| 1701 | /// Subclasses may override this routine to provide different behavior. |
| 1702 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1703 | QualType T, |
| 1704 | SourceLocation LParenLoc, |
| 1705 | MultiExprArg Args, |
| 1706 | SourceLocation *Commas, |
| 1707 | SourceLocation RParenLoc) { |
| 1708 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1709 | /*FIXME*/LParenLoc), |
| 1710 | T.getAsOpaquePtr(), |
| 1711 | LParenLoc, |
| 1712 | move(Args), |
| 1713 | Commas, |
| 1714 | RParenLoc); |
| 1715 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1716 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1717 | /// \brief Build a new member reference expression. |
| 1718 | /// |
| 1719 | /// By default, performs semantic analysis to build the new expression. |
| 1720 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1721 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1722 | QualType BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1723 | bool IsArrow, |
| 1724 | SourceLocation OperatorLoc, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1725 | NestedNameSpecifier *Qualifier, |
| 1726 | SourceRange QualifierRange, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1727 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1728 | DeclarationName Name, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1729 | SourceLocation MemberLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1730 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1731 | CXXScopeSpec SS; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1732 | SS.setRange(QualifierRange); |
| 1733 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1734 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1735 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1736 | OperatorLoc, IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1737 | SS, FirstQualifierInScope, |
| 1738 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1739 | } |
| 1740 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1741 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1742 | /// |
| 1743 | /// By default, performs semantic analysis to build the new expression. |
| 1744 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1745 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1746 | QualType BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1747 | SourceLocation OperatorLoc, |
| 1748 | bool IsArrow, |
| 1749 | NestedNameSpecifier *Qualifier, |
| 1750 | SourceRange QualifierRange, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1751 | NamedDecl *FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1752 | LookupResult &R, |
| 1753 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1754 | CXXScopeSpec SS; |
| 1755 | SS.setRange(QualifierRange); |
| 1756 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1757 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1758 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1759 | OperatorLoc, IsArrow, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1760 | SS, FirstQualifierInScope, |
| 1761 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1762 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1763 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1764 | /// \brief Build a new Objective-C @encode expression. |
| 1765 | /// |
| 1766 | /// By default, performs semantic analysis to build the new expression. |
| 1767 | /// Subclasses may override this routine to provide different behavior. |
| 1768 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1769 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1770 | SourceLocation RParenLoc) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1771 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1772 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1773 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1774 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1775 | /// \brief Build a new Objective-C class message. |
| 1776 | OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
| 1777 | Selector Sel, |
| 1778 | ObjCMethodDecl *Method, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1779 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1780 | MultiExprArg Args, |
| 1781 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1782 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 1783 | ReceiverTypeInfo->getType(), |
| 1784 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | f49bb08 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1785 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1786 | move(Args)); |
| 1787 | } |
| 1788 | |
| 1789 | /// \brief Build a new Objective-C instance message. |
| 1790 | OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver, |
| 1791 | Selector Sel, |
| 1792 | ObjCMethodDecl *Method, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1793 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1794 | MultiExprArg Args, |
| 1795 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1796 | QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType(); |
| 1797 | return SemaRef.BuildInstanceMessage(move(Receiver), |
| 1798 | ReceiverType, |
| 1799 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | f49bb08 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1800 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1801 | move(Args)); |
| 1802 | } |
| 1803 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1804 | /// \brief Build a new Objective-C ivar reference expression. |
| 1805 | /// |
| 1806 | /// By default, performs semantic analysis to build the new expression. |
| 1807 | /// Subclasses may override this routine to provide different behavior. |
| 1808 | OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar, |
| 1809 | SourceLocation IvarLoc, |
| 1810 | bool IsArrow, bool IsFreeIvar) { |
| 1811 | // FIXME: We lose track of the IsFreeIvar bit. |
| 1812 | CXXScopeSpec SS; |
| 1813 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1814 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 1815 | Sema::LookupMemberName); |
| 1816 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1817 | /*FIME:*/IvarLoc, |
| 1818 | SS, DeclPtrTy()); |
| 1819 | if (Result.isInvalid()) |
| 1820 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1821 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1822 | if (Result.get()) |
| 1823 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1824 | |
| 1825 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1826 | Base->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1827 | /*FIXME:*/IvarLoc, IsArrow, SS, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1828 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1829 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1830 | /*TemplateArgs=*/0); |
| 1831 | } |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1832 | |
| 1833 | /// \brief Build a new Objective-C property reference expression. |
| 1834 | /// |
| 1835 | /// By default, performs semantic analysis to build the new expression. |
| 1836 | /// Subclasses may override this routine to provide different behavior. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1837 | OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1838 | ObjCPropertyDecl *Property, |
| 1839 | SourceLocation PropertyLoc) { |
| 1840 | CXXScopeSpec SS; |
| 1841 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1842 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 1843 | Sema::LookupMemberName); |
| 1844 | bool IsArrow = false; |
| 1845 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1846 | /*FIME:*/PropertyLoc, |
| 1847 | SS, DeclPtrTy()); |
| 1848 | if (Result.isInvalid()) |
| 1849 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1850 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1851 | if (Result.get()) |
| 1852 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1853 | |
| 1854 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1855 | Base->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1856 | /*FIXME:*/PropertyLoc, IsArrow, |
| 1857 | SS, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1858 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1859 | R, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1860 | /*TemplateArgs=*/0); |
| 1861 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1862 | |
| 1863 | /// \brief Build a new Objective-C implicit setter/getter reference |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 1864 | /// expression. |
| 1865 | /// |
| 1866 | /// By default, performs semantic analysis to build the new expression. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1867 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 1868 | OwningExprResult RebuildObjCImplicitSetterGetterRefExpr( |
| 1869 | ObjCMethodDecl *Getter, |
| 1870 | QualType T, |
| 1871 | ObjCMethodDecl *Setter, |
| 1872 | SourceLocation NameLoc, |
| 1873 | ExprArg Base) { |
| 1874 | // Since these expressions can only be value-dependent, we do not need to |
| 1875 | // perform semantic analysis again. |
| 1876 | return getSema().Owned( |
| 1877 | new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T, |
| 1878 | Setter, |
| 1879 | NameLoc, |
| 1880 | Base.takeAs<Expr>())); |
| 1881 | } |
| 1882 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1883 | /// \brief Build a new Objective-C "isa" expression. |
| 1884 | /// |
| 1885 | /// By default, performs semantic analysis to build the new expression. |
| 1886 | /// Subclasses may override this routine to provide different behavior. |
| 1887 | OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc, |
| 1888 | bool IsArrow) { |
| 1889 | CXXScopeSpec SS; |
| 1890 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1891 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 1892 | Sema::LookupMemberName); |
| 1893 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1894 | /*FIME:*/IsaLoc, |
| 1895 | SS, DeclPtrTy()); |
| 1896 | if (Result.isInvalid()) |
| 1897 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1898 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1899 | if (Result.get()) |
| 1900 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1901 | |
| 1902 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1903 | Base->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1904 | /*FIXME:*/IsaLoc, IsArrow, SS, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1905 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1906 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1907 | /*TemplateArgs=*/0); |
| 1908 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1909 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1910 | /// \brief Build a new shuffle vector expression. |
| 1911 | /// |
| 1912 | /// By default, performs semantic analysis to build the new expression. |
| 1913 | /// Subclasses may override this routine to provide different behavior. |
| 1914 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1915 | MultiExprArg SubExprs, |
| 1916 | SourceLocation RParenLoc) { |
| 1917 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1918 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1919 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1920 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1921 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1922 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1923 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1924 | // Build a reference to the __builtin_shufflevector builtin |
| 1925 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1926 | Expr *Callee |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1927 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1928 | BuiltinLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1929 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1930 | |
| 1931 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1932 | unsigned NumSubExprs = SubExprs.size(); |
| 1933 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1934 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1935 | Subs, NumSubExprs, |
| 1936 | Builtin->getResultType(), |
| 1937 | RParenLoc); |
| 1938 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1939 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1940 | // Type-check the __builtin_shufflevector expression. |
| 1941 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1942 | if (Result.isInvalid()) |
| 1943 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1944 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1945 | OwnedCall.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1946 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1947 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1948 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1949 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1950 | template<typename Derived> |
| 1951 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1952 | if (!S) |
| 1953 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1954 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1955 | switch (S->getStmtClass()) { |
| 1956 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1957 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1958 | // Transform individual statement nodes |
| 1959 | #define STMT(Node, Parent) \ |
| 1960 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1961 | #define EXPR(Node, Parent) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1962 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1963 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1964 | // Transform expressions by calling TransformExpr. |
| 1965 | #define STMT(Node, Parent) |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 1966 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1967 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1968 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1969 | { |
| 1970 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1971 | if (E.isInvalid()) |
| 1972 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1973 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1974 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1975 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1976 | } |
| 1977 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1978 | return SemaRef.Owned(S->Retain()); |
| 1979 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1980 | |
| 1981 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1982 | template<typename Derived> |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1983 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1984 | if (!E) |
| 1985 | return SemaRef.Owned(E); |
| 1986 | |
| 1987 | switch (E->getStmtClass()) { |
| 1988 | case Stmt::NoStmtClass: break; |
| 1989 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 1990 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1991 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1992 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1993 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1994 | } |
| 1995 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1996 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1997 | } |
| 1998 | |
| 1999 | template<typename Derived> |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2000 | NestedNameSpecifier * |
| 2001 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2002 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2003 | QualType ObjectType, |
| 2004 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 0979c80 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 2005 | if (!NNS) |
| 2006 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2007 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2008 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2009 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 2010 | if (Prefix) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2011 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2012 | ObjectType, |
| 2013 | FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2014 | if (!Prefix) |
| 2015 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2016 | |
| 2017 | // 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] | 2018 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2019 | ObjectType = QualType(); |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2020 | FirstQualifierInScope = 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2021 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2022 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2023 | switch (NNS->getKind()) { |
| 2024 | case NestedNameSpecifier::Identifier: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2025 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2026 | "Identifier nested-name-specifier with no prefix or object type"); |
| 2027 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 2028 | ObjectType.isNull()) |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2029 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2030 | |
| 2031 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2032 | *NNS->getAsIdentifier(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2033 | ObjectType, |
| 2034 | FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2035 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2036 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2037 | NamespaceDecl *NS |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2038 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2039 | getDerived().TransformDecl(Range.getBegin(), |
| 2040 | NNS->getAsNamespace())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2041 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2042 | Prefix == NNS->getPrefix() && |
| 2043 | NS == NNS->getAsNamespace()) |
| 2044 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2045 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2046 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 2047 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2048 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2049 | case NestedNameSpecifier::Global: |
| 2050 | // There is no meaningful transformation that one could perform on the |
| 2051 | // global scope. |
| 2052 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2053 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2054 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2055 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | fbf2c94 | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 2056 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2057 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 2058 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2059 | if (T.isNull()) |
| 2060 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2061 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2062 | if (!getDerived().AlwaysRebuild() && |
| 2063 | Prefix == NNS->getPrefix() && |
| 2064 | T == QualType(NNS->getAsType(), 0)) |
| 2065 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2066 | |
| 2067 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 2068 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 2069 | T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2070 | } |
| 2071 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2072 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2073 | // Required to silence a GCC warning |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2074 | return 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2075 | } |
| 2076 | |
| 2077 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2078 | DeclarationName |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2079 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2080 | SourceLocation Loc, |
| 2081 | QualType ObjectType) { |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2082 | if (!Name) |
| 2083 | return Name; |
| 2084 | |
| 2085 | switch (Name.getNameKind()) { |
| 2086 | case DeclarationName::Identifier: |
| 2087 | case DeclarationName::ObjCZeroArgSelector: |
| 2088 | case DeclarationName::ObjCOneArgSelector: |
| 2089 | case DeclarationName::ObjCMultiArgSelector: |
| 2090 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2091 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2092 | case DeclarationName::CXXUsingDirective: |
| 2093 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2094 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2095 | case DeclarationName::CXXConstructorName: |
| 2096 | case DeclarationName::CXXDestructorName: |
| 2097 | case DeclarationName::CXXConversionFunctionName: { |
| 2098 | TemporaryBase Rebase(*this, Loc, Name); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2099 | QualType T = getDerived().TransformType(Name.getCXXNameType(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2100 | ObjectType); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2101 | if (T.isNull()) |
| 2102 | return DeclarationName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2103 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2104 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2105 | Name.getNameKind(), |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2106 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2107 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2108 | } |
| 2109 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2110 | return DeclarationName(); |
| 2111 | } |
| 2112 | |
| 2113 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2114 | TemplateName |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2115 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 2116 | QualType ObjectType) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2117 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2118 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2119 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2120 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2121 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2122 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2123 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2124 | if (!NNS) |
| 2125 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2126 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2127 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2128 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2129 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2130 | if (!TransTemplate) |
| 2131 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2132 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2133 | if (!getDerived().AlwaysRebuild() && |
| 2134 | NNS == QTN->getQualifier() && |
| 2135 | TransTemplate == Template) |
| 2136 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2137 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2138 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 2139 | TransTemplate); |
| 2140 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2141 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2142 | // These should be getting filtered out before they make it into the AST. |
| 2143 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2144 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2145 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2146 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2147 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2148 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2149 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2150 | ObjectType); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2151 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2152 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2153 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2154 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2155 | NNS == DTN->getQualifier() && |
| 2156 | ObjectType.isNull()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2157 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2158 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2159 | if (DTN->isIdentifier()) |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2160 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2161 | ObjectType); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2162 | |
| 2163 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2164 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2165 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2166 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2167 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2168 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2169 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2170 | if (!TransTemplate) |
| 2171 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2172 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2173 | if (!getDerived().AlwaysRebuild() && |
| 2174 | TransTemplate == Template) |
| 2175 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2176 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2177 | return TemplateName(TransTemplate); |
| 2178 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2179 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2180 | // These should be getting filtered out before they reach the AST. |
| 2181 | assert(false && "overloaded function decl survived to here"); |
| 2182 | return TemplateName(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2183 | } |
| 2184 | |
| 2185 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2186 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2187 | const TemplateArgument &Arg, |
| 2188 | TemplateArgumentLoc &Output) { |
| 2189 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2190 | switch (Arg.getKind()) { |
| 2191 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2192 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2193 | break; |
| 2194 | |
| 2195 | case TemplateArgument::Type: |
| 2196 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2197 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2198 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2199 | break; |
| 2200 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2201 | case TemplateArgument::Template: |
| 2202 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 2203 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2204 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2205 | case TemplateArgument::Expression: |
| 2206 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2207 | break; |
| 2208 | |
| 2209 | case TemplateArgument::Declaration: |
| 2210 | case TemplateArgument::Integral: |
| 2211 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2212 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2213 | break; |
| 2214 | } |
| 2215 | } |
| 2216 | |
| 2217 | template<typename Derived> |
| 2218 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2219 | const TemplateArgumentLoc &Input, |
| 2220 | TemplateArgumentLoc &Output) { |
| 2221 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2222 | switch (Arg.getKind()) { |
| 2223 | case TemplateArgument::Null: |
| 2224 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2225 | Output = Input; |
| 2226 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2227 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2228 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2229 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2230 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2231 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2232 | |
| 2233 | DI = getDerived().TransformType(DI); |
| 2234 | if (!DI) return true; |
| 2235 | |
| 2236 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2237 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2238 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2239 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2240 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2241 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2242 | DeclarationName Name; |
| 2243 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2244 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2245 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2246 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2247 | if (!D) return true; |
| 2248 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2249 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2250 | if (SourceExpr) { |
| 2251 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 2252 | Action::Unevaluated); |
| 2253 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 2254 | if (E.isInvalid()) |
| 2255 | SourceExpr = NULL; |
| 2256 | else { |
| 2257 | SourceExpr = E.takeAs<Expr>(); |
| 2258 | SourceExpr->Retain(); |
| 2259 | } |
| 2260 | } |
| 2261 | |
| 2262 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2263 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2264 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2265 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2266 | case TemplateArgument::Template: { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2267 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2268 | TemplateName Template |
| 2269 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2270 | if (Template.isNull()) |
| 2271 | return true; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2272 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2273 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2274 | Input.getTemplateQualifierRange(), |
| 2275 | Input.getTemplateNameLoc()); |
| 2276 | return false; |
| 2277 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2278 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2279 | case TemplateArgument::Expression: { |
| 2280 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2281 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2282 | Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2283 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2284 | Expr *InputExpr = Input.getSourceExpression(); |
| 2285 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2286 | |
| 2287 | Sema::OwningExprResult E |
| 2288 | = getDerived().TransformExpr(InputExpr); |
| 2289 | if (E.isInvalid()) return true; |
| 2290 | |
| 2291 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2292 | ETaken->Retain(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2293 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2294 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2295 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2296 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2297 | case TemplateArgument::Pack: { |
| 2298 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2299 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2300 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2301 | AEnd = Arg.pack_end(); |
| 2302 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2303 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2304 | // FIXME: preserve source information here when we start |
| 2305 | // caring about parameter packs. |
| 2306 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2307 | TemplateArgumentLoc InputArg; |
| 2308 | TemplateArgumentLoc OutputArg; |
| 2309 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2310 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2311 | return true; |
| 2312 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2313 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2314 | } |
| 2315 | TemplateArgument Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2316 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2317 | true); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2318 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2319 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2320 | } |
| 2321 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2322 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2323 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2324 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2325 | } |
| 2326 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2327 | //===----------------------------------------------------------------------===// |
| 2328 | // Type transformation |
| 2329 | //===----------------------------------------------------------------------===// |
| 2330 | |
| 2331 | template<typename Derived> |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2332 | QualType TreeTransform<Derived>::TransformType(QualType T, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2333 | QualType ObjectType) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2334 | if (getDerived().AlreadyTransformed(T)) |
| 2335 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2336 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2337 | // Temporary workaround. All of these transformations should |
| 2338 | // eventually turn into transformations on TypeLocs. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2339 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | 4802a31 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2340 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2341 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2342 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2343 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2344 | if (!NewDI) |
| 2345 | return QualType(); |
| 2346 | |
| 2347 | return NewDI->getType(); |
| 2348 | } |
| 2349 | |
| 2350 | template<typename Derived> |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2351 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2352 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2353 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2354 | return DI; |
| 2355 | |
| 2356 | TypeLocBuilder TLB; |
| 2357 | |
| 2358 | TypeLoc TL = DI->getTypeLoc(); |
| 2359 | TLB.reserve(TL.getFullDataSize()); |
| 2360 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2361 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2362 | if (Result.isNull()) |
| 2363 | return 0; |
| 2364 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2365 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | template<typename Derived> |
| 2369 | QualType |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2370 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2371 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2372 | switch (T.getTypeLocClass()) { |
| 2373 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2374 | #define TYPELOC(CLASS, PARENT) \ |
| 2375 | case TypeLoc::CLASS: \ |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2376 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2377 | ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2378 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2379 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2380 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2381 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2382 | return QualType(); |
| 2383 | } |
| 2384 | |
| 2385 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2386 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2387 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2388 | /// types). This is the right thing for template instantiation, but |
| 2389 | /// probably not for other clients. |
| 2390 | template<typename Derived> |
| 2391 | QualType |
| 2392 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2393 | QualifiedTypeLoc T, |
| 2394 | QualType ObjectType) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2395 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2396 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2397 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2398 | ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2399 | if (Result.isNull()) |
| 2400 | return QualType(); |
| 2401 | |
| 2402 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2403 | // FIXME: this is the right thing for template instantiation, but |
| 2404 | // probably not for other clients. |
| 2405 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2406 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2407 | |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame^] | 2408 | if (!Quals.empty()) { |
| 2409 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
| 2410 | TLB.push<QualifiedTypeLoc>(Result); |
| 2411 | // No location information to preserve. |
| 2412 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2413 | |
| 2414 | return Result; |
| 2415 | } |
| 2416 | |
| 2417 | template <class TyLoc> static inline |
| 2418 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2419 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2420 | NewT.setNameLoc(T.getNameLoc()); |
| 2421 | return T.getType(); |
| 2422 | } |
| 2423 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2424 | template<typename Derived> |
| 2425 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2426 | BuiltinTypeLoc T, |
| 2427 | QualType ObjectType) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2428 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2429 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2430 | if (T.needsExtraLocalData()) |
| 2431 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2432 | return T.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2433 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2434 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2435 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2436 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2437 | ComplexTypeLoc T, |
| 2438 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2439 | // FIXME: recurse? |
| 2440 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2441 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2442 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2443 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2444 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2445 | PointerTypeLoc TL, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2446 | QualType ObjectType) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2447 | QualType PointeeType |
| 2448 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2449 | if (PointeeType.isNull()) |
| 2450 | return QualType(); |
| 2451 | |
| 2452 | QualType Result = TL.getType(); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2453 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2454 | // A dependent pointer type 'T *' has is being transformed such |
| 2455 | // that an Objective-C class type is being replaced for 'T'. The |
| 2456 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 2457 | // PointerType. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2458 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2459 | |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2460 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 2461 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2462 | return Result; |
| 2463 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2464 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2465 | if (getDerived().AlwaysRebuild() || |
| 2466 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2467 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 2468 | if (Result.isNull()) |
| 2469 | return QualType(); |
| 2470 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2471 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2472 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 2473 | NewT.setSigilLoc(TL.getSigilLoc()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2474 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2475 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2476 | |
| 2477 | template<typename Derived> |
| 2478 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2479 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2480 | BlockPointerTypeLoc TL, |
| 2481 | QualType ObjectType) { |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2482 | QualType PointeeType |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2483 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2484 | if (PointeeType.isNull()) |
| 2485 | return QualType(); |
| 2486 | |
| 2487 | QualType Result = TL.getType(); |
| 2488 | if (getDerived().AlwaysRebuild() || |
| 2489 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2490 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2491 | TL.getSigilLoc()); |
| 2492 | if (Result.isNull()) |
| 2493 | return QualType(); |
| 2494 | } |
| 2495 | |
Douglas Gregor | 39968ad | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 2496 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2497 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 2498 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2499 | } |
| 2500 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2501 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2502 | /// don't care whether the type itself is an l-value type or an r-value |
| 2503 | /// type; we only care if the type was *written* as an l-value type |
| 2504 | /// or an r-value type. |
| 2505 | template<typename Derived> |
| 2506 | QualType |
| 2507 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2508 | ReferenceTypeLoc TL, |
| 2509 | QualType ObjectType) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2510 | const ReferenceType *T = TL.getTypePtr(); |
| 2511 | |
| 2512 | // Note that this works with the pointee-as-written. |
| 2513 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2514 | if (PointeeType.isNull()) |
| 2515 | return QualType(); |
| 2516 | |
| 2517 | QualType Result = TL.getType(); |
| 2518 | if (getDerived().AlwaysRebuild() || |
| 2519 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2520 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2521 | T->isSpelledAsLValue(), |
| 2522 | TL.getSigilLoc()); |
| 2523 | if (Result.isNull()) |
| 2524 | return QualType(); |
| 2525 | } |
| 2526 | |
| 2527 | // r-value references can be rebuilt as l-value references. |
| 2528 | ReferenceTypeLoc NewTL; |
| 2529 | if (isa<LValueReferenceType>(Result)) |
| 2530 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2531 | else |
| 2532 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2533 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2534 | |
| 2535 | return Result; |
| 2536 | } |
| 2537 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2538 | template<typename Derived> |
| 2539 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2540 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2541 | LValueReferenceTypeLoc TL, |
| 2542 | QualType ObjectType) { |
| 2543 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2544 | } |
| 2545 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2546 | template<typename Derived> |
| 2547 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2548 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2549 | RValueReferenceTypeLoc TL, |
| 2550 | QualType ObjectType) { |
| 2551 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2552 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2553 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2554 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2555 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2556 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2557 | MemberPointerTypeLoc TL, |
| 2558 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2559 | MemberPointerType *T = TL.getTypePtr(); |
| 2560 | |
| 2561 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2562 | if (PointeeType.isNull()) |
| 2563 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2564 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2565 | // TODO: preserve source information for this. |
| 2566 | QualType ClassType |
| 2567 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2568 | if (ClassType.isNull()) |
| 2569 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2570 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2571 | QualType Result = TL.getType(); |
| 2572 | if (getDerived().AlwaysRebuild() || |
| 2573 | PointeeType != T->getPointeeType() || |
| 2574 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2575 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2576 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2577 | if (Result.isNull()) |
| 2578 | return QualType(); |
| 2579 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2580 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2581 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2582 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2583 | |
| 2584 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2585 | } |
| 2586 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2587 | template<typename Derived> |
| 2588 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2589 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2590 | ConstantArrayTypeLoc TL, |
| 2591 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2592 | ConstantArrayType *T = TL.getTypePtr(); |
| 2593 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2594 | if (ElementType.isNull()) |
| 2595 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2596 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2597 | QualType Result = TL.getType(); |
| 2598 | if (getDerived().AlwaysRebuild() || |
| 2599 | ElementType != T->getElementType()) { |
| 2600 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2601 | T->getSizeModifier(), |
| 2602 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2603 | T->getIndexTypeCVRQualifiers(), |
| 2604 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2605 | if (Result.isNull()) |
| 2606 | return QualType(); |
| 2607 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2608 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2609 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2610 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2611 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2612 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2613 | Expr *Size = TL.getSizeExpr(); |
| 2614 | if (Size) { |
| 2615 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2616 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2617 | } |
| 2618 | NewTL.setSizeExpr(Size); |
| 2619 | |
| 2620 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2621 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2622 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2623 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2624 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2625 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2626 | IncompleteArrayTypeLoc TL, |
| 2627 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2628 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2629 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2630 | if (ElementType.isNull()) |
| 2631 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2632 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2633 | QualType Result = TL.getType(); |
| 2634 | if (getDerived().AlwaysRebuild() || |
| 2635 | ElementType != T->getElementType()) { |
| 2636 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2637 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2638 | T->getIndexTypeCVRQualifiers(), |
| 2639 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2640 | if (Result.isNull()) |
| 2641 | return QualType(); |
| 2642 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2643 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2644 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2645 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2646 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2647 | NewTL.setSizeExpr(0); |
| 2648 | |
| 2649 | return Result; |
| 2650 | } |
| 2651 | |
| 2652 | template<typename Derived> |
| 2653 | QualType |
| 2654 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2655 | VariableArrayTypeLoc TL, |
| 2656 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2657 | VariableArrayType *T = TL.getTypePtr(); |
| 2658 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2659 | if (ElementType.isNull()) |
| 2660 | return QualType(); |
| 2661 | |
| 2662 | // Array bounds are not potentially evaluated contexts |
| 2663 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2664 | |
| 2665 | Sema::OwningExprResult SizeResult |
| 2666 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2667 | if (SizeResult.isInvalid()) |
| 2668 | return QualType(); |
| 2669 | |
| 2670 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2671 | |
| 2672 | QualType Result = TL.getType(); |
| 2673 | if (getDerived().AlwaysRebuild() || |
| 2674 | ElementType != T->getElementType() || |
| 2675 | Size != T->getSizeExpr()) { |
| 2676 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2677 | T->getSizeModifier(), |
| 2678 | move(SizeResult), |
| 2679 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2680 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2681 | if (Result.isNull()) |
| 2682 | return QualType(); |
| 2683 | } |
| 2684 | else SizeResult.take(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2685 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2686 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2687 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2688 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2689 | NewTL.setSizeExpr(Size); |
| 2690 | |
| 2691 | return Result; |
| 2692 | } |
| 2693 | |
| 2694 | template<typename Derived> |
| 2695 | QualType |
| 2696 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2697 | DependentSizedArrayTypeLoc TL, |
| 2698 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2699 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2700 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2701 | if (ElementType.isNull()) |
| 2702 | return QualType(); |
| 2703 | |
| 2704 | // Array bounds are not potentially evaluated contexts |
| 2705 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2706 | |
| 2707 | Sema::OwningExprResult SizeResult |
| 2708 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2709 | if (SizeResult.isInvalid()) |
| 2710 | return QualType(); |
| 2711 | |
| 2712 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2713 | |
| 2714 | QualType Result = TL.getType(); |
| 2715 | if (getDerived().AlwaysRebuild() || |
| 2716 | ElementType != T->getElementType() || |
| 2717 | Size != T->getSizeExpr()) { |
| 2718 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2719 | T->getSizeModifier(), |
| 2720 | move(SizeResult), |
| 2721 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2722 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2723 | if (Result.isNull()) |
| 2724 | return QualType(); |
| 2725 | } |
| 2726 | else SizeResult.take(); |
| 2727 | |
| 2728 | // We might have any sort of array type now, but fortunately they |
| 2729 | // all have the same location layout. |
| 2730 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2731 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2732 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2733 | NewTL.setSizeExpr(Size); |
| 2734 | |
| 2735 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2736 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2737 | |
| 2738 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2739 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2740 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2741 | DependentSizedExtVectorTypeLoc TL, |
| 2742 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2743 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2744 | |
| 2745 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2746 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2747 | if (ElementType.isNull()) |
| 2748 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2749 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2750 | // Vector sizes are not potentially evaluated contexts |
| 2751 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2752 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2753 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2754 | if (Size.isInvalid()) |
| 2755 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2756 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2757 | QualType Result = TL.getType(); |
| 2758 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2759 | ElementType != T->getElementType() || |
| 2760 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2761 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2762 | move(Size), |
| 2763 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2764 | if (Result.isNull()) |
| 2765 | return QualType(); |
| 2766 | } |
| 2767 | else Size.take(); |
| 2768 | |
| 2769 | // Result might be dependent or not. |
| 2770 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2771 | DependentSizedExtVectorTypeLoc NewTL |
| 2772 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2773 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2774 | } else { |
| 2775 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2776 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2777 | } |
| 2778 | |
| 2779 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2780 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2781 | |
| 2782 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2783 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2784 | VectorTypeLoc TL, |
| 2785 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2786 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2787 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2788 | if (ElementType.isNull()) |
| 2789 | return QualType(); |
| 2790 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2791 | QualType Result = TL.getType(); |
| 2792 | if (getDerived().AlwaysRebuild() || |
| 2793 | ElementType != T->getElementType()) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2794 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 2795 | T->isAltiVec(), T->isPixel()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2796 | if (Result.isNull()) |
| 2797 | return QualType(); |
| 2798 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2799 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2800 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2801 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2802 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2803 | return Result; |
| 2804 | } |
| 2805 | |
| 2806 | template<typename Derived> |
| 2807 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2808 | ExtVectorTypeLoc TL, |
| 2809 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2810 | VectorType *T = TL.getTypePtr(); |
| 2811 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2812 | if (ElementType.isNull()) |
| 2813 | return QualType(); |
| 2814 | |
| 2815 | QualType Result = TL.getType(); |
| 2816 | if (getDerived().AlwaysRebuild() || |
| 2817 | ElementType != T->getElementType()) { |
| 2818 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2819 | T->getNumElements(), |
| 2820 | /*FIXME*/ SourceLocation()); |
| 2821 | if (Result.isNull()) |
| 2822 | return QualType(); |
| 2823 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2824 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2825 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2826 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2827 | |
| 2828 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2829 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2830 | |
| 2831 | template<typename Derived> |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2832 | ParmVarDecl * |
| 2833 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) { |
| 2834 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| 2835 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
| 2836 | if (!NewDI) |
| 2837 | return 0; |
| 2838 | |
| 2839 | if (NewDI == OldDI) |
| 2840 | return OldParm; |
| 2841 | else |
| 2842 | return ParmVarDecl::Create(SemaRef.Context, |
| 2843 | OldParm->getDeclContext(), |
| 2844 | OldParm->getLocation(), |
| 2845 | OldParm->getIdentifier(), |
| 2846 | NewDI->getType(), |
| 2847 | NewDI, |
| 2848 | OldParm->getStorageClass(), |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 2849 | OldParm->getStorageClassAsWritten(), |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2850 | /* DefArg */ NULL); |
| 2851 | } |
| 2852 | |
| 2853 | template<typename Derived> |
| 2854 | bool TreeTransform<Derived>:: |
| 2855 | TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 2856 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 2857 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars) { |
| 2858 | FunctionProtoType *T = TL.getTypePtr(); |
| 2859 | |
| 2860 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2861 | ParmVarDecl *OldParm = TL.getArg(i); |
| 2862 | |
| 2863 | QualType NewType; |
| 2864 | ParmVarDecl *NewParm; |
| 2865 | |
| 2866 | if (OldParm) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2867 | NewParm = getDerived().TransformFunctionTypeParam(OldParm); |
| 2868 | if (!NewParm) |
| 2869 | return true; |
| 2870 | NewType = NewParm->getType(); |
| 2871 | |
| 2872 | // Deal with the possibility that we don't have a parameter |
| 2873 | // declaration for this parameter. |
| 2874 | } else { |
| 2875 | NewParm = 0; |
| 2876 | |
| 2877 | QualType OldType = T->getArgType(i); |
| 2878 | NewType = getDerived().TransformType(OldType); |
| 2879 | if (NewType.isNull()) |
| 2880 | return true; |
| 2881 | } |
| 2882 | |
| 2883 | PTypes.push_back(NewType); |
| 2884 | PVars.push_back(NewParm); |
| 2885 | } |
| 2886 | |
| 2887 | return false; |
| 2888 | } |
| 2889 | |
| 2890 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2891 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2892 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2893 | FunctionProtoTypeLoc TL, |
| 2894 | QualType ObjectType) { |
Douglas Gregor | 895162d | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2895 | // Transform the parameters. We do this first for the benefit of template |
| 2896 | // instantiations, so that the ParmVarDecls get/ placed into the template |
| 2897 | // instantiation scope before we transform the function type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2898 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2899 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2900 | if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls)) |
| 2901 | return QualType(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2902 | |
Douglas Gregor | 895162d | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2903 | FunctionProtoType *T = TL.getTypePtr(); |
| 2904 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2905 | if (ResultType.isNull()) |
| 2906 | return QualType(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2907 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2908 | QualType Result = TL.getType(); |
| 2909 | if (getDerived().AlwaysRebuild() || |
| 2910 | ResultType != T->getResultType() || |
| 2911 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2912 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2913 | ParamTypes.data(), |
| 2914 | ParamTypes.size(), |
| 2915 | T->isVariadic(), |
| 2916 | T->getTypeQuals()); |
| 2917 | if (Result.isNull()) |
| 2918 | return QualType(); |
| 2919 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2920 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2921 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2922 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2923 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2924 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2925 | NewTL.setArg(i, ParamDecls[i]); |
| 2926 | |
| 2927 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2928 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2929 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2930 | template<typename Derived> |
| 2931 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2932 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2933 | FunctionNoProtoTypeLoc TL, |
| 2934 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2935 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2936 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2937 | if (ResultType.isNull()) |
| 2938 | return QualType(); |
| 2939 | |
| 2940 | QualType Result = TL.getType(); |
| 2941 | if (getDerived().AlwaysRebuild() || |
| 2942 | ResultType != T->getResultType()) |
| 2943 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2944 | |
| 2945 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2946 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2947 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2948 | |
| 2949 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2950 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2951 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2952 | template<typename Derived> QualType |
| 2953 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2954 | UnresolvedUsingTypeLoc TL, |
| 2955 | QualType ObjectType) { |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2956 | UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2957 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2958 | if (!D) |
| 2959 | return QualType(); |
| 2960 | |
| 2961 | QualType Result = TL.getType(); |
| 2962 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2963 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2964 | if (Result.isNull()) |
| 2965 | return QualType(); |
| 2966 | } |
| 2967 | |
| 2968 | // We might get an arbitrary type spec type back. We should at |
| 2969 | // least always get a type spec type, though. |
| 2970 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2971 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2972 | |
| 2973 | return Result; |
| 2974 | } |
| 2975 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2976 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2977 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2978 | TypedefTypeLoc TL, |
| 2979 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2980 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2981 | TypedefDecl *Typedef |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2982 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2983 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2984 | if (!Typedef) |
| 2985 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2986 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2987 | QualType Result = TL.getType(); |
| 2988 | if (getDerived().AlwaysRebuild() || |
| 2989 | Typedef != T->getDecl()) { |
| 2990 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2991 | if (Result.isNull()) |
| 2992 | return QualType(); |
| 2993 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2994 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2995 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2996 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2997 | |
| 2998 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2999 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3000 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3001 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3002 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3003 | TypeOfExprTypeLoc TL, |
| 3004 | QualType ObjectType) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3005 | // typeof expressions are not potentially evaluated contexts |
| 3006 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3007 | |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3008 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3009 | if (E.isInvalid()) |
| 3010 | return QualType(); |
| 3011 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3012 | QualType Result = TL.getType(); |
| 3013 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3014 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3015 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 3016 | if (Result.isNull()) |
| 3017 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3018 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3019 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3020 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3021 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3022 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3023 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3024 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3025 | |
| 3026 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3027 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3028 | |
| 3029 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3030 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3031 | TypeOfTypeLoc TL, |
| 3032 | QualType ObjectType) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3033 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 3034 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 3035 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3036 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3037 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3038 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3039 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 3040 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3041 | if (Result.isNull()) |
| 3042 | return QualType(); |
| 3043 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3044 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3045 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3046 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3047 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3048 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 3049 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3050 | |
| 3051 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3052 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3053 | |
| 3054 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3055 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3056 | DecltypeTypeLoc TL, |
| 3057 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3058 | DecltypeType *T = TL.getTypePtr(); |
| 3059 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3060 | // decltype expressions are not potentially evaluated contexts |
| 3061 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3062 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3063 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 3064 | if (E.isInvalid()) |
| 3065 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3066 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3067 | QualType Result = TL.getType(); |
| 3068 | if (getDerived().AlwaysRebuild() || |
| 3069 | E.get() != T->getUnderlyingExpr()) { |
| 3070 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 3071 | if (Result.isNull()) |
| 3072 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3073 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3074 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3075 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3076 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 3077 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3078 | |
| 3079 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3080 | } |
| 3081 | |
| 3082 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3083 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3084 | RecordTypeLoc TL, |
| 3085 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3086 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3087 | RecordDecl *Record |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3088 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3089 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3090 | if (!Record) |
| 3091 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3092 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3093 | QualType Result = TL.getType(); |
| 3094 | if (getDerived().AlwaysRebuild() || |
| 3095 | Record != T->getDecl()) { |
| 3096 | Result = getDerived().RebuildRecordType(Record); |
| 3097 | if (Result.isNull()) |
| 3098 | return QualType(); |
| 3099 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3100 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3101 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 3102 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3103 | |
| 3104 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3105 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3106 | |
| 3107 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3108 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3109 | EnumTypeLoc TL, |
| 3110 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3111 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3112 | EnumDecl *Enum |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3113 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3114 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3115 | if (!Enum) |
| 3116 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3117 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3118 | QualType Result = TL.getType(); |
| 3119 | if (getDerived().AlwaysRebuild() || |
| 3120 | Enum != T->getDecl()) { |
| 3121 | Result = getDerived().RebuildEnumType(Enum); |
| 3122 | if (Result.isNull()) |
| 3123 | return QualType(); |
| 3124 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3125 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3126 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 3127 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3128 | |
| 3129 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3130 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3131 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3132 | template<typename Derived> |
| 3133 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 3134 | TypeLocBuilder &TLB, |
| 3135 | InjectedClassNameTypeLoc TL, |
| 3136 | QualType ObjectType) { |
| 3137 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 3138 | TL.getTypePtr()->getDecl()); |
| 3139 | if (!D) return QualType(); |
| 3140 | |
| 3141 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 3142 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 3143 | return T; |
| 3144 | } |
| 3145 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3146 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3147 | template<typename Derived> |
| 3148 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3149 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3150 | TemplateTypeParmTypeLoc TL, |
| 3151 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3152 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3153 | } |
| 3154 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3155 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3156 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3157 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3158 | SubstTemplateTypeParmTypeLoc TL, |
| 3159 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3160 | return TransformTypeSpecType(TLB, TL); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3161 | } |
| 3162 | |
| 3163 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3164 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 3165 | const TemplateSpecializationType *TST, |
| 3166 | QualType ObjectType) { |
| 3167 | // FIXME: this entire method is a temporary workaround; callers |
| 3168 | // should be rewritten to provide real type locs. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3169 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3170 | // Fake up a TemplateSpecializationTypeLoc. |
| 3171 | TypeLocBuilder TLB; |
| 3172 | TemplateSpecializationTypeLoc TL |
| 3173 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 3174 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3175 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 3176 | |
| 3177 | TL.setTemplateNameLoc(BaseLoc); |
| 3178 | TL.setLAngleLoc(BaseLoc); |
| 3179 | TL.setRAngleLoc(BaseLoc); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3180 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 3181 | const TemplateArgument &TA = TST->getArg(i); |
| 3182 | TemplateArgumentLoc TAL; |
| 3183 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 3184 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 3185 | } |
| 3186 | |
| 3187 | TypeLocBuilder IgnoredTLB; |
| 3188 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3189 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3190 | |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3191 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3192 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3193 | TypeLocBuilder &TLB, |
| 3194 | TemplateSpecializationTypeLoc TL, |
| 3195 | QualType ObjectType) { |
| 3196 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 3197 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3198 | TemplateName Template |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3199 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3200 | if (Template.isNull()) |
| 3201 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3202 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3203 | TemplateArgumentListInfo NewTemplateArgs; |
| 3204 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 3205 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 3206 | |
| 3207 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 3208 | TemplateArgumentLoc Loc; |
| 3209 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3210 | return QualType(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3211 | NewTemplateArgs.addArgument(Loc); |
| 3212 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3213 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3214 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 3215 | |
| 3216 | QualType Result = |
| 3217 | getDerived().RebuildTemplateSpecializationType(Template, |
| 3218 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3219 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3220 | |
| 3221 | if (!Result.isNull()) { |
| 3222 | TemplateSpecializationTypeLoc NewTL |
| 3223 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 3224 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 3225 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 3226 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 3227 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 3228 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3229 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3230 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3231 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3232 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3233 | |
| 3234 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3235 | QualType |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3236 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 3237 | ElaboratedTypeLoc TL, |
| 3238 | QualType ObjectType) { |
| 3239 | ElaboratedType *T = TL.getTypePtr(); |
| 3240 | |
| 3241 | NestedNameSpecifier *NNS = 0; |
| 3242 | // NOTE: the qualifier in an ElaboratedType is optional. |
| 3243 | if (T->getQualifier() != 0) { |
| 3244 | NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3245 | TL.getQualifierRange(), |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3246 | ObjectType); |
| 3247 | if (!NNS) |
| 3248 | return QualType(); |
| 3249 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3250 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3251 | QualType NamedT; |
| 3252 | // FIXME: this test is meant to workaround a problem (failing assertion) |
| 3253 | // occurring if directly executing the code in the else branch. |
| 3254 | if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) { |
| 3255 | TemplateSpecializationTypeLoc OldNamedTL |
| 3256 | = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc()); |
| 3257 | const TemplateSpecializationType* OldTST |
Jim Grosbach | 9cbb4d8 | 2010-05-19 23:53:08 +0000 | [diff] [blame] | 3258 | = OldNamedTL.getType()->template getAs<TemplateSpecializationType>(); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3259 | NamedT = TransformTemplateSpecializationType(OldTST, ObjectType); |
| 3260 | if (NamedT.isNull()) |
| 3261 | return QualType(); |
| 3262 | TemplateSpecializationTypeLoc NewNamedTL |
| 3263 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| 3264 | NewNamedTL.copy(OldNamedTL); |
| 3265 | } |
| 3266 | else { |
| 3267 | NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 3268 | if (NamedT.isNull()) |
| 3269 | return QualType(); |
| 3270 | } |
Daniel Dunbar | a63db84 | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 3271 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3272 | QualType Result = TL.getType(); |
| 3273 | if (getDerived().AlwaysRebuild() || |
| 3274 | NNS != T->getQualifier() || |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3275 | NamedT != T->getNamedType()) { |
| 3276 | Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3277 | if (Result.isNull()) |
| 3278 | return QualType(); |
| 3279 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3280 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3281 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3282 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 3283 | NewTL.setQualifierRange(TL.getQualifierRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3284 | |
| 3285 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3286 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3287 | |
| 3288 | template<typename Derived> |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3289 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
| 3290 | DependentNameTypeLoc TL, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3291 | QualType ObjectType) { |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3292 | DependentNameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3293 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3294 | NestedNameSpecifier *NNS |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3295 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 3296 | TL.getQualifierRange(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3297 | ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3298 | if (!NNS) |
| 3299 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3300 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3301 | QualType Result; |
| 3302 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3303 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3304 | QualType NewTemplateId |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3305 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 3306 | if (NewTemplateId.isNull()) |
| 3307 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3308 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3309 | if (!getDerived().AlwaysRebuild() && |
| 3310 | NNS == T->getQualifier() && |
| 3311 | NewTemplateId == QualType(TemplateId, 0)) |
| 3312 | return QualType(T, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3313 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3314 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3315 | NewTemplateId); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3316 | } else { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3317 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 3318 | T->getIdentifier(), |
| 3319 | TL.getKeywordLoc(), |
| 3320 | TL.getQualifierRange(), |
| 3321 | TL.getNameLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3322 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3323 | if (Result.isNull()) |
| 3324 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3325 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3326 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 3327 | QualType NamedT = ElabT->getNamedType(); |
| 3328 | if (isa<TemplateSpecializationType>(NamedT)) { |
| 3329 | TemplateSpecializationTypeLoc NamedTLoc |
| 3330 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| 3331 | // FIXME: fill locations |
| 3332 | NamedTLoc.initializeLocal(TL.getNameLoc()); |
| 3333 | } else { |
| 3334 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 3335 | } |
| 3336 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 3337 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 3338 | NewTL.setQualifierRange(TL.getQualifierRange()); |
| 3339 | } |
| 3340 | else { |
| 3341 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
| 3342 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 3343 | NewTL.setQualifierRange(TL.getQualifierRange()); |
| 3344 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3345 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3346 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3347 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3348 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3349 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3350 | QualType |
| 3351 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3352 | ObjCInterfaceTypeLoc TL, |
| 3353 | QualType ObjectType) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3354 | // ObjCInterfaceType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3355 | TLB.pushFullCopy(TL); |
| 3356 | return TL.getType(); |
| 3357 | } |
| 3358 | |
| 3359 | template<typename Derived> |
| 3360 | QualType |
| 3361 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
| 3362 | ObjCObjectTypeLoc TL, |
| 3363 | QualType ObjectType) { |
| 3364 | // ObjCObjectType is never dependent. |
| 3365 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3366 | return TL.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3367 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3368 | |
| 3369 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3370 | QualType |
| 3371 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3372 | ObjCObjectPointerTypeLoc TL, |
| 3373 | QualType ObjectType) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3374 | // ObjCObjectPointerType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3375 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3376 | return TL.getType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3377 | } |
| 3378 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3379 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3380 | // Statement transformation |
| 3381 | //===----------------------------------------------------------------------===// |
| 3382 | template<typename Derived> |
| 3383 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3384 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3385 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3386 | } |
| 3387 | |
| 3388 | template<typename Derived> |
| 3389 | Sema::OwningStmtResult |
| 3390 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3391 | return getDerived().TransformCompoundStmt(S, false); |
| 3392 | } |
| 3393 | |
| 3394 | template<typename Derived> |
| 3395 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3396 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3397 | bool IsStmtExpr) { |
| 3398 | bool SubStmtChanged = false; |
| 3399 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3400 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3401 | B != BEnd; ++B) { |
| 3402 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3403 | if (Result.isInvalid()) |
| 3404 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3405 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3406 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3407 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3408 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3409 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3410 | if (!getDerived().AlwaysRebuild() && |
| 3411 | !SubStmtChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3412 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3413 | |
| 3414 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3415 | move_arg(Statements), |
| 3416 | S->getRBracLoc(), |
| 3417 | IsStmtExpr); |
| 3418 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3419 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3420 | template<typename Derived> |
| 3421 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3422 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3423 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3424 | { |
| 3425 | // The case value expressions are not potentially evaluated. |
| 3426 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3427 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3428 | // Transform the left-hand case value. |
| 3429 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3430 | if (LHS.isInvalid()) |
| 3431 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3432 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3433 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3434 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3435 | if (RHS.isInvalid()) |
| 3436 | return SemaRef.StmtError(); |
| 3437 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3438 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3439 | // Build the case statement. |
| 3440 | // Case statements are always rebuilt so that they will attached to their |
| 3441 | // transformed switch statement. |
| 3442 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3443 | move(LHS), |
| 3444 | S->getEllipsisLoc(), |
| 3445 | move(RHS), |
| 3446 | S->getColonLoc()); |
| 3447 | if (Case.isInvalid()) |
| 3448 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3449 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3450 | // Transform the statement following the case |
| 3451 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3452 | if (SubStmt.isInvalid()) |
| 3453 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3454 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3455 | // Attach the body to the case statement |
| 3456 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3457 | } |
| 3458 | |
| 3459 | template<typename Derived> |
| 3460 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3461 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3462 | // Transform the statement following the default case |
| 3463 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3464 | if (SubStmt.isInvalid()) |
| 3465 | return SemaRef.StmtError(); |
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 | // Default statements are always rebuilt |
| 3468 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3469 | move(SubStmt)); |
| 3470 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3471 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3472 | template<typename Derived> |
| 3473 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3474 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3475 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3476 | if (SubStmt.isInvalid()) |
| 3477 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3478 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3479 | // FIXME: Pass the real colon location in. |
| 3480 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3481 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3482 | move(SubStmt)); |
| 3483 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3484 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3485 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3486 | Sema::OwningStmtResult |
| 3487 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3488 | // Transform the condition |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3489 | OwningExprResult Cond(SemaRef); |
| 3490 | VarDecl *ConditionVar = 0; |
| 3491 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3492 | ConditionVar |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3493 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3494 | getDerived().TransformDefinition( |
| 3495 | S->getConditionVariable()->getLocation(), |
| 3496 | S->getConditionVariable())); |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3497 | if (!ConditionVar) |
| 3498 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3499 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3500 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3501 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3502 | if (Cond.isInvalid()) |
| 3503 | return SemaRef.StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3504 | |
| 3505 | // Convert the condition to a boolean value. |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3506 | if (S->getCond()) { |
| 3507 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
| 3508 | S->getIfLoc(), |
| 3509 | move(Cond)); |
| 3510 | if (CondE.isInvalid()) |
| 3511 | return getSema().StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3512 | |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3513 | Cond = move(CondE); |
| 3514 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3515 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3516 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3517 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3518 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3519 | return SemaRef.StmtError(); |
| 3520 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3521 | // Transform the "then" branch. |
| 3522 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3523 | if (Then.isInvalid()) |
| 3524 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3525 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3526 | // Transform the "else" branch. |
| 3527 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3528 | if (Else.isInvalid()) |
| 3529 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3530 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3531 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3532 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3533 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3534 | Then.get() == S->getThen() && |
| 3535 | Else.get() == S->getElse()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3536 | return SemaRef.Owned(S->Retain()); |
| 3537 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3538 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3539 | move(Then), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3540 | S->getElseLoc(), move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3541 | } |
| 3542 | |
| 3543 | template<typename Derived> |
| 3544 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3545 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3546 | // Transform the condition. |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3547 | OwningExprResult Cond(SemaRef); |
| 3548 | VarDecl *ConditionVar = 0; |
| 3549 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3550 | ConditionVar |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3551 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3552 | getDerived().TransformDefinition( |
| 3553 | S->getConditionVariable()->getLocation(), |
| 3554 | S->getConditionVariable())); |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3555 | if (!ConditionVar) |
| 3556 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3557 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3558 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3559 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3560 | if (Cond.isInvalid()) |
| 3561 | return SemaRef.StmtError(); |
| 3562 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3563 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3564 | // Rebuild the switch statement. |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 3565 | OwningStmtResult Switch |
| 3566 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond), |
| 3567 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3568 | if (Switch.isInvalid()) |
| 3569 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3570 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3571 | // Transform the body of the switch statement. |
| 3572 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3573 | if (Body.isInvalid()) |
| 3574 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3575 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3576 | // Complete the switch statement. |
| 3577 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3578 | move(Body)); |
| 3579 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3580 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3581 | template<typename Derived> |
| 3582 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3583 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3584 | // Transform the condition |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3585 | OwningExprResult Cond(SemaRef); |
| 3586 | VarDecl *ConditionVar = 0; |
| 3587 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3588 | ConditionVar |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3589 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3590 | getDerived().TransformDefinition( |
| 3591 | S->getConditionVariable()->getLocation(), |
| 3592 | S->getConditionVariable())); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3593 | if (!ConditionVar) |
| 3594 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3595 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3596 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3597 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3598 | if (Cond.isInvalid()) |
| 3599 | return SemaRef.StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3600 | |
| 3601 | if (S->getCond()) { |
| 3602 | // Convert the condition to a boolean value. |
| 3603 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3604 | S->getWhileLoc(), |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3605 | move(Cond)); |
| 3606 | if (CondE.isInvalid()) |
| 3607 | return getSema().StmtError(); |
| 3608 | Cond = move(CondE); |
| 3609 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3610 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3611 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3612 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3613 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3614 | return SemaRef.StmtError(); |
| 3615 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3616 | // Transform the body |
| 3617 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3618 | if (Body.isInvalid()) |
| 3619 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3620 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3621 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3622 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3623 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3624 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3625 | return SemaRef.Owned(S->Retain()); |
| 3626 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3627 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 3628 | ConditionVar, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3629 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3630 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3631 | template<typename Derived> |
| 3632 | Sema::OwningStmtResult |
| 3633 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3634 | // Transform the body |
| 3635 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3636 | if (Body.isInvalid()) |
| 3637 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3638 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3639 | // Transform the condition |
| 3640 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3641 | if (Cond.isInvalid()) |
| 3642 | return SemaRef.StmtError(); |
| 3643 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3644 | if (!getDerived().AlwaysRebuild() && |
| 3645 | Cond.get() == S->getCond() && |
| 3646 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3647 | return SemaRef.Owned(S->Retain()); |
| 3648 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3649 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3650 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3651 | S->getRParenLoc()); |
| 3652 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3653 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3654 | template<typename Derived> |
| 3655 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3656 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3657 | // Transform the initialization statement |
| 3658 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3659 | if (Init.isInvalid()) |
| 3660 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3661 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3662 | // Transform the condition |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3663 | OwningExprResult Cond(SemaRef); |
| 3664 | VarDecl *ConditionVar = 0; |
| 3665 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3666 | ConditionVar |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3667 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3668 | getDerived().TransformDefinition( |
| 3669 | S->getConditionVariable()->getLocation(), |
| 3670 | S->getConditionVariable())); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3671 | if (!ConditionVar) |
| 3672 | return SemaRef.StmtError(); |
| 3673 | } else { |
| 3674 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3675 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3676 | if (Cond.isInvalid()) |
| 3677 | return SemaRef.StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3678 | |
| 3679 | if (S->getCond()) { |
| 3680 | // Convert the condition to a boolean value. |
| 3681 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
| 3682 | S->getForLoc(), |
| 3683 | move(Cond)); |
| 3684 | if (CondE.isInvalid()) |
| 3685 | return getSema().StmtError(); |
| 3686 | |
| 3687 | Cond = move(CondE); |
| 3688 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3689 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3690 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3691 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3692 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3693 | return SemaRef.StmtError(); |
| 3694 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3695 | // Transform the increment |
| 3696 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3697 | if (Inc.isInvalid()) |
| 3698 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3699 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3700 | Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc)); |
| 3701 | if (S->getInc() && !FullInc->get()) |
| 3702 | return SemaRef.StmtError(); |
| 3703 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3704 | // Transform the body |
| 3705 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3706 | if (Body.isInvalid()) |
| 3707 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3708 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3709 | if (!getDerived().AlwaysRebuild() && |
| 3710 | Init.get() == S->getInit() && |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3711 | FullCond->get() == S->getCond() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3712 | Inc.get() == S->getInc() && |
| 3713 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3714 | return SemaRef.Owned(S->Retain()); |
| 3715 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3716 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3717 | move(Init), FullCond, ConditionVar, |
| 3718 | FullInc, S->getRParenLoc(), move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3719 | } |
| 3720 | |
| 3721 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3722 | Sema::OwningStmtResult |
| 3723 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3724 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3725 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3726 | S->getLabel()); |
| 3727 | } |
| 3728 | |
| 3729 | template<typename Derived> |
| 3730 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3731 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3732 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3733 | if (Target.isInvalid()) |
| 3734 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3735 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3736 | if (!getDerived().AlwaysRebuild() && |
| 3737 | Target.get() == S->getTarget()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3738 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3739 | |
| 3740 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3741 | move(Target)); |
| 3742 | } |
| 3743 | |
| 3744 | template<typename Derived> |
| 3745 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3746 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3747 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3748 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3749 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3750 | template<typename Derived> |
| 3751 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3752 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3753 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3754 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3755 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3756 | template<typename Derived> |
| 3757 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3758 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3759 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3760 | if (Result.isInvalid()) |
| 3761 | return SemaRef.StmtError(); |
| 3762 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3763 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3764 | // to tell whether the return type of the function has changed. |
| 3765 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3766 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3767 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3768 | template<typename Derived> |
| 3769 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3770 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3771 | bool DeclChanged = false; |
| 3772 | llvm::SmallVector<Decl *, 4> Decls; |
| 3773 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3774 | D != DEnd; ++D) { |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3775 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 3776 | *D); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3777 | if (!Transformed) |
| 3778 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3779 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3780 | if (Transformed != *D) |
| 3781 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3782 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3783 | Decls.push_back(Transformed); |
| 3784 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3785 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3786 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3787 | return SemaRef.Owned(S->Retain()); |
| 3788 | |
| 3789 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3790 | S->getStartLoc(), S->getEndLoc()); |
| 3791 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3792 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3793 | template<typename Derived> |
| 3794 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3795 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3796 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3797 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | template<typename Derived> |
| 3801 | Sema::OwningStmtResult |
| 3802 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3803 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3804 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3805 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3806 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3807 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3808 | OwningExprResult AsmString(SemaRef); |
| 3809 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3810 | |
| 3811 | bool ExprsChanged = false; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3812 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3813 | // Go through the outputs. |
| 3814 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3815 | Names.push_back(S->getOutputIdentifier(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3816 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3817 | // No need to transform the constraint literal. |
| 3818 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3819 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3820 | // Transform the output expr. |
| 3821 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3822 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3823 | if (Result.isInvalid()) |
| 3824 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3825 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3826 | ExprsChanged |= Result.get() != OutputExpr; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3827 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3828 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3829 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3830 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3831 | // Go through the inputs. |
| 3832 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3833 | Names.push_back(S->getInputIdentifier(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3834 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3835 | // No need to transform the constraint literal. |
| 3836 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3837 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3838 | // Transform the input expr. |
| 3839 | Expr *InputExpr = S->getInputExpr(I); |
| 3840 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3841 | if (Result.isInvalid()) |
| 3842 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3843 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3844 | ExprsChanged |= Result.get() != InputExpr; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3845 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3846 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3847 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3848 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3849 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3850 | return SemaRef.Owned(S->Retain()); |
| 3851 | |
| 3852 | // Go through the clobbers. |
| 3853 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3854 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3855 | |
| 3856 | // No need to transform the asm string literal. |
| 3857 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3858 | |
| 3859 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3860 | S->isSimple(), |
| 3861 | S->isVolatile(), |
| 3862 | S->getNumOutputs(), |
| 3863 | S->getNumInputs(), |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3864 | Names.data(), |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3865 | move_arg(Constraints), |
| 3866 | move_arg(Exprs), |
| 3867 | move(AsmString), |
| 3868 | move_arg(Clobbers), |
| 3869 | S->getRParenLoc(), |
| 3870 | S->isMSAsm()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3871 | } |
| 3872 | |
| 3873 | |
| 3874 | template<typename Derived> |
| 3875 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3876 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3877 | // Transform the body of the @try. |
| 3878 | OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
| 3879 | if (TryBody.isInvalid()) |
| 3880 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3881 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3882 | // Transform the @catch statements (if present). |
| 3883 | bool AnyCatchChanged = false; |
| 3884 | ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef); |
| 3885 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
| 3886 | OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3887 | if (Catch.isInvalid()) |
| 3888 | return SemaRef.StmtError(); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3889 | if (Catch.get() != S->getCatchStmt(I)) |
| 3890 | AnyCatchChanged = true; |
| 3891 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3892 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3893 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3894 | // Transform the @finally statement (if present). |
| 3895 | OwningStmtResult Finally(SemaRef); |
| 3896 | if (S->getFinallyStmt()) { |
| 3897 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 3898 | if (Finally.isInvalid()) |
| 3899 | return SemaRef.StmtError(); |
| 3900 | } |
| 3901 | |
| 3902 | // If nothing changed, just retain this statement. |
| 3903 | if (!getDerived().AlwaysRebuild() && |
| 3904 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3905 | !AnyCatchChanged && |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3906 | Finally.get() == S->getFinallyStmt()) |
| 3907 | return SemaRef.Owned(S->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3908 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3909 | // Build a new statement. |
| 3910 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody), |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3911 | move_arg(CatchStmts), move(Finally)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3912 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3913 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3914 | template<typename Derived> |
| 3915 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3916 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3917 | // Transform the @catch parameter, if there is one. |
| 3918 | VarDecl *Var = 0; |
| 3919 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 3920 | TypeSourceInfo *TSInfo = 0; |
| 3921 | if (FromVar->getTypeSourceInfo()) { |
| 3922 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 3923 | if (!TSInfo) |
| 3924 | return SemaRef.StmtError(); |
| 3925 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3926 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3927 | QualType T; |
| 3928 | if (TSInfo) |
| 3929 | T = TSInfo->getType(); |
| 3930 | else { |
| 3931 | T = getDerived().TransformType(FromVar->getType()); |
| 3932 | if (T.isNull()) |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3933 | return SemaRef.StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3934 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3935 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3936 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 3937 | if (!Var) |
| 3938 | return SemaRef.StmtError(); |
| 3939 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3940 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3941 | OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
| 3942 | if (Body.isInvalid()) |
| 3943 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3944 | |
| 3945 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3946 | S->getRParenLoc(), |
| 3947 | Var, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3948 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3949 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3950 | template<typename Derived> |
| 3951 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3952 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3953 | // Transform the body. |
| 3954 | OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
| 3955 | if (Body.isInvalid()) |
| 3956 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3957 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3958 | // If nothing changed, just retain this statement. |
| 3959 | if (!getDerived().AlwaysRebuild() && |
| 3960 | Body.get() == S->getFinallyBody()) |
| 3961 | return SemaRef.Owned(S->Retain()); |
| 3962 | |
| 3963 | // Build a new statement. |
| 3964 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
| 3965 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3966 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3967 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3968 | template<typename Derived> |
| 3969 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3970 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 3971 | OwningExprResult Operand(SemaRef); |
| 3972 | if (S->getThrowExpr()) { |
| 3973 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 3974 | if (Operand.isInvalid()) |
| 3975 | return getSema().StmtError(); |
| 3976 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3977 | |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 3978 | if (!getDerived().AlwaysRebuild() && |
| 3979 | Operand.get() == S->getThrowExpr()) |
| 3980 | return getSema().Owned(S->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3981 | |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 3982 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3983 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3984 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3985 | template<typename Derived> |
| 3986 | Sema::OwningStmtResult |
| 3987 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3988 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 3989 | // Transform the object we are locking. |
| 3990 | OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
| 3991 | if (Object.isInvalid()) |
| 3992 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3993 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 3994 | // Transform the body. |
| 3995 | OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
| 3996 | if (Body.isInvalid()) |
| 3997 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3998 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 3999 | // If nothing change, just retain the current statement. |
| 4000 | if (!getDerived().AlwaysRebuild() && |
| 4001 | Object.get() == S->getSynchExpr() && |
| 4002 | Body.get() == S->getSynchBody()) |
| 4003 | return SemaRef.Owned(S->Retain()); |
| 4004 | |
| 4005 | // Build a new statement. |
| 4006 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
| 4007 | move(Object), move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4008 | } |
| 4009 | |
| 4010 | template<typename Derived> |
| 4011 | Sema::OwningStmtResult |
| 4012 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4013 | ObjCForCollectionStmt *S) { |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4014 | // Transform the element statement. |
| 4015 | OwningStmtResult Element = getDerived().TransformStmt(S->getElement()); |
| 4016 | if (Element.isInvalid()) |
| 4017 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4018 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4019 | // Transform the collection expression. |
| 4020 | OwningExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
| 4021 | if (Collection.isInvalid()) |
| 4022 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4023 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4024 | // Transform the body. |
| 4025 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 4026 | if (Body.isInvalid()) |
| 4027 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4028 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4029 | // If nothing changed, just retain this statement. |
| 4030 | if (!getDerived().AlwaysRebuild() && |
| 4031 | Element.get() == S->getElement() && |
| 4032 | Collection.get() == S->getCollection() && |
| 4033 | Body.get() == S->getBody()) |
| 4034 | return SemaRef.Owned(S->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4035 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4036 | // Build a new statement. |
| 4037 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 4038 | /*FIXME:*/S->getForLoc(), |
| 4039 | move(Element), |
| 4040 | move(Collection), |
| 4041 | S->getRParenLoc(), |
| 4042 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4043 | } |
| 4044 | |
| 4045 | |
| 4046 | template<typename Derived> |
| 4047 | Sema::OwningStmtResult |
| 4048 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 4049 | // Transform the exception declaration, if any. |
| 4050 | VarDecl *Var = 0; |
| 4051 | if (S->getExceptionDecl()) { |
| 4052 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 4053 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 4054 | ExceptionDecl->getDeclName()); |
| 4055 | |
| 4056 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 4057 | if (T.isNull()) |
| 4058 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4059 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4060 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 4061 | T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4062 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4063 | ExceptionDecl->getIdentifier(), |
| 4064 | ExceptionDecl->getLocation(), |
| 4065 | /*FIXME: Inaccurate*/ |
| 4066 | SourceRange(ExceptionDecl->getLocation())); |
| 4067 | if (!Var || Var->isInvalidDecl()) { |
| 4068 | if (Var) |
| 4069 | Var->Destroy(SemaRef.Context); |
| 4070 | return SemaRef.StmtError(); |
| 4071 | } |
| 4072 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4073 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4074 | // Transform the actual exception handler. |
| 4075 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 4076 | if (Handler.isInvalid()) { |
| 4077 | if (Var) |
| 4078 | Var->Destroy(SemaRef.Context); |
| 4079 | return SemaRef.StmtError(); |
| 4080 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4081 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4082 | if (!getDerived().AlwaysRebuild() && |
| 4083 | !Var && |
| 4084 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4085 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4086 | |
| 4087 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 4088 | Var, |
| 4089 | move(Handler)); |
| 4090 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4091 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4092 | template<typename Derived> |
| 4093 | Sema::OwningStmtResult |
| 4094 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 4095 | // Transform the try block itself. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4096 | OwningStmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4097 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 4098 | if (TryBlock.isInvalid()) |
| 4099 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4100 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4101 | // Transform the handlers. |
| 4102 | bool HandlerChanged = false; |
| 4103 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 4104 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4105 | OwningStmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4106 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 4107 | if (Handler.isInvalid()) |
| 4108 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4109 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4110 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 4111 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 4112 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4113 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4114 | if (!getDerived().AlwaysRebuild() && |
| 4115 | TryBlock.get() == S->getTryBlock() && |
| 4116 | !HandlerChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4117 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4118 | |
| 4119 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4120 | move_arg(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4121 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4122 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4123 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4124 | // Expression transformation |
| 4125 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4126 | template<typename Derived> |
| 4127 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4128 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4129 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4130 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4131 | |
| 4132 | template<typename Derived> |
| 4133 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4134 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4135 | NestedNameSpecifier *Qualifier = 0; |
| 4136 | if (E->getQualifier()) { |
| 4137 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4138 | E->getQualifierRange()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4139 | if (!Qualifier) |
| 4140 | return SemaRef.ExprError(); |
| 4141 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4142 | |
| 4143 | ValueDecl *ND |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4144 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 4145 | E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4146 | if (!ND) |
| 4147 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4148 | |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4149 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4150 | Qualifier == E->getQualifier() && |
| 4151 | ND == E->getDecl() && |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4152 | !E->hasExplicitTemplateArgumentList()) { |
| 4153 | |
| 4154 | // Mark it referenced in the new context regardless. |
| 4155 | // FIXME: this is a bit instantiation-specific. |
| 4156 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 4157 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4158 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4159 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4160 | |
| 4161 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 4162 | if (E->hasExplicitTemplateArgumentList()) { |
| 4163 | TemplateArgs = &TransArgs; |
| 4164 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4165 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 4166 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 4167 | TemplateArgumentLoc Loc; |
| 4168 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 4169 | return SemaRef.ExprError(); |
| 4170 | TransArgs.addArgument(Loc); |
| 4171 | } |
| 4172 | } |
| 4173 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4174 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4175 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4176 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4177 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4178 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4179 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4180 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4181 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4182 | } |
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 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4185 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4186 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4187 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4188 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4189 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4190 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4191 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4192 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4193 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4194 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4195 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4196 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4197 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4198 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4199 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4200 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4201 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4202 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4203 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4204 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4205 | return SemaRef.Owned(E->Retain()); |
| 4206 | } |
| 4207 | |
| 4208 | template<typename Derived> |
| 4209 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4210 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4211 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4212 | if (SubExpr.isInvalid()) |
| 4213 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4214 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4215 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4216 | return SemaRef.Owned(E->Retain()); |
| 4217 | |
| 4218 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4219 | E->getRParen()); |
| 4220 | } |
| 4221 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4222 | template<typename Derived> |
| 4223 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4224 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 4225 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4226 | if (SubExpr.isInvalid()) |
| 4227 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4228 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4229 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4230 | return SemaRef.Owned(E->Retain()); |
| 4231 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4232 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 4233 | E->getOpcode(), |
| 4234 | move(SubExpr)); |
| 4235 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4236 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4237 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4238 | Sema::OwningExprResult |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4239 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 4240 | // Transform the type. |
| 4241 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 4242 | if (!Type) |
| 4243 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4244 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4245 | // Transform all of the components into components similar to what the |
| 4246 | // parser uses. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4247 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 4248 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 4249 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4250 | // template code that we don't care. |
| 4251 | bool ExprChanged = false; |
| 4252 | typedef Action::OffsetOfComponent Component; |
| 4253 | typedef OffsetOfExpr::OffsetOfNode Node; |
| 4254 | llvm::SmallVector<Component, 4> Components; |
| 4255 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 4256 | const Node &ON = E->getComponent(I); |
| 4257 | Component Comp; |
Douglas Gregor | 72be24f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 4258 | Comp.isBrackets = true; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4259 | Comp.LocStart = ON.getRange().getBegin(); |
| 4260 | Comp.LocEnd = ON.getRange().getEnd(); |
| 4261 | switch (ON.getKind()) { |
| 4262 | case Node::Array: { |
| 4263 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
| 4264 | OwningExprResult Index = getDerived().TransformExpr(FromIndex); |
| 4265 | if (Index.isInvalid()) |
| 4266 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4267 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4268 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 4269 | Comp.isBrackets = true; |
| 4270 | Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked |
| 4271 | break; |
| 4272 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4273 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4274 | case Node::Field: |
| 4275 | case Node::Identifier: |
| 4276 | Comp.isBrackets = false; |
| 4277 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | 29d2fd5 | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 4278 | if (!Comp.U.IdentInfo) |
| 4279 | continue; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4280 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4281 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4282 | |
Douglas Gregor | cc8a5d5 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 4283 | case Node::Base: |
| 4284 | // Will be recomputed during the rebuild. |
| 4285 | continue; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4286 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4287 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4288 | Components.push_back(Comp); |
| 4289 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4290 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4291 | // If nothing changed, retain the existing expression. |
| 4292 | if (!getDerived().AlwaysRebuild() && |
| 4293 | Type == E->getTypeSourceInfo() && |
| 4294 | !ExprChanged) |
| 4295 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4296 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4297 | // Build a new offsetof expression. |
| 4298 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 4299 | Components.data(), Components.size(), |
| 4300 | E->getRParenLoc()); |
| 4301 | } |
| 4302 | |
| 4303 | template<typename Derived> |
| 4304 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4305 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4306 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4307 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4308 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4309 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4310 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4311 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4312 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4313 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4314 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4315 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4316 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4317 | E->isSizeOf(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4318 | E->getSourceRange()); |
| 4319 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4320 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4321 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4322 | { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4323 | // C++0x [expr.sizeof]p1: |
| 4324 | // The operand is either an expression, which is an unevaluated operand |
| 4325 | // [...] |
| 4326 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4327 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4328 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 4329 | if (SubExpr.isInvalid()) |
| 4330 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4331 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4332 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 4333 | return SemaRef.Owned(E->Retain()); |
| 4334 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4335 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4336 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 4337 | E->isSizeOf(), |
| 4338 | E->getSourceRange()); |
| 4339 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4340 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4341 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4342 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4343 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4344 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4345 | if (LHS.isInvalid()) |
| 4346 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4347 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4348 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4349 | if (RHS.isInvalid()) |
| 4350 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4351 | |
| 4352 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4353 | if (!getDerived().AlwaysRebuild() && |
| 4354 | LHS.get() == E->getLHS() && |
| 4355 | RHS.get() == E->getRHS()) |
| 4356 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4357 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4358 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 4359 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 4360 | move(RHS), |
| 4361 | E->getRBracketLoc()); |
| 4362 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4363 | |
| 4364 | template<typename Derived> |
| 4365 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4366 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4367 | // Transform the callee. |
| 4368 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4369 | if (Callee.isInvalid()) |
| 4370 | return SemaRef.ExprError(); |
| 4371 | |
| 4372 | // Transform arguments. |
| 4373 | bool ArgChanged = false; |
| 4374 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4375 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4376 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 4377 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4378 | if (Arg.isInvalid()) |
| 4379 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4380 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4381 | // FIXME: Wrong source location information for the ','. |
| 4382 | FakeCommaLocs.push_back( |
| 4383 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4384 | |
| 4385 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4386 | Args.push_back(Arg.takeAs<Expr>()); |
| 4387 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4388 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4389 | if (!getDerived().AlwaysRebuild() && |
| 4390 | Callee.get() == E->getCallee() && |
| 4391 | !ArgChanged) |
| 4392 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4393 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4394 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4395 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4396 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 4397 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 4398 | move_arg(Args), |
| 4399 | FakeCommaLocs.data(), |
| 4400 | E->getRParenLoc()); |
| 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>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4406 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4407 | if (Base.isInvalid()) |
| 4408 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4409 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4410 | NestedNameSpecifier *Qualifier = 0; |
| 4411 | if (E->hasQualifier()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4412 | Qualifier |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4413 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4414 | E->getQualifierRange()); |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 4415 | if (Qualifier == 0) |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4416 | return SemaRef.ExprError(); |
| 4417 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4418 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 4419 | ValueDecl *Member |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4420 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 4421 | E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4422 | if (!Member) |
| 4423 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4424 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4425 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 4426 | if (FoundDecl == E->getMemberDecl()) { |
| 4427 | FoundDecl = Member; |
| 4428 | } else { |
| 4429 | FoundDecl = cast_or_null<NamedDecl>( |
| 4430 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 4431 | if (!FoundDecl) |
| 4432 | return SemaRef.ExprError(); |
| 4433 | } |
| 4434 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4435 | if (!getDerived().AlwaysRebuild() && |
| 4436 | Base.get() == E->getBase() && |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4437 | Qualifier == E->getQualifier() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4438 | Member == E->getMemberDecl() && |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4439 | FoundDecl == E->getFoundDecl() && |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4440 | !E->hasExplicitTemplateArgumentList()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4441 | |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4442 | // Mark it referenced in the new context regardless. |
| 4443 | // FIXME: this is a bit instantiation-specific. |
| 4444 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4445 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4446 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4447 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4448 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4449 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4450 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4451 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4452 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4453 | TemplateArgumentLoc Loc; |
| 4454 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4455 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4456 | TransArgs.addArgument(Loc); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4457 | } |
| 4458 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4459 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4460 | // FIXME: Bogus source location for the operator |
| 4461 | SourceLocation FakeOperatorLoc |
| 4462 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 4463 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4464 | // FIXME: to do this check properly, we will need to preserve the |
| 4465 | // first-qualifier-in-scope here, just in case we had a dependent |
| 4466 | // base (and therefore couldn't do the check) and a |
| 4467 | // nested-name-qualifier (and therefore could do the lookup). |
| 4468 | NamedDecl *FirstQualifierInScope = 0; |
| 4469 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4470 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 4471 | E->isArrow(), |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4472 | Qualifier, |
| 4473 | E->getQualifierRange(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4474 | E->getMemberLoc(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4475 | Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4476 | FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4477 | (E->hasExplicitTemplateArgumentList() |
| 4478 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4479 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4480 | } |
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 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4483 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4484 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4485 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4486 | if (LHS.isInvalid()) |
| 4487 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4488 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4489 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4490 | if (RHS.isInvalid()) |
| 4491 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4492 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4493 | if (!getDerived().AlwaysRebuild() && |
| 4494 | LHS.get() == E->getLHS() && |
| 4495 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4496 | return SemaRef.Owned(E->Retain()); |
| 4497 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4498 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 4499 | move(LHS), move(RHS)); |
| 4500 | } |
| 4501 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4502 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4503 | Sema::OwningExprResult |
| 4504 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4505 | CompoundAssignOperator *E) { |
| 4506 | return getDerived().TransformBinaryOperator(E); |
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> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4510 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4511 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4512 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4513 | if (Cond.isInvalid()) |
| 4514 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4515 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4516 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4517 | if (LHS.isInvalid()) |
| 4518 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4519 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4520 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4521 | if (RHS.isInvalid()) |
| 4522 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4523 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4524 | if (!getDerived().AlwaysRebuild() && |
| 4525 | Cond.get() == E->getCond() && |
| 4526 | LHS.get() == E->getLHS() && |
| 4527 | RHS.get() == E->getRHS()) |
| 4528 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4529 | |
| 4530 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4531 | E->getQuestionLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4532 | move(LHS), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4533 | E->getColonLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4534 | move(RHS)); |
| 4535 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4536 | |
| 4537 | template<typename Derived> |
| 4538 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4539 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4540 | // Implicit casts are eliminated during transformation, since they |
| 4541 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4542 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4543 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4544 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4545 | template<typename Derived> |
| 4546 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4547 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4548 | TypeSourceInfo *OldT; |
| 4549 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4550 | { |
| 4551 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4552 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4553 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 4554 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4555 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4556 | OldT = E->getTypeInfoAsWritten(); |
| 4557 | NewT = getDerived().TransformType(OldT); |
| 4558 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4559 | return SemaRef.ExprError(); |
| 4560 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4561 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4562 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4563 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4564 | if (SubExpr.isInvalid()) |
| 4565 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4566 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4567 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4568 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4569 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4570 | return SemaRef.Owned(E->Retain()); |
| 4571 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4572 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 4573 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4574 | E->getRParenLoc(), |
| 4575 | move(SubExpr)); |
| 4576 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4577 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4578 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4579 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4580 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4581 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 4582 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 4583 | if (!NewT) |
| 4584 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4585 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4586 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 4587 | if (Init.isInvalid()) |
| 4588 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4589 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4590 | if (!getDerived().AlwaysRebuild() && |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4591 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4592 | Init.get() == E->getInitializer()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4593 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4594 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 4595 | // Note: the expression type doesn't necessarily match the |
| 4596 | // type-as-written, but that's okay, because it should always be |
| 4597 | // derivable from the initializer. |
| 4598 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4599 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4600 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 4601 | move(Init)); |
| 4602 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4603 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4604 | template<typename Derived> |
| 4605 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4606 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4607 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4608 | if (Base.isInvalid()) |
| 4609 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4610 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4611 | if (!getDerived().AlwaysRebuild() && |
| 4612 | Base.get() == E->getBase()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4613 | return SemaRef.Owned(E->Retain()); |
| 4614 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4615 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4616 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4617 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 4618 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 4619 | E->getAccessorLoc(), |
| 4620 | E->getAccessor()); |
| 4621 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4622 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4623 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4624 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4625 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4626 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4627 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4628 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4629 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4630 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4631 | if (Init.isInvalid()) |
| 4632 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4633 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4634 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4635 | Inits.push_back(Init.takeAs<Expr>()); |
| 4636 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4637 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4638 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4639 | return SemaRef.Owned(E->Retain()); |
| 4640 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4641 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4642 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4643 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4644 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4645 | template<typename Derived> |
| 4646 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4647 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4648 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4649 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4650 | // transform the initializer value |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4651 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4652 | if (Init.isInvalid()) |
| 4653 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4654 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4655 | // transform the designators. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4656 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4657 | bool ExprChanged = false; |
| 4658 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4659 | DEnd = E->designators_end(); |
| 4660 | D != DEnd; ++D) { |
| 4661 | if (D->isFieldDesignator()) { |
| 4662 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4663 | D->getDotLoc(), |
| 4664 | D->getFieldLoc())); |
| 4665 | continue; |
| 4666 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4667 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4668 | if (D->isArrayDesignator()) { |
| 4669 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4670 | if (Index.isInvalid()) |
| 4671 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4672 | |
| 4673 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4674 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4675 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4676 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4677 | ArrayExprs.push_back(Index.release()); |
| 4678 | continue; |
| 4679 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4680 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4681 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4682 | OwningExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4683 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4684 | if (Start.isInvalid()) |
| 4685 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4686 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4687 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4688 | if (End.isInvalid()) |
| 4689 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4690 | |
| 4691 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4692 | End.get(), |
| 4693 | D->getLBracketLoc(), |
| 4694 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4695 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4696 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4697 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4698 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4699 | ArrayExprs.push_back(Start.release()); |
| 4700 | ArrayExprs.push_back(End.release()); |
| 4701 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4702 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4703 | if (!getDerived().AlwaysRebuild() && |
| 4704 | Init.get() == E->getInit() && |
| 4705 | !ExprChanged) |
| 4706 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4707 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4708 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4709 | E->getEqualOrColonLoc(), |
| 4710 | E->usesGNUSyntax(), move(Init)); |
| 4711 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4712 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4713 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4714 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4715 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4716 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4717 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4718 | |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4719 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4720 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4721 | QualType T = getDerived().TransformType(E->getType()); |
| 4722 | if (T.isNull()) |
| 4723 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4724 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4725 | if (!getDerived().AlwaysRebuild() && |
| 4726 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4727 | return SemaRef.Owned(E->Retain()); |
| 4728 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4729 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4730 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4731 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4732 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4733 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4734 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4735 | // FIXME: Do we want the type as written? |
| 4736 | QualType T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4737 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4738 | { |
| 4739 | // FIXME: Source location isn't quite accurate. |
| 4740 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4741 | T = getDerived().TransformType(E->getType()); |
| 4742 | if (T.isNull()) |
| 4743 | return SemaRef.ExprError(); |
| 4744 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4745 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4746 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4747 | if (SubExpr.isInvalid()) |
| 4748 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4749 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4750 | if (!getDerived().AlwaysRebuild() && |
| 4751 | T == E->getType() && |
| 4752 | SubExpr.get() == E->getSubExpr()) |
| 4753 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4754 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4755 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4756 | T, E->getRParenLoc()); |
| 4757 | } |
| 4758 | |
| 4759 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4760 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4761 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4762 | bool ArgumentChanged = false; |
| 4763 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4764 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4765 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4766 | if (Init.isInvalid()) |
| 4767 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4768 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4769 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4770 | Inits.push_back(Init.takeAs<Expr>()); |
| 4771 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4772 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4773 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4774 | move_arg(Inits), |
| 4775 | E->getRParenLoc()); |
| 4776 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4777 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4778 | /// \brief Transform an address-of-label expression. |
| 4779 | /// |
| 4780 | /// By default, the transformation of an address-of-label expression always |
| 4781 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4782 | /// the corresponding label statement by semantic analysis. |
| 4783 | template<typename Derived> |
| 4784 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4785 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4786 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4787 | E->getLabel()); |
| 4788 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4789 | |
| 4790 | template<typename Derived> |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4791 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4792 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4793 | OwningStmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4794 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4795 | if (SubStmt.isInvalid()) |
| 4796 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4797 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4798 | if (!getDerived().AlwaysRebuild() && |
| 4799 | SubStmt.get() == E->getSubStmt()) |
| 4800 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4801 | |
| 4802 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4803 | move(SubStmt), |
| 4804 | E->getRParenLoc()); |
| 4805 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4806 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4807 | template<typename Derived> |
| 4808 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4809 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4810 | QualType T1, T2; |
| 4811 | { |
| 4812 | // FIXME: Source location isn't quite accurate. |
| 4813 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4814 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4815 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4816 | if (T1.isNull()) |
| 4817 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4818 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4819 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4820 | if (T2.isNull()) |
| 4821 | return SemaRef.ExprError(); |
| 4822 | } |
| 4823 | |
| 4824 | if (!getDerived().AlwaysRebuild() && |
| 4825 | T1 == E->getArgType1() && |
| 4826 | T2 == E->getArgType2()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4827 | return SemaRef.Owned(E->Retain()); |
| 4828 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4829 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4830 | T1, T2, E->getRParenLoc()); |
| 4831 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4832 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4833 | template<typename Derived> |
| 4834 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4835 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4836 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4837 | if (Cond.isInvalid()) |
| 4838 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4839 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4840 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4841 | if (LHS.isInvalid()) |
| 4842 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4843 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4844 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4845 | if (RHS.isInvalid()) |
| 4846 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4847 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4848 | if (!getDerived().AlwaysRebuild() && |
| 4849 | Cond.get() == E->getCond() && |
| 4850 | LHS.get() == E->getLHS() && |
| 4851 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4852 | return SemaRef.Owned(E->Retain()); |
| 4853 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4854 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4855 | move(Cond), move(LHS), move(RHS), |
| 4856 | E->getRParenLoc()); |
| 4857 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4858 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4859 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4860 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4861 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4862 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | template<typename Derived> |
| 4866 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4867 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4868 | switch (E->getOperator()) { |
| 4869 | case OO_New: |
| 4870 | case OO_Delete: |
| 4871 | case OO_Array_New: |
| 4872 | case OO_Array_Delete: |
| 4873 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4874 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4875 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4876 | case OO_Call: { |
| 4877 | // This is a call to an object's operator(). |
| 4878 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4879 | |
| 4880 | // Transform the object itself. |
| 4881 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4882 | if (Object.isInvalid()) |
| 4883 | return SemaRef.ExprError(); |
| 4884 | |
| 4885 | // FIXME: Poor location information |
| 4886 | SourceLocation FakeLParenLoc |
| 4887 | = SemaRef.PP.getLocForEndOfToken( |
| 4888 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4889 | |
| 4890 | // Transform the call arguments. |
| 4891 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4892 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4893 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4894 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4895 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4896 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4897 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4898 | if (Arg.isInvalid()) |
| 4899 | return SemaRef.ExprError(); |
| 4900 | |
| 4901 | // FIXME: Poor source location information. |
| 4902 | SourceLocation FakeCommaLoc |
| 4903 | = SemaRef.PP.getLocForEndOfToken( |
| 4904 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4905 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4906 | Args.push_back(Arg.release()); |
| 4907 | } |
| 4908 | |
| 4909 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4910 | move_arg(Args), |
| 4911 | FakeCommaLocs.data(), |
| 4912 | E->getLocEnd()); |
| 4913 | } |
| 4914 | |
| 4915 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4916 | case OO_##Name: |
| 4917 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4918 | #include "clang/Basic/OperatorKinds.def" |
| 4919 | case OO_Subscript: |
| 4920 | // Handled below. |
| 4921 | break; |
| 4922 | |
| 4923 | case OO_Conditional: |
| 4924 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4925 | return SemaRef.ExprError(); |
| 4926 | |
| 4927 | case OO_None: |
| 4928 | case NUM_OVERLOADED_OPERATORS: |
| 4929 | llvm_unreachable("not an overloaded operator?"); |
| 4930 | return SemaRef.ExprError(); |
| 4931 | } |
| 4932 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4933 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4934 | if (Callee.isInvalid()) |
| 4935 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4936 | |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4937 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4938 | if (First.isInvalid()) |
| 4939 | return SemaRef.ExprError(); |
| 4940 | |
| 4941 | OwningExprResult Second(SemaRef); |
| 4942 | if (E->getNumArgs() == 2) { |
| 4943 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4944 | if (Second.isInvalid()) |
| 4945 | return SemaRef.ExprError(); |
| 4946 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4947 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4948 | if (!getDerived().AlwaysRebuild() && |
| 4949 | Callee.get() == E->getCallee() && |
| 4950 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4951 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4952 | return SemaRef.Owned(E->Retain()); |
| 4953 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4954 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4955 | E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4956 | move(Callee), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4957 | move(First), |
| 4958 | move(Second)); |
| 4959 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4960 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4961 | template<typename Derived> |
| 4962 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4963 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4964 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4965 | } |
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 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4968 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4969 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4970 | TypeSourceInfo *OldT; |
| 4971 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4972 | { |
| 4973 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4974 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4975 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4976 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4977 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4978 | OldT = E->getTypeInfoAsWritten(); |
| 4979 | NewT = getDerived().TransformType(OldT); |
| 4980 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4981 | return SemaRef.ExprError(); |
| 4982 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4983 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4984 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4985 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4986 | if (SubExpr.isInvalid()) |
| 4987 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4988 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4989 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4990 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4991 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4992 | return SemaRef.Owned(E->Retain()); |
| 4993 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4994 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4995 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4996 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4997 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4998 | SourceLocation FakeRParenLoc |
| 4999 | = SemaRef.PP.getLocForEndOfToken( |
| 5000 | E->getSubExpr()->getSourceRange().getEnd()); |
| 5001 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5002 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5003 | FakeLAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5004 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5005 | FakeRAngleLoc, |
| 5006 | FakeRAngleLoc, |
| 5007 | move(SubExpr), |
| 5008 | FakeRParenLoc); |
| 5009 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5010 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5011 | template<typename Derived> |
| 5012 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5013 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 5014 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5015 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5016 | |
| 5017 | template<typename Derived> |
| 5018 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5019 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 5020 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5021 | } |
| 5022 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5023 | template<typename Derived> |
| 5024 | Sema::OwningExprResult |
| 5025 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5026 | CXXReinterpretCastExpr *E) { |
| 5027 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5028 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5029 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5030 | template<typename Derived> |
| 5031 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5032 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 5033 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5034 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5035 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5036 | template<typename Derived> |
| 5037 | Sema::OwningExprResult |
| 5038 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5039 | CXXFunctionalCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5040 | TypeSourceInfo *OldT; |
| 5041 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5042 | { |
| 5043 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5044 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5045 | OldT = E->getTypeInfoAsWritten(); |
| 5046 | NewT = getDerived().TransformType(OldT); |
| 5047 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5048 | return SemaRef.ExprError(); |
| 5049 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5050 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 5051 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5052 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5053 | if (SubExpr.isInvalid()) |
| 5054 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5055 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5056 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5057 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5058 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5059 | return SemaRef.Owned(E->Retain()); |
| 5060 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5061 | // FIXME: The end of the type's source range is wrong |
| 5062 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 5063 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5064 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5065 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 5066 | move(SubExpr), |
| 5067 | E->getRParenLoc()); |
| 5068 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5069 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5070 | template<typename Derived> |
| 5071 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5072 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5073 | if (E->isTypeOperand()) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5074 | TypeSourceInfo *TInfo |
| 5075 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 5076 | if (!TInfo) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5077 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5078 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5079 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5080 | TInfo == E->getTypeOperandSourceInfo()) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5081 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5082 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5083 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 5084 | E->getLocStart(), |
| 5085 | TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5086 | E->getLocEnd()); |
| 5087 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5088 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5089 | // We don't know whether the expression is potentially evaluated until |
| 5090 | // after we perform semantic analysis, so the expression is potentially |
| 5091 | // potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5092 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5093 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5094 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5095 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 5096 | if (SubExpr.isInvalid()) |
| 5097 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5098 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5099 | if (!getDerived().AlwaysRebuild() && |
| 5100 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5101 | return SemaRef.Owned(E->Retain()); |
| 5102 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5103 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 5104 | E->getLocStart(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5105 | move(SubExpr), |
| 5106 | E->getLocEnd()); |
| 5107 | } |
| 5108 | |
| 5109 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5110 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5111 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5112 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5113 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5114 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5115 | template<typename Derived> |
| 5116 | Sema::OwningExprResult |
| 5117 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5118 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5119 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5120 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5121 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5122 | template<typename Derived> |
| 5123 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5124 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5125 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5126 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5127 | QualType T = getDerived().TransformType(E->getType()); |
| 5128 | if (T.isNull()) |
| 5129 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5130 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5131 | if (!getDerived().AlwaysRebuild() && |
| 5132 | T == E->getType()) |
| 5133 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5134 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 5135 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5136 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5137 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5138 | template<typename Derived> |
| 5139 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5140 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5141 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 5142 | if (SubExpr.isInvalid()) |
| 5143 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5144 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5145 | if (!getDerived().AlwaysRebuild() && |
| 5146 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5147 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5148 | |
| 5149 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 5150 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5151 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5152 | template<typename Derived> |
| 5153 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5154 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5155 | ParmVarDecl *Param |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5156 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 5157 | E->getParam())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5158 | if (!Param) |
| 5159 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5160 | |
Chandler Carruth | 53cb6f8 | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 5161 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5162 | Param == E->getParam()) |
| 5163 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5164 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 5165 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5166 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5167 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5168 | template<typename Derived> |
| 5169 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5170 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5171 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5172 | |
| 5173 | QualType T = getDerived().TransformType(E->getType()); |
| 5174 | if (T.isNull()) |
| 5175 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5176 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5177 | if (!getDerived().AlwaysRebuild() && |
| 5178 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5179 | return SemaRef.Owned(E->Retain()); |
| 5180 | |
| 5181 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5182 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5183 | T, |
| 5184 | E->getRParenLoc()); |
| 5185 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5186 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5187 | template<typename Derived> |
| 5188 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5189 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5190 | // Transform the type that we're allocating |
| 5191 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 5192 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 5193 | if (AllocType.isNull()) |
| 5194 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5195 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5196 | // Transform the size of the array we're allocating (if any). |
| 5197 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 5198 | if (ArraySize.isInvalid()) |
| 5199 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5200 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5201 | // Transform the placement arguments (if any). |
| 5202 | bool ArgumentChanged = false; |
| 5203 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 5204 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 5205 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 5206 | if (Arg.isInvalid()) |
| 5207 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5208 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5209 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 5210 | PlacementArgs.push_back(Arg.take()); |
| 5211 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5212 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5213 | // transform the constructor arguments (if any). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5214 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 5215 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
Douglas Gregor | ff2e4f4 | 2010-05-26 07:10:06 +0000 | [diff] [blame] | 5216 | if (getDerived().DropCallArgument(E->getConstructorArg(I))) |
| 5217 | break; |
| 5218 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5219 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 5220 | if (Arg.isInvalid()) |
| 5221 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5222 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5223 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 5224 | ConstructorArgs.push_back(Arg.take()); |
| 5225 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5226 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5227 | // Transform constructor, new operator, and delete operator. |
| 5228 | CXXConstructorDecl *Constructor = 0; |
| 5229 | if (E->getConstructor()) { |
| 5230 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5231 | getDerived().TransformDecl(E->getLocStart(), |
| 5232 | E->getConstructor())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5233 | if (!Constructor) |
| 5234 | return SemaRef.ExprError(); |
| 5235 | } |
| 5236 | |
| 5237 | FunctionDecl *OperatorNew = 0; |
| 5238 | if (E->getOperatorNew()) { |
| 5239 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5240 | getDerived().TransformDecl(E->getLocStart(), |
| 5241 | E->getOperatorNew())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5242 | if (!OperatorNew) |
| 5243 | return SemaRef.ExprError(); |
| 5244 | } |
| 5245 | |
| 5246 | FunctionDecl *OperatorDelete = 0; |
| 5247 | if (E->getOperatorDelete()) { |
| 5248 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5249 | getDerived().TransformDecl(E->getLocStart(), |
| 5250 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5251 | if (!OperatorDelete) |
| 5252 | return SemaRef.ExprError(); |
| 5253 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5254 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5255 | if (!getDerived().AlwaysRebuild() && |
| 5256 | AllocType == E->getAllocatedType() && |
| 5257 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5258 | Constructor == E->getConstructor() && |
| 5259 | OperatorNew == E->getOperatorNew() && |
| 5260 | OperatorDelete == E->getOperatorDelete() && |
| 5261 | !ArgumentChanged) { |
| 5262 | // Mark any declarations we need as referenced. |
| 5263 | // FIXME: instantiation-specific. |
| 5264 | if (Constructor) |
| 5265 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 5266 | if (OperatorNew) |
| 5267 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 5268 | if (OperatorDelete) |
| 5269 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5270 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5271 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5272 | |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5273 | if (!ArraySize.get()) { |
| 5274 | // If no array size was specified, but the new expression was |
| 5275 | // instantiated with an array type (e.g., "new T" where T is |
| 5276 | // instantiated with "int[4]"), extract the outer bound from the |
| 5277 | // array type as our array size. We do this with constant and |
| 5278 | // dependently-sized array types. |
| 5279 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 5280 | if (!ArrayT) { |
| 5281 | // Do nothing |
| 5282 | } else if (const ConstantArrayType *ConsArrayT |
| 5283 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5284 | ArraySize |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5285 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5286 | ConsArrayT->getSize(), |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5287 | SemaRef.Context.getSizeType(), |
| 5288 | /*FIXME:*/E->getLocStart())); |
| 5289 | AllocType = ConsArrayT->getElementType(); |
| 5290 | } else if (const DependentSizedArrayType *DepArrayT |
| 5291 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 5292 | if (DepArrayT->getSizeExpr()) { |
| 5293 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 5294 | AllocType = DepArrayT->getElementType(); |
| 5295 | } |
| 5296 | } |
| 5297 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5298 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 5299 | E->isGlobalNew(), |
| 5300 | /*FIXME:*/E->getLocStart(), |
| 5301 | move_arg(PlacementArgs), |
| 5302 | /*FIXME:*/E->getLocStart(), |
| 5303 | E->isParenTypeId(), |
| 5304 | AllocType, |
| 5305 | /*FIXME:*/E->getLocStart(), |
| 5306 | /*FIXME:*/SourceRange(), |
| 5307 | move(ArraySize), |
| 5308 | /*FIXME:*/E->getLocStart(), |
| 5309 | move_arg(ConstructorArgs), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5310 | E->getLocEnd()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5311 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5312 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5313 | template<typename Derived> |
| 5314 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5315 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5316 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 5317 | if (Operand.isInvalid()) |
| 5318 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5319 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5320 | // Transform the delete operator, if known. |
| 5321 | FunctionDecl *OperatorDelete = 0; |
| 5322 | if (E->getOperatorDelete()) { |
| 5323 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5324 | getDerived().TransformDecl(E->getLocStart(), |
| 5325 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5326 | if (!OperatorDelete) |
| 5327 | return SemaRef.ExprError(); |
| 5328 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5329 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5330 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5331 | Operand.get() == E->getArgument() && |
| 5332 | OperatorDelete == E->getOperatorDelete()) { |
| 5333 | // Mark any declarations we need as referenced. |
| 5334 | // FIXME: instantiation-specific. |
| 5335 | if (OperatorDelete) |
| 5336 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5337 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5338 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5339 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5340 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 5341 | E->isGlobalDelete(), |
| 5342 | E->isArrayForm(), |
| 5343 | move(Operand)); |
| 5344 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5345 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5346 | template<typename Derived> |
| 5347 | Sema::OwningExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5348 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5349 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5350 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 5351 | if (Base.isInvalid()) |
| 5352 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5353 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5354 | Sema::TypeTy *ObjectTypePtr = 0; |
| 5355 | bool MayBePseudoDestructor = false; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5356 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5357 | E->getOperatorLoc(), |
| 5358 | E->isArrow()? tok::arrow : tok::period, |
| 5359 | ObjectTypePtr, |
| 5360 | MayBePseudoDestructor); |
| 5361 | if (Base.isInvalid()) |
| 5362 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5363 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5364 | QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5365 | NestedNameSpecifier *Qualifier |
| 5366 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | b10cd04 | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 5367 | E->getQualifierRange(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5368 | ObjectType); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5369 | if (E->getQualifier() && !Qualifier) |
| 5370 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5371 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5372 | PseudoDestructorTypeStorage Destroyed; |
| 5373 | if (E->getDestroyedTypeInfo()) { |
| 5374 | TypeSourceInfo *DestroyedTypeInfo |
| 5375 | = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType); |
| 5376 | if (!DestroyedTypeInfo) |
| 5377 | return SemaRef.ExprError(); |
| 5378 | Destroyed = DestroyedTypeInfo; |
| 5379 | } else if (ObjectType->isDependentType()) { |
| 5380 | // We aren't likely to be able to resolve the identifier down to a type |
| 5381 | // now anyway, so just retain the identifier. |
| 5382 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 5383 | E->getDestroyedTypeLoc()); |
| 5384 | } else { |
| 5385 | // Look for a destructor known with the given name. |
| 5386 | CXXScopeSpec SS; |
| 5387 | if (Qualifier) { |
| 5388 | SS.setScopeRep(Qualifier); |
| 5389 | SS.setRange(E->getQualifierRange()); |
| 5390 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5391 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5392 | Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(), |
| 5393 | *E->getDestroyedTypeIdentifier(), |
| 5394 | E->getDestroyedTypeLoc(), |
| 5395 | /*Scope=*/0, |
| 5396 | SS, ObjectTypePtr, |
| 5397 | false); |
| 5398 | if (!T) |
| 5399 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5400 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5401 | Destroyed |
| 5402 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 5403 | E->getDestroyedTypeLoc()); |
| 5404 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5405 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5406 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 5407 | if (E->getScopeTypeInfo()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5408 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5409 | ObjectType); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5410 | if (!ScopeTypeInfo) |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5411 | return SemaRef.ExprError(); |
| 5412 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5413 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5414 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 5415 | E->getOperatorLoc(), |
| 5416 | E->isArrow(), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5417 | Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5418 | E->getQualifierRange(), |
| 5419 | ScopeTypeInfo, |
| 5420 | E->getColonColonLoc(), |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 5421 | E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5422 | Destroyed); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5423 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5424 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5425 | template<typename Derived> |
| 5426 | Sema::OwningExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5427 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5428 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5429 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 5430 | |
| 5431 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 5432 | Sema::LookupOrdinaryName); |
| 5433 | |
| 5434 | // Transform all the decls. |
| 5435 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 5436 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5437 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5438 | getDerived().TransformDecl(Old->getNameLoc(), |
| 5439 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5440 | if (!InstD) { |
| 5441 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5442 | // This can happen because of dependent hiding. |
| 5443 | if (isa<UsingShadowDecl>(*I)) |
| 5444 | continue; |
| 5445 | else |
| 5446 | return SemaRef.ExprError(); |
| 5447 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5448 | |
| 5449 | // Expand using declarations. |
| 5450 | if (isa<UsingDecl>(InstD)) { |
| 5451 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5452 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5453 | E = UD->shadow_end(); I != E; ++I) |
| 5454 | R.addDecl(*I); |
| 5455 | continue; |
| 5456 | } |
| 5457 | |
| 5458 | R.addDecl(InstD); |
| 5459 | } |
| 5460 | |
| 5461 | // Resolve a kind, but don't do any further analysis. If it's |
| 5462 | // ambiguous, the callee needs to deal with it. |
| 5463 | R.resolveKind(); |
| 5464 | |
| 5465 | // Rebuild the nested-name qualifier, if present. |
| 5466 | CXXScopeSpec SS; |
| 5467 | NestedNameSpecifier *Qualifier = 0; |
| 5468 | if (Old->getQualifier()) { |
| 5469 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5470 | Old->getQualifierRange()); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5471 | if (!Qualifier) |
| 5472 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5473 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5474 | SS.setScopeRep(Qualifier); |
| 5475 | SS.setRange(Old->getQualifierRange()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5476 | } |
| 5477 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5478 | if (Old->getNamingClass()) { |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5479 | CXXRecordDecl *NamingClass |
| 5480 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 5481 | Old->getNameLoc(), |
| 5482 | Old->getNamingClass())); |
| 5483 | if (!NamingClass) |
| 5484 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5485 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5486 | R.setNamingClass(NamingClass); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5487 | } |
| 5488 | |
| 5489 | // If we have no template arguments, it's a normal declaration name. |
| 5490 | if (!Old->hasExplicitTemplateArgs()) |
| 5491 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 5492 | |
| 5493 | // If we have template arguments, rebuild them, then rebuild the |
| 5494 | // templateid expression. |
| 5495 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 5496 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5497 | TemplateArgumentLoc Loc; |
| 5498 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 5499 | return SemaRef.ExprError(); |
| 5500 | TransArgs.addArgument(Loc); |
| 5501 | } |
| 5502 | |
| 5503 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 5504 | TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5505 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5506 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5507 | template<typename Derived> |
| 5508 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5509 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5510 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5511 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5512 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 5513 | if (T.isNull()) |
| 5514 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5515 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5516 | if (!getDerived().AlwaysRebuild() && |
| 5517 | T == E->getQueriedType()) |
| 5518 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5519 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5520 | // FIXME: Bad location information |
| 5521 | SourceLocation FakeLParenLoc |
| 5522 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5523 | |
| 5524 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5525 | E->getLocStart(), |
| 5526 | /*FIXME:*/FakeLParenLoc, |
| 5527 | T, |
| 5528 | E->getLocEnd()); |
| 5529 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5530 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5531 | template<typename Derived> |
| 5532 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5533 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5534 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5535 | NestedNameSpecifier *NNS |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5536 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5537 | E->getQualifierRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5538 | if (!NNS) |
| 5539 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5540 | |
| 5541 | DeclarationName Name |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5542 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 5543 | if (!Name) |
| 5544 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5545 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5546 | if (!E->hasExplicitTemplateArgs()) { |
| 5547 | if (!getDerived().AlwaysRebuild() && |
| 5548 | NNS == E->getQualifier() && |
| 5549 | Name == E->getDeclName()) |
| 5550 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5551 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5552 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5553 | E->getQualifierRange(), |
| 5554 | Name, E->getLocation(), |
| 5555 | /*TemplateArgs*/ 0); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5556 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5557 | |
| 5558 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5559 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5560 | TemplateArgumentLoc Loc; |
| 5561 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5562 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5563 | TransArgs.addArgument(Loc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5564 | } |
| 5565 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5566 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5567 | E->getQualifierRange(), |
| 5568 | Name, E->getLocation(), |
| 5569 | &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5570 | } |
| 5571 | |
| 5572 | template<typename Derived> |
| 5573 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5574 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 5575 | // CXXConstructExprs are always implicit, so when we have a |
| 5576 | // 1-argument construction we just transform that argument. |
| 5577 | if (E->getNumArgs() == 1 || |
| 5578 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 5579 | return getDerived().TransformExpr(E->getArg(0)); |
| 5580 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5581 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 5582 | |
| 5583 | QualType T = getDerived().TransformType(E->getType()); |
| 5584 | if (T.isNull()) |
| 5585 | return SemaRef.ExprError(); |
| 5586 | |
| 5587 | CXXConstructorDecl *Constructor |
| 5588 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5589 | getDerived().TransformDecl(E->getLocStart(), |
| 5590 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5591 | if (!Constructor) |
| 5592 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5593 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5594 | bool ArgumentChanged = false; |
| 5595 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5596 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5597 | ArgEnd = E->arg_end(); |
| 5598 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5599 | if (getDerived().DropCallArgument(*Arg)) { |
| 5600 | ArgumentChanged = true; |
| 5601 | break; |
| 5602 | } |
| 5603 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5604 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5605 | if (TransArg.isInvalid()) |
| 5606 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5607 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5608 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5609 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5610 | } |
| 5611 | |
| 5612 | if (!getDerived().AlwaysRebuild() && |
| 5613 | T == E->getType() && |
| 5614 | Constructor == E->getConstructor() && |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5615 | !ArgumentChanged) { |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5616 | // Mark the constructor as referenced. |
| 5617 | // FIXME: Instantiation-specific |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5618 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5619 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5620 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5621 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 5622 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 5623 | Constructor, E->isElidable(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5624 | move_arg(Args)); |
| 5625 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5626 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5627 | /// \brief Transform a C++ temporary-binding expression. |
| 5628 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5629 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 5630 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5631 | template<typename Derived> |
| 5632 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5633 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5634 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5635 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5636 | |
Anders Carlsson | eb60edf | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 5637 | /// \brief Transform a C++ reference-binding expression. |
| 5638 | /// |
| 5639 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 5640 | /// transform the subexpression and return that. |
| 5641 | template<typename Derived> |
| 5642 | Sema::OwningExprResult |
| 5643 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 5644 | return getDerived().TransformExpr(E->getSubExpr()); |
| 5645 | } |
| 5646 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5647 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5648 | /// be destroyed after the expression is evaluated. |
| 5649 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5650 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 5651 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5652 | template<typename Derived> |
| 5653 | Sema::OwningExprResult |
| 5654 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5655 | CXXExprWithTemporaries *E) { |
| 5656 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5657 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5658 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5659 | template<typename Derived> |
| 5660 | Sema::OwningExprResult |
| 5661 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5662 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5663 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5664 | QualType T = getDerived().TransformType(E->getType()); |
| 5665 | if (T.isNull()) |
| 5666 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5667 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5668 | CXXConstructorDecl *Constructor |
| 5669 | = cast_or_null<CXXConstructorDecl>( |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5670 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5671 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5672 | if (!Constructor) |
| 5673 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5674 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5675 | bool ArgumentChanged = false; |
| 5676 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5677 | Args.reserve(E->getNumArgs()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5678 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5679 | ArgEnd = E->arg_end(); |
| 5680 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5681 | if (getDerived().DropCallArgument(*Arg)) { |
| 5682 | ArgumentChanged = true; |
| 5683 | break; |
| 5684 | } |
| 5685 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5686 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5687 | if (TransArg.isInvalid()) |
| 5688 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5689 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5690 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5691 | Args.push_back((Expr *)TransArg.release()); |
| 5692 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5693 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5694 | if (!getDerived().AlwaysRebuild() && |
| 5695 | T == E->getType() && |
| 5696 | Constructor == E->getConstructor() && |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5697 | !ArgumentChanged) { |
| 5698 | // FIXME: Instantiation-specific |
| 5699 | SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor); |
Chandler Carruth | a3ce8ae | 2010-03-31 18:34:58 +0000 | [diff] [blame] | 5700 | return SemaRef.MaybeBindToTemporary(E->Retain()); |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5701 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5702 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5703 | // FIXME: Bogus location information |
| 5704 | SourceLocation CommaLoc; |
| 5705 | if (Args.size() > 1) { |
| 5706 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5707 | CommaLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5708 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 5709 | } |
| 5710 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 5711 | T, |
| 5712 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5713 | move_arg(Args), |
| 5714 | &CommaLoc, |
| 5715 | E->getLocEnd()); |
| 5716 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5717 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5718 | template<typename Derived> |
| 5719 | Sema::OwningExprResult |
| 5720 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5721 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5722 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5723 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 5724 | if (T.isNull()) |
| 5725 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5726 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5727 | bool ArgumentChanged = false; |
| 5728 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5729 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 5730 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 5731 | ArgEnd = E->arg_end(); |
| 5732 | Arg != ArgEnd; ++Arg) { |
| 5733 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5734 | if (TransArg.isInvalid()) |
| 5735 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5736 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5737 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5738 | FakeCommaLocs.push_back( |
| 5739 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 5740 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5741 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5742 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5743 | if (!getDerived().AlwaysRebuild() && |
| 5744 | T == E->getTypeAsWritten() && |
| 5745 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5746 | return SemaRef.Owned(E->Retain()); |
| 5747 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5748 | // FIXME: we're faking the locations of the commas |
| 5749 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5750 | T, |
| 5751 | E->getLParenLoc(), |
| 5752 | move_arg(Args), |
| 5753 | FakeCommaLocs.data(), |
| 5754 | E->getRParenLoc()); |
| 5755 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5756 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5757 | template<typename Derived> |
| 5758 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5759 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5760 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5761 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5762 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5763 | Expr *OldBase; |
| 5764 | QualType BaseType; |
| 5765 | QualType ObjectType; |
| 5766 | if (!E->isImplicitAccess()) { |
| 5767 | OldBase = E->getBase(); |
| 5768 | Base = getDerived().TransformExpr(OldBase); |
| 5769 | if (Base.isInvalid()) |
| 5770 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5771 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5772 | // Start the member reference and compute the object's type. |
| 5773 | Sema::TypeTy *ObjectTy = 0; |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5774 | bool MayBePseudoDestructor = false; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5775 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5776 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5777 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5778 | ObjectTy, |
| 5779 | MayBePseudoDestructor); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5780 | if (Base.isInvalid()) |
| 5781 | return SemaRef.ExprError(); |
| 5782 | |
| 5783 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5784 | BaseType = ((Expr*) Base.get())->getType(); |
| 5785 | } else { |
| 5786 | OldBase = 0; |
| 5787 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5788 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5789 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5790 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5791 | // Transform the first part of the nested-name-specifier that qualifies |
| 5792 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5793 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5794 | = getDerived().TransformFirstQualifierInScope( |
| 5795 | E->getFirstQualifierFoundInScope(), |
| 5796 | E->getQualifierRange().getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5797 | |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5798 | NestedNameSpecifier *Qualifier = 0; |
| 5799 | if (E->getQualifier()) { |
| 5800 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5801 | E->getQualifierRange(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5802 | ObjectType, |
| 5803 | FirstQualifierInScope); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5804 | if (!Qualifier) |
| 5805 | return SemaRef.ExprError(); |
| 5806 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5807 | |
| 5808 | DeclarationName Name |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5809 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5810 | ObjectType); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5811 | if (!Name) |
| 5812 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5813 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5814 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5815 | // This is a reference to a member without an explicitly-specified |
| 5816 | // template argument list. Optimize for this common case. |
| 5817 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5818 | Base.get() == OldBase && |
| 5819 | BaseType == E->getBaseType() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5820 | Qualifier == E->getQualifier() && |
| 5821 | Name == E->getMember() && |
| 5822 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5823 | return SemaRef.Owned(E->Retain()); |
| 5824 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5825 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5826 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5827 | E->isArrow(), |
| 5828 | E->getOperatorLoc(), |
| 5829 | Qualifier, |
| 5830 | E->getQualifierRange(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5831 | FirstQualifierInScope, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5832 | Name, |
| 5833 | E->getMemberLoc(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5834 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5835 | } |
| 5836 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5837 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5838 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5839 | TemplateArgumentLoc Loc; |
| 5840 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5841 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5842 | TransArgs.addArgument(Loc); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5843 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5844 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5845 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5846 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5847 | E->isArrow(), |
| 5848 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5849 | Qualifier, |
| 5850 | E->getQualifierRange(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5851 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5852 | Name, |
| 5853 | E->getMemberLoc(), |
| 5854 | &TransArgs); |
| 5855 | } |
| 5856 | |
| 5857 | template<typename Derived> |
| 5858 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5859 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5860 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5861 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5862 | QualType BaseType; |
| 5863 | if (!Old->isImplicitAccess()) { |
| 5864 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5865 | if (Base.isInvalid()) |
| 5866 | return SemaRef.ExprError(); |
| 5867 | BaseType = ((Expr*) Base.get())->getType(); |
| 5868 | } else { |
| 5869 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5870 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5871 | |
| 5872 | NestedNameSpecifier *Qualifier = 0; |
| 5873 | if (Old->getQualifier()) { |
| 5874 | Qualifier |
| 5875 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5876 | Old->getQualifierRange()); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5877 | if (Qualifier == 0) |
| 5878 | return SemaRef.ExprError(); |
| 5879 | } |
| 5880 | |
| 5881 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5882 | Sema::LookupOrdinaryName); |
| 5883 | |
| 5884 | // Transform all the decls. |
| 5885 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5886 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5887 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5888 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 5889 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5890 | if (!InstD) { |
| 5891 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5892 | // This can happen because of dependent hiding. |
| 5893 | if (isa<UsingShadowDecl>(*I)) |
| 5894 | continue; |
| 5895 | else |
| 5896 | return SemaRef.ExprError(); |
| 5897 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5898 | |
| 5899 | // Expand using declarations. |
| 5900 | if (isa<UsingDecl>(InstD)) { |
| 5901 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5902 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5903 | E = UD->shadow_end(); I != E; ++I) |
| 5904 | R.addDecl(*I); |
| 5905 | continue; |
| 5906 | } |
| 5907 | |
| 5908 | R.addDecl(InstD); |
| 5909 | } |
| 5910 | |
| 5911 | R.resolveKind(); |
| 5912 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5913 | // Determine the naming class. |
Chandler Carruth | 042d6f9 | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 5914 | if (Old->getNamingClass()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5915 | CXXRecordDecl *NamingClass |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5916 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5917 | Old->getMemberLoc(), |
| 5918 | Old->getNamingClass())); |
| 5919 | if (!NamingClass) |
| 5920 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5921 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5922 | R.setNamingClass(NamingClass); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5923 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5924 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5925 | TemplateArgumentListInfo TransArgs; |
| 5926 | if (Old->hasExplicitTemplateArgs()) { |
| 5927 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5928 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5929 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5930 | TemplateArgumentLoc Loc; |
| 5931 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5932 | Loc)) |
| 5933 | return SemaRef.ExprError(); |
| 5934 | TransArgs.addArgument(Loc); |
| 5935 | } |
| 5936 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5937 | |
| 5938 | // FIXME: to do this check properly, we will need to preserve the |
| 5939 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5940 | // base (and therefore couldn't do the check) and a |
| 5941 | // nested-name-qualifier (and therefore could do the lookup). |
| 5942 | NamedDecl *FirstQualifierInScope = 0; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5943 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5944 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5945 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5946 | Old->getOperatorLoc(), |
| 5947 | Old->isArrow(), |
| 5948 | Qualifier, |
| 5949 | Old->getQualifierRange(), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5950 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5951 | R, |
| 5952 | (Old->hasExplicitTemplateArgs() |
| 5953 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5954 | } |
| 5955 | |
| 5956 | template<typename Derived> |
| 5957 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5958 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5959 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5960 | } |
| 5961 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5962 | template<typename Derived> |
| 5963 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5964 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5965 | TypeSourceInfo *EncodedTypeInfo |
| 5966 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 5967 | if (!EncodedTypeInfo) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5968 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5969 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5970 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5971 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5972 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5973 | |
| 5974 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5975 | EncodedTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5976 | E->getRParenLoc()); |
| 5977 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5978 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5979 | template<typename Derived> |
| 5980 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5981 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5982 | // Transform arguments. |
| 5983 | bool ArgChanged = false; |
| 5984 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5985 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 5986 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 5987 | if (Arg.isInvalid()) |
| 5988 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5989 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5990 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
| 5991 | Args.push_back(Arg.takeAs<Expr>()); |
| 5992 | } |
| 5993 | |
| 5994 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 5995 | // Class message: transform the receiver type. |
| 5996 | TypeSourceInfo *ReceiverTypeInfo |
| 5997 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 5998 | if (!ReceiverTypeInfo) |
| 5999 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6000 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6001 | // If nothing changed, just retain the existing message send. |
| 6002 | if (!getDerived().AlwaysRebuild() && |
| 6003 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
| 6004 | return SemaRef.Owned(E->Retain()); |
| 6005 | |
| 6006 | // Build a new class message send. |
| 6007 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 6008 | E->getSelector(), |
| 6009 | E->getMethodDecl(), |
| 6010 | E->getLeftLoc(), |
| 6011 | move_arg(Args), |
| 6012 | E->getRightLoc()); |
| 6013 | } |
| 6014 | |
| 6015 | // Instance message: transform the receiver |
| 6016 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 6017 | "Only class and instance messages may be instantiated"); |
| 6018 | OwningExprResult Receiver |
| 6019 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 6020 | if (Receiver.isInvalid()) |
| 6021 | return SemaRef.ExprError(); |
| 6022 | |
| 6023 | // If nothing changed, just retain the existing message send. |
| 6024 | if (!getDerived().AlwaysRebuild() && |
| 6025 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
| 6026 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6027 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6028 | // Build a new instance message send. |
| 6029 | return getDerived().RebuildObjCMessageExpr(move(Receiver), |
| 6030 | E->getSelector(), |
| 6031 | E->getMethodDecl(), |
| 6032 | E->getLeftLoc(), |
| 6033 | move_arg(Args), |
| 6034 | E->getRightLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6035 | } |
| 6036 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6037 | template<typename Derived> |
| 6038 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6039 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6040 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6041 | } |
| 6042 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6043 | template<typename Derived> |
| 6044 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6045 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 6046 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6047 | } |
| 6048 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6049 | template<typename Derived> |
| 6050 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6051 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6052 | // Transform the base expression. |
| 6053 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6054 | if (Base.isInvalid()) |
| 6055 | return SemaRef.ExprError(); |
| 6056 | |
| 6057 | // We don't need to transform the ivar; it will never change. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6058 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6059 | // If nothing changed, just retain the existing expression. |
| 6060 | if (!getDerived().AlwaysRebuild() && |
| 6061 | Base.get() == E->getBase()) |
| 6062 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6063 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6064 | return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(), |
| 6065 | E->getLocation(), |
| 6066 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6067 | } |
| 6068 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6069 | template<typename Derived> |
| 6070 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6071 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6072 | // Transform the base expression. |
| 6073 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6074 | if (Base.isInvalid()) |
| 6075 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6076 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6077 | // We don't need to transform the property; it will never change. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6078 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6079 | // If nothing changed, just retain the existing expression. |
| 6080 | if (!getDerived().AlwaysRebuild() && |
| 6081 | Base.get() == E->getBase()) |
| 6082 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6083 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6084 | return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(), |
| 6085 | E->getLocation()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6086 | } |
| 6087 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6088 | template<typename Derived> |
| 6089 | Sema::OwningExprResult |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 6090 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6091 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6092 | // If this implicit setter/getter refers to class methods, it cannot have any |
| 6093 | // dependent parts. Just retain the existing declaration. |
| 6094 | if (E->getInterfaceDecl()) |
| 6095 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6096 | |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6097 | // Transform the base expression. |
| 6098 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6099 | if (Base.isInvalid()) |
| 6100 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6101 | |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6102 | // We don't need to transform the getters/setters; they will never change. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6103 | |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6104 | // If nothing changed, just retain the existing expression. |
| 6105 | if (!getDerived().AlwaysRebuild() && |
| 6106 | Base.get() == E->getBase()) |
| 6107 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6108 | |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6109 | return getDerived().RebuildObjCImplicitSetterGetterRefExpr( |
| 6110 | E->getGetterMethod(), |
| 6111 | E->getType(), |
| 6112 | E->getSetterMethod(), |
| 6113 | E->getLocation(), |
| 6114 | move(Base)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6115 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6116 | } |
| 6117 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6118 | template<typename Derived> |
| 6119 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6120 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 6121 | // Can never occur in a dependent context. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6122 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6123 | } |
| 6124 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6125 | template<typename Derived> |
| 6126 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6127 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6128 | // Transform the base expression. |
| 6129 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6130 | if (Base.isInvalid()) |
| 6131 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6132 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6133 | // If nothing changed, just retain the existing expression. |
| 6134 | if (!getDerived().AlwaysRebuild() && |
| 6135 | Base.get() == E->getBase()) |
| 6136 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6137 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6138 | return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(), |
| 6139 | E->isArrow()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6140 | } |
| 6141 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6142 | template<typename Derived> |
| 6143 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6144 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6145 | bool ArgumentChanged = false; |
| 6146 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 6147 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 6148 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 6149 | if (SubExpr.isInvalid()) |
| 6150 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6151 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6152 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 6153 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 6154 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6155 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6156 | if (!getDerived().AlwaysRebuild() && |
| 6157 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6158 | return SemaRef.Owned(E->Retain()); |
| 6159 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6160 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 6161 | move_arg(SubExprs), |
| 6162 | E->getRParenLoc()); |
| 6163 | } |
| 6164 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6165 | template<typename Derived> |
| 6166 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6167 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6168 | // FIXME: Implement this! |
| 6169 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6170 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6171 | } |
| 6172 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6173 | template<typename Derived> |
| 6174 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6175 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6176 | // FIXME: Implement this! |
| 6177 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6178 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6179 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6180 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6181 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6182 | // Type reconstruction |
| 6183 | //===----------------------------------------------------------------------===// |
| 6184 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6185 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6186 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 6187 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame^] | 6188 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6189 | getDerived().getBaseEntity()); |
| 6190 | } |
| 6191 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6192 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6193 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 6194 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame^] | 6195 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6196 | getDerived().getBaseEntity()); |
| 6197 | } |
| 6198 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6199 | template<typename Derived> |
| 6200 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6201 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 6202 | bool WrittenAsLValue, |
| 6203 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame^] | 6204 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6205 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6206 | } |
| 6207 | |
| 6208 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6209 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6210 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 6211 | QualType ClassType, |
| 6212 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame^] | 6213 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6214 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6215 | } |
| 6216 | |
| 6217 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6218 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6219 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 6220 | ArrayType::ArraySizeModifier SizeMod, |
| 6221 | const llvm::APInt *Size, |
| 6222 | Expr *SizeExpr, |
| 6223 | unsigned IndexTypeQuals, |
| 6224 | SourceRange BracketsRange) { |
| 6225 | if (SizeExpr || !Size) |
| 6226 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 6227 | IndexTypeQuals, BracketsRange, |
| 6228 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6229 | |
| 6230 | QualType Types[] = { |
| 6231 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 6232 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 6233 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6234 | }; |
| 6235 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 6236 | QualType SizeType; |
| 6237 | for (unsigned I = 0; I != NumTypes; ++I) |
| 6238 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 6239 | SizeType = Types[I]; |
| 6240 | break; |
| 6241 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6242 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6243 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6244 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6245 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6246 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6247 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6248 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6249 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6250 | QualType |
| 6251 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6252 | ArrayType::ArraySizeModifier SizeMod, |
| 6253 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6254 | unsigned IndexTypeQuals, |
| 6255 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6256 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6257 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6258 | } |
| 6259 | |
| 6260 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6261 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6262 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6263 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6264 | unsigned IndexTypeQuals, |
| 6265 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6266 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6267 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6268 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6269 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6270 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6271 | QualType |
| 6272 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6273 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6274 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6275 | unsigned IndexTypeQuals, |
| 6276 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6277 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6278 | SizeExpr.takeAs<Expr>(), |
| 6279 | IndexTypeQuals, BracketsRange); |
| 6280 | } |
| 6281 | |
| 6282 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6283 | QualType |
| 6284 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6285 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6286 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6287 | unsigned IndexTypeQuals, |
| 6288 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6289 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6290 | SizeExpr.takeAs<Expr>(), |
| 6291 | IndexTypeQuals, BracketsRange); |
| 6292 | } |
| 6293 | |
| 6294 | template<typename Derived> |
| 6295 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 6296 | unsigned NumElements, |
| 6297 | bool IsAltiVec, bool IsPixel) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6298 | // FIXME: semantic checking! |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 6299 | return SemaRef.Context.getVectorType(ElementType, NumElements, |
| 6300 | IsAltiVec, IsPixel); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6301 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6302 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6303 | template<typename Derived> |
| 6304 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 6305 | unsigned NumElements, |
| 6306 | SourceLocation AttributeLoc) { |
| 6307 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 6308 | NumElements, true); |
| 6309 | IntegerLiteral *VectorSize |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6310 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6311 | AttributeLoc); |
| 6312 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 6313 | AttributeLoc); |
| 6314 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6315 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6316 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6317 | QualType |
| 6318 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6319 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6320 | SourceLocation AttributeLoc) { |
| 6321 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 6322 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6323 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6324 | template<typename Derived> |
| 6325 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6326 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6327 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6328 | bool Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6329 | unsigned Quals) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6330 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6331 | Quals, |
| 6332 | getDerived().getBaseLocation(), |
| 6333 | getDerived().getBaseEntity()); |
| 6334 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6335 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6336 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6337 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 6338 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 6339 | } |
| 6340 | |
| 6341 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6342 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 6343 | assert(D && "no decl found"); |
| 6344 | if (D->isInvalidDecl()) return QualType(); |
| 6345 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6346 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6347 | TypeDecl *Ty; |
| 6348 | if (isa<UsingDecl>(D)) { |
| 6349 | UsingDecl *Using = cast<UsingDecl>(D); |
| 6350 | assert(Using->isTypeName() && |
| 6351 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 6352 | |
| 6353 | // A valid resolved using typename decl points to exactly one type decl. |
| 6354 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 6355 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6356 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6357 | } else { |
| 6358 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 6359 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 6360 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 6361 | } |
| 6362 | |
| 6363 | return SemaRef.Context.getTypeDeclType(Ty); |
| 6364 | } |
| 6365 | |
| 6366 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6367 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6368 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 6369 | } |
| 6370 | |
| 6371 | template<typename Derived> |
| 6372 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 6373 | return SemaRef.Context.getTypeOfType(Underlying); |
| 6374 | } |
| 6375 | |
| 6376 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6377 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6378 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 6379 | } |
| 6380 | |
| 6381 | template<typename Derived> |
| 6382 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6383 | TemplateName Template, |
| 6384 | SourceLocation TemplateNameLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6385 | const TemplateArgumentListInfo &TemplateArgs) { |
| 6386 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6387 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6388 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6389 | template<typename Derived> |
| 6390 | NestedNameSpecifier * |
| 6391 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6392 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6393 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6394 | QualType ObjectType, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6395 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6396 | CXXScopeSpec SS; |
| 6397 | // FIXME: The source location information is all wrong. |
| 6398 | SS.setRange(Range); |
| 6399 | SS.setScopeRep(Prefix); |
| 6400 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6401 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 6402 | Range.getEnd(), II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6403 | ObjectType, |
| 6404 | FirstQualifierInScope, |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 6405 | false, false)); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6406 | } |
| 6407 | |
| 6408 | template<typename Derived> |
| 6409 | NestedNameSpecifier * |
| 6410 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6411 | SourceRange Range, |
| 6412 | NamespaceDecl *NS) { |
| 6413 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 6414 | } |
| 6415 | |
| 6416 | template<typename Derived> |
| 6417 | NestedNameSpecifier * |
| 6418 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6419 | SourceRange Range, |
| 6420 | bool TemplateKW, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 6421 | QualType T) { |
| 6422 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6423 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 6424 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6425 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 6426 | T.getTypePtr()); |
| 6427 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6428 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6429 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 6430 | return 0; |
| 6431 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6432 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6433 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6434 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6435 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6436 | bool TemplateKW, |
| 6437 | TemplateDecl *Template) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6438 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6439 | Template); |
| 6440 | } |
| 6441 | |
| 6442 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6443 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6444 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6445 | const IdentifierInfo &II, |
| 6446 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6447 | CXXScopeSpec SS; |
| 6448 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6449 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 6450 | UnqualifiedId Name; |
| 6451 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6452 | return getSema().ActOnDependentTemplateName( |
| 6453 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6454 | SS, |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 6455 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 6456 | ObjectType.getAsOpaquePtr(), |
| 6457 | /*EnteringContext=*/false) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6458 | .template getAsVal<TemplateName>(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6459 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6460 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6461 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6462 | TemplateName |
| 6463 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6464 | OverloadedOperatorKind Operator, |
| 6465 | QualType ObjectType) { |
| 6466 | CXXScopeSpec SS; |
| 6467 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 6468 | SS.setScopeRep(Qualifier); |
| 6469 | UnqualifiedId Name; |
| 6470 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 6471 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 6472 | Operator, SymbolLocations); |
| 6473 | return getSema().ActOnDependentTemplateName( |
| 6474 | /*FIXME:*/getDerived().getBaseLocation(), |
| 6475 | SS, |
| 6476 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 6477 | ObjectType.getAsOpaquePtr(), |
| 6478 | /*EnteringContext=*/false) |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6479 | .template getAsVal<TemplateName>(); |
| 6480 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6481 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6482 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6483 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6484 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 6485 | SourceLocation OpLoc, |
| 6486 | ExprArg Callee, |
| 6487 | ExprArg First, |
| 6488 | ExprArg Second) { |
| 6489 | Expr *FirstExpr = (Expr *)First.get(); |
| 6490 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6491 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6492 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6493 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6494 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6495 | if (Op == OO_Subscript) { |
| 6496 | if (!FirstExpr->getType()->isOverloadableType() && |
| 6497 | !SecondExpr->getType()->isOverloadableType()) |
| 6498 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6499 | CalleeExpr->getLocStart(), |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6500 | move(Second), OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 6501 | } else if (Op == OO_Arrow) { |
| 6502 | // -> is never a builtin operation. |
| 6503 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6504 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6505 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 6506 | // The argument is not of overloadable type, so try to create a |
| 6507 | // built-in unary operation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6508 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6509 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6510 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6511 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 6512 | } |
| 6513 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6514 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6515 | !SecondExpr->getType()->isOverloadableType()) { |
| 6516 | // Neither of the arguments is an overloadable type, so try to |
| 6517 | // create a built-in binary operation. |
| 6518 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6519 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6520 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 6521 | if (Result.isInvalid()) |
| 6522 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6523 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6524 | First.release(); |
| 6525 | Second.release(); |
| 6526 | return move(Result); |
| 6527 | } |
| 6528 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6529 | |
| 6530 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6531 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6532 | UnresolvedSet<16> Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6533 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6534 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 6535 | assert(ULE->requiresADL()); |
| 6536 | |
| 6537 | // FIXME: Do we have to check |
| 6538 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6539 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6540 | } else { |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6541 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6542 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6543 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6544 | // Add any functions found via argument-dependent lookup. |
| 6545 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 6546 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6547 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6548 | // Create the overloaded operator invocation for unary operators. |
| 6549 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6550 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6551 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 6552 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 6553 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6554 | |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6555 | if (Op == OO_Subscript) |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6556 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 6557 | OpLoc, |
| 6558 | move(First), |
| 6559 | move(Second)); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6560 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6561 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6562 | BinaryOperator::Opcode Opc = |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6563 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6564 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6565 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 6566 | if (Result.isInvalid()) |
| 6567 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6568 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6569 | First.release(); |
| 6570 | Second.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6571 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6572 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6573 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6574 | template<typename Derived> |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6575 | Sema::OwningExprResult |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6576 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 6577 | SourceLocation OperatorLoc, |
| 6578 | bool isArrow, |
| 6579 | NestedNameSpecifier *Qualifier, |
| 6580 | SourceRange QualifierRange, |
| 6581 | TypeSourceInfo *ScopeType, |
| 6582 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6583 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6584 | PseudoDestructorTypeStorage Destroyed) { |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6585 | CXXScopeSpec SS; |
| 6586 | if (Qualifier) { |
| 6587 | SS.setRange(QualifierRange); |
| 6588 | SS.setScopeRep(Qualifier); |
| 6589 | } |
| 6590 | |
| 6591 | Expr *BaseE = (Expr *)Base.get(); |
| 6592 | QualType BaseType = BaseE->getType(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6593 | if (BaseE->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6594 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6595 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | bf2ca2f | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 6596 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 6597 | ->template getAs<RecordType>())){ |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6598 | // This pseudo-destructor expression is still a pseudo-destructor. |
| 6599 | return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc, |
| 6600 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6601 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6602 | Destroyed, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6603 | /*FIXME?*/true); |
| 6604 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6605 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6606 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6607 | DeclarationName Name |
| 6608 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 6609 | SemaRef.Context.getCanonicalType(DestroyedType->getType())); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6610 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6611 | // FIXME: the ScopeType should be tacked onto SS. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6612 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6613 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 6614 | OperatorLoc, isArrow, |
| 6615 | SS, /*FIXME: FirstQualifier*/ 0, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6616 | Name, Destroyed.getLocation(), |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6617 | /*TemplateArgs*/ 0); |
| 6618 | } |
| 6619 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6620 | } // end namespace clang |
| 6621 | |
| 6622 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |