blob: f9ffd3f41aa5bdbb58a88df54b373fba16f77f6b [file] [log] [blame]
John McCalla2becad2009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregor577f75a2009-08-04 16:50:30 +00002//
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 McCallf7a1a742009-11-24 19:00:30 +000017#include "Lookup.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000020#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000021#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000023#include "clang/AST/Stmt.h"
24#include "clang/AST/StmtCXX.h"
25#include "clang/AST/StmtObjC.h"
John McCalla2becad2009-10-21 00:40:46 +000026#include "clang/AST/TypeLocBuilder.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000027#include "clang/Parse/Ownership.h"
28#include "clang/Parse/Designator.h"
29#include "clang/Lex/Preprocessor.h"
John McCalla2becad2009-10-21 00:40:46 +000030#include "llvm/Support/ErrorHandling.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000031#include <algorithm>
32
33namespace clang {
Mike Stump1eb44332009-09-09 15:08:12 +000034
Douglas Gregor577f75a2009-08-04 16:50:30 +000035/// \brief A semantic tree transformation that allows one to transform one
36/// abstract syntax tree into another.
37///
Mike Stump1eb44332009-09-09 15:08:12 +000038/// 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 Gregor577f75a2009-08-04 16:50:30 +000041/// 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 Stump1eb44332009-09-09 15:08:12 +000048/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000049/// 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 Stump1eb44332009-09-09 15:08:12 +000063/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000064/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000065/// 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 Gregor43959a92009-08-20 07:17:43 +000071/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000072/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000073/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000074/// 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 Stump1eb44332009-09-09 15:08:12 +000081/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000082/// (\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 Gregor577f75a2009-08-04 16:50:30 +000086template<typename Derived>
87class TreeTransform {
88protected:
89 Sema &SemaRef;
Mike Stump1eb44332009-09-09 15:08:12 +000090
91public:
Douglas Gregorb98b1992009-08-11 05:31:07 +000092 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 Gregor43959a92009-08-20 07:17:43 +000097 typedef Sema::MultiStmtArg MultiStmtArg;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +000098 typedef Sema::DeclPtrTy DeclPtrTy;
99
Douglas Gregor577f75a2009-08-04 16:50:30 +0000100 /// \brief Initializes a new tree transformer.
101 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000102
Douglas Gregor577f75a2009-08-04 16:50:30 +0000103 /// \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 Stump1eb44332009-09-09 15:08:12 +0000107 const Derived &getDerived() const {
108 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000109 }
110
111 /// \brief Retrieves a reference to the semantic analysis object used for
112 /// this tree transform.
113 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000114
Douglas Gregor577f75a2009-08-04 16:50:30 +0000115 /// \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 Stump1eb44332009-09-09 15:08:12 +0000121
Douglas Gregor577f75a2009-08-04 16:50:30 +0000122 /// \brief Returns the location of the entity being transformed, if that
123 /// information was not available elsewhere in the AST.
124 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000125 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000126 /// provide an alternative implementation that provides better location
127 /// information.
128 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000129
Douglas Gregor577f75a2009-08-04 16:50:30 +0000130 /// \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 Gregorb98b1992009-08-11 05:31:07 +0000137 /// \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 Stump1eb44332009-09-09 15:08:12 +0000143
Douglas Gregorb98b1992009-08-11 05:31:07 +0000144 /// \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 Stump1eb44332009-09-09 15:08:12 +0000150
Douglas Gregorb98b1992009-08-11 05:31:07 +0000151 public:
152 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000153 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000154 OldLocation = Self.getDerived().getBaseLocation();
155 OldEntity = Self.getDerived().getBaseEntity();
156 Self.getDerived().setBase(Location, Entity);
157 }
Mike Stump1eb44332009-09-09 15:08:12 +0000158
Douglas Gregorb98b1992009-08-11 05:31:07 +0000159 ~TemporaryBase() {
160 Self.getDerived().setBase(OldLocation, OldEntity);
161 }
162 };
Mike Stump1eb44332009-09-09 15:08:12 +0000163
164 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000165 /// transformed.
166 ///
167 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000168 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000169 /// 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 Gregor6eef5192009-12-14 19:27:10 +0000175 /// \brief Determine whether the given call argument should be dropped, e.g.,
176 /// because it is a default argument.
177 ///
178 /// Subclasses can provide an alternative implementation of this routine to
179 /// determine which kinds of call arguments get dropped. By default,
180 /// CXXDefaultArgument nodes are dropped (prior to transformation).
181 bool DropCallArgument(Expr *E) {
182 return E->isDefaultArgument();
183 }
184
Douglas Gregor577f75a2009-08-04 16:50:30 +0000185 /// \brief Transforms the given type into another type.
186 ///
John McCalla2becad2009-10-21 00:40:46 +0000187 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000188 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000189 /// function. This is expensive, but we don't mind, because
190 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000191 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000192 ///
193 /// \returns the transformed type.
Douglas Gregor124b8782010-02-16 19:09:40 +0000194 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000195
John McCalla2becad2009-10-21 00:40:46 +0000196 /// \brief Transforms the given type-with-location into a new
197 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000198 ///
John McCalla2becad2009-10-21 00:40:46 +0000199 /// By default, this routine transforms a type by delegating to the
200 /// appropriate TransformXXXType to build a new type. Subclasses
201 /// may override this function (to take over all type
202 /// transformations) or some set of the TransformXXXType functions
203 /// to alter the transformation.
Douglas Gregor124b8782010-02-16 19:09:40 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
205 QualType ObjectType = QualType());
John McCalla2becad2009-10-21 00:40:46 +0000206
207 /// \brief Transform the given type-with-location into a new
208 /// type, collecting location information in the given builder
209 /// as necessary.
210 ///
Douglas Gregor124b8782010-02-16 19:09:40 +0000211 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
212 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000213
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000214 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000215 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000216 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000217 /// 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 Gregorb98b1992009-08-11 05:31:07 +0000223 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000224
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000225 /// \brief Transform the given expression.
226 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000227 /// 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 McCall454feb92009-12-08 09:21:05 +0000233 OwningExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000234
Douglas Gregor577f75a2009-08-04 16:50:30 +0000235 /// \brief Transform the given declaration, which is referenced from a type
236 /// or expression.
237 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000238 /// By default, acts as the identity function on declarations. Subclasses
239 /// may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000240 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000241
242 /// \brief Transform the definition of the given declaration.
243 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000244 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000245 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000246 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +0000247 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000248 }
Mike Stump1eb44332009-09-09 15:08:12 +0000249
Douglas Gregor6cd21982009-10-20 05:58:46 +0000250 /// \brief Transform the given declaration, which was the first part of a
251 /// nested-name-specifier in a member access expression.
252 ///
253 /// This specific declaration transformation only applies to the first
254 /// identifier in a nested-name-specifier of a member access expression, e.g.,
255 /// the \c T in \c x->T::member
256 ///
257 /// By default, invokes TransformDecl() to transform the declaration.
258 /// Subclasses may override this function to provide alternate behavior.
259 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000260 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000261 }
262
Douglas Gregor577f75a2009-08-04 16:50:30 +0000263 /// \brief Transform the given nested-name-specifier.
264 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000265 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000266 /// nested-name-specifier. Subclasses may override this function to provide
267 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000268 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000269 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000270 QualType ObjectType = QualType(),
271 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000272
Douglas Gregor81499bb2009-09-03 22:13:48 +0000273 /// \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 Gregordd62b152009-10-19 22:04:39 +0000280 SourceLocation Loc,
281 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000282
Douglas Gregor577f75a2009-08-04 16:50:30 +0000283 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000284 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000285 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000286 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000287 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000288 TemplateName TransformTemplateName(TemplateName Name,
289 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000290
Douglas Gregor577f75a2009-08-04 16:50:30 +0000291 /// \brief Transform the given template argument.
292 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000293 /// By default, this operation transforms the type, expression, or
294 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000295 /// new template argument from the transformed result. Subclasses may
296 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000297 ///
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 McCalla93c9342009-12-07 02:54:59 +0000306 /// \brief Fakes up a TypeSourceInfo for a type.
307 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
308 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000309 getDerived().getBaseLocation());
310 }
Mike Stump1eb44332009-09-09 15:08:12 +0000311
John McCalla2becad2009-10-21 00:40:46 +0000312#define ABSTRACT_TYPELOC(CLASS, PARENT)
313#define TYPELOC(CLASS, PARENT) \
Douglas Gregor124b8782010-02-16 19:09:40 +0000314 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
315 QualType ObjectType = QualType());
John McCalla2becad2009-10-21 00:40:46 +0000316#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000317
John McCall21ef0fa2010-03-11 09:03:00 +0000318 /// \brief Transforms the parameters of a function type into the
319 /// given vectors.
320 ///
321 /// The result vectors should be kept in sync; null entries in the
322 /// variables vector are acceptable.
323 ///
324 /// Return true on error.
325 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
326 llvm::SmallVectorImpl<QualType> &PTypes,
327 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
328
329 /// \brief Transforms a single function-type parameter. Return null
330 /// on error.
331 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
332
Douglas Gregor124b8782010-02-16 19:09:40 +0000333 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
334 QualType ObjectType);
John McCall85737a72009-10-30 00:06:24 +0000335
Douglas Gregordd62b152009-10-19 22:04:39 +0000336 QualType
337 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
338 QualType ObjectType);
John McCall833ca992009-10-29 08:12:44 +0000339
Douglas Gregor43959a92009-08-20 07:17:43 +0000340 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Mike Stump1eb44332009-09-09 15:08:12 +0000341
Douglas Gregor43959a92009-08-20 07:17:43 +0000342#define STMT(Node, Parent) \
343 OwningStmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000344#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +0000345 OwningExprResult Transform##Node(Node *E);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000346#define ABSTRACT_EXPR(Node, Parent)
347#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +0000348
Douglas Gregor577f75a2009-08-04 16:50:30 +0000349 /// \brief Build a new pointer type given its pointee type.
350 ///
351 /// By default, performs semantic analysis when building the pointer type.
352 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000353 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000354
355 /// \brief Build a new block pointer type given its pointee type.
356 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000357 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000358 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000359 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000360
John McCall85737a72009-10-30 00:06:24 +0000361 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000362 ///
John McCall85737a72009-10-30 00:06:24 +0000363 /// By default, performs semantic analysis when building the
364 /// reference type. Subclasses may override this routine to provide
365 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000366 ///
John McCall85737a72009-10-30 00:06:24 +0000367 /// \param LValue whether the type was written with an lvalue sigil
368 /// or an rvalue sigil.
369 QualType RebuildReferenceType(QualType ReferentType,
370 bool LValue,
371 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000372
Douglas Gregor577f75a2009-08-04 16:50:30 +0000373 /// \brief Build a new member pointer type given the pointee type and the
374 /// class type it refers into.
375 ///
376 /// By default, performs semantic analysis when building the member pointer
377 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000378 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
379 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000380
John McCalla2becad2009-10-21 00:40:46 +0000381 /// \brief Build a new Objective C object pointer type.
John McCall85737a72009-10-30 00:06:24 +0000382 QualType RebuildObjCObjectPointerType(QualType PointeeType,
383 SourceLocation Sigil);
John McCalla2becad2009-10-21 00:40:46 +0000384
Douglas Gregor577f75a2009-08-04 16:50:30 +0000385 /// \brief Build a new array type given the element type, size
386 /// modifier, size of the array (if known), size expression, and index type
387 /// qualifiers.
388 ///
389 /// By default, performs semantic analysis when building the array type.
390 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000391 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000392 QualType RebuildArrayType(QualType ElementType,
393 ArrayType::ArraySizeModifier SizeMod,
394 const llvm::APInt *Size,
395 Expr *SizeExpr,
396 unsigned IndexTypeQuals,
397 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000398
Douglas Gregor577f75a2009-08-04 16:50:30 +0000399 /// \brief Build a new constant array type given the element type, size
400 /// modifier, (known) size of the array, and index type qualifiers.
401 ///
402 /// By default, performs semantic analysis when building the array type.
403 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000404 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000405 ArrayType::ArraySizeModifier SizeMod,
406 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000407 unsigned IndexTypeQuals,
408 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000409
Douglas Gregor577f75a2009-08-04 16:50:30 +0000410 /// \brief Build a new incomplete array type given the element type, size
411 /// modifier, and index type qualifiers.
412 ///
413 /// By default, performs semantic analysis when building the array type.
414 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000415 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000416 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000417 unsigned IndexTypeQuals,
418 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000419
Mike Stump1eb44332009-09-09 15:08:12 +0000420 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000421 /// size modifier, size expression, and index type qualifiers.
422 ///
423 /// By default, performs semantic analysis when building the array type.
424 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000425 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000426 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000427 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000428 unsigned IndexTypeQuals,
429 SourceRange BracketsRange);
430
Mike Stump1eb44332009-09-09 15:08:12 +0000431 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000432 /// size modifier, size expression, and index type qualifiers.
433 ///
434 /// By default, performs semantic analysis when building the array type.
435 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000436 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000437 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000438 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000439 unsigned IndexTypeQuals,
440 SourceRange BracketsRange);
441
442 /// \brief Build a new vector type given the element type and
443 /// number of elements.
444 ///
445 /// By default, performs semantic analysis when building the vector type.
446 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000447 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
448 bool IsAltiVec, bool IsPixel);
Mike Stump1eb44332009-09-09 15:08:12 +0000449
Douglas Gregor577f75a2009-08-04 16:50:30 +0000450 /// \brief Build a new extended vector type given the element type and
451 /// number of elements.
452 ///
453 /// By default, performs semantic analysis when building the vector type.
454 /// Subclasses may override this routine to provide different behavior.
455 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
456 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000457
458 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000459 /// given the element type and number of elements.
460 ///
461 /// By default, performs semantic analysis when building the vector type.
462 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000463 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000464 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000465 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000466
Douglas Gregor577f75a2009-08-04 16:50:30 +0000467 /// \brief Build a new function type.
468 ///
469 /// By default, performs semantic analysis when building the function type.
470 /// Subclasses may override this routine to provide different behavior.
471 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000472 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000473 unsigned NumParamTypes,
474 bool Variadic, unsigned Quals);
Mike Stump1eb44332009-09-09 15:08:12 +0000475
John McCalla2becad2009-10-21 00:40:46 +0000476 /// \brief Build a new unprototyped function type.
477 QualType RebuildFunctionNoProtoType(QualType ResultType);
478
John McCalled976492009-12-04 22:46:56 +0000479 /// \brief Rebuild an unresolved typename type, given the decl that
480 /// the UnresolvedUsingTypenameDecl was transformed to.
481 QualType RebuildUnresolvedUsingType(Decl *D);
482
Douglas Gregor577f75a2009-08-04 16:50:30 +0000483 /// \brief Build a new typedef type.
484 QualType RebuildTypedefType(TypedefDecl *Typedef) {
485 return SemaRef.Context.getTypeDeclType(Typedef);
486 }
487
488 /// \brief Build a new class/struct/union type.
489 QualType RebuildRecordType(RecordDecl *Record) {
490 return SemaRef.Context.getTypeDeclType(Record);
491 }
492
493 /// \brief Build a new Enum type.
494 QualType RebuildEnumType(EnumDecl *Enum) {
495 return SemaRef.Context.getTypeDeclType(Enum);
496 }
John McCall7da24312009-09-05 00:15:47 +0000497
498 /// \brief Build a new elaborated type.
499 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
500 return SemaRef.Context.getElaboratedType(T, Tag);
501 }
Mike Stump1eb44332009-09-09 15:08:12 +0000502
503 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000504 ///
505 /// By default, performs semantic analysis when building the typeof type.
506 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000507 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000508
Mike Stump1eb44332009-09-09 15:08:12 +0000509 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000510 ///
511 /// By default, builds a new TypeOfType with the given underlying type.
512 QualType RebuildTypeOfType(QualType Underlying);
513
Mike Stump1eb44332009-09-09 15:08:12 +0000514 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000515 ///
516 /// By default, performs semantic analysis when building the decltype type.
517 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000518 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump1eb44332009-09-09 15:08:12 +0000519
Douglas Gregor577f75a2009-08-04 16:50:30 +0000520 /// \brief Build a new template specialization type.
521 ///
522 /// By default, performs semantic analysis when building the template
523 /// specialization type. Subclasses may override this routine to provide
524 /// different behavior.
525 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000526 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000527 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000528
Douglas Gregor577f75a2009-08-04 16:50:30 +0000529 /// \brief Build a new qualified name type.
530 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000531 /// By default, builds a new QualifiedNameType type from the
532 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregor577f75a2009-08-04 16:50:30 +0000533 /// this routine to provide different behavior.
534 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
535 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000536 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000537
538 /// \brief Build a new typename type that refers to a template-id.
539 ///
Douglas Gregor40336422010-03-31 22:19:08 +0000540 /// By default, builds a new DependentNameType type from the
541 /// nested-name-specifier
Mike Stump1eb44332009-09-09 15:08:12 +0000542 /// and the given type. Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000543 /// different behavior.
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000544 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
545 NestedNameSpecifier *NNS, QualType T) {
Douglas Gregorae628892010-02-13 06:05:33 +0000546 if (NNS->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000547 // If the name is still dependent, just build a new dependent name type.
Douglas Gregorae628892010-02-13 06:05:33 +0000548 CXXScopeSpec SS;
549 SS.setScopeRep(NNS);
550 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000551 return SemaRef.Context.getDependentNameType(Keyword, NNS,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000552 cast<TemplateSpecializationType>(T));
Douglas Gregorae628892010-02-13 06:05:33 +0000553 }
Douglas Gregor40336422010-03-31 22:19:08 +0000554
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000555 // FIXME: Handle elaborated-type-specifiers separately.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000556 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000557 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000558
559 /// \brief Build a new typename type that refers to an identifier.
560 ///
561 /// By default, performs semantic analysis when building the typename type
Mike Stump1eb44332009-09-09 15:08:12 +0000562 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000563 /// different behavior.
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000564 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
565 NestedNameSpecifier *NNS,
566 const IdentifierInfo *Id,
567 SourceRange SR) {
Douglas Gregor40336422010-03-31 22:19:08 +0000568 CXXScopeSpec SS;
569 SS.setScopeRep(NNS);
570
571 if (NNS->isDependent()) {
572 // If the name is still dependent, just build a new dependent name type.
573 if (!SemaRef.computeDeclContext(SS))
574 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
575 }
576
577 TagDecl::TagKind Kind = TagDecl::TK_enum;
578 switch (Keyword) {
579 case ETK_None:
580 // FIXME: Note the lack of the "typename" specifier!
581 // Fall through
582 case ETK_Typename:
583 return SemaRef.CheckTypenameType(NNS, *Id, SR);
584
585 case ETK_Class: Kind = TagDecl::TK_class; break;
586 case ETK_Struct: Kind = TagDecl::TK_struct; break;
587 case ETK_Union: Kind = TagDecl::TK_union; break;
588 case ETK_Enum: Kind = TagDecl::TK_enum; break;
589 }
590
591 // We had a dependent elaborated-type-specifier that as been transformed
592 // into a non-dependent elaborated-type-specifier. Find the tag we're
593 // referring to.
594 LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName);
595 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
596 if (!DC)
597 return QualType();
598
599 TagDecl *Tag = 0;
600 SemaRef.LookupQualifiedName(Result, DC);
601 switch (Result.getResultKind()) {
602 case LookupResult::NotFound:
603 case LookupResult::NotFoundInCurrentInstantiation:
604 break;
605
606 case LookupResult::Found:
607 Tag = Result.getAsSingle<TagDecl>();
608 break;
609
610 case LookupResult::FoundOverloaded:
611 case LookupResult::FoundUnresolvedValue:
612 llvm_unreachable("Tag lookup cannot find non-tags");
613 return QualType();
614
615 case LookupResult::Ambiguous:
616 // Let the LookupResult structure handle ambiguities.
617 return QualType();
618 }
619
620 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000621 // FIXME: Would be nice to highlight just the source range.
Douglas Gregor40336422010-03-31 22:19:08 +0000622 SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000623 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000624 return QualType();
625 }
626
627 // FIXME: Terrible location information
628 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) {
629 SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id;
630 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
631 return QualType();
632 }
633
634 // Build the elaborated-type-specifier type.
635 QualType T = SemaRef.Context.getTypeDeclType(Tag);
636 T = SemaRef.Context.getQualifiedNameType(NNS, T);
637 return SemaRef.Context.getElaboratedType(T, Kind);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000638 }
Mike Stump1eb44332009-09-09 15:08:12 +0000639
Douglas Gregordcee1a12009-08-06 05:28:30 +0000640 /// \brief Build a new nested-name-specifier given the prefix and an
641 /// identifier that names the next step in the nested-name-specifier.
642 ///
643 /// By default, performs semantic analysis when building the new
644 /// nested-name-specifier. Subclasses may override this routine to provide
645 /// different behavior.
646 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
647 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000648 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000649 QualType ObjectType,
650 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000651
652 /// \brief Build a new nested-name-specifier given the prefix and the
653 /// namespace named in the next step in the nested-name-specifier.
654 ///
655 /// By default, performs semantic analysis when building the new
656 /// nested-name-specifier. Subclasses may override this routine to provide
657 /// different behavior.
658 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
659 SourceRange Range,
660 NamespaceDecl *NS);
661
662 /// \brief Build a new nested-name-specifier given the prefix and the
663 /// type named in the next step in the nested-name-specifier.
664 ///
665 /// By default, performs semantic analysis when building the new
666 /// nested-name-specifier. Subclasses may override this routine to provide
667 /// different behavior.
668 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
669 SourceRange Range,
670 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000671 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000672
673 /// \brief Build a new template name given a nested name specifier, a flag
674 /// indicating whether the "template" keyword was provided, and the template
675 /// that the template name refers to.
676 ///
677 /// By default, builds the new template name directly. Subclasses may override
678 /// this routine to provide different behavior.
679 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
680 bool TemplateKW,
681 TemplateDecl *Template);
682
Douglas Gregord1067e52009-08-06 06:41:21 +0000683 /// \brief Build a new template name given a nested name specifier and the
684 /// name that is referred to as a template.
685 ///
686 /// By default, performs semantic analysis to determine whether the name can
687 /// be resolved to a specific template, then builds the appropriate kind of
688 /// template name. Subclasses may override this routine to provide different
689 /// behavior.
690 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000691 const IdentifierInfo &II,
692 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000693
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000694 /// \brief Build a new template name given a nested name specifier and the
695 /// overloaded operator name that is referred to as a template.
696 ///
697 /// By default, performs semantic analysis to determine whether the name can
698 /// be resolved to a specific template, then builds the appropriate kind of
699 /// template name. Subclasses may override this routine to provide different
700 /// behavior.
701 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
702 OverloadedOperatorKind Operator,
703 QualType ObjectType);
704
Douglas Gregor43959a92009-08-20 07:17:43 +0000705 /// \brief Build a new compound statement.
706 ///
707 /// By default, performs semantic analysis to build the new statement.
708 /// Subclasses may override this routine to provide different behavior.
709 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
710 MultiStmtArg Statements,
711 SourceLocation RBraceLoc,
712 bool IsStmtExpr) {
713 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
714 IsStmtExpr);
715 }
716
717 /// \brief Build a new case statement.
718 ///
719 /// By default, performs semantic analysis to build the new statement.
720 /// Subclasses may override this routine to provide different behavior.
721 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
722 ExprArg LHS,
723 SourceLocation EllipsisLoc,
724 ExprArg RHS,
725 SourceLocation ColonLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000726 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregor43959a92009-08-20 07:17:43 +0000727 ColonLoc);
728 }
Mike Stump1eb44332009-09-09 15:08:12 +0000729
Douglas Gregor43959a92009-08-20 07:17:43 +0000730 /// \brief Attach the body to a new case statement.
731 ///
732 /// By default, performs semantic analysis to build the new statement.
733 /// Subclasses may override this routine to provide different behavior.
734 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
735 getSema().ActOnCaseStmtBody(S.get(), move(Body));
736 return move(S);
737 }
Mike Stump1eb44332009-09-09 15:08:12 +0000738
Douglas Gregor43959a92009-08-20 07:17:43 +0000739 /// \brief Build a new default statement.
740 ///
741 /// By default, performs semantic analysis to build the new statement.
742 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000743 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000744 SourceLocation ColonLoc,
745 StmtArg SubStmt) {
Mike Stump1eb44332009-09-09 15:08:12 +0000746 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregor43959a92009-08-20 07:17:43 +0000747 /*CurScope=*/0);
748 }
Mike Stump1eb44332009-09-09 15:08:12 +0000749
Douglas Gregor43959a92009-08-20 07:17:43 +0000750 /// \brief Build a new label statement.
751 ///
752 /// By default, performs semantic analysis to build the new statement.
753 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000754 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000755 IdentifierInfo *Id,
756 SourceLocation ColonLoc,
757 StmtArg SubStmt) {
758 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
759 }
Mike Stump1eb44332009-09-09 15:08:12 +0000760
Douglas Gregor43959a92009-08-20 07:17:43 +0000761 /// \brief Build a new "if" statement.
762 ///
763 /// By default, performs semantic analysis to build the new statement.
764 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000765 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000766 VarDecl *CondVar, StmtArg Then,
767 SourceLocation ElseLoc, StmtArg Else) {
768 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
769 move(Then), ElseLoc, move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +0000770 }
Mike Stump1eb44332009-09-09 15:08:12 +0000771
Douglas Gregor43959a92009-08-20 07:17:43 +0000772 /// \brief Start building a new switch statement.
773 ///
774 /// By default, performs semantic analysis to build the new statement.
775 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000776 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
777 VarDecl *CondVar) {
778 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregor43959a92009-08-20 07:17:43 +0000779 }
Mike Stump1eb44332009-09-09 15:08:12 +0000780
Douglas Gregor43959a92009-08-20 07:17:43 +0000781 /// \brief Attach the body to the switch statement.
782 ///
783 /// By default, performs semantic analysis to build the new statement.
784 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000785 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000786 StmtArg Switch, StmtArg Body) {
787 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
788 move(Body));
789 }
790
791 /// \brief Build a new while statement.
792 ///
793 /// By default, performs semantic analysis to build the new statement.
794 /// Subclasses may override this routine to provide different behavior.
795 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
796 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000797 VarDecl *CondVar,
Douglas Gregor43959a92009-08-20 07:17:43 +0000798 StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000799 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
800 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000801 }
Mike Stump1eb44332009-09-09 15:08:12 +0000802
Douglas Gregor43959a92009-08-20 07:17:43 +0000803 /// \brief Build a new do-while statement.
804 ///
805 /// By default, performs semantic analysis to build the new statement.
806 /// Subclasses may override this routine to provide different behavior.
807 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
808 SourceLocation WhileLoc,
809 SourceLocation LParenLoc,
810 ExprArg Cond,
811 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000812 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000813 move(Cond), RParenLoc);
814 }
815
816 /// \brief Build a new for statement.
817 ///
818 /// By default, performs semantic analysis to build the new statement.
819 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000820 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000821 SourceLocation LParenLoc,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000822 StmtArg Init, Sema::FullExprArg Cond,
823 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000824 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000825 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
826 DeclPtrTy::make(CondVar),
827 Inc, RParenLoc, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000828 }
Mike Stump1eb44332009-09-09 15:08:12 +0000829
Douglas Gregor43959a92009-08-20 07:17:43 +0000830 /// \brief Build a new goto statement.
831 ///
832 /// By default, performs semantic analysis to build the new statement.
833 /// Subclasses may override this routine to provide different behavior.
834 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
835 SourceLocation LabelLoc,
836 LabelStmt *Label) {
837 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
838 }
839
840 /// \brief Build a new indirect goto statement.
841 ///
842 /// By default, performs semantic analysis to build the new statement.
843 /// Subclasses may override this routine to provide different behavior.
844 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
845 SourceLocation StarLoc,
846 ExprArg Target) {
847 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
848 }
Mike Stump1eb44332009-09-09 15:08:12 +0000849
Douglas Gregor43959a92009-08-20 07:17:43 +0000850 /// \brief Build a new return statement.
851 ///
852 /// By default, performs semantic analysis to build the new statement.
853 /// Subclasses may override this routine to provide different behavior.
854 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
855 ExprArg Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000856
Douglas Gregor43959a92009-08-20 07:17:43 +0000857 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
858 }
Mike Stump1eb44332009-09-09 15:08:12 +0000859
Douglas Gregor43959a92009-08-20 07:17:43 +0000860 /// \brief Build a new declaration statement.
861 ///
862 /// By default, performs semantic analysis to build the new statement.
863 /// Subclasses may override this routine to provide different behavior.
864 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000865 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000866 SourceLocation EndLoc) {
867 return getSema().Owned(
868 new (getSema().Context) DeclStmt(
869 DeclGroupRef::Create(getSema().Context,
870 Decls, NumDecls),
871 StartLoc, EndLoc));
872 }
Mike Stump1eb44332009-09-09 15:08:12 +0000873
Anders Carlsson703e3942010-01-24 05:50:09 +0000874 /// \brief Build a new inline asm statement.
875 ///
876 /// By default, performs semantic analysis to build the new statement.
877 /// Subclasses may override this routine to provide different behavior.
878 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
879 bool IsSimple,
880 bool IsVolatile,
881 unsigned NumOutputs,
882 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000883 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000884 MultiExprArg Constraints,
885 MultiExprArg Exprs,
886 ExprArg AsmString,
887 MultiExprArg Clobbers,
888 SourceLocation RParenLoc,
889 bool MSAsm) {
890 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
891 NumInputs, Names, move(Constraints),
892 move(Exprs), move(AsmString), move(Clobbers),
893 RParenLoc, MSAsm);
894 }
895
Douglas Gregor43959a92009-08-20 07:17:43 +0000896 /// \brief Build a new C++ exception declaration.
897 ///
898 /// By default, performs semantic analysis to build the new decaration.
899 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000900 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000901 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000902 IdentifierInfo *Name,
903 SourceLocation Loc,
904 SourceRange TypeRange) {
Mike Stump1eb44332009-09-09 15:08:12 +0000905 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000906 TypeRange);
907 }
908
909 /// \brief Build a new C++ catch statement.
910 ///
911 /// By default, performs semantic analysis to build the new statement.
912 /// Subclasses may override this routine to provide different behavior.
913 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
914 VarDecl *ExceptionDecl,
915 StmtArg Handler) {
916 return getSema().Owned(
Mike Stump1eb44332009-09-09 15:08:12 +0000917 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregor43959a92009-08-20 07:17:43 +0000918 Handler.takeAs<Stmt>()));
919 }
Mike Stump1eb44332009-09-09 15:08:12 +0000920
Douglas Gregor43959a92009-08-20 07:17:43 +0000921 /// \brief Build a new C++ try statement.
922 ///
923 /// By default, performs semantic analysis to build the new statement.
924 /// Subclasses may override this routine to provide different behavior.
925 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
926 StmtArg TryBlock,
927 MultiStmtArg Handlers) {
928 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
929 }
Mike Stump1eb44332009-09-09 15:08:12 +0000930
Douglas Gregorb98b1992009-08-11 05:31:07 +0000931 /// \brief Build a new expression that references a declaration.
932 ///
933 /// By default, performs semantic analysis to build the new expression.
934 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +0000935 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
936 LookupResult &R,
937 bool RequiresADL) {
938 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
939 }
940
941
942 /// \brief Build a new expression that references a declaration.
943 ///
944 /// By default, performs semantic analysis to build the new expression.
945 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora2813ce2009-10-23 18:54:35 +0000946 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
947 SourceRange QualifierRange,
John McCalldbd872f2009-12-08 09:08:17 +0000948 ValueDecl *VD, SourceLocation Loc,
949 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +0000950 CXXScopeSpec SS;
951 SS.setScopeRep(Qualifier);
952 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +0000953
954 // FIXME: loses template args.
955
956 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000957 }
Mike Stump1eb44332009-09-09 15:08:12 +0000958
Douglas Gregorb98b1992009-08-11 05:31:07 +0000959 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +0000960 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000961 /// By default, performs semantic analysis to build the new expression.
962 /// Subclasses may override this routine to provide different behavior.
963 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
964 SourceLocation RParen) {
965 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
966 }
967
Douglas Gregora71d8192009-09-04 17:36:40 +0000968 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000969 ///
Douglas Gregora71d8192009-09-04 17:36:40 +0000970 /// By default, performs semantic analysis to build the new expression.
971 /// Subclasses may override this routine to provide different behavior.
972 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
973 SourceLocation OperatorLoc,
974 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000975 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +0000976 SourceRange QualifierRange,
977 TypeSourceInfo *ScopeType,
978 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +0000979 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000980 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +0000981
Douglas Gregorb98b1992009-08-11 05:31:07 +0000982 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000983 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000984 /// By default, performs semantic analysis to build the new expression.
985 /// Subclasses may override this routine to provide different behavior.
986 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
987 UnaryOperator::Opcode Opc,
988 ExprArg SubExpr) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +0000989 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +0000990 }
Mike Stump1eb44332009-09-09 15:08:12 +0000991
Douglas Gregorb98b1992009-08-11 05:31:07 +0000992 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +0000993 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000994 /// By default, performs semantic analysis to build the new expression.
995 /// Subclasses may override this routine to provide different behavior.
John McCalla93c9342009-12-07 02:54:59 +0000996 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +0000997 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000998 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +0000999 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001000 }
1001
Mike Stump1eb44332009-09-09 15:08:12 +00001002 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001003 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001004 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001005 /// By default, performs semantic analysis to build the new expression.
1006 /// Subclasses may override this routine to provide different behavior.
1007 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1008 bool isSizeOf, SourceRange R) {
Mike Stump1eb44332009-09-09 15:08:12 +00001009 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001010 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1011 OpLoc, isSizeOf, R);
1012 if (Result.isInvalid())
1013 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001014
Douglas Gregorb98b1992009-08-11 05:31:07 +00001015 SubExpr.release();
1016 return move(Result);
1017 }
Mike Stump1eb44332009-09-09 15:08:12 +00001018
Douglas Gregorb98b1992009-08-11 05:31:07 +00001019 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001020 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001021 /// By default, performs semantic analysis to build the new expression.
1022 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001023 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001024 SourceLocation LBracketLoc,
1025 ExprArg RHS,
1026 SourceLocation RBracketLoc) {
1027 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump1eb44332009-09-09 15:08:12 +00001028 LBracketLoc, move(RHS),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001029 RBracketLoc);
1030 }
1031
1032 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001033 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001034 /// By default, performs semantic analysis to build the new expression.
1035 /// Subclasses may override this routine to provide different behavior.
1036 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1037 MultiExprArg Args,
1038 SourceLocation *CommaLocs,
1039 SourceLocation RParenLoc) {
1040 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1041 move(Args), CommaLocs, RParenLoc);
1042 }
1043
1044 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001045 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001046 /// By default, performs semantic analysis to build the new expression.
1047 /// Subclasses may override this routine to provide different behavior.
1048 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001049 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001050 NestedNameSpecifier *Qualifier,
1051 SourceRange QualifierRange,
1052 SourceLocation MemberLoc,
Eli Friedmanf595cc42009-12-04 06:40:45 +00001053 ValueDecl *Member,
John McCall6bb80172010-03-30 21:47:33 +00001054 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001055 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +00001056 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001057 if (!Member->getDeclName()) {
1058 // We have a reference to an unnamed field.
1059 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +00001060
Douglas Gregor83a56c42009-12-24 20:02:50 +00001061 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall6bb80172010-03-30 21:47:33 +00001062 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1063 FoundDecl, Member))
Douglas Gregor83a56c42009-12-24 20:02:50 +00001064 return getSema().ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001065
Mike Stump1eb44332009-09-09 15:08:12 +00001066 MemberExpr *ME =
Douglas Gregor83a56c42009-12-24 20:02:50 +00001067 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlssond8b285f2009-09-01 04:26:58 +00001068 Member, MemberLoc,
1069 cast<FieldDecl>(Member)->getType());
1070 return getSema().Owned(ME);
1071 }
Mike Stump1eb44332009-09-09 15:08:12 +00001072
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001073 CXXScopeSpec SS;
1074 if (Qualifier) {
1075 SS.setRange(QualifierRange);
1076 SS.setScopeRep(Qualifier);
1077 }
1078
John McCallaa81e162009-12-01 22:10:20 +00001079 QualType BaseType = ((Expr*) Base.get())->getType();
1080
John McCall6bb80172010-03-30 21:47:33 +00001081 // FIXME: this involves duplicating earlier analysis in a lot of
1082 // cases; we should avoid this when possible.
John McCallc2233c52010-01-15 08:34:02 +00001083 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1084 Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001085 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001086 R.resolveKind();
1087
John McCallaa81e162009-12-01 22:10:20 +00001088 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1089 OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001090 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001091 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001092 }
Mike Stump1eb44332009-09-09 15:08:12 +00001093
Douglas Gregorb98b1992009-08-11 05:31:07 +00001094 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001095 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001096 /// By default, performs semantic analysis to build the new expression.
1097 /// Subclasses may override this routine to provide different behavior.
1098 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1099 BinaryOperator::Opcode Opc,
1100 ExprArg LHS, ExprArg RHS) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001101 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1102 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregorb98b1992009-08-11 05:31:07 +00001103 }
1104
1105 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001106 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001107 /// By default, performs semantic analysis to build the new expression.
1108 /// Subclasses may override this routine to provide different behavior.
1109 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1110 SourceLocation QuestionLoc,
1111 ExprArg LHS,
1112 SourceLocation ColonLoc,
1113 ExprArg RHS) {
Mike Stump1eb44332009-09-09 15:08:12 +00001114 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001115 move(LHS), move(RHS));
1116 }
1117
Douglas Gregorb98b1992009-08-11 05:31:07 +00001118 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001119 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001120 /// By default, performs semantic analysis to build the new expression.
1121 /// Subclasses may override this routine to provide different behavior.
John McCall9d125032010-01-15 18:39:57 +00001122 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1123 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001124 SourceLocation RParenLoc,
1125 ExprArg SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001126 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1127 move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001128 }
Mike Stump1eb44332009-09-09 15:08:12 +00001129
Douglas Gregorb98b1992009-08-11 05:31:07 +00001130 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001131 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001132 /// By default, performs semantic analysis to build the new expression.
1133 /// Subclasses may override this routine to provide different behavior.
1134 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001135 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001136 SourceLocation RParenLoc,
1137 ExprArg Init) {
John McCall42f56b52010-01-18 19:35:47 +00001138 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1139 move(Init));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001140 }
Mike Stump1eb44332009-09-09 15:08:12 +00001141
Douglas Gregorb98b1992009-08-11 05:31:07 +00001142 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001143 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001144 /// By default, performs semantic analysis to build the new expression.
1145 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001146 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001147 SourceLocation OpLoc,
1148 SourceLocation AccessorLoc,
1149 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001150
John McCall129e2df2009-11-30 22:42:35 +00001151 CXXScopeSpec SS;
John McCallaa81e162009-12-01 22:10:20 +00001152 QualType BaseType = ((Expr*) Base.get())->getType();
1153 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001154 OpLoc, /*IsArrow*/ false,
1155 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor2d1c2142009-11-03 19:44:04 +00001156 DeclarationName(&Accessor),
John McCall129e2df2009-11-30 22:42:35 +00001157 AccessorLoc,
1158 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001159 }
Mike Stump1eb44332009-09-09 15:08:12 +00001160
Douglas Gregorb98b1992009-08-11 05:31:07 +00001161 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001162 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001163 /// By default, performs semantic analysis to build the new expression.
1164 /// Subclasses may override this routine to provide different behavior.
1165 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1166 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001167 SourceLocation RBraceLoc,
1168 QualType ResultTy) {
1169 OwningExprResult Result
1170 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1171 if (Result.isInvalid() || ResultTy->isDependentType())
1172 return move(Result);
1173
1174 // Patch in the result type we were given, which may have been computed
1175 // when the initial InitListExpr was built.
1176 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1177 ILE->setType(ResultTy);
1178 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001179 }
Mike Stump1eb44332009-09-09 15:08:12 +00001180
Douglas Gregorb98b1992009-08-11 05:31:07 +00001181 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001182 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001183 /// By default, performs semantic analysis to build the new expression.
1184 /// Subclasses may override this routine to provide different behavior.
1185 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1186 MultiExprArg ArrayExprs,
1187 SourceLocation EqualOrColonLoc,
1188 bool GNUSyntax,
1189 ExprArg Init) {
1190 OwningExprResult Result
1191 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1192 move(Init));
1193 if (Result.isInvalid())
1194 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001195
Douglas Gregorb98b1992009-08-11 05:31:07 +00001196 ArrayExprs.release();
1197 return move(Result);
1198 }
Mike Stump1eb44332009-09-09 15:08:12 +00001199
Douglas Gregorb98b1992009-08-11 05:31:07 +00001200 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001201 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001202 /// By default, builds the implicit value initialization without performing
1203 /// any semantic analysis. Subclasses may override this routine to provide
1204 /// different behavior.
1205 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1206 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1207 }
Mike Stump1eb44332009-09-09 15:08:12 +00001208
Douglas Gregorb98b1992009-08-11 05:31:07 +00001209 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001210 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001211 /// By default, performs semantic analysis to build the new expression.
1212 /// Subclasses may override this routine to provide different behavior.
1213 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1214 QualType T, SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001215 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001216 RParenLoc);
1217 }
1218
1219 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001220 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001221 /// By default, performs semantic analysis to build the new expression.
1222 /// Subclasses may override this routine to provide different behavior.
1223 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1224 MultiExprArg SubExprs,
1225 SourceLocation RParenLoc) {
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001226 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1227 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001228 }
Mike Stump1eb44332009-09-09 15:08:12 +00001229
Douglas Gregorb98b1992009-08-11 05:31:07 +00001230 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001231 ///
1232 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001233 /// rather than attempting to map the label statement itself.
1234 /// Subclasses may override this routine to provide different behavior.
1235 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1236 SourceLocation LabelLoc,
1237 LabelStmt *Label) {
1238 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1239 }
Mike Stump1eb44332009-09-09 15:08:12 +00001240
Douglas Gregorb98b1992009-08-11 05:31:07 +00001241 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001242 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001243 /// By default, performs semantic analysis to build the new expression.
1244 /// Subclasses may override this routine to provide different behavior.
1245 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1246 StmtArg SubStmt,
1247 SourceLocation RParenLoc) {
1248 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1249 }
Mike Stump1eb44332009-09-09 15:08:12 +00001250
Douglas Gregorb98b1992009-08-11 05:31:07 +00001251 /// \brief Build a new __builtin_types_compatible_p expression.
1252 ///
1253 /// By default, performs semantic analysis to build the new expression.
1254 /// Subclasses may override this routine to provide different behavior.
1255 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1256 QualType T1, QualType T2,
1257 SourceLocation RParenLoc) {
1258 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1259 T1.getAsOpaquePtr(),
1260 T2.getAsOpaquePtr(),
1261 RParenLoc);
1262 }
Mike Stump1eb44332009-09-09 15:08:12 +00001263
Douglas Gregorb98b1992009-08-11 05:31:07 +00001264 /// \brief Build a new __builtin_choose_expr expression.
1265 ///
1266 /// By default, performs semantic analysis to build the new expression.
1267 /// Subclasses may override this routine to provide different behavior.
1268 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1269 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1270 SourceLocation RParenLoc) {
1271 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1272 move(Cond), move(LHS), move(RHS),
1273 RParenLoc);
1274 }
Mike Stump1eb44332009-09-09 15:08:12 +00001275
Douglas Gregorb98b1992009-08-11 05:31:07 +00001276 /// \brief Build a new overloaded operator call expression.
1277 ///
1278 /// By default, performs semantic analysis to build the new expression.
1279 /// The semantic analysis provides the behavior of template instantiation,
1280 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001281 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001282 /// argument-dependent lookup, etc. Subclasses may override this routine to
1283 /// provide different behavior.
1284 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1285 SourceLocation OpLoc,
1286 ExprArg Callee,
1287 ExprArg First,
1288 ExprArg Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001289
1290 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001291 /// reinterpret_cast.
1292 ///
1293 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001294 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001295 /// Subclasses may override this routine to provide different behavior.
1296 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1297 Stmt::StmtClass Class,
1298 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001299 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001300 SourceLocation RAngleLoc,
1301 SourceLocation LParenLoc,
1302 ExprArg SubExpr,
1303 SourceLocation RParenLoc) {
1304 switch (Class) {
1305 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001306 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001307 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001308 move(SubExpr), RParenLoc);
1309
1310 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001311 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001312 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001313 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001314
Douglas Gregorb98b1992009-08-11 05:31:07 +00001315 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001316 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001317 RAngleLoc, LParenLoc,
1318 move(SubExpr),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001319 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001320
Douglas Gregorb98b1992009-08-11 05:31:07 +00001321 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001322 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001323 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001324 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001325
Douglas Gregorb98b1992009-08-11 05:31:07 +00001326 default:
1327 assert(false && "Invalid C++ named cast");
1328 break;
1329 }
Mike Stump1eb44332009-09-09 15:08:12 +00001330
Douglas Gregorb98b1992009-08-11 05:31:07 +00001331 return getSema().ExprError();
1332 }
Mike Stump1eb44332009-09-09 15:08:12 +00001333
Douglas Gregorb98b1992009-08-11 05:31:07 +00001334 /// \brief Build a new C++ static_cast expression.
1335 ///
1336 /// By default, performs semantic analysis to build the new expression.
1337 /// Subclasses may override this routine to provide different behavior.
1338 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1339 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001340 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001341 SourceLocation RAngleLoc,
1342 SourceLocation LParenLoc,
1343 ExprArg SubExpr,
1344 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001345 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1346 TInfo, move(SubExpr),
1347 SourceRange(LAngleLoc, RAngleLoc),
1348 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001349 }
1350
1351 /// \brief Build a new C++ dynamic_cast expression.
1352 ///
1353 /// By default, performs semantic analysis to build the new expression.
1354 /// Subclasses may override this routine to provide different behavior.
1355 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1356 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001357 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001358 SourceLocation RAngleLoc,
1359 SourceLocation LParenLoc,
1360 ExprArg SubExpr,
1361 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001362 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1363 TInfo, move(SubExpr),
1364 SourceRange(LAngleLoc, RAngleLoc),
1365 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001366 }
1367
1368 /// \brief Build a new C++ reinterpret_cast expression.
1369 ///
1370 /// By default, performs semantic analysis to build the new expression.
1371 /// Subclasses may override this routine to provide different behavior.
1372 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1373 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001374 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001375 SourceLocation RAngleLoc,
1376 SourceLocation LParenLoc,
1377 ExprArg SubExpr,
1378 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001379 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1380 TInfo, move(SubExpr),
1381 SourceRange(LAngleLoc, RAngleLoc),
1382 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001383 }
1384
1385 /// \brief Build a new C++ const_cast expression.
1386 ///
1387 /// By default, performs semantic analysis to build the new expression.
1388 /// Subclasses may override this routine to provide different behavior.
1389 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1390 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001391 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001392 SourceLocation RAngleLoc,
1393 SourceLocation LParenLoc,
1394 ExprArg SubExpr,
1395 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001396 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1397 TInfo, move(SubExpr),
1398 SourceRange(LAngleLoc, RAngleLoc),
1399 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001400 }
Mike Stump1eb44332009-09-09 15:08:12 +00001401
Douglas Gregorb98b1992009-08-11 05:31:07 +00001402 /// \brief Build a new C++ functional-style cast expression.
1403 ///
1404 /// By default, performs semantic analysis to build the new expression.
1405 /// Subclasses may override this routine to provide different behavior.
1406 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001407 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001408 SourceLocation LParenLoc,
1409 ExprArg SubExpr,
1410 SourceLocation RParenLoc) {
Chris Lattner88650c32009-08-24 05:19:01 +00001411 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001412 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001413 TInfo->getType().getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001414 LParenLoc,
Chris Lattner88650c32009-08-24 05:19:01 +00001415 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump1eb44332009-09-09 15:08:12 +00001416 /*CommaLocs=*/0,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 RParenLoc);
1418 }
Mike Stump1eb44332009-09-09 15:08:12 +00001419
Douglas Gregorb98b1992009-08-11 05:31:07 +00001420 /// \brief Build a new C++ typeid(type) expression.
1421 ///
1422 /// By default, performs semantic analysis to build the new expression.
1423 /// Subclasses may override this routine to provide different behavior.
1424 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1425 SourceLocation LParenLoc,
1426 QualType T,
1427 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001428 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001429 T.getAsOpaquePtr(), RParenLoc);
1430 }
Mike Stump1eb44332009-09-09 15:08:12 +00001431
Douglas Gregorb98b1992009-08-11 05:31:07 +00001432 /// \brief Build a new C++ typeid(expr) expression.
1433 ///
1434 /// By default, performs semantic analysis to build the new expression.
1435 /// Subclasses may override this routine to provide different behavior.
1436 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1437 SourceLocation LParenLoc,
1438 ExprArg Operand,
1439 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001440 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001441 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1442 RParenLoc);
1443 if (Result.isInvalid())
1444 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001445
Douglas Gregorb98b1992009-08-11 05:31:07 +00001446 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1447 return move(Result);
Mike Stump1eb44332009-09-09 15:08:12 +00001448 }
1449
Douglas Gregorb98b1992009-08-11 05:31:07 +00001450 /// \brief Build a new C++ "this" expression.
1451 ///
1452 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001453 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001454 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001455 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001456 QualType ThisType,
1457 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001458 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001459 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1460 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001461 }
1462
1463 /// \brief Build a new C++ throw expression.
1464 ///
1465 /// By default, performs semantic analysis to build the new expression.
1466 /// Subclasses may override this routine to provide different behavior.
1467 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1468 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1469 }
1470
1471 /// \brief Build a new C++ default-argument expression.
1472 ///
1473 /// By default, builds a new default-argument expression, which does not
1474 /// require any semantic analysis. Subclasses may override this routine to
1475 /// provide different behavior.
Douglas Gregor036aed12009-12-23 23:03:06 +00001476 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1477 ParmVarDecl *Param) {
1478 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1479 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 }
1481
1482 /// \brief Build a new C++ zero-initialization expression.
1483 ///
1484 /// By default, performs semantic analysis to build the new expression.
1485 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001486 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 SourceLocation LParenLoc,
1488 QualType T,
1489 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001490 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1491 T.getAsOpaquePtr(), LParenLoc,
1492 MultiExprArg(getSema(), 0, 0),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 0, RParenLoc);
1494 }
Mike Stump1eb44332009-09-09 15:08:12 +00001495
Douglas Gregorb98b1992009-08-11 05:31:07 +00001496 /// \brief Build a new C++ "new" expression.
1497 ///
1498 /// By default, performs semantic analysis to build the new expression.
1499 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001500 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001501 bool UseGlobal,
1502 SourceLocation PlacementLParen,
1503 MultiExprArg PlacementArgs,
1504 SourceLocation PlacementRParen,
Mike Stump1eb44332009-09-09 15:08:12 +00001505 bool ParenTypeId,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001506 QualType AllocType,
1507 SourceLocation TypeLoc,
1508 SourceRange TypeRange,
1509 ExprArg ArraySize,
1510 SourceLocation ConstructorLParen,
1511 MultiExprArg ConstructorArgs,
1512 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001513 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001514 PlacementLParen,
1515 move(PlacementArgs),
1516 PlacementRParen,
1517 ParenTypeId,
1518 AllocType,
1519 TypeLoc,
1520 TypeRange,
1521 move(ArraySize),
1522 ConstructorLParen,
1523 move(ConstructorArgs),
1524 ConstructorRParen);
1525 }
Mike Stump1eb44332009-09-09 15:08:12 +00001526
Douglas Gregorb98b1992009-08-11 05:31:07 +00001527 /// \brief Build a new C++ "delete" expression.
1528 ///
1529 /// By default, performs semantic analysis to build the new expression.
1530 /// Subclasses may override this routine to provide different behavior.
1531 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1532 bool IsGlobalDelete,
1533 bool IsArrayForm,
1534 ExprArg Operand) {
1535 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1536 move(Operand));
1537 }
Mike Stump1eb44332009-09-09 15:08:12 +00001538
Douglas Gregorb98b1992009-08-11 05:31:07 +00001539 /// \brief Build a new unary type trait expression.
1540 ///
1541 /// By default, performs semantic analysis to build the new expression.
1542 /// Subclasses may override this routine to provide different behavior.
1543 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1544 SourceLocation StartLoc,
1545 SourceLocation LParenLoc,
1546 QualType T,
1547 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001548 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001549 T.getAsOpaquePtr(), RParenLoc);
1550 }
1551
Mike Stump1eb44332009-09-09 15:08:12 +00001552 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001553 /// expression.
1554 ///
1555 /// By default, performs semantic analysis to build the new expression.
1556 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001557 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001558 SourceRange QualifierRange,
1559 DeclarationName Name,
1560 SourceLocation Location,
John McCallf7a1a742009-11-24 19:00:30 +00001561 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001562 CXXScopeSpec SS;
1563 SS.setRange(QualifierRange);
1564 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001565
1566 if (TemplateArgs)
1567 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1568 *TemplateArgs);
1569
1570 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 }
1572
1573 /// \brief Build a new template-id expression.
1574 ///
1575 /// By default, performs semantic analysis to build the new expression.
1576 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001577 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1578 LookupResult &R,
1579 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001580 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001581 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 }
1583
1584 /// \brief Build a new object-construction expression.
1585 ///
1586 /// By default, performs semantic analysis to build the new expression.
1587 /// Subclasses may override this routine to provide different behavior.
1588 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001589 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 CXXConstructorDecl *Constructor,
1591 bool IsElidable,
1592 MultiExprArg Args) {
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001593 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1594 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1595 ConvertedArgs))
1596 return getSema().ExprError();
1597
1598 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1599 move_arg(ConvertedArgs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 }
1601
1602 /// \brief Build a new object-construction expression.
1603 ///
1604 /// By default, performs semantic analysis to build the new expression.
1605 /// Subclasses may override this routine to provide different behavior.
1606 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1607 QualType T,
1608 SourceLocation LParenLoc,
1609 MultiExprArg Args,
1610 SourceLocation *Commas,
1611 SourceLocation RParenLoc) {
1612 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1613 T.getAsOpaquePtr(),
1614 LParenLoc,
1615 move(Args),
1616 Commas,
1617 RParenLoc);
1618 }
1619
1620 /// \brief Build a new object-construction expression.
1621 ///
1622 /// By default, performs semantic analysis to build the new expression.
1623 /// Subclasses may override this routine to provide different behavior.
1624 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1625 QualType T,
1626 SourceLocation LParenLoc,
1627 MultiExprArg Args,
1628 SourceLocation *Commas,
1629 SourceLocation RParenLoc) {
1630 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1631 /*FIXME*/LParenLoc),
1632 T.getAsOpaquePtr(),
1633 LParenLoc,
1634 move(Args),
1635 Commas,
1636 RParenLoc);
1637 }
Mike Stump1eb44332009-09-09 15:08:12 +00001638
Douglas Gregorb98b1992009-08-11 05:31:07 +00001639 /// \brief Build a new member reference expression.
1640 ///
1641 /// By default, performs semantic analysis to build the new expression.
1642 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001643 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001644 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001645 bool IsArrow,
1646 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001647 NestedNameSpecifier *Qualifier,
1648 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001649 NamedDecl *FirstQualifierInScope,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001650 DeclarationName Name,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001651 SourceLocation MemberLoc,
John McCall129e2df2009-11-30 22:42:35 +00001652 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001654 SS.setRange(QualifierRange);
1655 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001656
John McCallaa81e162009-12-01 22:10:20 +00001657 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1658 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001659 SS, FirstQualifierInScope,
1660 Name, MemberLoc, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 }
1662
John McCall129e2df2009-11-30 22:42:35 +00001663 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001664 ///
1665 /// By default, performs semantic analysis to build the new expression.
1666 /// Subclasses may override this routine to provide different behavior.
John McCall129e2df2009-11-30 22:42:35 +00001667 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001668 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001669 SourceLocation OperatorLoc,
1670 bool IsArrow,
1671 NestedNameSpecifier *Qualifier,
1672 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001673 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001674 LookupResult &R,
1675 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001676 CXXScopeSpec SS;
1677 SS.setRange(QualifierRange);
1678 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001679
John McCallaa81e162009-12-01 22:10:20 +00001680 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1681 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001682 SS, FirstQualifierInScope,
1683 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001684 }
Mike Stump1eb44332009-09-09 15:08:12 +00001685
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 /// \brief Build a new Objective-C @encode expression.
1687 ///
1688 /// By default, performs semantic analysis to build the new expression.
1689 /// Subclasses may override this routine to provide different behavior.
1690 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1691 QualType T,
1692 SourceLocation RParenLoc) {
1693 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1694 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001695 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696
1697 /// \brief Build a new Objective-C protocol expression.
1698 ///
1699 /// By default, performs semantic analysis to build the new expression.
1700 /// Subclasses may override this routine to provide different behavior.
1701 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1702 SourceLocation AtLoc,
1703 SourceLocation ProtoLoc,
1704 SourceLocation LParenLoc,
1705 SourceLocation RParenLoc) {
1706 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1707 Protocol->getIdentifier(),
1708 AtLoc,
1709 ProtoLoc,
1710 LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001711 RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 }
Mike Stump1eb44332009-09-09 15:08:12 +00001713
Douglas Gregorb98b1992009-08-11 05:31:07 +00001714 /// \brief Build a new shuffle vector expression.
1715 ///
1716 /// By default, performs semantic analysis to build the new expression.
1717 /// Subclasses may override this routine to provide different behavior.
1718 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1719 MultiExprArg SubExprs,
1720 SourceLocation RParenLoc) {
1721 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001722 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1724 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1725 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1726 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001727
Douglas Gregorb98b1992009-08-11 05:31:07 +00001728 // Build a reference to the __builtin_shufflevector builtin
1729 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001730 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001731 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001732 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001733 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001734
1735 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001736 unsigned NumSubExprs = SubExprs.size();
1737 Expr **Subs = (Expr **)SubExprs.release();
1738 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1739 Subs, NumSubExprs,
1740 Builtin->getResultType(),
1741 RParenLoc);
1742 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001743
Douglas Gregorb98b1992009-08-11 05:31:07 +00001744 // Type-check the __builtin_shufflevector expression.
1745 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1746 if (Result.isInvalid())
1747 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001748
Douglas Gregorb98b1992009-08-11 05:31:07 +00001749 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001750 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001751 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001752};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001753
Douglas Gregor43959a92009-08-20 07:17:43 +00001754template<typename Derived>
1755Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1756 if (!S)
1757 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001758
Douglas Gregor43959a92009-08-20 07:17:43 +00001759 switch (S->getStmtClass()) {
1760 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001761
Douglas Gregor43959a92009-08-20 07:17:43 +00001762 // Transform individual statement nodes
1763#define STMT(Node, Parent) \
1764 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1765#define EXPR(Node, Parent)
1766#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001767
Douglas Gregor43959a92009-08-20 07:17:43 +00001768 // Transform expressions by calling TransformExpr.
1769#define STMT(Node, Parent)
John McCall09cc1412010-02-03 00:55:45 +00001770#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregor43959a92009-08-20 07:17:43 +00001771#define EXPR(Node, Parent) case Stmt::Node##Class:
1772#include "clang/AST/StmtNodes.def"
1773 {
1774 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1775 if (E.isInvalid())
1776 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001777
Anders Carlsson5ee56e92009-12-16 02:09:40 +00001778 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregor43959a92009-08-20 07:17:43 +00001779 }
Mike Stump1eb44332009-09-09 15:08:12 +00001780 }
1781
Douglas Gregor43959a92009-08-20 07:17:43 +00001782 return SemaRef.Owned(S->Retain());
1783}
Mike Stump1eb44332009-09-09 15:08:12 +00001784
1785
Douglas Gregor670444e2009-08-04 22:27:00 +00001786template<typename Derived>
John McCall454feb92009-12-08 09:21:05 +00001787Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001788 if (!E)
1789 return SemaRef.Owned(E);
1790
1791 switch (E->getStmtClass()) {
1792 case Stmt::NoStmtClass: break;
1793#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall09cc1412010-02-03 00:55:45 +00001794#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorb98b1992009-08-11 05:31:07 +00001795#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00001796 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001798 }
1799
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00001801}
1802
1803template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00001804NestedNameSpecifier *
1805TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00001806 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001807 QualType ObjectType,
1808 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00001809 if (!NNS)
1810 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001811
Douglas Gregor43959a92009-08-20 07:17:43 +00001812 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00001813 NestedNameSpecifier *Prefix = NNS->getPrefix();
1814 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00001815 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001816 ObjectType,
1817 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00001818 if (!Prefix)
1819 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001820
1821 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00001822 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00001823 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00001824 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001825 }
Mike Stump1eb44332009-09-09 15:08:12 +00001826
Douglas Gregordcee1a12009-08-06 05:28:30 +00001827 switch (NNS->getKind()) {
1828 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00001829 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00001830 "Identifier nested-name-specifier with no prefix or object type");
1831 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1832 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00001833 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001834
1835 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00001836 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00001837 ObjectType,
1838 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001839
Douglas Gregordcee1a12009-08-06 05:28:30 +00001840 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00001841 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00001842 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00001843 getDerived().TransformDecl(Range.getBegin(),
1844 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00001845 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00001846 Prefix == NNS->getPrefix() &&
1847 NS == NNS->getAsNamespace())
1848 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001849
Douglas Gregordcee1a12009-08-06 05:28:30 +00001850 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1851 }
Mike Stump1eb44332009-09-09 15:08:12 +00001852
Douglas Gregordcee1a12009-08-06 05:28:30 +00001853 case NestedNameSpecifier::Global:
1854 // There is no meaningful transformation that one could perform on the
1855 // global scope.
1856 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001857
Douglas Gregordcee1a12009-08-06 05:28:30 +00001858 case NestedNameSpecifier::TypeSpecWithTemplate:
1859 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00001860 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor124b8782010-02-16 19:09:40 +00001861 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
1862 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00001863 if (T.isNull())
1864 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001865
Douglas Gregordcee1a12009-08-06 05:28:30 +00001866 if (!getDerived().AlwaysRebuild() &&
1867 Prefix == NNS->getPrefix() &&
1868 T == QualType(NNS->getAsType(), 0))
1869 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001870
1871 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1872 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00001873 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00001874 }
1875 }
Mike Stump1eb44332009-09-09 15:08:12 +00001876
Douglas Gregordcee1a12009-08-06 05:28:30 +00001877 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00001878 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001879}
1880
1881template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001882DeclarationName
Douglas Gregor81499bb2009-09-03 22:13:48 +00001883TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +00001884 SourceLocation Loc,
1885 QualType ObjectType) {
Douglas Gregor81499bb2009-09-03 22:13:48 +00001886 if (!Name)
1887 return Name;
1888
1889 switch (Name.getNameKind()) {
1890 case DeclarationName::Identifier:
1891 case DeclarationName::ObjCZeroArgSelector:
1892 case DeclarationName::ObjCOneArgSelector:
1893 case DeclarationName::ObjCMultiArgSelector:
1894 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00001895 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00001896 case DeclarationName::CXXUsingDirective:
1897 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001898
Douglas Gregor81499bb2009-09-03 22:13:48 +00001899 case DeclarationName::CXXConstructorName:
1900 case DeclarationName::CXXDestructorName:
1901 case DeclarationName::CXXConversionFunctionName: {
1902 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregor124b8782010-02-16 19:09:40 +00001903 QualType T = getDerived().TransformType(Name.getCXXNameType(),
1904 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00001905 if (T.isNull())
1906 return DeclarationName();
Mike Stump1eb44332009-09-09 15:08:12 +00001907
Douglas Gregor81499bb2009-09-03 22:13:48 +00001908 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump1eb44332009-09-09 15:08:12 +00001909 Name.getNameKind(),
Douglas Gregor81499bb2009-09-03 22:13:48 +00001910 SemaRef.Context.getCanonicalType(T));
Douglas Gregor81499bb2009-09-03 22:13:48 +00001911 }
Mike Stump1eb44332009-09-09 15:08:12 +00001912 }
1913
Douglas Gregor81499bb2009-09-03 22:13:48 +00001914 return DeclarationName();
1915}
1916
1917template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001918TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001919TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1920 QualType ObjectType) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00001921 SourceLocation Loc = getDerived().getBaseLocation();
1922
Douglas Gregord1067e52009-08-06 06:41:21 +00001923 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001924 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00001925 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00001926 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1927 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00001928 if (!NNS)
1929 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001930
Douglas Gregord1067e52009-08-06 06:41:21 +00001931 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001932 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00001933 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00001934 if (!TransTemplate)
1935 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001936
Douglas Gregord1067e52009-08-06 06:41:21 +00001937 if (!getDerived().AlwaysRebuild() &&
1938 NNS == QTN->getQualifier() &&
1939 TransTemplate == Template)
1940 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001941
Douglas Gregord1067e52009-08-06 06:41:21 +00001942 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1943 TransTemplate);
1944 }
Mike Stump1eb44332009-09-09 15:08:12 +00001945
John McCallf7a1a742009-11-24 19:00:30 +00001946 // These should be getting filtered out before they make it into the AST.
1947 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00001948 }
Mike Stump1eb44332009-09-09 15:08:12 +00001949
Douglas Gregord1067e52009-08-06 06:41:21 +00001950 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001951 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00001952 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00001953 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1954 ObjectType);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001955 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00001956 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001957
Douglas Gregord1067e52009-08-06 06:41:21 +00001958 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00001959 NNS == DTN->getQualifier() &&
1960 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00001961 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001962
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001963 if (DTN->isIdentifier())
1964 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1965 ObjectType);
1966
1967 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1968 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00001969 }
Mike Stump1eb44332009-09-09 15:08:12 +00001970
Douglas Gregord1067e52009-08-06 06:41:21 +00001971 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001972 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00001973 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00001974 if (!TransTemplate)
1975 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001976
Douglas Gregord1067e52009-08-06 06:41:21 +00001977 if (!getDerived().AlwaysRebuild() &&
1978 TransTemplate == Template)
1979 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001980
Douglas Gregord1067e52009-08-06 06:41:21 +00001981 return TemplateName(TransTemplate);
1982 }
Mike Stump1eb44332009-09-09 15:08:12 +00001983
John McCallf7a1a742009-11-24 19:00:30 +00001984 // These should be getting filtered out before they reach the AST.
1985 assert(false && "overloaded function decl survived to here");
1986 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00001987}
1988
1989template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00001990void TreeTransform<Derived>::InventTemplateArgumentLoc(
1991 const TemplateArgument &Arg,
1992 TemplateArgumentLoc &Output) {
1993 SourceLocation Loc = getDerived().getBaseLocation();
1994 switch (Arg.getKind()) {
1995 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00001996 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00001997 break;
1998
1999 case TemplateArgument::Type:
2000 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002001 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall833ca992009-10-29 08:12:44 +00002002
2003 break;
2004
Douglas Gregor788cd062009-11-11 01:00:40 +00002005 case TemplateArgument::Template:
2006 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2007 break;
2008
John McCall833ca992009-10-29 08:12:44 +00002009 case TemplateArgument::Expression:
2010 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2011 break;
2012
2013 case TemplateArgument::Declaration:
2014 case TemplateArgument::Integral:
2015 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002016 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002017 break;
2018 }
2019}
2020
2021template<typename Derived>
2022bool TreeTransform<Derived>::TransformTemplateArgument(
2023 const TemplateArgumentLoc &Input,
2024 TemplateArgumentLoc &Output) {
2025 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002026 switch (Arg.getKind()) {
2027 case TemplateArgument::Null:
2028 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002029 Output = Input;
2030 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002031
Douglas Gregor670444e2009-08-04 22:27:00 +00002032 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002033 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002034 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002035 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002036
2037 DI = getDerived().TransformType(DI);
2038 if (!DI) return true;
2039
2040 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2041 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002042 }
Mike Stump1eb44332009-09-09 15:08:12 +00002043
Douglas Gregor670444e2009-08-04 22:27:00 +00002044 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002045 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002046 DeclarationName Name;
2047 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2048 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002049 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002050 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002051 if (!D) return true;
2052
John McCall828bff22009-10-29 18:45:58 +00002053 Expr *SourceExpr = Input.getSourceDeclExpression();
2054 if (SourceExpr) {
2055 EnterExpressionEvaluationContext Unevaluated(getSema(),
2056 Action::Unevaluated);
2057 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2058 if (E.isInvalid())
2059 SourceExpr = NULL;
2060 else {
2061 SourceExpr = E.takeAs<Expr>();
2062 SourceExpr->Retain();
2063 }
2064 }
2065
2066 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002067 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002068 }
Mike Stump1eb44332009-09-09 15:08:12 +00002069
Douglas Gregor788cd062009-11-11 01:00:40 +00002070 case TemplateArgument::Template: {
2071 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
2072 TemplateName Template
2073 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2074 if (Template.isNull())
2075 return true;
2076
2077 Output = TemplateArgumentLoc(TemplateArgument(Template),
2078 Input.getTemplateQualifierRange(),
2079 Input.getTemplateNameLoc());
2080 return false;
2081 }
2082
Douglas Gregor670444e2009-08-04 22:27:00 +00002083 case TemplateArgument::Expression: {
2084 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002085 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002086 Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002087
John McCall833ca992009-10-29 08:12:44 +00002088 Expr *InputExpr = Input.getSourceExpression();
2089 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2090
2091 Sema::OwningExprResult E
2092 = getDerived().TransformExpr(InputExpr);
2093 if (E.isInvalid()) return true;
2094
2095 Expr *ETaken = E.takeAs<Expr>();
John McCall828bff22009-10-29 18:45:58 +00002096 ETaken->Retain();
John McCall833ca992009-10-29 08:12:44 +00002097 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2098 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002099 }
Mike Stump1eb44332009-09-09 15:08:12 +00002100
Douglas Gregor670444e2009-08-04 22:27:00 +00002101 case TemplateArgument::Pack: {
2102 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2103 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002104 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002105 AEnd = Arg.pack_end();
2106 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002107
John McCall833ca992009-10-29 08:12:44 +00002108 // FIXME: preserve source information here when we start
2109 // caring about parameter packs.
2110
John McCall828bff22009-10-29 18:45:58 +00002111 TemplateArgumentLoc InputArg;
2112 TemplateArgumentLoc OutputArg;
2113 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2114 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002115 return true;
2116
John McCall828bff22009-10-29 18:45:58 +00002117 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002118 }
2119 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002120 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002121 true);
John McCall828bff22009-10-29 18:45:58 +00002122 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002123 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002124 }
2125 }
Mike Stump1eb44332009-09-09 15:08:12 +00002126
Douglas Gregor670444e2009-08-04 22:27:00 +00002127 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002128 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002129}
2130
Douglas Gregor577f75a2009-08-04 16:50:30 +00002131//===----------------------------------------------------------------------===//
2132// Type transformation
2133//===----------------------------------------------------------------------===//
2134
2135template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002136QualType TreeTransform<Derived>::TransformType(QualType T,
2137 QualType ObjectType) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002138 if (getDerived().AlreadyTransformed(T))
2139 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002140
John McCalla2becad2009-10-21 00:40:46 +00002141 // Temporary workaround. All of these transformations should
2142 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002143 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002144 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCalla2becad2009-10-21 00:40:46 +00002145
Douglas Gregor124b8782010-02-16 19:09:40 +00002146 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall0953e762009-09-24 19:53:00 +00002147
John McCalla2becad2009-10-21 00:40:46 +00002148 if (!NewDI)
2149 return QualType();
2150
2151 return NewDI->getType();
2152}
2153
2154template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002155TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2156 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002157 if (getDerived().AlreadyTransformed(DI->getType()))
2158 return DI;
2159
2160 TypeLocBuilder TLB;
2161
2162 TypeLoc TL = DI->getTypeLoc();
2163 TLB.reserve(TL.getFullDataSize());
2164
Douglas Gregor124b8782010-02-16 19:09:40 +00002165 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002166 if (Result.isNull())
2167 return 0;
2168
John McCalla93c9342009-12-07 02:54:59 +00002169 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002170}
2171
2172template<typename Derived>
2173QualType
Douglas Gregor124b8782010-02-16 19:09:40 +00002174TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2175 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002176 switch (T.getTypeLocClass()) {
2177#define ABSTRACT_TYPELOC(CLASS, PARENT)
2178#define TYPELOC(CLASS, PARENT) \
2179 case TypeLoc::CLASS: \
Douglas Gregor124b8782010-02-16 19:09:40 +00002180 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2181 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002182#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002183 }
Mike Stump1eb44332009-09-09 15:08:12 +00002184
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002185 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002186 return QualType();
2187}
2188
2189/// FIXME: By default, this routine adds type qualifiers only to types
2190/// that can have qualifiers, and silently suppresses those qualifiers
2191/// that are not permitted (e.g., qualifiers on reference or function
2192/// types). This is the right thing for template instantiation, but
2193/// probably not for other clients.
2194template<typename Derived>
2195QualType
2196TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002197 QualifiedTypeLoc T,
2198 QualType ObjectType) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002199 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002200
Douglas Gregor124b8782010-02-16 19:09:40 +00002201 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2202 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002203 if (Result.isNull())
2204 return QualType();
2205
2206 // Silently suppress qualifiers if the result type can't be qualified.
2207 // FIXME: this is the right thing for template instantiation, but
2208 // probably not for other clients.
2209 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002210 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002211
John McCalla2becad2009-10-21 00:40:46 +00002212 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2213
2214 TLB.push<QualifiedTypeLoc>(Result);
2215
2216 // No location information to preserve.
2217
2218 return Result;
2219}
2220
2221template <class TyLoc> static inline
2222QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2223 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2224 NewT.setNameLoc(T.getNameLoc());
2225 return T.getType();
2226}
2227
2228// Ugly metaprogramming macros because I couldn't be bothered to make
2229// the equivalent template version work.
2230#define TransformPointerLikeType(TypeClass) do { \
2231 QualType PointeeType \
2232 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2233 if (PointeeType.isNull()) \
2234 return QualType(); \
2235 \
2236 QualType Result = TL.getType(); \
2237 if (getDerived().AlwaysRebuild() || \
2238 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall85737a72009-10-30 00:06:24 +00002239 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2240 TL.getSigilLoc()); \
John McCalla2becad2009-10-21 00:40:46 +00002241 if (Result.isNull()) \
2242 return QualType(); \
2243 } \
2244 \
2245 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2246 NewT.setSigilLoc(TL.getSigilLoc()); \
2247 \
2248 return Result; \
2249} while(0)
2250
John McCalla2becad2009-10-21 00:40:46 +00002251template<typename Derived>
2252QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002253 BuiltinTypeLoc T,
2254 QualType ObjectType) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002255 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2256 NewT.setBuiltinLoc(T.getBuiltinLoc());
2257 if (T.needsExtraLocalData())
2258 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2259 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002260}
Mike Stump1eb44332009-09-09 15:08:12 +00002261
Douglas Gregor577f75a2009-08-04 16:50:30 +00002262template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002263QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002264 ComplexTypeLoc T,
2265 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002266 // FIXME: recurse?
2267 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002268}
Mike Stump1eb44332009-09-09 15:08:12 +00002269
Douglas Gregor577f75a2009-08-04 16:50:30 +00002270template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002271QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002272 PointerTypeLoc TL,
2273 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002274 TransformPointerLikeType(PointerType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002275}
Mike Stump1eb44332009-09-09 15:08:12 +00002276
2277template<typename Derived>
2278QualType
John McCalla2becad2009-10-21 00:40:46 +00002279TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002280 BlockPointerTypeLoc TL,
2281 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002282 TransformPointerLikeType(BlockPointerType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002283}
2284
John McCall85737a72009-10-30 00:06:24 +00002285/// Transforms a reference type. Note that somewhat paradoxically we
2286/// don't care whether the type itself is an l-value type or an r-value
2287/// type; we only care if the type was *written* as an l-value type
2288/// or an r-value type.
2289template<typename Derived>
2290QualType
2291TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002292 ReferenceTypeLoc TL,
2293 QualType ObjectType) {
John McCall85737a72009-10-30 00:06:24 +00002294 const ReferenceType *T = TL.getTypePtr();
2295
2296 // Note that this works with the pointee-as-written.
2297 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2298 if (PointeeType.isNull())
2299 return QualType();
2300
2301 QualType Result = TL.getType();
2302 if (getDerived().AlwaysRebuild() ||
2303 PointeeType != T->getPointeeTypeAsWritten()) {
2304 Result = getDerived().RebuildReferenceType(PointeeType,
2305 T->isSpelledAsLValue(),
2306 TL.getSigilLoc());
2307 if (Result.isNull())
2308 return QualType();
2309 }
2310
2311 // r-value references can be rebuilt as l-value references.
2312 ReferenceTypeLoc NewTL;
2313 if (isa<LValueReferenceType>(Result))
2314 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2315 else
2316 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2317 NewTL.setSigilLoc(TL.getSigilLoc());
2318
2319 return Result;
2320}
2321
Mike Stump1eb44332009-09-09 15:08:12 +00002322template<typename Derived>
2323QualType
John McCalla2becad2009-10-21 00:40:46 +00002324TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002325 LValueReferenceTypeLoc TL,
2326 QualType ObjectType) {
2327 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002328}
2329
Mike Stump1eb44332009-09-09 15:08:12 +00002330template<typename Derived>
2331QualType
John McCalla2becad2009-10-21 00:40:46 +00002332TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002333 RValueReferenceTypeLoc TL,
2334 QualType ObjectType) {
2335 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002336}
Mike Stump1eb44332009-09-09 15:08:12 +00002337
Douglas Gregor577f75a2009-08-04 16:50:30 +00002338template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002339QualType
John McCalla2becad2009-10-21 00:40:46 +00002340TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002341 MemberPointerTypeLoc TL,
2342 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002343 MemberPointerType *T = TL.getTypePtr();
2344
2345 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002346 if (PointeeType.isNull())
2347 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002348
John McCalla2becad2009-10-21 00:40:46 +00002349 // TODO: preserve source information for this.
2350 QualType ClassType
2351 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002352 if (ClassType.isNull())
2353 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002354
John McCalla2becad2009-10-21 00:40:46 +00002355 QualType Result = TL.getType();
2356 if (getDerived().AlwaysRebuild() ||
2357 PointeeType != T->getPointeeType() ||
2358 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002359 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2360 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002361 if (Result.isNull())
2362 return QualType();
2363 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002364
John McCalla2becad2009-10-21 00:40:46 +00002365 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2366 NewTL.setSigilLoc(TL.getSigilLoc());
2367
2368 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002369}
2370
Mike Stump1eb44332009-09-09 15:08:12 +00002371template<typename Derived>
2372QualType
John McCalla2becad2009-10-21 00:40:46 +00002373TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002374 ConstantArrayTypeLoc TL,
2375 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002376 ConstantArrayType *T = TL.getTypePtr();
2377 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002378 if (ElementType.isNull())
2379 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002380
John McCalla2becad2009-10-21 00:40:46 +00002381 QualType Result = TL.getType();
2382 if (getDerived().AlwaysRebuild() ||
2383 ElementType != T->getElementType()) {
2384 Result = getDerived().RebuildConstantArrayType(ElementType,
2385 T->getSizeModifier(),
2386 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002387 T->getIndexTypeCVRQualifiers(),
2388 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002389 if (Result.isNull())
2390 return QualType();
2391 }
2392
2393 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2394 NewTL.setLBracketLoc(TL.getLBracketLoc());
2395 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002396
John McCalla2becad2009-10-21 00:40:46 +00002397 Expr *Size = TL.getSizeExpr();
2398 if (Size) {
2399 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2400 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2401 }
2402 NewTL.setSizeExpr(Size);
2403
2404 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002405}
Mike Stump1eb44332009-09-09 15:08:12 +00002406
Douglas Gregor577f75a2009-08-04 16:50:30 +00002407template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002408QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002409 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002410 IncompleteArrayTypeLoc TL,
2411 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002412 IncompleteArrayType *T = TL.getTypePtr();
2413 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002414 if (ElementType.isNull())
2415 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002416
John McCalla2becad2009-10-21 00:40:46 +00002417 QualType Result = TL.getType();
2418 if (getDerived().AlwaysRebuild() ||
2419 ElementType != T->getElementType()) {
2420 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002421 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002422 T->getIndexTypeCVRQualifiers(),
2423 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002424 if (Result.isNull())
2425 return QualType();
2426 }
2427
2428 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2429 NewTL.setLBracketLoc(TL.getLBracketLoc());
2430 NewTL.setRBracketLoc(TL.getRBracketLoc());
2431 NewTL.setSizeExpr(0);
2432
2433 return Result;
2434}
2435
2436template<typename Derived>
2437QualType
2438TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002439 VariableArrayTypeLoc TL,
2440 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002441 VariableArrayType *T = TL.getTypePtr();
2442 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2443 if (ElementType.isNull())
2444 return QualType();
2445
2446 // Array bounds are not potentially evaluated contexts
2447 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2448
2449 Sema::OwningExprResult SizeResult
2450 = getDerived().TransformExpr(T->getSizeExpr());
2451 if (SizeResult.isInvalid())
2452 return QualType();
2453
2454 Expr *Size = static_cast<Expr*>(SizeResult.get());
2455
2456 QualType Result = TL.getType();
2457 if (getDerived().AlwaysRebuild() ||
2458 ElementType != T->getElementType() ||
2459 Size != T->getSizeExpr()) {
2460 Result = getDerived().RebuildVariableArrayType(ElementType,
2461 T->getSizeModifier(),
2462 move(SizeResult),
2463 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002464 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002465 if (Result.isNull())
2466 return QualType();
2467 }
2468 else SizeResult.take();
2469
2470 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2471 NewTL.setLBracketLoc(TL.getLBracketLoc());
2472 NewTL.setRBracketLoc(TL.getRBracketLoc());
2473 NewTL.setSizeExpr(Size);
2474
2475 return Result;
2476}
2477
2478template<typename Derived>
2479QualType
2480TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002481 DependentSizedArrayTypeLoc TL,
2482 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002483 DependentSizedArrayType *T = TL.getTypePtr();
2484 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2485 if (ElementType.isNull())
2486 return QualType();
2487
2488 // Array bounds are not potentially evaluated contexts
2489 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2490
2491 Sema::OwningExprResult SizeResult
2492 = getDerived().TransformExpr(T->getSizeExpr());
2493 if (SizeResult.isInvalid())
2494 return QualType();
2495
2496 Expr *Size = static_cast<Expr*>(SizeResult.get());
2497
2498 QualType Result = TL.getType();
2499 if (getDerived().AlwaysRebuild() ||
2500 ElementType != T->getElementType() ||
2501 Size != T->getSizeExpr()) {
2502 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2503 T->getSizeModifier(),
2504 move(SizeResult),
2505 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002506 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002507 if (Result.isNull())
2508 return QualType();
2509 }
2510 else SizeResult.take();
2511
2512 // We might have any sort of array type now, but fortunately they
2513 // all have the same location layout.
2514 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2515 NewTL.setLBracketLoc(TL.getLBracketLoc());
2516 NewTL.setRBracketLoc(TL.getRBracketLoc());
2517 NewTL.setSizeExpr(Size);
2518
2519 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002520}
Mike Stump1eb44332009-09-09 15:08:12 +00002521
2522template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002523QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002524 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002525 DependentSizedExtVectorTypeLoc TL,
2526 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002527 DependentSizedExtVectorType *T = TL.getTypePtr();
2528
2529 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002530 QualType ElementType = getDerived().TransformType(T->getElementType());
2531 if (ElementType.isNull())
2532 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002533
Douglas Gregor670444e2009-08-04 22:27:00 +00002534 // Vector sizes are not potentially evaluated contexts
2535 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2536
Douglas Gregor577f75a2009-08-04 16:50:30 +00002537 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2538 if (Size.isInvalid())
2539 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002540
John McCalla2becad2009-10-21 00:40:46 +00002541 QualType Result = TL.getType();
2542 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002543 ElementType != T->getElementType() ||
2544 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002545 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002546 move(Size),
2547 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002548 if (Result.isNull())
2549 return QualType();
2550 }
2551 else Size.take();
2552
2553 // Result might be dependent or not.
2554 if (isa<DependentSizedExtVectorType>(Result)) {
2555 DependentSizedExtVectorTypeLoc NewTL
2556 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2557 NewTL.setNameLoc(TL.getNameLoc());
2558 } else {
2559 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2560 NewTL.setNameLoc(TL.getNameLoc());
2561 }
2562
2563 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002564}
Mike Stump1eb44332009-09-09 15:08:12 +00002565
2566template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002567QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002568 VectorTypeLoc TL,
2569 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002570 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002571 QualType ElementType = getDerived().TransformType(T->getElementType());
2572 if (ElementType.isNull())
2573 return QualType();
2574
John McCalla2becad2009-10-21 00:40:46 +00002575 QualType Result = TL.getType();
2576 if (getDerived().AlwaysRebuild() ||
2577 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002578 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2579 T->isAltiVec(), T->isPixel());
John McCalla2becad2009-10-21 00:40:46 +00002580 if (Result.isNull())
2581 return QualType();
2582 }
2583
2584 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2585 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002586
John McCalla2becad2009-10-21 00:40:46 +00002587 return Result;
2588}
2589
2590template<typename Derived>
2591QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002592 ExtVectorTypeLoc TL,
2593 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002594 VectorType *T = TL.getTypePtr();
2595 QualType ElementType = getDerived().TransformType(T->getElementType());
2596 if (ElementType.isNull())
2597 return QualType();
2598
2599 QualType Result = TL.getType();
2600 if (getDerived().AlwaysRebuild() ||
2601 ElementType != T->getElementType()) {
2602 Result = getDerived().RebuildExtVectorType(ElementType,
2603 T->getNumElements(),
2604 /*FIXME*/ SourceLocation());
2605 if (Result.isNull())
2606 return QualType();
2607 }
2608
2609 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2610 NewTL.setNameLoc(TL.getNameLoc());
2611
2612 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002613}
Mike Stump1eb44332009-09-09 15:08:12 +00002614
2615template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002616ParmVarDecl *
2617TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2618 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2619 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2620 if (!NewDI)
2621 return 0;
2622
2623 if (NewDI == OldDI)
2624 return OldParm;
2625 else
2626 return ParmVarDecl::Create(SemaRef.Context,
2627 OldParm->getDeclContext(),
2628 OldParm->getLocation(),
2629 OldParm->getIdentifier(),
2630 NewDI->getType(),
2631 NewDI,
2632 OldParm->getStorageClass(),
2633 /* DefArg */ NULL);
2634}
2635
2636template<typename Derived>
2637bool TreeTransform<Derived>::
2638 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2639 llvm::SmallVectorImpl<QualType> &PTypes,
2640 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2641 FunctionProtoType *T = TL.getTypePtr();
2642
2643 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2644 ParmVarDecl *OldParm = TL.getArg(i);
2645
2646 QualType NewType;
2647 ParmVarDecl *NewParm;
2648
2649 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002650 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2651 if (!NewParm)
2652 return true;
2653 NewType = NewParm->getType();
2654
2655 // Deal with the possibility that we don't have a parameter
2656 // declaration for this parameter.
2657 } else {
2658 NewParm = 0;
2659
2660 QualType OldType = T->getArgType(i);
2661 NewType = getDerived().TransformType(OldType);
2662 if (NewType.isNull())
2663 return true;
2664 }
2665
2666 PTypes.push_back(NewType);
2667 PVars.push_back(NewParm);
2668 }
2669
2670 return false;
2671}
2672
2673template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002674QualType
John McCalla2becad2009-10-21 00:40:46 +00002675TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002676 FunctionProtoTypeLoc TL,
2677 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002678 FunctionProtoType *T = TL.getTypePtr();
2679 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002680 if (ResultType.isNull())
2681 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002682
John McCalla2becad2009-10-21 00:40:46 +00002683 // Transform the parameters.
Douglas Gregor577f75a2009-08-04 16:50:30 +00002684 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002685 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall21ef0fa2010-03-11 09:03:00 +00002686 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2687 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002688
John McCalla2becad2009-10-21 00:40:46 +00002689 QualType Result = TL.getType();
2690 if (getDerived().AlwaysRebuild() ||
2691 ResultType != T->getResultType() ||
2692 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2693 Result = getDerived().RebuildFunctionProtoType(ResultType,
2694 ParamTypes.data(),
2695 ParamTypes.size(),
2696 T->isVariadic(),
2697 T->getTypeQuals());
2698 if (Result.isNull())
2699 return QualType();
2700 }
Mike Stump1eb44332009-09-09 15:08:12 +00002701
John McCalla2becad2009-10-21 00:40:46 +00002702 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2703 NewTL.setLParenLoc(TL.getLParenLoc());
2704 NewTL.setRParenLoc(TL.getRParenLoc());
2705 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2706 NewTL.setArg(i, ParamDecls[i]);
2707
2708 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002709}
Mike Stump1eb44332009-09-09 15:08:12 +00002710
Douglas Gregor577f75a2009-08-04 16:50:30 +00002711template<typename Derived>
2712QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002713 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002714 FunctionNoProtoTypeLoc TL,
2715 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002716 FunctionNoProtoType *T = TL.getTypePtr();
2717 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2718 if (ResultType.isNull())
2719 return QualType();
2720
2721 QualType Result = TL.getType();
2722 if (getDerived().AlwaysRebuild() ||
2723 ResultType != T->getResultType())
2724 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2725
2726 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2727 NewTL.setLParenLoc(TL.getLParenLoc());
2728 NewTL.setRParenLoc(TL.getRParenLoc());
2729
2730 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002731}
Mike Stump1eb44332009-09-09 15:08:12 +00002732
John McCalled976492009-12-04 22:46:56 +00002733template<typename Derived> QualType
2734TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002735 UnresolvedUsingTypeLoc TL,
2736 QualType ObjectType) {
John McCalled976492009-12-04 22:46:56 +00002737 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002738 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00002739 if (!D)
2740 return QualType();
2741
2742 QualType Result = TL.getType();
2743 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2744 Result = getDerived().RebuildUnresolvedUsingType(D);
2745 if (Result.isNull())
2746 return QualType();
2747 }
2748
2749 // We might get an arbitrary type spec type back. We should at
2750 // least always get a type spec type, though.
2751 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2752 NewTL.setNameLoc(TL.getNameLoc());
2753
2754 return Result;
2755}
2756
Douglas Gregor577f75a2009-08-04 16:50:30 +00002757template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002758QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002759 TypedefTypeLoc TL,
2760 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002761 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002762 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002763 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2764 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002765 if (!Typedef)
2766 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002767
John McCalla2becad2009-10-21 00:40:46 +00002768 QualType Result = TL.getType();
2769 if (getDerived().AlwaysRebuild() ||
2770 Typedef != T->getDecl()) {
2771 Result = getDerived().RebuildTypedefType(Typedef);
2772 if (Result.isNull())
2773 return QualType();
2774 }
Mike Stump1eb44332009-09-09 15:08:12 +00002775
John McCalla2becad2009-10-21 00:40:46 +00002776 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2777 NewTL.setNameLoc(TL.getNameLoc());
2778
2779 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002780}
Mike Stump1eb44332009-09-09 15:08:12 +00002781
Douglas Gregor577f75a2009-08-04 16:50:30 +00002782template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002783QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002784 TypeOfExprTypeLoc TL,
2785 QualType ObjectType) {
Douglas Gregor670444e2009-08-04 22:27:00 +00002786 // typeof expressions are not potentially evaluated contexts
2787 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002788
John McCallcfb708c2010-01-13 20:03:27 +00002789 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002790 if (E.isInvalid())
2791 return QualType();
2792
John McCalla2becad2009-10-21 00:40:46 +00002793 QualType Result = TL.getType();
2794 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00002795 E.get() != TL.getUnderlyingExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002796 Result = getDerived().RebuildTypeOfExprType(move(E));
2797 if (Result.isNull())
2798 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002799 }
John McCalla2becad2009-10-21 00:40:46 +00002800 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002801
John McCalla2becad2009-10-21 00:40:46 +00002802 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002803 NewTL.setTypeofLoc(TL.getTypeofLoc());
2804 NewTL.setLParenLoc(TL.getLParenLoc());
2805 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00002806
2807 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002808}
Mike Stump1eb44332009-09-09 15:08:12 +00002809
2810template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002811QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002812 TypeOfTypeLoc TL,
2813 QualType ObjectType) {
John McCallcfb708c2010-01-13 20:03:27 +00002814 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2815 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2816 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00002817 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002818
John McCalla2becad2009-10-21 00:40:46 +00002819 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00002820 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2821 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00002822 if (Result.isNull())
2823 return QualType();
2824 }
Mike Stump1eb44332009-09-09 15:08:12 +00002825
John McCalla2becad2009-10-21 00:40:46 +00002826 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002827 NewTL.setTypeofLoc(TL.getTypeofLoc());
2828 NewTL.setLParenLoc(TL.getLParenLoc());
2829 NewTL.setRParenLoc(TL.getRParenLoc());
2830 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00002831
2832 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002833}
Mike Stump1eb44332009-09-09 15:08:12 +00002834
2835template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002836QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002837 DecltypeTypeLoc TL,
2838 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002839 DecltypeType *T = TL.getTypePtr();
2840
Douglas Gregor670444e2009-08-04 22:27:00 +00002841 // decltype expressions are not potentially evaluated contexts
2842 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002843
Douglas Gregor577f75a2009-08-04 16:50:30 +00002844 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2845 if (E.isInvalid())
2846 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002847
John McCalla2becad2009-10-21 00:40:46 +00002848 QualType Result = TL.getType();
2849 if (getDerived().AlwaysRebuild() ||
2850 E.get() != T->getUnderlyingExpr()) {
2851 Result = getDerived().RebuildDecltypeType(move(E));
2852 if (Result.isNull())
2853 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002854 }
John McCalla2becad2009-10-21 00:40:46 +00002855 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002856
John McCalla2becad2009-10-21 00:40:46 +00002857 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2858 NewTL.setNameLoc(TL.getNameLoc());
2859
2860 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002861}
2862
2863template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002864QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002865 RecordTypeLoc TL,
2866 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002867 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002868 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002869 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2870 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002871 if (!Record)
2872 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002873
John McCalla2becad2009-10-21 00:40:46 +00002874 QualType Result = TL.getType();
2875 if (getDerived().AlwaysRebuild() ||
2876 Record != T->getDecl()) {
2877 Result = getDerived().RebuildRecordType(Record);
2878 if (Result.isNull())
2879 return QualType();
2880 }
Mike Stump1eb44332009-09-09 15:08:12 +00002881
John McCalla2becad2009-10-21 00:40:46 +00002882 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2883 NewTL.setNameLoc(TL.getNameLoc());
2884
2885 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002886}
Mike Stump1eb44332009-09-09 15:08:12 +00002887
2888template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002889QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002890 EnumTypeLoc TL,
2891 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002892 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002893 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002894 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2895 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002896 if (!Enum)
2897 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002898
John McCalla2becad2009-10-21 00:40:46 +00002899 QualType Result = TL.getType();
2900 if (getDerived().AlwaysRebuild() ||
2901 Enum != T->getDecl()) {
2902 Result = getDerived().RebuildEnumType(Enum);
2903 if (Result.isNull())
2904 return QualType();
2905 }
Mike Stump1eb44332009-09-09 15:08:12 +00002906
John McCalla2becad2009-10-21 00:40:46 +00002907 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2908 NewTL.setNameLoc(TL.getNameLoc());
2909
2910 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002911}
John McCall7da24312009-09-05 00:15:47 +00002912
2913template <typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002914QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002915 ElaboratedTypeLoc TL,
2916 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002917 ElaboratedType *T = TL.getTypePtr();
2918
2919 // FIXME: this should be a nested type.
John McCall7da24312009-09-05 00:15:47 +00002920 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2921 if (Underlying.isNull())
2922 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002923
John McCalla2becad2009-10-21 00:40:46 +00002924 QualType Result = TL.getType();
2925 if (getDerived().AlwaysRebuild() ||
2926 Underlying != T->getUnderlyingType()) {
2927 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2928 if (Result.isNull())
2929 return QualType();
2930 }
Mike Stump1eb44332009-09-09 15:08:12 +00002931
John McCalla2becad2009-10-21 00:40:46 +00002932 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2933 NewTL.setNameLoc(TL.getNameLoc());
2934
2935 return Result;
John McCall7da24312009-09-05 00:15:47 +00002936}
Mike Stump1eb44332009-09-09 15:08:12 +00002937
John McCall3cb0ebd2010-03-10 03:28:59 +00002938template<typename Derived>
2939QualType TreeTransform<Derived>::TransformInjectedClassNameType(
2940 TypeLocBuilder &TLB,
2941 InjectedClassNameTypeLoc TL,
2942 QualType ObjectType) {
2943 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
2944 TL.getTypePtr()->getDecl());
2945 if (!D) return QualType();
2946
2947 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
2948 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
2949 return T;
2950}
2951
Mike Stump1eb44332009-09-09 15:08:12 +00002952
Douglas Gregor577f75a2009-08-04 16:50:30 +00002953template<typename Derived>
2954QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00002955 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002956 TemplateTypeParmTypeLoc TL,
2957 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002958 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002959}
2960
Mike Stump1eb44332009-09-09 15:08:12 +00002961template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00002962QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00002963 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002964 SubstTemplateTypeParmTypeLoc TL,
2965 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002966 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00002967}
2968
2969template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002970QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2971 const TemplateSpecializationType *TST,
2972 QualType ObjectType) {
2973 // FIXME: this entire method is a temporary workaround; callers
2974 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00002975
John McCall833ca992009-10-29 08:12:44 +00002976 // Fake up a TemplateSpecializationTypeLoc.
2977 TypeLocBuilder TLB;
2978 TemplateSpecializationTypeLoc TL
2979 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2980
John McCall828bff22009-10-29 18:45:58 +00002981 SourceLocation BaseLoc = getDerived().getBaseLocation();
2982
2983 TL.setTemplateNameLoc(BaseLoc);
2984 TL.setLAngleLoc(BaseLoc);
2985 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00002986 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2987 const TemplateArgument &TA = TST->getArg(i);
2988 TemplateArgumentLoc TAL;
2989 getDerived().InventTemplateArgumentLoc(TA, TAL);
2990 TL.setArgLocInfo(i, TAL.getLocInfo());
2991 }
2992
2993 TypeLocBuilder IgnoredTLB;
2994 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00002995}
2996
2997template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002998QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00002999 TypeLocBuilder &TLB,
3000 TemplateSpecializationTypeLoc TL,
3001 QualType ObjectType) {
3002 const TemplateSpecializationType *T = TL.getTypePtr();
3003
Mike Stump1eb44332009-09-09 15:08:12 +00003004 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00003005 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003006 if (Template.isNull())
3007 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003008
John McCalld5532b62009-11-23 01:53:49 +00003009 TemplateArgumentListInfo NewTemplateArgs;
3010 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3011 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3012
3013 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3014 TemplateArgumentLoc Loc;
3015 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00003016 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00003017 NewTemplateArgs.addArgument(Loc);
3018 }
Mike Stump1eb44332009-09-09 15:08:12 +00003019
John McCall833ca992009-10-29 08:12:44 +00003020 // FIXME: maybe don't rebuild if all the template arguments are the same.
3021
3022 QualType Result =
3023 getDerived().RebuildTemplateSpecializationType(Template,
3024 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003025 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003026
3027 if (!Result.isNull()) {
3028 TemplateSpecializationTypeLoc NewTL
3029 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3030 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3031 NewTL.setLAngleLoc(TL.getLAngleLoc());
3032 NewTL.setRAngleLoc(TL.getRAngleLoc());
3033 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3034 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003035 }
Mike Stump1eb44332009-09-09 15:08:12 +00003036
John McCall833ca992009-10-29 08:12:44 +00003037 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003038}
Mike Stump1eb44332009-09-09 15:08:12 +00003039
3040template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003041QualType
3042TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003043 QualifiedNameTypeLoc TL,
3044 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003045 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003046 NestedNameSpecifier *NNS
3047 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00003048 SourceRange(),
3049 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003050 if (!NNS)
3051 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003052
Douglas Gregor577f75a2009-08-04 16:50:30 +00003053 QualType Named = getDerived().TransformType(T->getNamedType());
3054 if (Named.isNull())
3055 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003056
John McCalla2becad2009-10-21 00:40:46 +00003057 QualType Result = TL.getType();
3058 if (getDerived().AlwaysRebuild() ||
3059 NNS != T->getQualifier() ||
3060 Named != T->getNamedType()) {
3061 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
3062 if (Result.isNull())
3063 return QualType();
3064 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003065
John McCalla2becad2009-10-21 00:40:46 +00003066 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
3067 NewTL.setNameLoc(TL.getNameLoc());
3068
3069 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003070}
Mike Stump1eb44332009-09-09 15:08:12 +00003071
3072template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003073QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3074 DependentNameTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00003075 QualType ObjectType) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003076 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003077
3078 /* FIXME: preserve source information better than this */
3079 SourceRange SR(TL.getNameLoc());
3080
Douglas Gregor577f75a2009-08-04 16:50:30 +00003081 NestedNameSpecifier *NNS
Douglas Gregor124b8782010-02-16 19:09:40 +00003082 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregoredc90502010-02-25 04:46:04 +00003083 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003084 if (!NNS)
3085 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003086
John McCalla2becad2009-10-21 00:40:46 +00003087 QualType Result;
3088
Douglas Gregor577f75a2009-08-04 16:50:30 +00003089 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump1eb44332009-09-09 15:08:12 +00003090 QualType NewTemplateId
Douglas Gregor577f75a2009-08-04 16:50:30 +00003091 = getDerived().TransformType(QualType(TemplateId, 0));
3092 if (NewTemplateId.isNull())
3093 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003094
Douglas Gregor577f75a2009-08-04 16:50:30 +00003095 if (!getDerived().AlwaysRebuild() &&
3096 NNS == T->getQualifier() &&
3097 NewTemplateId == QualType(TemplateId, 0))
3098 return QualType(T, 0);
Mike Stump1eb44332009-09-09 15:08:12 +00003099
Douglas Gregor4a2023f2010-03-31 20:19:30 +00003100 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3101 NewTemplateId);
John McCalla2becad2009-10-21 00:40:46 +00003102 } else {
Douglas Gregor4a2023f2010-03-31 20:19:30 +00003103 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3104 T->getIdentifier(), SR);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003105 }
John McCalla2becad2009-10-21 00:40:46 +00003106 if (Result.isNull())
3107 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003108
Douglas Gregor4714c122010-03-31 17:34:00 +00003109 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003110 NewTL.setNameLoc(TL.getNameLoc());
3111
3112 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003113}
Mike Stump1eb44332009-09-09 15:08:12 +00003114
Douglas Gregor577f75a2009-08-04 16:50:30 +00003115template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003116QualType
3117TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003118 ObjCInterfaceTypeLoc TL,
3119 QualType ObjectType) {
John McCall54e14c42009-10-22 22:37:11 +00003120 assert(false && "TransformObjCInterfaceType unimplemented");
3121 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003122}
Mike Stump1eb44332009-09-09 15:08:12 +00003123
3124template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003125QualType
3126TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003127 ObjCObjectPointerTypeLoc TL,
3128 QualType ObjectType) {
John McCall54e14c42009-10-22 22:37:11 +00003129 assert(false && "TransformObjCObjectPointerType unimplemented");
3130 return QualType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003131}
3132
Douglas Gregor577f75a2009-08-04 16:50:30 +00003133//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003134// Statement transformation
3135//===----------------------------------------------------------------------===//
3136template<typename Derived>
3137Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003138TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3139 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003140}
3141
3142template<typename Derived>
3143Sema::OwningStmtResult
3144TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3145 return getDerived().TransformCompoundStmt(S, false);
3146}
3147
3148template<typename Derived>
3149Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003150TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003151 bool IsStmtExpr) {
3152 bool SubStmtChanged = false;
3153 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3154 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3155 B != BEnd; ++B) {
3156 OwningStmtResult Result = getDerived().TransformStmt(*B);
3157 if (Result.isInvalid())
3158 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003159
Douglas Gregor43959a92009-08-20 07:17:43 +00003160 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3161 Statements.push_back(Result.takeAs<Stmt>());
3162 }
Mike Stump1eb44332009-09-09 15:08:12 +00003163
Douglas Gregor43959a92009-08-20 07:17:43 +00003164 if (!getDerived().AlwaysRebuild() &&
3165 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003166 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003167
3168 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3169 move_arg(Statements),
3170 S->getRBracLoc(),
3171 IsStmtExpr);
3172}
Mike Stump1eb44332009-09-09 15:08:12 +00003173
Douglas Gregor43959a92009-08-20 07:17:43 +00003174template<typename Derived>
3175Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003176TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman264c1f82009-11-19 03:14:00 +00003177 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3178 {
3179 // The case value expressions are not potentially evaluated.
3180 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003181
Eli Friedman264c1f82009-11-19 03:14:00 +00003182 // Transform the left-hand case value.
3183 LHS = getDerived().TransformExpr(S->getLHS());
3184 if (LHS.isInvalid())
3185 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003186
Eli Friedman264c1f82009-11-19 03:14:00 +00003187 // Transform the right-hand case value (for the GNU case-range extension).
3188 RHS = getDerived().TransformExpr(S->getRHS());
3189 if (RHS.isInvalid())
3190 return SemaRef.StmtError();
3191 }
Mike Stump1eb44332009-09-09 15:08:12 +00003192
Douglas Gregor43959a92009-08-20 07:17:43 +00003193 // Build the case statement.
3194 // Case statements are always rebuilt so that they will attached to their
3195 // transformed switch statement.
3196 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3197 move(LHS),
3198 S->getEllipsisLoc(),
3199 move(RHS),
3200 S->getColonLoc());
3201 if (Case.isInvalid())
3202 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003203
Douglas Gregor43959a92009-08-20 07:17:43 +00003204 // Transform the statement following the case
3205 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3206 if (SubStmt.isInvalid())
3207 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003208
Douglas Gregor43959a92009-08-20 07:17:43 +00003209 // Attach the body to the case statement
3210 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3211}
3212
3213template<typename Derived>
3214Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003215TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003216 // Transform the statement following the default case
3217 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3218 if (SubStmt.isInvalid())
3219 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003220
Douglas Gregor43959a92009-08-20 07:17:43 +00003221 // Default statements are always rebuilt
3222 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3223 move(SubStmt));
3224}
Mike Stump1eb44332009-09-09 15:08:12 +00003225
Douglas Gregor43959a92009-08-20 07:17:43 +00003226template<typename Derived>
3227Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003228TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003229 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3230 if (SubStmt.isInvalid())
3231 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003232
Douglas Gregor43959a92009-08-20 07:17:43 +00003233 // FIXME: Pass the real colon location in.
3234 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3235 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3236 move(SubStmt));
3237}
Mike Stump1eb44332009-09-09 15:08:12 +00003238
Douglas Gregor43959a92009-08-20 07:17:43 +00003239template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003240Sema::OwningStmtResult
3241TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003242 // Transform the condition
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003243 OwningExprResult Cond(SemaRef);
3244 VarDecl *ConditionVar = 0;
3245 if (S->getConditionVariable()) {
3246 ConditionVar
3247 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003248 getDerived().TransformDefinition(
3249 S->getConditionVariable()->getLocation(),
3250 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003251 if (!ConditionVar)
3252 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003253 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003254 Cond = getDerived().TransformExpr(S->getCond());
3255
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003256 if (Cond.isInvalid())
3257 return SemaRef.StmtError();
3258 }
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003259
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003260 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump1eb44332009-09-09 15:08:12 +00003261
Douglas Gregor43959a92009-08-20 07:17:43 +00003262 // Transform the "then" branch.
3263 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3264 if (Then.isInvalid())
3265 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003266
Douglas Gregor43959a92009-08-20 07:17:43 +00003267 // Transform the "else" branch.
3268 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3269 if (Else.isInvalid())
3270 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003271
Douglas Gregor43959a92009-08-20 07:17:43 +00003272 if (!getDerived().AlwaysRebuild() &&
3273 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003274 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003275 Then.get() == S->getThen() &&
3276 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003277 return SemaRef.Owned(S->Retain());
3278
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003279 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3280 move(Then),
Mike Stump1eb44332009-09-09 15:08:12 +00003281 S->getElseLoc(), move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +00003282}
3283
3284template<typename Derived>
3285Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003286TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003287 // Transform the condition.
Douglas Gregord3d53012009-11-24 17:07:59 +00003288 OwningExprResult Cond(SemaRef);
3289 VarDecl *ConditionVar = 0;
3290 if (S->getConditionVariable()) {
3291 ConditionVar
3292 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003293 getDerived().TransformDefinition(
3294 S->getConditionVariable()->getLocation(),
3295 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003296 if (!ConditionVar)
3297 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003298 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003299 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003300
3301 if (Cond.isInvalid())
3302 return SemaRef.StmtError();
3303 }
Mike Stump1eb44332009-09-09 15:08:12 +00003304
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003305 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003306
Douglas Gregor43959a92009-08-20 07:17:43 +00003307 // Rebuild the switch statement.
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003308 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3309 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003310 if (Switch.isInvalid())
3311 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003312
Douglas Gregor43959a92009-08-20 07:17:43 +00003313 // Transform the body of the switch statement.
3314 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3315 if (Body.isInvalid())
3316 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003317
Douglas Gregor43959a92009-08-20 07:17:43 +00003318 // Complete the switch statement.
3319 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3320 move(Body));
3321}
Mike Stump1eb44332009-09-09 15:08:12 +00003322
Douglas Gregor43959a92009-08-20 07:17:43 +00003323template<typename Derived>
3324Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003325TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003326 // Transform the condition
Douglas Gregor5656e142009-11-24 21:15:44 +00003327 OwningExprResult Cond(SemaRef);
3328 VarDecl *ConditionVar = 0;
3329 if (S->getConditionVariable()) {
3330 ConditionVar
3331 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003332 getDerived().TransformDefinition(
3333 S->getConditionVariable()->getLocation(),
3334 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003335 if (!ConditionVar)
3336 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003337 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003338 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003339
3340 if (Cond.isInvalid())
3341 return SemaRef.StmtError();
3342 }
Mike Stump1eb44332009-09-09 15:08:12 +00003343
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003344 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump1eb44332009-09-09 15:08:12 +00003345
Douglas Gregor43959a92009-08-20 07:17:43 +00003346 // Transform the body
3347 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3348 if (Body.isInvalid())
3349 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003350
Douglas Gregor43959a92009-08-20 07:17:43 +00003351 if (!getDerived().AlwaysRebuild() &&
3352 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003353 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003354 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003355 return SemaRef.Owned(S->Retain());
3356
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003357 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3358 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003359}
Mike Stump1eb44332009-09-09 15:08:12 +00003360
Douglas Gregor43959a92009-08-20 07:17:43 +00003361template<typename Derived>
3362Sema::OwningStmtResult
3363TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3364 // Transform the condition
3365 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3366 if (Cond.isInvalid())
3367 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003368
Douglas Gregor43959a92009-08-20 07:17:43 +00003369 // Transform the body
3370 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3371 if (Body.isInvalid())
3372 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003373
Douglas Gregor43959a92009-08-20 07:17:43 +00003374 if (!getDerived().AlwaysRebuild() &&
3375 Cond.get() == S->getCond() &&
3376 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003377 return SemaRef.Owned(S->Retain());
3378
Douglas Gregor43959a92009-08-20 07:17:43 +00003379 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3380 /*FIXME:*/S->getWhileLoc(), move(Cond),
3381 S->getRParenLoc());
3382}
Mike Stump1eb44332009-09-09 15:08:12 +00003383
Douglas Gregor43959a92009-08-20 07:17:43 +00003384template<typename Derived>
3385Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003386TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003387 // Transform the initialization statement
3388 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3389 if (Init.isInvalid())
3390 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003391
Douglas Gregor43959a92009-08-20 07:17:43 +00003392 // Transform the condition
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003393 OwningExprResult Cond(SemaRef);
3394 VarDecl *ConditionVar = 0;
3395 if (S->getConditionVariable()) {
3396 ConditionVar
3397 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003398 getDerived().TransformDefinition(
3399 S->getConditionVariable()->getLocation(),
3400 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003401 if (!ConditionVar)
3402 return SemaRef.StmtError();
3403 } else {
3404 Cond = getDerived().TransformExpr(S->getCond());
3405
3406 if (Cond.isInvalid())
3407 return SemaRef.StmtError();
3408 }
Mike Stump1eb44332009-09-09 15:08:12 +00003409
Douglas Gregor43959a92009-08-20 07:17:43 +00003410 // Transform the increment
3411 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3412 if (Inc.isInvalid())
3413 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003414
Douglas Gregor43959a92009-08-20 07:17:43 +00003415 // Transform the body
3416 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3417 if (Body.isInvalid())
3418 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003419
Douglas Gregor43959a92009-08-20 07:17:43 +00003420 if (!getDerived().AlwaysRebuild() &&
3421 Init.get() == S->getInit() &&
3422 Cond.get() == S->getCond() &&
3423 Inc.get() == S->getInc() &&
3424 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003425 return SemaRef.Owned(S->Retain());
3426
Douglas Gregor43959a92009-08-20 07:17:43 +00003427 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003428 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003429 ConditionVar,
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003430 getSema().MakeFullExpr(Inc),
Douglas Gregor43959a92009-08-20 07:17:43 +00003431 S->getRParenLoc(), move(Body));
3432}
3433
3434template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003435Sema::OwningStmtResult
3436TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003437 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003438 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003439 S->getLabel());
3440}
3441
3442template<typename Derived>
3443Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003444TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003445 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3446 if (Target.isInvalid())
3447 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003448
Douglas Gregor43959a92009-08-20 07:17:43 +00003449 if (!getDerived().AlwaysRebuild() &&
3450 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003451 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003452
3453 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3454 move(Target));
3455}
3456
3457template<typename Derived>
3458Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003459TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3460 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003461}
Mike Stump1eb44332009-09-09 15:08:12 +00003462
Douglas Gregor43959a92009-08-20 07:17:43 +00003463template<typename Derived>
3464Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003465TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3466 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003467}
Mike Stump1eb44332009-09-09 15:08:12 +00003468
Douglas Gregor43959a92009-08-20 07:17:43 +00003469template<typename Derived>
3470Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003471TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003472 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3473 if (Result.isInvalid())
3474 return SemaRef.StmtError();
3475
Mike Stump1eb44332009-09-09 15:08:12 +00003476 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003477 // to tell whether the return type of the function has changed.
3478 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3479}
Mike Stump1eb44332009-09-09 15:08:12 +00003480
Douglas Gregor43959a92009-08-20 07:17:43 +00003481template<typename Derived>
3482Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003483TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003484 bool DeclChanged = false;
3485 llvm::SmallVector<Decl *, 4> Decls;
3486 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3487 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003488 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3489 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003490 if (!Transformed)
3491 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003492
Douglas Gregor43959a92009-08-20 07:17:43 +00003493 if (Transformed != *D)
3494 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003495
Douglas Gregor43959a92009-08-20 07:17:43 +00003496 Decls.push_back(Transformed);
3497 }
Mike Stump1eb44332009-09-09 15:08:12 +00003498
Douglas Gregor43959a92009-08-20 07:17:43 +00003499 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003500 return SemaRef.Owned(S->Retain());
3501
3502 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003503 S->getStartLoc(), S->getEndLoc());
3504}
Mike Stump1eb44332009-09-09 15:08:12 +00003505
Douglas Gregor43959a92009-08-20 07:17:43 +00003506template<typename Derived>
3507Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003508TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003509 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003510 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003511}
3512
3513template<typename Derived>
3514Sema::OwningStmtResult
3515TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlsson703e3942010-01-24 05:50:09 +00003516
3517 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3518 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003519 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003520
Anders Carlsson703e3942010-01-24 05:50:09 +00003521 OwningExprResult AsmString(SemaRef);
3522 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3523
3524 bool ExprsChanged = false;
3525
3526 // Go through the outputs.
3527 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003528 Names.push_back(S->getOutputIdentifier(I));
Anders Carlssona5a79f72010-01-30 20:05:21 +00003529
Anders Carlsson703e3942010-01-24 05:50:09 +00003530 // No need to transform the constraint literal.
3531 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3532
3533 // Transform the output expr.
3534 Expr *OutputExpr = S->getOutputExpr(I);
3535 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3536 if (Result.isInvalid())
3537 return SemaRef.StmtError();
3538
3539 ExprsChanged |= Result.get() != OutputExpr;
3540
3541 Exprs.push_back(Result.takeAs<Expr>());
3542 }
3543
3544 // Go through the inputs.
3545 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003546 Names.push_back(S->getInputIdentifier(I));
Anders Carlssona5a79f72010-01-30 20:05:21 +00003547
Anders Carlsson703e3942010-01-24 05:50:09 +00003548 // No need to transform the constraint literal.
3549 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3550
3551 // Transform the input expr.
3552 Expr *InputExpr = S->getInputExpr(I);
3553 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3554 if (Result.isInvalid())
3555 return SemaRef.StmtError();
3556
3557 ExprsChanged |= Result.get() != InputExpr;
3558
3559 Exprs.push_back(Result.takeAs<Expr>());
3560 }
3561
3562 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3563 return SemaRef.Owned(S->Retain());
3564
3565 // Go through the clobbers.
3566 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3567 Clobbers.push_back(S->getClobber(I)->Retain());
3568
3569 // No need to transform the asm string literal.
3570 AsmString = SemaRef.Owned(S->getAsmString());
3571
3572 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3573 S->isSimple(),
3574 S->isVolatile(),
3575 S->getNumOutputs(),
3576 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003577 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003578 move_arg(Constraints),
3579 move_arg(Exprs),
3580 move(AsmString),
3581 move_arg(Clobbers),
3582 S->getRParenLoc(),
3583 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003584}
3585
3586
3587template<typename Derived>
3588Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003589TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003590 // FIXME: Implement this
3591 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003592 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003593}
Mike Stump1eb44332009-09-09 15:08:12 +00003594
Douglas Gregor43959a92009-08-20 07:17:43 +00003595template<typename Derived>
3596Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003597TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003598 // FIXME: Implement this
3599 assert(false && "Cannot transform an Objective-C @catch statement");
3600 return SemaRef.Owned(S->Retain());
3601}
Mike Stump1eb44332009-09-09 15:08:12 +00003602
Douglas Gregor43959a92009-08-20 07:17:43 +00003603template<typename Derived>
3604Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003605TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003606 // FIXME: Implement this
3607 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003608 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003609}
Mike Stump1eb44332009-09-09 15:08:12 +00003610
Douglas Gregor43959a92009-08-20 07:17:43 +00003611template<typename Derived>
3612Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003613TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003614 // FIXME: Implement this
3615 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003616 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003617}
Mike Stump1eb44332009-09-09 15:08:12 +00003618
Douglas Gregor43959a92009-08-20 07:17:43 +00003619template<typename Derived>
3620Sema::OwningStmtResult
3621TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003622 ObjCAtSynchronizedStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003623 // FIXME: Implement this
3624 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003625 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003626}
3627
3628template<typename Derived>
3629Sema::OwningStmtResult
3630TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003631 ObjCForCollectionStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003632 // FIXME: Implement this
3633 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003634 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003635}
3636
3637
3638template<typename Derived>
3639Sema::OwningStmtResult
3640TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3641 // Transform the exception declaration, if any.
3642 VarDecl *Var = 0;
3643 if (S->getExceptionDecl()) {
3644 VarDecl *ExceptionDecl = S->getExceptionDecl();
3645 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3646 ExceptionDecl->getDeclName());
3647
3648 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3649 if (T.isNull())
3650 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003651
Douglas Gregor43959a92009-08-20 07:17:43 +00003652 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3653 T,
John McCalla93c9342009-12-07 02:54:59 +00003654 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003655 ExceptionDecl->getIdentifier(),
3656 ExceptionDecl->getLocation(),
3657 /*FIXME: Inaccurate*/
3658 SourceRange(ExceptionDecl->getLocation()));
3659 if (!Var || Var->isInvalidDecl()) {
3660 if (Var)
3661 Var->Destroy(SemaRef.Context);
3662 return SemaRef.StmtError();
3663 }
3664 }
Mike Stump1eb44332009-09-09 15:08:12 +00003665
Douglas Gregor43959a92009-08-20 07:17:43 +00003666 // Transform the actual exception handler.
3667 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3668 if (Handler.isInvalid()) {
3669 if (Var)
3670 Var->Destroy(SemaRef.Context);
3671 return SemaRef.StmtError();
3672 }
Mike Stump1eb44332009-09-09 15:08:12 +00003673
Douglas Gregor43959a92009-08-20 07:17:43 +00003674 if (!getDerived().AlwaysRebuild() &&
3675 !Var &&
3676 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00003677 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003678
3679 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3680 Var,
3681 move(Handler));
3682}
Mike Stump1eb44332009-09-09 15:08:12 +00003683
Douglas Gregor43959a92009-08-20 07:17:43 +00003684template<typename Derived>
3685Sema::OwningStmtResult
3686TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3687 // Transform the try block itself.
Mike Stump1eb44332009-09-09 15:08:12 +00003688 OwningStmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00003689 = getDerived().TransformCompoundStmt(S->getTryBlock());
3690 if (TryBlock.isInvalid())
3691 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003692
Douglas Gregor43959a92009-08-20 07:17:43 +00003693 // Transform the handlers.
3694 bool HandlerChanged = false;
3695 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3696 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump1eb44332009-09-09 15:08:12 +00003697 OwningStmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00003698 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3699 if (Handler.isInvalid())
3700 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003701
Douglas Gregor43959a92009-08-20 07:17:43 +00003702 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3703 Handlers.push_back(Handler.takeAs<Stmt>());
3704 }
Mike Stump1eb44332009-09-09 15:08:12 +00003705
Douglas Gregor43959a92009-08-20 07:17:43 +00003706 if (!getDerived().AlwaysRebuild() &&
3707 TryBlock.get() == S->getTryBlock() &&
3708 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003709 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003710
3711 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump1eb44332009-09-09 15:08:12 +00003712 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00003713}
Mike Stump1eb44332009-09-09 15:08:12 +00003714
Douglas Gregor43959a92009-08-20 07:17:43 +00003715//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00003716// Expression transformation
3717//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00003718template<typename Derived>
3719Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003720TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003721 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003722}
Mike Stump1eb44332009-09-09 15:08:12 +00003723
3724template<typename Derived>
3725Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003726TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00003727 NestedNameSpecifier *Qualifier = 0;
3728 if (E->getQualifier()) {
3729 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003730 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00003731 if (!Qualifier)
3732 return SemaRef.ExprError();
3733 }
John McCalldbd872f2009-12-08 09:08:17 +00003734
3735 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003736 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
3737 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00003738 if (!ND)
3739 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003740
Douglas Gregora2813ce2009-10-23 18:54:35 +00003741 if (!getDerived().AlwaysRebuild() &&
3742 Qualifier == E->getQualifier() &&
3743 ND == E->getDecl() &&
John McCalldbd872f2009-12-08 09:08:17 +00003744 !E->hasExplicitTemplateArgumentList()) {
3745
3746 // Mark it referenced in the new context regardless.
3747 // FIXME: this is a bit instantiation-specific.
3748 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3749
Mike Stump1eb44332009-09-09 15:08:12 +00003750 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00003751 }
John McCalldbd872f2009-12-08 09:08:17 +00003752
3753 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3754 if (E->hasExplicitTemplateArgumentList()) {
3755 TemplateArgs = &TransArgs;
3756 TransArgs.setLAngleLoc(E->getLAngleLoc());
3757 TransArgs.setRAngleLoc(E->getRAngleLoc());
3758 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3759 TemplateArgumentLoc Loc;
3760 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3761 return SemaRef.ExprError();
3762 TransArgs.addArgument(Loc);
3763 }
3764 }
3765
Douglas Gregora2813ce2009-10-23 18:54:35 +00003766 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCalldbd872f2009-12-08 09:08:17 +00003767 ND, E->getLocation(), TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003768}
Mike Stump1eb44332009-09-09 15:08:12 +00003769
Douglas Gregorb98b1992009-08-11 05:31:07 +00003770template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003771Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003772TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003773 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003774}
Mike Stump1eb44332009-09-09 15:08:12 +00003775
Douglas Gregorb98b1992009-08-11 05:31:07 +00003776template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003777Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003778TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003779 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003780}
Mike Stump1eb44332009-09-09 15:08:12 +00003781
Douglas Gregorb98b1992009-08-11 05:31:07 +00003782template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003783Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003784TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003785 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003786}
Mike Stump1eb44332009-09-09 15:08:12 +00003787
Douglas Gregorb98b1992009-08-11 05:31:07 +00003788template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003789Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003790TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003791 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003792}
Mike Stump1eb44332009-09-09 15:08:12 +00003793
Douglas Gregorb98b1992009-08-11 05:31:07 +00003794template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003795Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003796TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003797 return SemaRef.Owned(E->Retain());
3798}
3799
3800template<typename Derived>
3801Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003802TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003803 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3804 if (SubExpr.isInvalid())
3805 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003806
Douglas Gregorb98b1992009-08-11 05:31:07 +00003807 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003808 return SemaRef.Owned(E->Retain());
3809
3810 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003811 E->getRParen());
3812}
3813
Mike Stump1eb44332009-09-09 15:08:12 +00003814template<typename Derived>
3815Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003816TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3817 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003818 if (SubExpr.isInvalid())
3819 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003820
Douglas Gregorb98b1992009-08-11 05:31:07 +00003821 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003822 return SemaRef.Owned(E->Retain());
3823
Douglas Gregorb98b1992009-08-11 05:31:07 +00003824 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3825 E->getOpcode(),
3826 move(SubExpr));
3827}
Mike Stump1eb44332009-09-09 15:08:12 +00003828
Douglas Gregorb98b1992009-08-11 05:31:07 +00003829template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003830Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003831TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003832 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00003833 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00003834
John McCalla93c9342009-12-07 02:54:59 +00003835 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00003836 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003837 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003838
John McCall5ab75172009-11-04 07:28:41 +00003839 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003840 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003841
John McCall5ab75172009-11-04 07:28:41 +00003842 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00003843 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003844 E->getSourceRange());
3845 }
Mike Stump1eb44332009-09-09 15:08:12 +00003846
Douglas Gregorb98b1992009-08-11 05:31:07 +00003847 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00003848 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003849 // C++0x [expr.sizeof]p1:
3850 // The operand is either an expression, which is an unevaluated operand
3851 // [...]
3852 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003853
Douglas Gregorb98b1992009-08-11 05:31:07 +00003854 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3855 if (SubExpr.isInvalid())
3856 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003857
Douglas Gregorb98b1992009-08-11 05:31:07 +00003858 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3859 return SemaRef.Owned(E->Retain());
3860 }
Mike Stump1eb44332009-09-09 15:08:12 +00003861
Douglas Gregorb98b1992009-08-11 05:31:07 +00003862 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3863 E->isSizeOf(),
3864 E->getSourceRange());
3865}
Mike Stump1eb44332009-09-09 15:08:12 +00003866
Douglas Gregorb98b1992009-08-11 05:31:07 +00003867template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003868Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003869TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003870 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3871 if (LHS.isInvalid())
3872 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003873
Douglas Gregorb98b1992009-08-11 05:31:07 +00003874 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3875 if (RHS.isInvalid())
3876 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003877
3878
Douglas Gregorb98b1992009-08-11 05:31:07 +00003879 if (!getDerived().AlwaysRebuild() &&
3880 LHS.get() == E->getLHS() &&
3881 RHS.get() == E->getRHS())
3882 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003883
Douglas Gregorb98b1992009-08-11 05:31:07 +00003884 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3885 /*FIXME:*/E->getLHS()->getLocStart(),
3886 move(RHS),
3887 E->getRBracketLoc());
3888}
Mike Stump1eb44332009-09-09 15:08:12 +00003889
3890template<typename Derived>
3891Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003892TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003893 // Transform the callee.
3894 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3895 if (Callee.isInvalid())
3896 return SemaRef.ExprError();
3897
3898 // Transform arguments.
3899 bool ArgChanged = false;
3900 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3901 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3902 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3903 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3904 if (Arg.isInvalid())
3905 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003906
Douglas Gregorb98b1992009-08-11 05:31:07 +00003907 // FIXME: Wrong source location information for the ','.
3908 FakeCommaLocs.push_back(
3909 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00003910
3911 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003912 Args.push_back(Arg.takeAs<Expr>());
3913 }
Mike Stump1eb44332009-09-09 15:08:12 +00003914
Douglas Gregorb98b1992009-08-11 05:31:07 +00003915 if (!getDerived().AlwaysRebuild() &&
3916 Callee.get() == E->getCallee() &&
3917 !ArgChanged)
3918 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003919
Douglas Gregorb98b1992009-08-11 05:31:07 +00003920 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00003921 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003922 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3923 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3924 move_arg(Args),
3925 FakeCommaLocs.data(),
3926 E->getRParenLoc());
3927}
Mike Stump1eb44332009-09-09 15:08:12 +00003928
3929template<typename Derived>
3930Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003931TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003932 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3933 if (Base.isInvalid())
3934 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003935
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003936 NestedNameSpecifier *Qualifier = 0;
3937 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00003938 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003939 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003940 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00003941 if (Qualifier == 0)
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003942 return SemaRef.ExprError();
3943 }
Mike Stump1eb44332009-09-09 15:08:12 +00003944
Eli Friedmanf595cc42009-12-04 06:40:45 +00003945 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003946 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
3947 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00003948 if (!Member)
3949 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003950
John McCall6bb80172010-03-30 21:47:33 +00003951 NamedDecl *FoundDecl = E->getFoundDecl();
3952 if (FoundDecl == E->getMemberDecl()) {
3953 FoundDecl = Member;
3954 } else {
3955 FoundDecl = cast_or_null<NamedDecl>(
3956 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
3957 if (!FoundDecl)
3958 return SemaRef.ExprError();
3959 }
3960
Douglas Gregorb98b1992009-08-11 05:31:07 +00003961 if (!getDerived().AlwaysRebuild() &&
3962 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003963 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003964 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00003965 FoundDecl == E->getFoundDecl() &&
Anders Carlsson1f240322009-12-22 05:24:09 +00003966 !E->hasExplicitTemplateArgumentList()) {
3967
3968 // Mark it referenced in the new context regardless.
3969 // FIXME: this is a bit instantiation-specific.
3970 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00003971 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00003972 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00003973
John McCalld5532b62009-11-23 01:53:49 +00003974 TemplateArgumentListInfo TransArgs;
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003975 if (E->hasExplicitTemplateArgumentList()) {
John McCalld5532b62009-11-23 01:53:49 +00003976 TransArgs.setLAngleLoc(E->getLAngleLoc());
3977 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003978 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00003979 TemplateArgumentLoc Loc;
3980 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003981 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00003982 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003983 }
3984 }
3985
Douglas Gregorb98b1992009-08-11 05:31:07 +00003986 // FIXME: Bogus source location for the operator
3987 SourceLocation FakeOperatorLoc
3988 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3989
John McCallc2233c52010-01-15 08:34:02 +00003990 // FIXME: to do this check properly, we will need to preserve the
3991 // first-qualifier-in-scope here, just in case we had a dependent
3992 // base (and therefore couldn't do the check) and a
3993 // nested-name-qualifier (and therefore could do the lookup).
3994 NamedDecl *FirstQualifierInScope = 0;
3995
Douglas Gregorb98b1992009-08-11 05:31:07 +00003996 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3997 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003998 Qualifier,
3999 E->getQualifierRange(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004000 E->getMemberLoc(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004001 Member,
John McCall6bb80172010-03-30 21:47:33 +00004002 FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00004003 (E->hasExplicitTemplateArgumentList()
4004 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004005 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004006}
Mike Stump1eb44332009-09-09 15:08:12 +00004007
Douglas Gregorb98b1992009-08-11 05:31:07 +00004008template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00004009Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004010TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004011 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4012 if (LHS.isInvalid())
4013 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004014
Douglas Gregorb98b1992009-08-11 05:31:07 +00004015 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4016 if (RHS.isInvalid())
4017 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004018
Douglas Gregorb98b1992009-08-11 05:31:07 +00004019 if (!getDerived().AlwaysRebuild() &&
4020 LHS.get() == E->getLHS() &&
4021 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004022 return SemaRef.Owned(E->Retain());
4023
Douglas Gregorb98b1992009-08-11 05:31:07 +00004024 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4025 move(LHS), move(RHS));
4026}
4027
Mike Stump1eb44332009-09-09 15:08:12 +00004028template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00004029Sema::OwningExprResult
4030TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004031 CompoundAssignOperator *E) {
4032 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004033}
Mike Stump1eb44332009-09-09 15:08:12 +00004034
Douglas Gregorb98b1992009-08-11 05:31:07 +00004035template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004036Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004037TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004038 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4039 if (Cond.isInvalid())
4040 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004041
Douglas Gregorb98b1992009-08-11 05:31:07 +00004042 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4043 if (LHS.isInvalid())
4044 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004045
Douglas Gregorb98b1992009-08-11 05:31:07 +00004046 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4047 if (RHS.isInvalid())
4048 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004049
Douglas Gregorb98b1992009-08-11 05:31:07 +00004050 if (!getDerived().AlwaysRebuild() &&
4051 Cond.get() == E->getCond() &&
4052 LHS.get() == E->getLHS() &&
4053 RHS.get() == E->getRHS())
4054 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004055
4056 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004057 E->getQuestionLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004058 move(LHS),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004059 E->getColonLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004060 move(RHS));
4061}
Mike Stump1eb44332009-09-09 15:08:12 +00004062
4063template<typename Derived>
4064Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004065TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004066 // Implicit casts are eliminated during transformation, since they
4067 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004068 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004069}
Mike Stump1eb44332009-09-09 15:08:12 +00004070
Douglas Gregorb98b1992009-08-11 05:31:07 +00004071template<typename Derived>
4072Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004073TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004074 TypeSourceInfo *OldT;
4075 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004076 {
4077 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004078 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004079 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4080 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004081
John McCall9d125032010-01-15 18:39:57 +00004082 OldT = E->getTypeInfoAsWritten();
4083 NewT = getDerived().TransformType(OldT);
4084 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004085 return SemaRef.ExprError();
4086 }
Mike Stump1eb44332009-09-09 15:08:12 +00004087
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004088 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004089 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004090 if (SubExpr.isInvalid())
4091 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004092
Douglas Gregorb98b1992009-08-11 05:31:07 +00004093 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004094 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004095 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004096 return SemaRef.Owned(E->Retain());
4097
John McCall9d125032010-01-15 18:39:57 +00004098 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4099 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004100 E->getRParenLoc(),
4101 move(SubExpr));
4102}
Mike Stump1eb44332009-09-09 15:08:12 +00004103
Douglas Gregorb98b1992009-08-11 05:31:07 +00004104template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004105Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004106TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004107 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4108 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4109 if (!NewT)
4110 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004111
Douglas Gregorb98b1992009-08-11 05:31:07 +00004112 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4113 if (Init.isInvalid())
4114 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004115
Douglas Gregorb98b1992009-08-11 05:31:07 +00004116 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004117 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004118 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00004119 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004120
John McCall1d7d8d62010-01-19 22:33:45 +00004121 // Note: the expression type doesn't necessarily match the
4122 // type-as-written, but that's okay, because it should always be
4123 // derivable from the initializer.
4124
John McCall42f56b52010-01-18 19:35:47 +00004125 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004126 /*FIXME:*/E->getInitializer()->getLocEnd(),
4127 move(Init));
4128}
Mike Stump1eb44332009-09-09 15:08:12 +00004129
Douglas Gregorb98b1992009-08-11 05:31:07 +00004130template<typename Derived>
4131Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004132TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004133 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4134 if (Base.isInvalid())
4135 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004136
Douglas Gregorb98b1992009-08-11 05:31:07 +00004137 if (!getDerived().AlwaysRebuild() &&
4138 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00004139 return SemaRef.Owned(E->Retain());
4140
Douglas Gregorb98b1992009-08-11 05:31:07 +00004141 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004142 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004143 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4144 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4145 E->getAccessorLoc(),
4146 E->getAccessor());
4147}
Mike Stump1eb44332009-09-09 15:08:12 +00004148
Douglas Gregorb98b1992009-08-11 05:31:07 +00004149template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004150Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004151TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004152 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004153
Douglas Gregorb98b1992009-08-11 05:31:07 +00004154 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4155 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4156 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4157 if (Init.isInvalid())
4158 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004159
Douglas Gregorb98b1992009-08-11 05:31:07 +00004160 InitChanged = InitChanged || Init.get() != E->getInit(I);
4161 Inits.push_back(Init.takeAs<Expr>());
4162 }
Mike Stump1eb44332009-09-09 15:08:12 +00004163
Douglas Gregorb98b1992009-08-11 05:31:07 +00004164 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004165 return SemaRef.Owned(E->Retain());
4166
Douglas Gregorb98b1992009-08-11 05:31:07 +00004167 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004168 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004169}
Mike Stump1eb44332009-09-09 15:08:12 +00004170
Douglas Gregorb98b1992009-08-11 05:31:07 +00004171template<typename Derived>
4172Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004173TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004174 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004175
Douglas Gregor43959a92009-08-20 07:17:43 +00004176 // transform the initializer value
Douglas Gregorb98b1992009-08-11 05:31:07 +00004177 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4178 if (Init.isInvalid())
4179 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004180
Douglas Gregor43959a92009-08-20 07:17:43 +00004181 // transform the designators.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004182 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4183 bool ExprChanged = false;
4184 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4185 DEnd = E->designators_end();
4186 D != DEnd; ++D) {
4187 if (D->isFieldDesignator()) {
4188 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4189 D->getDotLoc(),
4190 D->getFieldLoc()));
4191 continue;
4192 }
Mike Stump1eb44332009-09-09 15:08:12 +00004193
Douglas Gregorb98b1992009-08-11 05:31:07 +00004194 if (D->isArrayDesignator()) {
4195 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4196 if (Index.isInvalid())
4197 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004198
4199 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004200 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004201
Douglas Gregorb98b1992009-08-11 05:31:07 +00004202 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4203 ArrayExprs.push_back(Index.release());
4204 continue;
4205 }
Mike Stump1eb44332009-09-09 15:08:12 +00004206
Douglas Gregorb98b1992009-08-11 05:31:07 +00004207 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump1eb44332009-09-09 15:08:12 +00004208 OwningExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004209 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4210 if (Start.isInvalid())
4211 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004212
Douglas Gregorb98b1992009-08-11 05:31:07 +00004213 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4214 if (End.isInvalid())
4215 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004216
4217 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004218 End.get(),
4219 D->getLBracketLoc(),
4220 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004221
Douglas Gregorb98b1992009-08-11 05:31:07 +00004222 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4223 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004224
Douglas Gregorb98b1992009-08-11 05:31:07 +00004225 ArrayExprs.push_back(Start.release());
4226 ArrayExprs.push_back(End.release());
4227 }
Mike Stump1eb44332009-09-09 15:08:12 +00004228
Douglas Gregorb98b1992009-08-11 05:31:07 +00004229 if (!getDerived().AlwaysRebuild() &&
4230 Init.get() == E->getInit() &&
4231 !ExprChanged)
4232 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004233
Douglas Gregorb98b1992009-08-11 05:31:07 +00004234 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4235 E->getEqualOrColonLoc(),
4236 E->usesGNUSyntax(), move(Init));
4237}
Mike Stump1eb44332009-09-09 15:08:12 +00004238
Douglas Gregorb98b1992009-08-11 05:31:07 +00004239template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004240Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004241TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004242 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004243 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4244
4245 // FIXME: Will we ever have proper type location here? Will we actually
4246 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004247 QualType T = getDerived().TransformType(E->getType());
4248 if (T.isNull())
4249 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004250
Douglas Gregorb98b1992009-08-11 05:31:07 +00004251 if (!getDerived().AlwaysRebuild() &&
4252 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004253 return SemaRef.Owned(E->Retain());
4254
Douglas Gregorb98b1992009-08-11 05:31:07 +00004255 return getDerived().RebuildImplicitValueInitExpr(T);
4256}
Mike Stump1eb44332009-09-09 15:08:12 +00004257
Douglas Gregorb98b1992009-08-11 05:31:07 +00004258template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004259Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004260TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004261 // FIXME: Do we want the type as written?
4262 QualType T;
Mike Stump1eb44332009-09-09 15:08:12 +00004263
Douglas Gregorb98b1992009-08-11 05:31:07 +00004264 {
4265 // FIXME: Source location isn't quite accurate.
4266 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4267 T = getDerived().TransformType(E->getType());
4268 if (T.isNull())
4269 return SemaRef.ExprError();
4270 }
Mike Stump1eb44332009-09-09 15:08:12 +00004271
Douglas Gregorb98b1992009-08-11 05:31:07 +00004272 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4273 if (SubExpr.isInvalid())
4274 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004275
Douglas Gregorb98b1992009-08-11 05:31:07 +00004276 if (!getDerived().AlwaysRebuild() &&
4277 T == E->getType() &&
4278 SubExpr.get() == E->getSubExpr())
4279 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004280
Douglas Gregorb98b1992009-08-11 05:31:07 +00004281 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4282 T, E->getRParenLoc());
4283}
4284
4285template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004286Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004287TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004288 bool ArgumentChanged = false;
4289 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4290 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4291 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4292 if (Init.isInvalid())
4293 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004294
Douglas Gregorb98b1992009-08-11 05:31:07 +00004295 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4296 Inits.push_back(Init.takeAs<Expr>());
4297 }
Mike Stump1eb44332009-09-09 15:08:12 +00004298
Douglas Gregorb98b1992009-08-11 05:31:07 +00004299 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4300 move_arg(Inits),
4301 E->getRParenLoc());
4302}
Mike Stump1eb44332009-09-09 15:08:12 +00004303
Douglas Gregorb98b1992009-08-11 05:31:07 +00004304/// \brief Transform an address-of-label expression.
4305///
4306/// By default, the transformation of an address-of-label expression always
4307/// rebuilds the expression, so that the label identifier can be resolved to
4308/// the corresponding label statement by semantic analysis.
4309template<typename Derived>
4310Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004311TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004312 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4313 E->getLabel());
4314}
Mike Stump1eb44332009-09-09 15:08:12 +00004315
4316template<typename Derived>
Douglas Gregorc86a6e92009-11-04 07:01:15 +00004317Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004318TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004319 OwningStmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004320 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4321 if (SubStmt.isInvalid())
4322 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004323
Douglas Gregorb98b1992009-08-11 05:31:07 +00004324 if (!getDerived().AlwaysRebuild() &&
4325 SubStmt.get() == E->getSubStmt())
4326 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004327
4328 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004329 move(SubStmt),
4330 E->getRParenLoc());
4331}
Mike Stump1eb44332009-09-09 15:08:12 +00004332
Douglas Gregorb98b1992009-08-11 05:31:07 +00004333template<typename Derived>
4334Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004335TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004336 QualType T1, T2;
4337 {
4338 // FIXME: Source location isn't quite accurate.
4339 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004340
Douglas Gregorb98b1992009-08-11 05:31:07 +00004341 T1 = getDerived().TransformType(E->getArgType1());
4342 if (T1.isNull())
4343 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004344
Douglas Gregorb98b1992009-08-11 05:31:07 +00004345 T2 = getDerived().TransformType(E->getArgType2());
4346 if (T2.isNull())
4347 return SemaRef.ExprError();
4348 }
4349
4350 if (!getDerived().AlwaysRebuild() &&
4351 T1 == E->getArgType1() &&
4352 T2 == E->getArgType2())
Mike Stump1eb44332009-09-09 15:08:12 +00004353 return SemaRef.Owned(E->Retain());
4354
Douglas Gregorb98b1992009-08-11 05:31:07 +00004355 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4356 T1, T2, E->getRParenLoc());
4357}
Mike Stump1eb44332009-09-09 15:08:12 +00004358
Douglas Gregorb98b1992009-08-11 05:31:07 +00004359template<typename Derived>
4360Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004361TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004362 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4363 if (Cond.isInvalid())
4364 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004365
Douglas Gregorb98b1992009-08-11 05:31:07 +00004366 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4367 if (LHS.isInvalid())
4368 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004369
Douglas Gregorb98b1992009-08-11 05:31:07 +00004370 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4371 if (RHS.isInvalid())
4372 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004373
Douglas Gregorb98b1992009-08-11 05:31:07 +00004374 if (!getDerived().AlwaysRebuild() &&
4375 Cond.get() == E->getCond() &&
4376 LHS.get() == E->getLHS() &&
4377 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004378 return SemaRef.Owned(E->Retain());
4379
Douglas Gregorb98b1992009-08-11 05:31:07 +00004380 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4381 move(Cond), move(LHS), move(RHS),
4382 E->getRParenLoc());
4383}
Mike Stump1eb44332009-09-09 15:08:12 +00004384
Douglas Gregorb98b1992009-08-11 05:31:07 +00004385template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004386Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004387TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004388 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004389}
4390
4391template<typename Derived>
4392Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004393TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004394 switch (E->getOperator()) {
4395 case OO_New:
4396 case OO_Delete:
4397 case OO_Array_New:
4398 case OO_Array_Delete:
4399 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4400 return SemaRef.ExprError();
4401
4402 case OO_Call: {
4403 // This is a call to an object's operator().
4404 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4405
4406 // Transform the object itself.
4407 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4408 if (Object.isInvalid())
4409 return SemaRef.ExprError();
4410
4411 // FIXME: Poor location information
4412 SourceLocation FakeLParenLoc
4413 = SemaRef.PP.getLocForEndOfToken(
4414 static_cast<Expr *>(Object.get())->getLocEnd());
4415
4416 // Transform the call arguments.
4417 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4418 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4419 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004420 if (getDerived().DropCallArgument(E->getArg(I)))
4421 break;
4422
Douglas Gregor668d6d92009-12-13 20:44:55 +00004423 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4424 if (Arg.isInvalid())
4425 return SemaRef.ExprError();
4426
4427 // FIXME: Poor source location information.
4428 SourceLocation FakeCommaLoc
4429 = SemaRef.PP.getLocForEndOfToken(
4430 static_cast<Expr *>(Arg.get())->getLocEnd());
4431 FakeCommaLocs.push_back(FakeCommaLoc);
4432 Args.push_back(Arg.release());
4433 }
4434
4435 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4436 move_arg(Args),
4437 FakeCommaLocs.data(),
4438 E->getLocEnd());
4439 }
4440
4441#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4442 case OO_##Name:
4443#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4444#include "clang/Basic/OperatorKinds.def"
4445 case OO_Subscript:
4446 // Handled below.
4447 break;
4448
4449 case OO_Conditional:
4450 llvm_unreachable("conditional operator is not actually overloadable");
4451 return SemaRef.ExprError();
4452
4453 case OO_None:
4454 case NUM_OVERLOADED_OPERATORS:
4455 llvm_unreachable("not an overloaded operator?");
4456 return SemaRef.ExprError();
4457 }
4458
Douglas Gregorb98b1992009-08-11 05:31:07 +00004459 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4460 if (Callee.isInvalid())
4461 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004462
John McCall454feb92009-12-08 09:21:05 +00004463 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004464 if (First.isInvalid())
4465 return SemaRef.ExprError();
4466
4467 OwningExprResult Second(SemaRef);
4468 if (E->getNumArgs() == 2) {
4469 Second = getDerived().TransformExpr(E->getArg(1));
4470 if (Second.isInvalid())
4471 return SemaRef.ExprError();
4472 }
Mike Stump1eb44332009-09-09 15:08:12 +00004473
Douglas Gregorb98b1992009-08-11 05:31:07 +00004474 if (!getDerived().AlwaysRebuild() &&
4475 Callee.get() == E->getCallee() &&
4476 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00004477 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4478 return SemaRef.Owned(E->Retain());
4479
Douglas Gregorb98b1992009-08-11 05:31:07 +00004480 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4481 E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004482 move(Callee),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004483 move(First),
4484 move(Second));
4485}
Mike Stump1eb44332009-09-09 15:08:12 +00004486
Douglas Gregorb98b1992009-08-11 05:31:07 +00004487template<typename Derived>
4488Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004489TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4490 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004491}
Mike Stump1eb44332009-09-09 15:08:12 +00004492
Douglas Gregorb98b1992009-08-11 05:31:07 +00004493template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004494Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004495TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004496 TypeSourceInfo *OldT;
4497 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004498 {
4499 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004500 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004501 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4502 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004503
John McCall9d125032010-01-15 18:39:57 +00004504 OldT = E->getTypeInfoAsWritten();
4505 NewT = getDerived().TransformType(OldT);
4506 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004507 return SemaRef.ExprError();
4508 }
Mike Stump1eb44332009-09-09 15:08:12 +00004509
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004510 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004511 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004512 if (SubExpr.isInvalid())
4513 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004514
Douglas Gregorb98b1992009-08-11 05:31:07 +00004515 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004516 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004517 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004518 return SemaRef.Owned(E->Retain());
4519
Douglas Gregorb98b1992009-08-11 05:31:07 +00004520 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00004521 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004522 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4523 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4524 SourceLocation FakeRParenLoc
4525 = SemaRef.PP.getLocForEndOfToken(
4526 E->getSubExpr()->getSourceRange().getEnd());
4527 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004528 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004529 FakeLAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00004530 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004531 FakeRAngleLoc,
4532 FakeRAngleLoc,
4533 move(SubExpr),
4534 FakeRParenLoc);
4535}
Mike Stump1eb44332009-09-09 15:08:12 +00004536
Douglas Gregorb98b1992009-08-11 05:31:07 +00004537template<typename Derived>
4538Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004539TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4540 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004541}
Mike Stump1eb44332009-09-09 15:08:12 +00004542
4543template<typename Derived>
4544Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004545TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4546 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004547}
4548
Douglas Gregorb98b1992009-08-11 05:31:07 +00004549template<typename Derived>
4550Sema::OwningExprResult
4551TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004552 CXXReinterpretCastExpr *E) {
4553 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004554}
Mike Stump1eb44332009-09-09 15:08:12 +00004555
Douglas Gregorb98b1992009-08-11 05:31:07 +00004556template<typename Derived>
4557Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004558TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4559 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004560}
Mike Stump1eb44332009-09-09 15:08:12 +00004561
Douglas Gregorb98b1992009-08-11 05:31:07 +00004562template<typename Derived>
4563Sema::OwningExprResult
4564TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004565 CXXFunctionalCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004566 TypeSourceInfo *OldT;
4567 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004568 {
4569 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004570
John McCall9d125032010-01-15 18:39:57 +00004571 OldT = E->getTypeInfoAsWritten();
4572 NewT = getDerived().TransformType(OldT);
4573 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004574 return SemaRef.ExprError();
4575 }
Mike Stump1eb44332009-09-09 15:08:12 +00004576
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004577 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004578 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004579 if (SubExpr.isInvalid())
4580 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004581
Douglas Gregorb98b1992009-08-11 05:31:07 +00004582 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004583 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004584 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004585 return SemaRef.Owned(E->Retain());
4586
Douglas Gregorb98b1992009-08-11 05:31:07 +00004587 // FIXME: The end of the type's source range is wrong
4588 return getDerived().RebuildCXXFunctionalCastExpr(
4589 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall9d125032010-01-15 18:39:57 +00004590 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004591 /*FIXME:*/E->getSubExpr()->getLocStart(),
4592 move(SubExpr),
4593 E->getRParenLoc());
4594}
Mike Stump1eb44332009-09-09 15:08:12 +00004595
Douglas Gregorb98b1992009-08-11 05:31:07 +00004596template<typename Derived>
4597Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004598TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004599 if (E->isTypeOperand()) {
4600 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004601
Douglas Gregorb98b1992009-08-11 05:31:07 +00004602 QualType T = getDerived().TransformType(E->getTypeOperand());
4603 if (T.isNull())
4604 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004605
Douglas Gregorb98b1992009-08-11 05:31:07 +00004606 if (!getDerived().AlwaysRebuild() &&
4607 T == E->getTypeOperand())
4608 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004609
Douglas Gregorb98b1992009-08-11 05:31:07 +00004610 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4611 /*FIXME:*/E->getLocStart(),
4612 T,
4613 E->getLocEnd());
4614 }
Mike Stump1eb44332009-09-09 15:08:12 +00004615
Douglas Gregorb98b1992009-08-11 05:31:07 +00004616 // We don't know whether the expression is potentially evaluated until
4617 // after we perform semantic analysis, so the expression is potentially
4618 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00004619 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004620 Action::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004621
Douglas Gregorb98b1992009-08-11 05:31:07 +00004622 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4623 if (SubExpr.isInvalid())
4624 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004625
Douglas Gregorb98b1992009-08-11 05:31:07 +00004626 if (!getDerived().AlwaysRebuild() &&
4627 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00004628 return SemaRef.Owned(E->Retain());
4629
Douglas Gregorb98b1992009-08-11 05:31:07 +00004630 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4631 /*FIXME:*/E->getLocStart(),
4632 move(SubExpr),
4633 E->getLocEnd());
4634}
4635
4636template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004637Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004638TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004639 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004640}
Mike Stump1eb44332009-09-09 15:08:12 +00004641
Douglas Gregorb98b1992009-08-11 05:31:07 +00004642template<typename Derived>
4643Sema::OwningExprResult
4644TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00004645 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004646 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004647}
Mike Stump1eb44332009-09-09 15:08:12 +00004648
Douglas Gregorb98b1992009-08-11 05:31:07 +00004649template<typename Derived>
4650Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004651TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004652 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004653
Douglas Gregorb98b1992009-08-11 05:31:07 +00004654 QualType T = getDerived().TransformType(E->getType());
4655 if (T.isNull())
4656 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004657
Douglas Gregorb98b1992009-08-11 05:31:07 +00004658 if (!getDerived().AlwaysRebuild() &&
4659 T == E->getType())
4660 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004661
Douglas Gregor828a1972010-01-07 23:12:05 +00004662 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004663}
Mike Stump1eb44332009-09-09 15:08:12 +00004664
Douglas Gregorb98b1992009-08-11 05:31:07 +00004665template<typename Derived>
4666Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004667TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004668 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4669 if (SubExpr.isInvalid())
4670 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004671
Douglas Gregorb98b1992009-08-11 05:31:07 +00004672 if (!getDerived().AlwaysRebuild() &&
4673 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004674 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004675
4676 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4677}
Mike Stump1eb44332009-09-09 15:08:12 +00004678
Douglas Gregorb98b1992009-08-11 05:31:07 +00004679template<typename Derived>
4680Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004681TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004682 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004683 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
4684 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004685 if (!Param)
4686 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004687
Chandler Carruth53cb6f82010-02-08 06:42:49 +00004688 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004689 Param == E->getParam())
4690 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004691
Douglas Gregor036aed12009-12-23 23:03:06 +00004692 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004693}
Mike Stump1eb44332009-09-09 15:08:12 +00004694
Douglas Gregorb98b1992009-08-11 05:31:07 +00004695template<typename Derived>
4696Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004697TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004698 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4699
4700 QualType T = getDerived().TransformType(E->getType());
4701 if (T.isNull())
4702 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004703
Douglas Gregorb98b1992009-08-11 05:31:07 +00004704 if (!getDerived().AlwaysRebuild() &&
4705 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004706 return SemaRef.Owned(E->Retain());
4707
4708 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004709 /*FIXME:*/E->getTypeBeginLoc(),
4710 T,
4711 E->getRParenLoc());
4712}
Mike Stump1eb44332009-09-09 15:08:12 +00004713
Douglas Gregorb98b1992009-08-11 05:31:07 +00004714template<typename Derived>
4715Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004716TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004717 // Transform the type that we're allocating
4718 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4719 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4720 if (AllocType.isNull())
4721 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004722
Douglas Gregorb98b1992009-08-11 05:31:07 +00004723 // Transform the size of the array we're allocating (if any).
4724 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4725 if (ArraySize.isInvalid())
4726 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004727
Douglas Gregorb98b1992009-08-11 05:31:07 +00004728 // Transform the placement arguments (if any).
4729 bool ArgumentChanged = false;
4730 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4731 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4732 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4733 if (Arg.isInvalid())
4734 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004735
Douglas Gregorb98b1992009-08-11 05:31:07 +00004736 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4737 PlacementArgs.push_back(Arg.take());
4738 }
Mike Stump1eb44332009-09-09 15:08:12 +00004739
Douglas Gregor43959a92009-08-20 07:17:43 +00004740 // transform the constructor arguments (if any).
Douglas Gregorb98b1992009-08-11 05:31:07 +00004741 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4742 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4743 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4744 if (Arg.isInvalid())
4745 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004746
Douglas Gregorb98b1992009-08-11 05:31:07 +00004747 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4748 ConstructorArgs.push_back(Arg.take());
4749 }
Mike Stump1eb44332009-09-09 15:08:12 +00004750
Douglas Gregor1af74512010-02-26 00:38:10 +00004751 // Transform constructor, new operator, and delete operator.
4752 CXXConstructorDecl *Constructor = 0;
4753 if (E->getConstructor()) {
4754 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004755 getDerived().TransformDecl(E->getLocStart(),
4756 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00004757 if (!Constructor)
4758 return SemaRef.ExprError();
4759 }
4760
4761 FunctionDecl *OperatorNew = 0;
4762 if (E->getOperatorNew()) {
4763 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004764 getDerived().TransformDecl(E->getLocStart(),
4765 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00004766 if (!OperatorNew)
4767 return SemaRef.ExprError();
4768 }
4769
4770 FunctionDecl *OperatorDelete = 0;
4771 if (E->getOperatorDelete()) {
4772 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004773 getDerived().TransformDecl(E->getLocStart(),
4774 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00004775 if (!OperatorDelete)
4776 return SemaRef.ExprError();
4777 }
4778
Douglas Gregorb98b1992009-08-11 05:31:07 +00004779 if (!getDerived().AlwaysRebuild() &&
4780 AllocType == E->getAllocatedType() &&
4781 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00004782 Constructor == E->getConstructor() &&
4783 OperatorNew == E->getOperatorNew() &&
4784 OperatorDelete == E->getOperatorDelete() &&
4785 !ArgumentChanged) {
4786 // Mark any declarations we need as referenced.
4787 // FIXME: instantiation-specific.
4788 if (Constructor)
4789 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
4790 if (OperatorNew)
4791 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
4792 if (OperatorDelete)
4793 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00004794 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00004795 }
Mike Stump1eb44332009-09-09 15:08:12 +00004796
Douglas Gregor5b5ad842009-12-22 17:13:37 +00004797 if (!ArraySize.get()) {
4798 // If no array size was specified, but the new expression was
4799 // instantiated with an array type (e.g., "new T" where T is
4800 // instantiated with "int[4]"), extract the outer bound from the
4801 // array type as our array size. We do this with constant and
4802 // dependently-sized array types.
4803 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4804 if (!ArrayT) {
4805 // Do nothing
4806 } else if (const ConstantArrayType *ConsArrayT
4807 = dyn_cast<ConstantArrayType>(ArrayT)) {
4808 ArraySize
4809 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4810 ConsArrayT->getSize(),
4811 SemaRef.Context.getSizeType(),
4812 /*FIXME:*/E->getLocStart()));
4813 AllocType = ConsArrayT->getElementType();
4814 } else if (const DependentSizedArrayType *DepArrayT
4815 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4816 if (DepArrayT->getSizeExpr()) {
4817 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4818 AllocType = DepArrayT->getElementType();
4819 }
4820 }
4821 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004822 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4823 E->isGlobalNew(),
4824 /*FIXME:*/E->getLocStart(),
4825 move_arg(PlacementArgs),
4826 /*FIXME:*/E->getLocStart(),
4827 E->isParenTypeId(),
4828 AllocType,
4829 /*FIXME:*/E->getLocStart(),
4830 /*FIXME:*/SourceRange(),
4831 move(ArraySize),
4832 /*FIXME:*/E->getLocStart(),
4833 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00004834 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004835}
Mike Stump1eb44332009-09-09 15:08:12 +00004836
Douglas Gregorb98b1992009-08-11 05:31:07 +00004837template<typename Derived>
4838Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004839TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004840 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4841 if (Operand.isInvalid())
4842 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004843
Douglas Gregor1af74512010-02-26 00:38:10 +00004844 // Transform the delete operator, if known.
4845 FunctionDecl *OperatorDelete = 0;
4846 if (E->getOperatorDelete()) {
4847 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004848 getDerived().TransformDecl(E->getLocStart(),
4849 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00004850 if (!OperatorDelete)
4851 return SemaRef.ExprError();
4852 }
4853
Douglas Gregorb98b1992009-08-11 05:31:07 +00004854 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00004855 Operand.get() == E->getArgument() &&
4856 OperatorDelete == E->getOperatorDelete()) {
4857 // Mark any declarations we need as referenced.
4858 // FIXME: instantiation-specific.
4859 if (OperatorDelete)
4860 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00004861 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00004862 }
Mike Stump1eb44332009-09-09 15:08:12 +00004863
Douglas Gregorb98b1992009-08-11 05:31:07 +00004864 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4865 E->isGlobalDelete(),
4866 E->isArrayForm(),
4867 move(Operand));
4868}
Mike Stump1eb44332009-09-09 15:08:12 +00004869
Douglas Gregorb98b1992009-08-11 05:31:07 +00004870template<typename Derived>
4871Sema::OwningExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00004872TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00004873 CXXPseudoDestructorExpr *E) {
Douglas Gregora71d8192009-09-04 17:36:40 +00004874 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4875 if (Base.isInvalid())
4876 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004877
Douglas Gregora2e7dd22010-02-25 01:56:36 +00004878 Sema::TypeTy *ObjectTypePtr = 0;
4879 bool MayBePseudoDestructor = false;
4880 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4881 E->getOperatorLoc(),
4882 E->isArrow()? tok::arrow : tok::period,
4883 ObjectTypePtr,
4884 MayBePseudoDestructor);
4885 if (Base.isInvalid())
4886 return SemaRef.ExprError();
4887
4888 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregora71d8192009-09-04 17:36:40 +00004889 NestedNameSpecifier *Qualifier
4890 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00004891 E->getQualifierRange(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00004892 ObjectType);
Douglas Gregora71d8192009-09-04 17:36:40 +00004893 if (E->getQualifier() && !Qualifier)
4894 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004895
Douglas Gregora2e7dd22010-02-25 01:56:36 +00004896 PseudoDestructorTypeStorage Destroyed;
4897 if (E->getDestroyedTypeInfo()) {
4898 TypeSourceInfo *DestroyedTypeInfo
4899 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
4900 if (!DestroyedTypeInfo)
4901 return SemaRef.ExprError();
4902 Destroyed = DestroyedTypeInfo;
4903 } else if (ObjectType->isDependentType()) {
4904 // We aren't likely to be able to resolve the identifier down to a type
4905 // now anyway, so just retain the identifier.
4906 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
4907 E->getDestroyedTypeLoc());
4908 } else {
4909 // Look for a destructor known with the given name.
4910 CXXScopeSpec SS;
4911 if (Qualifier) {
4912 SS.setScopeRep(Qualifier);
4913 SS.setRange(E->getQualifierRange());
4914 }
4915
4916 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
4917 *E->getDestroyedTypeIdentifier(),
4918 E->getDestroyedTypeLoc(),
4919 /*Scope=*/0,
4920 SS, ObjectTypePtr,
4921 false);
4922 if (!T)
4923 return SemaRef.ExprError();
4924
4925 Destroyed
4926 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
4927 E->getDestroyedTypeLoc());
4928 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004929
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004930 TypeSourceInfo *ScopeTypeInfo = 0;
4931 if (E->getScopeTypeInfo()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00004932 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
4933 ObjectType);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004934 if (!ScopeTypeInfo)
Douglas Gregora71d8192009-09-04 17:36:40 +00004935 return SemaRef.ExprError();
4936 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004937
Douglas Gregora71d8192009-09-04 17:36:40 +00004938 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4939 E->getOperatorLoc(),
4940 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00004941 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004942 E->getQualifierRange(),
4943 ScopeTypeInfo,
4944 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00004945 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00004946 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00004947}
Mike Stump1eb44332009-09-09 15:08:12 +00004948
Douglas Gregora71d8192009-09-04 17:36:40 +00004949template<typename Derived>
4950Sema::OwningExprResult
John McCallba135432009-11-21 08:51:07 +00004951TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00004952 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00004953 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4954
4955 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4956 Sema::LookupOrdinaryName);
4957
4958 // Transform all the decls.
4959 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4960 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004961 NamedDecl *InstD = static_cast<NamedDecl*>(
4962 getDerived().TransformDecl(Old->getNameLoc(),
4963 *I));
John McCall9f54ad42009-12-10 09:41:52 +00004964 if (!InstD) {
4965 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4966 // This can happen because of dependent hiding.
4967 if (isa<UsingShadowDecl>(*I))
4968 continue;
4969 else
4970 return SemaRef.ExprError();
4971 }
John McCallf7a1a742009-11-24 19:00:30 +00004972
4973 // Expand using declarations.
4974 if (isa<UsingDecl>(InstD)) {
4975 UsingDecl *UD = cast<UsingDecl>(InstD);
4976 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4977 E = UD->shadow_end(); I != E; ++I)
4978 R.addDecl(*I);
4979 continue;
4980 }
4981
4982 R.addDecl(InstD);
4983 }
4984
4985 // Resolve a kind, but don't do any further analysis. If it's
4986 // ambiguous, the callee needs to deal with it.
4987 R.resolveKind();
4988
4989 // Rebuild the nested-name qualifier, if present.
4990 CXXScopeSpec SS;
4991 NestedNameSpecifier *Qualifier = 0;
4992 if (Old->getQualifier()) {
4993 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004994 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00004995 if (!Qualifier)
4996 return SemaRef.ExprError();
4997
4998 SS.setScopeRep(Qualifier);
4999 SS.setRange(Old->getQualifierRange());
5000 }
5001
5002 // If we have no template arguments, it's a normal declaration name.
5003 if (!Old->hasExplicitTemplateArgs())
5004 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5005
5006 // If we have template arguments, rebuild them, then rebuild the
5007 // templateid expression.
5008 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5009 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5010 TemplateArgumentLoc Loc;
5011 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5012 return SemaRef.ExprError();
5013 TransArgs.addArgument(Loc);
5014 }
5015
5016 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5017 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005018}
Mike Stump1eb44332009-09-09 15:08:12 +00005019
Douglas Gregorb98b1992009-08-11 05:31:07 +00005020template<typename Derived>
5021Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005022TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005023 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005024
Douglas Gregorb98b1992009-08-11 05:31:07 +00005025 QualType T = getDerived().TransformType(E->getQueriedType());
5026 if (T.isNull())
5027 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005028
Douglas Gregorb98b1992009-08-11 05:31:07 +00005029 if (!getDerived().AlwaysRebuild() &&
5030 T == E->getQueriedType())
5031 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005032
Douglas Gregorb98b1992009-08-11 05:31:07 +00005033 // FIXME: Bad location information
5034 SourceLocation FakeLParenLoc
5035 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump1eb44332009-09-09 15:08:12 +00005036
5037 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005038 E->getLocStart(),
5039 /*FIXME:*/FakeLParenLoc,
5040 T,
5041 E->getLocEnd());
5042}
Mike Stump1eb44332009-09-09 15:08:12 +00005043
Douglas Gregorb98b1992009-08-11 05:31:07 +00005044template<typename Derived>
5045Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00005046TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall454feb92009-12-08 09:21:05 +00005047 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005048 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00005049 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005050 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005051 if (!NNS)
5052 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005053
5054 DeclarationName Name
Douglas Gregor81499bb2009-09-03 22:13:48 +00005055 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5056 if (!Name)
5057 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005058
John McCallf7a1a742009-11-24 19:00:30 +00005059 if (!E->hasExplicitTemplateArgs()) {
5060 if (!getDerived().AlwaysRebuild() &&
5061 NNS == E->getQualifier() &&
5062 Name == E->getDeclName())
5063 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005064
John McCallf7a1a742009-11-24 19:00:30 +00005065 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5066 E->getQualifierRange(),
5067 Name, E->getLocation(),
5068 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00005069 }
John McCalld5532b62009-11-23 01:53:49 +00005070
5071 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005072 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005073 TemplateArgumentLoc Loc;
5074 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb98b1992009-08-11 05:31:07 +00005075 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005076 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005077 }
5078
John McCallf7a1a742009-11-24 19:00:30 +00005079 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5080 E->getQualifierRange(),
5081 Name, E->getLocation(),
5082 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005083}
5084
5085template<typename Derived>
5086Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005087TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00005088 // CXXConstructExprs are always implicit, so when we have a
5089 // 1-argument construction we just transform that argument.
5090 if (E->getNumArgs() == 1 ||
5091 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5092 return getDerived().TransformExpr(E->getArg(0));
5093
Douglas Gregorb98b1992009-08-11 05:31:07 +00005094 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5095
5096 QualType T = getDerived().TransformType(E->getType());
5097 if (T.isNull())
5098 return SemaRef.ExprError();
5099
5100 CXXConstructorDecl *Constructor
5101 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005102 getDerived().TransformDecl(E->getLocStart(),
5103 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005104 if (!Constructor)
5105 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005106
Douglas Gregorb98b1992009-08-11 05:31:07 +00005107 bool ArgumentChanged = false;
5108 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005109 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005110 ArgEnd = E->arg_end();
5111 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005112 if (getDerived().DropCallArgument(*Arg)) {
5113 ArgumentChanged = true;
5114 break;
5115 }
5116
Douglas Gregorb98b1992009-08-11 05:31:07 +00005117 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5118 if (TransArg.isInvalid())
5119 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005120
Douglas Gregorb98b1992009-08-11 05:31:07 +00005121 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5122 Args.push_back(TransArg.takeAs<Expr>());
5123 }
5124
5125 if (!getDerived().AlwaysRebuild() &&
5126 T == E->getType() &&
5127 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005128 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005129 // Mark the constructor as referenced.
5130 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005131 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005132 return SemaRef.Owned(E->Retain());
Douglas Gregorc845aad2010-02-26 00:01:57 +00005133 }
Mike Stump1eb44332009-09-09 15:08:12 +00005134
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005135 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5136 Constructor, E->isElidable(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005137 move_arg(Args));
5138}
Mike Stump1eb44332009-09-09 15:08:12 +00005139
Douglas Gregorb98b1992009-08-11 05:31:07 +00005140/// \brief Transform a C++ temporary-binding expression.
5141///
Douglas Gregor51326552009-12-24 18:51:59 +00005142/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5143/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005144template<typename Derived>
5145Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005146TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005147 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005148}
Mike Stump1eb44332009-09-09 15:08:12 +00005149
Anders Carlssoneb60edf2010-01-29 02:39:32 +00005150/// \brief Transform a C++ reference-binding expression.
5151///
5152/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5153/// transform the subexpression and return that.
5154template<typename Derived>
5155Sema::OwningExprResult
5156TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5157 return getDerived().TransformExpr(E->getSubExpr());
5158}
5159
Mike Stump1eb44332009-09-09 15:08:12 +00005160/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00005161/// be destroyed after the expression is evaluated.
5162///
Douglas Gregor51326552009-12-24 18:51:59 +00005163/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5164/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005165template<typename Derived>
5166Sema::OwningExprResult
5167TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00005168 CXXExprWithTemporaries *E) {
5169 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005170}
Mike Stump1eb44332009-09-09 15:08:12 +00005171
Douglas Gregorb98b1992009-08-11 05:31:07 +00005172template<typename Derived>
5173Sema::OwningExprResult
5174TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall454feb92009-12-08 09:21:05 +00005175 CXXTemporaryObjectExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005176 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5177 QualType T = getDerived().TransformType(E->getType());
5178 if (T.isNull())
5179 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005180
Douglas Gregorb98b1992009-08-11 05:31:07 +00005181 CXXConstructorDecl *Constructor
5182 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005183 getDerived().TransformDecl(E->getLocStart(),
5184 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005185 if (!Constructor)
5186 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005187
Douglas Gregorb98b1992009-08-11 05:31:07 +00005188 bool ArgumentChanged = false;
5189 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5190 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005191 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005192 ArgEnd = E->arg_end();
5193 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005194 if (getDerived().DropCallArgument(*Arg)) {
5195 ArgumentChanged = true;
5196 break;
5197 }
5198
Douglas Gregorb98b1992009-08-11 05:31:07 +00005199 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5200 if (TransArg.isInvalid())
5201 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005202
Douglas Gregorb98b1992009-08-11 05:31:07 +00005203 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5204 Args.push_back((Expr *)TransArg.release());
5205 }
Mike Stump1eb44332009-09-09 15:08:12 +00005206
Douglas Gregorb98b1992009-08-11 05:31:07 +00005207 if (!getDerived().AlwaysRebuild() &&
5208 T == E->getType() &&
5209 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005210 !ArgumentChanged) {
5211 // FIXME: Instantiation-specific
5212 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carrutha3ce8ae2010-03-31 18:34:58 +00005213 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor91be6f52010-03-02 17:18:33 +00005214 }
Mike Stump1eb44332009-09-09 15:08:12 +00005215
Douglas Gregorb98b1992009-08-11 05:31:07 +00005216 // FIXME: Bogus location information
5217 SourceLocation CommaLoc;
5218 if (Args.size() > 1) {
5219 Expr *First = (Expr *)Args[0];
Mike Stump1eb44332009-09-09 15:08:12 +00005220 CommaLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005221 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5222 }
5223 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5224 T,
5225 /*FIXME:*/E->getTypeBeginLoc(),
5226 move_arg(Args),
5227 &CommaLoc,
5228 E->getLocEnd());
5229}
Mike Stump1eb44332009-09-09 15:08:12 +00005230
Douglas Gregorb98b1992009-08-11 05:31:07 +00005231template<typename Derived>
5232Sema::OwningExprResult
5233TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005234 CXXUnresolvedConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005235 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5236 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5237 if (T.isNull())
5238 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005239
Douglas Gregorb98b1992009-08-11 05:31:07 +00005240 bool ArgumentChanged = false;
5241 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5242 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5243 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5244 ArgEnd = E->arg_end();
5245 Arg != ArgEnd; ++Arg) {
5246 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5247 if (TransArg.isInvalid())
5248 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005249
Douglas Gregorb98b1992009-08-11 05:31:07 +00005250 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5251 FakeCommaLocs.push_back(
5252 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5253 Args.push_back(TransArg.takeAs<Expr>());
5254 }
Mike Stump1eb44332009-09-09 15:08:12 +00005255
Douglas Gregorb98b1992009-08-11 05:31:07 +00005256 if (!getDerived().AlwaysRebuild() &&
5257 T == E->getTypeAsWritten() &&
5258 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005259 return SemaRef.Owned(E->Retain());
5260
Douglas Gregorb98b1992009-08-11 05:31:07 +00005261 // FIXME: we're faking the locations of the commas
5262 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5263 T,
5264 E->getLParenLoc(),
5265 move_arg(Args),
5266 FakeCommaLocs.data(),
5267 E->getRParenLoc());
5268}
Mike Stump1eb44332009-09-09 15:08:12 +00005269
Douglas Gregorb98b1992009-08-11 05:31:07 +00005270template<typename Derived>
5271Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00005272TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall454feb92009-12-08 09:21:05 +00005273 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005274 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005275 OwningExprResult Base(SemaRef, (Expr*) 0);
5276 Expr *OldBase;
5277 QualType BaseType;
5278 QualType ObjectType;
5279 if (!E->isImplicitAccess()) {
5280 OldBase = E->getBase();
5281 Base = getDerived().TransformExpr(OldBase);
5282 if (Base.isInvalid())
5283 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005284
John McCallaa81e162009-12-01 22:10:20 +00005285 // Start the member reference and compute the object's type.
5286 Sema::TypeTy *ObjectTy = 0;
Douglas Gregord4dca082010-02-24 18:44:31 +00005287 bool MayBePseudoDestructor = false;
John McCallaa81e162009-12-01 22:10:20 +00005288 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5289 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005290 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005291 ObjectTy,
5292 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005293 if (Base.isInvalid())
5294 return SemaRef.ExprError();
5295
5296 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5297 BaseType = ((Expr*) Base.get())->getType();
5298 } else {
5299 OldBase = 0;
5300 BaseType = getDerived().TransformType(E->getBaseType());
5301 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5302 }
Mike Stump1eb44332009-09-09 15:08:12 +00005303
Douglas Gregor6cd21982009-10-20 05:58:46 +00005304 // Transform the first part of the nested-name-specifier that qualifies
5305 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005306 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005307 = getDerived().TransformFirstQualifierInScope(
5308 E->getFirstQualifierFoundInScope(),
5309 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005310
Douglas Gregora38c6872009-09-03 16:14:30 +00005311 NestedNameSpecifier *Qualifier = 0;
5312 if (E->getQualifier()) {
5313 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5314 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005315 ObjectType,
5316 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005317 if (!Qualifier)
5318 return SemaRef.ExprError();
5319 }
Mike Stump1eb44332009-09-09 15:08:12 +00005320
5321 DeclarationName Name
Douglas Gregordd62b152009-10-19 22:04:39 +00005322 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCallaa81e162009-12-01 22:10:20 +00005323 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00005324 if (!Name)
5325 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005326
John McCallaa81e162009-12-01 22:10:20 +00005327 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005328 // This is a reference to a member without an explicitly-specified
5329 // template argument list. Optimize for this common case.
5330 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005331 Base.get() == OldBase &&
5332 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005333 Qualifier == E->getQualifier() &&
5334 Name == E->getMember() &&
5335 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005336 return SemaRef.Owned(E->Retain());
5337
John McCall865d4472009-11-19 22:55:06 +00005338 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005339 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005340 E->isArrow(),
5341 E->getOperatorLoc(),
5342 Qualifier,
5343 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005344 FirstQualifierInScope,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005345 Name,
5346 E->getMemberLoc(),
John McCall129e2df2009-11-30 22:42:35 +00005347 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005348 }
5349
John McCalld5532b62009-11-23 01:53:49 +00005350 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005351 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005352 TemplateArgumentLoc Loc;
5353 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005354 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005355 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005356 }
Mike Stump1eb44332009-09-09 15:08:12 +00005357
John McCall865d4472009-11-19 22:55:06 +00005358 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005359 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005360 E->isArrow(),
5361 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005362 Qualifier,
5363 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005364 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005365 Name,
5366 E->getMemberLoc(),
5367 &TransArgs);
5368}
5369
5370template<typename Derived>
5371Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005372TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005373 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005374 OwningExprResult Base(SemaRef, (Expr*) 0);
5375 QualType BaseType;
5376 if (!Old->isImplicitAccess()) {
5377 Base = getDerived().TransformExpr(Old->getBase());
5378 if (Base.isInvalid())
5379 return SemaRef.ExprError();
5380 BaseType = ((Expr*) Base.get())->getType();
5381 } else {
5382 BaseType = getDerived().TransformType(Old->getBaseType());
5383 }
John McCall129e2df2009-11-30 22:42:35 +00005384
5385 NestedNameSpecifier *Qualifier = 0;
5386 if (Old->getQualifier()) {
5387 Qualifier
5388 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005389 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00005390 if (Qualifier == 0)
5391 return SemaRef.ExprError();
5392 }
5393
5394 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5395 Sema::LookupOrdinaryName);
5396
5397 // Transform all the decls.
5398 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5399 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005400 NamedDecl *InstD = static_cast<NamedDecl*>(
5401 getDerived().TransformDecl(Old->getMemberLoc(),
5402 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005403 if (!InstD) {
5404 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5405 // This can happen because of dependent hiding.
5406 if (isa<UsingShadowDecl>(*I))
5407 continue;
5408 else
5409 return SemaRef.ExprError();
5410 }
John McCall129e2df2009-11-30 22:42:35 +00005411
5412 // Expand using declarations.
5413 if (isa<UsingDecl>(InstD)) {
5414 UsingDecl *UD = cast<UsingDecl>(InstD);
5415 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5416 E = UD->shadow_end(); I != E; ++I)
5417 R.addDecl(*I);
5418 continue;
5419 }
5420
5421 R.addDecl(InstD);
5422 }
5423
5424 R.resolveKind();
5425
5426 TemplateArgumentListInfo TransArgs;
5427 if (Old->hasExplicitTemplateArgs()) {
5428 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5429 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5430 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5431 TemplateArgumentLoc Loc;
5432 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5433 Loc))
5434 return SemaRef.ExprError();
5435 TransArgs.addArgument(Loc);
5436 }
5437 }
John McCallc2233c52010-01-15 08:34:02 +00005438
5439 // FIXME: to do this check properly, we will need to preserve the
5440 // first-qualifier-in-scope here, just in case we had a dependent
5441 // base (and therefore couldn't do the check) and a
5442 // nested-name-qualifier (and therefore could do the lookup).
5443 NamedDecl *FirstQualifierInScope = 0;
John McCall129e2df2009-11-30 22:42:35 +00005444
5445 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005446 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00005447 Old->getOperatorLoc(),
5448 Old->isArrow(),
5449 Qualifier,
5450 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00005451 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005452 R,
5453 (Old->hasExplicitTemplateArgs()
5454 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005455}
5456
5457template<typename Derived>
5458Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005459TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005460 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005461}
5462
Mike Stump1eb44332009-09-09 15:08:12 +00005463template<typename Derived>
5464Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005465TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005466 // FIXME: poor source location
5467 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5468 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5469 if (EncodedType.isNull())
5470 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005471
Douglas Gregorb98b1992009-08-11 05:31:07 +00005472 if (!getDerived().AlwaysRebuild() &&
5473 EncodedType == E->getEncodedType())
Mike Stump1eb44332009-09-09 15:08:12 +00005474 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005475
5476 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5477 EncodedType,
5478 E->getRParenLoc());
5479}
Mike Stump1eb44332009-09-09 15:08:12 +00005480
Douglas Gregorb98b1992009-08-11 05:31:07 +00005481template<typename Derived>
5482Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005483TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005484 // FIXME: Implement this!
5485 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005486 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005487}
5488
Mike Stump1eb44332009-09-09 15:08:12 +00005489template<typename Derived>
5490Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005491TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005492 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005493}
5494
Mike Stump1eb44332009-09-09 15:08:12 +00005495template<typename Derived>
5496Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005497TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005498 ObjCProtocolDecl *Protocol
Douglas Gregorb98b1992009-08-11 05:31:07 +00005499 = cast_or_null<ObjCProtocolDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005500 getDerived().TransformDecl(E->getLocStart(),
5501 E->getProtocol()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005502 if (!Protocol)
5503 return SemaRef.ExprError();
5504
5505 if (!getDerived().AlwaysRebuild() &&
5506 Protocol == E->getProtocol())
Mike Stump1eb44332009-09-09 15:08:12 +00005507 return SemaRef.Owned(E->Retain());
5508
Douglas Gregorb98b1992009-08-11 05:31:07 +00005509 return getDerived().RebuildObjCProtocolExpr(Protocol,
5510 E->getAtLoc(),
5511 /*FIXME:*/E->getAtLoc(),
5512 /*FIXME:*/E->getAtLoc(),
5513 E->getRParenLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00005514
Douglas Gregorb98b1992009-08-11 05:31:07 +00005515}
5516
Mike Stump1eb44332009-09-09 15:08:12 +00005517template<typename Derived>
5518Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005519TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005520 // FIXME: Implement this!
5521 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005522 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005523}
5524
Mike Stump1eb44332009-09-09 15:08:12 +00005525template<typename Derived>
5526Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005527TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005528 // FIXME: Implement this!
5529 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005530 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005531}
5532
Mike Stump1eb44332009-09-09 15:08:12 +00005533template<typename Derived>
5534Sema::OwningExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00005535TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00005536 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005537 // FIXME: Implement this!
5538 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005539 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005540}
5541
Mike Stump1eb44332009-09-09 15:08:12 +00005542template<typename Derived>
5543Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005544TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005545 // FIXME: Implement this!
5546 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005547 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005548}
5549
Mike Stump1eb44332009-09-09 15:08:12 +00005550template<typename Derived>
5551Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005552TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005553 // FIXME: Implement this!
5554 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005555 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005556}
5557
Mike Stump1eb44332009-09-09 15:08:12 +00005558template<typename Derived>
5559Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005560TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005561 bool ArgumentChanged = false;
5562 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5563 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5564 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5565 if (SubExpr.isInvalid())
5566 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005567
Douglas Gregorb98b1992009-08-11 05:31:07 +00005568 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5569 SubExprs.push_back(SubExpr.takeAs<Expr>());
5570 }
Mike Stump1eb44332009-09-09 15:08:12 +00005571
Douglas Gregorb98b1992009-08-11 05:31:07 +00005572 if (!getDerived().AlwaysRebuild() &&
5573 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005574 return SemaRef.Owned(E->Retain());
5575
Douglas Gregorb98b1992009-08-11 05:31:07 +00005576 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5577 move_arg(SubExprs),
5578 E->getRParenLoc());
5579}
5580
Mike Stump1eb44332009-09-09 15:08:12 +00005581template<typename Derived>
5582Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005583TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005584 // FIXME: Implement this!
5585 assert(false && "Cannot transform block expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005586 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005587}
5588
Mike Stump1eb44332009-09-09 15:08:12 +00005589template<typename Derived>
5590Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005591TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005592 // FIXME: Implement this!
5593 assert(false && "Cannot transform block-related expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005594 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005595}
Mike Stump1eb44332009-09-09 15:08:12 +00005596
Douglas Gregorb98b1992009-08-11 05:31:07 +00005597//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00005598// Type reconstruction
5599//===----------------------------------------------------------------------===//
5600
Mike Stump1eb44332009-09-09 15:08:12 +00005601template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005602QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5603 SourceLocation Star) {
5604 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005605 getDerived().getBaseEntity());
5606}
5607
Mike Stump1eb44332009-09-09 15:08:12 +00005608template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005609QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5610 SourceLocation Star) {
5611 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005612 getDerived().getBaseEntity());
5613}
5614
Mike Stump1eb44332009-09-09 15:08:12 +00005615template<typename Derived>
5616QualType
John McCall85737a72009-10-30 00:06:24 +00005617TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5618 bool WrittenAsLValue,
5619 SourceLocation Sigil) {
5620 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5621 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005622}
5623
5624template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005625QualType
John McCall85737a72009-10-30 00:06:24 +00005626TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5627 QualType ClassType,
5628 SourceLocation Sigil) {
John McCall0953e762009-09-24 19:53:00 +00005629 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall85737a72009-10-30 00:06:24 +00005630 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005631}
5632
5633template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005634QualType
John McCall85737a72009-10-30 00:06:24 +00005635TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5636 SourceLocation Sigil) {
5637 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCalla2becad2009-10-21 00:40:46 +00005638 getDerived().getBaseEntity());
5639}
5640
5641template<typename Derived>
5642QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00005643TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5644 ArrayType::ArraySizeModifier SizeMod,
5645 const llvm::APInt *Size,
5646 Expr *SizeExpr,
5647 unsigned IndexTypeQuals,
5648 SourceRange BracketsRange) {
5649 if (SizeExpr || !Size)
5650 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5651 IndexTypeQuals, BracketsRange,
5652 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00005653
5654 QualType Types[] = {
5655 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5656 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5657 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00005658 };
5659 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5660 QualType SizeType;
5661 for (unsigned I = 0; I != NumTypes; ++I)
5662 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5663 SizeType = Types[I];
5664 break;
5665 }
Mike Stump1eb44332009-09-09 15:08:12 +00005666
Douglas Gregor577f75a2009-08-04 16:50:30 +00005667 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005668 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005669 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00005670 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005671}
Mike Stump1eb44332009-09-09 15:08:12 +00005672
Douglas Gregor577f75a2009-08-04 16:50:30 +00005673template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005674QualType
5675TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005676 ArrayType::ArraySizeModifier SizeMod,
5677 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00005678 unsigned IndexTypeQuals,
5679 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005680 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00005681 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005682}
5683
5684template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005685QualType
Mike Stump1eb44332009-09-09 15:08:12 +00005686TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005687 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00005688 unsigned IndexTypeQuals,
5689 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005690 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00005691 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005692}
Mike Stump1eb44332009-09-09 15:08:12 +00005693
Douglas Gregor577f75a2009-08-04 16:50:30 +00005694template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005695QualType
5696TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005697 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005698 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005699 unsigned IndexTypeQuals,
5700 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005701 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005702 SizeExpr.takeAs<Expr>(),
5703 IndexTypeQuals, BracketsRange);
5704}
5705
5706template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005707QualType
5708TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005709 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005710 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005711 unsigned IndexTypeQuals,
5712 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005713 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005714 SizeExpr.takeAs<Expr>(),
5715 IndexTypeQuals, BracketsRange);
5716}
5717
5718template<typename Derived>
5719QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson82287d12010-02-05 00:12:22 +00005720 unsigned NumElements,
5721 bool IsAltiVec, bool IsPixel) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005722 // FIXME: semantic checking!
John Thompson82287d12010-02-05 00:12:22 +00005723 return SemaRef.Context.getVectorType(ElementType, NumElements,
5724 IsAltiVec, IsPixel);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005725}
Mike Stump1eb44332009-09-09 15:08:12 +00005726
Douglas Gregor577f75a2009-08-04 16:50:30 +00005727template<typename Derived>
5728QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5729 unsigned NumElements,
5730 SourceLocation AttributeLoc) {
5731 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5732 NumElements, true);
5733 IntegerLiteral *VectorSize
Mike Stump1eb44332009-09-09 15:08:12 +00005734 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005735 AttributeLoc);
5736 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5737 AttributeLoc);
5738}
Mike Stump1eb44332009-09-09 15:08:12 +00005739
Douglas Gregor577f75a2009-08-04 16:50:30 +00005740template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005741QualType
5742TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005743 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005744 SourceLocation AttributeLoc) {
5745 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5746}
Mike Stump1eb44332009-09-09 15:08:12 +00005747
Douglas Gregor577f75a2009-08-04 16:50:30 +00005748template<typename Derived>
5749QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00005750 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005751 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00005752 bool Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005753 unsigned Quals) {
Mike Stump1eb44332009-09-09 15:08:12 +00005754 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005755 Quals,
5756 getDerived().getBaseLocation(),
5757 getDerived().getBaseEntity());
5758}
Mike Stump1eb44332009-09-09 15:08:12 +00005759
Douglas Gregor577f75a2009-08-04 16:50:30 +00005760template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005761QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5762 return SemaRef.Context.getFunctionNoProtoType(T);
5763}
5764
5765template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00005766QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5767 assert(D && "no decl found");
5768 if (D->isInvalidDecl()) return QualType();
5769
5770 TypeDecl *Ty;
5771 if (isa<UsingDecl>(D)) {
5772 UsingDecl *Using = cast<UsingDecl>(D);
5773 assert(Using->isTypeName() &&
5774 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5775
5776 // A valid resolved using typename decl points to exactly one type decl.
5777 assert(++Using->shadow_begin() == Using->shadow_end());
5778 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5779
5780 } else {
5781 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5782 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5783 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5784 }
5785
5786 return SemaRef.Context.getTypeDeclType(Ty);
5787}
5788
5789template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00005790QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005791 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5792}
5793
5794template<typename Derived>
5795QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5796 return SemaRef.Context.getTypeOfType(Underlying);
5797}
5798
5799template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00005800QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005801 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5802}
5803
5804template<typename Derived>
5805QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00005806 TemplateName Template,
5807 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00005808 const TemplateArgumentListInfo &TemplateArgs) {
5809 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005810}
Mike Stump1eb44332009-09-09 15:08:12 +00005811
Douglas Gregordcee1a12009-08-06 05:28:30 +00005812template<typename Derived>
5813NestedNameSpecifier *
5814TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5815 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00005816 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00005817 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00005818 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00005819 CXXScopeSpec SS;
5820 // FIXME: The source location information is all wrong.
5821 SS.setRange(Range);
5822 SS.setScopeRep(Prefix);
5823 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00005824 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00005825 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00005826 ObjectType,
5827 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00005828 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00005829}
5830
5831template<typename Derived>
5832NestedNameSpecifier *
5833TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5834 SourceRange Range,
5835 NamespaceDecl *NS) {
5836 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5837}
5838
5839template<typename Derived>
5840NestedNameSpecifier *
5841TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5842 SourceRange Range,
5843 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00005844 QualType T) {
5845 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00005846 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00005847 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00005848 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5849 T.getTypePtr());
5850 }
Mike Stump1eb44332009-09-09 15:08:12 +00005851
Douglas Gregordcee1a12009-08-06 05:28:30 +00005852 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5853 return 0;
5854}
Mike Stump1eb44332009-09-09 15:08:12 +00005855
Douglas Gregord1067e52009-08-06 06:41:21 +00005856template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005857TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00005858TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5859 bool TemplateKW,
5860 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00005861 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00005862 Template);
5863}
5864
5865template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005866TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00005867TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005868 const IdentifierInfo &II,
5869 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00005870 CXXScopeSpec SS;
5871 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump1eb44332009-09-09 15:08:12 +00005872 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00005873 UnqualifiedId Name;
5874 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005875 return getSema().ActOnDependentTemplateName(
5876 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005877 SS,
Douglas Gregor014e88d2009-11-03 23:16:33 +00005878 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00005879 ObjectType.getAsOpaquePtr(),
5880 /*EnteringContext=*/false)
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005881 .template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00005882}
Mike Stump1eb44332009-09-09 15:08:12 +00005883
Douglas Gregorb98b1992009-08-11 05:31:07 +00005884template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00005885TemplateName
5886TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5887 OverloadedOperatorKind Operator,
5888 QualType ObjectType) {
5889 CXXScopeSpec SS;
5890 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5891 SS.setScopeRep(Qualifier);
5892 UnqualifiedId Name;
5893 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5894 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5895 Operator, SymbolLocations);
5896 return getSema().ActOnDependentTemplateName(
5897 /*FIXME:*/getDerived().getBaseLocation(),
5898 SS,
5899 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00005900 ObjectType.getAsOpaquePtr(),
5901 /*EnteringContext=*/false)
Douglas Gregorca1bdd72009-11-04 00:56:37 +00005902 .template getAsVal<TemplateName>();
5903}
5904
5905template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005906Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005907TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5908 SourceLocation OpLoc,
5909 ExprArg Callee,
5910 ExprArg First,
5911 ExprArg Second) {
5912 Expr *FirstExpr = (Expr *)First.get();
5913 Expr *SecondExpr = (Expr *)Second.get();
John McCallba135432009-11-21 08:51:07 +00005914 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005915 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00005916
Douglas Gregorb98b1992009-08-11 05:31:07 +00005917 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00005918 if (Op == OO_Subscript) {
5919 if (!FirstExpr->getType()->isOverloadableType() &&
5920 !SecondExpr->getType()->isOverloadableType())
5921 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCallba135432009-11-21 08:51:07 +00005922 CalleeExpr->getLocStart(),
Sebastian Redlf322ed62009-10-29 20:17:01 +00005923 move(Second), OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00005924 } else if (Op == OO_Arrow) {
5925 // -> is never a builtin operation.
5926 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redlf322ed62009-10-29 20:17:01 +00005927 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005928 if (!FirstExpr->getType()->isOverloadableType()) {
5929 // The argument is not of overloadable type, so try to create a
5930 // built-in unary operation.
Mike Stump1eb44332009-09-09 15:08:12 +00005931 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005932 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00005933
Douglas Gregorb98b1992009-08-11 05:31:07 +00005934 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5935 }
5936 } else {
Mike Stump1eb44332009-09-09 15:08:12 +00005937 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005938 !SecondExpr->getType()->isOverloadableType()) {
5939 // Neither of the arguments is an overloadable type, so try to
5940 // create a built-in binary operation.
5941 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00005942 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00005943 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5944 if (Result.isInvalid())
5945 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005946
Douglas Gregorb98b1992009-08-11 05:31:07 +00005947 First.release();
5948 Second.release();
5949 return move(Result);
5950 }
5951 }
Mike Stump1eb44332009-09-09 15:08:12 +00005952
5953 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00005954 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00005955 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00005956
John McCallba135432009-11-21 08:51:07 +00005957 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5958 assert(ULE->requiresADL());
5959
5960 // FIXME: Do we have to check
5961 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00005962 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00005963 } else {
John McCall6e266892010-01-26 03:27:55 +00005964 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCallba135432009-11-21 08:51:07 +00005965 }
Mike Stump1eb44332009-09-09 15:08:12 +00005966
Douglas Gregorb98b1992009-08-11 05:31:07 +00005967 // Add any functions found via argument-dependent lookup.
5968 Expr *Args[2] = { FirstExpr, SecondExpr };
5969 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00005970
Douglas Gregorb98b1992009-08-11 05:31:07 +00005971 // Create the overloaded operator invocation for unary operators.
5972 if (NumArgs == 1 || isPostIncDec) {
Mike Stump1eb44332009-09-09 15:08:12 +00005973 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005974 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5975 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5976 }
Mike Stump1eb44332009-09-09 15:08:12 +00005977
Sebastian Redlf322ed62009-10-29 20:17:01 +00005978 if (Op == OO_Subscript)
John McCallba135432009-11-21 08:51:07 +00005979 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5980 OpLoc,
5981 move(First),
5982 move(Second));
Sebastian Redlf322ed62009-10-29 20:17:01 +00005983
Douglas Gregorb98b1992009-08-11 05:31:07 +00005984 // Create the overloaded operator invocation for binary operators.
Mike Stump1eb44332009-09-09 15:08:12 +00005985 BinaryOperator::Opcode Opc =
Douglas Gregorb98b1992009-08-11 05:31:07 +00005986 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00005987 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00005988 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5989 if (Result.isInvalid())
5990 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005991
Douglas Gregorb98b1992009-08-11 05:31:07 +00005992 First.release();
5993 Second.release();
Mike Stump1eb44332009-09-09 15:08:12 +00005994 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005995}
Mike Stump1eb44332009-09-09 15:08:12 +00005996
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005997template<typename Derived>
5998Sema::OwningExprResult
5999TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6000 SourceLocation OperatorLoc,
6001 bool isArrow,
6002 NestedNameSpecifier *Qualifier,
6003 SourceRange QualifierRange,
6004 TypeSourceInfo *ScopeType,
6005 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006006 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006007 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006008 CXXScopeSpec SS;
6009 if (Qualifier) {
6010 SS.setRange(QualifierRange);
6011 SS.setScopeRep(Qualifier);
6012 }
6013
6014 Expr *BaseE = (Expr *)Base.get();
6015 QualType BaseType = BaseE->getType();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006016 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006017 (!isArrow && !BaseType->getAs<RecordType>()) ||
6018 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00006019 !BaseType->getAs<PointerType>()->getPointeeType()
6020 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006021 // This pseudo-destructor expression is still a pseudo-destructor.
6022 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6023 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006024 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006025 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006026 /*FIXME?*/true);
6027 }
6028
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006029 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006030 DeclarationName Name
6031 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6032 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
6033
6034 // FIXME: the ScopeType should be tacked onto SS.
6035
6036 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6037 OperatorLoc, isArrow,
6038 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006039 Name, Destroyed.getLocation(),
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006040 /*TemplateArgs*/ 0);
6041}
6042
Douglas Gregor577f75a2009-08-04 16:50:30 +00006043} // end namespace clang
6044
6045#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H