blob: a41cbc38a292005eb0954b30aadfca3bd0acaaf6 [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);
Zhongxing Xud8383d42010-04-21 06:32:25 +0000341 OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000342
Douglas Gregor43959a92009-08-20 07:17:43 +0000343#define STMT(Node, Parent) \
344 OwningStmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000345#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +0000346 OwningExprResult Transform##Node(Node *E);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000347#define ABSTRACT_EXPR(Node, Parent)
348#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +0000349
Douglas Gregor577f75a2009-08-04 16:50:30 +0000350 /// \brief Build a new pointer type given its pointee type.
351 ///
352 /// By default, performs semantic analysis when building the pointer type.
353 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000354 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000355
356 /// \brief Build a new block pointer type given its pointee type.
357 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000358 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000359 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000360 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000361
John McCall85737a72009-10-30 00:06:24 +0000362 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000363 ///
John McCall85737a72009-10-30 00:06:24 +0000364 /// By default, performs semantic analysis when building the
365 /// reference type. Subclasses may override this routine to provide
366 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000367 ///
John McCall85737a72009-10-30 00:06:24 +0000368 /// \param LValue whether the type was written with an lvalue sigil
369 /// or an rvalue sigil.
370 QualType RebuildReferenceType(QualType ReferentType,
371 bool LValue,
372 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000373
Douglas Gregor577f75a2009-08-04 16:50:30 +0000374 /// \brief Build a new member pointer type given the pointee type and the
375 /// class type it refers into.
376 ///
377 /// By default, performs semantic analysis when building the member pointer
378 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000379 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
380 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000381
Douglas Gregor577f75a2009-08-04 16:50:30 +0000382 /// \brief Build a new array type given the element type, size
383 /// modifier, size of the array (if known), size expression, and index type
384 /// qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000388 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000389 QualType RebuildArrayType(QualType ElementType,
390 ArrayType::ArraySizeModifier SizeMod,
391 const llvm::APInt *Size,
392 Expr *SizeExpr,
393 unsigned IndexTypeQuals,
394 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000395
Douglas Gregor577f75a2009-08-04 16:50:30 +0000396 /// \brief Build a new constant array type given the element type, size
397 /// modifier, (known) size of the array, and index type qualifiers.
398 ///
399 /// By default, performs semantic analysis when building the array type.
400 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000401 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000402 ArrayType::ArraySizeModifier SizeMod,
403 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000404 unsigned IndexTypeQuals,
405 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000406
Douglas Gregor577f75a2009-08-04 16:50:30 +0000407 /// \brief Build a new incomplete array type given the element type, size
408 /// modifier, and index type qualifiers.
409 ///
410 /// By default, performs semantic analysis when building the array type.
411 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000412 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000413 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000414 unsigned IndexTypeQuals,
415 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000416
Mike Stump1eb44332009-09-09 15:08:12 +0000417 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000418 /// size modifier, size expression, and index type qualifiers.
419 ///
420 /// By default, performs semantic analysis when building the array type.
421 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000422 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000423 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000424 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000425 unsigned IndexTypeQuals,
426 SourceRange BracketsRange);
427
Mike Stump1eb44332009-09-09 15:08:12 +0000428 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000429 /// size modifier, size expression, and index type qualifiers.
430 ///
431 /// By default, performs semantic analysis when building the array type.
432 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000433 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000434 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000435 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000436 unsigned IndexTypeQuals,
437 SourceRange BracketsRange);
438
439 /// \brief Build a new vector type given the element type and
440 /// number of elements.
441 ///
442 /// By default, performs semantic analysis when building the vector type.
443 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000444 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
445 bool IsAltiVec, bool IsPixel);
Mike Stump1eb44332009-09-09 15:08:12 +0000446
Douglas Gregor577f75a2009-08-04 16:50:30 +0000447 /// \brief Build a new extended vector type given the element type and
448 /// number of elements.
449 ///
450 /// By default, performs semantic analysis when building the vector type.
451 /// Subclasses may override this routine to provide different behavior.
452 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
453 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000454
455 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000456 /// given the element type and number of elements.
457 ///
458 /// By default, performs semantic analysis when building the vector type.
459 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000460 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000461 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000462 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000463
Douglas Gregor577f75a2009-08-04 16:50:30 +0000464 /// \brief Build a new function type.
465 ///
466 /// By default, performs semantic analysis when building the function type.
467 /// Subclasses may override this routine to provide different behavior.
468 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000469 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000470 unsigned NumParamTypes,
471 bool Variadic, unsigned Quals);
Mike Stump1eb44332009-09-09 15:08:12 +0000472
John McCalla2becad2009-10-21 00:40:46 +0000473 /// \brief Build a new unprototyped function type.
474 QualType RebuildFunctionNoProtoType(QualType ResultType);
475
John McCalled976492009-12-04 22:46:56 +0000476 /// \brief Rebuild an unresolved typename type, given the decl that
477 /// the UnresolvedUsingTypenameDecl was transformed to.
478 QualType RebuildUnresolvedUsingType(Decl *D);
479
Douglas Gregor577f75a2009-08-04 16:50:30 +0000480 /// \brief Build a new typedef type.
481 QualType RebuildTypedefType(TypedefDecl *Typedef) {
482 return SemaRef.Context.getTypeDeclType(Typedef);
483 }
484
485 /// \brief Build a new class/struct/union type.
486 QualType RebuildRecordType(RecordDecl *Record) {
487 return SemaRef.Context.getTypeDeclType(Record);
488 }
489
490 /// \brief Build a new Enum type.
491 QualType RebuildEnumType(EnumDecl *Enum) {
492 return SemaRef.Context.getTypeDeclType(Enum);
493 }
John McCall7da24312009-09-05 00:15:47 +0000494
495 /// \brief Build a new elaborated type.
496 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
497 return SemaRef.Context.getElaboratedType(T, Tag);
498 }
Mike Stump1eb44332009-09-09 15:08:12 +0000499
500 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000501 ///
502 /// By default, performs semantic analysis when building the typeof type.
503 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000504 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000505
Mike Stump1eb44332009-09-09 15:08:12 +0000506 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000507 ///
508 /// By default, builds a new TypeOfType with the given underlying type.
509 QualType RebuildTypeOfType(QualType Underlying);
510
Mike Stump1eb44332009-09-09 15:08:12 +0000511 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000512 ///
513 /// By default, performs semantic analysis when building the decltype type.
514 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000515 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump1eb44332009-09-09 15:08:12 +0000516
Douglas Gregor577f75a2009-08-04 16:50:30 +0000517 /// \brief Build a new template specialization type.
518 ///
519 /// By default, performs semantic analysis when building the template
520 /// specialization type. Subclasses may override this routine to provide
521 /// different behavior.
522 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000523 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000524 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000525
Douglas Gregor577f75a2009-08-04 16:50:30 +0000526 /// \brief Build a new qualified name type.
527 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000528 /// By default, builds a new QualifiedNameType type from the
529 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregor577f75a2009-08-04 16:50:30 +0000530 /// this routine to provide different behavior.
531 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
532 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000533 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000534
535 /// \brief Build a new typename type that refers to a template-id.
536 ///
Douglas Gregor40336422010-03-31 22:19:08 +0000537 /// By default, builds a new DependentNameType type from the
538 /// nested-name-specifier
Mike Stump1eb44332009-09-09 15:08:12 +0000539 /// and the given type. Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000540 /// different behavior.
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000541 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
542 NestedNameSpecifier *NNS, QualType T) {
Douglas Gregorae628892010-02-13 06:05:33 +0000543 if (NNS->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000544 // If the name is still dependent, just build a new dependent name type.
Douglas Gregorae628892010-02-13 06:05:33 +0000545 CXXScopeSpec SS;
546 SS.setScopeRep(NNS);
547 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000548 return SemaRef.Context.getDependentNameType(Keyword, NNS,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000549 cast<TemplateSpecializationType>(T));
Douglas Gregorae628892010-02-13 06:05:33 +0000550 }
Douglas Gregor40336422010-03-31 22:19:08 +0000551
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000552 // FIXME: Handle elaborated-type-specifiers separately.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000553 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000554 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000555
556 /// \brief Build a new typename type that refers to an identifier.
557 ///
558 /// By default, performs semantic analysis when building the typename type
Mike Stump1eb44332009-09-09 15:08:12 +0000559 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000560 /// different behavior.
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000561 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
562 NestedNameSpecifier *NNS,
563 const IdentifierInfo *Id,
564 SourceRange SR) {
Douglas Gregor40336422010-03-31 22:19:08 +0000565 CXXScopeSpec SS;
566 SS.setScopeRep(NNS);
567
568 if (NNS->isDependent()) {
569 // If the name is still dependent, just build a new dependent name type.
570 if (!SemaRef.computeDeclContext(SS))
571 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
572 }
573
574 TagDecl::TagKind Kind = TagDecl::TK_enum;
575 switch (Keyword) {
576 case ETK_None:
577 // FIXME: Note the lack of the "typename" specifier!
578 // Fall through
579 case ETK_Typename:
580 return SemaRef.CheckTypenameType(NNS, *Id, SR);
581
582 case ETK_Class: Kind = TagDecl::TK_class; break;
583 case ETK_Struct: Kind = TagDecl::TK_struct; break;
584 case ETK_Union: Kind = TagDecl::TK_union; break;
585 case ETK_Enum: Kind = TagDecl::TK_enum; break;
586 }
587
588 // We had a dependent elaborated-type-specifier that as been transformed
589 // into a non-dependent elaborated-type-specifier. Find the tag we're
590 // referring to.
591 LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName);
592 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
593 if (!DC)
594 return QualType();
595
596 TagDecl *Tag = 0;
597 SemaRef.LookupQualifiedName(Result, DC);
598 switch (Result.getResultKind()) {
599 case LookupResult::NotFound:
600 case LookupResult::NotFoundInCurrentInstantiation:
601 break;
602
603 case LookupResult::Found:
604 Tag = Result.getAsSingle<TagDecl>();
605 break;
606
607 case LookupResult::FoundOverloaded:
608 case LookupResult::FoundUnresolvedValue:
609 llvm_unreachable("Tag lookup cannot find non-tags");
610 return QualType();
611
612 case LookupResult::Ambiguous:
613 // Let the LookupResult structure handle ambiguities.
614 return QualType();
615 }
616
617 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000618 // FIXME: Would be nice to highlight just the source range.
Douglas Gregor40336422010-03-31 22:19:08 +0000619 SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000620 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000621 return QualType();
622 }
623
624 // FIXME: Terrible location information
625 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) {
626 SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id;
627 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
628 return QualType();
629 }
630
631 // Build the elaborated-type-specifier type.
632 QualType T = SemaRef.Context.getTypeDeclType(Tag);
633 T = SemaRef.Context.getQualifiedNameType(NNS, T);
634 return SemaRef.Context.getElaboratedType(T, Kind);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000635 }
Mike Stump1eb44332009-09-09 15:08:12 +0000636
Douglas Gregordcee1a12009-08-06 05:28:30 +0000637 /// \brief Build a new nested-name-specifier given the prefix and an
638 /// identifier that names the next step in the nested-name-specifier.
639 ///
640 /// By default, performs semantic analysis when building the new
641 /// nested-name-specifier. Subclasses may override this routine to provide
642 /// different behavior.
643 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
644 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000645 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000646 QualType ObjectType,
647 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000648
649 /// \brief Build a new nested-name-specifier given the prefix and the
650 /// namespace named in the next step in the nested-name-specifier.
651 ///
652 /// By default, performs semantic analysis when building the new
653 /// nested-name-specifier. Subclasses may override this routine to provide
654 /// different behavior.
655 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
656 SourceRange Range,
657 NamespaceDecl *NS);
658
659 /// \brief Build a new nested-name-specifier given the prefix and the
660 /// type named in the next step in the nested-name-specifier.
661 ///
662 /// By default, performs semantic analysis when building the new
663 /// nested-name-specifier. Subclasses may override this routine to provide
664 /// different behavior.
665 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
666 SourceRange Range,
667 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000668 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000669
670 /// \brief Build a new template name given a nested name specifier, a flag
671 /// indicating whether the "template" keyword was provided, and the template
672 /// that the template name refers to.
673 ///
674 /// By default, builds the new template name directly. Subclasses may override
675 /// this routine to provide different behavior.
676 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
677 bool TemplateKW,
678 TemplateDecl *Template);
679
Douglas Gregord1067e52009-08-06 06:41:21 +0000680 /// \brief Build a new template name given a nested name specifier and the
681 /// name that is referred to as a template.
682 ///
683 /// By default, performs semantic analysis to determine whether the name can
684 /// be resolved to a specific template, then builds the appropriate kind of
685 /// template name. Subclasses may override this routine to provide different
686 /// behavior.
687 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000688 const IdentifierInfo &II,
689 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000690
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000691 /// \brief Build a new template name given a nested name specifier and the
692 /// overloaded operator name that is referred to as a template.
693 ///
694 /// By default, performs semantic analysis to determine whether the name can
695 /// be resolved to a specific template, then builds the appropriate kind of
696 /// template name. Subclasses may override this routine to provide different
697 /// behavior.
698 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
699 OverloadedOperatorKind Operator,
700 QualType ObjectType);
701
Douglas Gregor43959a92009-08-20 07:17:43 +0000702 /// \brief Build a new compound statement.
703 ///
704 /// By default, performs semantic analysis to build the new statement.
705 /// Subclasses may override this routine to provide different behavior.
706 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
707 MultiStmtArg Statements,
708 SourceLocation RBraceLoc,
709 bool IsStmtExpr) {
710 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
711 IsStmtExpr);
712 }
713
714 /// \brief Build a new case statement.
715 ///
716 /// By default, performs semantic analysis to build the new statement.
717 /// Subclasses may override this routine to provide different behavior.
718 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
719 ExprArg LHS,
720 SourceLocation EllipsisLoc,
721 ExprArg RHS,
722 SourceLocation ColonLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000723 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregor43959a92009-08-20 07:17:43 +0000724 ColonLoc);
725 }
Mike Stump1eb44332009-09-09 15:08:12 +0000726
Douglas Gregor43959a92009-08-20 07:17:43 +0000727 /// \brief Attach the body to a new case statement.
728 ///
729 /// By default, performs semantic analysis to build the new statement.
730 /// Subclasses may override this routine to provide different behavior.
731 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
732 getSema().ActOnCaseStmtBody(S.get(), move(Body));
733 return move(S);
734 }
Mike Stump1eb44332009-09-09 15:08:12 +0000735
Douglas Gregor43959a92009-08-20 07:17:43 +0000736 /// \brief Build a new default statement.
737 ///
738 /// By default, performs semantic analysis to build the new statement.
739 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000740 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000741 SourceLocation ColonLoc,
742 StmtArg SubStmt) {
Mike Stump1eb44332009-09-09 15:08:12 +0000743 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregor43959a92009-08-20 07:17:43 +0000744 /*CurScope=*/0);
745 }
Mike Stump1eb44332009-09-09 15:08:12 +0000746
Douglas Gregor43959a92009-08-20 07:17:43 +0000747 /// \brief Build a new label statement.
748 ///
749 /// By default, performs semantic analysis to build the new statement.
750 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000751 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000752 IdentifierInfo *Id,
753 SourceLocation ColonLoc,
754 StmtArg SubStmt) {
755 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
756 }
Mike Stump1eb44332009-09-09 15:08:12 +0000757
Douglas Gregor43959a92009-08-20 07:17:43 +0000758 /// \brief Build a new "if" statement.
759 ///
760 /// By default, performs semantic analysis to build the new statement.
761 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000762 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000763 VarDecl *CondVar, StmtArg Then,
764 SourceLocation ElseLoc, StmtArg Else) {
765 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
766 move(Then), ElseLoc, move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +0000767 }
Mike Stump1eb44332009-09-09 15:08:12 +0000768
Douglas Gregor43959a92009-08-20 07:17:43 +0000769 /// \brief Start building a new switch statement.
770 ///
771 /// By default, performs semantic analysis to build the new statement.
772 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000773 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
774 VarDecl *CondVar) {
775 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregor43959a92009-08-20 07:17:43 +0000776 }
Mike Stump1eb44332009-09-09 15:08:12 +0000777
Douglas Gregor43959a92009-08-20 07:17:43 +0000778 /// \brief Attach the body to the switch statement.
779 ///
780 /// By default, performs semantic analysis to build the new statement.
781 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000782 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000783 StmtArg Switch, StmtArg Body) {
784 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
785 move(Body));
786 }
787
788 /// \brief Build a new while statement.
789 ///
790 /// By default, performs semantic analysis to build the new statement.
791 /// Subclasses may override this routine to provide different behavior.
792 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
793 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000794 VarDecl *CondVar,
Douglas Gregor43959a92009-08-20 07:17:43 +0000795 StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000796 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
797 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000798 }
Mike Stump1eb44332009-09-09 15:08:12 +0000799
Douglas Gregor43959a92009-08-20 07:17:43 +0000800 /// \brief Build a new do-while statement.
801 ///
802 /// By default, performs semantic analysis to build the new statement.
803 /// Subclasses may override this routine to provide different behavior.
804 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
805 SourceLocation WhileLoc,
806 SourceLocation LParenLoc,
807 ExprArg Cond,
808 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000809 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000810 move(Cond), RParenLoc);
811 }
812
813 /// \brief Build a new for statement.
814 ///
815 /// By default, performs semantic analysis to build the new statement.
816 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000817 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000818 SourceLocation LParenLoc,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000819 StmtArg Init, Sema::FullExprArg Cond,
820 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000821 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000822 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
823 DeclPtrTy::make(CondVar),
824 Inc, RParenLoc, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000825 }
Mike Stump1eb44332009-09-09 15:08:12 +0000826
Douglas Gregor43959a92009-08-20 07:17:43 +0000827 /// \brief Build a new goto statement.
828 ///
829 /// By default, performs semantic analysis to build the new statement.
830 /// Subclasses may override this routine to provide different behavior.
831 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
832 SourceLocation LabelLoc,
833 LabelStmt *Label) {
834 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
835 }
836
837 /// \brief Build a new indirect goto statement.
838 ///
839 /// By default, performs semantic analysis to build the new statement.
840 /// Subclasses may override this routine to provide different behavior.
841 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
842 SourceLocation StarLoc,
843 ExprArg Target) {
844 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
845 }
Mike Stump1eb44332009-09-09 15:08:12 +0000846
Douglas Gregor43959a92009-08-20 07:17:43 +0000847 /// \brief Build a new return statement.
848 ///
849 /// By default, performs semantic analysis to build the new statement.
850 /// Subclasses may override this routine to provide different behavior.
851 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
852 ExprArg Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000853
Douglas Gregor43959a92009-08-20 07:17:43 +0000854 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
855 }
Mike Stump1eb44332009-09-09 15:08:12 +0000856
Douglas Gregor43959a92009-08-20 07:17:43 +0000857 /// \brief Build a new declaration statement.
858 ///
859 /// By default, performs semantic analysis to build the new statement.
860 /// Subclasses may override this routine to provide different behavior.
861 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000862 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000863 SourceLocation EndLoc) {
864 return getSema().Owned(
865 new (getSema().Context) DeclStmt(
866 DeclGroupRef::Create(getSema().Context,
867 Decls, NumDecls),
868 StartLoc, EndLoc));
869 }
Mike Stump1eb44332009-09-09 15:08:12 +0000870
Anders Carlsson703e3942010-01-24 05:50:09 +0000871 /// \brief Build a new inline asm statement.
872 ///
873 /// By default, performs semantic analysis to build the new statement.
874 /// Subclasses may override this routine to provide different behavior.
875 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
876 bool IsSimple,
877 bool IsVolatile,
878 unsigned NumOutputs,
879 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000880 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000881 MultiExprArg Constraints,
882 MultiExprArg Exprs,
883 ExprArg AsmString,
884 MultiExprArg Clobbers,
885 SourceLocation RParenLoc,
886 bool MSAsm) {
887 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
888 NumInputs, Names, move(Constraints),
889 move(Exprs), move(AsmString), move(Clobbers),
890 RParenLoc, MSAsm);
891 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000892
893 /// \brief Build a new Objective-C @try statement.
894 ///
895 /// By default, performs semantic analysis to build the new statement.
896 /// Subclasses may override this routine to provide different behavior.
897 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
898 StmtArg TryBody,
899 StmtArg Catch,
900 StmtArg Finally) {
901 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(Catch),
902 move(Finally));
903 }
904
905 /// \brief Build a new Objective-C @finally statement.
906 ///
907 /// By default, performs semantic analysis to build the new statement.
908 /// Subclasses may override this routine to provide different behavior.
909 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
910 StmtArg Body) {
911 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
912 }
Anders Carlsson703e3942010-01-24 05:50:09 +0000913
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000914 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +0000915 ///
916 /// By default, performs semantic analysis to build the new statement.
917 /// Subclasses may override this routine to provide different behavior.
918 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
919 ExprArg Operand) {
920 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
921 }
922
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000923 /// \brief Build a new Objective-C @synchronized statement.
924 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000925 /// By default, performs semantic analysis to build the new statement.
926 /// Subclasses may override this routine to provide different behavior.
927 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
928 ExprArg Object,
929 StmtArg Body) {
930 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
931 move(Body));
932 }
Douglas Gregorc3203e72010-04-22 23:10:45 +0000933
934 /// \brief Build a new Objective-C fast enumeration statement.
935 ///
936 /// By default, performs semantic analysis to build the new statement.
937 /// Subclasses may override this routine to provide different behavior.
938 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
939 SourceLocation LParenLoc,
940 StmtArg Element,
941 ExprArg Collection,
942 SourceLocation RParenLoc,
943 StmtArg Body) {
944 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
945 move(Element),
946 move(Collection),
947 RParenLoc,
948 move(Body));
949 }
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000950
Douglas Gregor43959a92009-08-20 07:17:43 +0000951 /// \brief Build a new C++ exception declaration.
952 ///
953 /// By default, performs semantic analysis to build the new decaration.
954 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000955 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000956 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000957 IdentifierInfo *Name,
958 SourceLocation Loc,
959 SourceRange TypeRange) {
Mike Stump1eb44332009-09-09 15:08:12 +0000960 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000961 TypeRange);
962 }
963
964 /// \brief Build a new C++ catch statement.
965 ///
966 /// By default, performs semantic analysis to build the new statement.
967 /// Subclasses may override this routine to provide different behavior.
968 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
969 VarDecl *ExceptionDecl,
970 StmtArg Handler) {
971 return getSema().Owned(
Mike Stump1eb44332009-09-09 15:08:12 +0000972 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregor43959a92009-08-20 07:17:43 +0000973 Handler.takeAs<Stmt>()));
974 }
Mike Stump1eb44332009-09-09 15:08:12 +0000975
Douglas Gregor43959a92009-08-20 07:17:43 +0000976 /// \brief Build a new C++ try statement.
977 ///
978 /// By default, performs semantic analysis to build the new statement.
979 /// Subclasses may override this routine to provide different behavior.
980 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
981 StmtArg TryBlock,
982 MultiStmtArg Handlers) {
983 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
984 }
Mike Stump1eb44332009-09-09 15:08:12 +0000985
Douglas Gregorb98b1992009-08-11 05:31:07 +0000986 /// \brief Build a new expression that references a declaration.
987 ///
988 /// By default, performs semantic analysis to build the new expression.
989 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +0000990 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
991 LookupResult &R,
992 bool RequiresADL) {
993 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
994 }
995
996
997 /// \brief Build a new expression that references a declaration.
998 ///
999 /// By default, performs semantic analysis to build the new expression.
1000 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora2813ce2009-10-23 18:54:35 +00001001 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1002 SourceRange QualifierRange,
John McCalldbd872f2009-12-08 09:08:17 +00001003 ValueDecl *VD, SourceLocation Loc,
1004 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001005 CXXScopeSpec SS;
1006 SS.setScopeRep(Qualifier);
1007 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001008
1009 // FIXME: loses template args.
1010
1011 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001012 }
Mike Stump1eb44332009-09-09 15:08:12 +00001013
Douglas Gregorb98b1992009-08-11 05:31:07 +00001014 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001015 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001016 /// By default, performs semantic analysis to build the new expression.
1017 /// Subclasses may override this routine to provide different behavior.
1018 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1019 SourceLocation RParen) {
1020 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1021 }
1022
Douglas Gregora71d8192009-09-04 17:36:40 +00001023 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001024 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001025 /// By default, performs semantic analysis to build the new expression.
1026 /// Subclasses may override this routine to provide different behavior.
1027 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1028 SourceLocation OperatorLoc,
1029 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001030 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001031 SourceRange QualifierRange,
1032 TypeSourceInfo *ScopeType,
1033 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001034 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001035 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001036
Douglas Gregorb98b1992009-08-11 05:31:07 +00001037 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001038 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001039 /// By default, performs semantic analysis to build the new expression.
1040 /// Subclasses may override this routine to provide different behavior.
1041 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1042 UnaryOperator::Opcode Opc,
1043 ExprArg SubExpr) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001044 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001045 }
Mike Stump1eb44332009-09-09 15:08:12 +00001046
Douglas Gregorb98b1992009-08-11 05:31:07 +00001047 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001048 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001049 /// By default, performs semantic analysis to build the new expression.
1050 /// Subclasses may override this routine to provide different behavior.
John McCalla93c9342009-12-07 02:54:59 +00001051 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001052 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001053 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001054 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001055 }
1056
Mike Stump1eb44332009-09-09 15:08:12 +00001057 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001058 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001059 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001060 /// By default, performs semantic analysis to build the new expression.
1061 /// Subclasses may override this routine to provide different behavior.
1062 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1063 bool isSizeOf, SourceRange R) {
Mike Stump1eb44332009-09-09 15:08:12 +00001064 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001065 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1066 OpLoc, isSizeOf, R);
1067 if (Result.isInvalid())
1068 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001069
Douglas Gregorb98b1992009-08-11 05:31:07 +00001070 SubExpr.release();
1071 return move(Result);
1072 }
Mike Stump1eb44332009-09-09 15:08:12 +00001073
Douglas Gregorb98b1992009-08-11 05:31:07 +00001074 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001075 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001076 /// By default, performs semantic analysis to build the new expression.
1077 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001078 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001079 SourceLocation LBracketLoc,
1080 ExprArg RHS,
1081 SourceLocation RBracketLoc) {
1082 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump1eb44332009-09-09 15:08:12 +00001083 LBracketLoc, move(RHS),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001084 RBracketLoc);
1085 }
1086
1087 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001088 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001089 /// By default, performs semantic analysis to build the new expression.
1090 /// Subclasses may override this routine to provide different behavior.
1091 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1092 MultiExprArg Args,
1093 SourceLocation *CommaLocs,
1094 SourceLocation RParenLoc) {
1095 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1096 move(Args), CommaLocs, RParenLoc);
1097 }
1098
1099 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001100 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001101 /// By default, performs semantic analysis to build the new expression.
1102 /// Subclasses may override this routine to provide different behavior.
1103 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001104 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001105 NestedNameSpecifier *Qualifier,
1106 SourceRange QualifierRange,
1107 SourceLocation MemberLoc,
Eli Friedmanf595cc42009-12-04 06:40:45 +00001108 ValueDecl *Member,
John McCall6bb80172010-03-30 21:47:33 +00001109 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001110 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +00001111 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001112 if (!Member->getDeclName()) {
1113 // We have a reference to an unnamed field.
1114 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +00001115
Douglas Gregor83a56c42009-12-24 20:02:50 +00001116 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall6bb80172010-03-30 21:47:33 +00001117 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1118 FoundDecl, Member))
Douglas Gregor83a56c42009-12-24 20:02:50 +00001119 return getSema().ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001120
Mike Stump1eb44332009-09-09 15:08:12 +00001121 MemberExpr *ME =
Douglas Gregor83a56c42009-12-24 20:02:50 +00001122 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlssond8b285f2009-09-01 04:26:58 +00001123 Member, MemberLoc,
1124 cast<FieldDecl>(Member)->getType());
1125 return getSema().Owned(ME);
1126 }
Mike Stump1eb44332009-09-09 15:08:12 +00001127
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001128 CXXScopeSpec SS;
1129 if (Qualifier) {
1130 SS.setRange(QualifierRange);
1131 SS.setScopeRep(Qualifier);
1132 }
1133
John McCallaa81e162009-12-01 22:10:20 +00001134 QualType BaseType = ((Expr*) Base.get())->getType();
1135
John McCall6bb80172010-03-30 21:47:33 +00001136 // FIXME: this involves duplicating earlier analysis in a lot of
1137 // cases; we should avoid this when possible.
John McCallc2233c52010-01-15 08:34:02 +00001138 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1139 Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001140 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001141 R.resolveKind();
1142
John McCallaa81e162009-12-01 22:10:20 +00001143 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1144 OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001145 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001146 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001147 }
Mike Stump1eb44332009-09-09 15:08:12 +00001148
Douglas Gregorb98b1992009-08-11 05:31:07 +00001149 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001150 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001151 /// By default, performs semantic analysis to build the new expression.
1152 /// Subclasses may override this routine to provide different behavior.
1153 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1154 BinaryOperator::Opcode Opc,
1155 ExprArg LHS, ExprArg RHS) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001156 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1157 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregorb98b1992009-08-11 05:31:07 +00001158 }
1159
1160 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001161 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001162 /// By default, performs semantic analysis to build the new expression.
1163 /// Subclasses may override this routine to provide different behavior.
1164 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1165 SourceLocation QuestionLoc,
1166 ExprArg LHS,
1167 SourceLocation ColonLoc,
1168 ExprArg RHS) {
Mike Stump1eb44332009-09-09 15:08:12 +00001169 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001170 move(LHS), move(RHS));
1171 }
1172
Douglas Gregorb98b1992009-08-11 05:31:07 +00001173 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001174 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001175 /// By default, performs semantic analysis to build the new expression.
1176 /// Subclasses may override this routine to provide different behavior.
John McCall9d125032010-01-15 18:39:57 +00001177 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1178 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001179 SourceLocation RParenLoc,
1180 ExprArg SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001181 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1182 move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001183 }
Mike Stump1eb44332009-09-09 15:08:12 +00001184
Douglas Gregorb98b1992009-08-11 05:31:07 +00001185 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001186 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001187 /// By default, performs semantic analysis to build the new expression.
1188 /// Subclasses may override this routine to provide different behavior.
1189 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001190 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001191 SourceLocation RParenLoc,
1192 ExprArg Init) {
John McCall42f56b52010-01-18 19:35:47 +00001193 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1194 move(Init));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001195 }
Mike Stump1eb44332009-09-09 15:08:12 +00001196
Douglas Gregorb98b1992009-08-11 05:31:07 +00001197 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001198 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001199 /// By default, performs semantic analysis to build the new expression.
1200 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001201 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001202 SourceLocation OpLoc,
1203 SourceLocation AccessorLoc,
1204 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001205
John McCall129e2df2009-11-30 22:42:35 +00001206 CXXScopeSpec SS;
John McCallaa81e162009-12-01 22:10:20 +00001207 QualType BaseType = ((Expr*) Base.get())->getType();
1208 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001209 OpLoc, /*IsArrow*/ false,
1210 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor2d1c2142009-11-03 19:44:04 +00001211 DeclarationName(&Accessor),
John McCall129e2df2009-11-30 22:42:35 +00001212 AccessorLoc,
1213 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001214 }
Mike Stump1eb44332009-09-09 15:08:12 +00001215
Douglas Gregorb98b1992009-08-11 05:31:07 +00001216 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001217 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001218 /// By default, performs semantic analysis to build the new expression.
1219 /// Subclasses may override this routine to provide different behavior.
1220 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1221 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001222 SourceLocation RBraceLoc,
1223 QualType ResultTy) {
1224 OwningExprResult Result
1225 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1226 if (Result.isInvalid() || ResultTy->isDependentType())
1227 return move(Result);
1228
1229 // Patch in the result type we were given, which may have been computed
1230 // when the initial InitListExpr was built.
1231 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1232 ILE->setType(ResultTy);
1233 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001234 }
Mike Stump1eb44332009-09-09 15:08:12 +00001235
Douglas Gregorb98b1992009-08-11 05:31:07 +00001236 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001237 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001238 /// By default, performs semantic analysis to build the new expression.
1239 /// Subclasses may override this routine to provide different behavior.
1240 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1241 MultiExprArg ArrayExprs,
1242 SourceLocation EqualOrColonLoc,
1243 bool GNUSyntax,
1244 ExprArg Init) {
1245 OwningExprResult Result
1246 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1247 move(Init));
1248 if (Result.isInvalid())
1249 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001250
Douglas Gregorb98b1992009-08-11 05:31:07 +00001251 ArrayExprs.release();
1252 return move(Result);
1253 }
Mike Stump1eb44332009-09-09 15:08:12 +00001254
Douglas Gregorb98b1992009-08-11 05:31:07 +00001255 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001256 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001257 /// By default, builds the implicit value initialization without performing
1258 /// any semantic analysis. Subclasses may override this routine to provide
1259 /// different behavior.
1260 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1261 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1262 }
Mike Stump1eb44332009-09-09 15:08:12 +00001263
Douglas Gregorb98b1992009-08-11 05:31:07 +00001264 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001265 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001266 /// By default, performs semantic analysis to build the new expression.
1267 /// Subclasses may override this routine to provide different behavior.
1268 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1269 QualType T, SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001270 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001271 RParenLoc);
1272 }
1273
1274 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001275 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001276 /// By default, performs semantic analysis to build the new expression.
1277 /// Subclasses may override this routine to provide different behavior.
1278 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1279 MultiExprArg SubExprs,
1280 SourceLocation RParenLoc) {
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001281 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1282 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001283 }
Mike Stump1eb44332009-09-09 15:08:12 +00001284
Douglas Gregorb98b1992009-08-11 05:31:07 +00001285 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001286 ///
1287 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001288 /// rather than attempting to map the label statement itself.
1289 /// Subclasses may override this routine to provide different behavior.
1290 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1291 SourceLocation LabelLoc,
1292 LabelStmt *Label) {
1293 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1294 }
Mike Stump1eb44332009-09-09 15:08:12 +00001295
Douglas Gregorb98b1992009-08-11 05:31:07 +00001296 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001297 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001298 /// By default, performs semantic analysis to build the new expression.
1299 /// Subclasses may override this routine to provide different behavior.
1300 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1301 StmtArg SubStmt,
1302 SourceLocation RParenLoc) {
1303 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1304 }
Mike Stump1eb44332009-09-09 15:08:12 +00001305
Douglas Gregorb98b1992009-08-11 05:31:07 +00001306 /// \brief Build a new __builtin_types_compatible_p expression.
1307 ///
1308 /// By default, performs semantic analysis to build the new expression.
1309 /// Subclasses may override this routine to provide different behavior.
1310 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1311 QualType T1, QualType T2,
1312 SourceLocation RParenLoc) {
1313 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1314 T1.getAsOpaquePtr(),
1315 T2.getAsOpaquePtr(),
1316 RParenLoc);
1317 }
Mike Stump1eb44332009-09-09 15:08:12 +00001318
Douglas Gregorb98b1992009-08-11 05:31:07 +00001319 /// \brief Build a new __builtin_choose_expr expression.
1320 ///
1321 /// By default, performs semantic analysis to build the new expression.
1322 /// Subclasses may override this routine to provide different behavior.
1323 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1324 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1325 SourceLocation RParenLoc) {
1326 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1327 move(Cond), move(LHS), move(RHS),
1328 RParenLoc);
1329 }
Mike Stump1eb44332009-09-09 15:08:12 +00001330
Douglas Gregorb98b1992009-08-11 05:31:07 +00001331 /// \brief Build a new overloaded operator call expression.
1332 ///
1333 /// By default, performs semantic analysis to build the new expression.
1334 /// The semantic analysis provides the behavior of template instantiation,
1335 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001336 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001337 /// argument-dependent lookup, etc. Subclasses may override this routine to
1338 /// provide different behavior.
1339 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1340 SourceLocation OpLoc,
1341 ExprArg Callee,
1342 ExprArg First,
1343 ExprArg Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001344
1345 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001346 /// reinterpret_cast.
1347 ///
1348 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001349 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001350 /// Subclasses may override this routine to provide different behavior.
1351 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1352 Stmt::StmtClass Class,
1353 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001354 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001355 SourceLocation RAngleLoc,
1356 SourceLocation LParenLoc,
1357 ExprArg SubExpr,
1358 SourceLocation RParenLoc) {
1359 switch (Class) {
1360 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001361 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001362 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001363 move(SubExpr), RParenLoc);
1364
1365 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001366 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001367 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001368 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001369
Douglas Gregorb98b1992009-08-11 05:31:07 +00001370 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001371 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001372 RAngleLoc, LParenLoc,
1373 move(SubExpr),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001374 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001375
Douglas Gregorb98b1992009-08-11 05:31:07 +00001376 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001377 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001378 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001379 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001380
Douglas Gregorb98b1992009-08-11 05:31:07 +00001381 default:
1382 assert(false && "Invalid C++ named cast");
1383 break;
1384 }
Mike Stump1eb44332009-09-09 15:08:12 +00001385
Douglas Gregorb98b1992009-08-11 05:31:07 +00001386 return getSema().ExprError();
1387 }
Mike Stump1eb44332009-09-09 15:08:12 +00001388
Douglas Gregorb98b1992009-08-11 05:31:07 +00001389 /// \brief Build a new C++ static_cast expression.
1390 ///
1391 /// By default, performs semantic analysis to build the new expression.
1392 /// Subclasses may override this routine to provide different behavior.
1393 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1394 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001395 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001396 SourceLocation RAngleLoc,
1397 SourceLocation LParenLoc,
1398 ExprArg SubExpr,
1399 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001400 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1401 TInfo, move(SubExpr),
1402 SourceRange(LAngleLoc, RAngleLoc),
1403 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001404 }
1405
1406 /// \brief Build a new C++ dynamic_cast expression.
1407 ///
1408 /// By default, performs semantic analysis to build the new expression.
1409 /// Subclasses may override this routine to provide different behavior.
1410 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1411 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001412 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001413 SourceLocation RAngleLoc,
1414 SourceLocation LParenLoc,
1415 ExprArg SubExpr,
1416 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001417 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1418 TInfo, move(SubExpr),
1419 SourceRange(LAngleLoc, RAngleLoc),
1420 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001421 }
1422
1423 /// \brief Build a new C++ reinterpret_cast expression.
1424 ///
1425 /// By default, performs semantic analysis to build the new expression.
1426 /// Subclasses may override this routine to provide different behavior.
1427 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1428 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001429 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001430 SourceLocation RAngleLoc,
1431 SourceLocation LParenLoc,
1432 ExprArg SubExpr,
1433 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001434 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1435 TInfo, move(SubExpr),
1436 SourceRange(LAngleLoc, RAngleLoc),
1437 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001438 }
1439
1440 /// \brief Build a new C++ const_cast expression.
1441 ///
1442 /// By default, performs semantic analysis to build the new expression.
1443 /// Subclasses may override this routine to provide different behavior.
1444 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1445 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001446 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001447 SourceLocation RAngleLoc,
1448 SourceLocation LParenLoc,
1449 ExprArg SubExpr,
1450 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001451 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1452 TInfo, move(SubExpr),
1453 SourceRange(LAngleLoc, RAngleLoc),
1454 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001455 }
Mike Stump1eb44332009-09-09 15:08:12 +00001456
Douglas Gregorb98b1992009-08-11 05:31:07 +00001457 /// \brief Build a new C++ functional-style cast expression.
1458 ///
1459 /// By default, performs semantic analysis to build the new expression.
1460 /// Subclasses may override this routine to provide different behavior.
1461 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001462 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001463 SourceLocation LParenLoc,
1464 ExprArg SubExpr,
1465 SourceLocation RParenLoc) {
Chris Lattner88650c32009-08-24 05:19:01 +00001466 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001467 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001468 TInfo->getType().getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001469 LParenLoc,
Chris Lattner88650c32009-08-24 05:19:01 +00001470 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump1eb44332009-09-09 15:08:12 +00001471 /*CommaLocs=*/0,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001472 RParenLoc);
1473 }
Mike Stump1eb44332009-09-09 15:08:12 +00001474
Douglas Gregorb98b1992009-08-11 05:31:07 +00001475 /// \brief Build a new C++ typeid(type) expression.
1476 ///
1477 /// By default, performs semantic analysis to build the new expression.
1478 /// Subclasses may override this routine to provide different behavior.
1479 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1480 SourceLocation LParenLoc,
1481 QualType T,
1482 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001483 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 T.getAsOpaquePtr(), RParenLoc);
1485 }
Mike Stump1eb44332009-09-09 15:08:12 +00001486
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 /// \brief Build a new C++ typeid(expr) expression.
1488 ///
1489 /// By default, performs semantic analysis to build the new expression.
1490 /// Subclasses may override this routine to provide different behavior.
1491 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1492 SourceLocation LParenLoc,
1493 ExprArg Operand,
1494 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001495 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001496 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1497 RParenLoc);
1498 if (Result.isInvalid())
1499 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001500
Douglas Gregorb98b1992009-08-11 05:31:07 +00001501 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1502 return move(Result);
Mike Stump1eb44332009-09-09 15:08:12 +00001503 }
1504
Douglas Gregorb98b1992009-08-11 05:31:07 +00001505 /// \brief Build a new C++ "this" expression.
1506 ///
1507 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001508 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001509 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001510 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001511 QualType ThisType,
1512 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001513 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001514 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1515 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001516 }
1517
1518 /// \brief Build a new C++ throw expression.
1519 ///
1520 /// By default, performs semantic analysis to build the new expression.
1521 /// Subclasses may override this routine to provide different behavior.
1522 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1523 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1524 }
1525
1526 /// \brief Build a new C++ default-argument expression.
1527 ///
1528 /// By default, builds a new default-argument expression, which does not
1529 /// require any semantic analysis. Subclasses may override this routine to
1530 /// provide different behavior.
Douglas Gregor036aed12009-12-23 23:03:06 +00001531 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1532 ParmVarDecl *Param) {
1533 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1534 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001535 }
1536
1537 /// \brief Build a new C++ zero-initialization expression.
1538 ///
1539 /// By default, performs semantic analysis to build the new expression.
1540 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001541 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001542 SourceLocation LParenLoc,
1543 QualType T,
1544 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001545 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1546 T.getAsOpaquePtr(), LParenLoc,
1547 MultiExprArg(getSema(), 0, 0),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001548 0, RParenLoc);
1549 }
Mike Stump1eb44332009-09-09 15:08:12 +00001550
Douglas Gregorb98b1992009-08-11 05:31:07 +00001551 /// \brief Build a new C++ "new" expression.
1552 ///
1553 /// By default, performs semantic analysis to build the new expression.
1554 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001555 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001556 bool UseGlobal,
1557 SourceLocation PlacementLParen,
1558 MultiExprArg PlacementArgs,
1559 SourceLocation PlacementRParen,
Mike Stump1eb44332009-09-09 15:08:12 +00001560 bool ParenTypeId,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001561 QualType AllocType,
1562 SourceLocation TypeLoc,
1563 SourceRange TypeRange,
1564 ExprArg ArraySize,
1565 SourceLocation ConstructorLParen,
1566 MultiExprArg ConstructorArgs,
1567 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001568 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 PlacementLParen,
1570 move(PlacementArgs),
1571 PlacementRParen,
1572 ParenTypeId,
1573 AllocType,
1574 TypeLoc,
1575 TypeRange,
1576 move(ArraySize),
1577 ConstructorLParen,
1578 move(ConstructorArgs),
1579 ConstructorRParen);
1580 }
Mike Stump1eb44332009-09-09 15:08:12 +00001581
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 /// \brief Build a new C++ "delete" expression.
1583 ///
1584 /// By default, performs semantic analysis to build the new expression.
1585 /// Subclasses may override this routine to provide different behavior.
1586 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1587 bool IsGlobalDelete,
1588 bool IsArrayForm,
1589 ExprArg Operand) {
1590 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1591 move(Operand));
1592 }
Mike Stump1eb44332009-09-09 15:08:12 +00001593
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 /// \brief Build a new unary type trait expression.
1595 ///
1596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
1598 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1599 SourceLocation StartLoc,
1600 SourceLocation LParenLoc,
1601 QualType T,
1602 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001603 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 T.getAsOpaquePtr(), RParenLoc);
1605 }
1606
Mike Stump1eb44332009-09-09 15:08:12 +00001607 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 /// expression.
1609 ///
1610 /// By default, performs semantic analysis to build the new expression.
1611 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001612 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001613 SourceRange QualifierRange,
1614 DeclarationName Name,
1615 SourceLocation Location,
John McCallf7a1a742009-11-24 19:00:30 +00001616 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001617 CXXScopeSpec SS;
1618 SS.setRange(QualifierRange);
1619 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001620
1621 if (TemplateArgs)
1622 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1623 *TemplateArgs);
1624
1625 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001626 }
1627
1628 /// \brief Build a new template-id expression.
1629 ///
1630 /// By default, performs semantic analysis to build the new expression.
1631 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001632 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1633 LookupResult &R,
1634 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001635 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001636 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001637 }
1638
1639 /// \brief Build a new object-construction expression.
1640 ///
1641 /// By default, performs semantic analysis to build the new expression.
1642 /// Subclasses may override this routine to provide different behavior.
1643 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001644 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001645 CXXConstructorDecl *Constructor,
1646 bool IsElidable,
1647 MultiExprArg Args) {
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001648 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1649 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1650 ConvertedArgs))
1651 return getSema().ExprError();
1652
1653 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1654 move_arg(ConvertedArgs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 }
1656
1657 /// \brief Build a new object-construction expression.
1658 ///
1659 /// By default, performs semantic analysis to build the new expression.
1660 /// Subclasses may override this routine to provide different behavior.
1661 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1662 QualType T,
1663 SourceLocation LParenLoc,
1664 MultiExprArg Args,
1665 SourceLocation *Commas,
1666 SourceLocation RParenLoc) {
1667 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1668 T.getAsOpaquePtr(),
1669 LParenLoc,
1670 move(Args),
1671 Commas,
1672 RParenLoc);
1673 }
1674
1675 /// \brief Build a new object-construction expression.
1676 ///
1677 /// By default, performs semantic analysis to build the new expression.
1678 /// Subclasses may override this routine to provide different behavior.
1679 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1680 QualType T,
1681 SourceLocation LParenLoc,
1682 MultiExprArg Args,
1683 SourceLocation *Commas,
1684 SourceLocation RParenLoc) {
1685 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1686 /*FIXME*/LParenLoc),
1687 T.getAsOpaquePtr(),
1688 LParenLoc,
1689 move(Args),
1690 Commas,
1691 RParenLoc);
1692 }
Mike Stump1eb44332009-09-09 15:08:12 +00001693
Douglas Gregorb98b1992009-08-11 05:31:07 +00001694 /// \brief Build a new member reference expression.
1695 ///
1696 /// By default, performs semantic analysis to build the new expression.
1697 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001698 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001699 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 bool IsArrow,
1701 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001702 NestedNameSpecifier *Qualifier,
1703 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001704 NamedDecl *FirstQualifierInScope,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705 DeclarationName Name,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001706 SourceLocation MemberLoc,
John McCall129e2df2009-11-30 22:42:35 +00001707 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001709 SS.setRange(QualifierRange);
1710 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001711
John McCallaa81e162009-12-01 22:10:20 +00001712 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1713 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001714 SS, FirstQualifierInScope,
1715 Name, MemberLoc, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001716 }
1717
John McCall129e2df2009-11-30 22:42:35 +00001718 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001719 ///
1720 /// By default, performs semantic analysis to build the new expression.
1721 /// Subclasses may override this routine to provide different behavior.
John McCall129e2df2009-11-30 22:42:35 +00001722 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001723 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001724 SourceLocation OperatorLoc,
1725 bool IsArrow,
1726 NestedNameSpecifier *Qualifier,
1727 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001728 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001729 LookupResult &R,
1730 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001731 CXXScopeSpec SS;
1732 SS.setRange(QualifierRange);
1733 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001734
John McCallaa81e162009-12-01 22:10:20 +00001735 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1736 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001737 SS, FirstQualifierInScope,
1738 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001739 }
Mike Stump1eb44332009-09-09 15:08:12 +00001740
Douglas Gregorb98b1992009-08-11 05:31:07 +00001741 /// \brief Build a new Objective-C @encode expression.
1742 ///
1743 /// By default, performs semantic analysis to build the new expression.
1744 /// Subclasses may override this routine to provide different behavior.
1745 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001746 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001747 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001748 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001749 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001750 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001751
Douglas Gregor92e986e2010-04-22 16:44:27 +00001752 /// \brief Build a new Objective-C class message.
1753 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1754 Selector Sel,
1755 ObjCMethodDecl *Method,
1756 SourceLocation LBracLoc,
1757 MultiExprArg Args,
1758 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001759 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1760 ReceiverTypeInfo->getType(),
1761 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001762 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001763 move(Args));
1764 }
1765
1766 /// \brief Build a new Objective-C instance message.
1767 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1768 Selector Sel,
1769 ObjCMethodDecl *Method,
1770 SourceLocation LBracLoc,
1771 MultiExprArg Args,
1772 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001773 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1774 return SemaRef.BuildInstanceMessage(move(Receiver),
1775 ReceiverType,
1776 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001777 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001778 move(Args));
1779 }
1780
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 /// \brief Build a new shuffle vector expression.
1782 ///
1783 /// By default, performs semantic analysis to build the new expression.
1784 /// Subclasses may override this routine to provide different behavior.
1785 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1786 MultiExprArg SubExprs,
1787 SourceLocation RParenLoc) {
1788 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001789 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001790 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1791 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1792 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1793 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001794
Douglas Gregorb98b1992009-08-11 05:31:07 +00001795 // Build a reference to the __builtin_shufflevector builtin
1796 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001797 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001798 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001799 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001801
1802 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 unsigned NumSubExprs = SubExprs.size();
1804 Expr **Subs = (Expr **)SubExprs.release();
1805 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1806 Subs, NumSubExprs,
1807 Builtin->getResultType(),
1808 RParenLoc);
1809 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001810
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 // Type-check the __builtin_shufflevector expression.
1812 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1813 if (Result.isInvalid())
1814 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001815
Douglas Gregorb98b1992009-08-11 05:31:07 +00001816 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001817 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001818 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001819};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001820
Douglas Gregor43959a92009-08-20 07:17:43 +00001821template<typename Derived>
1822Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1823 if (!S)
1824 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001825
Douglas Gregor43959a92009-08-20 07:17:43 +00001826 switch (S->getStmtClass()) {
1827 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001828
Douglas Gregor43959a92009-08-20 07:17:43 +00001829 // Transform individual statement nodes
1830#define STMT(Node, Parent) \
1831 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1832#define EXPR(Node, Parent)
1833#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001834
Douglas Gregor43959a92009-08-20 07:17:43 +00001835 // Transform expressions by calling TransformExpr.
1836#define STMT(Node, Parent)
John McCall09cc1412010-02-03 00:55:45 +00001837#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregor43959a92009-08-20 07:17:43 +00001838#define EXPR(Node, Parent) case Stmt::Node##Class:
1839#include "clang/AST/StmtNodes.def"
1840 {
1841 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1842 if (E.isInvalid())
1843 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001844
Anders Carlsson5ee56e92009-12-16 02:09:40 +00001845 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregor43959a92009-08-20 07:17:43 +00001846 }
Mike Stump1eb44332009-09-09 15:08:12 +00001847 }
1848
Douglas Gregor43959a92009-08-20 07:17:43 +00001849 return SemaRef.Owned(S->Retain());
1850}
Mike Stump1eb44332009-09-09 15:08:12 +00001851
1852
Douglas Gregor670444e2009-08-04 22:27:00 +00001853template<typename Derived>
John McCall454feb92009-12-08 09:21:05 +00001854Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001855 if (!E)
1856 return SemaRef.Owned(E);
1857
1858 switch (E->getStmtClass()) {
1859 case Stmt::NoStmtClass: break;
1860#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall09cc1412010-02-03 00:55:45 +00001861#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorb98b1992009-08-11 05:31:07 +00001862#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00001863 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001864#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001865 }
1866
Douglas Gregorb98b1992009-08-11 05:31:07 +00001867 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00001868}
1869
1870template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00001871NestedNameSpecifier *
1872TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00001873 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001874 QualType ObjectType,
1875 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00001876 if (!NNS)
1877 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001878
Douglas Gregor43959a92009-08-20 07:17:43 +00001879 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00001880 NestedNameSpecifier *Prefix = NNS->getPrefix();
1881 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00001882 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001883 ObjectType,
1884 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00001885 if (!Prefix)
1886 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001887
1888 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00001889 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00001890 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00001891 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001892 }
Mike Stump1eb44332009-09-09 15:08:12 +00001893
Douglas Gregordcee1a12009-08-06 05:28:30 +00001894 switch (NNS->getKind()) {
1895 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00001896 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00001897 "Identifier nested-name-specifier with no prefix or object type");
1898 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1899 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00001900 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001901
1902 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00001903 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00001904 ObjectType,
1905 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001906
Douglas Gregordcee1a12009-08-06 05:28:30 +00001907 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00001908 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00001909 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00001910 getDerived().TransformDecl(Range.getBegin(),
1911 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00001912 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00001913 Prefix == NNS->getPrefix() &&
1914 NS == NNS->getAsNamespace())
1915 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001916
Douglas Gregordcee1a12009-08-06 05:28:30 +00001917 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1918 }
Mike Stump1eb44332009-09-09 15:08:12 +00001919
Douglas Gregordcee1a12009-08-06 05:28:30 +00001920 case NestedNameSpecifier::Global:
1921 // There is no meaningful transformation that one could perform on the
1922 // global scope.
1923 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001924
Douglas Gregordcee1a12009-08-06 05:28:30 +00001925 case NestedNameSpecifier::TypeSpecWithTemplate:
1926 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00001927 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor124b8782010-02-16 19:09:40 +00001928 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
1929 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00001930 if (T.isNull())
1931 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001932
Douglas Gregordcee1a12009-08-06 05:28:30 +00001933 if (!getDerived().AlwaysRebuild() &&
1934 Prefix == NNS->getPrefix() &&
1935 T == QualType(NNS->getAsType(), 0))
1936 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001937
1938 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1939 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00001940 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00001941 }
1942 }
Mike Stump1eb44332009-09-09 15:08:12 +00001943
Douglas Gregordcee1a12009-08-06 05:28:30 +00001944 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00001945 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001946}
1947
1948template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001949DeclarationName
Douglas Gregor81499bb2009-09-03 22:13:48 +00001950TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +00001951 SourceLocation Loc,
1952 QualType ObjectType) {
Douglas Gregor81499bb2009-09-03 22:13:48 +00001953 if (!Name)
1954 return Name;
1955
1956 switch (Name.getNameKind()) {
1957 case DeclarationName::Identifier:
1958 case DeclarationName::ObjCZeroArgSelector:
1959 case DeclarationName::ObjCOneArgSelector:
1960 case DeclarationName::ObjCMultiArgSelector:
1961 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00001962 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00001963 case DeclarationName::CXXUsingDirective:
1964 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001965
Douglas Gregor81499bb2009-09-03 22:13:48 +00001966 case DeclarationName::CXXConstructorName:
1967 case DeclarationName::CXXDestructorName:
1968 case DeclarationName::CXXConversionFunctionName: {
1969 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregor124b8782010-02-16 19:09:40 +00001970 QualType T = getDerived().TransformType(Name.getCXXNameType(),
1971 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00001972 if (T.isNull())
1973 return DeclarationName();
Mike Stump1eb44332009-09-09 15:08:12 +00001974
Douglas Gregor81499bb2009-09-03 22:13:48 +00001975 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump1eb44332009-09-09 15:08:12 +00001976 Name.getNameKind(),
Douglas Gregor81499bb2009-09-03 22:13:48 +00001977 SemaRef.Context.getCanonicalType(T));
Douglas Gregor81499bb2009-09-03 22:13:48 +00001978 }
Mike Stump1eb44332009-09-09 15:08:12 +00001979 }
1980
Douglas Gregor81499bb2009-09-03 22:13:48 +00001981 return DeclarationName();
1982}
1983
1984template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001985TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001986TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1987 QualType ObjectType) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00001988 SourceLocation Loc = getDerived().getBaseLocation();
1989
Douglas Gregord1067e52009-08-06 06:41:21 +00001990 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001991 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00001992 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00001993 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1994 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00001995 if (!NNS)
1996 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001997
Douglas Gregord1067e52009-08-06 06:41:21 +00001998 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001999 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002000 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002001 if (!TransTemplate)
2002 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002003
Douglas Gregord1067e52009-08-06 06:41:21 +00002004 if (!getDerived().AlwaysRebuild() &&
2005 NNS == QTN->getQualifier() &&
2006 TransTemplate == Template)
2007 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002008
Douglas Gregord1067e52009-08-06 06:41:21 +00002009 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2010 TransTemplate);
2011 }
Mike Stump1eb44332009-09-09 15:08:12 +00002012
John McCallf7a1a742009-11-24 19:00:30 +00002013 // These should be getting filtered out before they make it into the AST.
2014 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002015 }
Mike Stump1eb44332009-09-09 15:08:12 +00002016
Douglas Gregord1067e52009-08-06 06:41:21 +00002017 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002018 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002019 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002020 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2021 ObjectType);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002022 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00002023 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002024
Douglas Gregord1067e52009-08-06 06:41:21 +00002025 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002026 NNS == DTN->getQualifier() &&
2027 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002028 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002029
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002030 if (DTN->isIdentifier())
2031 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
2032 ObjectType);
2033
2034 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
2035 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002036 }
Mike Stump1eb44332009-09-09 15:08:12 +00002037
Douglas Gregord1067e52009-08-06 06:41:21 +00002038 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002039 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002040 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002041 if (!TransTemplate)
2042 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002043
Douglas Gregord1067e52009-08-06 06:41:21 +00002044 if (!getDerived().AlwaysRebuild() &&
2045 TransTemplate == Template)
2046 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002047
Douglas Gregord1067e52009-08-06 06:41:21 +00002048 return TemplateName(TransTemplate);
2049 }
Mike Stump1eb44332009-09-09 15:08:12 +00002050
John McCallf7a1a742009-11-24 19:00:30 +00002051 // These should be getting filtered out before they reach the AST.
2052 assert(false && "overloaded function decl survived to here");
2053 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002054}
2055
2056template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002057void TreeTransform<Derived>::InventTemplateArgumentLoc(
2058 const TemplateArgument &Arg,
2059 TemplateArgumentLoc &Output) {
2060 SourceLocation Loc = getDerived().getBaseLocation();
2061 switch (Arg.getKind()) {
2062 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002063 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002064 break;
2065
2066 case TemplateArgument::Type:
2067 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002068 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall833ca992009-10-29 08:12:44 +00002069
2070 break;
2071
Douglas Gregor788cd062009-11-11 01:00:40 +00002072 case TemplateArgument::Template:
2073 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2074 break;
2075
John McCall833ca992009-10-29 08:12:44 +00002076 case TemplateArgument::Expression:
2077 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2078 break;
2079
2080 case TemplateArgument::Declaration:
2081 case TemplateArgument::Integral:
2082 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002083 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002084 break;
2085 }
2086}
2087
2088template<typename Derived>
2089bool TreeTransform<Derived>::TransformTemplateArgument(
2090 const TemplateArgumentLoc &Input,
2091 TemplateArgumentLoc &Output) {
2092 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002093 switch (Arg.getKind()) {
2094 case TemplateArgument::Null:
2095 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002096 Output = Input;
2097 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002098
Douglas Gregor670444e2009-08-04 22:27:00 +00002099 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002100 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002101 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002102 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002103
2104 DI = getDerived().TransformType(DI);
2105 if (!DI) return true;
2106
2107 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2108 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002109 }
Mike Stump1eb44332009-09-09 15:08:12 +00002110
Douglas Gregor670444e2009-08-04 22:27:00 +00002111 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002112 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002113 DeclarationName Name;
2114 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2115 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002116 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002117 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002118 if (!D) return true;
2119
John McCall828bff22009-10-29 18:45:58 +00002120 Expr *SourceExpr = Input.getSourceDeclExpression();
2121 if (SourceExpr) {
2122 EnterExpressionEvaluationContext Unevaluated(getSema(),
2123 Action::Unevaluated);
2124 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2125 if (E.isInvalid())
2126 SourceExpr = NULL;
2127 else {
2128 SourceExpr = E.takeAs<Expr>();
2129 SourceExpr->Retain();
2130 }
2131 }
2132
2133 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002134 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002135 }
Mike Stump1eb44332009-09-09 15:08:12 +00002136
Douglas Gregor788cd062009-11-11 01:00:40 +00002137 case TemplateArgument::Template: {
2138 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
2139 TemplateName Template
2140 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2141 if (Template.isNull())
2142 return true;
2143
2144 Output = TemplateArgumentLoc(TemplateArgument(Template),
2145 Input.getTemplateQualifierRange(),
2146 Input.getTemplateNameLoc());
2147 return false;
2148 }
2149
Douglas Gregor670444e2009-08-04 22:27:00 +00002150 case TemplateArgument::Expression: {
2151 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002152 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002153 Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002154
John McCall833ca992009-10-29 08:12:44 +00002155 Expr *InputExpr = Input.getSourceExpression();
2156 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2157
2158 Sema::OwningExprResult E
2159 = getDerived().TransformExpr(InputExpr);
2160 if (E.isInvalid()) return true;
2161
2162 Expr *ETaken = E.takeAs<Expr>();
John McCall828bff22009-10-29 18:45:58 +00002163 ETaken->Retain();
John McCall833ca992009-10-29 08:12:44 +00002164 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2165 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002166 }
Mike Stump1eb44332009-09-09 15:08:12 +00002167
Douglas Gregor670444e2009-08-04 22:27:00 +00002168 case TemplateArgument::Pack: {
2169 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2170 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002171 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002172 AEnd = Arg.pack_end();
2173 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002174
John McCall833ca992009-10-29 08:12:44 +00002175 // FIXME: preserve source information here when we start
2176 // caring about parameter packs.
2177
John McCall828bff22009-10-29 18:45:58 +00002178 TemplateArgumentLoc InputArg;
2179 TemplateArgumentLoc OutputArg;
2180 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2181 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002182 return true;
2183
John McCall828bff22009-10-29 18:45:58 +00002184 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002185 }
2186 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002187 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002188 true);
John McCall828bff22009-10-29 18:45:58 +00002189 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002190 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002191 }
2192 }
Mike Stump1eb44332009-09-09 15:08:12 +00002193
Douglas Gregor670444e2009-08-04 22:27:00 +00002194 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002195 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002196}
2197
Douglas Gregor577f75a2009-08-04 16:50:30 +00002198//===----------------------------------------------------------------------===//
2199// Type transformation
2200//===----------------------------------------------------------------------===//
2201
2202template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002203QualType TreeTransform<Derived>::TransformType(QualType T,
2204 QualType ObjectType) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002205 if (getDerived().AlreadyTransformed(T))
2206 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002207
John McCalla2becad2009-10-21 00:40:46 +00002208 // Temporary workaround. All of these transformations should
2209 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002210 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002211 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCalla2becad2009-10-21 00:40:46 +00002212
Douglas Gregor124b8782010-02-16 19:09:40 +00002213 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall0953e762009-09-24 19:53:00 +00002214
John McCalla2becad2009-10-21 00:40:46 +00002215 if (!NewDI)
2216 return QualType();
2217
2218 return NewDI->getType();
2219}
2220
2221template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002222TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2223 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002224 if (getDerived().AlreadyTransformed(DI->getType()))
2225 return DI;
2226
2227 TypeLocBuilder TLB;
2228
2229 TypeLoc TL = DI->getTypeLoc();
2230 TLB.reserve(TL.getFullDataSize());
2231
Douglas Gregor124b8782010-02-16 19:09:40 +00002232 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002233 if (Result.isNull())
2234 return 0;
2235
John McCalla93c9342009-12-07 02:54:59 +00002236 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002237}
2238
2239template<typename Derived>
2240QualType
Douglas Gregor124b8782010-02-16 19:09:40 +00002241TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2242 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002243 switch (T.getTypeLocClass()) {
2244#define ABSTRACT_TYPELOC(CLASS, PARENT)
2245#define TYPELOC(CLASS, PARENT) \
2246 case TypeLoc::CLASS: \
Douglas Gregor124b8782010-02-16 19:09:40 +00002247 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2248 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002249#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002250 }
Mike Stump1eb44332009-09-09 15:08:12 +00002251
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002252 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002253 return QualType();
2254}
2255
2256/// FIXME: By default, this routine adds type qualifiers only to types
2257/// that can have qualifiers, and silently suppresses those qualifiers
2258/// that are not permitted (e.g., qualifiers on reference or function
2259/// types). This is the right thing for template instantiation, but
2260/// probably not for other clients.
2261template<typename Derived>
2262QualType
2263TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002264 QualifiedTypeLoc T,
2265 QualType ObjectType) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002266 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002267
Douglas Gregor124b8782010-02-16 19:09:40 +00002268 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2269 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002270 if (Result.isNull())
2271 return QualType();
2272
2273 // Silently suppress qualifiers if the result type can't be qualified.
2274 // FIXME: this is the right thing for template instantiation, but
2275 // probably not for other clients.
2276 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002277 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002278
John McCalla2becad2009-10-21 00:40:46 +00002279 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2280
2281 TLB.push<QualifiedTypeLoc>(Result);
2282
2283 // No location information to preserve.
2284
2285 return Result;
2286}
2287
2288template <class TyLoc> static inline
2289QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2290 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2291 NewT.setNameLoc(T.getNameLoc());
2292 return T.getType();
2293}
2294
John McCalla2becad2009-10-21 00:40:46 +00002295template<typename Derived>
2296QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002297 BuiltinTypeLoc T,
2298 QualType ObjectType) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002299 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2300 NewT.setBuiltinLoc(T.getBuiltinLoc());
2301 if (T.needsExtraLocalData())
2302 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2303 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002304}
Mike Stump1eb44332009-09-09 15:08:12 +00002305
Douglas Gregor577f75a2009-08-04 16:50:30 +00002306template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002307QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002308 ComplexTypeLoc T,
2309 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002310 // FIXME: recurse?
2311 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002312}
Mike Stump1eb44332009-09-09 15:08:12 +00002313
Douglas Gregor577f75a2009-08-04 16:50:30 +00002314template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002315QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002316 PointerTypeLoc TL,
2317 QualType ObjectType) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002318 QualType PointeeType
2319 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2320 if (PointeeType.isNull())
2321 return QualType();
2322
2323 QualType Result = TL.getType();
2324 if (PointeeType->isObjCInterfaceType()) {
2325 // A dependent pointer type 'T *' has is being transformed such
2326 // that an Objective-C class type is being replaced for 'T'. The
2327 // resulting pointer type is an ObjCObjectPointerType, not a
2328 // PointerType.
2329 const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>();
2330 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType,
2331 const_cast<ObjCProtocolDecl **>(
2332 IFace->qual_begin()),
2333 IFace->getNumProtocols());
2334
2335 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2336 NewT.setStarLoc(TL.getSigilLoc());
2337 NewT.setHasProtocolsAsWritten(false);
2338 NewT.setLAngleLoc(SourceLocation());
2339 NewT.setRAngleLoc(SourceLocation());
2340 NewT.setHasBaseTypeAsWritten(true);
2341 return Result;
2342 }
2343
2344 if (getDerived().AlwaysRebuild() ||
2345 PointeeType != TL.getPointeeLoc().getType()) {
2346 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2347 if (Result.isNull())
2348 return QualType();
2349 }
2350
2351 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2352 NewT.setSigilLoc(TL.getSigilLoc());
2353 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002354}
Mike Stump1eb44332009-09-09 15:08:12 +00002355
2356template<typename Derived>
2357QualType
John McCalla2becad2009-10-21 00:40:46 +00002358TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002359 BlockPointerTypeLoc TL,
2360 QualType ObjectType) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002361 QualType PointeeType
2362 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2363 if (PointeeType.isNull())
2364 return QualType();
2365
2366 QualType Result = TL.getType();
2367 if (getDerived().AlwaysRebuild() ||
2368 PointeeType != TL.getPointeeLoc().getType()) {
2369 Result = getDerived().RebuildBlockPointerType(PointeeType,
2370 TL.getSigilLoc());
2371 if (Result.isNull())
2372 return QualType();
2373 }
2374
Douglas Gregor39968ad2010-04-22 16:50:51 +00002375 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002376 NewT.setSigilLoc(TL.getSigilLoc());
2377 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002378}
2379
John McCall85737a72009-10-30 00:06:24 +00002380/// Transforms a reference type. Note that somewhat paradoxically we
2381/// don't care whether the type itself is an l-value type or an r-value
2382/// type; we only care if the type was *written* as an l-value type
2383/// or an r-value type.
2384template<typename Derived>
2385QualType
2386TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002387 ReferenceTypeLoc TL,
2388 QualType ObjectType) {
John McCall85737a72009-10-30 00:06:24 +00002389 const ReferenceType *T = TL.getTypePtr();
2390
2391 // Note that this works with the pointee-as-written.
2392 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2393 if (PointeeType.isNull())
2394 return QualType();
2395
2396 QualType Result = TL.getType();
2397 if (getDerived().AlwaysRebuild() ||
2398 PointeeType != T->getPointeeTypeAsWritten()) {
2399 Result = getDerived().RebuildReferenceType(PointeeType,
2400 T->isSpelledAsLValue(),
2401 TL.getSigilLoc());
2402 if (Result.isNull())
2403 return QualType();
2404 }
2405
2406 // r-value references can be rebuilt as l-value references.
2407 ReferenceTypeLoc NewTL;
2408 if (isa<LValueReferenceType>(Result))
2409 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2410 else
2411 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2412 NewTL.setSigilLoc(TL.getSigilLoc());
2413
2414 return Result;
2415}
2416
Mike Stump1eb44332009-09-09 15:08:12 +00002417template<typename Derived>
2418QualType
John McCalla2becad2009-10-21 00:40:46 +00002419TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002420 LValueReferenceTypeLoc TL,
2421 QualType ObjectType) {
2422 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002423}
2424
Mike Stump1eb44332009-09-09 15:08:12 +00002425template<typename Derived>
2426QualType
John McCalla2becad2009-10-21 00:40:46 +00002427TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002428 RValueReferenceTypeLoc TL,
2429 QualType ObjectType) {
2430 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002431}
Mike Stump1eb44332009-09-09 15:08:12 +00002432
Douglas Gregor577f75a2009-08-04 16:50:30 +00002433template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002434QualType
John McCalla2becad2009-10-21 00:40:46 +00002435TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002436 MemberPointerTypeLoc TL,
2437 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002438 MemberPointerType *T = TL.getTypePtr();
2439
2440 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002441 if (PointeeType.isNull())
2442 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002443
John McCalla2becad2009-10-21 00:40:46 +00002444 // TODO: preserve source information for this.
2445 QualType ClassType
2446 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002447 if (ClassType.isNull())
2448 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002449
John McCalla2becad2009-10-21 00:40:46 +00002450 QualType Result = TL.getType();
2451 if (getDerived().AlwaysRebuild() ||
2452 PointeeType != T->getPointeeType() ||
2453 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002454 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2455 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002456 if (Result.isNull())
2457 return QualType();
2458 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002459
John McCalla2becad2009-10-21 00:40:46 +00002460 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2461 NewTL.setSigilLoc(TL.getSigilLoc());
2462
2463 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002464}
2465
Mike Stump1eb44332009-09-09 15:08:12 +00002466template<typename Derived>
2467QualType
John McCalla2becad2009-10-21 00:40:46 +00002468TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002469 ConstantArrayTypeLoc TL,
2470 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002471 ConstantArrayType *T = TL.getTypePtr();
2472 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002473 if (ElementType.isNull())
2474 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002475
John McCalla2becad2009-10-21 00:40:46 +00002476 QualType Result = TL.getType();
2477 if (getDerived().AlwaysRebuild() ||
2478 ElementType != T->getElementType()) {
2479 Result = getDerived().RebuildConstantArrayType(ElementType,
2480 T->getSizeModifier(),
2481 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002482 T->getIndexTypeCVRQualifiers(),
2483 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002484 if (Result.isNull())
2485 return QualType();
2486 }
2487
2488 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2489 NewTL.setLBracketLoc(TL.getLBracketLoc());
2490 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002491
John McCalla2becad2009-10-21 00:40:46 +00002492 Expr *Size = TL.getSizeExpr();
2493 if (Size) {
2494 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2495 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2496 }
2497 NewTL.setSizeExpr(Size);
2498
2499 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002500}
Mike Stump1eb44332009-09-09 15:08:12 +00002501
Douglas Gregor577f75a2009-08-04 16:50:30 +00002502template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002503QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002504 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002505 IncompleteArrayTypeLoc TL,
2506 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002507 IncompleteArrayType *T = TL.getTypePtr();
2508 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002509 if (ElementType.isNull())
2510 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002511
John McCalla2becad2009-10-21 00:40:46 +00002512 QualType Result = TL.getType();
2513 if (getDerived().AlwaysRebuild() ||
2514 ElementType != T->getElementType()) {
2515 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002516 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002517 T->getIndexTypeCVRQualifiers(),
2518 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002519 if (Result.isNull())
2520 return QualType();
2521 }
2522
2523 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2524 NewTL.setLBracketLoc(TL.getLBracketLoc());
2525 NewTL.setRBracketLoc(TL.getRBracketLoc());
2526 NewTL.setSizeExpr(0);
2527
2528 return Result;
2529}
2530
2531template<typename Derived>
2532QualType
2533TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002534 VariableArrayTypeLoc TL,
2535 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002536 VariableArrayType *T = TL.getTypePtr();
2537 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2538 if (ElementType.isNull())
2539 return QualType();
2540
2541 // Array bounds are not potentially evaluated contexts
2542 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2543
2544 Sema::OwningExprResult SizeResult
2545 = getDerived().TransformExpr(T->getSizeExpr());
2546 if (SizeResult.isInvalid())
2547 return QualType();
2548
2549 Expr *Size = static_cast<Expr*>(SizeResult.get());
2550
2551 QualType Result = TL.getType();
2552 if (getDerived().AlwaysRebuild() ||
2553 ElementType != T->getElementType() ||
2554 Size != T->getSizeExpr()) {
2555 Result = getDerived().RebuildVariableArrayType(ElementType,
2556 T->getSizeModifier(),
2557 move(SizeResult),
2558 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002559 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002560 if (Result.isNull())
2561 return QualType();
2562 }
2563 else SizeResult.take();
2564
2565 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2566 NewTL.setLBracketLoc(TL.getLBracketLoc());
2567 NewTL.setRBracketLoc(TL.getRBracketLoc());
2568 NewTL.setSizeExpr(Size);
2569
2570 return Result;
2571}
2572
2573template<typename Derived>
2574QualType
2575TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002576 DependentSizedArrayTypeLoc TL,
2577 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002578 DependentSizedArrayType *T = TL.getTypePtr();
2579 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2580 if (ElementType.isNull())
2581 return QualType();
2582
2583 // Array bounds are not potentially evaluated contexts
2584 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2585
2586 Sema::OwningExprResult SizeResult
2587 = getDerived().TransformExpr(T->getSizeExpr());
2588 if (SizeResult.isInvalid())
2589 return QualType();
2590
2591 Expr *Size = static_cast<Expr*>(SizeResult.get());
2592
2593 QualType Result = TL.getType();
2594 if (getDerived().AlwaysRebuild() ||
2595 ElementType != T->getElementType() ||
2596 Size != T->getSizeExpr()) {
2597 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2598 T->getSizeModifier(),
2599 move(SizeResult),
2600 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002601 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002602 if (Result.isNull())
2603 return QualType();
2604 }
2605 else SizeResult.take();
2606
2607 // We might have any sort of array type now, but fortunately they
2608 // all have the same location layout.
2609 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2610 NewTL.setLBracketLoc(TL.getLBracketLoc());
2611 NewTL.setRBracketLoc(TL.getRBracketLoc());
2612 NewTL.setSizeExpr(Size);
2613
2614 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002615}
Mike Stump1eb44332009-09-09 15:08:12 +00002616
2617template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002618QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002619 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002620 DependentSizedExtVectorTypeLoc TL,
2621 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002622 DependentSizedExtVectorType *T = TL.getTypePtr();
2623
2624 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002625 QualType ElementType = getDerived().TransformType(T->getElementType());
2626 if (ElementType.isNull())
2627 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002628
Douglas Gregor670444e2009-08-04 22:27:00 +00002629 // Vector sizes are not potentially evaluated contexts
2630 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2631
Douglas Gregor577f75a2009-08-04 16:50:30 +00002632 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2633 if (Size.isInvalid())
2634 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002635
John McCalla2becad2009-10-21 00:40:46 +00002636 QualType Result = TL.getType();
2637 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002638 ElementType != T->getElementType() ||
2639 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002640 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002641 move(Size),
2642 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002643 if (Result.isNull())
2644 return QualType();
2645 }
2646 else Size.take();
2647
2648 // Result might be dependent or not.
2649 if (isa<DependentSizedExtVectorType>(Result)) {
2650 DependentSizedExtVectorTypeLoc NewTL
2651 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2652 NewTL.setNameLoc(TL.getNameLoc());
2653 } else {
2654 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2655 NewTL.setNameLoc(TL.getNameLoc());
2656 }
2657
2658 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002659}
Mike Stump1eb44332009-09-09 15:08:12 +00002660
2661template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002662QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002663 VectorTypeLoc TL,
2664 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002665 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002666 QualType ElementType = getDerived().TransformType(T->getElementType());
2667 if (ElementType.isNull())
2668 return QualType();
2669
John McCalla2becad2009-10-21 00:40:46 +00002670 QualType Result = TL.getType();
2671 if (getDerived().AlwaysRebuild() ||
2672 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002673 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2674 T->isAltiVec(), T->isPixel());
John McCalla2becad2009-10-21 00:40:46 +00002675 if (Result.isNull())
2676 return QualType();
2677 }
2678
2679 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2680 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002681
John McCalla2becad2009-10-21 00:40:46 +00002682 return Result;
2683}
2684
2685template<typename Derived>
2686QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002687 ExtVectorTypeLoc TL,
2688 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002689 VectorType *T = TL.getTypePtr();
2690 QualType ElementType = getDerived().TransformType(T->getElementType());
2691 if (ElementType.isNull())
2692 return QualType();
2693
2694 QualType Result = TL.getType();
2695 if (getDerived().AlwaysRebuild() ||
2696 ElementType != T->getElementType()) {
2697 Result = getDerived().RebuildExtVectorType(ElementType,
2698 T->getNumElements(),
2699 /*FIXME*/ SourceLocation());
2700 if (Result.isNull())
2701 return QualType();
2702 }
2703
2704 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2705 NewTL.setNameLoc(TL.getNameLoc());
2706
2707 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002708}
Mike Stump1eb44332009-09-09 15:08:12 +00002709
2710template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002711ParmVarDecl *
2712TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2713 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2714 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2715 if (!NewDI)
2716 return 0;
2717
2718 if (NewDI == OldDI)
2719 return OldParm;
2720 else
2721 return ParmVarDecl::Create(SemaRef.Context,
2722 OldParm->getDeclContext(),
2723 OldParm->getLocation(),
2724 OldParm->getIdentifier(),
2725 NewDI->getType(),
2726 NewDI,
2727 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00002728 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00002729 /* DefArg */ NULL);
2730}
2731
2732template<typename Derived>
2733bool TreeTransform<Derived>::
2734 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2735 llvm::SmallVectorImpl<QualType> &PTypes,
2736 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2737 FunctionProtoType *T = TL.getTypePtr();
2738
2739 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2740 ParmVarDecl *OldParm = TL.getArg(i);
2741
2742 QualType NewType;
2743 ParmVarDecl *NewParm;
2744
2745 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002746 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2747 if (!NewParm)
2748 return true;
2749 NewType = NewParm->getType();
2750
2751 // Deal with the possibility that we don't have a parameter
2752 // declaration for this parameter.
2753 } else {
2754 NewParm = 0;
2755
2756 QualType OldType = T->getArgType(i);
2757 NewType = getDerived().TransformType(OldType);
2758 if (NewType.isNull())
2759 return true;
2760 }
2761
2762 PTypes.push_back(NewType);
2763 PVars.push_back(NewParm);
2764 }
2765
2766 return false;
2767}
2768
2769template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002770QualType
John McCalla2becad2009-10-21 00:40:46 +00002771TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002772 FunctionProtoTypeLoc TL,
2773 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002774 FunctionProtoType *T = TL.getTypePtr();
2775 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002776 if (ResultType.isNull())
2777 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002778
John McCalla2becad2009-10-21 00:40:46 +00002779 // Transform the parameters.
Douglas Gregor577f75a2009-08-04 16:50:30 +00002780 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002781 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall21ef0fa2010-03-11 09:03:00 +00002782 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2783 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002784
John McCalla2becad2009-10-21 00:40:46 +00002785 QualType Result = TL.getType();
2786 if (getDerived().AlwaysRebuild() ||
2787 ResultType != T->getResultType() ||
2788 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2789 Result = getDerived().RebuildFunctionProtoType(ResultType,
2790 ParamTypes.data(),
2791 ParamTypes.size(),
2792 T->isVariadic(),
2793 T->getTypeQuals());
2794 if (Result.isNull())
2795 return QualType();
2796 }
Mike Stump1eb44332009-09-09 15:08:12 +00002797
John McCalla2becad2009-10-21 00:40:46 +00002798 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2799 NewTL.setLParenLoc(TL.getLParenLoc());
2800 NewTL.setRParenLoc(TL.getRParenLoc());
2801 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2802 NewTL.setArg(i, ParamDecls[i]);
2803
2804 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002805}
Mike Stump1eb44332009-09-09 15:08:12 +00002806
Douglas Gregor577f75a2009-08-04 16:50:30 +00002807template<typename Derived>
2808QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002809 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002810 FunctionNoProtoTypeLoc TL,
2811 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002812 FunctionNoProtoType *T = TL.getTypePtr();
2813 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2814 if (ResultType.isNull())
2815 return QualType();
2816
2817 QualType Result = TL.getType();
2818 if (getDerived().AlwaysRebuild() ||
2819 ResultType != T->getResultType())
2820 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2821
2822 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2823 NewTL.setLParenLoc(TL.getLParenLoc());
2824 NewTL.setRParenLoc(TL.getRParenLoc());
2825
2826 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002827}
Mike Stump1eb44332009-09-09 15:08:12 +00002828
John McCalled976492009-12-04 22:46:56 +00002829template<typename Derived> QualType
2830TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002831 UnresolvedUsingTypeLoc TL,
2832 QualType ObjectType) {
John McCalled976492009-12-04 22:46:56 +00002833 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002834 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00002835 if (!D)
2836 return QualType();
2837
2838 QualType Result = TL.getType();
2839 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2840 Result = getDerived().RebuildUnresolvedUsingType(D);
2841 if (Result.isNull())
2842 return QualType();
2843 }
2844
2845 // We might get an arbitrary type spec type back. We should at
2846 // least always get a type spec type, though.
2847 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2848 NewTL.setNameLoc(TL.getNameLoc());
2849
2850 return Result;
2851}
2852
Douglas Gregor577f75a2009-08-04 16:50:30 +00002853template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002854QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002855 TypedefTypeLoc TL,
2856 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002857 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002858 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002859 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2860 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002861 if (!Typedef)
2862 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002863
John McCalla2becad2009-10-21 00:40:46 +00002864 QualType Result = TL.getType();
2865 if (getDerived().AlwaysRebuild() ||
2866 Typedef != T->getDecl()) {
2867 Result = getDerived().RebuildTypedefType(Typedef);
2868 if (Result.isNull())
2869 return QualType();
2870 }
Mike Stump1eb44332009-09-09 15:08:12 +00002871
John McCalla2becad2009-10-21 00:40:46 +00002872 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2873 NewTL.setNameLoc(TL.getNameLoc());
2874
2875 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002876}
Mike Stump1eb44332009-09-09 15:08:12 +00002877
Douglas Gregor577f75a2009-08-04 16:50:30 +00002878template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002879QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002880 TypeOfExprTypeLoc TL,
2881 QualType ObjectType) {
Douglas Gregor670444e2009-08-04 22:27:00 +00002882 // typeof expressions are not potentially evaluated contexts
2883 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002884
John McCallcfb708c2010-01-13 20:03:27 +00002885 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002886 if (E.isInvalid())
2887 return QualType();
2888
John McCalla2becad2009-10-21 00:40:46 +00002889 QualType Result = TL.getType();
2890 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00002891 E.get() != TL.getUnderlyingExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002892 Result = getDerived().RebuildTypeOfExprType(move(E));
2893 if (Result.isNull())
2894 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002895 }
John McCalla2becad2009-10-21 00:40:46 +00002896 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002897
John McCalla2becad2009-10-21 00:40:46 +00002898 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002899 NewTL.setTypeofLoc(TL.getTypeofLoc());
2900 NewTL.setLParenLoc(TL.getLParenLoc());
2901 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00002902
2903 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002904}
Mike Stump1eb44332009-09-09 15:08:12 +00002905
2906template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002907QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002908 TypeOfTypeLoc TL,
2909 QualType ObjectType) {
John McCallcfb708c2010-01-13 20:03:27 +00002910 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2911 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2912 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00002913 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002914
John McCalla2becad2009-10-21 00:40:46 +00002915 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00002916 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2917 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00002918 if (Result.isNull())
2919 return QualType();
2920 }
Mike Stump1eb44332009-09-09 15:08:12 +00002921
John McCalla2becad2009-10-21 00:40:46 +00002922 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002923 NewTL.setTypeofLoc(TL.getTypeofLoc());
2924 NewTL.setLParenLoc(TL.getLParenLoc());
2925 NewTL.setRParenLoc(TL.getRParenLoc());
2926 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00002927
2928 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002929}
Mike Stump1eb44332009-09-09 15:08:12 +00002930
2931template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002932QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002933 DecltypeTypeLoc TL,
2934 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002935 DecltypeType *T = TL.getTypePtr();
2936
Douglas Gregor670444e2009-08-04 22:27:00 +00002937 // decltype expressions are not potentially evaluated contexts
2938 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002939
Douglas Gregor577f75a2009-08-04 16:50:30 +00002940 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2941 if (E.isInvalid())
2942 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002943
John McCalla2becad2009-10-21 00:40:46 +00002944 QualType Result = TL.getType();
2945 if (getDerived().AlwaysRebuild() ||
2946 E.get() != T->getUnderlyingExpr()) {
2947 Result = getDerived().RebuildDecltypeType(move(E));
2948 if (Result.isNull())
2949 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002950 }
John McCalla2becad2009-10-21 00:40:46 +00002951 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002952
John McCalla2becad2009-10-21 00:40:46 +00002953 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2954 NewTL.setNameLoc(TL.getNameLoc());
2955
2956 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002957}
2958
2959template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002960QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002961 RecordTypeLoc TL,
2962 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002963 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002964 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002965 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2966 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002967 if (!Record)
2968 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002969
John McCalla2becad2009-10-21 00:40:46 +00002970 QualType Result = TL.getType();
2971 if (getDerived().AlwaysRebuild() ||
2972 Record != T->getDecl()) {
2973 Result = getDerived().RebuildRecordType(Record);
2974 if (Result.isNull())
2975 return QualType();
2976 }
Mike Stump1eb44332009-09-09 15:08:12 +00002977
John McCalla2becad2009-10-21 00:40:46 +00002978 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2979 NewTL.setNameLoc(TL.getNameLoc());
2980
2981 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002982}
Mike Stump1eb44332009-09-09 15:08:12 +00002983
2984template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002985QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002986 EnumTypeLoc TL,
2987 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002988 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002989 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002990 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2991 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002992 if (!Enum)
2993 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002994
John McCalla2becad2009-10-21 00:40:46 +00002995 QualType Result = TL.getType();
2996 if (getDerived().AlwaysRebuild() ||
2997 Enum != T->getDecl()) {
2998 Result = getDerived().RebuildEnumType(Enum);
2999 if (Result.isNull())
3000 return QualType();
3001 }
Mike Stump1eb44332009-09-09 15:08:12 +00003002
John McCalla2becad2009-10-21 00:40:46 +00003003 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3004 NewTL.setNameLoc(TL.getNameLoc());
3005
3006 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003007}
John McCall7da24312009-09-05 00:15:47 +00003008
3009template <typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003010QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003011 ElaboratedTypeLoc TL,
3012 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003013 ElaboratedType *T = TL.getTypePtr();
3014
3015 // FIXME: this should be a nested type.
John McCall7da24312009-09-05 00:15:47 +00003016 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
3017 if (Underlying.isNull())
3018 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003019
John McCalla2becad2009-10-21 00:40:46 +00003020 QualType Result = TL.getType();
3021 if (getDerived().AlwaysRebuild() ||
3022 Underlying != T->getUnderlyingType()) {
3023 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
3024 if (Result.isNull())
3025 return QualType();
3026 }
Mike Stump1eb44332009-09-09 15:08:12 +00003027
John McCalla2becad2009-10-21 00:40:46 +00003028 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3029 NewTL.setNameLoc(TL.getNameLoc());
3030
3031 return Result;
John McCall7da24312009-09-05 00:15:47 +00003032}
Mike Stump1eb44332009-09-09 15:08:12 +00003033
John McCall3cb0ebd2010-03-10 03:28:59 +00003034template<typename Derived>
3035QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3036 TypeLocBuilder &TLB,
3037 InjectedClassNameTypeLoc TL,
3038 QualType ObjectType) {
3039 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3040 TL.getTypePtr()->getDecl());
3041 if (!D) return QualType();
3042
3043 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3044 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3045 return T;
3046}
3047
Mike Stump1eb44332009-09-09 15:08:12 +00003048
Douglas Gregor577f75a2009-08-04 16:50:30 +00003049template<typename Derived>
3050QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003051 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003052 TemplateTypeParmTypeLoc TL,
3053 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003054 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003055}
3056
Mike Stump1eb44332009-09-09 15:08:12 +00003057template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003058QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003059 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003060 SubstTemplateTypeParmTypeLoc TL,
3061 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003062 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003063}
3064
3065template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003066QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3067 const TemplateSpecializationType *TST,
3068 QualType ObjectType) {
3069 // FIXME: this entire method is a temporary workaround; callers
3070 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00003071
John McCall833ca992009-10-29 08:12:44 +00003072 // Fake up a TemplateSpecializationTypeLoc.
3073 TypeLocBuilder TLB;
3074 TemplateSpecializationTypeLoc TL
3075 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3076
John McCall828bff22009-10-29 18:45:58 +00003077 SourceLocation BaseLoc = getDerived().getBaseLocation();
3078
3079 TL.setTemplateNameLoc(BaseLoc);
3080 TL.setLAngleLoc(BaseLoc);
3081 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00003082 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3083 const TemplateArgument &TA = TST->getArg(i);
3084 TemplateArgumentLoc TAL;
3085 getDerived().InventTemplateArgumentLoc(TA, TAL);
3086 TL.setArgLocInfo(i, TAL.getLocInfo());
3087 }
3088
3089 TypeLocBuilder IgnoredTLB;
3090 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00003091}
3092
3093template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003094QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003095 TypeLocBuilder &TLB,
3096 TemplateSpecializationTypeLoc TL,
3097 QualType ObjectType) {
3098 const TemplateSpecializationType *T = TL.getTypePtr();
3099
Mike Stump1eb44332009-09-09 15:08:12 +00003100 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00003101 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003102 if (Template.isNull())
3103 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003104
John McCalld5532b62009-11-23 01:53:49 +00003105 TemplateArgumentListInfo NewTemplateArgs;
3106 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3107 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3108
3109 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3110 TemplateArgumentLoc Loc;
3111 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00003112 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00003113 NewTemplateArgs.addArgument(Loc);
3114 }
Mike Stump1eb44332009-09-09 15:08:12 +00003115
John McCall833ca992009-10-29 08:12:44 +00003116 // FIXME: maybe don't rebuild if all the template arguments are the same.
3117
3118 QualType Result =
3119 getDerived().RebuildTemplateSpecializationType(Template,
3120 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003121 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003122
3123 if (!Result.isNull()) {
3124 TemplateSpecializationTypeLoc NewTL
3125 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3126 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3127 NewTL.setLAngleLoc(TL.getLAngleLoc());
3128 NewTL.setRAngleLoc(TL.getRAngleLoc());
3129 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3130 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003131 }
Mike Stump1eb44332009-09-09 15:08:12 +00003132
John McCall833ca992009-10-29 08:12:44 +00003133 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003134}
Mike Stump1eb44332009-09-09 15:08:12 +00003135
3136template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003137QualType
3138TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003139 QualifiedNameTypeLoc TL,
3140 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003141 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003142 NestedNameSpecifier *NNS
3143 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00003144 SourceRange(),
3145 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003146 if (!NNS)
3147 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003148
Douglas Gregor577f75a2009-08-04 16:50:30 +00003149 QualType Named = getDerived().TransformType(T->getNamedType());
3150 if (Named.isNull())
3151 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003152
John McCalla2becad2009-10-21 00:40:46 +00003153 QualType Result = TL.getType();
3154 if (getDerived().AlwaysRebuild() ||
3155 NNS != T->getQualifier() ||
3156 Named != T->getNamedType()) {
3157 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
3158 if (Result.isNull())
3159 return QualType();
3160 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003161
John McCalla2becad2009-10-21 00:40:46 +00003162 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
3163 NewTL.setNameLoc(TL.getNameLoc());
3164
3165 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003166}
Mike Stump1eb44332009-09-09 15:08:12 +00003167
3168template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003169QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3170 DependentNameTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00003171 QualType ObjectType) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003172 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003173
3174 /* FIXME: preserve source information better than this */
3175 SourceRange SR(TL.getNameLoc());
3176
Douglas Gregor577f75a2009-08-04 16:50:30 +00003177 NestedNameSpecifier *NNS
Douglas Gregor124b8782010-02-16 19:09:40 +00003178 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregoredc90502010-02-25 04:46:04 +00003179 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003180 if (!NNS)
3181 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003182
John McCalla2becad2009-10-21 00:40:46 +00003183 QualType Result;
3184
Douglas Gregor577f75a2009-08-04 16:50:30 +00003185 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump1eb44332009-09-09 15:08:12 +00003186 QualType NewTemplateId
Douglas Gregor577f75a2009-08-04 16:50:30 +00003187 = getDerived().TransformType(QualType(TemplateId, 0));
3188 if (NewTemplateId.isNull())
3189 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003190
Douglas Gregor577f75a2009-08-04 16:50:30 +00003191 if (!getDerived().AlwaysRebuild() &&
3192 NNS == T->getQualifier() &&
3193 NewTemplateId == QualType(TemplateId, 0))
3194 return QualType(T, 0);
Mike Stump1eb44332009-09-09 15:08:12 +00003195
Douglas Gregor4a2023f2010-03-31 20:19:30 +00003196 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3197 NewTemplateId);
John McCalla2becad2009-10-21 00:40:46 +00003198 } else {
Douglas Gregor4a2023f2010-03-31 20:19:30 +00003199 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3200 T->getIdentifier(), SR);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003201 }
John McCalla2becad2009-10-21 00:40:46 +00003202 if (Result.isNull())
3203 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003204
Douglas Gregor4714c122010-03-31 17:34:00 +00003205 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003206 NewTL.setNameLoc(TL.getNameLoc());
3207
3208 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003209}
Mike Stump1eb44332009-09-09 15:08:12 +00003210
Douglas Gregor577f75a2009-08-04 16:50:30 +00003211template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003212QualType
3213TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003214 ObjCInterfaceTypeLoc TL,
3215 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003216 // ObjCInterfaceType is never dependent.
3217 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003218}
Mike Stump1eb44332009-09-09 15:08:12 +00003219
3220template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003221QualType
3222TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003223 ObjCObjectPointerTypeLoc TL,
3224 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003225 // ObjCObjectPointerType is never dependent.
3226 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003227}
3228
Douglas Gregor577f75a2009-08-04 16:50:30 +00003229//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003230// Statement transformation
3231//===----------------------------------------------------------------------===//
3232template<typename Derived>
3233Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003234TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3235 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003236}
3237
3238template<typename Derived>
3239Sema::OwningStmtResult
3240TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3241 return getDerived().TransformCompoundStmt(S, false);
3242}
3243
3244template<typename Derived>
3245Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003246TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003247 bool IsStmtExpr) {
3248 bool SubStmtChanged = false;
3249 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3250 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3251 B != BEnd; ++B) {
3252 OwningStmtResult Result = getDerived().TransformStmt(*B);
3253 if (Result.isInvalid())
3254 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003255
Douglas Gregor43959a92009-08-20 07:17:43 +00003256 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3257 Statements.push_back(Result.takeAs<Stmt>());
3258 }
Mike Stump1eb44332009-09-09 15:08:12 +00003259
Douglas Gregor43959a92009-08-20 07:17:43 +00003260 if (!getDerived().AlwaysRebuild() &&
3261 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003262 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003263
3264 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3265 move_arg(Statements),
3266 S->getRBracLoc(),
3267 IsStmtExpr);
3268}
Mike Stump1eb44332009-09-09 15:08:12 +00003269
Douglas Gregor43959a92009-08-20 07:17:43 +00003270template<typename Derived>
3271Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003272TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman264c1f82009-11-19 03:14:00 +00003273 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3274 {
3275 // The case value expressions are not potentially evaluated.
3276 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003277
Eli Friedman264c1f82009-11-19 03:14:00 +00003278 // Transform the left-hand case value.
3279 LHS = getDerived().TransformExpr(S->getLHS());
3280 if (LHS.isInvalid())
3281 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003282
Eli Friedman264c1f82009-11-19 03:14:00 +00003283 // Transform the right-hand case value (for the GNU case-range extension).
3284 RHS = getDerived().TransformExpr(S->getRHS());
3285 if (RHS.isInvalid())
3286 return SemaRef.StmtError();
3287 }
Mike Stump1eb44332009-09-09 15:08:12 +00003288
Douglas Gregor43959a92009-08-20 07:17:43 +00003289 // Build the case statement.
3290 // Case statements are always rebuilt so that they will attached to their
3291 // transformed switch statement.
3292 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3293 move(LHS),
3294 S->getEllipsisLoc(),
3295 move(RHS),
3296 S->getColonLoc());
3297 if (Case.isInvalid())
3298 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003299
Douglas Gregor43959a92009-08-20 07:17:43 +00003300 // Transform the statement following the case
3301 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3302 if (SubStmt.isInvalid())
3303 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003304
Douglas Gregor43959a92009-08-20 07:17:43 +00003305 // Attach the body to the case statement
3306 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3307}
3308
3309template<typename Derived>
3310Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003311TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003312 // Transform the statement following the default case
3313 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3314 if (SubStmt.isInvalid())
3315 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003316
Douglas Gregor43959a92009-08-20 07:17:43 +00003317 // Default statements are always rebuilt
3318 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3319 move(SubStmt));
3320}
Mike Stump1eb44332009-09-09 15:08:12 +00003321
Douglas Gregor43959a92009-08-20 07:17:43 +00003322template<typename Derived>
3323Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003324TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003325 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3326 if (SubStmt.isInvalid())
3327 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003328
Douglas Gregor43959a92009-08-20 07:17:43 +00003329 // FIXME: Pass the real colon location in.
3330 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3331 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3332 move(SubStmt));
3333}
Mike Stump1eb44332009-09-09 15:08:12 +00003334
Douglas Gregor43959a92009-08-20 07:17:43 +00003335template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003336Sema::OwningStmtResult
3337TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003338 // Transform the condition
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003339 OwningExprResult Cond(SemaRef);
3340 VarDecl *ConditionVar = 0;
3341 if (S->getConditionVariable()) {
3342 ConditionVar
3343 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003344 getDerived().TransformDefinition(
3345 S->getConditionVariable()->getLocation(),
3346 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003347 if (!ConditionVar)
3348 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003349 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003350 Cond = getDerived().TransformExpr(S->getCond());
3351
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003352 if (Cond.isInvalid())
3353 return SemaRef.StmtError();
3354 }
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003355
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003356 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump1eb44332009-09-09 15:08:12 +00003357
Douglas Gregor43959a92009-08-20 07:17:43 +00003358 // Transform the "then" branch.
3359 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3360 if (Then.isInvalid())
3361 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003362
Douglas Gregor43959a92009-08-20 07:17:43 +00003363 // Transform the "else" branch.
3364 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3365 if (Else.isInvalid())
3366 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003367
Douglas Gregor43959a92009-08-20 07:17:43 +00003368 if (!getDerived().AlwaysRebuild() &&
3369 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003370 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003371 Then.get() == S->getThen() &&
3372 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003373 return SemaRef.Owned(S->Retain());
3374
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003375 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3376 move(Then),
Mike Stump1eb44332009-09-09 15:08:12 +00003377 S->getElseLoc(), move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +00003378}
3379
3380template<typename Derived>
3381Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003382TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003383 // Transform the condition.
Douglas Gregord3d53012009-11-24 17:07:59 +00003384 OwningExprResult Cond(SemaRef);
3385 VarDecl *ConditionVar = 0;
3386 if (S->getConditionVariable()) {
3387 ConditionVar
3388 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003389 getDerived().TransformDefinition(
3390 S->getConditionVariable()->getLocation(),
3391 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003392 if (!ConditionVar)
3393 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003394 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003395 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003396
3397 if (Cond.isInvalid())
3398 return SemaRef.StmtError();
3399 }
Mike Stump1eb44332009-09-09 15:08:12 +00003400
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003401 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003402
Douglas Gregor43959a92009-08-20 07:17:43 +00003403 // Rebuild the switch statement.
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003404 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3405 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003406 if (Switch.isInvalid())
3407 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003408
Douglas Gregor43959a92009-08-20 07:17:43 +00003409 // Transform the body of the switch statement.
3410 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3411 if (Body.isInvalid())
3412 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003413
Douglas Gregor43959a92009-08-20 07:17:43 +00003414 // Complete the switch statement.
3415 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3416 move(Body));
3417}
Mike Stump1eb44332009-09-09 15:08:12 +00003418
Douglas Gregor43959a92009-08-20 07:17:43 +00003419template<typename Derived>
3420Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003421TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003422 // Transform the condition
Douglas Gregor5656e142009-11-24 21:15:44 +00003423 OwningExprResult Cond(SemaRef);
3424 VarDecl *ConditionVar = 0;
3425 if (S->getConditionVariable()) {
3426 ConditionVar
3427 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003428 getDerived().TransformDefinition(
3429 S->getConditionVariable()->getLocation(),
3430 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003431 if (!ConditionVar)
3432 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003433 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003434 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003435
3436 if (Cond.isInvalid())
3437 return SemaRef.StmtError();
3438 }
Mike Stump1eb44332009-09-09 15:08:12 +00003439
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003440 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump1eb44332009-09-09 15:08:12 +00003441
Douglas Gregor43959a92009-08-20 07:17:43 +00003442 // Transform the body
3443 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3444 if (Body.isInvalid())
3445 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003446
Douglas Gregor43959a92009-08-20 07:17:43 +00003447 if (!getDerived().AlwaysRebuild() &&
3448 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003449 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003450 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003451 return SemaRef.Owned(S->Retain());
3452
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003453 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3454 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003455}
Mike Stump1eb44332009-09-09 15:08:12 +00003456
Douglas Gregor43959a92009-08-20 07:17:43 +00003457template<typename Derived>
3458Sema::OwningStmtResult
3459TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3460 // Transform the condition
3461 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3462 if (Cond.isInvalid())
3463 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003464
Douglas Gregor43959a92009-08-20 07:17:43 +00003465 // Transform the body
3466 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3467 if (Body.isInvalid())
3468 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003469
Douglas Gregor43959a92009-08-20 07:17:43 +00003470 if (!getDerived().AlwaysRebuild() &&
3471 Cond.get() == S->getCond() &&
3472 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003473 return SemaRef.Owned(S->Retain());
3474
Douglas Gregor43959a92009-08-20 07:17:43 +00003475 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3476 /*FIXME:*/S->getWhileLoc(), move(Cond),
3477 S->getRParenLoc());
3478}
Mike Stump1eb44332009-09-09 15:08:12 +00003479
Douglas Gregor43959a92009-08-20 07:17:43 +00003480template<typename Derived>
3481Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003482TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003483 // Transform the initialization statement
3484 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3485 if (Init.isInvalid())
3486 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003487
Douglas Gregor43959a92009-08-20 07:17:43 +00003488 // Transform the condition
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003489 OwningExprResult Cond(SemaRef);
3490 VarDecl *ConditionVar = 0;
3491 if (S->getConditionVariable()) {
3492 ConditionVar
3493 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003494 getDerived().TransformDefinition(
3495 S->getConditionVariable()->getLocation(),
3496 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003497 if (!ConditionVar)
3498 return SemaRef.StmtError();
3499 } else {
3500 Cond = getDerived().TransformExpr(S->getCond());
3501
3502 if (Cond.isInvalid())
3503 return SemaRef.StmtError();
3504 }
Mike Stump1eb44332009-09-09 15:08:12 +00003505
Douglas Gregor43959a92009-08-20 07:17:43 +00003506 // Transform the increment
3507 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3508 if (Inc.isInvalid())
3509 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003510
Douglas Gregor43959a92009-08-20 07:17:43 +00003511 // Transform the body
3512 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3513 if (Body.isInvalid())
3514 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003515
Douglas Gregor43959a92009-08-20 07:17:43 +00003516 if (!getDerived().AlwaysRebuild() &&
3517 Init.get() == S->getInit() &&
3518 Cond.get() == S->getCond() &&
3519 Inc.get() == S->getInc() &&
3520 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003521 return SemaRef.Owned(S->Retain());
3522
Douglas Gregor43959a92009-08-20 07:17:43 +00003523 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003524 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003525 ConditionVar,
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003526 getSema().MakeFullExpr(Inc),
Douglas Gregor43959a92009-08-20 07:17:43 +00003527 S->getRParenLoc(), move(Body));
3528}
3529
3530template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003531Sema::OwningStmtResult
3532TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003533 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003534 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003535 S->getLabel());
3536}
3537
3538template<typename Derived>
3539Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003540TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003541 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3542 if (Target.isInvalid())
3543 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003544
Douglas Gregor43959a92009-08-20 07:17:43 +00003545 if (!getDerived().AlwaysRebuild() &&
3546 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003547 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003548
3549 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3550 move(Target));
3551}
3552
3553template<typename Derived>
3554Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003555TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3556 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003557}
Mike Stump1eb44332009-09-09 15:08:12 +00003558
Douglas Gregor43959a92009-08-20 07:17:43 +00003559template<typename Derived>
3560Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003561TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3562 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003563}
Mike Stump1eb44332009-09-09 15:08:12 +00003564
Douglas Gregor43959a92009-08-20 07:17:43 +00003565template<typename Derived>
3566Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003567TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003568 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3569 if (Result.isInvalid())
3570 return SemaRef.StmtError();
3571
Mike Stump1eb44332009-09-09 15:08:12 +00003572 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003573 // to tell whether the return type of the function has changed.
3574 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3575}
Mike Stump1eb44332009-09-09 15:08:12 +00003576
Douglas Gregor43959a92009-08-20 07:17:43 +00003577template<typename Derived>
3578Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003579TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003580 bool DeclChanged = false;
3581 llvm::SmallVector<Decl *, 4> Decls;
3582 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3583 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003584 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3585 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003586 if (!Transformed)
3587 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003588
Douglas Gregor43959a92009-08-20 07:17:43 +00003589 if (Transformed != *D)
3590 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003591
Douglas Gregor43959a92009-08-20 07:17:43 +00003592 Decls.push_back(Transformed);
3593 }
Mike Stump1eb44332009-09-09 15:08:12 +00003594
Douglas Gregor43959a92009-08-20 07:17:43 +00003595 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003596 return SemaRef.Owned(S->Retain());
3597
3598 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003599 S->getStartLoc(), S->getEndLoc());
3600}
Mike Stump1eb44332009-09-09 15:08:12 +00003601
Douglas Gregor43959a92009-08-20 07:17:43 +00003602template<typename Derived>
3603Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003604TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003605 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003606 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003607}
3608
3609template<typename Derived>
3610Sema::OwningStmtResult
3611TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlsson703e3942010-01-24 05:50:09 +00003612
3613 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3614 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003615 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003616
Anders Carlsson703e3942010-01-24 05:50:09 +00003617 OwningExprResult AsmString(SemaRef);
3618 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3619
3620 bool ExprsChanged = false;
3621
3622 // Go through the outputs.
3623 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003624 Names.push_back(S->getOutputIdentifier(I));
Anders Carlssona5a79f72010-01-30 20:05:21 +00003625
Anders Carlsson703e3942010-01-24 05:50:09 +00003626 // No need to transform the constraint literal.
3627 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3628
3629 // Transform the output expr.
3630 Expr *OutputExpr = S->getOutputExpr(I);
3631 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3632 if (Result.isInvalid())
3633 return SemaRef.StmtError();
3634
3635 ExprsChanged |= Result.get() != OutputExpr;
3636
3637 Exprs.push_back(Result.takeAs<Expr>());
3638 }
3639
3640 // Go through the inputs.
3641 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003642 Names.push_back(S->getInputIdentifier(I));
Anders Carlssona5a79f72010-01-30 20:05:21 +00003643
Anders Carlsson703e3942010-01-24 05:50:09 +00003644 // No need to transform the constraint literal.
3645 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3646
3647 // Transform the input expr.
3648 Expr *InputExpr = S->getInputExpr(I);
3649 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3650 if (Result.isInvalid())
3651 return SemaRef.StmtError();
3652
3653 ExprsChanged |= Result.get() != InputExpr;
3654
3655 Exprs.push_back(Result.takeAs<Expr>());
3656 }
3657
3658 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3659 return SemaRef.Owned(S->Retain());
3660
3661 // Go through the clobbers.
3662 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3663 Clobbers.push_back(S->getClobber(I)->Retain());
3664
3665 // No need to transform the asm string literal.
3666 AsmString = SemaRef.Owned(S->getAsmString());
3667
3668 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3669 S->isSimple(),
3670 S->isVolatile(),
3671 S->getNumOutputs(),
3672 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003673 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003674 move_arg(Constraints),
3675 move_arg(Exprs),
3676 move(AsmString),
3677 move_arg(Clobbers),
3678 S->getRParenLoc(),
3679 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003680}
3681
3682
3683template<typename Derived>
3684Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003685TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003686 // Transform the body of the @try.
3687 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3688 if (TryBody.isInvalid())
3689 return SemaRef.StmtError();
3690
3691 // Transform the @catch statement (if present).
3692 OwningStmtResult Catch(SemaRef);
3693 if (S->getCatchStmts()) {
3694 Catch = getDerived().TransformStmt(S->getCatchStmts());
3695 if (Catch.isInvalid())
3696 return SemaRef.StmtError();
3697 }
3698
3699 // Transform the @finally statement (if present).
3700 OwningStmtResult Finally(SemaRef);
3701 if (S->getFinallyStmt()) {
3702 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3703 if (Finally.isInvalid())
3704 return SemaRef.StmtError();
3705 }
3706
3707 // If nothing changed, just retain this statement.
3708 if (!getDerived().AlwaysRebuild() &&
3709 TryBody.get() == S->getTryBody() &&
3710 Catch.get() == S->getCatchStmts() &&
3711 Finally.get() == S->getFinallyStmt())
3712 return SemaRef.Owned(S->Retain());
3713
3714 // Build a new statement.
3715 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
3716 move(Catch), move(Finally));
Douglas Gregor43959a92009-08-20 07:17:43 +00003717}
Mike Stump1eb44332009-09-09 15:08:12 +00003718
Douglas Gregor43959a92009-08-20 07:17:43 +00003719template<typename Derived>
3720Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003721TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003722 // FIXME: Implement this
3723 assert(false && "Cannot transform an Objective-C @catch statement");
3724 return SemaRef.Owned(S->Retain());
3725}
Mike Stump1eb44332009-09-09 15:08:12 +00003726
Douglas Gregor43959a92009-08-20 07:17:43 +00003727template<typename Derived>
3728Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003729TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003730 // Transform the body.
3731 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
3732 if (Body.isInvalid())
3733 return SemaRef.StmtError();
3734
3735 // If nothing changed, just retain this statement.
3736 if (!getDerived().AlwaysRebuild() &&
3737 Body.get() == S->getFinallyBody())
3738 return SemaRef.Owned(S->Retain());
3739
3740 // Build a new statement.
3741 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
3742 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003743}
Mike Stump1eb44332009-09-09 15:08:12 +00003744
Douglas Gregor43959a92009-08-20 07:17:43 +00003745template<typename Derived>
3746Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003747TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregord1377b22010-04-22 21:44:01 +00003748 OwningExprResult Operand(SemaRef);
3749 if (S->getThrowExpr()) {
3750 Operand = getDerived().TransformExpr(S->getThrowExpr());
3751 if (Operand.isInvalid())
3752 return getSema().StmtError();
3753 }
3754
3755 if (!getDerived().AlwaysRebuild() &&
3756 Operand.get() == S->getThrowExpr())
3757 return getSema().Owned(S->Retain());
3758
3759 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregor43959a92009-08-20 07:17:43 +00003760}
Mike Stump1eb44332009-09-09 15:08:12 +00003761
Douglas Gregor43959a92009-08-20 07:17:43 +00003762template<typename Derived>
3763Sema::OwningStmtResult
3764TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003765 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00003766 // Transform the object we are locking.
3767 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
3768 if (Object.isInvalid())
3769 return SemaRef.StmtError();
3770
3771 // Transform the body.
3772 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
3773 if (Body.isInvalid())
3774 return SemaRef.StmtError();
3775
3776 // If nothing change, just retain the current statement.
3777 if (!getDerived().AlwaysRebuild() &&
3778 Object.get() == S->getSynchExpr() &&
3779 Body.get() == S->getSynchBody())
3780 return SemaRef.Owned(S->Retain());
3781
3782 // Build a new statement.
3783 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
3784 move(Object), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003785}
3786
3787template<typename Derived>
3788Sema::OwningStmtResult
3789TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003790 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00003791 // Transform the element statement.
3792 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
3793 if (Element.isInvalid())
3794 return SemaRef.StmtError();
3795
3796 // Transform the collection expression.
3797 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
3798 if (Collection.isInvalid())
3799 return SemaRef.StmtError();
3800
3801 // Transform the body.
3802 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3803 if (Body.isInvalid())
3804 return SemaRef.StmtError();
3805
3806 // If nothing changed, just retain this statement.
3807 if (!getDerived().AlwaysRebuild() &&
3808 Element.get() == S->getElement() &&
3809 Collection.get() == S->getCollection() &&
3810 Body.get() == S->getBody())
3811 return SemaRef.Owned(S->Retain());
3812
3813 // Build a new statement.
3814 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
3815 /*FIXME:*/S->getForLoc(),
3816 move(Element),
3817 move(Collection),
3818 S->getRParenLoc(),
3819 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003820}
3821
3822
3823template<typename Derived>
3824Sema::OwningStmtResult
3825TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3826 // Transform the exception declaration, if any.
3827 VarDecl *Var = 0;
3828 if (S->getExceptionDecl()) {
3829 VarDecl *ExceptionDecl = S->getExceptionDecl();
3830 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3831 ExceptionDecl->getDeclName());
3832
3833 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3834 if (T.isNull())
3835 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003836
Douglas Gregor43959a92009-08-20 07:17:43 +00003837 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3838 T,
John McCalla93c9342009-12-07 02:54:59 +00003839 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003840 ExceptionDecl->getIdentifier(),
3841 ExceptionDecl->getLocation(),
3842 /*FIXME: Inaccurate*/
3843 SourceRange(ExceptionDecl->getLocation()));
3844 if (!Var || Var->isInvalidDecl()) {
3845 if (Var)
3846 Var->Destroy(SemaRef.Context);
3847 return SemaRef.StmtError();
3848 }
3849 }
Mike Stump1eb44332009-09-09 15:08:12 +00003850
Douglas Gregor43959a92009-08-20 07:17:43 +00003851 // Transform the actual exception handler.
3852 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3853 if (Handler.isInvalid()) {
3854 if (Var)
3855 Var->Destroy(SemaRef.Context);
3856 return SemaRef.StmtError();
3857 }
Mike Stump1eb44332009-09-09 15:08:12 +00003858
Douglas Gregor43959a92009-08-20 07:17:43 +00003859 if (!getDerived().AlwaysRebuild() &&
3860 !Var &&
3861 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00003862 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003863
3864 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3865 Var,
3866 move(Handler));
3867}
Mike Stump1eb44332009-09-09 15:08:12 +00003868
Douglas Gregor43959a92009-08-20 07:17:43 +00003869template<typename Derived>
3870Sema::OwningStmtResult
3871TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3872 // Transform the try block itself.
Mike Stump1eb44332009-09-09 15:08:12 +00003873 OwningStmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00003874 = getDerived().TransformCompoundStmt(S->getTryBlock());
3875 if (TryBlock.isInvalid())
3876 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003877
Douglas Gregor43959a92009-08-20 07:17:43 +00003878 // Transform the handlers.
3879 bool HandlerChanged = false;
3880 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3881 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump1eb44332009-09-09 15:08:12 +00003882 OwningStmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00003883 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3884 if (Handler.isInvalid())
3885 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003886
Douglas Gregor43959a92009-08-20 07:17:43 +00003887 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3888 Handlers.push_back(Handler.takeAs<Stmt>());
3889 }
Mike Stump1eb44332009-09-09 15:08:12 +00003890
Douglas Gregor43959a92009-08-20 07:17:43 +00003891 if (!getDerived().AlwaysRebuild() &&
3892 TryBlock.get() == S->getTryBlock() &&
3893 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003894 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003895
3896 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump1eb44332009-09-09 15:08:12 +00003897 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00003898}
Mike Stump1eb44332009-09-09 15:08:12 +00003899
Douglas Gregor43959a92009-08-20 07:17:43 +00003900//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00003901// Expression transformation
3902//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00003903template<typename Derived>
3904Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003905TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003906 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003907}
Mike Stump1eb44332009-09-09 15:08:12 +00003908
3909template<typename Derived>
3910Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003911TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00003912 NestedNameSpecifier *Qualifier = 0;
3913 if (E->getQualifier()) {
3914 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003915 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00003916 if (!Qualifier)
3917 return SemaRef.ExprError();
3918 }
John McCalldbd872f2009-12-08 09:08:17 +00003919
3920 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003921 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
3922 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00003923 if (!ND)
3924 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003925
Douglas Gregora2813ce2009-10-23 18:54:35 +00003926 if (!getDerived().AlwaysRebuild() &&
3927 Qualifier == E->getQualifier() &&
3928 ND == E->getDecl() &&
John McCalldbd872f2009-12-08 09:08:17 +00003929 !E->hasExplicitTemplateArgumentList()) {
3930
3931 // Mark it referenced in the new context regardless.
3932 // FIXME: this is a bit instantiation-specific.
3933 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3934
Mike Stump1eb44332009-09-09 15:08:12 +00003935 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00003936 }
John McCalldbd872f2009-12-08 09:08:17 +00003937
3938 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3939 if (E->hasExplicitTemplateArgumentList()) {
3940 TemplateArgs = &TransArgs;
3941 TransArgs.setLAngleLoc(E->getLAngleLoc());
3942 TransArgs.setRAngleLoc(E->getRAngleLoc());
3943 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3944 TemplateArgumentLoc Loc;
3945 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3946 return SemaRef.ExprError();
3947 TransArgs.addArgument(Loc);
3948 }
3949 }
3950
Douglas Gregora2813ce2009-10-23 18:54:35 +00003951 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCalldbd872f2009-12-08 09:08:17 +00003952 ND, E->getLocation(), TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003953}
Mike Stump1eb44332009-09-09 15:08:12 +00003954
Douglas Gregorb98b1992009-08-11 05:31:07 +00003955template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003956Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003957TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003958 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003959}
Mike Stump1eb44332009-09-09 15:08:12 +00003960
Douglas Gregorb98b1992009-08-11 05:31:07 +00003961template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003962Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003963TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003964 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003965}
Mike Stump1eb44332009-09-09 15:08:12 +00003966
Douglas Gregorb98b1992009-08-11 05:31:07 +00003967template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003968Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003969TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003970 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003971}
Mike Stump1eb44332009-09-09 15:08:12 +00003972
Douglas Gregorb98b1992009-08-11 05:31:07 +00003973template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003974Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003975TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003976 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003977}
Mike Stump1eb44332009-09-09 15:08:12 +00003978
Douglas Gregorb98b1992009-08-11 05:31:07 +00003979template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003980Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003981TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003982 return SemaRef.Owned(E->Retain());
3983}
3984
3985template<typename Derived>
3986Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003987TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003988 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3989 if (SubExpr.isInvalid())
3990 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003991
Douglas Gregorb98b1992009-08-11 05:31:07 +00003992 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003993 return SemaRef.Owned(E->Retain());
3994
3995 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003996 E->getRParen());
3997}
3998
Mike Stump1eb44332009-09-09 15:08:12 +00003999template<typename Derived>
4000Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004001TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4002 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004003 if (SubExpr.isInvalid())
4004 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004005
Douglas Gregorb98b1992009-08-11 05:31:07 +00004006 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004007 return SemaRef.Owned(E->Retain());
4008
Douglas Gregorb98b1992009-08-11 05:31:07 +00004009 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4010 E->getOpcode(),
4011 move(SubExpr));
4012}
Mike Stump1eb44332009-09-09 15:08:12 +00004013
Douglas Gregorb98b1992009-08-11 05:31:07 +00004014template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004015Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004016TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004017 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004018 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004019
John McCalla93c9342009-12-07 02:54:59 +00004020 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004021 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004022 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004023
John McCall5ab75172009-11-04 07:28:41 +00004024 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004025 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004026
John McCall5ab75172009-11-04 07:28:41 +00004027 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004028 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004029 E->getSourceRange());
4030 }
Mike Stump1eb44332009-09-09 15:08:12 +00004031
Douglas Gregorb98b1992009-08-11 05:31:07 +00004032 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00004033 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004034 // C++0x [expr.sizeof]p1:
4035 // The operand is either an expression, which is an unevaluated operand
4036 // [...]
4037 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004038
Douglas Gregorb98b1992009-08-11 05:31:07 +00004039 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4040 if (SubExpr.isInvalid())
4041 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004042
Douglas Gregorb98b1992009-08-11 05:31:07 +00004043 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4044 return SemaRef.Owned(E->Retain());
4045 }
Mike Stump1eb44332009-09-09 15:08:12 +00004046
Douglas Gregorb98b1992009-08-11 05:31:07 +00004047 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4048 E->isSizeOf(),
4049 E->getSourceRange());
4050}
Mike Stump1eb44332009-09-09 15:08:12 +00004051
Douglas Gregorb98b1992009-08-11 05:31:07 +00004052template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004053Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004054TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004055 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4056 if (LHS.isInvalid())
4057 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004058
Douglas Gregorb98b1992009-08-11 05:31:07 +00004059 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4060 if (RHS.isInvalid())
4061 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004062
4063
Douglas Gregorb98b1992009-08-11 05:31:07 +00004064 if (!getDerived().AlwaysRebuild() &&
4065 LHS.get() == E->getLHS() &&
4066 RHS.get() == E->getRHS())
4067 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004068
Douglas Gregorb98b1992009-08-11 05:31:07 +00004069 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4070 /*FIXME:*/E->getLHS()->getLocStart(),
4071 move(RHS),
4072 E->getRBracketLoc());
4073}
Mike Stump1eb44332009-09-09 15:08:12 +00004074
4075template<typename Derived>
4076Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004077TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004078 // Transform the callee.
4079 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4080 if (Callee.isInvalid())
4081 return SemaRef.ExprError();
4082
4083 // Transform arguments.
4084 bool ArgChanged = false;
4085 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4086 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4087 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4088 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4089 if (Arg.isInvalid())
4090 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004091
Douglas Gregorb98b1992009-08-11 05:31:07 +00004092 // FIXME: Wrong source location information for the ','.
4093 FakeCommaLocs.push_back(
4094 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00004095
4096 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004097 Args.push_back(Arg.takeAs<Expr>());
4098 }
Mike Stump1eb44332009-09-09 15:08:12 +00004099
Douglas Gregorb98b1992009-08-11 05:31:07 +00004100 if (!getDerived().AlwaysRebuild() &&
4101 Callee.get() == E->getCallee() &&
4102 !ArgChanged)
4103 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004104
Douglas Gregorb98b1992009-08-11 05:31:07 +00004105 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004106 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004107 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4108 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4109 move_arg(Args),
4110 FakeCommaLocs.data(),
4111 E->getRParenLoc());
4112}
Mike Stump1eb44332009-09-09 15:08:12 +00004113
4114template<typename Derived>
4115Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004116TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004117 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4118 if (Base.isInvalid())
4119 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004120
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004121 NestedNameSpecifier *Qualifier = 0;
4122 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004123 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004124 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004125 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004126 if (Qualifier == 0)
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004127 return SemaRef.ExprError();
4128 }
Mike Stump1eb44332009-09-09 15:08:12 +00004129
Eli Friedmanf595cc42009-12-04 06:40:45 +00004130 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004131 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4132 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004133 if (!Member)
4134 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004135
John McCall6bb80172010-03-30 21:47:33 +00004136 NamedDecl *FoundDecl = E->getFoundDecl();
4137 if (FoundDecl == E->getMemberDecl()) {
4138 FoundDecl = Member;
4139 } else {
4140 FoundDecl = cast_or_null<NamedDecl>(
4141 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4142 if (!FoundDecl)
4143 return SemaRef.ExprError();
4144 }
4145
Douglas Gregorb98b1992009-08-11 05:31:07 +00004146 if (!getDerived().AlwaysRebuild() &&
4147 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004148 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004149 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004150 FoundDecl == E->getFoundDecl() &&
Anders Carlsson1f240322009-12-22 05:24:09 +00004151 !E->hasExplicitTemplateArgumentList()) {
4152
4153 // Mark it referenced in the new context regardless.
4154 // FIXME: this is a bit instantiation-specific.
4155 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00004156 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00004157 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004158
John McCalld5532b62009-11-23 01:53:49 +00004159 TemplateArgumentListInfo TransArgs;
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004160 if (E->hasExplicitTemplateArgumentList()) {
John McCalld5532b62009-11-23 01:53:49 +00004161 TransArgs.setLAngleLoc(E->getLAngleLoc());
4162 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004163 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004164 TemplateArgumentLoc Loc;
4165 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004166 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004167 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004168 }
4169 }
4170
Douglas Gregorb98b1992009-08-11 05:31:07 +00004171 // FIXME: Bogus source location for the operator
4172 SourceLocation FakeOperatorLoc
4173 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4174
John McCallc2233c52010-01-15 08:34:02 +00004175 // FIXME: to do this check properly, we will need to preserve the
4176 // first-qualifier-in-scope here, just in case we had a dependent
4177 // base (and therefore couldn't do the check) and a
4178 // nested-name-qualifier (and therefore could do the lookup).
4179 NamedDecl *FirstQualifierInScope = 0;
4180
Douglas Gregorb98b1992009-08-11 05:31:07 +00004181 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4182 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004183 Qualifier,
4184 E->getQualifierRange(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004185 E->getMemberLoc(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004186 Member,
John McCall6bb80172010-03-30 21:47:33 +00004187 FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00004188 (E->hasExplicitTemplateArgumentList()
4189 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004190 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004191}
Mike Stump1eb44332009-09-09 15:08:12 +00004192
Douglas Gregorb98b1992009-08-11 05:31:07 +00004193template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00004194Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004195TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004196 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4197 if (LHS.isInvalid())
4198 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004199
Douglas Gregorb98b1992009-08-11 05:31:07 +00004200 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4201 if (RHS.isInvalid())
4202 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004203
Douglas Gregorb98b1992009-08-11 05:31:07 +00004204 if (!getDerived().AlwaysRebuild() &&
4205 LHS.get() == E->getLHS() &&
4206 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004207 return SemaRef.Owned(E->Retain());
4208
Douglas Gregorb98b1992009-08-11 05:31:07 +00004209 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4210 move(LHS), move(RHS));
4211}
4212
Mike Stump1eb44332009-09-09 15:08:12 +00004213template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00004214Sema::OwningExprResult
4215TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004216 CompoundAssignOperator *E) {
4217 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004218}
Mike Stump1eb44332009-09-09 15:08:12 +00004219
Douglas Gregorb98b1992009-08-11 05:31:07 +00004220template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004221Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004222TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004223 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4224 if (Cond.isInvalid())
4225 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004226
Douglas Gregorb98b1992009-08-11 05:31:07 +00004227 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4228 if (LHS.isInvalid())
4229 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004230
Douglas Gregorb98b1992009-08-11 05:31:07 +00004231 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4232 if (RHS.isInvalid())
4233 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004234
Douglas Gregorb98b1992009-08-11 05:31:07 +00004235 if (!getDerived().AlwaysRebuild() &&
4236 Cond.get() == E->getCond() &&
4237 LHS.get() == E->getLHS() &&
4238 RHS.get() == E->getRHS())
4239 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004240
4241 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004242 E->getQuestionLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004243 move(LHS),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004244 E->getColonLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004245 move(RHS));
4246}
Mike Stump1eb44332009-09-09 15:08:12 +00004247
4248template<typename Derived>
4249Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004250TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004251 // Implicit casts are eliminated during transformation, since they
4252 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004253 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004254}
Mike Stump1eb44332009-09-09 15:08:12 +00004255
Douglas Gregorb98b1992009-08-11 05:31:07 +00004256template<typename Derived>
4257Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004258TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004259 TypeSourceInfo *OldT;
4260 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004261 {
4262 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004263 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004264 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4265 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004266
John McCall9d125032010-01-15 18:39:57 +00004267 OldT = E->getTypeInfoAsWritten();
4268 NewT = getDerived().TransformType(OldT);
4269 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004270 return SemaRef.ExprError();
4271 }
Mike Stump1eb44332009-09-09 15:08:12 +00004272
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004273 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004274 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004275 if (SubExpr.isInvalid())
4276 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004277
Douglas Gregorb98b1992009-08-11 05:31:07 +00004278 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004279 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004280 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004281 return SemaRef.Owned(E->Retain());
4282
John McCall9d125032010-01-15 18:39:57 +00004283 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4284 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004285 E->getRParenLoc(),
4286 move(SubExpr));
4287}
Mike Stump1eb44332009-09-09 15:08:12 +00004288
Douglas Gregorb98b1992009-08-11 05:31:07 +00004289template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004290Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004291TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004292 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4293 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4294 if (!NewT)
4295 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004296
Douglas Gregorb98b1992009-08-11 05:31:07 +00004297 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4298 if (Init.isInvalid())
4299 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004300
Douglas Gregorb98b1992009-08-11 05:31:07 +00004301 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004302 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004303 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00004304 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004305
John McCall1d7d8d62010-01-19 22:33:45 +00004306 // Note: the expression type doesn't necessarily match the
4307 // type-as-written, but that's okay, because it should always be
4308 // derivable from the initializer.
4309
John McCall42f56b52010-01-18 19:35:47 +00004310 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004311 /*FIXME:*/E->getInitializer()->getLocEnd(),
4312 move(Init));
4313}
Mike Stump1eb44332009-09-09 15:08:12 +00004314
Douglas Gregorb98b1992009-08-11 05:31:07 +00004315template<typename Derived>
4316Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004317TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004318 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4319 if (Base.isInvalid())
4320 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004321
Douglas Gregorb98b1992009-08-11 05:31:07 +00004322 if (!getDerived().AlwaysRebuild() &&
4323 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00004324 return SemaRef.Owned(E->Retain());
4325
Douglas Gregorb98b1992009-08-11 05:31:07 +00004326 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004327 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004328 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4329 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4330 E->getAccessorLoc(),
4331 E->getAccessor());
4332}
Mike Stump1eb44332009-09-09 15:08:12 +00004333
Douglas Gregorb98b1992009-08-11 05:31:07 +00004334template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004335Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004336TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004337 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004338
Douglas Gregorb98b1992009-08-11 05:31:07 +00004339 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4340 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4341 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4342 if (Init.isInvalid())
4343 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004344
Douglas Gregorb98b1992009-08-11 05:31:07 +00004345 InitChanged = InitChanged || Init.get() != E->getInit(I);
4346 Inits.push_back(Init.takeAs<Expr>());
4347 }
Mike Stump1eb44332009-09-09 15:08:12 +00004348
Douglas Gregorb98b1992009-08-11 05:31:07 +00004349 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004350 return SemaRef.Owned(E->Retain());
4351
Douglas Gregorb98b1992009-08-11 05:31:07 +00004352 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004353 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004354}
Mike Stump1eb44332009-09-09 15:08:12 +00004355
Douglas Gregorb98b1992009-08-11 05:31:07 +00004356template<typename Derived>
4357Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004358TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004359 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004360
Douglas Gregor43959a92009-08-20 07:17:43 +00004361 // transform the initializer value
Douglas Gregorb98b1992009-08-11 05:31:07 +00004362 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4363 if (Init.isInvalid())
4364 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004365
Douglas Gregor43959a92009-08-20 07:17:43 +00004366 // transform the designators.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004367 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4368 bool ExprChanged = false;
4369 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4370 DEnd = E->designators_end();
4371 D != DEnd; ++D) {
4372 if (D->isFieldDesignator()) {
4373 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4374 D->getDotLoc(),
4375 D->getFieldLoc()));
4376 continue;
4377 }
Mike Stump1eb44332009-09-09 15:08:12 +00004378
Douglas Gregorb98b1992009-08-11 05:31:07 +00004379 if (D->isArrayDesignator()) {
4380 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4381 if (Index.isInvalid())
4382 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004383
4384 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004385 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004386
Douglas Gregorb98b1992009-08-11 05:31:07 +00004387 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4388 ArrayExprs.push_back(Index.release());
4389 continue;
4390 }
Mike Stump1eb44332009-09-09 15:08:12 +00004391
Douglas Gregorb98b1992009-08-11 05:31:07 +00004392 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump1eb44332009-09-09 15:08:12 +00004393 OwningExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004394 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4395 if (Start.isInvalid())
4396 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004397
Douglas Gregorb98b1992009-08-11 05:31:07 +00004398 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4399 if (End.isInvalid())
4400 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004401
4402 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004403 End.get(),
4404 D->getLBracketLoc(),
4405 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004406
Douglas Gregorb98b1992009-08-11 05:31:07 +00004407 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4408 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004409
Douglas Gregorb98b1992009-08-11 05:31:07 +00004410 ArrayExprs.push_back(Start.release());
4411 ArrayExprs.push_back(End.release());
4412 }
Mike Stump1eb44332009-09-09 15:08:12 +00004413
Douglas Gregorb98b1992009-08-11 05:31:07 +00004414 if (!getDerived().AlwaysRebuild() &&
4415 Init.get() == E->getInit() &&
4416 !ExprChanged)
4417 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004418
Douglas Gregorb98b1992009-08-11 05:31:07 +00004419 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4420 E->getEqualOrColonLoc(),
4421 E->usesGNUSyntax(), move(Init));
4422}
Mike Stump1eb44332009-09-09 15:08:12 +00004423
Douglas Gregorb98b1992009-08-11 05:31:07 +00004424template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004425Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004426TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004427 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004428 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4429
4430 // FIXME: Will we ever have proper type location here? Will we actually
4431 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004432 QualType T = getDerived().TransformType(E->getType());
4433 if (T.isNull())
4434 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004435
Douglas Gregorb98b1992009-08-11 05:31:07 +00004436 if (!getDerived().AlwaysRebuild() &&
4437 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004438 return SemaRef.Owned(E->Retain());
4439
Douglas Gregorb98b1992009-08-11 05:31:07 +00004440 return getDerived().RebuildImplicitValueInitExpr(T);
4441}
Mike Stump1eb44332009-09-09 15:08:12 +00004442
Douglas Gregorb98b1992009-08-11 05:31:07 +00004443template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004444Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004445TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004446 // FIXME: Do we want the type as written?
4447 QualType T;
Mike Stump1eb44332009-09-09 15:08:12 +00004448
Douglas Gregorb98b1992009-08-11 05:31:07 +00004449 {
4450 // FIXME: Source location isn't quite accurate.
4451 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4452 T = getDerived().TransformType(E->getType());
4453 if (T.isNull())
4454 return SemaRef.ExprError();
4455 }
Mike Stump1eb44332009-09-09 15:08:12 +00004456
Douglas Gregorb98b1992009-08-11 05:31:07 +00004457 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4458 if (SubExpr.isInvalid())
4459 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004460
Douglas Gregorb98b1992009-08-11 05:31:07 +00004461 if (!getDerived().AlwaysRebuild() &&
4462 T == E->getType() &&
4463 SubExpr.get() == E->getSubExpr())
4464 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004465
Douglas Gregorb98b1992009-08-11 05:31:07 +00004466 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4467 T, E->getRParenLoc());
4468}
4469
4470template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004471Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004472TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004473 bool ArgumentChanged = false;
4474 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4475 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4476 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4477 if (Init.isInvalid())
4478 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004479
Douglas Gregorb98b1992009-08-11 05:31:07 +00004480 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4481 Inits.push_back(Init.takeAs<Expr>());
4482 }
Mike Stump1eb44332009-09-09 15:08:12 +00004483
Douglas Gregorb98b1992009-08-11 05:31:07 +00004484 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4485 move_arg(Inits),
4486 E->getRParenLoc());
4487}
Mike Stump1eb44332009-09-09 15:08:12 +00004488
Douglas Gregorb98b1992009-08-11 05:31:07 +00004489/// \brief Transform an address-of-label expression.
4490///
4491/// By default, the transformation of an address-of-label expression always
4492/// rebuilds the expression, so that the label identifier can be resolved to
4493/// the corresponding label statement by semantic analysis.
4494template<typename Derived>
4495Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004496TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004497 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4498 E->getLabel());
4499}
Mike Stump1eb44332009-09-09 15:08:12 +00004500
4501template<typename Derived>
Douglas Gregorc86a6e92009-11-04 07:01:15 +00004502Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004503TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004504 OwningStmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004505 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4506 if (SubStmt.isInvalid())
4507 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004508
Douglas Gregorb98b1992009-08-11 05:31:07 +00004509 if (!getDerived().AlwaysRebuild() &&
4510 SubStmt.get() == E->getSubStmt())
4511 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004512
4513 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004514 move(SubStmt),
4515 E->getRParenLoc());
4516}
Mike Stump1eb44332009-09-09 15:08:12 +00004517
Douglas Gregorb98b1992009-08-11 05:31:07 +00004518template<typename Derived>
4519Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004520TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004521 QualType T1, T2;
4522 {
4523 // FIXME: Source location isn't quite accurate.
4524 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004525
Douglas Gregorb98b1992009-08-11 05:31:07 +00004526 T1 = getDerived().TransformType(E->getArgType1());
4527 if (T1.isNull())
4528 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004529
Douglas Gregorb98b1992009-08-11 05:31:07 +00004530 T2 = getDerived().TransformType(E->getArgType2());
4531 if (T2.isNull())
4532 return SemaRef.ExprError();
4533 }
4534
4535 if (!getDerived().AlwaysRebuild() &&
4536 T1 == E->getArgType1() &&
4537 T2 == E->getArgType2())
Mike Stump1eb44332009-09-09 15:08:12 +00004538 return SemaRef.Owned(E->Retain());
4539
Douglas Gregorb98b1992009-08-11 05:31:07 +00004540 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4541 T1, T2, E->getRParenLoc());
4542}
Mike Stump1eb44332009-09-09 15:08:12 +00004543
Douglas Gregorb98b1992009-08-11 05:31:07 +00004544template<typename Derived>
4545Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004546TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004547 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4548 if (Cond.isInvalid())
4549 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004550
Douglas Gregorb98b1992009-08-11 05:31:07 +00004551 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4552 if (LHS.isInvalid())
4553 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004554
Douglas Gregorb98b1992009-08-11 05:31:07 +00004555 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4556 if (RHS.isInvalid())
4557 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004558
Douglas Gregorb98b1992009-08-11 05:31:07 +00004559 if (!getDerived().AlwaysRebuild() &&
4560 Cond.get() == E->getCond() &&
4561 LHS.get() == E->getLHS() &&
4562 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004563 return SemaRef.Owned(E->Retain());
4564
Douglas Gregorb98b1992009-08-11 05:31:07 +00004565 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4566 move(Cond), move(LHS), move(RHS),
4567 E->getRParenLoc());
4568}
Mike Stump1eb44332009-09-09 15:08:12 +00004569
Douglas Gregorb98b1992009-08-11 05:31:07 +00004570template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004571Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004572TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004573 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004574}
4575
4576template<typename Derived>
4577Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004578TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004579 switch (E->getOperator()) {
4580 case OO_New:
4581 case OO_Delete:
4582 case OO_Array_New:
4583 case OO_Array_Delete:
4584 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4585 return SemaRef.ExprError();
4586
4587 case OO_Call: {
4588 // This is a call to an object's operator().
4589 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4590
4591 // Transform the object itself.
4592 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4593 if (Object.isInvalid())
4594 return SemaRef.ExprError();
4595
4596 // FIXME: Poor location information
4597 SourceLocation FakeLParenLoc
4598 = SemaRef.PP.getLocForEndOfToken(
4599 static_cast<Expr *>(Object.get())->getLocEnd());
4600
4601 // Transform the call arguments.
4602 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4603 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4604 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004605 if (getDerived().DropCallArgument(E->getArg(I)))
4606 break;
4607
Douglas Gregor668d6d92009-12-13 20:44:55 +00004608 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4609 if (Arg.isInvalid())
4610 return SemaRef.ExprError();
4611
4612 // FIXME: Poor source location information.
4613 SourceLocation FakeCommaLoc
4614 = SemaRef.PP.getLocForEndOfToken(
4615 static_cast<Expr *>(Arg.get())->getLocEnd());
4616 FakeCommaLocs.push_back(FakeCommaLoc);
4617 Args.push_back(Arg.release());
4618 }
4619
4620 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4621 move_arg(Args),
4622 FakeCommaLocs.data(),
4623 E->getLocEnd());
4624 }
4625
4626#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4627 case OO_##Name:
4628#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4629#include "clang/Basic/OperatorKinds.def"
4630 case OO_Subscript:
4631 // Handled below.
4632 break;
4633
4634 case OO_Conditional:
4635 llvm_unreachable("conditional operator is not actually overloadable");
4636 return SemaRef.ExprError();
4637
4638 case OO_None:
4639 case NUM_OVERLOADED_OPERATORS:
4640 llvm_unreachable("not an overloaded operator?");
4641 return SemaRef.ExprError();
4642 }
4643
Douglas Gregorb98b1992009-08-11 05:31:07 +00004644 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4645 if (Callee.isInvalid())
4646 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004647
John McCall454feb92009-12-08 09:21:05 +00004648 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004649 if (First.isInvalid())
4650 return SemaRef.ExprError();
4651
4652 OwningExprResult Second(SemaRef);
4653 if (E->getNumArgs() == 2) {
4654 Second = getDerived().TransformExpr(E->getArg(1));
4655 if (Second.isInvalid())
4656 return SemaRef.ExprError();
4657 }
Mike Stump1eb44332009-09-09 15:08:12 +00004658
Douglas Gregorb98b1992009-08-11 05:31:07 +00004659 if (!getDerived().AlwaysRebuild() &&
4660 Callee.get() == E->getCallee() &&
4661 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00004662 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4663 return SemaRef.Owned(E->Retain());
4664
Douglas Gregorb98b1992009-08-11 05:31:07 +00004665 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4666 E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004667 move(Callee),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004668 move(First),
4669 move(Second));
4670}
Mike Stump1eb44332009-09-09 15:08:12 +00004671
Douglas Gregorb98b1992009-08-11 05:31:07 +00004672template<typename Derived>
4673Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004674TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4675 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004676}
Mike Stump1eb44332009-09-09 15:08:12 +00004677
Douglas Gregorb98b1992009-08-11 05:31:07 +00004678template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004679Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004680TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004681 TypeSourceInfo *OldT;
4682 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004683 {
4684 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004685 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004686 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4687 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004688
John McCall9d125032010-01-15 18:39:57 +00004689 OldT = E->getTypeInfoAsWritten();
4690 NewT = getDerived().TransformType(OldT);
4691 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004692 return SemaRef.ExprError();
4693 }
Mike Stump1eb44332009-09-09 15:08:12 +00004694
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004695 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004696 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004697 if (SubExpr.isInvalid())
4698 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004699
Douglas Gregorb98b1992009-08-11 05:31:07 +00004700 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004701 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004702 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004703 return SemaRef.Owned(E->Retain());
4704
Douglas Gregorb98b1992009-08-11 05:31:07 +00004705 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00004706 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004707 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4708 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4709 SourceLocation FakeRParenLoc
4710 = SemaRef.PP.getLocForEndOfToken(
4711 E->getSubExpr()->getSourceRange().getEnd());
4712 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004713 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004714 FakeLAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00004715 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004716 FakeRAngleLoc,
4717 FakeRAngleLoc,
4718 move(SubExpr),
4719 FakeRParenLoc);
4720}
Mike Stump1eb44332009-09-09 15:08:12 +00004721
Douglas Gregorb98b1992009-08-11 05:31:07 +00004722template<typename Derived>
4723Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004724TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4725 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004726}
Mike Stump1eb44332009-09-09 15:08:12 +00004727
4728template<typename Derived>
4729Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004730TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4731 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004732}
4733
Douglas Gregorb98b1992009-08-11 05:31:07 +00004734template<typename Derived>
4735Sema::OwningExprResult
4736TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004737 CXXReinterpretCastExpr *E) {
4738 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004739}
Mike Stump1eb44332009-09-09 15:08:12 +00004740
Douglas Gregorb98b1992009-08-11 05:31:07 +00004741template<typename Derived>
4742Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004743TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4744 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004745}
Mike Stump1eb44332009-09-09 15:08:12 +00004746
Douglas Gregorb98b1992009-08-11 05:31:07 +00004747template<typename Derived>
4748Sema::OwningExprResult
4749TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004750 CXXFunctionalCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004751 TypeSourceInfo *OldT;
4752 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004753 {
4754 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004755
John McCall9d125032010-01-15 18:39:57 +00004756 OldT = E->getTypeInfoAsWritten();
4757 NewT = getDerived().TransformType(OldT);
4758 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004759 return SemaRef.ExprError();
4760 }
Mike Stump1eb44332009-09-09 15:08:12 +00004761
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004762 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004763 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004764 if (SubExpr.isInvalid())
4765 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004766
Douglas Gregorb98b1992009-08-11 05:31:07 +00004767 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004768 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004769 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004770 return SemaRef.Owned(E->Retain());
4771
Douglas Gregorb98b1992009-08-11 05:31:07 +00004772 // FIXME: The end of the type's source range is wrong
4773 return getDerived().RebuildCXXFunctionalCastExpr(
4774 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall9d125032010-01-15 18:39:57 +00004775 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004776 /*FIXME:*/E->getSubExpr()->getLocStart(),
4777 move(SubExpr),
4778 E->getRParenLoc());
4779}
Mike Stump1eb44332009-09-09 15:08:12 +00004780
Douglas Gregorb98b1992009-08-11 05:31:07 +00004781template<typename Derived>
4782Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004783TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004784 if (E->isTypeOperand()) {
4785 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004786
Douglas Gregorb98b1992009-08-11 05:31:07 +00004787 QualType T = getDerived().TransformType(E->getTypeOperand());
4788 if (T.isNull())
4789 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004790
Douglas Gregorb98b1992009-08-11 05:31:07 +00004791 if (!getDerived().AlwaysRebuild() &&
4792 T == E->getTypeOperand())
4793 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004794
Douglas Gregorb98b1992009-08-11 05:31:07 +00004795 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4796 /*FIXME:*/E->getLocStart(),
4797 T,
4798 E->getLocEnd());
4799 }
Mike Stump1eb44332009-09-09 15:08:12 +00004800
Douglas Gregorb98b1992009-08-11 05:31:07 +00004801 // We don't know whether the expression is potentially evaluated until
4802 // after we perform semantic analysis, so the expression is potentially
4803 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00004804 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004805 Action::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004806
Douglas Gregorb98b1992009-08-11 05:31:07 +00004807 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4808 if (SubExpr.isInvalid())
4809 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004810
Douglas Gregorb98b1992009-08-11 05:31:07 +00004811 if (!getDerived().AlwaysRebuild() &&
4812 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00004813 return SemaRef.Owned(E->Retain());
4814
Douglas Gregorb98b1992009-08-11 05:31:07 +00004815 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4816 /*FIXME:*/E->getLocStart(),
4817 move(SubExpr),
4818 E->getLocEnd());
4819}
4820
4821template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004822Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004823TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004824 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004825}
Mike Stump1eb44332009-09-09 15:08:12 +00004826
Douglas Gregorb98b1992009-08-11 05:31:07 +00004827template<typename Derived>
4828Sema::OwningExprResult
4829TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00004830 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004831 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004832}
Mike Stump1eb44332009-09-09 15:08:12 +00004833
Douglas Gregorb98b1992009-08-11 05:31:07 +00004834template<typename Derived>
4835Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004836TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004837 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004838
Douglas Gregorb98b1992009-08-11 05:31:07 +00004839 QualType T = getDerived().TransformType(E->getType());
4840 if (T.isNull())
4841 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004842
Douglas Gregorb98b1992009-08-11 05:31:07 +00004843 if (!getDerived().AlwaysRebuild() &&
4844 T == E->getType())
4845 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004846
Douglas Gregor828a1972010-01-07 23:12:05 +00004847 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004848}
Mike Stump1eb44332009-09-09 15:08:12 +00004849
Douglas Gregorb98b1992009-08-11 05:31:07 +00004850template<typename Derived>
4851Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004852TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004853 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4854 if (SubExpr.isInvalid())
4855 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004856
Douglas Gregorb98b1992009-08-11 05:31:07 +00004857 if (!getDerived().AlwaysRebuild() &&
4858 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004859 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004860
4861 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4862}
Mike Stump1eb44332009-09-09 15:08:12 +00004863
Douglas Gregorb98b1992009-08-11 05:31:07 +00004864template<typename Derived>
4865Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004866TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004867 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004868 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
4869 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004870 if (!Param)
4871 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004872
Chandler Carruth53cb6f82010-02-08 06:42:49 +00004873 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004874 Param == E->getParam())
4875 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004876
Douglas Gregor036aed12009-12-23 23:03:06 +00004877 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004878}
Mike Stump1eb44332009-09-09 15:08:12 +00004879
Douglas Gregorb98b1992009-08-11 05:31:07 +00004880template<typename Derived>
4881Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004882TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004883 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4884
4885 QualType T = getDerived().TransformType(E->getType());
4886 if (T.isNull())
4887 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004888
Douglas Gregorb98b1992009-08-11 05:31:07 +00004889 if (!getDerived().AlwaysRebuild() &&
4890 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004891 return SemaRef.Owned(E->Retain());
4892
4893 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004894 /*FIXME:*/E->getTypeBeginLoc(),
4895 T,
4896 E->getRParenLoc());
4897}
Mike Stump1eb44332009-09-09 15:08:12 +00004898
Douglas Gregorb98b1992009-08-11 05:31:07 +00004899template<typename Derived>
4900Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004901TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004902 // Transform the type that we're allocating
4903 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4904 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4905 if (AllocType.isNull())
4906 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004907
Douglas Gregorb98b1992009-08-11 05:31:07 +00004908 // Transform the size of the array we're allocating (if any).
4909 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4910 if (ArraySize.isInvalid())
4911 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004912
Douglas Gregorb98b1992009-08-11 05:31:07 +00004913 // Transform the placement arguments (if any).
4914 bool ArgumentChanged = false;
4915 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4916 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4917 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4918 if (Arg.isInvalid())
4919 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004920
Douglas Gregorb98b1992009-08-11 05:31:07 +00004921 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4922 PlacementArgs.push_back(Arg.take());
4923 }
Mike Stump1eb44332009-09-09 15:08:12 +00004924
Douglas Gregor43959a92009-08-20 07:17:43 +00004925 // transform the constructor arguments (if any).
Douglas Gregorb98b1992009-08-11 05:31:07 +00004926 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4927 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4928 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4929 if (Arg.isInvalid())
4930 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004931
Douglas Gregorb98b1992009-08-11 05:31:07 +00004932 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4933 ConstructorArgs.push_back(Arg.take());
4934 }
Mike Stump1eb44332009-09-09 15:08:12 +00004935
Douglas Gregor1af74512010-02-26 00:38:10 +00004936 // Transform constructor, new operator, and delete operator.
4937 CXXConstructorDecl *Constructor = 0;
4938 if (E->getConstructor()) {
4939 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004940 getDerived().TransformDecl(E->getLocStart(),
4941 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00004942 if (!Constructor)
4943 return SemaRef.ExprError();
4944 }
4945
4946 FunctionDecl *OperatorNew = 0;
4947 if (E->getOperatorNew()) {
4948 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004949 getDerived().TransformDecl(E->getLocStart(),
4950 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00004951 if (!OperatorNew)
4952 return SemaRef.ExprError();
4953 }
4954
4955 FunctionDecl *OperatorDelete = 0;
4956 if (E->getOperatorDelete()) {
4957 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004958 getDerived().TransformDecl(E->getLocStart(),
4959 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00004960 if (!OperatorDelete)
4961 return SemaRef.ExprError();
4962 }
4963
Douglas Gregorb98b1992009-08-11 05:31:07 +00004964 if (!getDerived().AlwaysRebuild() &&
4965 AllocType == E->getAllocatedType() &&
4966 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00004967 Constructor == E->getConstructor() &&
4968 OperatorNew == E->getOperatorNew() &&
4969 OperatorDelete == E->getOperatorDelete() &&
4970 !ArgumentChanged) {
4971 // Mark any declarations we need as referenced.
4972 // FIXME: instantiation-specific.
4973 if (Constructor)
4974 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
4975 if (OperatorNew)
4976 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
4977 if (OperatorDelete)
4978 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00004979 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00004980 }
Mike Stump1eb44332009-09-09 15:08:12 +00004981
Douglas Gregor5b5ad842009-12-22 17:13:37 +00004982 if (!ArraySize.get()) {
4983 // If no array size was specified, but the new expression was
4984 // instantiated with an array type (e.g., "new T" where T is
4985 // instantiated with "int[4]"), extract the outer bound from the
4986 // array type as our array size. We do this with constant and
4987 // dependently-sized array types.
4988 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4989 if (!ArrayT) {
4990 // Do nothing
4991 } else if (const ConstantArrayType *ConsArrayT
4992 = dyn_cast<ConstantArrayType>(ArrayT)) {
4993 ArraySize
4994 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4995 ConsArrayT->getSize(),
4996 SemaRef.Context.getSizeType(),
4997 /*FIXME:*/E->getLocStart()));
4998 AllocType = ConsArrayT->getElementType();
4999 } else if (const DependentSizedArrayType *DepArrayT
5000 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5001 if (DepArrayT->getSizeExpr()) {
5002 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5003 AllocType = DepArrayT->getElementType();
5004 }
5005 }
5006 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005007 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5008 E->isGlobalNew(),
5009 /*FIXME:*/E->getLocStart(),
5010 move_arg(PlacementArgs),
5011 /*FIXME:*/E->getLocStart(),
5012 E->isParenTypeId(),
5013 AllocType,
5014 /*FIXME:*/E->getLocStart(),
5015 /*FIXME:*/SourceRange(),
5016 move(ArraySize),
5017 /*FIXME:*/E->getLocStart(),
5018 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005019 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005020}
Mike Stump1eb44332009-09-09 15:08:12 +00005021
Douglas Gregorb98b1992009-08-11 05:31:07 +00005022template<typename Derived>
5023Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005024TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005025 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5026 if (Operand.isInvalid())
5027 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005028
Douglas Gregor1af74512010-02-26 00:38:10 +00005029 // Transform the delete operator, if known.
5030 FunctionDecl *OperatorDelete = 0;
5031 if (E->getOperatorDelete()) {
5032 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005033 getDerived().TransformDecl(E->getLocStart(),
5034 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005035 if (!OperatorDelete)
5036 return SemaRef.ExprError();
5037 }
5038
Douglas Gregorb98b1992009-08-11 05:31:07 +00005039 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005040 Operand.get() == E->getArgument() &&
5041 OperatorDelete == E->getOperatorDelete()) {
5042 // Mark any declarations we need as referenced.
5043 // FIXME: instantiation-specific.
5044 if (OperatorDelete)
5045 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005046 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005047 }
Mike Stump1eb44332009-09-09 15:08:12 +00005048
Douglas Gregorb98b1992009-08-11 05:31:07 +00005049 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5050 E->isGlobalDelete(),
5051 E->isArrayForm(),
5052 move(Operand));
5053}
Mike Stump1eb44332009-09-09 15:08:12 +00005054
Douglas Gregorb98b1992009-08-11 05:31:07 +00005055template<typename Derived>
5056Sema::OwningExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005057TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005058 CXXPseudoDestructorExpr *E) {
Douglas Gregora71d8192009-09-04 17:36:40 +00005059 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5060 if (Base.isInvalid())
5061 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005062
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005063 Sema::TypeTy *ObjectTypePtr = 0;
5064 bool MayBePseudoDestructor = false;
5065 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5066 E->getOperatorLoc(),
5067 E->isArrow()? tok::arrow : tok::period,
5068 ObjectTypePtr,
5069 MayBePseudoDestructor);
5070 if (Base.isInvalid())
5071 return SemaRef.ExprError();
5072
5073 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregora71d8192009-09-04 17:36:40 +00005074 NestedNameSpecifier *Qualifier
5075 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00005076 E->getQualifierRange(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005077 ObjectType);
Douglas Gregora71d8192009-09-04 17:36:40 +00005078 if (E->getQualifier() && !Qualifier)
5079 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005080
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005081 PseudoDestructorTypeStorage Destroyed;
5082 if (E->getDestroyedTypeInfo()) {
5083 TypeSourceInfo *DestroyedTypeInfo
5084 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5085 if (!DestroyedTypeInfo)
5086 return SemaRef.ExprError();
5087 Destroyed = DestroyedTypeInfo;
5088 } else if (ObjectType->isDependentType()) {
5089 // We aren't likely to be able to resolve the identifier down to a type
5090 // now anyway, so just retain the identifier.
5091 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5092 E->getDestroyedTypeLoc());
5093 } else {
5094 // Look for a destructor known with the given name.
5095 CXXScopeSpec SS;
5096 if (Qualifier) {
5097 SS.setScopeRep(Qualifier);
5098 SS.setRange(E->getQualifierRange());
5099 }
5100
5101 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5102 *E->getDestroyedTypeIdentifier(),
5103 E->getDestroyedTypeLoc(),
5104 /*Scope=*/0,
5105 SS, ObjectTypePtr,
5106 false);
5107 if (!T)
5108 return SemaRef.ExprError();
5109
5110 Destroyed
5111 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5112 E->getDestroyedTypeLoc());
5113 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005114
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005115 TypeSourceInfo *ScopeTypeInfo = 0;
5116 if (E->getScopeTypeInfo()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005117 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
5118 ObjectType);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005119 if (!ScopeTypeInfo)
Douglas Gregora71d8192009-09-04 17:36:40 +00005120 return SemaRef.ExprError();
5121 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005122
Douglas Gregora71d8192009-09-04 17:36:40 +00005123 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5124 E->getOperatorLoc(),
5125 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005126 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005127 E->getQualifierRange(),
5128 ScopeTypeInfo,
5129 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005130 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005131 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00005132}
Mike Stump1eb44332009-09-09 15:08:12 +00005133
Douglas Gregora71d8192009-09-04 17:36:40 +00005134template<typename Derived>
5135Sema::OwningExprResult
John McCallba135432009-11-21 08:51:07 +00005136TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00005137 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00005138 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5139
5140 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5141 Sema::LookupOrdinaryName);
5142
5143 // Transform all the decls.
5144 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5145 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005146 NamedDecl *InstD = static_cast<NamedDecl*>(
5147 getDerived().TransformDecl(Old->getNameLoc(),
5148 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005149 if (!InstD) {
5150 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5151 // This can happen because of dependent hiding.
5152 if (isa<UsingShadowDecl>(*I))
5153 continue;
5154 else
5155 return SemaRef.ExprError();
5156 }
John McCallf7a1a742009-11-24 19:00:30 +00005157
5158 // Expand using declarations.
5159 if (isa<UsingDecl>(InstD)) {
5160 UsingDecl *UD = cast<UsingDecl>(InstD);
5161 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5162 E = UD->shadow_end(); I != E; ++I)
5163 R.addDecl(*I);
5164 continue;
5165 }
5166
5167 R.addDecl(InstD);
5168 }
5169
5170 // Resolve a kind, but don't do any further analysis. If it's
5171 // ambiguous, the callee needs to deal with it.
5172 R.resolveKind();
5173
5174 // Rebuild the nested-name qualifier, if present.
5175 CXXScopeSpec SS;
5176 NestedNameSpecifier *Qualifier = 0;
5177 if (Old->getQualifier()) {
5178 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005179 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00005180 if (!Qualifier)
5181 return SemaRef.ExprError();
5182
5183 SS.setScopeRep(Qualifier);
5184 SS.setRange(Old->getQualifierRange());
5185 }
5186
5187 // If we have no template arguments, it's a normal declaration name.
5188 if (!Old->hasExplicitTemplateArgs())
5189 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5190
5191 // If we have template arguments, rebuild them, then rebuild the
5192 // templateid expression.
5193 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5194 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5195 TemplateArgumentLoc Loc;
5196 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5197 return SemaRef.ExprError();
5198 TransArgs.addArgument(Loc);
5199 }
5200
5201 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5202 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005203}
Mike Stump1eb44332009-09-09 15:08:12 +00005204
Douglas Gregorb98b1992009-08-11 05:31:07 +00005205template<typename Derived>
5206Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005207TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005208 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005209
Douglas Gregorb98b1992009-08-11 05:31:07 +00005210 QualType T = getDerived().TransformType(E->getQueriedType());
5211 if (T.isNull())
5212 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005213
Douglas Gregorb98b1992009-08-11 05:31:07 +00005214 if (!getDerived().AlwaysRebuild() &&
5215 T == E->getQueriedType())
5216 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005217
Douglas Gregorb98b1992009-08-11 05:31:07 +00005218 // FIXME: Bad location information
5219 SourceLocation FakeLParenLoc
5220 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump1eb44332009-09-09 15:08:12 +00005221
5222 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005223 E->getLocStart(),
5224 /*FIXME:*/FakeLParenLoc,
5225 T,
5226 E->getLocEnd());
5227}
Mike Stump1eb44332009-09-09 15:08:12 +00005228
Douglas Gregorb98b1992009-08-11 05:31:07 +00005229template<typename Derived>
5230Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00005231TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall454feb92009-12-08 09:21:05 +00005232 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005233 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00005234 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005235 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005236 if (!NNS)
5237 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005238
5239 DeclarationName Name
Douglas Gregor81499bb2009-09-03 22:13:48 +00005240 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5241 if (!Name)
5242 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005243
John McCallf7a1a742009-11-24 19:00:30 +00005244 if (!E->hasExplicitTemplateArgs()) {
5245 if (!getDerived().AlwaysRebuild() &&
5246 NNS == E->getQualifier() &&
5247 Name == E->getDeclName())
5248 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005249
John McCallf7a1a742009-11-24 19:00:30 +00005250 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5251 E->getQualifierRange(),
5252 Name, E->getLocation(),
5253 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00005254 }
John McCalld5532b62009-11-23 01:53:49 +00005255
5256 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005257 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005258 TemplateArgumentLoc Loc;
5259 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb98b1992009-08-11 05:31:07 +00005260 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005261 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005262 }
5263
John McCallf7a1a742009-11-24 19:00:30 +00005264 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5265 E->getQualifierRange(),
5266 Name, E->getLocation(),
5267 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005268}
5269
5270template<typename Derived>
5271Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005272TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00005273 // CXXConstructExprs are always implicit, so when we have a
5274 // 1-argument construction we just transform that argument.
5275 if (E->getNumArgs() == 1 ||
5276 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5277 return getDerived().TransformExpr(E->getArg(0));
5278
Douglas Gregorb98b1992009-08-11 05:31:07 +00005279 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5280
5281 QualType T = getDerived().TransformType(E->getType());
5282 if (T.isNull())
5283 return SemaRef.ExprError();
5284
5285 CXXConstructorDecl *Constructor
5286 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005287 getDerived().TransformDecl(E->getLocStart(),
5288 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005289 if (!Constructor)
5290 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005291
Douglas Gregorb98b1992009-08-11 05:31:07 +00005292 bool ArgumentChanged = false;
5293 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005294 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005295 ArgEnd = E->arg_end();
5296 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005297 if (getDerived().DropCallArgument(*Arg)) {
5298 ArgumentChanged = true;
5299 break;
5300 }
5301
Douglas Gregorb98b1992009-08-11 05:31:07 +00005302 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5303 if (TransArg.isInvalid())
5304 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005305
Douglas Gregorb98b1992009-08-11 05:31:07 +00005306 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5307 Args.push_back(TransArg.takeAs<Expr>());
5308 }
5309
5310 if (!getDerived().AlwaysRebuild() &&
5311 T == E->getType() &&
5312 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005313 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005314 // Mark the constructor as referenced.
5315 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005316 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005317 return SemaRef.Owned(E->Retain());
Douglas Gregorc845aad2010-02-26 00:01:57 +00005318 }
Mike Stump1eb44332009-09-09 15:08:12 +00005319
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005320 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5321 Constructor, E->isElidable(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005322 move_arg(Args));
5323}
Mike Stump1eb44332009-09-09 15:08:12 +00005324
Douglas Gregorb98b1992009-08-11 05:31:07 +00005325/// \brief Transform a C++ temporary-binding expression.
5326///
Douglas Gregor51326552009-12-24 18:51:59 +00005327/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5328/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005329template<typename Derived>
5330Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005331TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005332 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005333}
Mike Stump1eb44332009-09-09 15:08:12 +00005334
Anders Carlssoneb60edf2010-01-29 02:39:32 +00005335/// \brief Transform a C++ reference-binding expression.
5336///
5337/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5338/// transform the subexpression and return that.
5339template<typename Derived>
5340Sema::OwningExprResult
5341TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5342 return getDerived().TransformExpr(E->getSubExpr());
5343}
5344
Mike Stump1eb44332009-09-09 15:08:12 +00005345/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00005346/// be destroyed after the expression is evaluated.
5347///
Douglas Gregor51326552009-12-24 18:51:59 +00005348/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5349/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005350template<typename Derived>
5351Sema::OwningExprResult
5352TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00005353 CXXExprWithTemporaries *E) {
5354 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005355}
Mike Stump1eb44332009-09-09 15:08:12 +00005356
Douglas Gregorb98b1992009-08-11 05:31:07 +00005357template<typename Derived>
5358Sema::OwningExprResult
5359TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall454feb92009-12-08 09:21:05 +00005360 CXXTemporaryObjectExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005361 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5362 QualType T = getDerived().TransformType(E->getType());
5363 if (T.isNull())
5364 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005365
Douglas Gregorb98b1992009-08-11 05:31:07 +00005366 CXXConstructorDecl *Constructor
5367 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005368 getDerived().TransformDecl(E->getLocStart(),
5369 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005370 if (!Constructor)
5371 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005372
Douglas Gregorb98b1992009-08-11 05:31:07 +00005373 bool ArgumentChanged = false;
5374 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5375 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005376 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005377 ArgEnd = E->arg_end();
5378 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005379 if (getDerived().DropCallArgument(*Arg)) {
5380 ArgumentChanged = true;
5381 break;
5382 }
5383
Douglas Gregorb98b1992009-08-11 05:31:07 +00005384 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5385 if (TransArg.isInvalid())
5386 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005387
Douglas Gregorb98b1992009-08-11 05:31:07 +00005388 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5389 Args.push_back((Expr *)TransArg.release());
5390 }
Mike Stump1eb44332009-09-09 15:08:12 +00005391
Douglas Gregorb98b1992009-08-11 05:31:07 +00005392 if (!getDerived().AlwaysRebuild() &&
5393 T == E->getType() &&
5394 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005395 !ArgumentChanged) {
5396 // FIXME: Instantiation-specific
5397 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carrutha3ce8ae2010-03-31 18:34:58 +00005398 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor91be6f52010-03-02 17:18:33 +00005399 }
Mike Stump1eb44332009-09-09 15:08:12 +00005400
Douglas Gregorb98b1992009-08-11 05:31:07 +00005401 // FIXME: Bogus location information
5402 SourceLocation CommaLoc;
5403 if (Args.size() > 1) {
5404 Expr *First = (Expr *)Args[0];
Mike Stump1eb44332009-09-09 15:08:12 +00005405 CommaLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005406 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5407 }
5408 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5409 T,
5410 /*FIXME:*/E->getTypeBeginLoc(),
5411 move_arg(Args),
5412 &CommaLoc,
5413 E->getLocEnd());
5414}
Mike Stump1eb44332009-09-09 15:08:12 +00005415
Douglas Gregorb98b1992009-08-11 05:31:07 +00005416template<typename Derived>
5417Sema::OwningExprResult
5418TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005419 CXXUnresolvedConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005420 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5421 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5422 if (T.isNull())
5423 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005424
Douglas Gregorb98b1992009-08-11 05:31:07 +00005425 bool ArgumentChanged = false;
5426 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5427 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5428 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5429 ArgEnd = E->arg_end();
5430 Arg != ArgEnd; ++Arg) {
5431 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5432 if (TransArg.isInvalid())
5433 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005434
Douglas Gregorb98b1992009-08-11 05:31:07 +00005435 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5436 FakeCommaLocs.push_back(
5437 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5438 Args.push_back(TransArg.takeAs<Expr>());
5439 }
Mike Stump1eb44332009-09-09 15:08:12 +00005440
Douglas Gregorb98b1992009-08-11 05:31:07 +00005441 if (!getDerived().AlwaysRebuild() &&
5442 T == E->getTypeAsWritten() &&
5443 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005444 return SemaRef.Owned(E->Retain());
5445
Douglas Gregorb98b1992009-08-11 05:31:07 +00005446 // FIXME: we're faking the locations of the commas
5447 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5448 T,
5449 E->getLParenLoc(),
5450 move_arg(Args),
5451 FakeCommaLocs.data(),
5452 E->getRParenLoc());
5453}
Mike Stump1eb44332009-09-09 15:08:12 +00005454
Douglas Gregorb98b1992009-08-11 05:31:07 +00005455template<typename Derived>
5456Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00005457TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall454feb92009-12-08 09:21:05 +00005458 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005459 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005460 OwningExprResult Base(SemaRef, (Expr*) 0);
5461 Expr *OldBase;
5462 QualType BaseType;
5463 QualType ObjectType;
5464 if (!E->isImplicitAccess()) {
5465 OldBase = E->getBase();
5466 Base = getDerived().TransformExpr(OldBase);
5467 if (Base.isInvalid())
5468 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005469
John McCallaa81e162009-12-01 22:10:20 +00005470 // Start the member reference and compute the object's type.
5471 Sema::TypeTy *ObjectTy = 0;
Douglas Gregord4dca082010-02-24 18:44:31 +00005472 bool MayBePseudoDestructor = false;
John McCallaa81e162009-12-01 22:10:20 +00005473 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5474 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005475 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005476 ObjectTy,
5477 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005478 if (Base.isInvalid())
5479 return SemaRef.ExprError();
5480
5481 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5482 BaseType = ((Expr*) Base.get())->getType();
5483 } else {
5484 OldBase = 0;
5485 BaseType = getDerived().TransformType(E->getBaseType());
5486 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5487 }
Mike Stump1eb44332009-09-09 15:08:12 +00005488
Douglas Gregor6cd21982009-10-20 05:58:46 +00005489 // Transform the first part of the nested-name-specifier that qualifies
5490 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005491 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005492 = getDerived().TransformFirstQualifierInScope(
5493 E->getFirstQualifierFoundInScope(),
5494 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005495
Douglas Gregora38c6872009-09-03 16:14:30 +00005496 NestedNameSpecifier *Qualifier = 0;
5497 if (E->getQualifier()) {
5498 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5499 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005500 ObjectType,
5501 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005502 if (!Qualifier)
5503 return SemaRef.ExprError();
5504 }
Mike Stump1eb44332009-09-09 15:08:12 +00005505
5506 DeclarationName Name
Douglas Gregordd62b152009-10-19 22:04:39 +00005507 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCallaa81e162009-12-01 22:10:20 +00005508 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00005509 if (!Name)
5510 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005511
John McCallaa81e162009-12-01 22:10:20 +00005512 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005513 // This is a reference to a member without an explicitly-specified
5514 // template argument list. Optimize for this common case.
5515 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005516 Base.get() == OldBase &&
5517 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005518 Qualifier == E->getQualifier() &&
5519 Name == E->getMember() &&
5520 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005521 return SemaRef.Owned(E->Retain());
5522
John McCall865d4472009-11-19 22:55:06 +00005523 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005524 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005525 E->isArrow(),
5526 E->getOperatorLoc(),
5527 Qualifier,
5528 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005529 FirstQualifierInScope,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005530 Name,
5531 E->getMemberLoc(),
John McCall129e2df2009-11-30 22:42:35 +00005532 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005533 }
5534
John McCalld5532b62009-11-23 01:53:49 +00005535 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005536 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005537 TemplateArgumentLoc Loc;
5538 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005539 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005540 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005541 }
Mike Stump1eb44332009-09-09 15:08:12 +00005542
John McCall865d4472009-11-19 22:55:06 +00005543 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005544 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005545 E->isArrow(),
5546 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005547 Qualifier,
5548 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005549 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005550 Name,
5551 E->getMemberLoc(),
5552 &TransArgs);
5553}
5554
5555template<typename Derived>
5556Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005557TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005558 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005559 OwningExprResult Base(SemaRef, (Expr*) 0);
5560 QualType BaseType;
5561 if (!Old->isImplicitAccess()) {
5562 Base = getDerived().TransformExpr(Old->getBase());
5563 if (Base.isInvalid())
5564 return SemaRef.ExprError();
5565 BaseType = ((Expr*) Base.get())->getType();
5566 } else {
5567 BaseType = getDerived().TransformType(Old->getBaseType());
5568 }
John McCall129e2df2009-11-30 22:42:35 +00005569
5570 NestedNameSpecifier *Qualifier = 0;
5571 if (Old->getQualifier()) {
5572 Qualifier
5573 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005574 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00005575 if (Qualifier == 0)
5576 return SemaRef.ExprError();
5577 }
5578
5579 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5580 Sema::LookupOrdinaryName);
5581
5582 // Transform all the decls.
5583 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5584 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005585 NamedDecl *InstD = static_cast<NamedDecl*>(
5586 getDerived().TransformDecl(Old->getMemberLoc(),
5587 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005588 if (!InstD) {
5589 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5590 // This can happen because of dependent hiding.
5591 if (isa<UsingShadowDecl>(*I))
5592 continue;
5593 else
5594 return SemaRef.ExprError();
5595 }
John McCall129e2df2009-11-30 22:42:35 +00005596
5597 // Expand using declarations.
5598 if (isa<UsingDecl>(InstD)) {
5599 UsingDecl *UD = cast<UsingDecl>(InstD);
5600 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5601 E = UD->shadow_end(); I != E; ++I)
5602 R.addDecl(*I);
5603 continue;
5604 }
5605
5606 R.addDecl(InstD);
5607 }
5608
5609 R.resolveKind();
5610
5611 TemplateArgumentListInfo TransArgs;
5612 if (Old->hasExplicitTemplateArgs()) {
5613 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5614 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5615 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5616 TemplateArgumentLoc Loc;
5617 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5618 Loc))
5619 return SemaRef.ExprError();
5620 TransArgs.addArgument(Loc);
5621 }
5622 }
John McCallc2233c52010-01-15 08:34:02 +00005623
5624 // FIXME: to do this check properly, we will need to preserve the
5625 // first-qualifier-in-scope here, just in case we had a dependent
5626 // base (and therefore couldn't do the check) and a
5627 // nested-name-qualifier (and therefore could do the lookup).
5628 NamedDecl *FirstQualifierInScope = 0;
John McCall129e2df2009-11-30 22:42:35 +00005629
5630 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005631 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00005632 Old->getOperatorLoc(),
5633 Old->isArrow(),
5634 Qualifier,
5635 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00005636 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005637 R,
5638 (Old->hasExplicitTemplateArgs()
5639 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005640}
5641
5642template<typename Derived>
5643Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005644TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005645 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005646}
5647
Mike Stump1eb44332009-09-09 15:08:12 +00005648template<typename Derived>
5649Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005650TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00005651 TypeSourceInfo *EncodedTypeInfo
5652 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5653 if (!EncodedTypeInfo)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005654 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005655
Douglas Gregorb98b1992009-08-11 05:31:07 +00005656 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00005657 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump1eb44332009-09-09 15:08:12 +00005658 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005659
5660 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00005661 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005662 E->getRParenLoc());
5663}
Mike Stump1eb44332009-09-09 15:08:12 +00005664
Douglas Gregorb98b1992009-08-11 05:31:07 +00005665template<typename Derived>
5666Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005667TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00005668 // Transform arguments.
5669 bool ArgChanged = false;
5670 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5671 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5672 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5673 if (Arg.isInvalid())
5674 return SemaRef.ExprError();
5675
5676 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5677 Args.push_back(Arg.takeAs<Expr>());
5678 }
5679
5680 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5681 // Class message: transform the receiver type.
5682 TypeSourceInfo *ReceiverTypeInfo
5683 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5684 if (!ReceiverTypeInfo)
5685 return SemaRef.ExprError();
5686
5687 // If nothing changed, just retain the existing message send.
5688 if (!getDerived().AlwaysRebuild() &&
5689 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
5690 return SemaRef.Owned(E->Retain());
5691
5692 // Build a new class message send.
5693 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
5694 E->getSelector(),
5695 E->getMethodDecl(),
5696 E->getLeftLoc(),
5697 move_arg(Args),
5698 E->getRightLoc());
5699 }
5700
5701 // Instance message: transform the receiver
5702 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
5703 "Only class and instance messages may be instantiated");
5704 OwningExprResult Receiver
5705 = getDerived().TransformExpr(E->getInstanceReceiver());
5706 if (Receiver.isInvalid())
5707 return SemaRef.ExprError();
5708
5709 // If nothing changed, just retain the existing message send.
5710 if (!getDerived().AlwaysRebuild() &&
5711 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
5712 return SemaRef.Owned(E->Retain());
5713
5714 // Build a new instance message send.
5715 return getDerived().RebuildObjCMessageExpr(move(Receiver),
5716 E->getSelector(),
5717 E->getMethodDecl(),
5718 E->getLeftLoc(),
5719 move_arg(Args),
5720 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005721}
5722
Mike Stump1eb44332009-09-09 15:08:12 +00005723template<typename Derived>
5724Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005725TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005726 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005727}
5728
Mike Stump1eb44332009-09-09 15:08:12 +00005729template<typename Derived>
5730Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005731TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005732 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005733}
5734
Mike Stump1eb44332009-09-09 15:08:12 +00005735template<typename Derived>
5736Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005737TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005738 // FIXME: Implement this!
5739 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005740 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005741}
5742
Mike Stump1eb44332009-09-09 15:08:12 +00005743template<typename Derived>
5744Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005745TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005746 // FIXME: Implement this!
5747 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005748 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005749}
5750
Mike Stump1eb44332009-09-09 15:08:12 +00005751template<typename Derived>
5752Sema::OwningExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00005753TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00005754 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005755 // FIXME: Implement this!
5756 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005757 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005758}
5759
Mike Stump1eb44332009-09-09 15:08:12 +00005760template<typename Derived>
5761Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005762TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005763 // Can never occur in a dependent context.
Mike Stump1eb44332009-09-09 15:08:12 +00005764 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005765}
5766
Mike Stump1eb44332009-09-09 15:08:12 +00005767template<typename Derived>
5768Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005769TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005770 // FIXME: Implement this!
5771 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005772 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005773}
5774
Mike Stump1eb44332009-09-09 15:08:12 +00005775template<typename Derived>
5776Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005777TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005778 bool ArgumentChanged = false;
5779 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5780 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5781 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5782 if (SubExpr.isInvalid())
5783 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005784
Douglas Gregorb98b1992009-08-11 05:31:07 +00005785 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5786 SubExprs.push_back(SubExpr.takeAs<Expr>());
5787 }
Mike Stump1eb44332009-09-09 15:08:12 +00005788
Douglas Gregorb98b1992009-08-11 05:31:07 +00005789 if (!getDerived().AlwaysRebuild() &&
5790 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005791 return SemaRef.Owned(E->Retain());
5792
Douglas Gregorb98b1992009-08-11 05:31:07 +00005793 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5794 move_arg(SubExprs),
5795 E->getRParenLoc());
5796}
5797
Mike Stump1eb44332009-09-09 15:08:12 +00005798template<typename Derived>
5799Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005800TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005801 // FIXME: Implement this!
5802 assert(false && "Cannot transform block expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005803 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005804}
5805
Mike Stump1eb44332009-09-09 15:08:12 +00005806template<typename Derived>
5807Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005808TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005809 // FIXME: Implement this!
5810 assert(false && "Cannot transform block-related expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005811 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005812}
Mike Stump1eb44332009-09-09 15:08:12 +00005813
Douglas Gregorb98b1992009-08-11 05:31:07 +00005814//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00005815// Type reconstruction
5816//===----------------------------------------------------------------------===//
5817
Mike Stump1eb44332009-09-09 15:08:12 +00005818template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005819QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5820 SourceLocation Star) {
5821 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005822 getDerived().getBaseEntity());
5823}
5824
Mike Stump1eb44332009-09-09 15:08:12 +00005825template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005826QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5827 SourceLocation Star) {
5828 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005829 getDerived().getBaseEntity());
5830}
5831
Mike Stump1eb44332009-09-09 15:08:12 +00005832template<typename Derived>
5833QualType
John McCall85737a72009-10-30 00:06:24 +00005834TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5835 bool WrittenAsLValue,
5836 SourceLocation Sigil) {
5837 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5838 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005839}
5840
5841template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005842QualType
John McCall85737a72009-10-30 00:06:24 +00005843TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5844 QualType ClassType,
5845 SourceLocation Sigil) {
John McCall0953e762009-09-24 19:53:00 +00005846 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall85737a72009-10-30 00:06:24 +00005847 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005848}
5849
5850template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005851QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00005852TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5853 ArrayType::ArraySizeModifier SizeMod,
5854 const llvm::APInt *Size,
5855 Expr *SizeExpr,
5856 unsigned IndexTypeQuals,
5857 SourceRange BracketsRange) {
5858 if (SizeExpr || !Size)
5859 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5860 IndexTypeQuals, BracketsRange,
5861 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00005862
5863 QualType Types[] = {
5864 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5865 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5866 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00005867 };
5868 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5869 QualType SizeType;
5870 for (unsigned I = 0; I != NumTypes; ++I)
5871 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5872 SizeType = Types[I];
5873 break;
5874 }
Mike Stump1eb44332009-09-09 15:08:12 +00005875
Douglas Gregor577f75a2009-08-04 16:50:30 +00005876 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005877 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005878 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00005879 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005880}
Mike Stump1eb44332009-09-09 15:08:12 +00005881
Douglas Gregor577f75a2009-08-04 16:50:30 +00005882template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005883QualType
5884TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005885 ArrayType::ArraySizeModifier SizeMod,
5886 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00005887 unsigned IndexTypeQuals,
5888 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005889 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00005890 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005891}
5892
5893template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005894QualType
Mike Stump1eb44332009-09-09 15:08:12 +00005895TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005896 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00005897 unsigned IndexTypeQuals,
5898 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005899 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00005900 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005901}
Mike Stump1eb44332009-09-09 15:08:12 +00005902
Douglas Gregor577f75a2009-08-04 16:50:30 +00005903template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005904QualType
5905TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005906 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005907 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005908 unsigned IndexTypeQuals,
5909 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005910 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005911 SizeExpr.takeAs<Expr>(),
5912 IndexTypeQuals, BracketsRange);
5913}
5914
5915template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005916QualType
5917TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005918 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005919 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005920 unsigned IndexTypeQuals,
5921 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005922 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005923 SizeExpr.takeAs<Expr>(),
5924 IndexTypeQuals, BracketsRange);
5925}
5926
5927template<typename Derived>
5928QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson82287d12010-02-05 00:12:22 +00005929 unsigned NumElements,
5930 bool IsAltiVec, bool IsPixel) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005931 // FIXME: semantic checking!
John Thompson82287d12010-02-05 00:12:22 +00005932 return SemaRef.Context.getVectorType(ElementType, NumElements,
5933 IsAltiVec, IsPixel);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005934}
Mike Stump1eb44332009-09-09 15:08:12 +00005935
Douglas Gregor577f75a2009-08-04 16:50:30 +00005936template<typename Derived>
5937QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5938 unsigned NumElements,
5939 SourceLocation AttributeLoc) {
5940 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5941 NumElements, true);
5942 IntegerLiteral *VectorSize
Mike Stump1eb44332009-09-09 15:08:12 +00005943 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005944 AttributeLoc);
5945 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5946 AttributeLoc);
5947}
Mike Stump1eb44332009-09-09 15:08:12 +00005948
Douglas Gregor577f75a2009-08-04 16:50:30 +00005949template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005950QualType
5951TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005952 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005953 SourceLocation AttributeLoc) {
5954 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5955}
Mike Stump1eb44332009-09-09 15:08:12 +00005956
Douglas Gregor577f75a2009-08-04 16:50:30 +00005957template<typename Derived>
5958QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00005959 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005960 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00005961 bool Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005962 unsigned Quals) {
Mike Stump1eb44332009-09-09 15:08:12 +00005963 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005964 Quals,
5965 getDerived().getBaseLocation(),
5966 getDerived().getBaseEntity());
5967}
Mike Stump1eb44332009-09-09 15:08:12 +00005968
Douglas Gregor577f75a2009-08-04 16:50:30 +00005969template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005970QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5971 return SemaRef.Context.getFunctionNoProtoType(T);
5972}
5973
5974template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00005975QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5976 assert(D && "no decl found");
5977 if (D->isInvalidDecl()) return QualType();
5978
Douglas Gregor92e986e2010-04-22 16:44:27 +00005979 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00005980 TypeDecl *Ty;
5981 if (isa<UsingDecl>(D)) {
5982 UsingDecl *Using = cast<UsingDecl>(D);
5983 assert(Using->isTypeName() &&
5984 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5985
5986 // A valid resolved using typename decl points to exactly one type decl.
5987 assert(++Using->shadow_begin() == Using->shadow_end());
5988 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5989
5990 } else {
5991 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5992 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5993 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5994 }
5995
5996 return SemaRef.Context.getTypeDeclType(Ty);
5997}
5998
5999template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00006000QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006001 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6002}
6003
6004template<typename Derived>
6005QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6006 return SemaRef.Context.getTypeOfType(Underlying);
6007}
6008
6009template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00006010QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006011 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6012}
6013
6014template<typename Derived>
6015QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00006016 TemplateName Template,
6017 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00006018 const TemplateArgumentListInfo &TemplateArgs) {
6019 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006020}
Mike Stump1eb44332009-09-09 15:08:12 +00006021
Douglas Gregordcee1a12009-08-06 05:28:30 +00006022template<typename Derived>
6023NestedNameSpecifier *
6024TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6025 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00006026 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006027 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00006028 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00006029 CXXScopeSpec SS;
6030 // FIXME: The source location information is all wrong.
6031 SS.setRange(Range);
6032 SS.setScopeRep(Prefix);
6033 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00006034 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00006035 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006036 ObjectType,
6037 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00006038 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00006039}
6040
6041template<typename Derived>
6042NestedNameSpecifier *
6043TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6044 SourceRange Range,
6045 NamespaceDecl *NS) {
6046 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6047}
6048
6049template<typename Derived>
6050NestedNameSpecifier *
6051TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6052 SourceRange Range,
6053 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00006054 QualType T) {
6055 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00006056 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00006057 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00006058 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6059 T.getTypePtr());
6060 }
Mike Stump1eb44332009-09-09 15:08:12 +00006061
Douglas Gregordcee1a12009-08-06 05:28:30 +00006062 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6063 return 0;
6064}
Mike Stump1eb44332009-09-09 15:08:12 +00006065
Douglas Gregord1067e52009-08-06 06:41:21 +00006066template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006067TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006068TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6069 bool TemplateKW,
6070 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00006071 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00006072 Template);
6073}
6074
6075template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006076TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006077TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006078 const IdentifierInfo &II,
6079 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00006080 CXXScopeSpec SS;
6081 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump1eb44332009-09-09 15:08:12 +00006082 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00006083 UnqualifiedId Name;
6084 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006085 return getSema().ActOnDependentTemplateName(
6086 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006087 SS,
Douglas Gregor014e88d2009-11-03 23:16:33 +00006088 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00006089 ObjectType.getAsOpaquePtr(),
6090 /*EnteringContext=*/false)
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006091 .template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00006092}
Mike Stump1eb44332009-09-09 15:08:12 +00006093
Douglas Gregorb98b1992009-08-11 05:31:07 +00006094template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006095TemplateName
6096TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6097 OverloadedOperatorKind Operator,
6098 QualType ObjectType) {
6099 CXXScopeSpec SS;
6100 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6101 SS.setScopeRep(Qualifier);
6102 UnqualifiedId Name;
6103 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6104 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6105 Operator, SymbolLocations);
6106 return getSema().ActOnDependentTemplateName(
6107 /*FIXME:*/getDerived().getBaseLocation(),
6108 SS,
6109 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00006110 ObjectType.getAsOpaquePtr(),
6111 /*EnteringContext=*/false)
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006112 .template getAsVal<TemplateName>();
6113}
6114
6115template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006116Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006117TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6118 SourceLocation OpLoc,
6119 ExprArg Callee,
6120 ExprArg First,
6121 ExprArg Second) {
6122 Expr *FirstExpr = (Expr *)First.get();
6123 Expr *SecondExpr = (Expr *)Second.get();
John McCallba135432009-11-21 08:51:07 +00006124 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006125 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00006126
Douglas Gregorb98b1992009-08-11 05:31:07 +00006127 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00006128 if (Op == OO_Subscript) {
6129 if (!FirstExpr->getType()->isOverloadableType() &&
6130 !SecondExpr->getType()->isOverloadableType())
6131 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCallba135432009-11-21 08:51:07 +00006132 CalleeExpr->getLocStart(),
Sebastian Redlf322ed62009-10-29 20:17:01 +00006133 move(Second), OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00006134 } else if (Op == OO_Arrow) {
6135 // -> is never a builtin operation.
6136 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redlf322ed62009-10-29 20:17:01 +00006137 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006138 if (!FirstExpr->getType()->isOverloadableType()) {
6139 // The argument is not of overloadable type, so try to create a
6140 // built-in unary operation.
Mike Stump1eb44332009-09-09 15:08:12 +00006141 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006142 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00006143
Douglas Gregorb98b1992009-08-11 05:31:07 +00006144 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6145 }
6146 } else {
Mike Stump1eb44332009-09-09 15:08:12 +00006147 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006148 !SecondExpr->getType()->isOverloadableType()) {
6149 // Neither of the arguments is an overloadable type, so try to
6150 // create a built-in binary operation.
6151 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00006152 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006153 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6154 if (Result.isInvalid())
6155 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006156
Douglas Gregorb98b1992009-08-11 05:31:07 +00006157 First.release();
6158 Second.release();
6159 return move(Result);
6160 }
6161 }
Mike Stump1eb44332009-09-09 15:08:12 +00006162
6163 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00006164 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00006165 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00006166
John McCallba135432009-11-21 08:51:07 +00006167 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6168 assert(ULE->requiresADL());
6169
6170 // FIXME: Do we have to check
6171 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00006172 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00006173 } else {
John McCall6e266892010-01-26 03:27:55 +00006174 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCallba135432009-11-21 08:51:07 +00006175 }
Mike Stump1eb44332009-09-09 15:08:12 +00006176
Douglas Gregorb98b1992009-08-11 05:31:07 +00006177 // Add any functions found via argument-dependent lookup.
6178 Expr *Args[2] = { FirstExpr, SecondExpr };
6179 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00006180
Douglas Gregorb98b1992009-08-11 05:31:07 +00006181 // Create the overloaded operator invocation for unary operators.
6182 if (NumArgs == 1 || isPostIncDec) {
Mike Stump1eb44332009-09-09 15:08:12 +00006183 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006184 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6185 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6186 }
Mike Stump1eb44332009-09-09 15:08:12 +00006187
Sebastian Redlf322ed62009-10-29 20:17:01 +00006188 if (Op == OO_Subscript)
John McCallba135432009-11-21 08:51:07 +00006189 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6190 OpLoc,
6191 move(First),
6192 move(Second));
Sebastian Redlf322ed62009-10-29 20:17:01 +00006193
Douglas Gregorb98b1992009-08-11 05:31:07 +00006194 // Create the overloaded operator invocation for binary operators.
Mike Stump1eb44332009-09-09 15:08:12 +00006195 BinaryOperator::Opcode Opc =
Douglas Gregorb98b1992009-08-11 05:31:07 +00006196 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00006197 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006198 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6199 if (Result.isInvalid())
6200 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006201
Douglas Gregorb98b1992009-08-11 05:31:07 +00006202 First.release();
6203 Second.release();
Mike Stump1eb44332009-09-09 15:08:12 +00006204 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006205}
Mike Stump1eb44332009-09-09 15:08:12 +00006206
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006207template<typename Derived>
6208Sema::OwningExprResult
6209TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6210 SourceLocation OperatorLoc,
6211 bool isArrow,
6212 NestedNameSpecifier *Qualifier,
6213 SourceRange QualifierRange,
6214 TypeSourceInfo *ScopeType,
6215 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006216 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006217 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006218 CXXScopeSpec SS;
6219 if (Qualifier) {
6220 SS.setRange(QualifierRange);
6221 SS.setScopeRep(Qualifier);
6222 }
6223
6224 Expr *BaseE = (Expr *)Base.get();
6225 QualType BaseType = BaseE->getType();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006226 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006227 (!isArrow && !BaseType->getAs<RecordType>()) ||
6228 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00006229 !BaseType->getAs<PointerType>()->getPointeeType()
6230 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006231 // This pseudo-destructor expression is still a pseudo-destructor.
6232 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6233 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006234 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006235 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006236 /*FIXME?*/true);
6237 }
6238
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006239 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006240 DeclarationName Name
6241 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6242 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
6243
6244 // FIXME: the ScopeType should be tacked onto SS.
6245
6246 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6247 OperatorLoc, isArrow,
6248 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006249 Name, Destroyed.getLocation(),
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006250 /*TemplateArgs*/ 0);
6251}
6252
Douglas Gregor577f75a2009-08-04 16:50:30 +00006253} // end namespace clang
6254
6255#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H