blob: a61768bcf432e621fe8287fb87ed3d7fd225cf65 [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;
Sean Huntc3021132010-05-05 15:23:54 +000099
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 }
Sean Huntc3021132010-05-05 15:23:54 +0000184
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.
Sean Huntc3021132010-05-05 15:23:54 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
Douglas Gregor124b8782010-02-16 19:09:40 +0000205 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 ///
Sean Huntc3021132010-05-05 15:23:54 +0000211 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +0000212 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.
Sean Huntc3021132010-05-05 15:23:54 +0000246 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
247 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 ///
Sean Huntc3021132010-05-05 15:23:54 +0000253 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000254 /// identifier in a nested-name-specifier of a member access expression, e.g.,
255 /// the \c T in \c x->T::member
256 ///
257 /// By default, invokes TransformDecl() to transform the declaration.
258 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000259 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
260 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000261 }
Sean Huntc3021132010-05-05 15:23:54 +0000262
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
Sean Huntc3021132010-05-05 15:23:54 +0000333 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +0000334 QualType ObjectType);
John McCall85737a72009-10-30 00:06:24 +0000335
Sean Huntc3021132010-05-05 15:23:54 +0000336 QualType
Douglas Gregordd62b152009-10-19 22:04:39 +0000337 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);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000347#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000348#include "clang/AST/StmtNodes.inc"
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,
Chris Lattner788b0fd2010-06-23 06:00:24 +0000445 VectorType::AltiVecSpecific AltiVecSpec);
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,
Eli Friedmanfa869542010-08-05 02:54:05 +0000471 bool Variadic, unsigned Quals,
472 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000473
John McCalla2becad2009-10-21 00:40:46 +0000474 /// \brief Build a new unprototyped function type.
475 QualType RebuildFunctionNoProtoType(QualType ResultType);
476
John McCalled976492009-12-04 22:46:56 +0000477 /// \brief Rebuild an unresolved typename type, given the decl that
478 /// the UnresolvedUsingTypenameDecl was transformed to.
479 QualType RebuildUnresolvedUsingType(Decl *D);
480
Douglas Gregor577f75a2009-08-04 16:50:30 +0000481 /// \brief Build a new typedef type.
482 QualType RebuildTypedefType(TypedefDecl *Typedef) {
483 return SemaRef.Context.getTypeDeclType(Typedef);
484 }
485
486 /// \brief Build a new class/struct/union type.
487 QualType RebuildRecordType(RecordDecl *Record) {
488 return SemaRef.Context.getTypeDeclType(Record);
489 }
490
491 /// \brief Build a new Enum type.
492 QualType RebuildEnumType(EnumDecl *Enum) {
493 return SemaRef.Context.getTypeDeclType(Enum);
494 }
John McCall7da24312009-09-05 00:15:47 +0000495
Mike Stump1eb44332009-09-09 15:08:12 +0000496 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000497 ///
498 /// By default, performs semantic analysis when building the typeof type.
499 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000500 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000501
Mike Stump1eb44332009-09-09 15:08:12 +0000502 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000503 ///
504 /// By default, builds a new TypeOfType with the given underlying type.
505 QualType RebuildTypeOfType(QualType Underlying);
506
Mike Stump1eb44332009-09-09 15:08:12 +0000507 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000508 ///
509 /// By default, performs semantic analysis when building the decltype type.
510 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000511 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump1eb44332009-09-09 15:08:12 +0000512
Douglas Gregor577f75a2009-08-04 16:50:30 +0000513 /// \brief Build a new template specialization type.
514 ///
515 /// By default, performs semantic analysis when building the template
516 /// specialization type. Subclasses may override this routine to provide
517 /// different behavior.
518 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000519 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000520 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000521
Douglas Gregor577f75a2009-08-04 16:50:30 +0000522 /// \brief Build a new qualified name type.
523 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000524 /// By default, builds a new ElaboratedType type from the keyword,
525 /// the nested-name-specifier and the named type.
526 /// Subclasses may override this routine to provide different behavior.
527 QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword,
528 NestedNameSpecifier *NNS, QualType Named) {
529 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000530 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000531
532 /// \brief Build a new typename type that refers to a template-id.
533 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000534 /// By default, builds a new DependentNameType type from the
535 /// nested-name-specifier and the given type. Subclasses may override
536 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000537 QualType RebuildDependentTemplateSpecializationType(
538 ElaboratedTypeKeyword Keyword,
539 NestedNameSpecifier *NNS,
540 const IdentifierInfo *Name,
541 SourceLocation NameLoc,
542 const TemplateArgumentListInfo &Args) {
543 // Rebuild the template name.
544 // TODO: avoid TemplateName abstraction
545 TemplateName InstName =
546 getDerived().RebuildTemplateName(NNS, *Name, QualType());
547
Douglas Gregor96fb42e2010-06-18 22:12:56 +0000548 if (InstName.isNull())
549 return QualType();
550
John McCall33500952010-06-11 00:33:02 +0000551 // If it's still dependent, make a dependent specialization.
552 if (InstName.getAsDependentTemplateName())
553 return SemaRef.Context.getDependentTemplateSpecializationType(
554 Keyword, NNS, Name, Args);
555
556 // Otherwise, make an elaborated type wrapping a non-dependent
557 // specialization.
558 QualType T =
559 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
560 if (T.isNull()) return QualType();
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000561
562 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000563 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000564
565 /// \brief Build a new typename type that refers to an identifier.
566 ///
567 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000568 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000569 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000570 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000571 NestedNameSpecifier *NNS,
572 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000573 SourceLocation KeywordLoc,
574 SourceRange NNSRange,
575 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000576 CXXScopeSpec SS;
577 SS.setScopeRep(NNS);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000578 SS.setRange(NNSRange);
579
Douglas Gregor40336422010-03-31 22:19:08 +0000580 if (NNS->isDependent()) {
581 // If the name is still dependent, just build a new dependent name type.
582 if (!SemaRef.computeDeclContext(SS))
583 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
584 }
585
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000586 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000587 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
588 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000589
590 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
591
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000592 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000593 // into a non-dependent elaborated-type-specifier. Find the tag we're
594 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000595 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000596 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
597 if (!DC)
598 return QualType();
599
John McCall56138762010-05-27 06:40:31 +0000600 if (SemaRef.RequireCompleteDeclContext(SS, DC))
601 return QualType();
602
Douglas Gregor40336422010-03-31 22:19:08 +0000603 TagDecl *Tag = 0;
604 SemaRef.LookupQualifiedName(Result, DC);
605 switch (Result.getResultKind()) {
606 case LookupResult::NotFound:
607 case LookupResult::NotFoundInCurrentInstantiation:
608 break;
Sean Huntc3021132010-05-05 15:23:54 +0000609
Douglas Gregor40336422010-03-31 22:19:08 +0000610 case LookupResult::Found:
611 Tag = Result.getAsSingle<TagDecl>();
612 break;
Sean Huntc3021132010-05-05 15:23:54 +0000613
Douglas Gregor40336422010-03-31 22:19:08 +0000614 case LookupResult::FoundOverloaded:
615 case LookupResult::FoundUnresolvedValue:
616 llvm_unreachable("Tag lookup cannot find non-tags");
617 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000618
Douglas Gregor40336422010-03-31 22:19:08 +0000619 case LookupResult::Ambiguous:
620 // Let the LookupResult structure handle ambiguities.
621 return QualType();
622 }
623
624 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000625 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000626 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000627 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000628 return QualType();
629 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000630
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000631 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
632 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000633 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
634 return QualType();
635 }
636
637 // Build the elaborated-type-specifier type.
638 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000639 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000640 }
Mike Stump1eb44332009-09-09 15:08:12 +0000641
Douglas Gregordcee1a12009-08-06 05:28:30 +0000642 /// \brief Build a new nested-name-specifier given the prefix and an
643 /// identifier that names the next step in the nested-name-specifier.
644 ///
645 /// By default, performs semantic analysis when building the new
646 /// nested-name-specifier. Subclasses may override this routine to provide
647 /// different behavior.
648 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
649 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000650 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000651 QualType ObjectType,
652 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000653
654 /// \brief Build a new nested-name-specifier given the prefix and the
655 /// namespace named in the next step in the nested-name-specifier.
656 ///
657 /// By default, performs semantic analysis when building the new
658 /// nested-name-specifier. Subclasses may override this routine to provide
659 /// different behavior.
660 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
661 SourceRange Range,
662 NamespaceDecl *NS);
663
664 /// \brief Build a new nested-name-specifier given the prefix and the
665 /// type named in the next step in the nested-name-specifier.
666 ///
667 /// By default, performs semantic analysis when building the new
668 /// nested-name-specifier. Subclasses may override this routine to provide
669 /// different behavior.
670 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
671 SourceRange Range,
672 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000673 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000674
675 /// \brief Build a new template name given a nested name specifier, a flag
676 /// indicating whether the "template" keyword was provided, and the template
677 /// that the template name refers to.
678 ///
679 /// By default, builds the new template name directly. Subclasses may override
680 /// this routine to provide different behavior.
681 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
682 bool TemplateKW,
683 TemplateDecl *Template);
684
Douglas Gregord1067e52009-08-06 06:41:21 +0000685 /// \brief Build a new template name given a nested name specifier and the
686 /// name that is referred to as a template.
687 ///
688 /// By default, performs semantic analysis to determine whether the name can
689 /// be resolved to a specific template, then builds the appropriate kind of
690 /// template name. Subclasses may override this routine to provide different
691 /// behavior.
692 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000693 const IdentifierInfo &II,
694 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000695
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000696 /// \brief Build a new template name given a nested name specifier and the
697 /// overloaded operator name that is referred to as a template.
698 ///
699 /// By default, performs semantic analysis to determine whether the name can
700 /// be resolved to a specific template, then builds the appropriate kind of
701 /// template name. Subclasses may override this routine to provide different
702 /// behavior.
703 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
704 OverloadedOperatorKind Operator,
705 QualType ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +0000706
Douglas Gregor43959a92009-08-20 07:17:43 +0000707 /// \brief Build a new compound statement.
708 ///
709 /// By default, performs semantic analysis to build the new statement.
710 /// Subclasses may override this routine to provide different behavior.
711 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
712 MultiStmtArg Statements,
713 SourceLocation RBraceLoc,
714 bool IsStmtExpr) {
715 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
716 IsStmtExpr);
717 }
718
719 /// \brief Build a new case statement.
720 ///
721 /// By default, performs semantic analysis to build the new statement.
722 /// Subclasses may override this routine to provide different behavior.
723 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
724 ExprArg LHS,
725 SourceLocation EllipsisLoc,
726 ExprArg RHS,
727 SourceLocation ColonLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000728 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregor43959a92009-08-20 07:17:43 +0000729 ColonLoc);
730 }
Mike Stump1eb44332009-09-09 15:08:12 +0000731
Douglas Gregor43959a92009-08-20 07:17:43 +0000732 /// \brief Attach the body to a new case statement.
733 ///
734 /// By default, performs semantic analysis to build the new statement.
735 /// Subclasses may override this routine to provide different behavior.
736 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
737 getSema().ActOnCaseStmtBody(S.get(), move(Body));
738 return move(S);
739 }
Mike Stump1eb44332009-09-09 15:08:12 +0000740
Douglas Gregor43959a92009-08-20 07:17:43 +0000741 /// \brief Build a new default statement.
742 ///
743 /// By default, performs semantic analysis to build the new statement.
744 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000745 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000746 SourceLocation ColonLoc,
747 StmtArg SubStmt) {
Mike Stump1eb44332009-09-09 15:08:12 +0000748 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregor43959a92009-08-20 07:17:43 +0000749 /*CurScope=*/0);
750 }
Mike Stump1eb44332009-09-09 15:08:12 +0000751
Douglas Gregor43959a92009-08-20 07:17:43 +0000752 /// \brief Build a new label statement.
753 ///
754 /// By default, performs semantic analysis to build the new statement.
755 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000756 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000757 IdentifierInfo *Id,
758 SourceLocation ColonLoc,
759 StmtArg SubStmt) {
760 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
761 }
Mike Stump1eb44332009-09-09 15:08:12 +0000762
Douglas Gregor43959a92009-08-20 07:17:43 +0000763 /// \brief Build a new "if" statement.
764 ///
765 /// By default, performs semantic analysis to build the new statement.
766 /// Subclasses may override this routine to provide different behavior.
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000767 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Sean Huntc3021132010-05-05 15:23:54 +0000768 VarDecl *CondVar, StmtArg Then,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000769 SourceLocation ElseLoc, StmtArg Else) {
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000770 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000771 move(Then), ElseLoc, move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +0000772 }
Mike Stump1eb44332009-09-09 15:08:12 +0000773
Douglas Gregor43959a92009-08-20 07:17:43 +0000774 /// \brief Start building a new switch statement.
775 ///
776 /// By default, performs semantic analysis to build the new statement.
777 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor586596f2010-05-06 17:25:47 +0000778 OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
779 Sema::ExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000780 VarDecl *CondVar) {
Douglas Gregor586596f2010-05-06 17:25:47 +0000781 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond),
782 DeclPtrTy::make(CondVar));
Douglas Gregor43959a92009-08-20 07:17:43 +0000783 }
Mike Stump1eb44332009-09-09 15:08:12 +0000784
Douglas Gregor43959a92009-08-20 07:17:43 +0000785 /// \brief Attach the body to the switch statement.
786 ///
787 /// By default, performs semantic analysis to build the new statement.
788 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000789 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000790 StmtArg Switch, StmtArg Body) {
791 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
792 move(Body));
793 }
794
795 /// \brief Build a new while statement.
796 ///
797 /// By default, performs semantic analysis to build the new statement.
798 /// Subclasses may override this routine to provide different behavior.
799 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000800 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000801 VarDecl *CondVar,
Douglas Gregor43959a92009-08-20 07:17:43 +0000802 StmtArg Body) {
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000803 return getSema().ActOnWhileStmt(WhileLoc, Cond,
Douglas Gregor586596f2010-05-06 17:25:47 +0000804 DeclPtrTy::make(CondVar), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000805 }
Mike Stump1eb44332009-09-09 15:08:12 +0000806
Douglas Gregor43959a92009-08-20 07:17:43 +0000807 /// \brief Build a new do-while statement.
808 ///
809 /// By default, performs semantic analysis to build the new statement.
810 /// Subclasses may override this routine to provide different behavior.
811 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
812 SourceLocation WhileLoc,
813 SourceLocation LParenLoc,
814 ExprArg Cond,
815 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000816 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000817 move(Cond), RParenLoc);
818 }
819
820 /// \brief Build a new for statement.
821 ///
822 /// By default, performs semantic analysis to build the new statement.
823 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000824 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000825 SourceLocation LParenLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000826 StmtArg Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000827 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000828 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000829 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000830 DeclPtrTy::make(CondVar),
831 Inc, RParenLoc, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000832 }
Mike Stump1eb44332009-09-09 15:08:12 +0000833
Douglas Gregor43959a92009-08-20 07:17:43 +0000834 /// \brief Build a new goto statement.
835 ///
836 /// By default, performs semantic analysis to build the new statement.
837 /// Subclasses may override this routine to provide different behavior.
838 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
839 SourceLocation LabelLoc,
840 LabelStmt *Label) {
841 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
842 }
843
844 /// \brief Build a new indirect goto statement.
845 ///
846 /// By default, performs semantic analysis to build the new statement.
847 /// Subclasses may override this routine to provide different behavior.
848 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
849 SourceLocation StarLoc,
850 ExprArg Target) {
851 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
852 }
Mike Stump1eb44332009-09-09 15:08:12 +0000853
Douglas Gregor43959a92009-08-20 07:17:43 +0000854 /// \brief Build a new return statement.
855 ///
856 /// By default, performs semantic analysis to build the new statement.
857 /// Subclasses may override this routine to provide different behavior.
858 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
859 ExprArg Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000860
Douglas Gregor43959a92009-08-20 07:17:43 +0000861 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
862 }
Mike Stump1eb44332009-09-09 15:08:12 +0000863
Douglas Gregor43959a92009-08-20 07:17:43 +0000864 /// \brief Build a new declaration statement.
865 ///
866 /// By default, performs semantic analysis to build the new statement.
867 /// Subclasses may override this routine to provide different behavior.
868 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000869 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000870 SourceLocation EndLoc) {
871 return getSema().Owned(
872 new (getSema().Context) DeclStmt(
873 DeclGroupRef::Create(getSema().Context,
874 Decls, NumDecls),
875 StartLoc, EndLoc));
876 }
Mike Stump1eb44332009-09-09 15:08:12 +0000877
Anders Carlsson703e3942010-01-24 05:50:09 +0000878 /// \brief Build a new inline asm statement.
879 ///
880 /// By default, performs semantic analysis to build the new statement.
881 /// Subclasses may override this routine to provide different behavior.
882 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
883 bool IsSimple,
884 bool IsVolatile,
885 unsigned NumOutputs,
886 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000887 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000888 MultiExprArg Constraints,
889 MultiExprArg Exprs,
890 ExprArg AsmString,
891 MultiExprArg Clobbers,
892 SourceLocation RParenLoc,
893 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +0000894 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +0000895 NumInputs, Names, move(Constraints),
896 move(Exprs), move(AsmString), move(Clobbers),
897 RParenLoc, MSAsm);
898 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000899
900 /// \brief Build a new Objective-C @try statement.
901 ///
902 /// By default, performs semantic analysis to build the new statement.
903 /// Subclasses may override this routine to provide different behavior.
904 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
905 StmtArg TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000906 MultiStmtArg CatchStmts,
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000907 StmtArg Finally) {
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000908 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts),
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000909 move(Finally));
910 }
911
Douglas Gregorbe270a02010-04-26 17:57:08 +0000912 /// \brief Rebuild an Objective-C exception declaration.
913 ///
914 /// By default, performs semantic analysis to build the new declaration.
915 /// Subclasses may override this routine to provide different behavior.
916 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
917 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +0000918 return getSema().BuildObjCExceptionDecl(TInfo, T,
919 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +0000920 ExceptionDecl->getLocation());
921 }
Sean Huntc3021132010-05-05 15:23:54 +0000922
Douglas Gregorbe270a02010-04-26 17:57:08 +0000923 /// \brief Build a new Objective-C @catch statement.
924 ///
925 /// By default, performs semantic analysis to build the new statement.
926 /// Subclasses may override this routine to provide different behavior.
927 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
928 SourceLocation RParenLoc,
929 VarDecl *Var,
930 StmtArg Body) {
931 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
932 Sema::DeclPtrTy::make(Var),
933 move(Body));
934 }
Sean Huntc3021132010-05-05 15:23:54 +0000935
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000936 /// \brief Build a new Objective-C @finally statement.
937 ///
938 /// By default, performs semantic analysis to build the new statement.
939 /// Subclasses may override this routine to provide different behavior.
940 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
941 StmtArg Body) {
942 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
943 }
Sean Huntc3021132010-05-05 15:23:54 +0000944
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000945 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +0000946 ///
947 /// By default, performs semantic analysis to build the new statement.
948 /// Subclasses may override this routine to provide different behavior.
949 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
950 ExprArg Operand) {
951 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
952 }
Sean Huntc3021132010-05-05 15:23:54 +0000953
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000954 /// \brief Build a new Objective-C @synchronized statement.
955 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000956 /// By default, performs semantic analysis to build the new statement.
957 /// Subclasses may override this routine to provide different behavior.
958 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
959 ExprArg Object,
960 StmtArg Body) {
961 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
962 move(Body));
963 }
Douglas Gregorc3203e72010-04-22 23:10:45 +0000964
965 /// \brief Build a new Objective-C fast enumeration statement.
966 ///
967 /// By default, performs semantic analysis to build the new statement.
968 /// Subclasses may override this routine to provide different behavior.
969 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
970 SourceLocation LParenLoc,
971 StmtArg Element,
972 ExprArg Collection,
973 SourceLocation RParenLoc,
974 StmtArg Body) {
975 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
Sean Huntc3021132010-05-05 15:23:54 +0000976 move(Element),
Douglas Gregorc3203e72010-04-22 23:10:45 +0000977 move(Collection),
978 RParenLoc,
979 move(Body));
980 }
Sean Huntc3021132010-05-05 15:23:54 +0000981
Douglas Gregor43959a92009-08-20 07:17:43 +0000982 /// \brief Build a new C++ exception declaration.
983 ///
984 /// By default, performs semantic analysis to build the new decaration.
985 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000986 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000987 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000988 IdentifierInfo *Name,
989 SourceLocation Loc,
990 SourceRange TypeRange) {
Mike Stump1eb44332009-09-09 15:08:12 +0000991 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000992 TypeRange);
993 }
994
995 /// \brief Build a new C++ catch statement.
996 ///
997 /// By default, performs semantic analysis to build the new statement.
998 /// Subclasses may override this routine to provide different behavior.
999 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1000 VarDecl *ExceptionDecl,
1001 StmtArg Handler) {
1002 return getSema().Owned(
Mike Stump1eb44332009-09-09 15:08:12 +00001003 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregor43959a92009-08-20 07:17:43 +00001004 Handler.takeAs<Stmt>()));
1005 }
Mike Stump1eb44332009-09-09 15:08:12 +00001006
Douglas Gregor43959a92009-08-20 07:17:43 +00001007 /// \brief Build a new C++ try statement.
1008 ///
1009 /// By default, performs semantic analysis to build the new statement.
1010 /// Subclasses may override this routine to provide different behavior.
1011 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1012 StmtArg TryBlock,
1013 MultiStmtArg Handlers) {
1014 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
1015 }
Mike Stump1eb44332009-09-09 15:08:12 +00001016
Douglas Gregorb98b1992009-08-11 05:31:07 +00001017 /// \brief Build a new expression that references a declaration.
1018 ///
1019 /// By default, performs semantic analysis to build the new expression.
1020 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001021 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1022 LookupResult &R,
1023 bool RequiresADL) {
1024 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1025 }
1026
1027
1028 /// \brief Build a new expression that references a declaration.
1029 ///
1030 /// By default, performs semantic analysis to build the new expression.
1031 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora2813ce2009-10-23 18:54:35 +00001032 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1033 SourceRange QualifierRange,
John McCalldbd872f2009-12-08 09:08:17 +00001034 ValueDecl *VD, SourceLocation Loc,
1035 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001036 CXXScopeSpec SS;
1037 SS.setScopeRep(Qualifier);
1038 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001039
1040 // FIXME: loses template args.
Sean Huntc3021132010-05-05 15:23:54 +00001041
John McCalldbd872f2009-12-08 09:08:17 +00001042 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001043 }
Mike Stump1eb44332009-09-09 15:08:12 +00001044
Douglas Gregorb98b1992009-08-11 05:31:07 +00001045 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001046 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001047 /// By default, performs semantic analysis to build the new expression.
1048 /// Subclasses may override this routine to provide different behavior.
1049 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1050 SourceLocation RParen) {
1051 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1052 }
1053
Douglas Gregora71d8192009-09-04 17:36:40 +00001054 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001055 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001056 /// By default, performs semantic analysis to build the new expression.
1057 /// Subclasses may override this routine to provide different behavior.
1058 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1059 SourceLocation OperatorLoc,
1060 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001061 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001062 SourceRange QualifierRange,
1063 TypeSourceInfo *ScopeType,
1064 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001065 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001066 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001067
Douglas Gregorb98b1992009-08-11 05:31:07 +00001068 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001069 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001070 /// By default, performs semantic analysis to build the new expression.
1071 /// Subclasses may override this routine to provide different behavior.
1072 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1073 UnaryOperator::Opcode Opc,
1074 ExprArg SubExpr) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001075 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001076 }
Mike Stump1eb44332009-09-09 15:08:12 +00001077
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001078 /// \brief Build a new builtin offsetof expression.
1079 ///
1080 /// By default, performs semantic analysis to build the new expression.
1081 /// Subclasses may override this routine to provide different behavior.
1082 OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1083 TypeSourceInfo *Type,
1084 Action::OffsetOfComponent *Components,
1085 unsigned NumComponents,
1086 SourceLocation RParenLoc) {
1087 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1088 NumComponents, RParenLoc);
1089 }
Sean Huntc3021132010-05-05 15:23:54 +00001090
Douglas Gregorb98b1992009-08-11 05:31:07 +00001091 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001092 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001093 /// By default, performs semantic analysis to build the new expression.
1094 /// Subclasses may override this routine to provide different behavior.
John McCalla93c9342009-12-07 02:54:59 +00001095 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001096 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001097 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001098 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001099 }
1100
Mike Stump1eb44332009-09-09 15:08:12 +00001101 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001102 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001103 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001104 /// By default, performs semantic analysis to build the new expression.
1105 /// Subclasses may override this routine to provide different behavior.
1106 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1107 bool isSizeOf, SourceRange R) {
Mike Stump1eb44332009-09-09 15:08:12 +00001108 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001109 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1110 OpLoc, isSizeOf, R);
1111 if (Result.isInvalid())
1112 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001113
Douglas Gregorb98b1992009-08-11 05:31:07 +00001114 SubExpr.release();
1115 return move(Result);
1116 }
Mike Stump1eb44332009-09-09 15:08:12 +00001117
Douglas Gregorb98b1992009-08-11 05:31:07 +00001118 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001119 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001120 /// By default, performs semantic analysis to build the new expression.
1121 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001122 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001123 SourceLocation LBracketLoc,
1124 ExprArg RHS,
1125 SourceLocation RBracketLoc) {
1126 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump1eb44332009-09-09 15:08:12 +00001127 LBracketLoc, move(RHS),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001128 RBracketLoc);
1129 }
1130
1131 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001132 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001133 /// By default, performs semantic analysis to build the new expression.
1134 /// Subclasses may override this routine to provide different behavior.
1135 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1136 MultiExprArg Args,
1137 SourceLocation *CommaLocs,
1138 SourceLocation RParenLoc) {
1139 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1140 move(Args), CommaLocs, RParenLoc);
1141 }
1142
1143 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001144 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001145 /// By default, performs semantic analysis to build the new expression.
1146 /// Subclasses may override this routine to provide different behavior.
1147 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001148 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001149 NestedNameSpecifier *Qualifier,
1150 SourceRange QualifierRange,
1151 SourceLocation MemberLoc,
Eli Friedmanf595cc42009-12-04 06:40:45 +00001152 ValueDecl *Member,
John McCall6bb80172010-03-30 21:47:33 +00001153 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001154 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +00001155 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001156 if (!Member->getDeclName()) {
1157 // We have a reference to an unnamed field.
1158 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +00001159
Douglas Gregor83a56c42009-12-24 20:02:50 +00001160 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall6bb80172010-03-30 21:47:33 +00001161 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1162 FoundDecl, Member))
Douglas Gregor83a56c42009-12-24 20:02:50 +00001163 return getSema().ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001164
Mike Stump1eb44332009-09-09 15:08:12 +00001165 MemberExpr *ME =
Douglas Gregor83a56c42009-12-24 20:02:50 +00001166 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlssond8b285f2009-09-01 04:26:58 +00001167 Member, MemberLoc,
1168 cast<FieldDecl>(Member)->getType());
1169 return getSema().Owned(ME);
1170 }
Mike Stump1eb44332009-09-09 15:08:12 +00001171
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001172 CXXScopeSpec SS;
1173 if (Qualifier) {
1174 SS.setRange(QualifierRange);
1175 SS.setScopeRep(Qualifier);
1176 }
1177
Douglas Gregor83c9abc2010-06-22 02:41:05 +00001178 Expr *BaseExpr = Base.takeAs<Expr>();
1179 getSema().DefaultFunctionArrayConversion(BaseExpr);
1180 QualType BaseType = BaseExpr->getType();
John McCallaa81e162009-12-01 22:10:20 +00001181
John McCall6bb80172010-03-30 21:47:33 +00001182 // FIXME: this involves duplicating earlier analysis in a lot of
1183 // cases; we should avoid this when possible.
John McCallc2233c52010-01-15 08:34:02 +00001184 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1185 Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001186 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001187 R.resolveKind();
1188
Douglas Gregor83c9abc2010-06-22 02:41:05 +00001189 return getSema().BuildMemberReferenceExpr(getSema().Owned(BaseExpr),
1190 BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001191 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001192 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001193 }
Mike Stump1eb44332009-09-09 15:08:12 +00001194
Douglas Gregorb98b1992009-08-11 05:31:07 +00001195 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001196 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001197 /// By default, performs semantic analysis to build the new expression.
1198 /// Subclasses may override this routine to provide different behavior.
1199 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1200 BinaryOperator::Opcode Opc,
1201 ExprArg LHS, ExprArg RHS) {
Sean Huntc3021132010-05-05 15:23:54 +00001202 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001203 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregorb98b1992009-08-11 05:31:07 +00001204 }
1205
1206 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001207 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001208 /// By default, performs semantic analysis to build the new expression.
1209 /// Subclasses may override this routine to provide different behavior.
1210 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1211 SourceLocation QuestionLoc,
1212 ExprArg LHS,
1213 SourceLocation ColonLoc,
1214 ExprArg RHS) {
Mike Stump1eb44332009-09-09 15:08:12 +00001215 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001216 move(LHS), move(RHS));
1217 }
1218
Douglas Gregorb98b1992009-08-11 05:31:07 +00001219 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001220 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001221 /// By default, performs semantic analysis to build the new expression.
1222 /// Subclasses may override this routine to provide different behavior.
John McCall9d125032010-01-15 18:39:57 +00001223 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1224 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001225 SourceLocation RParenLoc,
1226 ExprArg SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001227 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1228 move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001229 }
Mike Stump1eb44332009-09-09 15:08:12 +00001230
Douglas Gregorb98b1992009-08-11 05:31:07 +00001231 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001232 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001233 /// By default, performs semantic analysis to build the new expression.
1234 /// Subclasses may override this routine to provide different behavior.
1235 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001236 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001237 SourceLocation RParenLoc,
1238 ExprArg Init) {
John McCall42f56b52010-01-18 19:35:47 +00001239 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1240 move(Init));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001241 }
Mike Stump1eb44332009-09-09 15:08:12 +00001242
Douglas Gregorb98b1992009-08-11 05:31:07 +00001243 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001244 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001245 /// By default, performs semantic analysis to build the new expression.
1246 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001247 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001248 SourceLocation OpLoc,
1249 SourceLocation AccessorLoc,
1250 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001251
John McCall129e2df2009-11-30 22:42:35 +00001252 CXXScopeSpec SS;
John McCallaa81e162009-12-01 22:10:20 +00001253 QualType BaseType = ((Expr*) Base.get())->getType();
1254 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001255 OpLoc, /*IsArrow*/ false,
1256 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor2d1c2142009-11-03 19:44:04 +00001257 DeclarationName(&Accessor),
John McCall129e2df2009-11-30 22:42:35 +00001258 AccessorLoc,
1259 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001260 }
Mike Stump1eb44332009-09-09 15:08:12 +00001261
Douglas Gregorb98b1992009-08-11 05:31:07 +00001262 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001263 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001264 /// By default, performs semantic analysis to build the new expression.
1265 /// Subclasses may override this routine to provide different behavior.
1266 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1267 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001268 SourceLocation RBraceLoc,
1269 QualType ResultTy) {
1270 OwningExprResult Result
1271 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1272 if (Result.isInvalid() || ResultTy->isDependentType())
1273 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001274
Douglas Gregore48319a2009-11-09 17:16:50 +00001275 // Patch in the result type we were given, which may have been computed
1276 // when the initial InitListExpr was built.
1277 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1278 ILE->setType(ResultTy);
1279 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001280 }
Mike Stump1eb44332009-09-09 15:08:12 +00001281
Douglas Gregorb98b1992009-08-11 05:31:07 +00001282 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001283 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001284 /// By default, performs semantic analysis to build the new expression.
1285 /// Subclasses may override this routine to provide different behavior.
1286 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1287 MultiExprArg ArrayExprs,
1288 SourceLocation EqualOrColonLoc,
1289 bool GNUSyntax,
1290 ExprArg Init) {
1291 OwningExprResult Result
1292 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1293 move(Init));
1294 if (Result.isInvalid())
1295 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001296
Douglas Gregorb98b1992009-08-11 05:31:07 +00001297 ArrayExprs.release();
1298 return move(Result);
1299 }
Mike Stump1eb44332009-09-09 15:08:12 +00001300
Douglas Gregorb98b1992009-08-11 05:31:07 +00001301 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001302 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001303 /// By default, builds the implicit value initialization without performing
1304 /// any semantic analysis. Subclasses may override this routine to provide
1305 /// different behavior.
1306 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1307 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1308 }
Mike Stump1eb44332009-09-09 15:08:12 +00001309
Douglas Gregorb98b1992009-08-11 05:31:07 +00001310 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001311 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001314 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
1315 ExprArg SubExpr, TypeSourceInfo *TInfo,
1316 SourceLocation RParenLoc) {
1317 return getSema().BuildVAArgExpr(BuiltinLoc,
1318 move(SubExpr), TInfo,
1319 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001320 }
1321
1322 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001323 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001324 /// By default, performs semantic analysis to build the new expression.
1325 /// Subclasses may override this routine to provide different behavior.
1326 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1327 MultiExprArg SubExprs,
1328 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001329 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001330 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001331 }
Mike Stump1eb44332009-09-09 15:08:12 +00001332
Douglas Gregorb98b1992009-08-11 05:31:07 +00001333 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001334 ///
1335 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001336 /// rather than attempting to map the label statement itself.
1337 /// Subclasses may override this routine to provide different behavior.
1338 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1339 SourceLocation LabelLoc,
1340 LabelStmt *Label) {
1341 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1342 }
Mike Stump1eb44332009-09-09 15:08:12 +00001343
Douglas Gregorb98b1992009-08-11 05:31:07 +00001344 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001345 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001346 /// By default, performs semantic analysis to build the new expression.
1347 /// Subclasses may override this routine to provide different behavior.
1348 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1349 StmtArg SubStmt,
1350 SourceLocation RParenLoc) {
1351 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1352 }
Mike Stump1eb44332009-09-09 15:08:12 +00001353
Douglas Gregorb98b1992009-08-11 05:31:07 +00001354 /// \brief Build a new __builtin_types_compatible_p expression.
1355 ///
1356 /// By default, performs semantic analysis to build the new expression.
1357 /// Subclasses may override this routine to provide different behavior.
1358 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001359 TypeSourceInfo *TInfo1,
1360 TypeSourceInfo *TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001361 SourceLocation RParenLoc) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001362 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1363 TInfo1, TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001364 RParenLoc);
1365 }
Mike Stump1eb44332009-09-09 15:08:12 +00001366
Douglas Gregorb98b1992009-08-11 05:31:07 +00001367 /// \brief Build a new __builtin_choose_expr expression.
1368 ///
1369 /// By default, performs semantic analysis to build the new expression.
1370 /// Subclasses may override this routine to provide different behavior.
1371 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1372 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1373 SourceLocation RParenLoc) {
1374 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1375 move(Cond), move(LHS), move(RHS),
1376 RParenLoc);
1377 }
Mike Stump1eb44332009-09-09 15:08:12 +00001378
Douglas Gregorb98b1992009-08-11 05:31:07 +00001379 /// \brief Build a new overloaded operator call expression.
1380 ///
1381 /// By default, performs semantic analysis to build the new expression.
1382 /// The semantic analysis provides the behavior of template instantiation,
1383 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001384 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001385 /// argument-dependent lookup, etc. Subclasses may override this routine to
1386 /// provide different behavior.
1387 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1388 SourceLocation OpLoc,
1389 ExprArg Callee,
1390 ExprArg First,
1391 ExprArg Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001392
1393 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001394 /// reinterpret_cast.
1395 ///
1396 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001397 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001398 /// Subclasses may override this routine to provide different behavior.
1399 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1400 Stmt::StmtClass Class,
1401 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001402 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001403 SourceLocation RAngleLoc,
1404 SourceLocation LParenLoc,
1405 ExprArg SubExpr,
1406 SourceLocation RParenLoc) {
1407 switch (Class) {
1408 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001409 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001410 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001411 move(SubExpr), RParenLoc);
1412
1413 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001414 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001415 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001416 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001417
Douglas Gregorb98b1992009-08-11 05:31:07 +00001418 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001419 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001420 RAngleLoc, LParenLoc,
1421 move(SubExpr),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001422 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001423
Douglas Gregorb98b1992009-08-11 05:31:07 +00001424 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001425 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001426 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001427 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001428
Douglas Gregorb98b1992009-08-11 05:31:07 +00001429 default:
1430 assert(false && "Invalid C++ named cast");
1431 break;
1432 }
Mike Stump1eb44332009-09-09 15:08:12 +00001433
Douglas Gregorb98b1992009-08-11 05:31:07 +00001434 return getSema().ExprError();
1435 }
Mike Stump1eb44332009-09-09 15:08:12 +00001436
Douglas Gregorb98b1992009-08-11 05:31:07 +00001437 /// \brief Build a new C++ static_cast expression.
1438 ///
1439 /// By default, performs semantic analysis to build the new expression.
1440 /// Subclasses may override this routine to provide different behavior.
1441 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1442 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001443 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001444 SourceLocation RAngleLoc,
1445 SourceLocation LParenLoc,
1446 ExprArg SubExpr,
1447 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001448 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1449 TInfo, move(SubExpr),
1450 SourceRange(LAngleLoc, RAngleLoc),
1451 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001452 }
1453
1454 /// \brief Build a new C++ dynamic_cast expression.
1455 ///
1456 /// By default, performs semantic analysis to build the new expression.
1457 /// Subclasses may override this routine to provide different behavior.
1458 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1459 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001460 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001461 SourceLocation RAngleLoc,
1462 SourceLocation LParenLoc,
1463 ExprArg SubExpr,
1464 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001465 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1466 TInfo, move(SubExpr),
1467 SourceRange(LAngleLoc, RAngleLoc),
1468 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001469 }
1470
1471 /// \brief Build a new C++ reinterpret_cast expression.
1472 ///
1473 /// By default, performs semantic analysis to build the new expression.
1474 /// Subclasses may override this routine to provide different behavior.
1475 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1476 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001477 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001478 SourceLocation RAngleLoc,
1479 SourceLocation LParenLoc,
1480 ExprArg SubExpr,
1481 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001482 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1483 TInfo, move(SubExpr),
1484 SourceRange(LAngleLoc, RAngleLoc),
1485 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001486 }
1487
1488 /// \brief Build a new C++ const_cast expression.
1489 ///
1490 /// By default, performs semantic analysis to build the new expression.
1491 /// Subclasses may override this routine to provide different behavior.
1492 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1493 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001494 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 SourceLocation RAngleLoc,
1496 SourceLocation LParenLoc,
1497 ExprArg SubExpr,
1498 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001499 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1500 TInfo, move(SubExpr),
1501 SourceRange(LAngleLoc, RAngleLoc),
1502 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 }
Mike Stump1eb44332009-09-09 15:08:12 +00001504
Douglas Gregorb98b1992009-08-11 05:31:07 +00001505 /// \brief Build a new C++ functional-style cast expression.
1506 ///
1507 /// By default, performs semantic analysis to build the new expression.
1508 /// Subclasses may override this routine to provide different behavior.
1509 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001510 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001511 SourceLocation LParenLoc,
1512 ExprArg SubExpr,
1513 SourceLocation RParenLoc) {
Chris Lattner88650c32009-08-24 05:19:01 +00001514 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001516 TInfo->getType().getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001517 LParenLoc,
Chris Lattner88650c32009-08-24 05:19:01 +00001518 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump1eb44332009-09-09 15:08:12 +00001519 /*CommaLocs=*/0,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001520 RParenLoc);
1521 }
Mike Stump1eb44332009-09-09 15:08:12 +00001522
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 /// \brief Build a new C++ typeid(type) expression.
1524 ///
1525 /// By default, performs semantic analysis to build the new expression.
1526 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001527 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1528 SourceLocation TypeidLoc,
1529 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001530 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001531 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001532 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001533 }
Mike Stump1eb44332009-09-09 15:08:12 +00001534
Douglas Gregorb98b1992009-08-11 05:31:07 +00001535 /// \brief Build a new C++ typeid(expr) expression.
1536 ///
1537 /// By default, performs semantic analysis to build the new expression.
1538 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001539 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1540 SourceLocation TypeidLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001541 ExprArg Operand,
1542 SourceLocation RParenLoc) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001543 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand),
1544 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001545 }
1546
Douglas Gregorb98b1992009-08-11 05:31:07 +00001547 /// \brief Build a new C++ "this" expression.
1548 ///
1549 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001550 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001551 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001552 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001553 QualType ThisType,
1554 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001555 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001556 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1557 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001558 }
1559
1560 /// \brief Build a new C++ throw expression.
1561 ///
1562 /// By default, performs semantic analysis to build the new expression.
1563 /// Subclasses may override this routine to provide different behavior.
1564 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1565 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1566 }
1567
1568 /// \brief Build a new C++ default-argument expression.
1569 ///
1570 /// By default, builds a new default-argument expression, which does not
1571 /// require any semantic analysis. Subclasses may override this routine to
1572 /// provide different behavior.
Sean Huntc3021132010-05-05 15:23:54 +00001573 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001574 ParmVarDecl *Param) {
1575 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1576 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001577 }
1578
1579 /// \brief Build a new C++ zero-initialization expression.
1580 ///
1581 /// By default, performs semantic analysis to build the new expression.
1582 /// Subclasses may override this routine to provide different behavior.
Douglas Gregored8abf12010-07-08 06:14:04 +00001583 OwningExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001584 SourceLocation LParenLoc,
1585 QualType T,
1586 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001587 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1588 T.getAsOpaquePtr(), LParenLoc,
1589 MultiExprArg(getSema(), 0, 0),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 0, RParenLoc);
1591 }
Mike Stump1eb44332009-09-09 15:08:12 +00001592
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 /// \brief Build a new C++ "new" expression.
1594 ///
1595 /// By default, performs semantic analysis to build the new expression.
1596 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001597 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001598 bool UseGlobal,
1599 SourceLocation PlacementLParen,
1600 MultiExprArg PlacementArgs,
1601 SourceLocation PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001602 SourceRange TypeIdParens,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 QualType AllocType,
1604 SourceLocation TypeLoc,
1605 SourceRange TypeRange,
1606 ExprArg ArraySize,
1607 SourceLocation ConstructorLParen,
1608 MultiExprArg ConstructorArgs,
1609 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001610 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001611 PlacementLParen,
1612 move(PlacementArgs),
1613 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001614 TypeIdParens,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001615 AllocType,
1616 TypeLoc,
1617 TypeRange,
1618 move(ArraySize),
1619 ConstructorLParen,
1620 move(ConstructorArgs),
1621 ConstructorRParen);
1622 }
Mike Stump1eb44332009-09-09 15:08:12 +00001623
Douglas Gregorb98b1992009-08-11 05:31:07 +00001624 /// \brief Build a new C++ "delete" expression.
1625 ///
1626 /// By default, performs semantic analysis to build the new expression.
1627 /// Subclasses may override this routine to provide different behavior.
1628 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1629 bool IsGlobalDelete,
1630 bool IsArrayForm,
1631 ExprArg Operand) {
1632 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1633 move(Operand));
1634 }
Mike Stump1eb44332009-09-09 15:08:12 +00001635
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 /// \brief Build a new unary type trait expression.
1637 ///
1638 /// By default, performs semantic analysis to build the new expression.
1639 /// Subclasses may override this routine to provide different behavior.
1640 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1641 SourceLocation StartLoc,
1642 SourceLocation LParenLoc,
1643 QualType T,
1644 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001645 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 T.getAsOpaquePtr(), RParenLoc);
1647 }
1648
Mike Stump1eb44332009-09-09 15:08:12 +00001649 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001650 /// expression.
1651 ///
1652 /// By default, performs semantic analysis to build the new expression.
1653 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001654 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 SourceRange QualifierRange,
1656 DeclarationName Name,
1657 SourceLocation Location,
John McCallf7a1a742009-11-24 19:00:30 +00001658 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 CXXScopeSpec SS;
1660 SS.setRange(QualifierRange);
1661 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001662
1663 if (TemplateArgs)
1664 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1665 *TemplateArgs);
1666
1667 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 }
1669
1670 /// \brief Build a new template-id expression.
1671 ///
1672 /// By default, performs semantic analysis to build the new expression.
1673 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001674 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1675 LookupResult &R,
1676 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001677 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001678 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 }
1680
1681 /// \brief Build a new object-construction expression.
1682 ///
1683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
1685 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001686 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 CXXConstructorDecl *Constructor,
1688 bool IsElidable,
1689 MultiExprArg Args) {
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001690 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001691 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001692 ConvertedArgs))
1693 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001694
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001695 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1696 move_arg(ConvertedArgs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 }
1698
1699 /// \brief Build a new object-construction expression.
1700 ///
1701 /// By default, performs semantic analysis to build the new expression.
1702 /// Subclasses may override this routine to provide different behavior.
1703 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1704 QualType T,
1705 SourceLocation LParenLoc,
1706 MultiExprArg Args,
1707 SourceLocation *Commas,
1708 SourceLocation RParenLoc) {
1709 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1710 T.getAsOpaquePtr(),
1711 LParenLoc,
1712 move(Args),
1713 Commas,
1714 RParenLoc);
1715 }
1716
1717 /// \brief Build a new object-construction expression.
1718 ///
1719 /// By default, performs semantic analysis to build the new expression.
1720 /// Subclasses may override this routine to provide different behavior.
1721 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1722 QualType T,
1723 SourceLocation LParenLoc,
1724 MultiExprArg Args,
1725 SourceLocation *Commas,
1726 SourceLocation RParenLoc) {
1727 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1728 /*FIXME*/LParenLoc),
1729 T.getAsOpaquePtr(),
1730 LParenLoc,
1731 move(Args),
1732 Commas,
1733 RParenLoc);
1734 }
Mike Stump1eb44332009-09-09 15:08:12 +00001735
Douglas Gregorb98b1992009-08-11 05:31:07 +00001736 /// \brief Build a new member reference expression.
1737 ///
1738 /// By default, performs semantic analysis to build the new expression.
1739 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001740 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001741 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001742 bool IsArrow,
1743 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001744 NestedNameSpecifier *Qualifier,
1745 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001746 NamedDecl *FirstQualifierInScope,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001747 DeclarationName Name,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001748 SourceLocation MemberLoc,
John McCall129e2df2009-11-30 22:42:35 +00001749 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001751 SS.setRange(QualifierRange);
1752 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001753
John McCallaa81e162009-12-01 22:10:20 +00001754 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1755 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001756 SS, FirstQualifierInScope,
1757 Name, MemberLoc, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001758 }
1759
John McCall129e2df2009-11-30 22:42:35 +00001760 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001761 ///
1762 /// By default, performs semantic analysis to build the new expression.
1763 /// Subclasses may override this routine to provide different behavior.
John McCall129e2df2009-11-30 22:42:35 +00001764 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001765 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001766 SourceLocation OperatorLoc,
1767 bool IsArrow,
1768 NestedNameSpecifier *Qualifier,
1769 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001770 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001771 LookupResult &R,
1772 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001773 CXXScopeSpec SS;
1774 SS.setRange(QualifierRange);
1775 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001776
John McCallaa81e162009-12-01 22:10:20 +00001777 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1778 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001779 SS, FirstQualifierInScope,
1780 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001781 }
Mike Stump1eb44332009-09-09 15:08:12 +00001782
Douglas Gregorb98b1992009-08-11 05:31:07 +00001783 /// \brief Build a new Objective-C @encode expression.
1784 ///
1785 /// By default, performs semantic analysis to build the new expression.
1786 /// Subclasses may override this routine to provide different behavior.
1787 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001788 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001790 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001792 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793
Douglas Gregor92e986e2010-04-22 16:44:27 +00001794 /// \brief Build a new Objective-C class message.
1795 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1796 Selector Sel,
1797 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001798 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001799 MultiExprArg Args,
1800 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001801 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1802 ReceiverTypeInfo->getType(),
1803 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001804 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001805 move(Args));
1806 }
1807
1808 /// \brief Build a new Objective-C instance message.
1809 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1810 Selector Sel,
1811 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001812 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001813 MultiExprArg Args,
1814 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001815 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1816 return SemaRef.BuildInstanceMessage(move(Receiver),
1817 ReceiverType,
1818 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001819 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001820 move(Args));
1821 }
1822
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001823 /// \brief Build a new Objective-C ivar reference expression.
1824 ///
1825 /// By default, performs semantic analysis to build the new expression.
1826 /// Subclasses may override this routine to provide different behavior.
1827 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1828 SourceLocation IvarLoc,
1829 bool IsArrow, bool IsFreeIvar) {
1830 // FIXME: We lose track of the IsFreeIvar bit.
1831 CXXScopeSpec SS;
1832 Expr *Base = BaseArg.takeAs<Expr>();
1833 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1834 Sema::LookupMemberName);
1835 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1836 /*FIME:*/IvarLoc,
John McCallad00b772010-06-16 08:42:20 +00001837 SS, DeclPtrTy(),
1838 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001839 if (Result.isInvalid())
1840 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001841
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001842 if (Result.get())
1843 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001844
1845 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001846 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001847 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001848 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001849 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001850 /*TemplateArgs=*/0);
1851 }
Douglas Gregore3303542010-04-26 20:47:02 +00001852
1853 /// \brief Build a new Objective-C property reference expression.
1854 ///
1855 /// By default, performs semantic analysis to build the new expression.
1856 /// Subclasses may override this routine to provide different behavior.
Sean Huntc3021132010-05-05 15:23:54 +00001857 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00001858 ObjCPropertyDecl *Property,
1859 SourceLocation PropertyLoc) {
1860 CXXScopeSpec SS;
1861 Expr *Base = BaseArg.takeAs<Expr>();
1862 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1863 Sema::LookupMemberName);
1864 bool IsArrow = false;
1865 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1866 /*FIME:*/PropertyLoc,
John McCallad00b772010-06-16 08:42:20 +00001867 SS, DeclPtrTy(),
1868 false);
Douglas Gregore3303542010-04-26 20:47:02 +00001869 if (Result.isInvalid())
1870 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001871
Douglas Gregore3303542010-04-26 20:47:02 +00001872 if (Result.get())
1873 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001874
1875 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregore3303542010-04-26 20:47:02 +00001876 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001877 /*FIXME:*/PropertyLoc, IsArrow,
1878 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00001879 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001880 R,
Douglas Gregore3303542010-04-26 20:47:02 +00001881 /*TemplateArgs=*/0);
1882 }
Sean Huntc3021132010-05-05 15:23:54 +00001883
1884 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001885 /// expression.
1886 ///
1887 /// By default, performs semantic analysis to build the new expression.
Sean Huntc3021132010-05-05 15:23:54 +00001888 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001889 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1890 ObjCMethodDecl *Getter,
1891 QualType T,
1892 ObjCMethodDecl *Setter,
1893 SourceLocation NameLoc,
1894 ExprArg Base) {
1895 // Since these expressions can only be value-dependent, we do not need to
1896 // perform semantic analysis again.
1897 return getSema().Owned(
1898 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1899 Setter,
1900 NameLoc,
1901 Base.takeAs<Expr>()));
1902 }
1903
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001904 /// \brief Build a new Objective-C "isa" expression.
1905 ///
1906 /// By default, performs semantic analysis to build the new expression.
1907 /// Subclasses may override this routine to provide different behavior.
1908 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1909 bool IsArrow) {
1910 CXXScopeSpec SS;
1911 Expr *Base = BaseArg.takeAs<Expr>();
1912 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1913 Sema::LookupMemberName);
1914 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1915 /*FIME:*/IsaLoc,
John McCallad00b772010-06-16 08:42:20 +00001916 SS, DeclPtrTy(),
1917 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001918 if (Result.isInvalid())
1919 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001920
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001921 if (Result.get())
1922 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001923
1924 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001925 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001926 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001927 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001928 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001929 /*TemplateArgs=*/0);
1930 }
Sean Huntc3021132010-05-05 15:23:54 +00001931
Douglas Gregorb98b1992009-08-11 05:31:07 +00001932 /// \brief Build a new shuffle vector expression.
1933 ///
1934 /// By default, performs semantic analysis to build the new expression.
1935 /// Subclasses may override this routine to provide different behavior.
1936 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1937 MultiExprArg SubExprs,
1938 SourceLocation RParenLoc) {
1939 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001940 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001941 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1942 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1943 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1944 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001945
Douglas Gregorb98b1992009-08-11 05:31:07 +00001946 // Build a reference to the __builtin_shufflevector builtin
1947 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001948 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001949 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001950 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001951 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001952
1953 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001954 unsigned NumSubExprs = SubExprs.size();
1955 Expr **Subs = (Expr **)SubExprs.release();
1956 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1957 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00001958 Builtin->getCallResultType(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001959 RParenLoc);
1960 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001961
Douglas Gregorb98b1992009-08-11 05:31:07 +00001962 // Type-check the __builtin_shufflevector expression.
1963 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1964 if (Result.isInvalid())
1965 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001966
Douglas Gregorb98b1992009-08-11 05:31:07 +00001967 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001968 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001969 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001970};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001971
Douglas Gregor43959a92009-08-20 07:17:43 +00001972template<typename Derived>
1973Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1974 if (!S)
1975 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001976
Douglas Gregor43959a92009-08-20 07:17:43 +00001977 switch (S->getStmtClass()) {
1978 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001979
Douglas Gregor43959a92009-08-20 07:17:43 +00001980 // Transform individual statement nodes
1981#define STMT(Node, Parent) \
1982 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1983#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00001984#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00001985
Douglas Gregor43959a92009-08-20 07:17:43 +00001986 // Transform expressions by calling TransformExpr.
1987#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00001988#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00001989#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00001990#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00001991 {
1992 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1993 if (E.isInvalid())
1994 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001995
Anders Carlsson5ee56e92009-12-16 02:09:40 +00001996 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregor43959a92009-08-20 07:17:43 +00001997 }
Mike Stump1eb44332009-09-09 15:08:12 +00001998 }
1999
Douglas Gregor43959a92009-08-20 07:17:43 +00002000 return SemaRef.Owned(S->Retain());
2001}
Mike Stump1eb44332009-09-09 15:08:12 +00002002
2003
Douglas Gregor670444e2009-08-04 22:27:00 +00002004template<typename Derived>
John McCall454feb92009-12-08 09:21:05 +00002005Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002006 if (!E)
2007 return SemaRef.Owned(E);
2008
2009 switch (E->getStmtClass()) {
2010 case Stmt::NoStmtClass: break;
2011#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002012#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002013#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002014 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002015#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002016 }
2017
Douglas Gregorb98b1992009-08-11 05:31:07 +00002018 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002019}
2020
2021template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002022NestedNameSpecifier *
2023TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002024 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002025 QualType ObjectType,
2026 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00002027 if (!NNS)
2028 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002029
Douglas Gregor43959a92009-08-20 07:17:43 +00002030 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002031 NestedNameSpecifier *Prefix = NNS->getPrefix();
2032 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002033 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002034 ObjectType,
2035 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002036 if (!Prefix)
2037 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002038
2039 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00002040 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00002041 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00002042 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002043 }
Mike Stump1eb44332009-09-09 15:08:12 +00002044
Douglas Gregordcee1a12009-08-06 05:28:30 +00002045 switch (NNS->getKind()) {
2046 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00002047 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002048 "Identifier nested-name-specifier with no prefix or object type");
2049 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2050 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002051 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002052
2053 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002054 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002055 ObjectType,
2056 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002057
Douglas Gregordcee1a12009-08-06 05:28:30 +00002058 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002059 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002060 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002061 getDerived().TransformDecl(Range.getBegin(),
2062 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002063 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002064 Prefix == NNS->getPrefix() &&
2065 NS == NNS->getAsNamespace())
2066 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002067
Douglas Gregordcee1a12009-08-06 05:28:30 +00002068 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2069 }
Mike Stump1eb44332009-09-09 15:08:12 +00002070
Douglas Gregordcee1a12009-08-06 05:28:30 +00002071 case NestedNameSpecifier::Global:
2072 // There is no meaningful transformation that one could perform on the
2073 // global scope.
2074 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002075
Douglas Gregordcee1a12009-08-06 05:28:30 +00002076 case NestedNameSpecifier::TypeSpecWithTemplate:
2077 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002078 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor124b8782010-02-16 19:09:40 +00002079 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2080 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002081 if (T.isNull())
2082 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002083
Douglas Gregordcee1a12009-08-06 05:28:30 +00002084 if (!getDerived().AlwaysRebuild() &&
2085 Prefix == NNS->getPrefix() &&
2086 T == QualType(NNS->getAsType(), 0))
2087 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002088
2089 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2090 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002091 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002092 }
2093 }
Mike Stump1eb44332009-09-09 15:08:12 +00002094
Douglas Gregordcee1a12009-08-06 05:28:30 +00002095 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002096 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002097}
2098
2099template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002100DeclarationName
Douglas Gregor81499bb2009-09-03 22:13:48 +00002101TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +00002102 SourceLocation Loc,
2103 QualType ObjectType) {
Douglas Gregor81499bb2009-09-03 22:13:48 +00002104 if (!Name)
2105 return Name;
2106
2107 switch (Name.getNameKind()) {
2108 case DeclarationName::Identifier:
2109 case DeclarationName::ObjCZeroArgSelector:
2110 case DeclarationName::ObjCOneArgSelector:
2111 case DeclarationName::ObjCMultiArgSelector:
2112 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002113 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002114 case DeclarationName::CXXUsingDirective:
2115 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002116
Douglas Gregor81499bb2009-09-03 22:13:48 +00002117 case DeclarationName::CXXConstructorName:
2118 case DeclarationName::CXXDestructorName:
2119 case DeclarationName::CXXConversionFunctionName: {
2120 TemporaryBase Rebase(*this, Loc, Name);
Sean Huntc3021132010-05-05 15:23:54 +00002121 QualType T = getDerived().TransformType(Name.getCXXNameType(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002122 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00002123 if (T.isNull())
2124 return DeclarationName();
Mike Stump1eb44332009-09-09 15:08:12 +00002125
Douglas Gregor81499bb2009-09-03 22:13:48 +00002126 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump1eb44332009-09-09 15:08:12 +00002127 Name.getNameKind(),
Douglas Gregor81499bb2009-09-03 22:13:48 +00002128 SemaRef.Context.getCanonicalType(T));
Douglas Gregor81499bb2009-09-03 22:13:48 +00002129 }
Mike Stump1eb44332009-09-09 15:08:12 +00002130 }
2131
Douglas Gregor81499bb2009-09-03 22:13:48 +00002132 return DeclarationName();
2133}
2134
2135template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002136TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002137TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2138 QualType ObjectType) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002139 SourceLocation Loc = getDerived().getBaseLocation();
2140
Douglas Gregord1067e52009-08-06 06:41:21 +00002141 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002142 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002143 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002144 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2145 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002146 if (!NNS)
2147 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002148
Douglas Gregord1067e52009-08-06 06:41:21 +00002149 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002150 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002151 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002152 if (!TransTemplate)
2153 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002154
Douglas Gregord1067e52009-08-06 06:41:21 +00002155 if (!getDerived().AlwaysRebuild() &&
2156 NNS == QTN->getQualifier() &&
2157 TransTemplate == Template)
2158 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002159
Douglas Gregord1067e52009-08-06 06:41:21 +00002160 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2161 TransTemplate);
2162 }
Mike Stump1eb44332009-09-09 15:08:12 +00002163
John McCallf7a1a742009-11-24 19:00:30 +00002164 // These should be getting filtered out before they make it into the AST.
2165 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002166 }
Mike Stump1eb44332009-09-09 15:08:12 +00002167
Douglas Gregord1067e52009-08-06 06:41:21 +00002168 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002169 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002170 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002171 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2172 ObjectType);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002173 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00002174 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002175
Douglas Gregord1067e52009-08-06 06:41:21 +00002176 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002177 NNS == DTN->getQualifier() &&
2178 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002179 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002180
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002181 if (DTN->isIdentifier())
Sean Huntc3021132010-05-05 15:23:54 +00002182 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002183 ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +00002184
2185 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002186 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002187 }
Mike Stump1eb44332009-09-09 15:08:12 +00002188
Douglas Gregord1067e52009-08-06 06:41:21 +00002189 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002190 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002191 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002192 if (!TransTemplate)
2193 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002194
Douglas Gregord1067e52009-08-06 06:41:21 +00002195 if (!getDerived().AlwaysRebuild() &&
2196 TransTemplate == Template)
2197 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002198
Douglas Gregord1067e52009-08-06 06:41:21 +00002199 return TemplateName(TransTemplate);
2200 }
Mike Stump1eb44332009-09-09 15:08:12 +00002201
John McCallf7a1a742009-11-24 19:00:30 +00002202 // These should be getting filtered out before they reach the AST.
2203 assert(false && "overloaded function decl survived to here");
2204 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002205}
2206
2207template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002208void TreeTransform<Derived>::InventTemplateArgumentLoc(
2209 const TemplateArgument &Arg,
2210 TemplateArgumentLoc &Output) {
2211 SourceLocation Loc = getDerived().getBaseLocation();
2212 switch (Arg.getKind()) {
2213 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002214 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002215 break;
2216
2217 case TemplateArgument::Type:
2218 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002219 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002220
John McCall833ca992009-10-29 08:12:44 +00002221 break;
2222
Douglas Gregor788cd062009-11-11 01:00:40 +00002223 case TemplateArgument::Template:
2224 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2225 break;
Sean Huntc3021132010-05-05 15:23:54 +00002226
John McCall833ca992009-10-29 08:12:44 +00002227 case TemplateArgument::Expression:
2228 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2229 break;
2230
2231 case TemplateArgument::Declaration:
2232 case TemplateArgument::Integral:
2233 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002234 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002235 break;
2236 }
2237}
2238
2239template<typename Derived>
2240bool TreeTransform<Derived>::TransformTemplateArgument(
2241 const TemplateArgumentLoc &Input,
2242 TemplateArgumentLoc &Output) {
2243 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002244 switch (Arg.getKind()) {
2245 case TemplateArgument::Null:
2246 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002247 Output = Input;
2248 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002249
Douglas Gregor670444e2009-08-04 22:27:00 +00002250 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002251 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002252 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002253 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002254
2255 DI = getDerived().TransformType(DI);
2256 if (!DI) return true;
2257
2258 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2259 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002260 }
Mike Stump1eb44332009-09-09 15:08:12 +00002261
Douglas Gregor670444e2009-08-04 22:27:00 +00002262 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002263 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002264 DeclarationName Name;
2265 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2266 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002267 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002268 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002269 if (!D) return true;
2270
John McCall828bff22009-10-29 18:45:58 +00002271 Expr *SourceExpr = Input.getSourceDeclExpression();
2272 if (SourceExpr) {
2273 EnterExpressionEvaluationContext Unevaluated(getSema(),
2274 Action::Unevaluated);
2275 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2276 if (E.isInvalid())
2277 SourceExpr = NULL;
2278 else {
2279 SourceExpr = E.takeAs<Expr>();
2280 SourceExpr->Retain();
2281 }
2282 }
2283
2284 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002285 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002286 }
Mike Stump1eb44332009-09-09 15:08:12 +00002287
Douglas Gregor788cd062009-11-11 01:00:40 +00002288 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002289 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002290 TemplateName Template
2291 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2292 if (Template.isNull())
2293 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002294
Douglas Gregor788cd062009-11-11 01:00:40 +00002295 Output = TemplateArgumentLoc(TemplateArgument(Template),
2296 Input.getTemplateQualifierRange(),
2297 Input.getTemplateNameLoc());
2298 return false;
2299 }
Sean Huntc3021132010-05-05 15:23:54 +00002300
Douglas Gregor670444e2009-08-04 22:27:00 +00002301 case TemplateArgument::Expression: {
2302 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002303 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002304 Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002305
John McCall833ca992009-10-29 08:12:44 +00002306 Expr *InputExpr = Input.getSourceExpression();
2307 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2308
2309 Sema::OwningExprResult E
2310 = getDerived().TransformExpr(InputExpr);
2311 if (E.isInvalid()) return true;
2312
2313 Expr *ETaken = E.takeAs<Expr>();
John McCall828bff22009-10-29 18:45:58 +00002314 ETaken->Retain();
John McCall833ca992009-10-29 08:12:44 +00002315 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2316 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002317 }
Mike Stump1eb44332009-09-09 15:08:12 +00002318
Douglas Gregor670444e2009-08-04 22:27:00 +00002319 case TemplateArgument::Pack: {
2320 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2321 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002322 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002323 AEnd = Arg.pack_end();
2324 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002325
John McCall833ca992009-10-29 08:12:44 +00002326 // FIXME: preserve source information here when we start
2327 // caring about parameter packs.
2328
John McCall828bff22009-10-29 18:45:58 +00002329 TemplateArgumentLoc InputArg;
2330 TemplateArgumentLoc OutputArg;
2331 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2332 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002333 return true;
2334
John McCall828bff22009-10-29 18:45:58 +00002335 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002336 }
2337 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002338 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002339 true);
John McCall828bff22009-10-29 18:45:58 +00002340 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002341 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002342 }
2343 }
Mike Stump1eb44332009-09-09 15:08:12 +00002344
Douglas Gregor670444e2009-08-04 22:27:00 +00002345 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002346 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002347}
2348
Douglas Gregor577f75a2009-08-04 16:50:30 +00002349//===----------------------------------------------------------------------===//
2350// Type transformation
2351//===----------------------------------------------------------------------===//
2352
2353template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00002354QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregor124b8782010-02-16 19:09:40 +00002355 QualType ObjectType) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002356 if (getDerived().AlreadyTransformed(T))
2357 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002358
John McCalla2becad2009-10-21 00:40:46 +00002359 // Temporary workaround. All of these transformations should
2360 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002361 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002362 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002363
Douglas Gregor124b8782010-02-16 19:09:40 +00002364 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall0953e762009-09-24 19:53:00 +00002365
John McCalla2becad2009-10-21 00:40:46 +00002366 if (!NewDI)
2367 return QualType();
2368
2369 return NewDI->getType();
2370}
2371
2372template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002373TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2374 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002375 if (getDerived().AlreadyTransformed(DI->getType()))
2376 return DI;
2377
2378 TypeLocBuilder TLB;
2379
2380 TypeLoc TL = DI->getTypeLoc();
2381 TLB.reserve(TL.getFullDataSize());
2382
Douglas Gregor124b8782010-02-16 19:09:40 +00002383 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002384 if (Result.isNull())
2385 return 0;
2386
John McCalla93c9342009-12-07 02:54:59 +00002387 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002388}
2389
2390template<typename Derived>
2391QualType
Douglas Gregor124b8782010-02-16 19:09:40 +00002392TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2393 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002394 switch (T.getTypeLocClass()) {
2395#define ABSTRACT_TYPELOC(CLASS, PARENT)
2396#define TYPELOC(CLASS, PARENT) \
2397 case TypeLoc::CLASS: \
Douglas Gregor124b8782010-02-16 19:09:40 +00002398 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2399 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002400#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002401 }
Mike Stump1eb44332009-09-09 15:08:12 +00002402
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002403 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002404 return QualType();
2405}
2406
2407/// FIXME: By default, this routine adds type qualifiers only to types
2408/// that can have qualifiers, and silently suppresses those qualifiers
2409/// that are not permitted (e.g., qualifiers on reference or function
2410/// types). This is the right thing for template instantiation, but
2411/// probably not for other clients.
2412template<typename Derived>
2413QualType
2414TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002415 QualifiedTypeLoc T,
2416 QualType ObjectType) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002417 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002418
Douglas Gregor124b8782010-02-16 19:09:40 +00002419 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2420 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002421 if (Result.isNull())
2422 return QualType();
2423
2424 // Silently suppress qualifiers if the result type can't be qualified.
2425 // FIXME: this is the right thing for template instantiation, but
2426 // probably not for other clients.
2427 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002428 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002429
John McCall28654742010-06-05 06:41:15 +00002430 if (!Quals.empty()) {
2431 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2432 TLB.push<QualifiedTypeLoc>(Result);
2433 // No location information to preserve.
2434 }
John McCalla2becad2009-10-21 00:40:46 +00002435
2436 return Result;
2437}
2438
2439template <class TyLoc> static inline
2440QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2441 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2442 NewT.setNameLoc(T.getNameLoc());
2443 return T.getType();
2444}
2445
John McCalla2becad2009-10-21 00:40:46 +00002446template<typename Derived>
2447QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002448 BuiltinTypeLoc T,
2449 QualType ObjectType) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002450 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2451 NewT.setBuiltinLoc(T.getBuiltinLoc());
2452 if (T.needsExtraLocalData())
2453 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2454 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002455}
Mike Stump1eb44332009-09-09 15:08:12 +00002456
Douglas Gregor577f75a2009-08-04 16:50:30 +00002457template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002458QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002459 ComplexTypeLoc T,
2460 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002461 // FIXME: recurse?
2462 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002463}
Mike Stump1eb44332009-09-09 15:08:12 +00002464
Douglas Gregor577f75a2009-08-04 16:50:30 +00002465template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002466QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Sean Huntc3021132010-05-05 15:23:54 +00002467 PointerTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00002468 QualType ObjectType) {
Sean Huntc3021132010-05-05 15:23:54 +00002469 QualType PointeeType
2470 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002471 if (PointeeType.isNull())
2472 return QualType();
2473
2474 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00002475 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002476 // A dependent pointer type 'T *' has is being transformed such
2477 // that an Objective-C class type is being replaced for 'T'. The
2478 // resulting pointer type is an ObjCObjectPointerType, not a
2479 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00002480 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00002481
John McCallc12c5bb2010-05-15 11:32:37 +00002482 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2483 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002484 return Result;
2485 }
Sean Huntc3021132010-05-05 15:23:54 +00002486
Douglas Gregor92e986e2010-04-22 16:44:27 +00002487 if (getDerived().AlwaysRebuild() ||
2488 PointeeType != TL.getPointeeLoc().getType()) {
2489 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2490 if (Result.isNull())
2491 return QualType();
2492 }
Sean Huntc3021132010-05-05 15:23:54 +00002493
Douglas Gregor92e986e2010-04-22 16:44:27 +00002494 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2495 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00002496 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002497}
Mike Stump1eb44332009-09-09 15:08:12 +00002498
2499template<typename Derived>
2500QualType
John McCalla2becad2009-10-21 00:40:46 +00002501TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002502 BlockPointerTypeLoc TL,
2503 QualType ObjectType) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002504 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00002505 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2506 if (PointeeType.isNull())
2507 return QualType();
2508
2509 QualType Result = TL.getType();
2510 if (getDerived().AlwaysRebuild() ||
2511 PointeeType != TL.getPointeeLoc().getType()) {
2512 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002513 TL.getSigilLoc());
2514 if (Result.isNull())
2515 return QualType();
2516 }
2517
Douglas Gregor39968ad2010-04-22 16:50:51 +00002518 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002519 NewT.setSigilLoc(TL.getSigilLoc());
2520 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002521}
2522
John McCall85737a72009-10-30 00:06:24 +00002523/// Transforms a reference type. Note that somewhat paradoxically we
2524/// don't care whether the type itself is an l-value type or an r-value
2525/// type; we only care if the type was *written* as an l-value type
2526/// or an r-value type.
2527template<typename Derived>
2528QualType
2529TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002530 ReferenceTypeLoc TL,
2531 QualType ObjectType) {
John McCall85737a72009-10-30 00:06:24 +00002532 const ReferenceType *T = TL.getTypePtr();
2533
2534 // Note that this works with the pointee-as-written.
2535 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2536 if (PointeeType.isNull())
2537 return QualType();
2538
2539 QualType Result = TL.getType();
2540 if (getDerived().AlwaysRebuild() ||
2541 PointeeType != T->getPointeeTypeAsWritten()) {
2542 Result = getDerived().RebuildReferenceType(PointeeType,
2543 T->isSpelledAsLValue(),
2544 TL.getSigilLoc());
2545 if (Result.isNull())
2546 return QualType();
2547 }
2548
2549 // r-value references can be rebuilt as l-value references.
2550 ReferenceTypeLoc NewTL;
2551 if (isa<LValueReferenceType>(Result))
2552 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2553 else
2554 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2555 NewTL.setSigilLoc(TL.getSigilLoc());
2556
2557 return Result;
2558}
2559
Mike Stump1eb44332009-09-09 15:08:12 +00002560template<typename Derived>
2561QualType
John McCalla2becad2009-10-21 00:40:46 +00002562TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002563 LValueReferenceTypeLoc TL,
2564 QualType ObjectType) {
2565 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002566}
2567
Mike Stump1eb44332009-09-09 15:08:12 +00002568template<typename Derived>
2569QualType
John McCalla2becad2009-10-21 00:40:46 +00002570TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002571 RValueReferenceTypeLoc TL,
2572 QualType ObjectType) {
2573 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002574}
Mike Stump1eb44332009-09-09 15:08:12 +00002575
Douglas Gregor577f75a2009-08-04 16:50:30 +00002576template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002577QualType
John McCalla2becad2009-10-21 00:40:46 +00002578TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002579 MemberPointerTypeLoc TL,
2580 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002581 MemberPointerType *T = TL.getTypePtr();
2582
2583 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002584 if (PointeeType.isNull())
2585 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002586
John McCalla2becad2009-10-21 00:40:46 +00002587 // TODO: preserve source information for this.
2588 QualType ClassType
2589 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002590 if (ClassType.isNull())
2591 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002592
John McCalla2becad2009-10-21 00:40:46 +00002593 QualType Result = TL.getType();
2594 if (getDerived().AlwaysRebuild() ||
2595 PointeeType != T->getPointeeType() ||
2596 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002597 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2598 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002599 if (Result.isNull())
2600 return QualType();
2601 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002602
John McCalla2becad2009-10-21 00:40:46 +00002603 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2604 NewTL.setSigilLoc(TL.getSigilLoc());
2605
2606 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002607}
2608
Mike Stump1eb44332009-09-09 15:08:12 +00002609template<typename Derived>
2610QualType
John McCalla2becad2009-10-21 00:40:46 +00002611TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002612 ConstantArrayTypeLoc TL,
2613 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002614 ConstantArrayType *T = TL.getTypePtr();
2615 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002616 if (ElementType.isNull())
2617 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002618
John McCalla2becad2009-10-21 00:40:46 +00002619 QualType Result = TL.getType();
2620 if (getDerived().AlwaysRebuild() ||
2621 ElementType != T->getElementType()) {
2622 Result = getDerived().RebuildConstantArrayType(ElementType,
2623 T->getSizeModifier(),
2624 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002625 T->getIndexTypeCVRQualifiers(),
2626 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002627 if (Result.isNull())
2628 return QualType();
2629 }
Sean Huntc3021132010-05-05 15:23:54 +00002630
John McCalla2becad2009-10-21 00:40:46 +00002631 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2632 NewTL.setLBracketLoc(TL.getLBracketLoc());
2633 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002634
John McCalla2becad2009-10-21 00:40:46 +00002635 Expr *Size = TL.getSizeExpr();
2636 if (Size) {
2637 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2638 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2639 }
2640 NewTL.setSizeExpr(Size);
2641
2642 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002643}
Mike Stump1eb44332009-09-09 15:08:12 +00002644
Douglas Gregor577f75a2009-08-04 16:50:30 +00002645template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002646QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002647 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002648 IncompleteArrayTypeLoc TL,
2649 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002650 IncompleteArrayType *T = TL.getTypePtr();
2651 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002652 if (ElementType.isNull())
2653 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002654
John McCalla2becad2009-10-21 00:40:46 +00002655 QualType Result = TL.getType();
2656 if (getDerived().AlwaysRebuild() ||
2657 ElementType != T->getElementType()) {
2658 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002659 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002660 T->getIndexTypeCVRQualifiers(),
2661 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002662 if (Result.isNull())
2663 return QualType();
2664 }
Sean Huntc3021132010-05-05 15:23:54 +00002665
John McCalla2becad2009-10-21 00:40:46 +00002666 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2667 NewTL.setLBracketLoc(TL.getLBracketLoc());
2668 NewTL.setRBracketLoc(TL.getRBracketLoc());
2669 NewTL.setSizeExpr(0);
2670
2671 return Result;
2672}
2673
2674template<typename Derived>
2675QualType
2676TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002677 VariableArrayTypeLoc TL,
2678 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002679 VariableArrayType *T = TL.getTypePtr();
2680 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2681 if (ElementType.isNull())
2682 return QualType();
2683
2684 // Array bounds are not potentially evaluated contexts
2685 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2686
2687 Sema::OwningExprResult SizeResult
2688 = getDerived().TransformExpr(T->getSizeExpr());
2689 if (SizeResult.isInvalid())
2690 return QualType();
2691
2692 Expr *Size = static_cast<Expr*>(SizeResult.get());
2693
2694 QualType Result = TL.getType();
2695 if (getDerived().AlwaysRebuild() ||
2696 ElementType != T->getElementType() ||
2697 Size != T->getSizeExpr()) {
2698 Result = getDerived().RebuildVariableArrayType(ElementType,
2699 T->getSizeModifier(),
2700 move(SizeResult),
2701 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002702 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002703 if (Result.isNull())
2704 return QualType();
2705 }
2706 else SizeResult.take();
Sean Huntc3021132010-05-05 15:23:54 +00002707
John McCalla2becad2009-10-21 00:40:46 +00002708 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2709 NewTL.setLBracketLoc(TL.getLBracketLoc());
2710 NewTL.setRBracketLoc(TL.getRBracketLoc());
2711 NewTL.setSizeExpr(Size);
2712
2713 return Result;
2714}
2715
2716template<typename Derived>
2717QualType
2718TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002719 DependentSizedArrayTypeLoc TL,
2720 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002721 DependentSizedArrayType *T = TL.getTypePtr();
2722 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2723 if (ElementType.isNull())
2724 return QualType();
2725
2726 // Array bounds are not potentially evaluated contexts
2727 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2728
2729 Sema::OwningExprResult SizeResult
2730 = getDerived().TransformExpr(T->getSizeExpr());
2731 if (SizeResult.isInvalid())
2732 return QualType();
2733
2734 Expr *Size = static_cast<Expr*>(SizeResult.get());
2735
2736 QualType Result = TL.getType();
2737 if (getDerived().AlwaysRebuild() ||
2738 ElementType != T->getElementType() ||
2739 Size != T->getSizeExpr()) {
2740 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2741 T->getSizeModifier(),
2742 move(SizeResult),
2743 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002744 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002745 if (Result.isNull())
2746 return QualType();
2747 }
2748 else SizeResult.take();
2749
2750 // We might have any sort of array type now, but fortunately they
2751 // all have the same location layout.
2752 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2753 NewTL.setLBracketLoc(TL.getLBracketLoc());
2754 NewTL.setRBracketLoc(TL.getRBracketLoc());
2755 NewTL.setSizeExpr(Size);
2756
2757 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002758}
Mike Stump1eb44332009-09-09 15:08:12 +00002759
2760template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002761QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002762 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002763 DependentSizedExtVectorTypeLoc TL,
2764 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002765 DependentSizedExtVectorType *T = TL.getTypePtr();
2766
2767 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002768 QualType ElementType = getDerived().TransformType(T->getElementType());
2769 if (ElementType.isNull())
2770 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002771
Douglas Gregor670444e2009-08-04 22:27:00 +00002772 // Vector sizes are not potentially evaluated contexts
2773 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2774
Douglas Gregor577f75a2009-08-04 16:50:30 +00002775 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2776 if (Size.isInvalid())
2777 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002778
John McCalla2becad2009-10-21 00:40:46 +00002779 QualType Result = TL.getType();
2780 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002781 ElementType != T->getElementType() ||
2782 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002783 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002784 move(Size),
2785 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002786 if (Result.isNull())
2787 return QualType();
2788 }
2789 else Size.take();
2790
2791 // Result might be dependent or not.
2792 if (isa<DependentSizedExtVectorType>(Result)) {
2793 DependentSizedExtVectorTypeLoc NewTL
2794 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2795 NewTL.setNameLoc(TL.getNameLoc());
2796 } else {
2797 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2798 NewTL.setNameLoc(TL.getNameLoc());
2799 }
2800
2801 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002802}
Mike Stump1eb44332009-09-09 15:08:12 +00002803
2804template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002805QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002806 VectorTypeLoc TL,
2807 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002808 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002809 QualType ElementType = getDerived().TransformType(T->getElementType());
2810 if (ElementType.isNull())
2811 return QualType();
2812
John McCalla2becad2009-10-21 00:40:46 +00002813 QualType Result = TL.getType();
2814 if (getDerived().AlwaysRebuild() ||
2815 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002816 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner788b0fd2010-06-23 06:00:24 +00002817 T->getAltiVecSpecific());
John McCalla2becad2009-10-21 00:40:46 +00002818 if (Result.isNull())
2819 return QualType();
2820 }
Sean Huntc3021132010-05-05 15:23:54 +00002821
John McCalla2becad2009-10-21 00:40:46 +00002822 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2823 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002824
John McCalla2becad2009-10-21 00:40:46 +00002825 return Result;
2826}
2827
2828template<typename Derived>
2829QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002830 ExtVectorTypeLoc TL,
2831 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002832 VectorType *T = TL.getTypePtr();
2833 QualType ElementType = getDerived().TransformType(T->getElementType());
2834 if (ElementType.isNull())
2835 return QualType();
2836
2837 QualType Result = TL.getType();
2838 if (getDerived().AlwaysRebuild() ||
2839 ElementType != T->getElementType()) {
2840 Result = getDerived().RebuildExtVectorType(ElementType,
2841 T->getNumElements(),
2842 /*FIXME*/ SourceLocation());
2843 if (Result.isNull())
2844 return QualType();
2845 }
Sean Huntc3021132010-05-05 15:23:54 +00002846
John McCalla2becad2009-10-21 00:40:46 +00002847 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2848 NewTL.setNameLoc(TL.getNameLoc());
2849
2850 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002851}
Mike Stump1eb44332009-09-09 15:08:12 +00002852
2853template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002854ParmVarDecl *
2855TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2856 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2857 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2858 if (!NewDI)
2859 return 0;
2860
2861 if (NewDI == OldDI)
2862 return OldParm;
2863 else
2864 return ParmVarDecl::Create(SemaRef.Context,
2865 OldParm->getDeclContext(),
2866 OldParm->getLocation(),
2867 OldParm->getIdentifier(),
2868 NewDI->getType(),
2869 NewDI,
2870 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00002871 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00002872 /* DefArg */ NULL);
2873}
2874
2875template<typename Derived>
2876bool TreeTransform<Derived>::
2877 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2878 llvm::SmallVectorImpl<QualType> &PTypes,
2879 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2880 FunctionProtoType *T = TL.getTypePtr();
2881
2882 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2883 ParmVarDecl *OldParm = TL.getArg(i);
2884
2885 QualType NewType;
2886 ParmVarDecl *NewParm;
2887
2888 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002889 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2890 if (!NewParm)
2891 return true;
2892 NewType = NewParm->getType();
2893
2894 // Deal with the possibility that we don't have a parameter
2895 // declaration for this parameter.
2896 } else {
2897 NewParm = 0;
2898
2899 QualType OldType = T->getArgType(i);
2900 NewType = getDerived().TransformType(OldType);
2901 if (NewType.isNull())
2902 return true;
2903 }
2904
2905 PTypes.push_back(NewType);
2906 PVars.push_back(NewParm);
2907 }
2908
2909 return false;
2910}
2911
2912template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002913QualType
John McCalla2becad2009-10-21 00:40:46 +00002914TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002915 FunctionProtoTypeLoc TL,
2916 QualType ObjectType) {
Douglas Gregor895162d2010-04-30 18:55:50 +00002917 // Transform the parameters. We do this first for the benefit of template
2918 // instantiations, so that the ParmVarDecls get/ placed into the template
2919 // instantiation scope before we transform the function type.
Douglas Gregor577f75a2009-08-04 16:50:30 +00002920 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002921 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall21ef0fa2010-03-11 09:03:00 +00002922 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2923 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +00002924
Douglas Gregor895162d2010-04-30 18:55:50 +00002925 FunctionProtoType *T = TL.getTypePtr();
2926 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2927 if (ResultType.isNull())
2928 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +00002929
John McCalla2becad2009-10-21 00:40:46 +00002930 QualType Result = TL.getType();
2931 if (getDerived().AlwaysRebuild() ||
2932 ResultType != T->getResultType() ||
2933 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2934 Result = getDerived().RebuildFunctionProtoType(ResultType,
2935 ParamTypes.data(),
2936 ParamTypes.size(),
2937 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00002938 T->getTypeQuals(),
2939 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00002940 if (Result.isNull())
2941 return QualType();
2942 }
Mike Stump1eb44332009-09-09 15:08:12 +00002943
John McCalla2becad2009-10-21 00:40:46 +00002944 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2945 NewTL.setLParenLoc(TL.getLParenLoc());
2946 NewTL.setRParenLoc(TL.getRParenLoc());
2947 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2948 NewTL.setArg(i, ParamDecls[i]);
2949
2950 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002951}
Mike Stump1eb44332009-09-09 15:08:12 +00002952
Douglas Gregor577f75a2009-08-04 16:50:30 +00002953template<typename Derived>
2954QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002955 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002956 FunctionNoProtoTypeLoc TL,
2957 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002958 FunctionNoProtoType *T = TL.getTypePtr();
2959 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2960 if (ResultType.isNull())
2961 return QualType();
2962
2963 QualType Result = TL.getType();
2964 if (getDerived().AlwaysRebuild() ||
2965 ResultType != T->getResultType())
2966 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2967
2968 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2969 NewTL.setLParenLoc(TL.getLParenLoc());
2970 NewTL.setRParenLoc(TL.getRParenLoc());
2971
2972 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002973}
Mike Stump1eb44332009-09-09 15:08:12 +00002974
John McCalled976492009-12-04 22:46:56 +00002975template<typename Derived> QualType
2976TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002977 UnresolvedUsingTypeLoc TL,
2978 QualType ObjectType) {
John McCalled976492009-12-04 22:46:56 +00002979 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002980 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00002981 if (!D)
2982 return QualType();
2983
2984 QualType Result = TL.getType();
2985 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2986 Result = getDerived().RebuildUnresolvedUsingType(D);
2987 if (Result.isNull())
2988 return QualType();
2989 }
2990
2991 // We might get an arbitrary type spec type back. We should at
2992 // least always get a type spec type, though.
2993 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2994 NewTL.setNameLoc(TL.getNameLoc());
2995
2996 return Result;
2997}
2998
Douglas Gregor577f75a2009-08-04 16:50:30 +00002999template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003000QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003001 TypedefTypeLoc TL,
3002 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003003 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003004 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003005 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3006 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003007 if (!Typedef)
3008 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003009
John McCalla2becad2009-10-21 00:40:46 +00003010 QualType Result = TL.getType();
3011 if (getDerived().AlwaysRebuild() ||
3012 Typedef != T->getDecl()) {
3013 Result = getDerived().RebuildTypedefType(Typedef);
3014 if (Result.isNull())
3015 return QualType();
3016 }
Mike Stump1eb44332009-09-09 15:08:12 +00003017
John McCalla2becad2009-10-21 00:40:46 +00003018 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3019 NewTL.setNameLoc(TL.getNameLoc());
3020
3021 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003022}
Mike Stump1eb44332009-09-09 15:08:12 +00003023
Douglas Gregor577f75a2009-08-04 16:50:30 +00003024template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003025QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003026 TypeOfExprTypeLoc TL,
3027 QualType ObjectType) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003028 // typeof expressions are not potentially evaluated contexts
3029 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003030
John McCallcfb708c2010-01-13 20:03:27 +00003031 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003032 if (E.isInvalid())
3033 return QualType();
3034
John McCalla2becad2009-10-21 00:40:46 +00003035 QualType Result = TL.getType();
3036 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003037 E.get() != TL.getUnderlyingExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003038 Result = getDerived().RebuildTypeOfExprType(move(E));
3039 if (Result.isNull())
3040 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003041 }
John McCalla2becad2009-10-21 00:40:46 +00003042 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003043
John McCalla2becad2009-10-21 00:40:46 +00003044 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003045 NewTL.setTypeofLoc(TL.getTypeofLoc());
3046 NewTL.setLParenLoc(TL.getLParenLoc());
3047 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003048
3049 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003050}
Mike Stump1eb44332009-09-09 15:08:12 +00003051
3052template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003053QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003054 TypeOfTypeLoc TL,
3055 QualType ObjectType) {
John McCallcfb708c2010-01-13 20:03:27 +00003056 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3057 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3058 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003059 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003060
John McCalla2becad2009-10-21 00:40:46 +00003061 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003062 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3063 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003064 if (Result.isNull())
3065 return QualType();
3066 }
Mike Stump1eb44332009-09-09 15:08:12 +00003067
John McCalla2becad2009-10-21 00:40:46 +00003068 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003069 NewTL.setTypeofLoc(TL.getTypeofLoc());
3070 NewTL.setLParenLoc(TL.getLParenLoc());
3071 NewTL.setRParenLoc(TL.getRParenLoc());
3072 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003073
3074 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003075}
Mike Stump1eb44332009-09-09 15:08:12 +00003076
3077template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003078QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003079 DecltypeTypeLoc TL,
3080 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003081 DecltypeType *T = TL.getTypePtr();
3082
Douglas Gregor670444e2009-08-04 22:27:00 +00003083 // decltype expressions are not potentially evaluated contexts
3084 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003085
Douglas Gregor577f75a2009-08-04 16:50:30 +00003086 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3087 if (E.isInvalid())
3088 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003089
John McCalla2becad2009-10-21 00:40:46 +00003090 QualType Result = TL.getType();
3091 if (getDerived().AlwaysRebuild() ||
3092 E.get() != T->getUnderlyingExpr()) {
3093 Result = getDerived().RebuildDecltypeType(move(E));
3094 if (Result.isNull())
3095 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003096 }
John McCalla2becad2009-10-21 00:40:46 +00003097 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003098
John McCalla2becad2009-10-21 00:40:46 +00003099 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3100 NewTL.setNameLoc(TL.getNameLoc());
3101
3102 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003103}
3104
3105template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003106QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003107 RecordTypeLoc TL,
3108 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003109 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003110 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003111 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3112 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003113 if (!Record)
3114 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003115
John McCalla2becad2009-10-21 00:40:46 +00003116 QualType Result = TL.getType();
3117 if (getDerived().AlwaysRebuild() ||
3118 Record != T->getDecl()) {
3119 Result = getDerived().RebuildRecordType(Record);
3120 if (Result.isNull())
3121 return QualType();
3122 }
Mike Stump1eb44332009-09-09 15:08:12 +00003123
John McCalla2becad2009-10-21 00:40:46 +00003124 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3125 NewTL.setNameLoc(TL.getNameLoc());
3126
3127 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003128}
Mike Stump1eb44332009-09-09 15:08:12 +00003129
3130template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003131QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003132 EnumTypeLoc TL,
3133 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003134 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003135 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003136 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3137 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003138 if (!Enum)
3139 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003140
John McCalla2becad2009-10-21 00:40:46 +00003141 QualType Result = TL.getType();
3142 if (getDerived().AlwaysRebuild() ||
3143 Enum != T->getDecl()) {
3144 Result = getDerived().RebuildEnumType(Enum);
3145 if (Result.isNull())
3146 return QualType();
3147 }
Mike Stump1eb44332009-09-09 15:08:12 +00003148
John McCalla2becad2009-10-21 00:40:46 +00003149 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3150 NewTL.setNameLoc(TL.getNameLoc());
3151
3152 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003153}
John McCall7da24312009-09-05 00:15:47 +00003154
John McCall3cb0ebd2010-03-10 03:28:59 +00003155template<typename Derived>
3156QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3157 TypeLocBuilder &TLB,
3158 InjectedClassNameTypeLoc TL,
3159 QualType ObjectType) {
3160 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3161 TL.getTypePtr()->getDecl());
3162 if (!D) return QualType();
3163
3164 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3165 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3166 return T;
3167}
3168
Mike Stump1eb44332009-09-09 15:08:12 +00003169
Douglas Gregor577f75a2009-08-04 16:50:30 +00003170template<typename Derived>
3171QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003172 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003173 TemplateTypeParmTypeLoc TL,
3174 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003175 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003176}
3177
Mike Stump1eb44332009-09-09 15:08:12 +00003178template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003179QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003180 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003181 SubstTemplateTypeParmTypeLoc TL,
3182 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003183 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003184}
3185
3186template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003187QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3188 const TemplateSpecializationType *TST,
3189 QualType ObjectType) {
3190 // FIXME: this entire method is a temporary workaround; callers
3191 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00003192
John McCall833ca992009-10-29 08:12:44 +00003193 // Fake up a TemplateSpecializationTypeLoc.
3194 TypeLocBuilder TLB;
3195 TemplateSpecializationTypeLoc TL
3196 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3197
John McCall828bff22009-10-29 18:45:58 +00003198 SourceLocation BaseLoc = getDerived().getBaseLocation();
3199
3200 TL.setTemplateNameLoc(BaseLoc);
3201 TL.setLAngleLoc(BaseLoc);
3202 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00003203 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3204 const TemplateArgument &TA = TST->getArg(i);
3205 TemplateArgumentLoc TAL;
3206 getDerived().InventTemplateArgumentLoc(TA, TAL);
3207 TL.setArgLocInfo(i, TAL.getLocInfo());
3208 }
3209
3210 TypeLocBuilder IgnoredTLB;
3211 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00003212}
Sean Huntc3021132010-05-05 15:23:54 +00003213
Douglas Gregordd62b152009-10-19 22:04:39 +00003214template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003215QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003216 TypeLocBuilder &TLB,
3217 TemplateSpecializationTypeLoc TL,
3218 QualType ObjectType) {
3219 const TemplateSpecializationType *T = TL.getTypePtr();
3220
Mike Stump1eb44332009-09-09 15:08:12 +00003221 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00003222 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003223 if (Template.isNull())
3224 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003225
John McCalld5532b62009-11-23 01:53:49 +00003226 TemplateArgumentListInfo NewTemplateArgs;
3227 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3228 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3229
3230 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3231 TemplateArgumentLoc Loc;
3232 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00003233 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00003234 NewTemplateArgs.addArgument(Loc);
3235 }
Mike Stump1eb44332009-09-09 15:08:12 +00003236
John McCall833ca992009-10-29 08:12:44 +00003237 // FIXME: maybe don't rebuild if all the template arguments are the same.
3238
3239 QualType Result =
3240 getDerived().RebuildTemplateSpecializationType(Template,
3241 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003242 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003243
3244 if (!Result.isNull()) {
3245 TemplateSpecializationTypeLoc NewTL
3246 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3247 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3248 NewTL.setLAngleLoc(TL.getLAngleLoc());
3249 NewTL.setRAngleLoc(TL.getRAngleLoc());
3250 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3251 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003252 }
Mike Stump1eb44332009-09-09 15:08:12 +00003253
John McCall833ca992009-10-29 08:12:44 +00003254 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003255}
Mike Stump1eb44332009-09-09 15:08:12 +00003256
3257template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003258QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003259TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3260 ElaboratedTypeLoc TL,
3261 QualType ObjectType) {
3262 ElaboratedType *T = TL.getTypePtr();
3263
3264 NestedNameSpecifier *NNS = 0;
3265 // NOTE: the qualifier in an ElaboratedType is optional.
3266 if (T->getQualifier() != 0) {
3267 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003268 TL.getQualifierRange(),
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003269 ObjectType);
3270 if (!NNS)
3271 return QualType();
3272 }
Mike Stump1eb44332009-09-09 15:08:12 +00003273
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003274 QualType NamedT;
3275 // FIXME: this test is meant to workaround a problem (failing assertion)
3276 // occurring if directly executing the code in the else branch.
3277 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3278 TemplateSpecializationTypeLoc OldNamedTL
3279 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3280 const TemplateSpecializationType* OldTST
Jim Grosbach9cbb4d82010-05-19 23:53:08 +00003281 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003282 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3283 if (NamedT.isNull())
3284 return QualType();
3285 TemplateSpecializationTypeLoc NewNamedTL
3286 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3287 NewNamedTL.copy(OldNamedTL);
3288 }
3289 else {
3290 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3291 if (NamedT.isNull())
3292 return QualType();
3293 }
Daniel Dunbara63db842010-05-14 16:34:09 +00003294
John McCalla2becad2009-10-21 00:40:46 +00003295 QualType Result = TL.getType();
3296 if (getDerived().AlwaysRebuild() ||
3297 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003298 NamedT != T->getNamedType()) {
3299 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00003300 if (Result.isNull())
3301 return QualType();
3302 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003303
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003304 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003305 NewTL.setKeywordLoc(TL.getKeywordLoc());
3306 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00003307
3308 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003309}
Mike Stump1eb44332009-09-09 15:08:12 +00003310
3311template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003312QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3313 DependentNameTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00003314 QualType ObjectType) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003315 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003316
Douglas Gregor577f75a2009-08-04 16:50:30 +00003317 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003318 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3319 TL.getQualifierRange(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003320 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003321 if (!NNS)
3322 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003323
John McCall33500952010-06-11 00:33:02 +00003324 QualType Result
3325 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3326 T->getIdentifier(),
3327 TL.getKeywordLoc(),
3328 TL.getQualifierRange(),
3329 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003330 if (Result.isNull())
3331 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003332
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003333 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3334 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00003335 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3336
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003337 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3338 NewTL.setKeywordLoc(TL.getKeywordLoc());
3339 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003340 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003341 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3342 NewTL.setKeywordLoc(TL.getKeywordLoc());
3343 NewTL.setQualifierRange(TL.getQualifierRange());
3344 NewTL.setNameLoc(TL.getNameLoc());
3345 }
John McCalla2becad2009-10-21 00:40:46 +00003346 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003347}
Mike Stump1eb44332009-09-09 15:08:12 +00003348
Douglas Gregor577f75a2009-08-04 16:50:30 +00003349template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00003350QualType TreeTransform<Derived>::
3351 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3352 DependentTemplateSpecializationTypeLoc TL,
3353 QualType ObjectType) {
3354 DependentTemplateSpecializationType *T = TL.getTypePtr();
3355
3356 NestedNameSpecifier *NNS
3357 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3358 TL.getQualifierRange(),
3359 ObjectType);
3360 if (!NNS)
3361 return QualType();
3362
3363 TemplateArgumentListInfo NewTemplateArgs;
3364 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3365 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3366
3367 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3368 TemplateArgumentLoc Loc;
3369 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3370 return QualType();
3371 NewTemplateArgs.addArgument(Loc);
3372 }
3373
3374 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
3375 T->getKeyword(),
3376 NNS,
3377 T->getIdentifier(),
3378 TL.getNameLoc(),
3379 NewTemplateArgs);
3380 if (Result.isNull())
3381 return QualType();
3382
3383 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3384 QualType NamedT = ElabT->getNamedType();
3385
3386 // Copy information relevant to the template specialization.
3387 TemplateSpecializationTypeLoc NamedTL
3388 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3389 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3390 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3391 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3392 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3393
3394 // Copy information relevant to the elaborated type.
3395 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3396 NewTL.setKeywordLoc(TL.getKeywordLoc());
3397 NewTL.setQualifierRange(TL.getQualifierRange());
3398 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00003399 TypeLoc NewTL(Result, TL.getOpaqueData());
3400 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00003401 }
3402 return Result;
3403}
3404
3405template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003406QualType
3407TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003408 ObjCInterfaceTypeLoc TL,
3409 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003410 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003411 TLB.pushFullCopy(TL);
3412 return TL.getType();
3413}
3414
3415template<typename Derived>
3416QualType
3417TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3418 ObjCObjectTypeLoc TL,
3419 QualType ObjectType) {
3420 // ObjCObjectType is never dependent.
3421 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003422 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003423}
Mike Stump1eb44332009-09-09 15:08:12 +00003424
3425template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003426QualType
3427TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003428 ObjCObjectPointerTypeLoc TL,
3429 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003430 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003431 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003432 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003433}
3434
Douglas Gregor577f75a2009-08-04 16:50:30 +00003435//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003436// Statement transformation
3437//===----------------------------------------------------------------------===//
3438template<typename Derived>
3439Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003440TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3441 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003442}
3443
3444template<typename Derived>
3445Sema::OwningStmtResult
3446TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3447 return getDerived().TransformCompoundStmt(S, false);
3448}
3449
3450template<typename Derived>
3451Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003452TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003453 bool IsStmtExpr) {
3454 bool SubStmtChanged = false;
3455 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3456 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3457 B != BEnd; ++B) {
3458 OwningStmtResult Result = getDerived().TransformStmt(*B);
3459 if (Result.isInvalid())
3460 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003461
Douglas Gregor43959a92009-08-20 07:17:43 +00003462 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3463 Statements.push_back(Result.takeAs<Stmt>());
3464 }
Mike Stump1eb44332009-09-09 15:08:12 +00003465
Douglas Gregor43959a92009-08-20 07:17:43 +00003466 if (!getDerived().AlwaysRebuild() &&
3467 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003468 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003469
3470 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3471 move_arg(Statements),
3472 S->getRBracLoc(),
3473 IsStmtExpr);
3474}
Mike Stump1eb44332009-09-09 15:08:12 +00003475
Douglas Gregor43959a92009-08-20 07:17:43 +00003476template<typename Derived>
3477Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003478TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman264c1f82009-11-19 03:14:00 +00003479 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3480 {
3481 // The case value expressions are not potentially evaluated.
3482 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003483
Eli Friedman264c1f82009-11-19 03:14:00 +00003484 // Transform the left-hand case value.
3485 LHS = getDerived().TransformExpr(S->getLHS());
3486 if (LHS.isInvalid())
3487 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003488
Eli Friedman264c1f82009-11-19 03:14:00 +00003489 // Transform the right-hand case value (for the GNU case-range extension).
3490 RHS = getDerived().TransformExpr(S->getRHS());
3491 if (RHS.isInvalid())
3492 return SemaRef.StmtError();
3493 }
Mike Stump1eb44332009-09-09 15:08:12 +00003494
Douglas Gregor43959a92009-08-20 07:17:43 +00003495 // Build the case statement.
3496 // Case statements are always rebuilt so that they will attached to their
3497 // transformed switch statement.
3498 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3499 move(LHS),
3500 S->getEllipsisLoc(),
3501 move(RHS),
3502 S->getColonLoc());
3503 if (Case.isInvalid())
3504 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003505
Douglas Gregor43959a92009-08-20 07:17:43 +00003506 // Transform the statement following the case
3507 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3508 if (SubStmt.isInvalid())
3509 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003510
Douglas Gregor43959a92009-08-20 07:17:43 +00003511 // Attach the body to the case statement
3512 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3513}
3514
3515template<typename Derived>
3516Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003517TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003518 // Transform the statement following the default case
3519 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3520 if (SubStmt.isInvalid())
3521 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003522
Douglas Gregor43959a92009-08-20 07:17:43 +00003523 // Default statements are always rebuilt
3524 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3525 move(SubStmt));
3526}
Mike Stump1eb44332009-09-09 15:08:12 +00003527
Douglas Gregor43959a92009-08-20 07:17:43 +00003528template<typename Derived>
3529Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003530TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003531 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3532 if (SubStmt.isInvalid())
3533 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003534
Douglas Gregor43959a92009-08-20 07:17:43 +00003535 // FIXME: Pass the real colon location in.
3536 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3537 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3538 move(SubStmt));
3539}
Mike Stump1eb44332009-09-09 15:08:12 +00003540
Douglas Gregor43959a92009-08-20 07:17:43 +00003541template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003542Sema::OwningStmtResult
3543TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003544 // Transform the condition
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003545 OwningExprResult Cond(SemaRef);
3546 VarDecl *ConditionVar = 0;
3547 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003548 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003549 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003550 getDerived().TransformDefinition(
3551 S->getConditionVariable()->getLocation(),
3552 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003553 if (!ConditionVar)
3554 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003555 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003556 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003557
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003558 if (Cond.isInvalid())
3559 return SemaRef.StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003560
3561 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003562 if (S->getCond()) {
3563 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3564 S->getIfLoc(),
3565 move(Cond));
3566 if (CondE.isInvalid())
3567 return getSema().StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003568
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003569 Cond = move(CondE);
3570 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003571 }
Sean Huntc3021132010-05-05 15:23:54 +00003572
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003573 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3574 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3575 return SemaRef.StmtError();
3576
Douglas Gregor43959a92009-08-20 07:17:43 +00003577 // Transform the "then" branch.
3578 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3579 if (Then.isInvalid())
3580 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003581
Douglas Gregor43959a92009-08-20 07:17:43 +00003582 // Transform the "else" branch.
3583 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3584 if (Else.isInvalid())
3585 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003586
Douglas Gregor43959a92009-08-20 07:17:43 +00003587 if (!getDerived().AlwaysRebuild() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003588 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003589 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003590 Then.get() == S->getThen() &&
3591 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003592 return SemaRef.Owned(S->Retain());
3593
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003594 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003595 move(Then),
Mike Stump1eb44332009-09-09 15:08:12 +00003596 S->getElseLoc(), move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +00003597}
3598
3599template<typename Derived>
3600Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003601TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003602 // Transform the condition.
Douglas Gregord3d53012009-11-24 17:07:59 +00003603 OwningExprResult Cond(SemaRef);
3604 VarDecl *ConditionVar = 0;
3605 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003606 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00003607 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003608 getDerived().TransformDefinition(
3609 S->getConditionVariable()->getLocation(),
3610 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003611 if (!ConditionVar)
3612 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003613 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003614 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003615
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003616 if (Cond.isInvalid())
3617 return SemaRef.StmtError();
3618 }
Mike Stump1eb44332009-09-09 15:08:12 +00003619
Douglas Gregor43959a92009-08-20 07:17:43 +00003620 // Rebuild the switch statement.
Douglas Gregor586596f2010-05-06 17:25:47 +00003621 OwningStmtResult Switch
3622 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond),
3623 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003624 if (Switch.isInvalid())
3625 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003626
Douglas Gregor43959a92009-08-20 07:17:43 +00003627 // Transform the body of the switch statement.
3628 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3629 if (Body.isInvalid())
3630 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003631
Douglas Gregor43959a92009-08-20 07:17:43 +00003632 // Complete the switch statement.
3633 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3634 move(Body));
3635}
Mike Stump1eb44332009-09-09 15:08:12 +00003636
Douglas Gregor43959a92009-08-20 07:17:43 +00003637template<typename Derived>
3638Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003639TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003640 // Transform the condition
Douglas Gregor5656e142009-11-24 21:15:44 +00003641 OwningExprResult Cond(SemaRef);
3642 VarDecl *ConditionVar = 0;
3643 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003644 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00003645 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003646 getDerived().TransformDefinition(
3647 S->getConditionVariable()->getLocation(),
3648 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003649 if (!ConditionVar)
3650 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003651 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003652 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003653
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003654 if (Cond.isInvalid())
3655 return SemaRef.StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003656
3657 if (S->getCond()) {
3658 // Convert the condition to a boolean value.
3659 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003660 S->getWhileLoc(),
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003661 move(Cond));
3662 if (CondE.isInvalid())
3663 return getSema().StmtError();
3664 Cond = move(CondE);
3665 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003666 }
Mike Stump1eb44332009-09-09 15:08:12 +00003667
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003668 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3669 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3670 return SemaRef.StmtError();
3671
Douglas Gregor43959a92009-08-20 07:17:43 +00003672 // Transform the body
3673 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3674 if (Body.isInvalid())
3675 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003676
Douglas Gregor43959a92009-08-20 07:17:43 +00003677 if (!getDerived().AlwaysRebuild() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003678 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003679 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003680 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003681 return SemaRef.Owned(S->Retain());
3682
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003683 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
Douglas Gregor586596f2010-05-06 17:25:47 +00003684 ConditionVar, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003685}
Mike Stump1eb44332009-09-09 15:08:12 +00003686
Douglas Gregor43959a92009-08-20 07:17:43 +00003687template<typename Derived>
3688Sema::OwningStmtResult
3689TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003690 // Transform the body
3691 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3692 if (Body.isInvalid())
3693 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003694
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003695 // Transform the condition
3696 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3697 if (Cond.isInvalid())
3698 return SemaRef.StmtError();
3699
Douglas Gregor43959a92009-08-20 07:17:43 +00003700 if (!getDerived().AlwaysRebuild() &&
3701 Cond.get() == S->getCond() &&
3702 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003703 return SemaRef.Owned(S->Retain());
3704
Douglas Gregor43959a92009-08-20 07:17:43 +00003705 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3706 /*FIXME:*/S->getWhileLoc(), move(Cond),
3707 S->getRParenLoc());
3708}
Mike Stump1eb44332009-09-09 15:08:12 +00003709
Douglas Gregor43959a92009-08-20 07:17:43 +00003710template<typename Derived>
3711Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003712TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003713 // Transform the initialization statement
3714 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3715 if (Init.isInvalid())
3716 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003717
Douglas Gregor43959a92009-08-20 07:17:43 +00003718 // Transform the condition
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003719 OwningExprResult Cond(SemaRef);
3720 VarDecl *ConditionVar = 0;
3721 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003722 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003723 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003724 getDerived().TransformDefinition(
3725 S->getConditionVariable()->getLocation(),
3726 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003727 if (!ConditionVar)
3728 return SemaRef.StmtError();
3729 } else {
3730 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003731
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003732 if (Cond.isInvalid())
3733 return SemaRef.StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003734
3735 if (S->getCond()) {
3736 // Convert the condition to a boolean value.
3737 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3738 S->getForLoc(),
3739 move(Cond));
3740 if (CondE.isInvalid())
3741 return getSema().StmtError();
3742
3743 Cond = move(CondE);
3744 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003745 }
Mike Stump1eb44332009-09-09 15:08:12 +00003746
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003747 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3748 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3749 return SemaRef.StmtError();
3750
Douglas Gregor43959a92009-08-20 07:17:43 +00003751 // Transform the increment
3752 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3753 if (Inc.isInvalid())
3754 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003755
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003756 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc));
3757 if (S->getInc() && !FullInc->get())
3758 return SemaRef.StmtError();
3759
Douglas Gregor43959a92009-08-20 07:17:43 +00003760 // Transform the body
3761 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3762 if (Body.isInvalid())
3763 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003764
Douglas Gregor43959a92009-08-20 07:17:43 +00003765 if (!getDerived().AlwaysRebuild() &&
3766 Init.get() == S->getInit() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003767 FullCond->get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003768 Inc.get() == S->getInc() &&
3769 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003770 return SemaRef.Owned(S->Retain());
3771
Douglas Gregor43959a92009-08-20 07:17:43 +00003772 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003773 move(Init), FullCond, ConditionVar,
3774 FullInc, S->getRParenLoc(), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003775}
3776
3777template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003778Sema::OwningStmtResult
3779TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003780 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003781 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003782 S->getLabel());
3783}
3784
3785template<typename Derived>
3786Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003787TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003788 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3789 if (Target.isInvalid())
3790 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003791
Douglas Gregor43959a92009-08-20 07:17:43 +00003792 if (!getDerived().AlwaysRebuild() &&
3793 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003794 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003795
3796 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3797 move(Target));
3798}
3799
3800template<typename Derived>
3801Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003802TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3803 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003804}
Mike Stump1eb44332009-09-09 15:08:12 +00003805
Douglas Gregor43959a92009-08-20 07:17:43 +00003806template<typename Derived>
3807Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003808TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3809 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003810}
Mike Stump1eb44332009-09-09 15:08:12 +00003811
Douglas Gregor43959a92009-08-20 07:17:43 +00003812template<typename Derived>
3813Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003814TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003815 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3816 if (Result.isInvalid())
3817 return SemaRef.StmtError();
3818
Mike Stump1eb44332009-09-09 15:08:12 +00003819 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003820 // to tell whether the return type of the function has changed.
3821 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3822}
Mike Stump1eb44332009-09-09 15:08:12 +00003823
Douglas Gregor43959a92009-08-20 07:17:43 +00003824template<typename Derived>
3825Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003826TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003827 bool DeclChanged = false;
3828 llvm::SmallVector<Decl *, 4> Decls;
3829 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3830 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003831 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3832 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003833 if (!Transformed)
3834 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003835
Douglas Gregor43959a92009-08-20 07:17:43 +00003836 if (Transformed != *D)
3837 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003838
Douglas Gregor43959a92009-08-20 07:17:43 +00003839 Decls.push_back(Transformed);
3840 }
Mike Stump1eb44332009-09-09 15:08:12 +00003841
Douglas Gregor43959a92009-08-20 07:17:43 +00003842 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003843 return SemaRef.Owned(S->Retain());
3844
3845 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003846 S->getStartLoc(), S->getEndLoc());
3847}
Mike Stump1eb44332009-09-09 15:08:12 +00003848
Douglas Gregor43959a92009-08-20 07:17:43 +00003849template<typename Derived>
3850Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003851TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003852 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003853 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003854}
3855
3856template<typename Derived>
3857Sema::OwningStmtResult
3858TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00003859
Anders Carlsson703e3942010-01-24 05:50:09 +00003860 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3861 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003862 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003863
Anders Carlsson703e3942010-01-24 05:50:09 +00003864 OwningExprResult AsmString(SemaRef);
3865 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3866
3867 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00003868
Anders Carlsson703e3942010-01-24 05:50:09 +00003869 // Go through the outputs.
3870 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003871 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003872
Anders Carlsson703e3942010-01-24 05:50:09 +00003873 // No need to transform the constraint literal.
3874 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003875
Anders Carlsson703e3942010-01-24 05:50:09 +00003876 // Transform the output expr.
3877 Expr *OutputExpr = S->getOutputExpr(I);
3878 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3879 if (Result.isInvalid())
3880 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003881
Anders Carlsson703e3942010-01-24 05:50:09 +00003882 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003883
Anders Carlsson703e3942010-01-24 05:50:09 +00003884 Exprs.push_back(Result.takeAs<Expr>());
3885 }
Sean Huntc3021132010-05-05 15:23:54 +00003886
Anders Carlsson703e3942010-01-24 05:50:09 +00003887 // Go through the inputs.
3888 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003889 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003890
Anders Carlsson703e3942010-01-24 05:50:09 +00003891 // No need to transform the constraint literal.
3892 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003893
Anders Carlsson703e3942010-01-24 05:50:09 +00003894 // Transform the input expr.
3895 Expr *InputExpr = S->getInputExpr(I);
3896 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3897 if (Result.isInvalid())
3898 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003899
Anders Carlsson703e3942010-01-24 05:50:09 +00003900 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003901
Anders Carlsson703e3942010-01-24 05:50:09 +00003902 Exprs.push_back(Result.takeAs<Expr>());
3903 }
Sean Huntc3021132010-05-05 15:23:54 +00003904
Anders Carlsson703e3942010-01-24 05:50:09 +00003905 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3906 return SemaRef.Owned(S->Retain());
3907
3908 // Go through the clobbers.
3909 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3910 Clobbers.push_back(S->getClobber(I)->Retain());
3911
3912 // No need to transform the asm string literal.
3913 AsmString = SemaRef.Owned(S->getAsmString());
3914
3915 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3916 S->isSimple(),
3917 S->isVolatile(),
3918 S->getNumOutputs(),
3919 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003920 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003921 move_arg(Constraints),
3922 move_arg(Exprs),
3923 move(AsmString),
3924 move_arg(Clobbers),
3925 S->getRParenLoc(),
3926 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003927}
3928
3929
3930template<typename Derived>
3931Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003932TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003933 // Transform the body of the @try.
3934 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3935 if (TryBody.isInvalid())
3936 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003937
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003938 // Transform the @catch statements (if present).
3939 bool AnyCatchChanged = false;
3940 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3941 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3942 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003943 if (Catch.isInvalid())
3944 return SemaRef.StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003945 if (Catch.get() != S->getCatchStmt(I))
3946 AnyCatchChanged = true;
3947 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003948 }
Sean Huntc3021132010-05-05 15:23:54 +00003949
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003950 // Transform the @finally statement (if present).
3951 OwningStmtResult Finally(SemaRef);
3952 if (S->getFinallyStmt()) {
3953 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3954 if (Finally.isInvalid())
3955 return SemaRef.StmtError();
3956 }
3957
3958 // If nothing changed, just retain this statement.
3959 if (!getDerived().AlwaysRebuild() &&
3960 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003961 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003962 Finally.get() == S->getFinallyStmt())
3963 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003964
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003965 // Build a new statement.
3966 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003967 move_arg(CatchStmts), move(Finally));
Douglas Gregor43959a92009-08-20 07:17:43 +00003968}
Mike Stump1eb44332009-09-09 15:08:12 +00003969
Douglas Gregor43959a92009-08-20 07:17:43 +00003970template<typename Derived>
3971Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003972TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00003973 // Transform the @catch parameter, if there is one.
3974 VarDecl *Var = 0;
3975 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3976 TypeSourceInfo *TSInfo = 0;
3977 if (FromVar->getTypeSourceInfo()) {
3978 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3979 if (!TSInfo)
3980 return SemaRef.StmtError();
3981 }
Sean Huntc3021132010-05-05 15:23:54 +00003982
Douglas Gregorbe270a02010-04-26 17:57:08 +00003983 QualType T;
3984 if (TSInfo)
3985 T = TSInfo->getType();
3986 else {
3987 T = getDerived().TransformType(FromVar->getType());
3988 if (T.isNull())
Sean Huntc3021132010-05-05 15:23:54 +00003989 return SemaRef.StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00003990 }
Sean Huntc3021132010-05-05 15:23:54 +00003991
Douglas Gregorbe270a02010-04-26 17:57:08 +00003992 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3993 if (!Var)
3994 return SemaRef.StmtError();
3995 }
Sean Huntc3021132010-05-05 15:23:54 +00003996
Douglas Gregorbe270a02010-04-26 17:57:08 +00003997 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3998 if (Body.isInvalid())
3999 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004000
4001 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004002 S->getRParenLoc(),
4003 Var, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004004}
Mike Stump1eb44332009-09-09 15:08:12 +00004005
Douglas Gregor43959a92009-08-20 07:17:43 +00004006template<typename Derived>
4007Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004008TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004009 // Transform the body.
4010 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
4011 if (Body.isInvalid())
4012 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004013
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004014 // If nothing changed, just retain this statement.
4015 if (!getDerived().AlwaysRebuild() &&
4016 Body.get() == S->getFinallyBody())
4017 return SemaRef.Owned(S->Retain());
4018
4019 // Build a new statement.
4020 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
4021 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004022}
Mike Stump1eb44332009-09-09 15:08:12 +00004023
Douglas Gregor43959a92009-08-20 07:17:43 +00004024template<typename Derived>
4025Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004026TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregord1377b22010-04-22 21:44:01 +00004027 OwningExprResult Operand(SemaRef);
4028 if (S->getThrowExpr()) {
4029 Operand = getDerived().TransformExpr(S->getThrowExpr());
4030 if (Operand.isInvalid())
4031 return getSema().StmtError();
4032 }
Sean Huntc3021132010-05-05 15:23:54 +00004033
Douglas Gregord1377b22010-04-22 21:44:01 +00004034 if (!getDerived().AlwaysRebuild() &&
4035 Operand.get() == S->getThrowExpr())
4036 return getSema().Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004037
Douglas Gregord1377b22010-04-22 21:44:01 +00004038 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregor43959a92009-08-20 07:17:43 +00004039}
Mike Stump1eb44332009-09-09 15:08:12 +00004040
Douglas Gregor43959a92009-08-20 07:17:43 +00004041template<typename Derived>
4042Sema::OwningStmtResult
4043TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004044 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004045 // Transform the object we are locking.
4046 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
4047 if (Object.isInvalid())
4048 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004049
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004050 // Transform the body.
4051 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
4052 if (Body.isInvalid())
4053 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004054
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004055 // If nothing change, just retain the current statement.
4056 if (!getDerived().AlwaysRebuild() &&
4057 Object.get() == S->getSynchExpr() &&
4058 Body.get() == S->getSynchBody())
4059 return SemaRef.Owned(S->Retain());
4060
4061 // Build a new statement.
4062 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
4063 move(Object), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004064}
4065
4066template<typename Derived>
4067Sema::OwningStmtResult
4068TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004069 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004070 // Transform the element statement.
4071 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
4072 if (Element.isInvalid())
4073 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004074
Douglas Gregorc3203e72010-04-22 23:10:45 +00004075 // Transform the collection expression.
4076 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
4077 if (Collection.isInvalid())
4078 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004079
Douglas Gregorc3203e72010-04-22 23:10:45 +00004080 // Transform the body.
4081 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
4082 if (Body.isInvalid())
4083 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004084
Douglas Gregorc3203e72010-04-22 23:10:45 +00004085 // If nothing changed, just retain this statement.
4086 if (!getDerived().AlwaysRebuild() &&
4087 Element.get() == S->getElement() &&
4088 Collection.get() == S->getCollection() &&
4089 Body.get() == S->getBody())
4090 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004091
Douglas Gregorc3203e72010-04-22 23:10:45 +00004092 // Build a new statement.
4093 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4094 /*FIXME:*/S->getForLoc(),
4095 move(Element),
4096 move(Collection),
4097 S->getRParenLoc(),
4098 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004099}
4100
4101
4102template<typename Derived>
4103Sema::OwningStmtResult
4104TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4105 // Transform the exception declaration, if any.
4106 VarDecl *Var = 0;
4107 if (S->getExceptionDecl()) {
4108 VarDecl *ExceptionDecl = S->getExceptionDecl();
4109 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4110 ExceptionDecl->getDeclName());
4111
4112 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4113 if (T.isNull())
4114 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004115
Douglas Gregor43959a92009-08-20 07:17:43 +00004116 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4117 T,
John McCalla93c9342009-12-07 02:54:59 +00004118 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004119 ExceptionDecl->getIdentifier(),
4120 ExceptionDecl->getLocation(),
4121 /*FIXME: Inaccurate*/
4122 SourceRange(ExceptionDecl->getLocation()));
Douglas Gregorff331c12010-07-25 18:17:45 +00004123 if (!Var || Var->isInvalidDecl())
Douglas Gregor43959a92009-08-20 07:17:43 +00004124 return SemaRef.StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004125 }
Mike Stump1eb44332009-09-09 15:08:12 +00004126
Douglas Gregor43959a92009-08-20 07:17:43 +00004127 // Transform the actual exception handler.
4128 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00004129 if (Handler.isInvalid())
Douglas Gregor43959a92009-08-20 07:17:43 +00004130 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004131
Douglas Gregor43959a92009-08-20 07:17:43 +00004132 if (!getDerived().AlwaysRebuild() &&
4133 !Var &&
4134 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00004135 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004136
4137 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4138 Var,
4139 move(Handler));
4140}
Mike Stump1eb44332009-09-09 15:08:12 +00004141
Douglas Gregor43959a92009-08-20 07:17:43 +00004142template<typename Derived>
4143Sema::OwningStmtResult
4144TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4145 // Transform the try block itself.
Mike Stump1eb44332009-09-09 15:08:12 +00004146 OwningStmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004147 = getDerived().TransformCompoundStmt(S->getTryBlock());
4148 if (TryBlock.isInvalid())
4149 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004150
Douglas Gregor43959a92009-08-20 07:17:43 +00004151 // Transform the handlers.
4152 bool HandlerChanged = false;
4153 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4154 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump1eb44332009-09-09 15:08:12 +00004155 OwningStmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004156 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4157 if (Handler.isInvalid())
4158 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004159
Douglas Gregor43959a92009-08-20 07:17:43 +00004160 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4161 Handlers.push_back(Handler.takeAs<Stmt>());
4162 }
Mike Stump1eb44332009-09-09 15:08:12 +00004163
Douglas Gregor43959a92009-08-20 07:17:43 +00004164 if (!getDerived().AlwaysRebuild() &&
4165 TryBlock.get() == S->getTryBlock() &&
4166 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004167 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004168
4169 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump1eb44332009-09-09 15:08:12 +00004170 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004171}
Mike Stump1eb44332009-09-09 15:08:12 +00004172
Douglas Gregor43959a92009-08-20 07:17:43 +00004173//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004174// Expression transformation
4175//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004176template<typename Derived>
4177Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004178TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004179 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004180}
Mike Stump1eb44332009-09-09 15:08:12 +00004181
4182template<typename Derived>
4183Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004184TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004185 NestedNameSpecifier *Qualifier = 0;
4186 if (E->getQualifier()) {
4187 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004188 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004189 if (!Qualifier)
4190 return SemaRef.ExprError();
4191 }
John McCalldbd872f2009-12-08 09:08:17 +00004192
4193 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004194 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4195 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004196 if (!ND)
4197 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004198
Sean Huntc3021132010-05-05 15:23:54 +00004199 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004200 Qualifier == E->getQualifier() &&
4201 ND == E->getDecl() &&
John McCalldbd872f2009-12-08 09:08:17 +00004202 !E->hasExplicitTemplateArgumentList()) {
4203
4204 // Mark it referenced in the new context regardless.
4205 // FIXME: this is a bit instantiation-specific.
4206 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4207
Mike Stump1eb44332009-09-09 15:08:12 +00004208 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004209 }
John McCalldbd872f2009-12-08 09:08:17 +00004210
4211 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4212 if (E->hasExplicitTemplateArgumentList()) {
4213 TemplateArgs = &TransArgs;
4214 TransArgs.setLAngleLoc(E->getLAngleLoc());
4215 TransArgs.setRAngleLoc(E->getRAngleLoc());
4216 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4217 TemplateArgumentLoc Loc;
4218 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4219 return SemaRef.ExprError();
4220 TransArgs.addArgument(Loc);
4221 }
4222 }
4223
Douglas Gregora2813ce2009-10-23 18:54:35 +00004224 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCalldbd872f2009-12-08 09:08:17 +00004225 ND, E->getLocation(), TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004226}
Mike Stump1eb44332009-09-09 15:08:12 +00004227
Douglas Gregorb98b1992009-08-11 05:31:07 +00004228template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004229Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004230TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004231 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004232}
Mike Stump1eb44332009-09-09 15:08:12 +00004233
Douglas Gregorb98b1992009-08-11 05:31:07 +00004234template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004235Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004236TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004237 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004238}
Mike Stump1eb44332009-09-09 15:08:12 +00004239
Douglas Gregorb98b1992009-08-11 05:31:07 +00004240template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004241Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004242TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004243 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004244}
Mike Stump1eb44332009-09-09 15:08:12 +00004245
Douglas Gregorb98b1992009-08-11 05:31:07 +00004246template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004247Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004248TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004249 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004250}
Mike Stump1eb44332009-09-09 15:08:12 +00004251
Douglas Gregorb98b1992009-08-11 05:31:07 +00004252template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004253Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004254TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004255 return SemaRef.Owned(E->Retain());
4256}
4257
4258template<typename Derived>
4259Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004260TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004261 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4262 if (SubExpr.isInvalid())
4263 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004264
Douglas Gregorb98b1992009-08-11 05:31:07 +00004265 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004266 return SemaRef.Owned(E->Retain());
4267
4268 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004269 E->getRParen());
4270}
4271
Mike Stump1eb44332009-09-09 15:08:12 +00004272template<typename Derived>
4273Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004274TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4275 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004276 if (SubExpr.isInvalid())
4277 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004278
Douglas Gregorb98b1992009-08-11 05:31:07 +00004279 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004280 return SemaRef.Owned(E->Retain());
4281
Douglas Gregorb98b1992009-08-11 05:31:07 +00004282 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4283 E->getOpcode(),
4284 move(SubExpr));
4285}
Mike Stump1eb44332009-09-09 15:08:12 +00004286
Douglas Gregorb98b1992009-08-11 05:31:07 +00004287template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004288Sema::OwningExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004289TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4290 // Transform the type.
4291 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4292 if (!Type)
4293 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004294
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004295 // Transform all of the components into components similar to what the
4296 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004297 // FIXME: It would be slightly more efficient in the non-dependent case to
4298 // just map FieldDecls, rather than requiring the rebuilder to look for
4299 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004300 // template code that we don't care.
4301 bool ExprChanged = false;
4302 typedef Action::OffsetOfComponent Component;
4303 typedef OffsetOfExpr::OffsetOfNode Node;
4304 llvm::SmallVector<Component, 4> Components;
4305 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4306 const Node &ON = E->getComponent(I);
4307 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004308 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004309 Comp.LocStart = ON.getRange().getBegin();
4310 Comp.LocEnd = ON.getRange().getEnd();
4311 switch (ON.getKind()) {
4312 case Node::Array: {
4313 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4314 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4315 if (Index.isInvalid())
4316 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004317
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004318 ExprChanged = ExprChanged || Index.get() != FromIndex;
4319 Comp.isBrackets = true;
4320 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4321 break;
4322 }
Sean Huntc3021132010-05-05 15:23:54 +00004323
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004324 case Node::Field:
4325 case Node::Identifier:
4326 Comp.isBrackets = false;
4327 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004328 if (!Comp.U.IdentInfo)
4329 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004330
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004331 break;
Sean Huntc3021132010-05-05 15:23:54 +00004332
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004333 case Node::Base:
4334 // Will be recomputed during the rebuild.
4335 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004336 }
Sean Huntc3021132010-05-05 15:23:54 +00004337
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004338 Components.push_back(Comp);
4339 }
Sean Huntc3021132010-05-05 15:23:54 +00004340
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004341 // If nothing changed, retain the existing expression.
4342 if (!getDerived().AlwaysRebuild() &&
4343 Type == E->getTypeSourceInfo() &&
4344 !ExprChanged)
4345 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004346
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004347 // Build a new offsetof expression.
4348 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4349 Components.data(), Components.size(),
4350 E->getRParenLoc());
4351}
4352
4353template<typename Derived>
4354Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004355TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004356 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004357 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004358
John McCalla93c9342009-12-07 02:54:59 +00004359 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004360 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004361 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004362
John McCall5ab75172009-11-04 07:28:41 +00004363 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004364 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004365
John McCall5ab75172009-11-04 07:28:41 +00004366 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004367 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004368 E->getSourceRange());
4369 }
Mike Stump1eb44332009-09-09 15:08:12 +00004370
Douglas Gregorb98b1992009-08-11 05:31:07 +00004371 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00004372 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004373 // C++0x [expr.sizeof]p1:
4374 // The operand is either an expression, which is an unevaluated operand
4375 // [...]
4376 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004377
Douglas Gregorb98b1992009-08-11 05:31:07 +00004378 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4379 if (SubExpr.isInvalid())
4380 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004381
Douglas Gregorb98b1992009-08-11 05:31:07 +00004382 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4383 return SemaRef.Owned(E->Retain());
4384 }
Mike Stump1eb44332009-09-09 15:08:12 +00004385
Douglas Gregorb98b1992009-08-11 05:31:07 +00004386 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4387 E->isSizeOf(),
4388 E->getSourceRange());
4389}
Mike Stump1eb44332009-09-09 15:08:12 +00004390
Douglas Gregorb98b1992009-08-11 05:31:07 +00004391template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004392Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004393TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004394 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4395 if (LHS.isInvalid())
4396 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004397
Douglas Gregorb98b1992009-08-11 05:31:07 +00004398 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4399 if (RHS.isInvalid())
4400 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004401
4402
Douglas Gregorb98b1992009-08-11 05:31:07 +00004403 if (!getDerived().AlwaysRebuild() &&
4404 LHS.get() == E->getLHS() &&
4405 RHS.get() == E->getRHS())
4406 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004407
Douglas Gregorb98b1992009-08-11 05:31:07 +00004408 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4409 /*FIXME:*/E->getLHS()->getLocStart(),
4410 move(RHS),
4411 E->getRBracketLoc());
4412}
Mike Stump1eb44332009-09-09 15:08:12 +00004413
4414template<typename Derived>
4415Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004416TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004417 // Transform the callee.
4418 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4419 if (Callee.isInvalid())
4420 return SemaRef.ExprError();
4421
4422 // Transform arguments.
4423 bool ArgChanged = false;
4424 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4425 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4426 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4427 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4428 if (Arg.isInvalid())
4429 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004430
Douglas Gregorb98b1992009-08-11 05:31:07 +00004431 // FIXME: Wrong source location information for the ','.
4432 FakeCommaLocs.push_back(
4433 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00004434
4435 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004436 Args.push_back(Arg.takeAs<Expr>());
4437 }
Mike Stump1eb44332009-09-09 15:08:12 +00004438
Douglas Gregorb98b1992009-08-11 05:31:07 +00004439 if (!getDerived().AlwaysRebuild() &&
4440 Callee.get() == E->getCallee() &&
4441 !ArgChanged)
4442 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004443
Douglas Gregorb98b1992009-08-11 05:31:07 +00004444 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004445 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004446 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4447 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4448 move_arg(Args),
4449 FakeCommaLocs.data(),
4450 E->getRParenLoc());
4451}
Mike Stump1eb44332009-09-09 15:08:12 +00004452
4453template<typename Derived>
4454Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004455TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004456 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4457 if (Base.isInvalid())
4458 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004459
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004460 NestedNameSpecifier *Qualifier = 0;
4461 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004462 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004463 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004464 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004465 if (Qualifier == 0)
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004466 return SemaRef.ExprError();
4467 }
Mike Stump1eb44332009-09-09 15:08:12 +00004468
Eli Friedmanf595cc42009-12-04 06:40:45 +00004469 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004470 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4471 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004472 if (!Member)
4473 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004474
John McCall6bb80172010-03-30 21:47:33 +00004475 NamedDecl *FoundDecl = E->getFoundDecl();
4476 if (FoundDecl == E->getMemberDecl()) {
4477 FoundDecl = Member;
4478 } else {
4479 FoundDecl = cast_or_null<NamedDecl>(
4480 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4481 if (!FoundDecl)
4482 return SemaRef.ExprError();
4483 }
4484
Douglas Gregorb98b1992009-08-11 05:31:07 +00004485 if (!getDerived().AlwaysRebuild() &&
4486 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004487 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004488 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004489 FoundDecl == E->getFoundDecl() &&
Anders Carlsson1f240322009-12-22 05:24:09 +00004490 !E->hasExplicitTemplateArgumentList()) {
Sean Huntc3021132010-05-05 15:23:54 +00004491
Anders Carlsson1f240322009-12-22 05:24:09 +00004492 // Mark it referenced in the new context regardless.
4493 // FIXME: this is a bit instantiation-specific.
4494 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00004495 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00004496 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004497
John McCalld5532b62009-11-23 01:53:49 +00004498 TemplateArgumentListInfo TransArgs;
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004499 if (E->hasExplicitTemplateArgumentList()) {
John McCalld5532b62009-11-23 01:53:49 +00004500 TransArgs.setLAngleLoc(E->getLAngleLoc());
4501 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004502 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004503 TemplateArgumentLoc Loc;
4504 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004505 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004506 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004507 }
4508 }
Sean Huntc3021132010-05-05 15:23:54 +00004509
Douglas Gregorb98b1992009-08-11 05:31:07 +00004510 // FIXME: Bogus source location for the operator
4511 SourceLocation FakeOperatorLoc
4512 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4513
John McCallc2233c52010-01-15 08:34:02 +00004514 // FIXME: to do this check properly, we will need to preserve the
4515 // first-qualifier-in-scope here, just in case we had a dependent
4516 // base (and therefore couldn't do the check) and a
4517 // nested-name-qualifier (and therefore could do the lookup).
4518 NamedDecl *FirstQualifierInScope = 0;
4519
Douglas Gregorb98b1992009-08-11 05:31:07 +00004520 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4521 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004522 Qualifier,
4523 E->getQualifierRange(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004524 E->getMemberLoc(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004525 Member,
John McCall6bb80172010-03-30 21:47:33 +00004526 FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00004527 (E->hasExplicitTemplateArgumentList()
4528 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004529 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004530}
Mike Stump1eb44332009-09-09 15:08:12 +00004531
Douglas Gregorb98b1992009-08-11 05:31:07 +00004532template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00004533Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004534TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004535 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4536 if (LHS.isInvalid())
4537 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004538
Douglas Gregorb98b1992009-08-11 05:31:07 +00004539 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4540 if (RHS.isInvalid())
4541 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004542
Douglas Gregorb98b1992009-08-11 05:31:07 +00004543 if (!getDerived().AlwaysRebuild() &&
4544 LHS.get() == E->getLHS() &&
4545 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004546 return SemaRef.Owned(E->Retain());
4547
Douglas Gregorb98b1992009-08-11 05:31:07 +00004548 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4549 move(LHS), move(RHS));
4550}
4551
Mike Stump1eb44332009-09-09 15:08:12 +00004552template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00004553Sema::OwningExprResult
4554TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004555 CompoundAssignOperator *E) {
4556 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004557}
Mike Stump1eb44332009-09-09 15:08:12 +00004558
Douglas Gregorb98b1992009-08-11 05:31:07 +00004559template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004560Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004561TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004562 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4563 if (Cond.isInvalid())
4564 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004565
Douglas Gregorb98b1992009-08-11 05:31:07 +00004566 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4567 if (LHS.isInvalid())
4568 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004569
Douglas Gregorb98b1992009-08-11 05:31:07 +00004570 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4571 if (RHS.isInvalid())
4572 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004573
Douglas Gregorb98b1992009-08-11 05:31:07 +00004574 if (!getDerived().AlwaysRebuild() &&
4575 Cond.get() == E->getCond() &&
4576 LHS.get() == E->getLHS() &&
4577 RHS.get() == E->getRHS())
4578 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004579
4580 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004581 E->getQuestionLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004582 move(LHS),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004583 E->getColonLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004584 move(RHS));
4585}
Mike Stump1eb44332009-09-09 15:08:12 +00004586
4587template<typename Derived>
4588Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004589TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004590 // Implicit casts are eliminated during transformation, since they
4591 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004592 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004593}
Mike Stump1eb44332009-09-09 15:08:12 +00004594
Douglas Gregorb98b1992009-08-11 05:31:07 +00004595template<typename Derived>
4596Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004597TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004598 TypeSourceInfo *OldT;
4599 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004600 {
4601 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004602 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004603 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4604 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004605
John McCall9d125032010-01-15 18:39:57 +00004606 OldT = E->getTypeInfoAsWritten();
4607 NewT = getDerived().TransformType(OldT);
4608 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004609 return SemaRef.ExprError();
4610 }
Mike Stump1eb44332009-09-09 15:08:12 +00004611
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004612 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004613 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004614 if (SubExpr.isInvalid())
4615 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004616
Douglas Gregorb98b1992009-08-11 05:31:07 +00004617 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004618 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004619 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004620 return SemaRef.Owned(E->Retain());
4621
John McCall9d125032010-01-15 18:39:57 +00004622 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4623 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004624 E->getRParenLoc(),
4625 move(SubExpr));
4626}
Mike Stump1eb44332009-09-09 15:08:12 +00004627
Douglas Gregorb98b1992009-08-11 05:31:07 +00004628template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004629Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004630TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004631 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4632 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4633 if (!NewT)
4634 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004635
Douglas Gregorb98b1992009-08-11 05:31:07 +00004636 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4637 if (Init.isInvalid())
4638 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004639
Douglas Gregorb98b1992009-08-11 05:31:07 +00004640 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004641 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004642 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00004643 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004644
John McCall1d7d8d62010-01-19 22:33:45 +00004645 // Note: the expression type doesn't necessarily match the
4646 // type-as-written, but that's okay, because it should always be
4647 // derivable from the initializer.
4648
John McCall42f56b52010-01-18 19:35:47 +00004649 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004650 /*FIXME:*/E->getInitializer()->getLocEnd(),
4651 move(Init));
4652}
Mike Stump1eb44332009-09-09 15:08:12 +00004653
Douglas Gregorb98b1992009-08-11 05:31:07 +00004654template<typename Derived>
4655Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004656TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004657 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4658 if (Base.isInvalid())
4659 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004660
Douglas Gregorb98b1992009-08-11 05:31:07 +00004661 if (!getDerived().AlwaysRebuild() &&
4662 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00004663 return SemaRef.Owned(E->Retain());
4664
Douglas Gregorb98b1992009-08-11 05:31:07 +00004665 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004666 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004667 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4668 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4669 E->getAccessorLoc(),
4670 E->getAccessor());
4671}
Mike Stump1eb44332009-09-09 15:08:12 +00004672
Douglas Gregorb98b1992009-08-11 05:31:07 +00004673template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004674Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004675TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004676 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004677
Douglas Gregorb98b1992009-08-11 05:31:07 +00004678 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4679 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4680 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4681 if (Init.isInvalid())
4682 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004683
Douglas Gregorb98b1992009-08-11 05:31:07 +00004684 InitChanged = InitChanged || Init.get() != E->getInit(I);
4685 Inits.push_back(Init.takeAs<Expr>());
4686 }
Mike Stump1eb44332009-09-09 15:08:12 +00004687
Douglas Gregorb98b1992009-08-11 05:31:07 +00004688 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004689 return SemaRef.Owned(E->Retain());
4690
Douglas Gregorb98b1992009-08-11 05:31:07 +00004691 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004692 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004693}
Mike Stump1eb44332009-09-09 15:08:12 +00004694
Douglas Gregorb98b1992009-08-11 05:31:07 +00004695template<typename Derived>
4696Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004697TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004698 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004699
Douglas Gregor43959a92009-08-20 07:17:43 +00004700 // transform the initializer value
Douglas Gregorb98b1992009-08-11 05:31:07 +00004701 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4702 if (Init.isInvalid())
4703 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004704
Douglas Gregor43959a92009-08-20 07:17:43 +00004705 // transform the designators.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004706 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4707 bool ExprChanged = false;
4708 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4709 DEnd = E->designators_end();
4710 D != DEnd; ++D) {
4711 if (D->isFieldDesignator()) {
4712 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4713 D->getDotLoc(),
4714 D->getFieldLoc()));
4715 continue;
4716 }
Mike Stump1eb44332009-09-09 15:08:12 +00004717
Douglas Gregorb98b1992009-08-11 05:31:07 +00004718 if (D->isArrayDesignator()) {
4719 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4720 if (Index.isInvalid())
4721 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004722
4723 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004724 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004725
Douglas Gregorb98b1992009-08-11 05:31:07 +00004726 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4727 ArrayExprs.push_back(Index.release());
4728 continue;
4729 }
Mike Stump1eb44332009-09-09 15:08:12 +00004730
Douglas Gregorb98b1992009-08-11 05:31:07 +00004731 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump1eb44332009-09-09 15:08:12 +00004732 OwningExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004733 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4734 if (Start.isInvalid())
4735 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004736
Douglas Gregorb98b1992009-08-11 05:31:07 +00004737 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4738 if (End.isInvalid())
4739 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004740
4741 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004742 End.get(),
4743 D->getLBracketLoc(),
4744 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004745
Douglas Gregorb98b1992009-08-11 05:31:07 +00004746 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4747 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004748
Douglas Gregorb98b1992009-08-11 05:31:07 +00004749 ArrayExprs.push_back(Start.release());
4750 ArrayExprs.push_back(End.release());
4751 }
Mike Stump1eb44332009-09-09 15:08:12 +00004752
Douglas Gregorb98b1992009-08-11 05:31:07 +00004753 if (!getDerived().AlwaysRebuild() &&
4754 Init.get() == E->getInit() &&
4755 !ExprChanged)
4756 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004757
Douglas Gregorb98b1992009-08-11 05:31:07 +00004758 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4759 E->getEqualOrColonLoc(),
4760 E->usesGNUSyntax(), move(Init));
4761}
Mike Stump1eb44332009-09-09 15:08:12 +00004762
Douglas Gregorb98b1992009-08-11 05:31:07 +00004763template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004764Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004765TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004766 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004767 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00004768
Douglas Gregor5557b252009-10-28 00:29:27 +00004769 // FIXME: Will we ever have proper type location here? Will we actually
4770 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004771 QualType T = getDerived().TransformType(E->getType());
4772 if (T.isNull())
4773 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004774
Douglas Gregorb98b1992009-08-11 05:31:07 +00004775 if (!getDerived().AlwaysRebuild() &&
4776 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004777 return SemaRef.Owned(E->Retain());
4778
Douglas Gregorb98b1992009-08-11 05:31:07 +00004779 return getDerived().RebuildImplicitValueInitExpr(T);
4780}
Mike Stump1eb44332009-09-09 15:08:12 +00004781
Douglas Gregorb98b1992009-08-11 05:31:07 +00004782template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004783Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004784TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004785 TypeSourceInfo *TInfo;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004786 {
4787 // FIXME: Source location isn't quite accurate.
4788 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004789 TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4790 if (!TInfo)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004791 return SemaRef.ExprError();
4792 }
Mike Stump1eb44332009-09-09 15:08:12 +00004793
Douglas Gregorb98b1992009-08-11 05:31:07 +00004794 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4795 if (SubExpr.isInvalid())
4796 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004797
Douglas Gregorb98b1992009-08-11 05:31:07 +00004798 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004799 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004800 SubExpr.get() == E->getSubExpr())
4801 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004802
Douglas Gregorb98b1992009-08-11 05:31:07 +00004803 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004804 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004805}
4806
4807template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004808Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004809TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004810 bool ArgumentChanged = false;
4811 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4812 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4813 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4814 if (Init.isInvalid())
4815 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004816
Douglas Gregorb98b1992009-08-11 05:31:07 +00004817 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4818 Inits.push_back(Init.takeAs<Expr>());
4819 }
Mike Stump1eb44332009-09-09 15:08:12 +00004820
Douglas Gregorb98b1992009-08-11 05:31:07 +00004821 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4822 move_arg(Inits),
4823 E->getRParenLoc());
4824}
Mike Stump1eb44332009-09-09 15:08:12 +00004825
Douglas Gregorb98b1992009-08-11 05:31:07 +00004826/// \brief Transform an address-of-label expression.
4827///
4828/// By default, the transformation of an address-of-label expression always
4829/// rebuilds the expression, so that the label identifier can be resolved to
4830/// the corresponding label statement by semantic analysis.
4831template<typename Derived>
4832Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004833TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004834 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4835 E->getLabel());
4836}
Mike Stump1eb44332009-09-09 15:08:12 +00004837
4838template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00004839Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004840TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004841 OwningStmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004842 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4843 if (SubStmt.isInvalid())
4844 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004845
Douglas Gregorb98b1992009-08-11 05:31:07 +00004846 if (!getDerived().AlwaysRebuild() &&
4847 SubStmt.get() == E->getSubStmt())
4848 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004849
4850 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004851 move(SubStmt),
4852 E->getRParenLoc());
4853}
Mike Stump1eb44332009-09-09 15:08:12 +00004854
Douglas Gregorb98b1992009-08-11 05:31:07 +00004855template<typename Derived>
4856Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004857TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004858 TypeSourceInfo *TInfo1;
4859 TypeSourceInfo *TInfo2;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004860 {
4861 // FIXME: Source location isn't quite accurate.
4862 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004863
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004864 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4865 if (!TInfo1)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004866 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004867
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004868 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4869 if (!TInfo2)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004870 return SemaRef.ExprError();
4871 }
4872
4873 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004874 TInfo1 == E->getArgTInfo1() &&
4875 TInfo2 == E->getArgTInfo2())
Mike Stump1eb44332009-09-09 15:08:12 +00004876 return SemaRef.Owned(E->Retain());
4877
Douglas Gregorb98b1992009-08-11 05:31:07 +00004878 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004879 TInfo1, TInfo2,
4880 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004881}
Mike Stump1eb44332009-09-09 15:08:12 +00004882
Douglas Gregorb98b1992009-08-11 05:31:07 +00004883template<typename Derived>
4884Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004885TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004886 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4887 if (Cond.isInvalid())
4888 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004889
Douglas Gregorb98b1992009-08-11 05:31:07 +00004890 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4891 if (LHS.isInvalid())
4892 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004893
Douglas Gregorb98b1992009-08-11 05:31:07 +00004894 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4895 if (RHS.isInvalid())
4896 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004897
Douglas Gregorb98b1992009-08-11 05:31:07 +00004898 if (!getDerived().AlwaysRebuild() &&
4899 Cond.get() == E->getCond() &&
4900 LHS.get() == E->getLHS() &&
4901 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004902 return SemaRef.Owned(E->Retain());
4903
Douglas Gregorb98b1992009-08-11 05:31:07 +00004904 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4905 move(Cond), move(LHS), move(RHS),
4906 E->getRParenLoc());
4907}
Mike Stump1eb44332009-09-09 15:08:12 +00004908
Douglas Gregorb98b1992009-08-11 05:31:07 +00004909template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004910Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004911TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004912 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004913}
4914
4915template<typename Derived>
4916Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004917TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004918 switch (E->getOperator()) {
4919 case OO_New:
4920 case OO_Delete:
4921 case OO_Array_New:
4922 case OO_Array_Delete:
4923 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4924 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004925
Douglas Gregor668d6d92009-12-13 20:44:55 +00004926 case OO_Call: {
4927 // This is a call to an object's operator().
4928 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4929
4930 // Transform the object itself.
4931 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4932 if (Object.isInvalid())
4933 return SemaRef.ExprError();
4934
4935 // FIXME: Poor location information
4936 SourceLocation FakeLParenLoc
4937 = SemaRef.PP.getLocForEndOfToken(
4938 static_cast<Expr *>(Object.get())->getLocEnd());
4939
4940 // Transform the call arguments.
4941 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4942 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4943 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004944 if (getDerived().DropCallArgument(E->getArg(I)))
4945 break;
Sean Huntc3021132010-05-05 15:23:54 +00004946
Douglas Gregor668d6d92009-12-13 20:44:55 +00004947 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4948 if (Arg.isInvalid())
4949 return SemaRef.ExprError();
4950
4951 // FIXME: Poor source location information.
4952 SourceLocation FakeCommaLoc
4953 = SemaRef.PP.getLocForEndOfToken(
4954 static_cast<Expr *>(Arg.get())->getLocEnd());
4955 FakeCommaLocs.push_back(FakeCommaLoc);
4956 Args.push_back(Arg.release());
4957 }
4958
4959 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4960 move_arg(Args),
4961 FakeCommaLocs.data(),
4962 E->getLocEnd());
4963 }
4964
4965#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4966 case OO_##Name:
4967#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4968#include "clang/Basic/OperatorKinds.def"
4969 case OO_Subscript:
4970 // Handled below.
4971 break;
4972
4973 case OO_Conditional:
4974 llvm_unreachable("conditional operator is not actually overloadable");
4975 return SemaRef.ExprError();
4976
4977 case OO_None:
4978 case NUM_OVERLOADED_OPERATORS:
4979 llvm_unreachable("not an overloaded operator?");
4980 return SemaRef.ExprError();
4981 }
4982
Douglas Gregorb98b1992009-08-11 05:31:07 +00004983 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4984 if (Callee.isInvalid())
4985 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004986
John McCall454feb92009-12-08 09:21:05 +00004987 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004988 if (First.isInvalid())
4989 return SemaRef.ExprError();
4990
4991 OwningExprResult Second(SemaRef);
4992 if (E->getNumArgs() == 2) {
4993 Second = getDerived().TransformExpr(E->getArg(1));
4994 if (Second.isInvalid())
4995 return SemaRef.ExprError();
4996 }
Mike Stump1eb44332009-09-09 15:08:12 +00004997
Douglas Gregorb98b1992009-08-11 05:31:07 +00004998 if (!getDerived().AlwaysRebuild() &&
4999 Callee.get() == E->getCallee() &&
5000 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005001 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
5002 return SemaRef.Owned(E->Retain());
5003
Douglas Gregorb98b1992009-08-11 05:31:07 +00005004 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5005 E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005006 move(Callee),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005007 move(First),
5008 move(Second));
5009}
Mike Stump1eb44332009-09-09 15:08:12 +00005010
Douglas Gregorb98b1992009-08-11 05:31:07 +00005011template<typename Derived>
5012Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005013TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5014 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005015}
Mike Stump1eb44332009-09-09 15:08:12 +00005016
Douglas Gregorb98b1992009-08-11 05:31:07 +00005017template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005018Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005019TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00005020 TypeSourceInfo *OldT;
5021 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005022 {
5023 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00005024 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005025 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5026 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005027
John McCall9d125032010-01-15 18:39:57 +00005028 OldT = E->getTypeInfoAsWritten();
5029 NewT = getDerived().TransformType(OldT);
5030 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005031 return SemaRef.ExprError();
5032 }
Mike Stump1eb44332009-09-09 15:08:12 +00005033
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005034 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005035 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005036 if (SubExpr.isInvalid())
5037 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005038
Douglas Gregorb98b1992009-08-11 05:31:07 +00005039 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00005040 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005041 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005042 return SemaRef.Owned(E->Retain());
5043
Douglas Gregorb98b1992009-08-11 05:31:07 +00005044 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005045 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005046 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5047 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5048 SourceLocation FakeRParenLoc
5049 = SemaRef.PP.getLocForEndOfToken(
5050 E->getSubExpr()->getSourceRange().getEnd());
5051 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005052 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005053 FakeLAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00005054 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005055 FakeRAngleLoc,
5056 FakeRAngleLoc,
5057 move(SubExpr),
5058 FakeRParenLoc);
5059}
Mike Stump1eb44332009-09-09 15:08:12 +00005060
Douglas Gregorb98b1992009-08-11 05:31:07 +00005061template<typename Derived>
5062Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005063TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5064 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005065}
Mike Stump1eb44332009-09-09 15:08:12 +00005066
5067template<typename Derived>
5068Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005069TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5070 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005071}
5072
Douglas Gregorb98b1992009-08-11 05:31:07 +00005073template<typename Derived>
5074Sema::OwningExprResult
5075TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005076 CXXReinterpretCastExpr *E) {
5077 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005078}
Mike Stump1eb44332009-09-09 15:08:12 +00005079
Douglas Gregorb98b1992009-08-11 05:31:07 +00005080template<typename Derived>
5081Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005082TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5083 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005084}
Mike Stump1eb44332009-09-09 15:08:12 +00005085
Douglas Gregorb98b1992009-08-11 05:31:07 +00005086template<typename Derived>
5087Sema::OwningExprResult
5088TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005089 CXXFunctionalCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00005090 TypeSourceInfo *OldT;
5091 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005092 {
5093 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005094
John McCall9d125032010-01-15 18:39:57 +00005095 OldT = E->getTypeInfoAsWritten();
5096 NewT = getDerived().TransformType(OldT);
5097 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005098 return SemaRef.ExprError();
5099 }
Mike Stump1eb44332009-09-09 15:08:12 +00005100
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005101 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005102 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005103 if (SubExpr.isInvalid())
5104 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005105
Douglas Gregorb98b1992009-08-11 05:31:07 +00005106 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00005107 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005108 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005109 return SemaRef.Owned(E->Retain());
5110
Douglas Gregorb98b1992009-08-11 05:31:07 +00005111 // FIXME: The end of the type's source range is wrong
5112 return getDerived().RebuildCXXFunctionalCastExpr(
5113 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall9d125032010-01-15 18:39:57 +00005114 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005115 /*FIXME:*/E->getSubExpr()->getLocStart(),
5116 move(SubExpr),
5117 E->getRParenLoc());
5118}
Mike Stump1eb44332009-09-09 15:08:12 +00005119
Douglas Gregorb98b1992009-08-11 05:31:07 +00005120template<typename Derived>
5121Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005122TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005123 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005124 TypeSourceInfo *TInfo
5125 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5126 if (!TInfo)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005127 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005128
Douglas Gregorb98b1992009-08-11 05:31:07 +00005129 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005130 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregorb98b1992009-08-11 05:31:07 +00005131 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005132
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005133 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5134 E->getLocStart(),
5135 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005136 E->getLocEnd());
5137 }
Mike Stump1eb44332009-09-09 15:08:12 +00005138
Douglas Gregorb98b1992009-08-11 05:31:07 +00005139 // We don't know whether the expression is potentially evaluated until
5140 // after we perform semantic analysis, so the expression is potentially
5141 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005142 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005143 Action::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005144
Douglas Gregorb98b1992009-08-11 05:31:07 +00005145 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5146 if (SubExpr.isInvalid())
5147 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005148
Douglas Gregorb98b1992009-08-11 05:31:07 +00005149 if (!getDerived().AlwaysRebuild() &&
5150 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00005151 return SemaRef.Owned(E->Retain());
5152
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005153 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5154 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005155 move(SubExpr),
5156 E->getLocEnd());
5157}
5158
5159template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005160Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005161TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005162 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005163}
Mike Stump1eb44332009-09-09 15:08:12 +00005164
Douglas Gregorb98b1992009-08-11 05:31:07 +00005165template<typename Derived>
5166Sema::OwningExprResult
5167TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005168 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005169 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005170}
Mike Stump1eb44332009-09-09 15:08:12 +00005171
Douglas Gregorb98b1992009-08-11 05:31:07 +00005172template<typename Derived>
5173Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005174TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005175 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005176
Douglas Gregorb98b1992009-08-11 05:31:07 +00005177 QualType T = getDerived().TransformType(E->getType());
5178 if (T.isNull())
5179 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005180
Douglas Gregorb98b1992009-08-11 05:31:07 +00005181 if (!getDerived().AlwaysRebuild() &&
5182 T == E->getType())
5183 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005184
Douglas Gregor828a1972010-01-07 23:12:05 +00005185 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005186}
Mike Stump1eb44332009-09-09 15:08:12 +00005187
Douglas Gregorb98b1992009-08-11 05:31:07 +00005188template<typename Derived>
5189Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005190TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005191 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5192 if (SubExpr.isInvalid())
5193 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005194
Douglas Gregorb98b1992009-08-11 05:31:07 +00005195 if (!getDerived().AlwaysRebuild() &&
5196 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005197 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005198
5199 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5200}
Mike Stump1eb44332009-09-09 15:08:12 +00005201
Douglas Gregorb98b1992009-08-11 05:31:07 +00005202template<typename Derived>
5203Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005204TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005205 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005206 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5207 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005208 if (!Param)
5209 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005210
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005211 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005212 Param == E->getParam())
5213 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005214
Douglas Gregor036aed12009-12-23 23:03:06 +00005215 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005216}
Mike Stump1eb44332009-09-09 15:08:12 +00005217
Douglas Gregorb98b1992009-08-11 05:31:07 +00005218template<typename Derived>
5219Sema::OwningExprResult
Douglas Gregored8abf12010-07-08 06:14:04 +00005220TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005221 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5222
5223 QualType T = getDerived().TransformType(E->getType());
5224 if (T.isNull())
5225 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005226
Douglas Gregorb98b1992009-08-11 05:31:07 +00005227 if (!getDerived().AlwaysRebuild() &&
5228 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00005229 return SemaRef.Owned(E->Retain());
5230
Douglas Gregored8abf12010-07-08 06:14:04 +00005231 return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(),
5232 /*FIXME:*/E->getTypeBeginLoc(),
5233 T,
5234 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005235}
Mike Stump1eb44332009-09-09 15:08:12 +00005236
Douglas Gregorb98b1992009-08-11 05:31:07 +00005237template<typename Derived>
5238Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005239TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005240 // Transform the type that we're allocating
5241 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5242 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5243 if (AllocType.isNull())
5244 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005245
Douglas Gregorb98b1992009-08-11 05:31:07 +00005246 // Transform the size of the array we're allocating (if any).
5247 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5248 if (ArraySize.isInvalid())
5249 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005250
Douglas Gregorb98b1992009-08-11 05:31:07 +00005251 // Transform the placement arguments (if any).
5252 bool ArgumentChanged = false;
5253 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5254 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5255 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5256 if (Arg.isInvalid())
5257 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005258
Douglas Gregorb98b1992009-08-11 05:31:07 +00005259 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5260 PlacementArgs.push_back(Arg.take());
5261 }
Mike Stump1eb44332009-09-09 15:08:12 +00005262
Douglas Gregor43959a92009-08-20 07:17:43 +00005263 // transform the constructor arguments (if any).
Douglas Gregorb98b1992009-08-11 05:31:07 +00005264 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5265 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005266 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5267 break;
5268
Douglas Gregorb98b1992009-08-11 05:31:07 +00005269 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5270 if (Arg.isInvalid())
5271 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005272
Douglas Gregorb98b1992009-08-11 05:31:07 +00005273 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5274 ConstructorArgs.push_back(Arg.take());
5275 }
Mike Stump1eb44332009-09-09 15:08:12 +00005276
Douglas Gregor1af74512010-02-26 00:38:10 +00005277 // Transform constructor, new operator, and delete operator.
5278 CXXConstructorDecl *Constructor = 0;
5279 if (E->getConstructor()) {
5280 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005281 getDerived().TransformDecl(E->getLocStart(),
5282 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005283 if (!Constructor)
5284 return SemaRef.ExprError();
5285 }
5286
5287 FunctionDecl *OperatorNew = 0;
5288 if (E->getOperatorNew()) {
5289 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005290 getDerived().TransformDecl(E->getLocStart(),
5291 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005292 if (!OperatorNew)
5293 return SemaRef.ExprError();
5294 }
5295
5296 FunctionDecl *OperatorDelete = 0;
5297 if (E->getOperatorDelete()) {
5298 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005299 getDerived().TransformDecl(E->getLocStart(),
5300 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005301 if (!OperatorDelete)
5302 return SemaRef.ExprError();
5303 }
Sean Huntc3021132010-05-05 15:23:54 +00005304
Douglas Gregorb98b1992009-08-11 05:31:07 +00005305 if (!getDerived().AlwaysRebuild() &&
5306 AllocType == E->getAllocatedType() &&
5307 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005308 Constructor == E->getConstructor() &&
5309 OperatorNew == E->getOperatorNew() &&
5310 OperatorDelete == E->getOperatorDelete() &&
5311 !ArgumentChanged) {
5312 // Mark any declarations we need as referenced.
5313 // FIXME: instantiation-specific.
5314 if (Constructor)
5315 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5316 if (OperatorNew)
5317 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5318 if (OperatorDelete)
5319 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005320 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005321 }
Mike Stump1eb44332009-09-09 15:08:12 +00005322
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005323 if (!ArraySize.get()) {
5324 // If no array size was specified, but the new expression was
5325 // instantiated with an array type (e.g., "new T" where T is
5326 // instantiated with "int[4]"), extract the outer bound from the
5327 // array type as our array size. We do this with constant and
5328 // dependently-sized array types.
5329 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5330 if (!ArrayT) {
5331 // Do nothing
5332 } else if (const ConstantArrayType *ConsArrayT
5333 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005334 ArraySize
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005335 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Sean Huntc3021132010-05-05 15:23:54 +00005336 ConsArrayT->getSize(),
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005337 SemaRef.Context.getSizeType(),
5338 /*FIXME:*/E->getLocStart()));
5339 AllocType = ConsArrayT->getElementType();
5340 } else if (const DependentSizedArrayType *DepArrayT
5341 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5342 if (DepArrayT->getSizeExpr()) {
5343 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5344 AllocType = DepArrayT->getElementType();
5345 }
5346 }
5347 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005348 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5349 E->isGlobalNew(),
5350 /*FIXME:*/E->getLocStart(),
5351 move_arg(PlacementArgs),
5352 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00005353 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005354 AllocType,
5355 /*FIXME:*/E->getLocStart(),
5356 /*FIXME:*/SourceRange(),
5357 move(ArraySize),
5358 /*FIXME:*/E->getLocStart(),
5359 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005360 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005361}
Mike Stump1eb44332009-09-09 15:08:12 +00005362
Douglas Gregorb98b1992009-08-11 05:31:07 +00005363template<typename Derived>
5364Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005365TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005366 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5367 if (Operand.isInvalid())
5368 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005369
Douglas Gregor1af74512010-02-26 00:38:10 +00005370 // Transform the delete operator, if known.
5371 FunctionDecl *OperatorDelete = 0;
5372 if (E->getOperatorDelete()) {
5373 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005374 getDerived().TransformDecl(E->getLocStart(),
5375 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005376 if (!OperatorDelete)
5377 return SemaRef.ExprError();
5378 }
Sean Huntc3021132010-05-05 15:23:54 +00005379
Douglas Gregorb98b1992009-08-11 05:31:07 +00005380 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005381 Operand.get() == E->getArgument() &&
5382 OperatorDelete == E->getOperatorDelete()) {
5383 // Mark any declarations we need as referenced.
5384 // FIXME: instantiation-specific.
5385 if (OperatorDelete)
5386 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005387 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005388 }
Mike Stump1eb44332009-09-09 15:08:12 +00005389
Douglas Gregorb98b1992009-08-11 05:31:07 +00005390 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5391 E->isGlobalDelete(),
5392 E->isArrayForm(),
5393 move(Operand));
5394}
Mike Stump1eb44332009-09-09 15:08:12 +00005395
Douglas Gregorb98b1992009-08-11 05:31:07 +00005396template<typename Derived>
5397Sema::OwningExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005398TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005399 CXXPseudoDestructorExpr *E) {
Douglas Gregora71d8192009-09-04 17:36:40 +00005400 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5401 if (Base.isInvalid())
5402 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005403
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005404 Sema::TypeTy *ObjectTypePtr = 0;
5405 bool MayBePseudoDestructor = false;
Sean Huntc3021132010-05-05 15:23:54 +00005406 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005407 E->getOperatorLoc(),
5408 E->isArrow()? tok::arrow : tok::period,
5409 ObjectTypePtr,
5410 MayBePseudoDestructor);
5411 if (Base.isInvalid())
5412 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005413
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005414 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregora71d8192009-09-04 17:36:40 +00005415 NestedNameSpecifier *Qualifier
5416 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00005417 E->getQualifierRange(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005418 ObjectType);
Douglas Gregora71d8192009-09-04 17:36:40 +00005419 if (E->getQualifier() && !Qualifier)
5420 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005421
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005422 PseudoDestructorTypeStorage Destroyed;
5423 if (E->getDestroyedTypeInfo()) {
5424 TypeSourceInfo *DestroyedTypeInfo
5425 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5426 if (!DestroyedTypeInfo)
5427 return SemaRef.ExprError();
5428 Destroyed = DestroyedTypeInfo;
5429 } else if (ObjectType->isDependentType()) {
5430 // We aren't likely to be able to resolve the identifier down to a type
5431 // now anyway, so just retain the identifier.
5432 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5433 E->getDestroyedTypeLoc());
5434 } else {
5435 // Look for a destructor known with the given name.
5436 CXXScopeSpec SS;
5437 if (Qualifier) {
5438 SS.setScopeRep(Qualifier);
5439 SS.setRange(E->getQualifierRange());
5440 }
Sean Huntc3021132010-05-05 15:23:54 +00005441
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005442 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5443 *E->getDestroyedTypeIdentifier(),
5444 E->getDestroyedTypeLoc(),
5445 /*Scope=*/0,
5446 SS, ObjectTypePtr,
5447 false);
5448 if (!T)
5449 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005450
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005451 Destroyed
5452 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5453 E->getDestroyedTypeLoc());
5454 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005455
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005456 TypeSourceInfo *ScopeTypeInfo = 0;
5457 if (E->getScopeTypeInfo()) {
Sean Huntc3021132010-05-05 15:23:54 +00005458 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005459 ObjectType);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005460 if (!ScopeTypeInfo)
Douglas Gregora71d8192009-09-04 17:36:40 +00005461 return SemaRef.ExprError();
5462 }
Sean Huntc3021132010-05-05 15:23:54 +00005463
Douglas Gregora71d8192009-09-04 17:36:40 +00005464 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5465 E->getOperatorLoc(),
5466 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005467 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005468 E->getQualifierRange(),
5469 ScopeTypeInfo,
5470 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005471 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005472 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00005473}
Mike Stump1eb44332009-09-09 15:08:12 +00005474
Douglas Gregora71d8192009-09-04 17:36:40 +00005475template<typename Derived>
5476Sema::OwningExprResult
John McCallba135432009-11-21 08:51:07 +00005477TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00005478 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00005479 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5480
5481 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5482 Sema::LookupOrdinaryName);
5483
5484 // Transform all the decls.
5485 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5486 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005487 NamedDecl *InstD = static_cast<NamedDecl*>(
5488 getDerived().TransformDecl(Old->getNameLoc(),
5489 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005490 if (!InstD) {
5491 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5492 // This can happen because of dependent hiding.
5493 if (isa<UsingShadowDecl>(*I))
5494 continue;
5495 else
5496 return SemaRef.ExprError();
5497 }
John McCallf7a1a742009-11-24 19:00:30 +00005498
5499 // Expand using declarations.
5500 if (isa<UsingDecl>(InstD)) {
5501 UsingDecl *UD = cast<UsingDecl>(InstD);
5502 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5503 E = UD->shadow_end(); I != E; ++I)
5504 R.addDecl(*I);
5505 continue;
5506 }
5507
5508 R.addDecl(InstD);
5509 }
5510
5511 // Resolve a kind, but don't do any further analysis. If it's
5512 // ambiguous, the callee needs to deal with it.
5513 R.resolveKind();
5514
5515 // Rebuild the nested-name qualifier, if present.
5516 CXXScopeSpec SS;
5517 NestedNameSpecifier *Qualifier = 0;
5518 if (Old->getQualifier()) {
5519 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005520 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00005521 if (!Qualifier)
5522 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005523
John McCallf7a1a742009-11-24 19:00:30 +00005524 SS.setScopeRep(Qualifier);
5525 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00005526 }
5527
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005528 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00005529 CXXRecordDecl *NamingClass
5530 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5531 Old->getNameLoc(),
5532 Old->getNamingClass()));
5533 if (!NamingClass)
5534 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005535
Douglas Gregor66c45152010-04-27 16:10:10 +00005536 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00005537 }
5538
5539 // If we have no template arguments, it's a normal declaration name.
5540 if (!Old->hasExplicitTemplateArgs())
5541 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5542
5543 // If we have template arguments, rebuild them, then rebuild the
5544 // templateid expression.
5545 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5546 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5547 TemplateArgumentLoc Loc;
5548 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5549 return SemaRef.ExprError();
5550 TransArgs.addArgument(Loc);
5551 }
5552
5553 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5554 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005555}
Mike Stump1eb44332009-09-09 15:08:12 +00005556
Douglas Gregorb98b1992009-08-11 05:31:07 +00005557template<typename Derived>
5558Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005559TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005560 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005561
Douglas Gregorb98b1992009-08-11 05:31:07 +00005562 QualType T = getDerived().TransformType(E->getQueriedType());
5563 if (T.isNull())
5564 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005565
Douglas Gregorb98b1992009-08-11 05:31:07 +00005566 if (!getDerived().AlwaysRebuild() &&
5567 T == E->getQueriedType())
5568 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005569
Douglas Gregorb98b1992009-08-11 05:31:07 +00005570 // FIXME: Bad location information
5571 SourceLocation FakeLParenLoc
5572 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump1eb44332009-09-09 15:08:12 +00005573
5574 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005575 E->getLocStart(),
5576 /*FIXME:*/FakeLParenLoc,
5577 T,
5578 E->getLocEnd());
5579}
Mike Stump1eb44332009-09-09 15:08:12 +00005580
Douglas Gregorb98b1992009-08-11 05:31:07 +00005581template<typename Derived>
5582Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00005583TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall454feb92009-12-08 09:21:05 +00005584 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005585 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00005586 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005587 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005588 if (!NNS)
5589 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005590
5591 DeclarationName Name
Douglas Gregor81499bb2009-09-03 22:13:48 +00005592 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5593 if (!Name)
5594 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005595
John McCallf7a1a742009-11-24 19:00:30 +00005596 if (!E->hasExplicitTemplateArgs()) {
5597 if (!getDerived().AlwaysRebuild() &&
5598 NNS == E->getQualifier() &&
5599 Name == E->getDeclName())
5600 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005601
John McCallf7a1a742009-11-24 19:00:30 +00005602 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5603 E->getQualifierRange(),
5604 Name, E->getLocation(),
5605 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00005606 }
John McCalld5532b62009-11-23 01:53:49 +00005607
5608 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005609 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005610 TemplateArgumentLoc Loc;
5611 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb98b1992009-08-11 05:31:07 +00005612 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005613 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005614 }
5615
John McCallf7a1a742009-11-24 19:00:30 +00005616 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5617 E->getQualifierRange(),
5618 Name, E->getLocation(),
5619 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005620}
5621
5622template<typename Derived>
5623Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005624TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00005625 // CXXConstructExprs are always implicit, so when we have a
5626 // 1-argument construction we just transform that argument.
5627 if (E->getNumArgs() == 1 ||
5628 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5629 return getDerived().TransformExpr(E->getArg(0));
5630
Douglas Gregorb98b1992009-08-11 05:31:07 +00005631 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5632
5633 QualType T = getDerived().TransformType(E->getType());
5634 if (T.isNull())
5635 return SemaRef.ExprError();
5636
5637 CXXConstructorDecl *Constructor
5638 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005639 getDerived().TransformDecl(E->getLocStart(),
5640 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005641 if (!Constructor)
5642 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005643
Douglas Gregorb98b1992009-08-11 05:31:07 +00005644 bool ArgumentChanged = false;
5645 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005646 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005647 ArgEnd = E->arg_end();
5648 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005649 if (getDerived().DropCallArgument(*Arg)) {
5650 ArgumentChanged = true;
5651 break;
5652 }
5653
Douglas Gregorb98b1992009-08-11 05:31:07 +00005654 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5655 if (TransArg.isInvalid())
5656 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005657
Douglas Gregorb98b1992009-08-11 05:31:07 +00005658 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5659 Args.push_back(TransArg.takeAs<Expr>());
5660 }
5661
5662 if (!getDerived().AlwaysRebuild() &&
5663 T == E->getType() &&
5664 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005665 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005666 // Mark the constructor as referenced.
5667 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005668 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005669 return SemaRef.Owned(E->Retain());
Douglas Gregorc845aad2010-02-26 00:01:57 +00005670 }
Mike Stump1eb44332009-09-09 15:08:12 +00005671
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005672 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5673 Constructor, E->isElidable(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005674 move_arg(Args));
5675}
Mike Stump1eb44332009-09-09 15:08:12 +00005676
Douglas Gregorb98b1992009-08-11 05:31:07 +00005677/// \brief Transform a C++ temporary-binding expression.
5678///
Douglas Gregor51326552009-12-24 18:51:59 +00005679/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5680/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005681template<typename Derived>
5682Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005683TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005684 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005685}
Mike Stump1eb44332009-09-09 15:08:12 +00005686
Anders Carlssoneb60edf2010-01-29 02:39:32 +00005687/// \brief Transform a C++ reference-binding expression.
5688///
5689/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5690/// transform the subexpression and return that.
5691template<typename Derived>
5692Sema::OwningExprResult
5693TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5694 return getDerived().TransformExpr(E->getSubExpr());
5695}
5696
Mike Stump1eb44332009-09-09 15:08:12 +00005697/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00005698/// be destroyed after the expression is evaluated.
5699///
Douglas Gregor51326552009-12-24 18:51:59 +00005700/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5701/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005702template<typename Derived>
5703Sema::OwningExprResult
5704TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00005705 CXXExprWithTemporaries *E) {
5706 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005707}
Mike Stump1eb44332009-09-09 15:08:12 +00005708
Douglas Gregorb98b1992009-08-11 05:31:07 +00005709template<typename Derived>
5710Sema::OwningExprResult
5711TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall454feb92009-12-08 09:21:05 +00005712 CXXTemporaryObjectExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005713 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5714 QualType T = getDerived().TransformType(E->getType());
5715 if (T.isNull())
5716 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005717
Douglas Gregorb98b1992009-08-11 05:31:07 +00005718 CXXConstructorDecl *Constructor
5719 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00005720 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005721 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005722 if (!Constructor)
5723 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005724
Douglas Gregorb98b1992009-08-11 05:31:07 +00005725 bool ArgumentChanged = false;
5726 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5727 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005728 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005729 ArgEnd = E->arg_end();
5730 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005731 if (getDerived().DropCallArgument(*Arg)) {
5732 ArgumentChanged = true;
5733 break;
5734 }
5735
Douglas Gregorb98b1992009-08-11 05:31:07 +00005736 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5737 if (TransArg.isInvalid())
5738 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005739
Douglas Gregorb98b1992009-08-11 05:31:07 +00005740 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5741 Args.push_back((Expr *)TransArg.release());
5742 }
Mike Stump1eb44332009-09-09 15:08:12 +00005743
Douglas Gregorb98b1992009-08-11 05:31:07 +00005744 if (!getDerived().AlwaysRebuild() &&
5745 T == E->getType() &&
5746 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005747 !ArgumentChanged) {
5748 // FIXME: Instantiation-specific
5749 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carrutha3ce8ae2010-03-31 18:34:58 +00005750 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor91be6f52010-03-02 17:18:33 +00005751 }
Mike Stump1eb44332009-09-09 15:08:12 +00005752
Douglas Gregorb98b1992009-08-11 05:31:07 +00005753 // FIXME: Bogus location information
5754 SourceLocation CommaLoc;
5755 if (Args.size() > 1) {
5756 Expr *First = (Expr *)Args[0];
Mike Stump1eb44332009-09-09 15:08:12 +00005757 CommaLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005758 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5759 }
5760 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5761 T,
5762 /*FIXME:*/E->getTypeBeginLoc(),
5763 move_arg(Args),
5764 &CommaLoc,
5765 E->getLocEnd());
5766}
Mike Stump1eb44332009-09-09 15:08:12 +00005767
Douglas Gregorb98b1992009-08-11 05:31:07 +00005768template<typename Derived>
5769Sema::OwningExprResult
5770TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005771 CXXUnresolvedConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005772 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5773 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5774 if (T.isNull())
5775 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005776
Douglas Gregorb98b1992009-08-11 05:31:07 +00005777 bool ArgumentChanged = false;
5778 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5779 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5780 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5781 ArgEnd = E->arg_end();
5782 Arg != ArgEnd; ++Arg) {
5783 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5784 if (TransArg.isInvalid())
5785 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005786
Douglas Gregorb98b1992009-08-11 05:31:07 +00005787 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5788 FakeCommaLocs.push_back(
5789 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5790 Args.push_back(TransArg.takeAs<Expr>());
5791 }
Mike Stump1eb44332009-09-09 15:08:12 +00005792
Douglas Gregorb98b1992009-08-11 05:31:07 +00005793 if (!getDerived().AlwaysRebuild() &&
5794 T == E->getTypeAsWritten() &&
5795 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005796 return SemaRef.Owned(E->Retain());
5797
Douglas Gregorb98b1992009-08-11 05:31:07 +00005798 // FIXME: we're faking the locations of the commas
5799 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5800 T,
5801 E->getLParenLoc(),
5802 move_arg(Args),
5803 FakeCommaLocs.data(),
5804 E->getRParenLoc());
5805}
Mike Stump1eb44332009-09-09 15:08:12 +00005806
Douglas Gregorb98b1992009-08-11 05:31:07 +00005807template<typename Derived>
5808Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00005809TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall454feb92009-12-08 09:21:05 +00005810 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005811 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005812 OwningExprResult Base(SemaRef, (Expr*) 0);
5813 Expr *OldBase;
5814 QualType BaseType;
5815 QualType ObjectType;
5816 if (!E->isImplicitAccess()) {
5817 OldBase = E->getBase();
5818 Base = getDerived().TransformExpr(OldBase);
5819 if (Base.isInvalid())
5820 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005821
John McCallaa81e162009-12-01 22:10:20 +00005822 // Start the member reference and compute the object's type.
5823 Sema::TypeTy *ObjectTy = 0;
Douglas Gregord4dca082010-02-24 18:44:31 +00005824 bool MayBePseudoDestructor = false;
John McCallaa81e162009-12-01 22:10:20 +00005825 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5826 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005827 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005828 ObjectTy,
5829 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005830 if (Base.isInvalid())
5831 return SemaRef.ExprError();
5832
5833 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5834 BaseType = ((Expr*) Base.get())->getType();
5835 } else {
5836 OldBase = 0;
5837 BaseType = getDerived().TransformType(E->getBaseType());
5838 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5839 }
Mike Stump1eb44332009-09-09 15:08:12 +00005840
Douglas Gregor6cd21982009-10-20 05:58:46 +00005841 // Transform the first part of the nested-name-specifier that qualifies
5842 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005843 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005844 = getDerived().TransformFirstQualifierInScope(
5845 E->getFirstQualifierFoundInScope(),
5846 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005847
Douglas Gregora38c6872009-09-03 16:14:30 +00005848 NestedNameSpecifier *Qualifier = 0;
5849 if (E->getQualifier()) {
5850 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5851 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005852 ObjectType,
5853 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005854 if (!Qualifier)
5855 return SemaRef.ExprError();
5856 }
Mike Stump1eb44332009-09-09 15:08:12 +00005857
5858 DeclarationName Name
Douglas Gregordd62b152009-10-19 22:04:39 +00005859 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCallaa81e162009-12-01 22:10:20 +00005860 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00005861 if (!Name)
5862 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005863
John McCallaa81e162009-12-01 22:10:20 +00005864 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005865 // This is a reference to a member without an explicitly-specified
5866 // template argument list. Optimize for this common case.
5867 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005868 Base.get() == OldBase &&
5869 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005870 Qualifier == E->getQualifier() &&
5871 Name == E->getMember() &&
5872 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005873 return SemaRef.Owned(E->Retain());
5874
John McCall865d4472009-11-19 22:55:06 +00005875 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005876 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005877 E->isArrow(),
5878 E->getOperatorLoc(),
5879 Qualifier,
5880 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005881 FirstQualifierInScope,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005882 Name,
5883 E->getMemberLoc(),
John McCall129e2df2009-11-30 22:42:35 +00005884 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005885 }
5886
John McCalld5532b62009-11-23 01:53:49 +00005887 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005888 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005889 TemplateArgumentLoc Loc;
5890 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005891 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005892 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005893 }
Mike Stump1eb44332009-09-09 15:08:12 +00005894
John McCall865d4472009-11-19 22:55:06 +00005895 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005896 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005897 E->isArrow(),
5898 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005899 Qualifier,
5900 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005901 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005902 Name,
5903 E->getMemberLoc(),
5904 &TransArgs);
5905}
5906
5907template<typename Derived>
5908Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005909TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005910 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005911 OwningExprResult Base(SemaRef, (Expr*) 0);
5912 QualType BaseType;
5913 if (!Old->isImplicitAccess()) {
5914 Base = getDerived().TransformExpr(Old->getBase());
5915 if (Base.isInvalid())
5916 return SemaRef.ExprError();
5917 BaseType = ((Expr*) Base.get())->getType();
5918 } else {
5919 BaseType = getDerived().TransformType(Old->getBaseType());
5920 }
John McCall129e2df2009-11-30 22:42:35 +00005921
5922 NestedNameSpecifier *Qualifier = 0;
5923 if (Old->getQualifier()) {
5924 Qualifier
5925 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005926 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00005927 if (Qualifier == 0)
5928 return SemaRef.ExprError();
5929 }
5930
5931 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5932 Sema::LookupOrdinaryName);
5933
5934 // Transform all the decls.
5935 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5936 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005937 NamedDecl *InstD = static_cast<NamedDecl*>(
5938 getDerived().TransformDecl(Old->getMemberLoc(),
5939 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005940 if (!InstD) {
5941 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5942 // This can happen because of dependent hiding.
5943 if (isa<UsingShadowDecl>(*I))
5944 continue;
5945 else
5946 return SemaRef.ExprError();
5947 }
John McCall129e2df2009-11-30 22:42:35 +00005948
5949 // Expand using declarations.
5950 if (isa<UsingDecl>(InstD)) {
5951 UsingDecl *UD = cast<UsingDecl>(InstD);
5952 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5953 E = UD->shadow_end(); I != E; ++I)
5954 R.addDecl(*I);
5955 continue;
5956 }
5957
5958 R.addDecl(InstD);
5959 }
5960
5961 R.resolveKind();
5962
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005963 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00005964 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00005965 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005966 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00005967 Old->getMemberLoc(),
5968 Old->getNamingClass()));
5969 if (!NamingClass)
5970 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005971
Douglas Gregor66c45152010-04-27 16:10:10 +00005972 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005973 }
Sean Huntc3021132010-05-05 15:23:54 +00005974
John McCall129e2df2009-11-30 22:42:35 +00005975 TemplateArgumentListInfo TransArgs;
5976 if (Old->hasExplicitTemplateArgs()) {
5977 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5978 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5979 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5980 TemplateArgumentLoc Loc;
5981 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5982 Loc))
5983 return SemaRef.ExprError();
5984 TransArgs.addArgument(Loc);
5985 }
5986 }
John McCallc2233c52010-01-15 08:34:02 +00005987
5988 // FIXME: to do this check properly, we will need to preserve the
5989 // first-qualifier-in-scope here, just in case we had a dependent
5990 // base (and therefore couldn't do the check) and a
5991 // nested-name-qualifier (and therefore could do the lookup).
5992 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00005993
John McCall129e2df2009-11-30 22:42:35 +00005994 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005995 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00005996 Old->getOperatorLoc(),
5997 Old->isArrow(),
5998 Qualifier,
5999 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006000 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006001 R,
6002 (Old->hasExplicitTemplateArgs()
6003 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006004}
6005
6006template<typename Derived>
6007Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006008TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006009 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006010}
6011
Mike Stump1eb44332009-09-09 15:08:12 +00006012template<typename Derived>
6013Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006014TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006015 TypeSourceInfo *EncodedTypeInfo
6016 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6017 if (!EncodedTypeInfo)
Douglas Gregorb98b1992009-08-11 05:31:07 +00006018 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006019
Douglas Gregorb98b1992009-08-11 05:31:07 +00006020 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006021 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump1eb44332009-09-09 15:08:12 +00006022 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006023
6024 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006025 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006026 E->getRParenLoc());
6027}
Mike Stump1eb44332009-09-09 15:08:12 +00006028
Douglas Gregorb98b1992009-08-11 05:31:07 +00006029template<typename Derived>
6030Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006031TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006032 // Transform arguments.
6033 bool ArgChanged = false;
6034 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
6035 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
6036 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
6037 if (Arg.isInvalid())
6038 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006039
Douglas Gregor92e986e2010-04-22 16:44:27 +00006040 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
6041 Args.push_back(Arg.takeAs<Expr>());
6042 }
6043
6044 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6045 // Class message: transform the receiver type.
6046 TypeSourceInfo *ReceiverTypeInfo
6047 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6048 if (!ReceiverTypeInfo)
6049 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006050
Douglas Gregor92e986e2010-04-22 16:44:27 +00006051 // If nothing changed, just retain the existing message send.
6052 if (!getDerived().AlwaysRebuild() &&
6053 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6054 return SemaRef.Owned(E->Retain());
6055
6056 // Build a new class message send.
6057 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6058 E->getSelector(),
6059 E->getMethodDecl(),
6060 E->getLeftLoc(),
6061 move_arg(Args),
6062 E->getRightLoc());
6063 }
6064
6065 // Instance message: transform the receiver
6066 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6067 "Only class and instance messages may be instantiated");
6068 OwningExprResult Receiver
6069 = getDerived().TransformExpr(E->getInstanceReceiver());
6070 if (Receiver.isInvalid())
6071 return SemaRef.ExprError();
6072
6073 // If nothing changed, just retain the existing message send.
6074 if (!getDerived().AlwaysRebuild() &&
6075 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6076 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006077
Douglas Gregor92e986e2010-04-22 16:44:27 +00006078 // Build a new instance message send.
6079 return getDerived().RebuildObjCMessageExpr(move(Receiver),
6080 E->getSelector(),
6081 E->getMethodDecl(),
6082 E->getLeftLoc(),
6083 move_arg(Args),
6084 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006085}
6086
Mike Stump1eb44332009-09-09 15:08:12 +00006087template<typename Derived>
6088Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006089TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006090 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006091}
6092
Mike Stump1eb44332009-09-09 15:08:12 +00006093template<typename Derived>
6094Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006095TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006096 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006097}
6098
Mike Stump1eb44332009-09-09 15:08:12 +00006099template<typename Derived>
6100Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006101TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006102 // Transform the base expression.
6103 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6104 if (Base.isInvalid())
6105 return SemaRef.ExprError();
6106
6107 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006108
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006109 // If nothing changed, just retain the existing expression.
6110 if (!getDerived().AlwaysRebuild() &&
6111 Base.get() == E->getBase())
6112 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006113
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006114 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6115 E->getLocation(),
6116 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006117}
6118
Mike Stump1eb44332009-09-09 15:08:12 +00006119template<typename Derived>
6120Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006121TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregore3303542010-04-26 20:47:02 +00006122 // Transform the base expression.
6123 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6124 if (Base.isInvalid())
6125 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006126
Douglas Gregore3303542010-04-26 20:47:02 +00006127 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006128
Douglas Gregore3303542010-04-26 20:47:02 +00006129 // If nothing changed, just retain the existing expression.
6130 if (!getDerived().AlwaysRebuild() &&
6131 Base.get() == E->getBase())
6132 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006133
Douglas Gregore3303542010-04-26 20:47:02 +00006134 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6135 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006136}
6137
Mike Stump1eb44332009-09-09 15:08:12 +00006138template<typename Derived>
6139Sema::OwningExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00006140TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00006141 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006142 // If this implicit setter/getter refers to class methods, it cannot have any
6143 // dependent parts. Just retain the existing declaration.
6144 if (E->getInterfaceDecl())
6145 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006146
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006147 // Transform the base expression.
6148 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6149 if (Base.isInvalid())
6150 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006151
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006152 // We don't need to transform the getters/setters; they will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006153
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006154 // If nothing changed, just retain the existing expression.
6155 if (!getDerived().AlwaysRebuild() &&
6156 Base.get() == E->getBase())
6157 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006158
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006159 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6160 E->getGetterMethod(),
6161 E->getType(),
6162 E->getSetterMethod(),
6163 E->getLocation(),
6164 move(Base));
Sean Huntc3021132010-05-05 15:23:54 +00006165
Douglas Gregorb98b1992009-08-11 05:31:07 +00006166}
6167
Mike Stump1eb44332009-09-09 15:08:12 +00006168template<typename Derived>
6169Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006170TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006171 // Can never occur in a dependent context.
Mike Stump1eb44332009-09-09 15:08:12 +00006172 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006173}
6174
Mike Stump1eb44332009-09-09 15:08:12 +00006175template<typename Derived>
6176Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006177TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006178 // Transform the base expression.
6179 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6180 if (Base.isInvalid())
6181 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006182
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006183 // If nothing changed, just retain the existing expression.
6184 if (!getDerived().AlwaysRebuild() &&
6185 Base.get() == E->getBase())
6186 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006187
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006188 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6189 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006190}
6191
Mike Stump1eb44332009-09-09 15:08:12 +00006192template<typename Derived>
6193Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006194TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006195 bool ArgumentChanged = false;
6196 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6197 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6198 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6199 if (SubExpr.isInvalid())
6200 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006201
Douglas Gregorb98b1992009-08-11 05:31:07 +00006202 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6203 SubExprs.push_back(SubExpr.takeAs<Expr>());
6204 }
Mike Stump1eb44332009-09-09 15:08:12 +00006205
Douglas Gregorb98b1992009-08-11 05:31:07 +00006206 if (!getDerived().AlwaysRebuild() &&
6207 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00006208 return SemaRef.Owned(E->Retain());
6209
Douglas Gregorb98b1992009-08-11 05:31:07 +00006210 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6211 move_arg(SubExprs),
6212 E->getRParenLoc());
6213}
6214
Mike Stump1eb44332009-09-09 15:08:12 +00006215template<typename Derived>
6216Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006217TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006218 SourceLocation CaretLoc(E->getExprLoc());
6219
6220 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6221 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6222 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6223 llvm::SmallVector<ParmVarDecl*, 4> Params;
6224 llvm::SmallVector<QualType, 4> ParamTypes;
6225
6226 // Parameter substitution.
6227 const BlockDecl *BD = E->getBlockDecl();
6228 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6229 EN = BD->param_end(); P != EN; ++P) {
6230 ParmVarDecl *OldParm = (*P);
6231 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6232 QualType NewType = NewParm->getType();
6233 Params.push_back(NewParm);
6234 ParamTypes.push_back(NewParm->getType());
6235 }
6236
6237 const FunctionType *BExprFunctionType = E->getFunctionType();
6238 QualType BExprResultType = BExprFunctionType->getResultType();
6239 if (!BExprResultType.isNull()) {
6240 if (!BExprResultType->isDependentType())
6241 CurBlock->ReturnType = BExprResultType;
6242 else if (BExprResultType != SemaRef.Context.DependentTy)
6243 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6244 }
6245
6246 // Transform the body
6247 OwningStmtResult Body = getDerived().TransformStmt(E->getBody());
6248 if (Body.isInvalid())
6249 return SemaRef.ExprError();
6250 // Set the parameters on the block decl.
6251 if (!Params.empty())
6252 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6253
6254 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6255 CurBlock->ReturnType,
6256 ParamTypes.data(),
6257 ParamTypes.size(),
6258 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006259 0,
6260 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006261
6262 CurBlock->FunctionType = FunctionType;
6263 return SemaRef.ActOnBlockStmtExpr(CaretLoc, move(Body), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006264}
6265
Mike Stump1eb44332009-09-09 15:08:12 +00006266template<typename Derived>
6267Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006268TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006269 NestedNameSpecifier *Qualifier = 0;
6270
6271 ValueDecl *ND
6272 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6273 E->getDecl()));
6274 if (!ND)
6275 return SemaRef.ExprError();
6276
6277 if (!getDerived().AlwaysRebuild() &&
6278 ND == E->getDecl()) {
6279 // Mark it referenced in the new context regardless.
6280 // FIXME: this is a bit instantiation-specific.
6281 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6282
6283 return SemaRef.Owned(E->Retain());
6284 }
6285
6286 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
6287 ND, E->getLocation(), 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006288}
Mike Stump1eb44332009-09-09 15:08:12 +00006289
Douglas Gregorb98b1992009-08-11 05:31:07 +00006290//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006291// Type reconstruction
6292//===----------------------------------------------------------------------===//
6293
Mike Stump1eb44332009-09-09 15:08:12 +00006294template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006295QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6296 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006297 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006298 getDerived().getBaseEntity());
6299}
6300
Mike Stump1eb44332009-09-09 15:08:12 +00006301template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006302QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6303 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006304 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006305 getDerived().getBaseEntity());
6306}
6307
Mike Stump1eb44332009-09-09 15:08:12 +00006308template<typename Derived>
6309QualType
John McCall85737a72009-10-30 00:06:24 +00006310TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6311 bool WrittenAsLValue,
6312 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006313 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00006314 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006315}
6316
6317template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006318QualType
John McCall85737a72009-10-30 00:06:24 +00006319TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6320 QualType ClassType,
6321 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006322 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00006323 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006324}
6325
6326template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006327QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006328TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6329 ArrayType::ArraySizeModifier SizeMod,
6330 const llvm::APInt *Size,
6331 Expr *SizeExpr,
6332 unsigned IndexTypeQuals,
6333 SourceRange BracketsRange) {
6334 if (SizeExpr || !Size)
6335 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6336 IndexTypeQuals, BracketsRange,
6337 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006338
6339 QualType Types[] = {
6340 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6341 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6342 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006343 };
6344 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6345 QualType SizeType;
6346 for (unsigned I = 0; I != NumTypes; ++I)
6347 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6348 SizeType = Types[I];
6349 break;
6350 }
Mike Stump1eb44332009-09-09 15:08:12 +00006351
Douglas Gregor577f75a2009-08-04 16:50:30 +00006352 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006353 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006354 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006355 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006356}
Mike Stump1eb44332009-09-09 15:08:12 +00006357
Douglas Gregor577f75a2009-08-04 16:50:30 +00006358template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006359QualType
6360TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006361 ArrayType::ArraySizeModifier SizeMod,
6362 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00006363 unsigned IndexTypeQuals,
6364 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006365 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00006366 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006367}
6368
6369template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006370QualType
Mike Stump1eb44332009-09-09 15:08:12 +00006371TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006372 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00006373 unsigned IndexTypeQuals,
6374 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006375 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00006376 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006377}
Mike Stump1eb44332009-09-09 15:08:12 +00006378
Douglas Gregor577f75a2009-08-04 16:50:30 +00006379template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006380QualType
6381TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006382 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006383 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006384 unsigned IndexTypeQuals,
6385 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006386 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006387 SizeExpr.takeAs<Expr>(),
6388 IndexTypeQuals, BracketsRange);
6389}
6390
6391template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006392QualType
6393TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006394 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006395 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006396 unsigned IndexTypeQuals,
6397 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006398 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006399 SizeExpr.takeAs<Expr>(),
6400 IndexTypeQuals, BracketsRange);
6401}
6402
6403template<typename Derived>
6404QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner788b0fd2010-06-23 06:00:24 +00006405 unsigned NumElements,
6406 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006407 // FIXME: semantic checking!
Chris Lattner788b0fd2010-06-23 06:00:24 +00006408 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006409}
Mike Stump1eb44332009-09-09 15:08:12 +00006410
Douglas Gregor577f75a2009-08-04 16:50:30 +00006411template<typename Derived>
6412QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6413 unsigned NumElements,
6414 SourceLocation AttributeLoc) {
6415 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6416 NumElements, true);
6417 IntegerLiteral *VectorSize
Mike Stump1eb44332009-09-09 15:08:12 +00006418 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006419 AttributeLoc);
6420 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6421 AttributeLoc);
6422}
Mike Stump1eb44332009-09-09 15:08:12 +00006423
Douglas Gregor577f75a2009-08-04 16:50:30 +00006424template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006425QualType
6426TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006427 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006428 SourceLocation AttributeLoc) {
6429 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6430}
Mike Stump1eb44332009-09-09 15:08:12 +00006431
Douglas Gregor577f75a2009-08-04 16:50:30 +00006432template<typename Derived>
6433QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00006434 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006435 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00006436 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00006437 unsigned Quals,
6438 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00006439 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006440 Quals,
6441 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006442 getDerived().getBaseEntity(),
6443 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006444}
Mike Stump1eb44332009-09-09 15:08:12 +00006445
Douglas Gregor577f75a2009-08-04 16:50:30 +00006446template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00006447QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6448 return SemaRef.Context.getFunctionNoProtoType(T);
6449}
6450
6451template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00006452QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6453 assert(D && "no decl found");
6454 if (D->isInvalidDecl()) return QualType();
6455
Douglas Gregor92e986e2010-04-22 16:44:27 +00006456 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00006457 TypeDecl *Ty;
6458 if (isa<UsingDecl>(D)) {
6459 UsingDecl *Using = cast<UsingDecl>(D);
6460 assert(Using->isTypeName() &&
6461 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6462
6463 // A valid resolved using typename decl points to exactly one type decl.
6464 assert(++Using->shadow_begin() == Using->shadow_end());
6465 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00006466
John McCalled976492009-12-04 22:46:56 +00006467 } else {
6468 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6469 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6470 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6471 }
6472
6473 return SemaRef.Context.getTypeDeclType(Ty);
6474}
6475
6476template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00006477QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006478 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6479}
6480
6481template<typename Derived>
6482QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6483 return SemaRef.Context.getTypeOfType(Underlying);
6484}
6485
6486template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00006487QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006488 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6489}
6490
6491template<typename Derived>
6492QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00006493 TemplateName Template,
6494 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00006495 const TemplateArgumentListInfo &TemplateArgs) {
6496 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006497}
Mike Stump1eb44332009-09-09 15:08:12 +00006498
Douglas Gregordcee1a12009-08-06 05:28:30 +00006499template<typename Derived>
6500NestedNameSpecifier *
6501TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6502 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00006503 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006504 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00006505 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00006506 CXXScopeSpec SS;
6507 // FIXME: The source location information is all wrong.
6508 SS.setRange(Range);
6509 SS.setScopeRep(Prefix);
6510 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00006511 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00006512 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006513 ObjectType,
6514 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00006515 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00006516}
6517
6518template<typename Derived>
6519NestedNameSpecifier *
6520TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6521 SourceRange Range,
6522 NamespaceDecl *NS) {
6523 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6524}
6525
6526template<typename Derived>
6527NestedNameSpecifier *
6528TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6529 SourceRange Range,
6530 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00006531 QualType T) {
6532 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00006533 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00006534 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00006535 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6536 T.getTypePtr());
6537 }
Mike Stump1eb44332009-09-09 15:08:12 +00006538
Douglas Gregordcee1a12009-08-06 05:28:30 +00006539 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6540 return 0;
6541}
Mike Stump1eb44332009-09-09 15:08:12 +00006542
Douglas Gregord1067e52009-08-06 06:41:21 +00006543template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006544TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006545TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6546 bool TemplateKW,
6547 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00006548 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00006549 Template);
6550}
6551
6552template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006553TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006554TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006555 const IdentifierInfo &II,
6556 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00006557 CXXScopeSpec SS;
6558 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump1eb44332009-09-09 15:08:12 +00006559 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00006560 UnqualifiedId Name;
6561 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00006562 Sema::TemplateTy Template;
6563 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6564 /*FIXME:*/getDerived().getBaseLocation(),
6565 SS,
6566 Name,
6567 ObjectType.getAsOpaquePtr(),
6568 /*EnteringContext=*/false,
6569 Template);
6570 return Template.template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00006571}
Mike Stump1eb44332009-09-09 15:08:12 +00006572
Douglas Gregorb98b1992009-08-11 05:31:07 +00006573template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006574TemplateName
6575TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6576 OverloadedOperatorKind Operator,
6577 QualType ObjectType) {
6578 CXXScopeSpec SS;
6579 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6580 SS.setScopeRep(Qualifier);
6581 UnqualifiedId Name;
6582 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6583 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6584 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00006585 Sema::TemplateTy Template;
6586 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006587 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006588 SS,
6589 Name,
6590 ObjectType.getAsOpaquePtr(),
6591 /*EnteringContext=*/false,
6592 Template);
6593 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006594}
Sean Huntc3021132010-05-05 15:23:54 +00006595
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006596template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006597Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006598TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6599 SourceLocation OpLoc,
6600 ExprArg Callee,
6601 ExprArg First,
6602 ExprArg Second) {
6603 Expr *FirstExpr = (Expr *)First.get();
6604 Expr *SecondExpr = (Expr *)Second.get();
John McCallba135432009-11-21 08:51:07 +00006605 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006606 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00006607
Douglas Gregorb98b1992009-08-11 05:31:07 +00006608 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00006609 if (Op == OO_Subscript) {
6610 if (!FirstExpr->getType()->isOverloadableType() &&
6611 !SecondExpr->getType()->isOverloadableType())
6612 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCallba135432009-11-21 08:51:07 +00006613 CalleeExpr->getLocStart(),
Sebastian Redlf322ed62009-10-29 20:17:01 +00006614 move(Second), OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00006615 } else if (Op == OO_Arrow) {
6616 // -> is never a builtin operation.
6617 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redlf322ed62009-10-29 20:17:01 +00006618 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006619 if (!FirstExpr->getType()->isOverloadableType()) {
6620 // The argument is not of overloadable type, so try to create a
6621 // built-in unary operation.
Mike Stump1eb44332009-09-09 15:08:12 +00006622 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00006624
Douglas Gregorb98b1992009-08-11 05:31:07 +00006625 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6626 }
6627 } else {
Mike Stump1eb44332009-09-09 15:08:12 +00006628 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629 !SecondExpr->getType()->isOverloadableType()) {
6630 // Neither of the arguments is an overloadable type, so try to
6631 // create a built-in binary operation.
6632 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00006633 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006634 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6635 if (Result.isInvalid())
6636 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006637
Douglas Gregorb98b1992009-08-11 05:31:07 +00006638 First.release();
6639 Second.release();
6640 return move(Result);
6641 }
6642 }
Mike Stump1eb44332009-09-09 15:08:12 +00006643
6644 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00006645 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00006646 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00006647
John McCallba135432009-11-21 08:51:07 +00006648 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6649 assert(ULE->requiresADL());
6650
6651 // FIXME: Do we have to check
6652 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00006653 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00006654 } else {
John McCall6e266892010-01-26 03:27:55 +00006655 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCallba135432009-11-21 08:51:07 +00006656 }
Mike Stump1eb44332009-09-09 15:08:12 +00006657
Douglas Gregorb98b1992009-08-11 05:31:07 +00006658 // Add any functions found via argument-dependent lookup.
6659 Expr *Args[2] = { FirstExpr, SecondExpr };
6660 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00006661
Douglas Gregorb98b1992009-08-11 05:31:07 +00006662 // Create the overloaded operator invocation for unary operators.
6663 if (NumArgs == 1 || isPostIncDec) {
Mike Stump1eb44332009-09-09 15:08:12 +00006664 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6666 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6667 }
Mike Stump1eb44332009-09-09 15:08:12 +00006668
Sebastian Redlf322ed62009-10-29 20:17:01 +00006669 if (Op == OO_Subscript)
John McCallba135432009-11-21 08:51:07 +00006670 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6671 OpLoc,
6672 move(First),
6673 move(Second));
Sebastian Redlf322ed62009-10-29 20:17:01 +00006674
Douglas Gregorb98b1992009-08-11 05:31:07 +00006675 // Create the overloaded operator invocation for binary operators.
Mike Stump1eb44332009-09-09 15:08:12 +00006676 BinaryOperator::Opcode Opc =
Douglas Gregorb98b1992009-08-11 05:31:07 +00006677 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00006678 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006679 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6680 if (Result.isInvalid())
6681 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006682
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683 First.release();
6684 Second.release();
Mike Stump1eb44332009-09-09 15:08:12 +00006685 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006686}
Mike Stump1eb44332009-09-09 15:08:12 +00006687
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006688template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00006689Sema::OwningExprResult
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006690TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6691 SourceLocation OperatorLoc,
6692 bool isArrow,
6693 NestedNameSpecifier *Qualifier,
6694 SourceRange QualifierRange,
6695 TypeSourceInfo *ScopeType,
6696 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006697 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006698 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006699 CXXScopeSpec SS;
6700 if (Qualifier) {
6701 SS.setRange(QualifierRange);
6702 SS.setScopeRep(Qualifier);
6703 }
6704
6705 Expr *BaseE = (Expr *)Base.get();
6706 QualType BaseType = BaseE->getType();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006707 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006708 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00006709 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00006710 !BaseType->getAs<PointerType>()->getPointeeType()
6711 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006712 // This pseudo-destructor expression is still a pseudo-destructor.
6713 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6714 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006715 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006716 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006717 /*FIXME?*/true);
6718 }
Sean Huntc3021132010-05-05 15:23:54 +00006719
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006720 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006721 DeclarationName Name
6722 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6723 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
Sean Huntc3021132010-05-05 15:23:54 +00006724
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006725 // FIXME: the ScopeType should be tacked onto SS.
Sean Huntc3021132010-05-05 15:23:54 +00006726
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006727 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6728 OperatorLoc, isArrow,
6729 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006730 Name, Destroyed.getLocation(),
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006731 /*TemplateArgs*/ 0);
6732}
6733
Douglas Gregor577f75a2009-08-04 16:50:30 +00006734} // end namespace clang
6735
6736#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H