blob: 65107ccfe79340743249c62d35ea784593dad834 [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.
1314 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1315 QualType T, SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001316 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001317 RParenLoc);
1318 }
1319
1320 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001321 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001322 /// By default, performs semantic analysis to build the new expression.
1323 /// Subclasses may override this routine to provide different behavior.
1324 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1325 MultiExprArg SubExprs,
1326 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001327 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001328 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001329 }
Mike Stump1eb44332009-09-09 15:08:12 +00001330
Douglas Gregorb98b1992009-08-11 05:31:07 +00001331 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001332 ///
1333 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001334 /// rather than attempting to map the label statement itself.
1335 /// Subclasses may override this routine to provide different behavior.
1336 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1337 SourceLocation LabelLoc,
1338 LabelStmt *Label) {
1339 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1340 }
Mike Stump1eb44332009-09-09 15:08:12 +00001341
Douglas Gregorb98b1992009-08-11 05:31:07 +00001342 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001343 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001344 /// By default, performs semantic analysis to build the new expression.
1345 /// Subclasses may override this routine to provide different behavior.
1346 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1347 StmtArg SubStmt,
1348 SourceLocation RParenLoc) {
1349 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1350 }
Mike Stump1eb44332009-09-09 15:08:12 +00001351
Douglas Gregorb98b1992009-08-11 05:31:07 +00001352 /// \brief Build a new __builtin_types_compatible_p expression.
1353 ///
1354 /// By default, performs semantic analysis to build the new expression.
1355 /// Subclasses may override this routine to provide different behavior.
1356 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001357 TypeSourceInfo *TInfo1,
1358 TypeSourceInfo *TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001359 SourceLocation RParenLoc) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001360 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1361 TInfo1, TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001362 RParenLoc);
1363 }
Mike Stump1eb44332009-09-09 15:08:12 +00001364
Douglas Gregorb98b1992009-08-11 05:31:07 +00001365 /// \brief Build a new __builtin_choose_expr expression.
1366 ///
1367 /// By default, performs semantic analysis to build the new expression.
1368 /// Subclasses may override this routine to provide different behavior.
1369 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1370 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1371 SourceLocation RParenLoc) {
1372 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1373 move(Cond), move(LHS), move(RHS),
1374 RParenLoc);
1375 }
Mike Stump1eb44332009-09-09 15:08:12 +00001376
Douglas Gregorb98b1992009-08-11 05:31:07 +00001377 /// \brief Build a new overloaded operator call expression.
1378 ///
1379 /// By default, performs semantic analysis to build the new expression.
1380 /// The semantic analysis provides the behavior of template instantiation,
1381 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001382 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001383 /// argument-dependent lookup, etc. Subclasses may override this routine to
1384 /// provide different behavior.
1385 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1386 SourceLocation OpLoc,
1387 ExprArg Callee,
1388 ExprArg First,
1389 ExprArg Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001390
1391 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001392 /// reinterpret_cast.
1393 ///
1394 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001395 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001396 /// Subclasses may override this routine to provide different behavior.
1397 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1398 Stmt::StmtClass Class,
1399 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001400 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001401 SourceLocation RAngleLoc,
1402 SourceLocation LParenLoc,
1403 ExprArg SubExpr,
1404 SourceLocation RParenLoc) {
1405 switch (Class) {
1406 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001407 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001408 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 move(SubExpr), RParenLoc);
1410
1411 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001412 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001413 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001414 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001415
Douglas Gregorb98b1992009-08-11 05:31:07 +00001416 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001417 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001418 RAngleLoc, LParenLoc,
1419 move(SubExpr),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001420 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001421
Douglas Gregorb98b1992009-08-11 05:31:07 +00001422 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001423 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001424 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001425 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001426
Douglas Gregorb98b1992009-08-11 05:31:07 +00001427 default:
1428 assert(false && "Invalid C++ named cast");
1429 break;
1430 }
Mike Stump1eb44332009-09-09 15:08:12 +00001431
Douglas Gregorb98b1992009-08-11 05:31:07 +00001432 return getSema().ExprError();
1433 }
Mike Stump1eb44332009-09-09 15:08:12 +00001434
Douglas Gregorb98b1992009-08-11 05:31:07 +00001435 /// \brief Build a new C++ static_cast expression.
1436 ///
1437 /// By default, performs semantic analysis to build the new expression.
1438 /// Subclasses may override this routine to provide different behavior.
1439 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1440 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001441 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001442 SourceLocation RAngleLoc,
1443 SourceLocation LParenLoc,
1444 ExprArg SubExpr,
1445 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001446 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1447 TInfo, move(SubExpr),
1448 SourceRange(LAngleLoc, RAngleLoc),
1449 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001450 }
1451
1452 /// \brief Build a new C++ dynamic_cast expression.
1453 ///
1454 /// By default, performs semantic analysis to build the new expression.
1455 /// Subclasses may override this routine to provide different behavior.
1456 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1457 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001458 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001459 SourceLocation RAngleLoc,
1460 SourceLocation LParenLoc,
1461 ExprArg SubExpr,
1462 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001463 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1464 TInfo, move(SubExpr),
1465 SourceRange(LAngleLoc, RAngleLoc),
1466 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001467 }
1468
1469 /// \brief Build a new C++ reinterpret_cast expression.
1470 ///
1471 /// By default, performs semantic analysis to build the new expression.
1472 /// Subclasses may override this routine to provide different behavior.
1473 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1474 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001475 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001476 SourceLocation RAngleLoc,
1477 SourceLocation LParenLoc,
1478 ExprArg SubExpr,
1479 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001480 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1481 TInfo, move(SubExpr),
1482 SourceRange(LAngleLoc, RAngleLoc),
1483 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 }
1485
1486 /// \brief Build a new C++ const_cast expression.
1487 ///
1488 /// By default, performs semantic analysis to build the new expression.
1489 /// Subclasses may override this routine to provide different behavior.
1490 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1491 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001492 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 SourceLocation RAngleLoc,
1494 SourceLocation LParenLoc,
1495 ExprArg SubExpr,
1496 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001497 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1498 TInfo, move(SubExpr),
1499 SourceRange(LAngleLoc, RAngleLoc),
1500 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001501 }
Mike Stump1eb44332009-09-09 15:08:12 +00001502
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 /// \brief Build a new C++ functional-style cast expression.
1504 ///
1505 /// By default, performs semantic analysis to build the new expression.
1506 /// Subclasses may override this routine to provide different behavior.
1507 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001508 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001509 SourceLocation LParenLoc,
1510 ExprArg SubExpr,
1511 SourceLocation RParenLoc) {
Chris Lattner88650c32009-08-24 05:19:01 +00001512 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001513 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001514 TInfo->getType().getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 LParenLoc,
Chris Lattner88650c32009-08-24 05:19:01 +00001516 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump1eb44332009-09-09 15:08:12 +00001517 /*CommaLocs=*/0,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 RParenLoc);
1519 }
Mike Stump1eb44332009-09-09 15:08:12 +00001520
Douglas Gregorb98b1992009-08-11 05:31:07 +00001521 /// \brief Build a new C++ typeid(type) expression.
1522 ///
1523 /// By default, performs semantic analysis to build the new expression.
1524 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001525 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1526 SourceLocation TypeidLoc,
1527 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001528 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001529 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001530 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001531 }
Mike Stump1eb44332009-09-09 15:08:12 +00001532
Douglas Gregorb98b1992009-08-11 05:31:07 +00001533 /// \brief Build a new C++ typeid(expr) expression.
1534 ///
1535 /// By default, performs semantic analysis to build the new expression.
1536 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001537 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1538 SourceLocation TypeidLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001539 ExprArg Operand,
1540 SourceLocation RParenLoc) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001541 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand),
1542 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001543 }
1544
Douglas Gregorb98b1992009-08-11 05:31:07 +00001545 /// \brief Build a new C++ "this" expression.
1546 ///
1547 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001548 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001549 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001550 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001551 QualType ThisType,
1552 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001553 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001554 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1555 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001556 }
1557
1558 /// \brief Build a new C++ throw expression.
1559 ///
1560 /// By default, performs semantic analysis to build the new expression.
1561 /// Subclasses may override this routine to provide different behavior.
1562 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1563 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1564 }
1565
1566 /// \brief Build a new C++ default-argument expression.
1567 ///
1568 /// By default, builds a new default-argument expression, which does not
1569 /// require any semantic analysis. Subclasses may override this routine to
1570 /// provide different behavior.
Sean Huntc3021132010-05-05 15:23:54 +00001571 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001572 ParmVarDecl *Param) {
1573 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1574 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001575 }
1576
1577 /// \brief Build a new C++ zero-initialization expression.
1578 ///
1579 /// By default, performs semantic analysis to build the new expression.
1580 /// Subclasses may override this routine to provide different behavior.
Douglas Gregored8abf12010-07-08 06:14:04 +00001581 OwningExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 SourceLocation LParenLoc,
1583 QualType T,
1584 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001585 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1586 T.getAsOpaquePtr(), LParenLoc,
1587 MultiExprArg(getSema(), 0, 0),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001588 0, RParenLoc);
1589 }
Mike Stump1eb44332009-09-09 15:08:12 +00001590
Douglas Gregorb98b1992009-08-11 05:31:07 +00001591 /// \brief Build a new C++ "new" expression.
1592 ///
1593 /// By default, performs semantic analysis to build the new expression.
1594 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001595 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 bool UseGlobal,
1597 SourceLocation PlacementLParen,
1598 MultiExprArg PlacementArgs,
1599 SourceLocation PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001600 SourceRange TypeIdParens,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001601 QualType AllocType,
1602 SourceLocation TypeLoc,
1603 SourceRange TypeRange,
1604 ExprArg ArraySize,
1605 SourceLocation ConstructorLParen,
1606 MultiExprArg ConstructorArgs,
1607 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001608 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001609 PlacementLParen,
1610 move(PlacementArgs),
1611 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001612 TypeIdParens,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001613 AllocType,
1614 TypeLoc,
1615 TypeRange,
1616 move(ArraySize),
1617 ConstructorLParen,
1618 move(ConstructorArgs),
1619 ConstructorRParen);
1620 }
Mike Stump1eb44332009-09-09 15:08:12 +00001621
Douglas Gregorb98b1992009-08-11 05:31:07 +00001622 /// \brief Build a new C++ "delete" expression.
1623 ///
1624 /// By default, performs semantic analysis to build the new expression.
1625 /// Subclasses may override this routine to provide different behavior.
1626 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1627 bool IsGlobalDelete,
1628 bool IsArrayForm,
1629 ExprArg Operand) {
1630 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1631 move(Operand));
1632 }
Mike Stump1eb44332009-09-09 15:08:12 +00001633
Douglas Gregorb98b1992009-08-11 05:31:07 +00001634 /// \brief Build a new unary type trait expression.
1635 ///
1636 /// By default, performs semantic analysis to build the new expression.
1637 /// Subclasses may override this routine to provide different behavior.
1638 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1639 SourceLocation StartLoc,
1640 SourceLocation LParenLoc,
1641 QualType T,
1642 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001643 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 T.getAsOpaquePtr(), RParenLoc);
1645 }
1646
Mike Stump1eb44332009-09-09 15:08:12 +00001647 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 /// expression.
1649 ///
1650 /// By default, performs semantic analysis to build the new expression.
1651 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001652 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 SourceRange QualifierRange,
1654 DeclarationName Name,
1655 SourceLocation Location,
John McCallf7a1a742009-11-24 19:00:30 +00001656 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001657 CXXScopeSpec SS;
1658 SS.setRange(QualifierRange);
1659 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001660
1661 if (TemplateArgs)
1662 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1663 *TemplateArgs);
1664
1665 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001666 }
1667
1668 /// \brief Build a new template-id expression.
1669 ///
1670 /// By default, performs semantic analysis to build the new expression.
1671 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001672 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1673 LookupResult &R,
1674 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001675 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001676 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001677 }
1678
1679 /// \brief Build a new object-construction expression.
1680 ///
1681 /// By default, performs semantic analysis to build the new expression.
1682 /// Subclasses may override this routine to provide different behavior.
1683 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001684 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001685 CXXConstructorDecl *Constructor,
1686 bool IsElidable,
1687 MultiExprArg Args) {
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001688 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001689 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001690 ConvertedArgs))
1691 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001692
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001693 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1694 move_arg(ConvertedArgs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 }
1696
1697 /// \brief Build a new object-construction expression.
1698 ///
1699 /// By default, performs semantic analysis to build the new expression.
1700 /// Subclasses may override this routine to provide different behavior.
1701 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1702 QualType T,
1703 SourceLocation LParenLoc,
1704 MultiExprArg Args,
1705 SourceLocation *Commas,
1706 SourceLocation RParenLoc) {
1707 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1708 T.getAsOpaquePtr(),
1709 LParenLoc,
1710 move(Args),
1711 Commas,
1712 RParenLoc);
1713 }
1714
1715 /// \brief Build a new object-construction expression.
1716 ///
1717 /// By default, performs semantic analysis to build the new expression.
1718 /// Subclasses may override this routine to provide different behavior.
1719 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1720 QualType T,
1721 SourceLocation LParenLoc,
1722 MultiExprArg Args,
1723 SourceLocation *Commas,
1724 SourceLocation RParenLoc) {
1725 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1726 /*FIXME*/LParenLoc),
1727 T.getAsOpaquePtr(),
1728 LParenLoc,
1729 move(Args),
1730 Commas,
1731 RParenLoc);
1732 }
Mike Stump1eb44332009-09-09 15:08:12 +00001733
Douglas Gregorb98b1992009-08-11 05:31:07 +00001734 /// \brief Build a new member reference expression.
1735 ///
1736 /// By default, performs semantic analysis to build the new expression.
1737 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001738 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001739 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001740 bool IsArrow,
1741 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001742 NestedNameSpecifier *Qualifier,
1743 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001744 NamedDecl *FirstQualifierInScope,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001745 DeclarationName Name,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001746 SourceLocation MemberLoc,
John McCall129e2df2009-11-30 22:42:35 +00001747 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001749 SS.setRange(QualifierRange);
1750 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001751
John McCallaa81e162009-12-01 22:10:20 +00001752 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1753 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001754 SS, FirstQualifierInScope,
1755 Name, MemberLoc, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 }
1757
John McCall129e2df2009-11-30 22:42:35 +00001758 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001759 ///
1760 /// By default, performs semantic analysis to build the new expression.
1761 /// Subclasses may override this routine to provide different behavior.
John McCall129e2df2009-11-30 22:42:35 +00001762 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001763 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001764 SourceLocation OperatorLoc,
1765 bool IsArrow,
1766 NestedNameSpecifier *Qualifier,
1767 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001768 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001769 LookupResult &R,
1770 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001771 CXXScopeSpec SS;
1772 SS.setRange(QualifierRange);
1773 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001774
John McCallaa81e162009-12-01 22:10:20 +00001775 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1776 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001777 SS, FirstQualifierInScope,
1778 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001779 }
Mike Stump1eb44332009-09-09 15:08:12 +00001780
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 /// \brief Build a new Objective-C @encode expression.
1782 ///
1783 /// By default, performs semantic analysis to build the new expression.
1784 /// Subclasses may override this routine to provide different behavior.
1785 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001786 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001788 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001790 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791
Douglas Gregor92e986e2010-04-22 16:44:27 +00001792 /// \brief Build a new Objective-C class message.
1793 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1794 Selector Sel,
1795 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001796 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001797 MultiExprArg Args,
1798 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001799 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1800 ReceiverTypeInfo->getType(),
1801 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001802 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001803 move(Args));
1804 }
1805
1806 /// \brief Build a new Objective-C instance message.
1807 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1808 Selector Sel,
1809 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001810 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001811 MultiExprArg Args,
1812 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001813 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1814 return SemaRef.BuildInstanceMessage(move(Receiver),
1815 ReceiverType,
1816 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001817 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001818 move(Args));
1819 }
1820
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001821 /// \brief Build a new Objective-C ivar reference expression.
1822 ///
1823 /// By default, performs semantic analysis to build the new expression.
1824 /// Subclasses may override this routine to provide different behavior.
1825 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1826 SourceLocation IvarLoc,
1827 bool IsArrow, bool IsFreeIvar) {
1828 // FIXME: We lose track of the IsFreeIvar bit.
1829 CXXScopeSpec SS;
1830 Expr *Base = BaseArg.takeAs<Expr>();
1831 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1832 Sema::LookupMemberName);
1833 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1834 /*FIME:*/IvarLoc,
John McCallad00b772010-06-16 08:42:20 +00001835 SS, DeclPtrTy(),
1836 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001837 if (Result.isInvalid())
1838 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001839
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001840 if (Result.get())
1841 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001842
1843 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001844 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001845 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001846 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001847 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001848 /*TemplateArgs=*/0);
1849 }
Douglas Gregore3303542010-04-26 20:47:02 +00001850
1851 /// \brief Build a new Objective-C property reference expression.
1852 ///
1853 /// By default, performs semantic analysis to build the new expression.
1854 /// Subclasses may override this routine to provide different behavior.
Sean Huntc3021132010-05-05 15:23:54 +00001855 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00001856 ObjCPropertyDecl *Property,
1857 SourceLocation PropertyLoc) {
1858 CXXScopeSpec SS;
1859 Expr *Base = BaseArg.takeAs<Expr>();
1860 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1861 Sema::LookupMemberName);
1862 bool IsArrow = false;
1863 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1864 /*FIME:*/PropertyLoc,
John McCallad00b772010-06-16 08:42:20 +00001865 SS, DeclPtrTy(),
1866 false);
Douglas Gregore3303542010-04-26 20:47:02 +00001867 if (Result.isInvalid())
1868 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001869
Douglas Gregore3303542010-04-26 20:47:02 +00001870 if (Result.get())
1871 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001872
1873 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregore3303542010-04-26 20:47:02 +00001874 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001875 /*FIXME:*/PropertyLoc, IsArrow,
1876 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00001877 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001878 R,
Douglas Gregore3303542010-04-26 20:47:02 +00001879 /*TemplateArgs=*/0);
1880 }
Sean Huntc3021132010-05-05 15:23:54 +00001881
1882 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001883 /// expression.
1884 ///
1885 /// By default, performs semantic analysis to build the new expression.
Sean Huntc3021132010-05-05 15:23:54 +00001886 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001887 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1888 ObjCMethodDecl *Getter,
1889 QualType T,
1890 ObjCMethodDecl *Setter,
1891 SourceLocation NameLoc,
1892 ExprArg Base) {
1893 // Since these expressions can only be value-dependent, we do not need to
1894 // perform semantic analysis again.
1895 return getSema().Owned(
1896 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1897 Setter,
1898 NameLoc,
1899 Base.takeAs<Expr>()));
1900 }
1901
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001902 /// \brief Build a new Objective-C "isa" expression.
1903 ///
1904 /// By default, performs semantic analysis to build the new expression.
1905 /// Subclasses may override this routine to provide different behavior.
1906 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1907 bool IsArrow) {
1908 CXXScopeSpec SS;
1909 Expr *Base = BaseArg.takeAs<Expr>();
1910 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1911 Sema::LookupMemberName);
1912 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1913 /*FIME:*/IsaLoc,
John McCallad00b772010-06-16 08:42:20 +00001914 SS, DeclPtrTy(),
1915 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001916 if (Result.isInvalid())
1917 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001918
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001919 if (Result.get())
1920 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001921
1922 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001923 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001924 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001925 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001926 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001927 /*TemplateArgs=*/0);
1928 }
Sean Huntc3021132010-05-05 15:23:54 +00001929
Douglas Gregorb98b1992009-08-11 05:31:07 +00001930 /// \brief Build a new shuffle vector expression.
1931 ///
1932 /// By default, performs semantic analysis to build the new expression.
1933 /// Subclasses may override this routine to provide different behavior.
1934 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1935 MultiExprArg SubExprs,
1936 SourceLocation RParenLoc) {
1937 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001938 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001939 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1940 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1941 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1942 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001943
Douglas Gregorb98b1992009-08-11 05:31:07 +00001944 // Build a reference to the __builtin_shufflevector builtin
1945 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001946 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001947 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001948 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001949 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001950
1951 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 unsigned NumSubExprs = SubExprs.size();
1953 Expr **Subs = (Expr **)SubExprs.release();
1954 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1955 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00001956 Builtin->getCallResultType(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001957 RParenLoc);
1958 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001959
Douglas Gregorb98b1992009-08-11 05:31:07 +00001960 // Type-check the __builtin_shufflevector expression.
1961 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1962 if (Result.isInvalid())
1963 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001964
Douglas Gregorb98b1992009-08-11 05:31:07 +00001965 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001966 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001967 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001968};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001969
Douglas Gregor43959a92009-08-20 07:17:43 +00001970template<typename Derived>
1971Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1972 if (!S)
1973 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001974
Douglas Gregor43959a92009-08-20 07:17:43 +00001975 switch (S->getStmtClass()) {
1976 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001977
Douglas Gregor43959a92009-08-20 07:17:43 +00001978 // Transform individual statement nodes
1979#define STMT(Node, Parent) \
1980 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1981#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00001982#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00001983
Douglas Gregor43959a92009-08-20 07:17:43 +00001984 // Transform expressions by calling TransformExpr.
1985#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00001986#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00001987#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00001988#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00001989 {
1990 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1991 if (E.isInvalid())
1992 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001993
Anders Carlsson5ee56e92009-12-16 02:09:40 +00001994 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregor43959a92009-08-20 07:17:43 +00001995 }
Mike Stump1eb44332009-09-09 15:08:12 +00001996 }
1997
Douglas Gregor43959a92009-08-20 07:17:43 +00001998 return SemaRef.Owned(S->Retain());
1999}
Mike Stump1eb44332009-09-09 15:08:12 +00002000
2001
Douglas Gregor670444e2009-08-04 22:27:00 +00002002template<typename Derived>
John McCall454feb92009-12-08 09:21:05 +00002003Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002004 if (!E)
2005 return SemaRef.Owned(E);
2006
2007 switch (E->getStmtClass()) {
2008 case Stmt::NoStmtClass: break;
2009#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002010#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002011#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002012 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002013#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002014 }
2015
Douglas Gregorb98b1992009-08-11 05:31:07 +00002016 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002017}
2018
2019template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002020NestedNameSpecifier *
2021TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002022 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002023 QualType ObjectType,
2024 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00002025 if (!NNS)
2026 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002027
Douglas Gregor43959a92009-08-20 07:17:43 +00002028 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002029 NestedNameSpecifier *Prefix = NNS->getPrefix();
2030 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002031 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002032 ObjectType,
2033 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002034 if (!Prefix)
2035 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002036
2037 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00002038 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00002039 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00002040 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002041 }
Mike Stump1eb44332009-09-09 15:08:12 +00002042
Douglas Gregordcee1a12009-08-06 05:28:30 +00002043 switch (NNS->getKind()) {
2044 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00002045 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002046 "Identifier nested-name-specifier with no prefix or object type");
2047 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2048 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002049 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002050
2051 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002052 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002053 ObjectType,
2054 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002055
Douglas Gregordcee1a12009-08-06 05:28:30 +00002056 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002057 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002058 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002059 getDerived().TransformDecl(Range.getBegin(),
2060 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002061 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002062 Prefix == NNS->getPrefix() &&
2063 NS == NNS->getAsNamespace())
2064 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002065
Douglas Gregordcee1a12009-08-06 05:28:30 +00002066 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2067 }
Mike Stump1eb44332009-09-09 15:08:12 +00002068
Douglas Gregordcee1a12009-08-06 05:28:30 +00002069 case NestedNameSpecifier::Global:
2070 // There is no meaningful transformation that one could perform on the
2071 // global scope.
2072 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002073
Douglas Gregordcee1a12009-08-06 05:28:30 +00002074 case NestedNameSpecifier::TypeSpecWithTemplate:
2075 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002076 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor124b8782010-02-16 19:09:40 +00002077 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2078 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002079 if (T.isNull())
2080 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002081
Douglas Gregordcee1a12009-08-06 05:28:30 +00002082 if (!getDerived().AlwaysRebuild() &&
2083 Prefix == NNS->getPrefix() &&
2084 T == QualType(NNS->getAsType(), 0))
2085 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002086
2087 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2088 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002089 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002090 }
2091 }
Mike Stump1eb44332009-09-09 15:08:12 +00002092
Douglas Gregordcee1a12009-08-06 05:28:30 +00002093 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002094 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002095}
2096
2097template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002098DeclarationName
Douglas Gregor81499bb2009-09-03 22:13:48 +00002099TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +00002100 SourceLocation Loc,
2101 QualType ObjectType) {
Douglas Gregor81499bb2009-09-03 22:13:48 +00002102 if (!Name)
2103 return Name;
2104
2105 switch (Name.getNameKind()) {
2106 case DeclarationName::Identifier:
2107 case DeclarationName::ObjCZeroArgSelector:
2108 case DeclarationName::ObjCOneArgSelector:
2109 case DeclarationName::ObjCMultiArgSelector:
2110 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002111 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002112 case DeclarationName::CXXUsingDirective:
2113 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002114
Douglas Gregor81499bb2009-09-03 22:13:48 +00002115 case DeclarationName::CXXConstructorName:
2116 case DeclarationName::CXXDestructorName:
2117 case DeclarationName::CXXConversionFunctionName: {
2118 TemporaryBase Rebase(*this, Loc, Name);
Sean Huntc3021132010-05-05 15:23:54 +00002119 QualType T = getDerived().TransformType(Name.getCXXNameType(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002120 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00002121 if (T.isNull())
2122 return DeclarationName();
Mike Stump1eb44332009-09-09 15:08:12 +00002123
Douglas Gregor81499bb2009-09-03 22:13:48 +00002124 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump1eb44332009-09-09 15:08:12 +00002125 Name.getNameKind(),
Douglas Gregor81499bb2009-09-03 22:13:48 +00002126 SemaRef.Context.getCanonicalType(T));
Douglas Gregor81499bb2009-09-03 22:13:48 +00002127 }
Mike Stump1eb44332009-09-09 15:08:12 +00002128 }
2129
Douglas Gregor81499bb2009-09-03 22:13:48 +00002130 return DeclarationName();
2131}
2132
2133template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002134TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002135TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2136 QualType ObjectType) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002137 SourceLocation Loc = getDerived().getBaseLocation();
2138
Douglas Gregord1067e52009-08-06 06:41:21 +00002139 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002140 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002141 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002142 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2143 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002144 if (!NNS)
2145 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002146
Douglas Gregord1067e52009-08-06 06:41:21 +00002147 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002148 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002149 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002150 if (!TransTemplate)
2151 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002152
Douglas Gregord1067e52009-08-06 06:41:21 +00002153 if (!getDerived().AlwaysRebuild() &&
2154 NNS == QTN->getQualifier() &&
2155 TransTemplate == Template)
2156 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002157
Douglas Gregord1067e52009-08-06 06:41:21 +00002158 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2159 TransTemplate);
2160 }
Mike Stump1eb44332009-09-09 15:08:12 +00002161
John McCallf7a1a742009-11-24 19:00:30 +00002162 // These should be getting filtered out before they make it into the AST.
2163 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002164 }
Mike Stump1eb44332009-09-09 15:08:12 +00002165
Douglas Gregord1067e52009-08-06 06:41:21 +00002166 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002167 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002168 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002169 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2170 ObjectType);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002171 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00002172 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002173
Douglas Gregord1067e52009-08-06 06:41:21 +00002174 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002175 NNS == DTN->getQualifier() &&
2176 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002177 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002178
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002179 if (DTN->isIdentifier())
Sean Huntc3021132010-05-05 15:23:54 +00002180 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002181 ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +00002182
2183 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002184 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002185 }
Mike Stump1eb44332009-09-09 15:08:12 +00002186
Douglas Gregord1067e52009-08-06 06:41:21 +00002187 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002188 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002189 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002190 if (!TransTemplate)
2191 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002192
Douglas Gregord1067e52009-08-06 06:41:21 +00002193 if (!getDerived().AlwaysRebuild() &&
2194 TransTemplate == Template)
2195 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002196
Douglas Gregord1067e52009-08-06 06:41:21 +00002197 return TemplateName(TransTemplate);
2198 }
Mike Stump1eb44332009-09-09 15:08:12 +00002199
John McCallf7a1a742009-11-24 19:00:30 +00002200 // These should be getting filtered out before they reach the AST.
2201 assert(false && "overloaded function decl survived to here");
2202 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002203}
2204
2205template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002206void TreeTransform<Derived>::InventTemplateArgumentLoc(
2207 const TemplateArgument &Arg,
2208 TemplateArgumentLoc &Output) {
2209 SourceLocation Loc = getDerived().getBaseLocation();
2210 switch (Arg.getKind()) {
2211 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002212 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002213 break;
2214
2215 case TemplateArgument::Type:
2216 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002217 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002218
John McCall833ca992009-10-29 08:12:44 +00002219 break;
2220
Douglas Gregor788cd062009-11-11 01:00:40 +00002221 case TemplateArgument::Template:
2222 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2223 break;
Sean Huntc3021132010-05-05 15:23:54 +00002224
John McCall833ca992009-10-29 08:12:44 +00002225 case TemplateArgument::Expression:
2226 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2227 break;
2228
2229 case TemplateArgument::Declaration:
2230 case TemplateArgument::Integral:
2231 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002232 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002233 break;
2234 }
2235}
2236
2237template<typename Derived>
2238bool TreeTransform<Derived>::TransformTemplateArgument(
2239 const TemplateArgumentLoc &Input,
2240 TemplateArgumentLoc &Output) {
2241 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002242 switch (Arg.getKind()) {
2243 case TemplateArgument::Null:
2244 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002245 Output = Input;
2246 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002247
Douglas Gregor670444e2009-08-04 22:27:00 +00002248 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002249 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002250 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002251 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002252
2253 DI = getDerived().TransformType(DI);
2254 if (!DI) return true;
2255
2256 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2257 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002258 }
Mike Stump1eb44332009-09-09 15:08:12 +00002259
Douglas Gregor670444e2009-08-04 22:27:00 +00002260 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002261 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002262 DeclarationName Name;
2263 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2264 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002265 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002266 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002267 if (!D) return true;
2268
John McCall828bff22009-10-29 18:45:58 +00002269 Expr *SourceExpr = Input.getSourceDeclExpression();
2270 if (SourceExpr) {
2271 EnterExpressionEvaluationContext Unevaluated(getSema(),
2272 Action::Unevaluated);
2273 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2274 if (E.isInvalid())
2275 SourceExpr = NULL;
2276 else {
2277 SourceExpr = E.takeAs<Expr>();
2278 SourceExpr->Retain();
2279 }
2280 }
2281
2282 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002283 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002284 }
Mike Stump1eb44332009-09-09 15:08:12 +00002285
Douglas Gregor788cd062009-11-11 01:00:40 +00002286 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002287 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002288 TemplateName Template
2289 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2290 if (Template.isNull())
2291 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002292
Douglas Gregor788cd062009-11-11 01:00:40 +00002293 Output = TemplateArgumentLoc(TemplateArgument(Template),
2294 Input.getTemplateQualifierRange(),
2295 Input.getTemplateNameLoc());
2296 return false;
2297 }
Sean Huntc3021132010-05-05 15:23:54 +00002298
Douglas Gregor670444e2009-08-04 22:27:00 +00002299 case TemplateArgument::Expression: {
2300 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002301 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002302 Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002303
John McCall833ca992009-10-29 08:12:44 +00002304 Expr *InputExpr = Input.getSourceExpression();
2305 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2306
2307 Sema::OwningExprResult E
2308 = getDerived().TransformExpr(InputExpr);
2309 if (E.isInvalid()) return true;
2310
2311 Expr *ETaken = E.takeAs<Expr>();
John McCall828bff22009-10-29 18:45:58 +00002312 ETaken->Retain();
John McCall833ca992009-10-29 08:12:44 +00002313 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2314 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002315 }
Mike Stump1eb44332009-09-09 15:08:12 +00002316
Douglas Gregor670444e2009-08-04 22:27:00 +00002317 case TemplateArgument::Pack: {
2318 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2319 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002320 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002321 AEnd = Arg.pack_end();
2322 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002323
John McCall833ca992009-10-29 08:12:44 +00002324 // FIXME: preserve source information here when we start
2325 // caring about parameter packs.
2326
John McCall828bff22009-10-29 18:45:58 +00002327 TemplateArgumentLoc InputArg;
2328 TemplateArgumentLoc OutputArg;
2329 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2330 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002331 return true;
2332
John McCall828bff22009-10-29 18:45:58 +00002333 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002334 }
2335 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002336 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002337 true);
John McCall828bff22009-10-29 18:45:58 +00002338 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002339 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002340 }
2341 }
Mike Stump1eb44332009-09-09 15:08:12 +00002342
Douglas Gregor670444e2009-08-04 22:27:00 +00002343 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002344 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002345}
2346
Douglas Gregor577f75a2009-08-04 16:50:30 +00002347//===----------------------------------------------------------------------===//
2348// Type transformation
2349//===----------------------------------------------------------------------===//
2350
2351template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00002352QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregor124b8782010-02-16 19:09:40 +00002353 QualType ObjectType) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002354 if (getDerived().AlreadyTransformed(T))
2355 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002356
John McCalla2becad2009-10-21 00:40:46 +00002357 // Temporary workaround. All of these transformations should
2358 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002359 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002360 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002361
Douglas Gregor124b8782010-02-16 19:09:40 +00002362 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall0953e762009-09-24 19:53:00 +00002363
John McCalla2becad2009-10-21 00:40:46 +00002364 if (!NewDI)
2365 return QualType();
2366
2367 return NewDI->getType();
2368}
2369
2370template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002371TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2372 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002373 if (getDerived().AlreadyTransformed(DI->getType()))
2374 return DI;
2375
2376 TypeLocBuilder TLB;
2377
2378 TypeLoc TL = DI->getTypeLoc();
2379 TLB.reserve(TL.getFullDataSize());
2380
Douglas Gregor124b8782010-02-16 19:09:40 +00002381 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002382 if (Result.isNull())
2383 return 0;
2384
John McCalla93c9342009-12-07 02:54:59 +00002385 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002386}
2387
2388template<typename Derived>
2389QualType
Douglas Gregor124b8782010-02-16 19:09:40 +00002390TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2391 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002392 switch (T.getTypeLocClass()) {
2393#define ABSTRACT_TYPELOC(CLASS, PARENT)
2394#define TYPELOC(CLASS, PARENT) \
2395 case TypeLoc::CLASS: \
Douglas Gregor124b8782010-02-16 19:09:40 +00002396 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2397 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002398#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002399 }
Mike Stump1eb44332009-09-09 15:08:12 +00002400
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002401 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002402 return QualType();
2403}
2404
2405/// FIXME: By default, this routine adds type qualifiers only to types
2406/// that can have qualifiers, and silently suppresses those qualifiers
2407/// that are not permitted (e.g., qualifiers on reference or function
2408/// types). This is the right thing for template instantiation, but
2409/// probably not for other clients.
2410template<typename Derived>
2411QualType
2412TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002413 QualifiedTypeLoc T,
2414 QualType ObjectType) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002415 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002416
Douglas Gregor124b8782010-02-16 19:09:40 +00002417 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2418 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002419 if (Result.isNull())
2420 return QualType();
2421
2422 // Silently suppress qualifiers if the result type can't be qualified.
2423 // FIXME: this is the right thing for template instantiation, but
2424 // probably not for other clients.
2425 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002426 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002427
John McCall28654742010-06-05 06:41:15 +00002428 if (!Quals.empty()) {
2429 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2430 TLB.push<QualifiedTypeLoc>(Result);
2431 // No location information to preserve.
2432 }
John McCalla2becad2009-10-21 00:40:46 +00002433
2434 return Result;
2435}
2436
2437template <class TyLoc> static inline
2438QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2439 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2440 NewT.setNameLoc(T.getNameLoc());
2441 return T.getType();
2442}
2443
John McCalla2becad2009-10-21 00:40:46 +00002444template<typename Derived>
2445QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002446 BuiltinTypeLoc T,
2447 QualType ObjectType) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002448 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2449 NewT.setBuiltinLoc(T.getBuiltinLoc());
2450 if (T.needsExtraLocalData())
2451 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2452 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002453}
Mike Stump1eb44332009-09-09 15:08:12 +00002454
Douglas Gregor577f75a2009-08-04 16:50:30 +00002455template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002456QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002457 ComplexTypeLoc T,
2458 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002459 // FIXME: recurse?
2460 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002461}
Mike Stump1eb44332009-09-09 15:08:12 +00002462
Douglas Gregor577f75a2009-08-04 16:50:30 +00002463template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002464QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Sean Huntc3021132010-05-05 15:23:54 +00002465 PointerTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00002466 QualType ObjectType) {
Sean Huntc3021132010-05-05 15:23:54 +00002467 QualType PointeeType
2468 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002469 if (PointeeType.isNull())
2470 return QualType();
2471
2472 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00002473 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002474 // A dependent pointer type 'T *' has is being transformed such
2475 // that an Objective-C class type is being replaced for 'T'. The
2476 // resulting pointer type is an ObjCObjectPointerType, not a
2477 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00002478 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00002479
John McCallc12c5bb2010-05-15 11:32:37 +00002480 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2481 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002482 return Result;
2483 }
Sean Huntc3021132010-05-05 15:23:54 +00002484
Douglas Gregor92e986e2010-04-22 16:44:27 +00002485 if (getDerived().AlwaysRebuild() ||
2486 PointeeType != TL.getPointeeLoc().getType()) {
2487 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2488 if (Result.isNull())
2489 return QualType();
2490 }
Sean Huntc3021132010-05-05 15:23:54 +00002491
Douglas Gregor92e986e2010-04-22 16:44:27 +00002492 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2493 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00002494 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002495}
Mike Stump1eb44332009-09-09 15:08:12 +00002496
2497template<typename Derived>
2498QualType
John McCalla2becad2009-10-21 00:40:46 +00002499TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002500 BlockPointerTypeLoc TL,
2501 QualType ObjectType) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002502 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00002503 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2504 if (PointeeType.isNull())
2505 return QualType();
2506
2507 QualType Result = TL.getType();
2508 if (getDerived().AlwaysRebuild() ||
2509 PointeeType != TL.getPointeeLoc().getType()) {
2510 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002511 TL.getSigilLoc());
2512 if (Result.isNull())
2513 return QualType();
2514 }
2515
Douglas Gregor39968ad2010-04-22 16:50:51 +00002516 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002517 NewT.setSigilLoc(TL.getSigilLoc());
2518 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002519}
2520
John McCall85737a72009-10-30 00:06:24 +00002521/// Transforms a reference type. Note that somewhat paradoxically we
2522/// don't care whether the type itself is an l-value type or an r-value
2523/// type; we only care if the type was *written* as an l-value type
2524/// or an r-value type.
2525template<typename Derived>
2526QualType
2527TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002528 ReferenceTypeLoc TL,
2529 QualType ObjectType) {
John McCall85737a72009-10-30 00:06:24 +00002530 const ReferenceType *T = TL.getTypePtr();
2531
2532 // Note that this works with the pointee-as-written.
2533 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2534 if (PointeeType.isNull())
2535 return QualType();
2536
2537 QualType Result = TL.getType();
2538 if (getDerived().AlwaysRebuild() ||
2539 PointeeType != T->getPointeeTypeAsWritten()) {
2540 Result = getDerived().RebuildReferenceType(PointeeType,
2541 T->isSpelledAsLValue(),
2542 TL.getSigilLoc());
2543 if (Result.isNull())
2544 return QualType();
2545 }
2546
2547 // r-value references can be rebuilt as l-value references.
2548 ReferenceTypeLoc NewTL;
2549 if (isa<LValueReferenceType>(Result))
2550 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2551 else
2552 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2553 NewTL.setSigilLoc(TL.getSigilLoc());
2554
2555 return Result;
2556}
2557
Mike Stump1eb44332009-09-09 15:08:12 +00002558template<typename Derived>
2559QualType
John McCalla2becad2009-10-21 00:40:46 +00002560TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002561 LValueReferenceTypeLoc TL,
2562 QualType ObjectType) {
2563 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002564}
2565
Mike Stump1eb44332009-09-09 15:08:12 +00002566template<typename Derived>
2567QualType
John McCalla2becad2009-10-21 00:40:46 +00002568TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002569 RValueReferenceTypeLoc TL,
2570 QualType ObjectType) {
2571 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002572}
Mike Stump1eb44332009-09-09 15:08:12 +00002573
Douglas Gregor577f75a2009-08-04 16:50:30 +00002574template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002575QualType
John McCalla2becad2009-10-21 00:40:46 +00002576TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002577 MemberPointerTypeLoc TL,
2578 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002579 MemberPointerType *T = TL.getTypePtr();
2580
2581 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002582 if (PointeeType.isNull())
2583 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002584
John McCalla2becad2009-10-21 00:40:46 +00002585 // TODO: preserve source information for this.
2586 QualType ClassType
2587 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002588 if (ClassType.isNull())
2589 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002590
John McCalla2becad2009-10-21 00:40:46 +00002591 QualType Result = TL.getType();
2592 if (getDerived().AlwaysRebuild() ||
2593 PointeeType != T->getPointeeType() ||
2594 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002595 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2596 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002597 if (Result.isNull())
2598 return QualType();
2599 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002600
John McCalla2becad2009-10-21 00:40:46 +00002601 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2602 NewTL.setSigilLoc(TL.getSigilLoc());
2603
2604 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002605}
2606
Mike Stump1eb44332009-09-09 15:08:12 +00002607template<typename Derived>
2608QualType
John McCalla2becad2009-10-21 00:40:46 +00002609TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002610 ConstantArrayTypeLoc TL,
2611 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002612 ConstantArrayType *T = TL.getTypePtr();
2613 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002614 if (ElementType.isNull())
2615 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002616
John McCalla2becad2009-10-21 00:40:46 +00002617 QualType Result = TL.getType();
2618 if (getDerived().AlwaysRebuild() ||
2619 ElementType != T->getElementType()) {
2620 Result = getDerived().RebuildConstantArrayType(ElementType,
2621 T->getSizeModifier(),
2622 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002623 T->getIndexTypeCVRQualifiers(),
2624 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002625 if (Result.isNull())
2626 return QualType();
2627 }
Sean Huntc3021132010-05-05 15:23:54 +00002628
John McCalla2becad2009-10-21 00:40:46 +00002629 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2630 NewTL.setLBracketLoc(TL.getLBracketLoc());
2631 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002632
John McCalla2becad2009-10-21 00:40:46 +00002633 Expr *Size = TL.getSizeExpr();
2634 if (Size) {
2635 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2636 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2637 }
2638 NewTL.setSizeExpr(Size);
2639
2640 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002641}
Mike Stump1eb44332009-09-09 15:08:12 +00002642
Douglas Gregor577f75a2009-08-04 16:50:30 +00002643template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002644QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002645 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002646 IncompleteArrayTypeLoc TL,
2647 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002648 IncompleteArrayType *T = TL.getTypePtr();
2649 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002650 if (ElementType.isNull())
2651 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002652
John McCalla2becad2009-10-21 00:40:46 +00002653 QualType Result = TL.getType();
2654 if (getDerived().AlwaysRebuild() ||
2655 ElementType != T->getElementType()) {
2656 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002657 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002658 T->getIndexTypeCVRQualifiers(),
2659 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002660 if (Result.isNull())
2661 return QualType();
2662 }
Sean Huntc3021132010-05-05 15:23:54 +00002663
John McCalla2becad2009-10-21 00:40:46 +00002664 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2665 NewTL.setLBracketLoc(TL.getLBracketLoc());
2666 NewTL.setRBracketLoc(TL.getRBracketLoc());
2667 NewTL.setSizeExpr(0);
2668
2669 return Result;
2670}
2671
2672template<typename Derived>
2673QualType
2674TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002675 VariableArrayTypeLoc TL,
2676 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002677 VariableArrayType *T = TL.getTypePtr();
2678 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2679 if (ElementType.isNull())
2680 return QualType();
2681
2682 // Array bounds are not potentially evaluated contexts
2683 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2684
2685 Sema::OwningExprResult SizeResult
2686 = getDerived().TransformExpr(T->getSizeExpr());
2687 if (SizeResult.isInvalid())
2688 return QualType();
2689
2690 Expr *Size = static_cast<Expr*>(SizeResult.get());
2691
2692 QualType Result = TL.getType();
2693 if (getDerived().AlwaysRebuild() ||
2694 ElementType != T->getElementType() ||
2695 Size != T->getSizeExpr()) {
2696 Result = getDerived().RebuildVariableArrayType(ElementType,
2697 T->getSizeModifier(),
2698 move(SizeResult),
2699 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002700 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002701 if (Result.isNull())
2702 return QualType();
2703 }
2704 else SizeResult.take();
Sean Huntc3021132010-05-05 15:23:54 +00002705
John McCalla2becad2009-10-21 00:40:46 +00002706 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2707 NewTL.setLBracketLoc(TL.getLBracketLoc());
2708 NewTL.setRBracketLoc(TL.getRBracketLoc());
2709 NewTL.setSizeExpr(Size);
2710
2711 return Result;
2712}
2713
2714template<typename Derived>
2715QualType
2716TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002717 DependentSizedArrayTypeLoc TL,
2718 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002719 DependentSizedArrayType *T = TL.getTypePtr();
2720 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2721 if (ElementType.isNull())
2722 return QualType();
2723
2724 // Array bounds are not potentially evaluated contexts
2725 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2726
2727 Sema::OwningExprResult SizeResult
2728 = getDerived().TransformExpr(T->getSizeExpr());
2729 if (SizeResult.isInvalid())
2730 return QualType();
2731
2732 Expr *Size = static_cast<Expr*>(SizeResult.get());
2733
2734 QualType Result = TL.getType();
2735 if (getDerived().AlwaysRebuild() ||
2736 ElementType != T->getElementType() ||
2737 Size != T->getSizeExpr()) {
2738 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2739 T->getSizeModifier(),
2740 move(SizeResult),
2741 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002742 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002743 if (Result.isNull())
2744 return QualType();
2745 }
2746 else SizeResult.take();
2747
2748 // We might have any sort of array type now, but fortunately they
2749 // all have the same location layout.
2750 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2751 NewTL.setLBracketLoc(TL.getLBracketLoc());
2752 NewTL.setRBracketLoc(TL.getRBracketLoc());
2753 NewTL.setSizeExpr(Size);
2754
2755 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002756}
Mike Stump1eb44332009-09-09 15:08:12 +00002757
2758template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002759QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002760 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002761 DependentSizedExtVectorTypeLoc TL,
2762 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002763 DependentSizedExtVectorType *T = TL.getTypePtr();
2764
2765 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002766 QualType ElementType = getDerived().TransformType(T->getElementType());
2767 if (ElementType.isNull())
2768 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002769
Douglas Gregor670444e2009-08-04 22:27:00 +00002770 // Vector sizes are not potentially evaluated contexts
2771 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2772
Douglas Gregor577f75a2009-08-04 16:50:30 +00002773 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2774 if (Size.isInvalid())
2775 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002776
John McCalla2becad2009-10-21 00:40:46 +00002777 QualType Result = TL.getType();
2778 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002779 ElementType != T->getElementType() ||
2780 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002781 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002782 move(Size),
2783 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002784 if (Result.isNull())
2785 return QualType();
2786 }
2787 else Size.take();
2788
2789 // Result might be dependent or not.
2790 if (isa<DependentSizedExtVectorType>(Result)) {
2791 DependentSizedExtVectorTypeLoc NewTL
2792 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2793 NewTL.setNameLoc(TL.getNameLoc());
2794 } else {
2795 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2796 NewTL.setNameLoc(TL.getNameLoc());
2797 }
2798
2799 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002800}
Mike Stump1eb44332009-09-09 15:08:12 +00002801
2802template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002803QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002804 VectorTypeLoc TL,
2805 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002806 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002807 QualType ElementType = getDerived().TransformType(T->getElementType());
2808 if (ElementType.isNull())
2809 return QualType();
2810
John McCalla2becad2009-10-21 00:40:46 +00002811 QualType Result = TL.getType();
2812 if (getDerived().AlwaysRebuild() ||
2813 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002814 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner788b0fd2010-06-23 06:00:24 +00002815 T->getAltiVecSpecific());
John McCalla2becad2009-10-21 00:40:46 +00002816 if (Result.isNull())
2817 return QualType();
2818 }
Sean Huntc3021132010-05-05 15:23:54 +00002819
John McCalla2becad2009-10-21 00:40:46 +00002820 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2821 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002822
John McCalla2becad2009-10-21 00:40:46 +00002823 return Result;
2824}
2825
2826template<typename Derived>
2827QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002828 ExtVectorTypeLoc TL,
2829 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002830 VectorType *T = TL.getTypePtr();
2831 QualType ElementType = getDerived().TransformType(T->getElementType());
2832 if (ElementType.isNull())
2833 return QualType();
2834
2835 QualType Result = TL.getType();
2836 if (getDerived().AlwaysRebuild() ||
2837 ElementType != T->getElementType()) {
2838 Result = getDerived().RebuildExtVectorType(ElementType,
2839 T->getNumElements(),
2840 /*FIXME*/ SourceLocation());
2841 if (Result.isNull())
2842 return QualType();
2843 }
Sean Huntc3021132010-05-05 15:23:54 +00002844
John McCalla2becad2009-10-21 00:40:46 +00002845 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2846 NewTL.setNameLoc(TL.getNameLoc());
2847
2848 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002849}
Mike Stump1eb44332009-09-09 15:08:12 +00002850
2851template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002852ParmVarDecl *
2853TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2854 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2855 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2856 if (!NewDI)
2857 return 0;
2858
2859 if (NewDI == OldDI)
2860 return OldParm;
2861 else
2862 return ParmVarDecl::Create(SemaRef.Context,
2863 OldParm->getDeclContext(),
2864 OldParm->getLocation(),
2865 OldParm->getIdentifier(),
2866 NewDI->getType(),
2867 NewDI,
2868 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00002869 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00002870 /* DefArg */ NULL);
2871}
2872
2873template<typename Derived>
2874bool TreeTransform<Derived>::
2875 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2876 llvm::SmallVectorImpl<QualType> &PTypes,
2877 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2878 FunctionProtoType *T = TL.getTypePtr();
2879
2880 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2881 ParmVarDecl *OldParm = TL.getArg(i);
2882
2883 QualType NewType;
2884 ParmVarDecl *NewParm;
2885
2886 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002887 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2888 if (!NewParm)
2889 return true;
2890 NewType = NewParm->getType();
2891
2892 // Deal with the possibility that we don't have a parameter
2893 // declaration for this parameter.
2894 } else {
2895 NewParm = 0;
2896
2897 QualType OldType = T->getArgType(i);
2898 NewType = getDerived().TransformType(OldType);
2899 if (NewType.isNull())
2900 return true;
2901 }
2902
2903 PTypes.push_back(NewType);
2904 PVars.push_back(NewParm);
2905 }
2906
2907 return false;
2908}
2909
2910template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002911QualType
John McCalla2becad2009-10-21 00:40:46 +00002912TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002913 FunctionProtoTypeLoc TL,
2914 QualType ObjectType) {
Douglas Gregor895162d2010-04-30 18:55:50 +00002915 // Transform the parameters. We do this first for the benefit of template
2916 // instantiations, so that the ParmVarDecls get/ placed into the template
2917 // instantiation scope before we transform the function type.
Douglas Gregor577f75a2009-08-04 16:50:30 +00002918 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002919 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall21ef0fa2010-03-11 09:03:00 +00002920 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2921 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +00002922
Douglas Gregor895162d2010-04-30 18:55:50 +00002923 FunctionProtoType *T = TL.getTypePtr();
2924 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2925 if (ResultType.isNull())
2926 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +00002927
John McCalla2becad2009-10-21 00:40:46 +00002928 QualType Result = TL.getType();
2929 if (getDerived().AlwaysRebuild() ||
2930 ResultType != T->getResultType() ||
2931 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2932 Result = getDerived().RebuildFunctionProtoType(ResultType,
2933 ParamTypes.data(),
2934 ParamTypes.size(),
2935 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00002936 T->getTypeQuals(),
2937 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00002938 if (Result.isNull())
2939 return QualType();
2940 }
Mike Stump1eb44332009-09-09 15:08:12 +00002941
John McCalla2becad2009-10-21 00:40:46 +00002942 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2943 NewTL.setLParenLoc(TL.getLParenLoc());
2944 NewTL.setRParenLoc(TL.getRParenLoc());
2945 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2946 NewTL.setArg(i, ParamDecls[i]);
2947
2948 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002949}
Mike Stump1eb44332009-09-09 15:08:12 +00002950
Douglas Gregor577f75a2009-08-04 16:50:30 +00002951template<typename Derived>
2952QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002953 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002954 FunctionNoProtoTypeLoc TL,
2955 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002956 FunctionNoProtoType *T = TL.getTypePtr();
2957 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2958 if (ResultType.isNull())
2959 return QualType();
2960
2961 QualType Result = TL.getType();
2962 if (getDerived().AlwaysRebuild() ||
2963 ResultType != T->getResultType())
2964 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2965
2966 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2967 NewTL.setLParenLoc(TL.getLParenLoc());
2968 NewTL.setRParenLoc(TL.getRParenLoc());
2969
2970 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002971}
Mike Stump1eb44332009-09-09 15:08:12 +00002972
John McCalled976492009-12-04 22:46:56 +00002973template<typename Derived> QualType
2974TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002975 UnresolvedUsingTypeLoc TL,
2976 QualType ObjectType) {
John McCalled976492009-12-04 22:46:56 +00002977 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002978 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00002979 if (!D)
2980 return QualType();
2981
2982 QualType Result = TL.getType();
2983 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2984 Result = getDerived().RebuildUnresolvedUsingType(D);
2985 if (Result.isNull())
2986 return QualType();
2987 }
2988
2989 // We might get an arbitrary type spec type back. We should at
2990 // least always get a type spec type, though.
2991 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2992 NewTL.setNameLoc(TL.getNameLoc());
2993
2994 return Result;
2995}
2996
Douglas Gregor577f75a2009-08-04 16:50:30 +00002997template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002998QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002999 TypedefTypeLoc TL,
3000 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003001 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003002 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003003 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3004 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003005 if (!Typedef)
3006 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003007
John McCalla2becad2009-10-21 00:40:46 +00003008 QualType Result = TL.getType();
3009 if (getDerived().AlwaysRebuild() ||
3010 Typedef != T->getDecl()) {
3011 Result = getDerived().RebuildTypedefType(Typedef);
3012 if (Result.isNull())
3013 return QualType();
3014 }
Mike Stump1eb44332009-09-09 15:08:12 +00003015
John McCalla2becad2009-10-21 00:40:46 +00003016 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3017 NewTL.setNameLoc(TL.getNameLoc());
3018
3019 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003020}
Mike Stump1eb44332009-09-09 15:08:12 +00003021
Douglas Gregor577f75a2009-08-04 16:50:30 +00003022template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003023QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003024 TypeOfExprTypeLoc TL,
3025 QualType ObjectType) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003026 // typeof expressions are not potentially evaluated contexts
3027 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003028
John McCallcfb708c2010-01-13 20:03:27 +00003029 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003030 if (E.isInvalid())
3031 return QualType();
3032
John McCalla2becad2009-10-21 00:40:46 +00003033 QualType Result = TL.getType();
3034 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003035 E.get() != TL.getUnderlyingExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003036 Result = getDerived().RebuildTypeOfExprType(move(E));
3037 if (Result.isNull())
3038 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003039 }
John McCalla2becad2009-10-21 00:40:46 +00003040 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003041
John McCalla2becad2009-10-21 00:40:46 +00003042 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003043 NewTL.setTypeofLoc(TL.getTypeofLoc());
3044 NewTL.setLParenLoc(TL.getLParenLoc());
3045 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003046
3047 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003048}
Mike Stump1eb44332009-09-09 15:08:12 +00003049
3050template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003051QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003052 TypeOfTypeLoc TL,
3053 QualType ObjectType) {
John McCallcfb708c2010-01-13 20:03:27 +00003054 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3055 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3056 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003057 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003058
John McCalla2becad2009-10-21 00:40:46 +00003059 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003060 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3061 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003062 if (Result.isNull())
3063 return QualType();
3064 }
Mike Stump1eb44332009-09-09 15:08:12 +00003065
John McCalla2becad2009-10-21 00:40:46 +00003066 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003067 NewTL.setTypeofLoc(TL.getTypeofLoc());
3068 NewTL.setLParenLoc(TL.getLParenLoc());
3069 NewTL.setRParenLoc(TL.getRParenLoc());
3070 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003071
3072 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003073}
Mike Stump1eb44332009-09-09 15:08:12 +00003074
3075template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003076QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003077 DecltypeTypeLoc TL,
3078 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003079 DecltypeType *T = TL.getTypePtr();
3080
Douglas Gregor670444e2009-08-04 22:27:00 +00003081 // decltype expressions are not potentially evaluated contexts
3082 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003083
Douglas Gregor577f75a2009-08-04 16:50:30 +00003084 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3085 if (E.isInvalid())
3086 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003087
John McCalla2becad2009-10-21 00:40:46 +00003088 QualType Result = TL.getType();
3089 if (getDerived().AlwaysRebuild() ||
3090 E.get() != T->getUnderlyingExpr()) {
3091 Result = getDerived().RebuildDecltypeType(move(E));
3092 if (Result.isNull())
3093 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003094 }
John McCalla2becad2009-10-21 00:40:46 +00003095 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003096
John McCalla2becad2009-10-21 00:40:46 +00003097 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3098 NewTL.setNameLoc(TL.getNameLoc());
3099
3100 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003101}
3102
3103template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003104QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003105 RecordTypeLoc TL,
3106 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003107 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003108 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003109 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3110 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003111 if (!Record)
3112 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003113
John McCalla2becad2009-10-21 00:40:46 +00003114 QualType Result = TL.getType();
3115 if (getDerived().AlwaysRebuild() ||
3116 Record != T->getDecl()) {
3117 Result = getDerived().RebuildRecordType(Record);
3118 if (Result.isNull())
3119 return QualType();
3120 }
Mike Stump1eb44332009-09-09 15:08:12 +00003121
John McCalla2becad2009-10-21 00:40:46 +00003122 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3123 NewTL.setNameLoc(TL.getNameLoc());
3124
3125 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003126}
Mike Stump1eb44332009-09-09 15:08:12 +00003127
3128template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003129QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003130 EnumTypeLoc TL,
3131 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003132 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003133 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003134 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3135 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003136 if (!Enum)
3137 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003138
John McCalla2becad2009-10-21 00:40:46 +00003139 QualType Result = TL.getType();
3140 if (getDerived().AlwaysRebuild() ||
3141 Enum != T->getDecl()) {
3142 Result = getDerived().RebuildEnumType(Enum);
3143 if (Result.isNull())
3144 return QualType();
3145 }
Mike Stump1eb44332009-09-09 15:08:12 +00003146
John McCalla2becad2009-10-21 00:40:46 +00003147 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3148 NewTL.setNameLoc(TL.getNameLoc());
3149
3150 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003151}
John McCall7da24312009-09-05 00:15:47 +00003152
John McCall3cb0ebd2010-03-10 03:28:59 +00003153template<typename Derived>
3154QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3155 TypeLocBuilder &TLB,
3156 InjectedClassNameTypeLoc TL,
3157 QualType ObjectType) {
3158 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3159 TL.getTypePtr()->getDecl());
3160 if (!D) return QualType();
3161
3162 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3163 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3164 return T;
3165}
3166
Mike Stump1eb44332009-09-09 15:08:12 +00003167
Douglas Gregor577f75a2009-08-04 16:50:30 +00003168template<typename Derived>
3169QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003170 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003171 TemplateTypeParmTypeLoc TL,
3172 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003173 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003174}
3175
Mike Stump1eb44332009-09-09 15:08:12 +00003176template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003177QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003178 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003179 SubstTemplateTypeParmTypeLoc TL,
3180 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003181 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003182}
3183
3184template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003185QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3186 const TemplateSpecializationType *TST,
3187 QualType ObjectType) {
3188 // FIXME: this entire method is a temporary workaround; callers
3189 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00003190
John McCall833ca992009-10-29 08:12:44 +00003191 // Fake up a TemplateSpecializationTypeLoc.
3192 TypeLocBuilder TLB;
3193 TemplateSpecializationTypeLoc TL
3194 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3195
John McCall828bff22009-10-29 18:45:58 +00003196 SourceLocation BaseLoc = getDerived().getBaseLocation();
3197
3198 TL.setTemplateNameLoc(BaseLoc);
3199 TL.setLAngleLoc(BaseLoc);
3200 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00003201 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3202 const TemplateArgument &TA = TST->getArg(i);
3203 TemplateArgumentLoc TAL;
3204 getDerived().InventTemplateArgumentLoc(TA, TAL);
3205 TL.setArgLocInfo(i, TAL.getLocInfo());
3206 }
3207
3208 TypeLocBuilder IgnoredTLB;
3209 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00003210}
Sean Huntc3021132010-05-05 15:23:54 +00003211
Douglas Gregordd62b152009-10-19 22:04:39 +00003212template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003213QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003214 TypeLocBuilder &TLB,
3215 TemplateSpecializationTypeLoc TL,
3216 QualType ObjectType) {
3217 const TemplateSpecializationType *T = TL.getTypePtr();
3218
Mike Stump1eb44332009-09-09 15:08:12 +00003219 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00003220 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003221 if (Template.isNull())
3222 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003223
John McCalld5532b62009-11-23 01:53:49 +00003224 TemplateArgumentListInfo NewTemplateArgs;
3225 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3226 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3227
3228 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3229 TemplateArgumentLoc Loc;
3230 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00003231 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00003232 NewTemplateArgs.addArgument(Loc);
3233 }
Mike Stump1eb44332009-09-09 15:08:12 +00003234
John McCall833ca992009-10-29 08:12:44 +00003235 // FIXME: maybe don't rebuild if all the template arguments are the same.
3236
3237 QualType Result =
3238 getDerived().RebuildTemplateSpecializationType(Template,
3239 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003240 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003241
3242 if (!Result.isNull()) {
3243 TemplateSpecializationTypeLoc NewTL
3244 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3245 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3246 NewTL.setLAngleLoc(TL.getLAngleLoc());
3247 NewTL.setRAngleLoc(TL.getRAngleLoc());
3248 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3249 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003250 }
Mike Stump1eb44332009-09-09 15:08:12 +00003251
John McCall833ca992009-10-29 08:12:44 +00003252 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003253}
Mike Stump1eb44332009-09-09 15:08:12 +00003254
3255template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003256QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003257TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3258 ElaboratedTypeLoc TL,
3259 QualType ObjectType) {
3260 ElaboratedType *T = TL.getTypePtr();
3261
3262 NestedNameSpecifier *NNS = 0;
3263 // NOTE: the qualifier in an ElaboratedType is optional.
3264 if (T->getQualifier() != 0) {
3265 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003266 TL.getQualifierRange(),
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003267 ObjectType);
3268 if (!NNS)
3269 return QualType();
3270 }
Mike Stump1eb44332009-09-09 15:08:12 +00003271
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003272 QualType NamedT;
3273 // FIXME: this test is meant to workaround a problem (failing assertion)
3274 // occurring if directly executing the code in the else branch.
3275 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3276 TemplateSpecializationTypeLoc OldNamedTL
3277 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3278 const TemplateSpecializationType* OldTST
Jim Grosbach9cbb4d82010-05-19 23:53:08 +00003279 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003280 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3281 if (NamedT.isNull())
3282 return QualType();
3283 TemplateSpecializationTypeLoc NewNamedTL
3284 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3285 NewNamedTL.copy(OldNamedTL);
3286 }
3287 else {
3288 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3289 if (NamedT.isNull())
3290 return QualType();
3291 }
Daniel Dunbara63db842010-05-14 16:34:09 +00003292
John McCalla2becad2009-10-21 00:40:46 +00003293 QualType Result = TL.getType();
3294 if (getDerived().AlwaysRebuild() ||
3295 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003296 NamedT != T->getNamedType()) {
3297 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00003298 if (Result.isNull())
3299 return QualType();
3300 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003301
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003302 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003303 NewTL.setKeywordLoc(TL.getKeywordLoc());
3304 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00003305
3306 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003307}
Mike Stump1eb44332009-09-09 15:08:12 +00003308
3309template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003310QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3311 DependentNameTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00003312 QualType ObjectType) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003313 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003314
Douglas Gregor577f75a2009-08-04 16:50:30 +00003315 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003316 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3317 TL.getQualifierRange(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003318 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003319 if (!NNS)
3320 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003321
John McCall33500952010-06-11 00:33:02 +00003322 QualType Result
3323 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3324 T->getIdentifier(),
3325 TL.getKeywordLoc(),
3326 TL.getQualifierRange(),
3327 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003328 if (Result.isNull())
3329 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003330
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003331 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3332 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00003333 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3334
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003335 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3336 NewTL.setKeywordLoc(TL.getKeywordLoc());
3337 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003338 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003339 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3340 NewTL.setKeywordLoc(TL.getKeywordLoc());
3341 NewTL.setQualifierRange(TL.getQualifierRange());
3342 NewTL.setNameLoc(TL.getNameLoc());
3343 }
John McCalla2becad2009-10-21 00:40:46 +00003344 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003345}
Mike Stump1eb44332009-09-09 15:08:12 +00003346
Douglas Gregor577f75a2009-08-04 16:50:30 +00003347template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00003348QualType TreeTransform<Derived>::
3349 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3350 DependentTemplateSpecializationTypeLoc TL,
3351 QualType ObjectType) {
3352 DependentTemplateSpecializationType *T = TL.getTypePtr();
3353
3354 NestedNameSpecifier *NNS
3355 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3356 TL.getQualifierRange(),
3357 ObjectType);
3358 if (!NNS)
3359 return QualType();
3360
3361 TemplateArgumentListInfo NewTemplateArgs;
3362 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3363 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3364
3365 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3366 TemplateArgumentLoc Loc;
3367 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3368 return QualType();
3369 NewTemplateArgs.addArgument(Loc);
3370 }
3371
3372 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
3373 T->getKeyword(),
3374 NNS,
3375 T->getIdentifier(),
3376 TL.getNameLoc(),
3377 NewTemplateArgs);
3378 if (Result.isNull())
3379 return QualType();
3380
3381 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3382 QualType NamedT = ElabT->getNamedType();
3383
3384 // Copy information relevant to the template specialization.
3385 TemplateSpecializationTypeLoc NamedTL
3386 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3387 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3388 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3389 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3390 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3391
3392 // Copy information relevant to the elaborated type.
3393 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3394 NewTL.setKeywordLoc(TL.getKeywordLoc());
3395 NewTL.setQualifierRange(TL.getQualifierRange());
3396 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00003397 TypeLoc NewTL(Result, TL.getOpaqueData());
3398 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00003399 }
3400 return Result;
3401}
3402
3403template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003404QualType
3405TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003406 ObjCInterfaceTypeLoc TL,
3407 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003408 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003409 TLB.pushFullCopy(TL);
3410 return TL.getType();
3411}
3412
3413template<typename Derived>
3414QualType
3415TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3416 ObjCObjectTypeLoc TL,
3417 QualType ObjectType) {
3418 // ObjCObjectType is never dependent.
3419 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003420 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003421}
Mike Stump1eb44332009-09-09 15:08:12 +00003422
3423template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003424QualType
3425TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003426 ObjCObjectPointerTypeLoc TL,
3427 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003428 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003429 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003430 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003431}
3432
Douglas Gregor577f75a2009-08-04 16:50:30 +00003433//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003434// Statement transformation
3435//===----------------------------------------------------------------------===//
3436template<typename Derived>
3437Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003438TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3439 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003440}
3441
3442template<typename Derived>
3443Sema::OwningStmtResult
3444TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3445 return getDerived().TransformCompoundStmt(S, false);
3446}
3447
3448template<typename Derived>
3449Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003450TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003451 bool IsStmtExpr) {
3452 bool SubStmtChanged = false;
3453 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3454 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3455 B != BEnd; ++B) {
3456 OwningStmtResult Result = getDerived().TransformStmt(*B);
3457 if (Result.isInvalid())
3458 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003459
Douglas Gregor43959a92009-08-20 07:17:43 +00003460 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3461 Statements.push_back(Result.takeAs<Stmt>());
3462 }
Mike Stump1eb44332009-09-09 15:08:12 +00003463
Douglas Gregor43959a92009-08-20 07:17:43 +00003464 if (!getDerived().AlwaysRebuild() &&
3465 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003466 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003467
3468 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3469 move_arg(Statements),
3470 S->getRBracLoc(),
3471 IsStmtExpr);
3472}
Mike Stump1eb44332009-09-09 15:08:12 +00003473
Douglas Gregor43959a92009-08-20 07:17:43 +00003474template<typename Derived>
3475Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003476TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman264c1f82009-11-19 03:14:00 +00003477 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3478 {
3479 // The case value expressions are not potentially evaluated.
3480 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003481
Eli Friedman264c1f82009-11-19 03:14:00 +00003482 // Transform the left-hand case value.
3483 LHS = getDerived().TransformExpr(S->getLHS());
3484 if (LHS.isInvalid())
3485 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003486
Eli Friedman264c1f82009-11-19 03:14:00 +00003487 // Transform the right-hand case value (for the GNU case-range extension).
3488 RHS = getDerived().TransformExpr(S->getRHS());
3489 if (RHS.isInvalid())
3490 return SemaRef.StmtError();
3491 }
Mike Stump1eb44332009-09-09 15:08:12 +00003492
Douglas Gregor43959a92009-08-20 07:17:43 +00003493 // Build the case statement.
3494 // Case statements are always rebuilt so that they will attached to their
3495 // transformed switch statement.
3496 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3497 move(LHS),
3498 S->getEllipsisLoc(),
3499 move(RHS),
3500 S->getColonLoc());
3501 if (Case.isInvalid())
3502 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003503
Douglas Gregor43959a92009-08-20 07:17:43 +00003504 // Transform the statement following the case
3505 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3506 if (SubStmt.isInvalid())
3507 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003508
Douglas Gregor43959a92009-08-20 07:17:43 +00003509 // Attach the body to the case statement
3510 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3511}
3512
3513template<typename Derived>
3514Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003515TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003516 // Transform the statement following the default case
3517 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3518 if (SubStmt.isInvalid())
3519 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003520
Douglas Gregor43959a92009-08-20 07:17:43 +00003521 // Default statements are always rebuilt
3522 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3523 move(SubStmt));
3524}
Mike Stump1eb44332009-09-09 15:08:12 +00003525
Douglas Gregor43959a92009-08-20 07:17:43 +00003526template<typename Derived>
3527Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003528TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003529 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3530 if (SubStmt.isInvalid())
3531 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003532
Douglas Gregor43959a92009-08-20 07:17:43 +00003533 // FIXME: Pass the real colon location in.
3534 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3535 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3536 move(SubStmt));
3537}
Mike Stump1eb44332009-09-09 15:08:12 +00003538
Douglas Gregor43959a92009-08-20 07:17:43 +00003539template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003540Sema::OwningStmtResult
3541TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003542 // Transform the condition
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003543 OwningExprResult Cond(SemaRef);
3544 VarDecl *ConditionVar = 0;
3545 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003546 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003547 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003548 getDerived().TransformDefinition(
3549 S->getConditionVariable()->getLocation(),
3550 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003551 if (!ConditionVar)
3552 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003553 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003554 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003555
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003556 if (Cond.isInvalid())
3557 return SemaRef.StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003558
3559 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003560 if (S->getCond()) {
3561 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3562 S->getIfLoc(),
3563 move(Cond));
3564 if (CondE.isInvalid())
3565 return getSema().StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003566
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003567 Cond = move(CondE);
3568 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003569 }
Sean Huntc3021132010-05-05 15:23:54 +00003570
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003571 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3572 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3573 return SemaRef.StmtError();
3574
Douglas Gregor43959a92009-08-20 07:17:43 +00003575 // Transform the "then" branch.
3576 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3577 if (Then.isInvalid())
3578 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003579
Douglas Gregor43959a92009-08-20 07:17:43 +00003580 // Transform the "else" branch.
3581 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3582 if (Else.isInvalid())
3583 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003584
Douglas Gregor43959a92009-08-20 07:17:43 +00003585 if (!getDerived().AlwaysRebuild() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003586 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003587 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003588 Then.get() == S->getThen() &&
3589 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003590 return SemaRef.Owned(S->Retain());
3591
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003592 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003593 move(Then),
Mike Stump1eb44332009-09-09 15:08:12 +00003594 S->getElseLoc(), move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +00003595}
3596
3597template<typename Derived>
3598Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003599TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003600 // Transform the condition.
Douglas Gregord3d53012009-11-24 17:07:59 +00003601 OwningExprResult Cond(SemaRef);
3602 VarDecl *ConditionVar = 0;
3603 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003604 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00003605 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003606 getDerived().TransformDefinition(
3607 S->getConditionVariable()->getLocation(),
3608 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003609 if (!ConditionVar)
3610 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003611 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003612 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003613
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003614 if (Cond.isInvalid())
3615 return SemaRef.StmtError();
3616 }
Mike Stump1eb44332009-09-09 15:08:12 +00003617
Douglas Gregor43959a92009-08-20 07:17:43 +00003618 // Rebuild the switch statement.
Douglas Gregor586596f2010-05-06 17:25:47 +00003619 OwningStmtResult Switch
3620 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond),
3621 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003622 if (Switch.isInvalid())
3623 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003624
Douglas Gregor43959a92009-08-20 07:17:43 +00003625 // Transform the body of the switch statement.
3626 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3627 if (Body.isInvalid())
3628 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003629
Douglas Gregor43959a92009-08-20 07:17:43 +00003630 // Complete the switch statement.
3631 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3632 move(Body));
3633}
Mike Stump1eb44332009-09-09 15:08:12 +00003634
Douglas Gregor43959a92009-08-20 07:17:43 +00003635template<typename Derived>
3636Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003637TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003638 // Transform the condition
Douglas Gregor5656e142009-11-24 21:15:44 +00003639 OwningExprResult Cond(SemaRef);
3640 VarDecl *ConditionVar = 0;
3641 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003642 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00003643 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003644 getDerived().TransformDefinition(
3645 S->getConditionVariable()->getLocation(),
3646 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003647 if (!ConditionVar)
3648 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003649 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003650 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003651
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003652 if (Cond.isInvalid())
3653 return SemaRef.StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003654
3655 if (S->getCond()) {
3656 // Convert the condition to a boolean value.
3657 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003658 S->getWhileLoc(),
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003659 move(Cond));
3660 if (CondE.isInvalid())
3661 return getSema().StmtError();
3662 Cond = move(CondE);
3663 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003664 }
Mike Stump1eb44332009-09-09 15:08:12 +00003665
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003666 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3667 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3668 return SemaRef.StmtError();
3669
Douglas Gregor43959a92009-08-20 07:17:43 +00003670 // Transform the body
3671 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3672 if (Body.isInvalid())
3673 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003674
Douglas Gregor43959a92009-08-20 07:17:43 +00003675 if (!getDerived().AlwaysRebuild() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003676 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003677 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003678 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003679 return SemaRef.Owned(S->Retain());
3680
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003681 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
Douglas Gregor586596f2010-05-06 17:25:47 +00003682 ConditionVar, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003683}
Mike Stump1eb44332009-09-09 15:08:12 +00003684
Douglas Gregor43959a92009-08-20 07:17:43 +00003685template<typename Derived>
3686Sema::OwningStmtResult
3687TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003688 // Transform the body
3689 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3690 if (Body.isInvalid())
3691 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003692
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003693 // Transform the condition
3694 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3695 if (Cond.isInvalid())
3696 return SemaRef.StmtError();
3697
Douglas Gregor43959a92009-08-20 07:17:43 +00003698 if (!getDerived().AlwaysRebuild() &&
3699 Cond.get() == S->getCond() &&
3700 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003701 return SemaRef.Owned(S->Retain());
3702
Douglas Gregor43959a92009-08-20 07:17:43 +00003703 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3704 /*FIXME:*/S->getWhileLoc(), move(Cond),
3705 S->getRParenLoc());
3706}
Mike Stump1eb44332009-09-09 15:08:12 +00003707
Douglas Gregor43959a92009-08-20 07:17:43 +00003708template<typename Derived>
3709Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003710TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003711 // Transform the initialization statement
3712 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3713 if (Init.isInvalid())
3714 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003715
Douglas Gregor43959a92009-08-20 07:17:43 +00003716 // Transform the condition
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003717 OwningExprResult Cond(SemaRef);
3718 VarDecl *ConditionVar = 0;
3719 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003720 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003721 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003722 getDerived().TransformDefinition(
3723 S->getConditionVariable()->getLocation(),
3724 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003725 if (!ConditionVar)
3726 return SemaRef.StmtError();
3727 } else {
3728 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003729
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003730 if (Cond.isInvalid())
3731 return SemaRef.StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003732
3733 if (S->getCond()) {
3734 // Convert the condition to a boolean value.
3735 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3736 S->getForLoc(),
3737 move(Cond));
3738 if (CondE.isInvalid())
3739 return getSema().StmtError();
3740
3741 Cond = move(CondE);
3742 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003743 }
Mike Stump1eb44332009-09-09 15:08:12 +00003744
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003745 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3746 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3747 return SemaRef.StmtError();
3748
Douglas Gregor43959a92009-08-20 07:17:43 +00003749 // Transform the increment
3750 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3751 if (Inc.isInvalid())
3752 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003753
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003754 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc));
3755 if (S->getInc() && !FullInc->get())
3756 return SemaRef.StmtError();
3757
Douglas Gregor43959a92009-08-20 07:17:43 +00003758 // Transform the body
3759 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3760 if (Body.isInvalid())
3761 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003762
Douglas Gregor43959a92009-08-20 07:17:43 +00003763 if (!getDerived().AlwaysRebuild() &&
3764 Init.get() == S->getInit() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003765 FullCond->get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003766 Inc.get() == S->getInc() &&
3767 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003768 return SemaRef.Owned(S->Retain());
3769
Douglas Gregor43959a92009-08-20 07:17:43 +00003770 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003771 move(Init), FullCond, ConditionVar,
3772 FullInc, S->getRParenLoc(), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003773}
3774
3775template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003776Sema::OwningStmtResult
3777TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003778 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003779 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003780 S->getLabel());
3781}
3782
3783template<typename Derived>
3784Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003785TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003786 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3787 if (Target.isInvalid())
3788 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003789
Douglas Gregor43959a92009-08-20 07:17:43 +00003790 if (!getDerived().AlwaysRebuild() &&
3791 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003792 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003793
3794 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3795 move(Target));
3796}
3797
3798template<typename Derived>
3799Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003800TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3801 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003802}
Mike Stump1eb44332009-09-09 15:08:12 +00003803
Douglas Gregor43959a92009-08-20 07:17:43 +00003804template<typename Derived>
3805Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003806TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3807 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003808}
Mike Stump1eb44332009-09-09 15:08:12 +00003809
Douglas Gregor43959a92009-08-20 07:17:43 +00003810template<typename Derived>
3811Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003812TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003813 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3814 if (Result.isInvalid())
3815 return SemaRef.StmtError();
3816
Mike Stump1eb44332009-09-09 15:08:12 +00003817 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003818 // to tell whether the return type of the function has changed.
3819 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3820}
Mike Stump1eb44332009-09-09 15:08:12 +00003821
Douglas Gregor43959a92009-08-20 07:17:43 +00003822template<typename Derived>
3823Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003824TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003825 bool DeclChanged = false;
3826 llvm::SmallVector<Decl *, 4> Decls;
3827 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3828 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003829 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3830 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003831 if (!Transformed)
3832 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003833
Douglas Gregor43959a92009-08-20 07:17:43 +00003834 if (Transformed != *D)
3835 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003836
Douglas Gregor43959a92009-08-20 07:17:43 +00003837 Decls.push_back(Transformed);
3838 }
Mike Stump1eb44332009-09-09 15:08:12 +00003839
Douglas Gregor43959a92009-08-20 07:17:43 +00003840 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003841 return SemaRef.Owned(S->Retain());
3842
3843 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003844 S->getStartLoc(), S->getEndLoc());
3845}
Mike Stump1eb44332009-09-09 15:08:12 +00003846
Douglas Gregor43959a92009-08-20 07:17:43 +00003847template<typename Derived>
3848Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003849TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003850 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003851 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003852}
3853
3854template<typename Derived>
3855Sema::OwningStmtResult
3856TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00003857
Anders Carlsson703e3942010-01-24 05:50:09 +00003858 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3859 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003860 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003861
Anders Carlsson703e3942010-01-24 05:50:09 +00003862 OwningExprResult AsmString(SemaRef);
3863 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3864
3865 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00003866
Anders Carlsson703e3942010-01-24 05:50:09 +00003867 // Go through the outputs.
3868 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003869 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003870
Anders Carlsson703e3942010-01-24 05:50:09 +00003871 // No need to transform the constraint literal.
3872 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003873
Anders Carlsson703e3942010-01-24 05:50:09 +00003874 // Transform the output expr.
3875 Expr *OutputExpr = S->getOutputExpr(I);
3876 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3877 if (Result.isInvalid())
3878 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003879
Anders Carlsson703e3942010-01-24 05:50:09 +00003880 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003881
Anders Carlsson703e3942010-01-24 05:50:09 +00003882 Exprs.push_back(Result.takeAs<Expr>());
3883 }
Sean Huntc3021132010-05-05 15:23:54 +00003884
Anders Carlsson703e3942010-01-24 05:50:09 +00003885 // Go through the inputs.
3886 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003887 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003888
Anders Carlsson703e3942010-01-24 05:50:09 +00003889 // No need to transform the constraint literal.
3890 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003891
Anders Carlsson703e3942010-01-24 05:50:09 +00003892 // Transform the input expr.
3893 Expr *InputExpr = S->getInputExpr(I);
3894 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3895 if (Result.isInvalid())
3896 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003897
Anders Carlsson703e3942010-01-24 05:50:09 +00003898 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003899
Anders Carlsson703e3942010-01-24 05:50:09 +00003900 Exprs.push_back(Result.takeAs<Expr>());
3901 }
Sean Huntc3021132010-05-05 15:23:54 +00003902
Anders Carlsson703e3942010-01-24 05:50:09 +00003903 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3904 return SemaRef.Owned(S->Retain());
3905
3906 // Go through the clobbers.
3907 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3908 Clobbers.push_back(S->getClobber(I)->Retain());
3909
3910 // No need to transform the asm string literal.
3911 AsmString = SemaRef.Owned(S->getAsmString());
3912
3913 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3914 S->isSimple(),
3915 S->isVolatile(),
3916 S->getNumOutputs(),
3917 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003918 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003919 move_arg(Constraints),
3920 move_arg(Exprs),
3921 move(AsmString),
3922 move_arg(Clobbers),
3923 S->getRParenLoc(),
3924 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003925}
3926
3927
3928template<typename Derived>
3929Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003930TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003931 // Transform the body of the @try.
3932 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3933 if (TryBody.isInvalid())
3934 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003935
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003936 // Transform the @catch statements (if present).
3937 bool AnyCatchChanged = false;
3938 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3939 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3940 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003941 if (Catch.isInvalid())
3942 return SemaRef.StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003943 if (Catch.get() != S->getCatchStmt(I))
3944 AnyCatchChanged = true;
3945 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003946 }
Sean Huntc3021132010-05-05 15:23:54 +00003947
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003948 // Transform the @finally statement (if present).
3949 OwningStmtResult Finally(SemaRef);
3950 if (S->getFinallyStmt()) {
3951 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3952 if (Finally.isInvalid())
3953 return SemaRef.StmtError();
3954 }
3955
3956 // If nothing changed, just retain this statement.
3957 if (!getDerived().AlwaysRebuild() &&
3958 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003959 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003960 Finally.get() == S->getFinallyStmt())
3961 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003962
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003963 // Build a new statement.
3964 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003965 move_arg(CatchStmts), move(Finally));
Douglas Gregor43959a92009-08-20 07:17:43 +00003966}
Mike Stump1eb44332009-09-09 15:08:12 +00003967
Douglas Gregor43959a92009-08-20 07:17:43 +00003968template<typename Derived>
3969Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003970TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00003971 // Transform the @catch parameter, if there is one.
3972 VarDecl *Var = 0;
3973 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3974 TypeSourceInfo *TSInfo = 0;
3975 if (FromVar->getTypeSourceInfo()) {
3976 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3977 if (!TSInfo)
3978 return SemaRef.StmtError();
3979 }
Sean Huntc3021132010-05-05 15:23:54 +00003980
Douglas Gregorbe270a02010-04-26 17:57:08 +00003981 QualType T;
3982 if (TSInfo)
3983 T = TSInfo->getType();
3984 else {
3985 T = getDerived().TransformType(FromVar->getType());
3986 if (T.isNull())
Sean Huntc3021132010-05-05 15:23:54 +00003987 return SemaRef.StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00003988 }
Sean Huntc3021132010-05-05 15:23:54 +00003989
Douglas Gregorbe270a02010-04-26 17:57:08 +00003990 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3991 if (!Var)
3992 return SemaRef.StmtError();
3993 }
Sean Huntc3021132010-05-05 15:23:54 +00003994
Douglas Gregorbe270a02010-04-26 17:57:08 +00003995 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3996 if (Body.isInvalid())
3997 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003998
3999 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004000 S->getRParenLoc(),
4001 Var, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004002}
Mike Stump1eb44332009-09-09 15:08:12 +00004003
Douglas Gregor43959a92009-08-20 07:17:43 +00004004template<typename Derived>
4005Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004006TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004007 // Transform the body.
4008 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
4009 if (Body.isInvalid())
4010 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004011
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004012 // If nothing changed, just retain this statement.
4013 if (!getDerived().AlwaysRebuild() &&
4014 Body.get() == S->getFinallyBody())
4015 return SemaRef.Owned(S->Retain());
4016
4017 // Build a new statement.
4018 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
4019 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004020}
Mike Stump1eb44332009-09-09 15:08:12 +00004021
Douglas Gregor43959a92009-08-20 07:17:43 +00004022template<typename Derived>
4023Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004024TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregord1377b22010-04-22 21:44:01 +00004025 OwningExprResult Operand(SemaRef);
4026 if (S->getThrowExpr()) {
4027 Operand = getDerived().TransformExpr(S->getThrowExpr());
4028 if (Operand.isInvalid())
4029 return getSema().StmtError();
4030 }
Sean Huntc3021132010-05-05 15:23:54 +00004031
Douglas Gregord1377b22010-04-22 21:44:01 +00004032 if (!getDerived().AlwaysRebuild() &&
4033 Operand.get() == S->getThrowExpr())
4034 return getSema().Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004035
Douglas Gregord1377b22010-04-22 21:44:01 +00004036 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregor43959a92009-08-20 07:17:43 +00004037}
Mike Stump1eb44332009-09-09 15:08:12 +00004038
Douglas Gregor43959a92009-08-20 07:17:43 +00004039template<typename Derived>
4040Sema::OwningStmtResult
4041TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004042 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004043 // Transform the object we are locking.
4044 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
4045 if (Object.isInvalid())
4046 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004047
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004048 // Transform the body.
4049 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
4050 if (Body.isInvalid())
4051 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004052
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004053 // If nothing change, just retain the current statement.
4054 if (!getDerived().AlwaysRebuild() &&
4055 Object.get() == S->getSynchExpr() &&
4056 Body.get() == S->getSynchBody())
4057 return SemaRef.Owned(S->Retain());
4058
4059 // Build a new statement.
4060 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
4061 move(Object), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004062}
4063
4064template<typename Derived>
4065Sema::OwningStmtResult
4066TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004067 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004068 // Transform the element statement.
4069 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
4070 if (Element.isInvalid())
4071 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004072
Douglas Gregorc3203e72010-04-22 23:10:45 +00004073 // Transform the collection expression.
4074 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
4075 if (Collection.isInvalid())
4076 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004077
Douglas Gregorc3203e72010-04-22 23:10:45 +00004078 // Transform the body.
4079 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
4080 if (Body.isInvalid())
4081 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004082
Douglas Gregorc3203e72010-04-22 23:10:45 +00004083 // If nothing changed, just retain this statement.
4084 if (!getDerived().AlwaysRebuild() &&
4085 Element.get() == S->getElement() &&
4086 Collection.get() == S->getCollection() &&
4087 Body.get() == S->getBody())
4088 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004089
Douglas Gregorc3203e72010-04-22 23:10:45 +00004090 // Build a new statement.
4091 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4092 /*FIXME:*/S->getForLoc(),
4093 move(Element),
4094 move(Collection),
4095 S->getRParenLoc(),
4096 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004097}
4098
4099
4100template<typename Derived>
4101Sema::OwningStmtResult
4102TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4103 // Transform the exception declaration, if any.
4104 VarDecl *Var = 0;
4105 if (S->getExceptionDecl()) {
4106 VarDecl *ExceptionDecl = S->getExceptionDecl();
4107 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4108 ExceptionDecl->getDeclName());
4109
4110 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4111 if (T.isNull())
4112 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004113
Douglas Gregor43959a92009-08-20 07:17:43 +00004114 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4115 T,
John McCalla93c9342009-12-07 02:54:59 +00004116 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004117 ExceptionDecl->getIdentifier(),
4118 ExceptionDecl->getLocation(),
4119 /*FIXME: Inaccurate*/
4120 SourceRange(ExceptionDecl->getLocation()));
Douglas Gregorff331c12010-07-25 18:17:45 +00004121 if (!Var || Var->isInvalidDecl())
Douglas Gregor43959a92009-08-20 07:17:43 +00004122 return SemaRef.StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004123 }
Mike Stump1eb44332009-09-09 15:08:12 +00004124
Douglas Gregor43959a92009-08-20 07:17:43 +00004125 // Transform the actual exception handler.
4126 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00004127 if (Handler.isInvalid())
Douglas Gregor43959a92009-08-20 07:17:43 +00004128 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004129
Douglas Gregor43959a92009-08-20 07:17:43 +00004130 if (!getDerived().AlwaysRebuild() &&
4131 !Var &&
4132 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00004133 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004134
4135 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4136 Var,
4137 move(Handler));
4138}
Mike Stump1eb44332009-09-09 15:08:12 +00004139
Douglas Gregor43959a92009-08-20 07:17:43 +00004140template<typename Derived>
4141Sema::OwningStmtResult
4142TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4143 // Transform the try block itself.
Mike Stump1eb44332009-09-09 15:08:12 +00004144 OwningStmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004145 = getDerived().TransformCompoundStmt(S->getTryBlock());
4146 if (TryBlock.isInvalid())
4147 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004148
Douglas Gregor43959a92009-08-20 07:17:43 +00004149 // Transform the handlers.
4150 bool HandlerChanged = false;
4151 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4152 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump1eb44332009-09-09 15:08:12 +00004153 OwningStmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004154 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4155 if (Handler.isInvalid())
4156 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004157
Douglas Gregor43959a92009-08-20 07:17:43 +00004158 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4159 Handlers.push_back(Handler.takeAs<Stmt>());
4160 }
Mike Stump1eb44332009-09-09 15:08:12 +00004161
Douglas Gregor43959a92009-08-20 07:17:43 +00004162 if (!getDerived().AlwaysRebuild() &&
4163 TryBlock.get() == S->getTryBlock() &&
4164 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004165 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004166
4167 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump1eb44332009-09-09 15:08:12 +00004168 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004169}
Mike Stump1eb44332009-09-09 15:08:12 +00004170
Douglas Gregor43959a92009-08-20 07:17:43 +00004171//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004172// Expression transformation
4173//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004174template<typename Derived>
4175Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004176TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004177 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004178}
Mike Stump1eb44332009-09-09 15:08:12 +00004179
4180template<typename Derived>
4181Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004182TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004183 NestedNameSpecifier *Qualifier = 0;
4184 if (E->getQualifier()) {
4185 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004186 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004187 if (!Qualifier)
4188 return SemaRef.ExprError();
4189 }
John McCalldbd872f2009-12-08 09:08:17 +00004190
4191 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004192 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4193 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004194 if (!ND)
4195 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004196
Sean Huntc3021132010-05-05 15:23:54 +00004197 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004198 Qualifier == E->getQualifier() &&
4199 ND == E->getDecl() &&
John McCalldbd872f2009-12-08 09:08:17 +00004200 !E->hasExplicitTemplateArgumentList()) {
4201
4202 // Mark it referenced in the new context regardless.
4203 // FIXME: this is a bit instantiation-specific.
4204 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4205
Mike Stump1eb44332009-09-09 15:08:12 +00004206 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004207 }
John McCalldbd872f2009-12-08 09:08:17 +00004208
4209 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4210 if (E->hasExplicitTemplateArgumentList()) {
4211 TemplateArgs = &TransArgs;
4212 TransArgs.setLAngleLoc(E->getLAngleLoc());
4213 TransArgs.setRAngleLoc(E->getRAngleLoc());
4214 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4215 TemplateArgumentLoc Loc;
4216 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4217 return SemaRef.ExprError();
4218 TransArgs.addArgument(Loc);
4219 }
4220 }
4221
Douglas Gregora2813ce2009-10-23 18:54:35 +00004222 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCalldbd872f2009-12-08 09:08:17 +00004223 ND, E->getLocation(), TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004224}
Mike Stump1eb44332009-09-09 15:08:12 +00004225
Douglas Gregorb98b1992009-08-11 05:31:07 +00004226template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004227Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004228TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004229 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004230}
Mike Stump1eb44332009-09-09 15:08:12 +00004231
Douglas Gregorb98b1992009-08-11 05:31:07 +00004232template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004233Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004234TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004235 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004236}
Mike Stump1eb44332009-09-09 15:08:12 +00004237
Douglas Gregorb98b1992009-08-11 05:31:07 +00004238template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004239Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004240TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004241 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004242}
Mike Stump1eb44332009-09-09 15:08:12 +00004243
Douglas Gregorb98b1992009-08-11 05:31:07 +00004244template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004245Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004246TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004247 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004248}
Mike Stump1eb44332009-09-09 15:08:12 +00004249
Douglas Gregorb98b1992009-08-11 05:31:07 +00004250template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004251Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004252TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004253 return SemaRef.Owned(E->Retain());
4254}
4255
4256template<typename Derived>
4257Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004258TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004259 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4260 if (SubExpr.isInvalid())
4261 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004262
Douglas Gregorb98b1992009-08-11 05:31:07 +00004263 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004264 return SemaRef.Owned(E->Retain());
4265
4266 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004267 E->getRParen());
4268}
4269
Mike Stump1eb44332009-09-09 15:08:12 +00004270template<typename Derived>
4271Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004272TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4273 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004274 if (SubExpr.isInvalid())
4275 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004276
Douglas Gregorb98b1992009-08-11 05:31:07 +00004277 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004278 return SemaRef.Owned(E->Retain());
4279
Douglas Gregorb98b1992009-08-11 05:31:07 +00004280 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4281 E->getOpcode(),
4282 move(SubExpr));
4283}
Mike Stump1eb44332009-09-09 15:08:12 +00004284
Douglas Gregorb98b1992009-08-11 05:31:07 +00004285template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004286Sema::OwningExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004287TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4288 // Transform the type.
4289 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4290 if (!Type)
4291 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004292
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004293 // Transform all of the components into components similar to what the
4294 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004295 // FIXME: It would be slightly more efficient in the non-dependent case to
4296 // just map FieldDecls, rather than requiring the rebuilder to look for
4297 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004298 // template code that we don't care.
4299 bool ExprChanged = false;
4300 typedef Action::OffsetOfComponent Component;
4301 typedef OffsetOfExpr::OffsetOfNode Node;
4302 llvm::SmallVector<Component, 4> Components;
4303 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4304 const Node &ON = E->getComponent(I);
4305 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004306 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004307 Comp.LocStart = ON.getRange().getBegin();
4308 Comp.LocEnd = ON.getRange().getEnd();
4309 switch (ON.getKind()) {
4310 case Node::Array: {
4311 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4312 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4313 if (Index.isInvalid())
4314 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004315
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004316 ExprChanged = ExprChanged || Index.get() != FromIndex;
4317 Comp.isBrackets = true;
4318 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4319 break;
4320 }
Sean Huntc3021132010-05-05 15:23:54 +00004321
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004322 case Node::Field:
4323 case Node::Identifier:
4324 Comp.isBrackets = false;
4325 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004326 if (!Comp.U.IdentInfo)
4327 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004328
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004329 break;
Sean Huntc3021132010-05-05 15:23:54 +00004330
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004331 case Node::Base:
4332 // Will be recomputed during the rebuild.
4333 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004334 }
Sean Huntc3021132010-05-05 15:23:54 +00004335
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004336 Components.push_back(Comp);
4337 }
Sean Huntc3021132010-05-05 15:23:54 +00004338
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004339 // If nothing changed, retain the existing expression.
4340 if (!getDerived().AlwaysRebuild() &&
4341 Type == E->getTypeSourceInfo() &&
4342 !ExprChanged)
4343 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004344
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004345 // Build a new offsetof expression.
4346 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4347 Components.data(), Components.size(),
4348 E->getRParenLoc());
4349}
4350
4351template<typename Derived>
4352Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004353TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004354 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004355 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004356
John McCalla93c9342009-12-07 02:54:59 +00004357 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004358 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004359 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004360
John McCall5ab75172009-11-04 07:28:41 +00004361 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004362 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004363
John McCall5ab75172009-11-04 07:28:41 +00004364 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004365 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004366 E->getSourceRange());
4367 }
Mike Stump1eb44332009-09-09 15:08:12 +00004368
Douglas Gregorb98b1992009-08-11 05:31:07 +00004369 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00004370 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004371 // C++0x [expr.sizeof]p1:
4372 // The operand is either an expression, which is an unevaluated operand
4373 // [...]
4374 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004375
Douglas Gregorb98b1992009-08-11 05:31:07 +00004376 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4377 if (SubExpr.isInvalid())
4378 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004379
Douglas Gregorb98b1992009-08-11 05:31:07 +00004380 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4381 return SemaRef.Owned(E->Retain());
4382 }
Mike Stump1eb44332009-09-09 15:08:12 +00004383
Douglas Gregorb98b1992009-08-11 05:31:07 +00004384 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4385 E->isSizeOf(),
4386 E->getSourceRange());
4387}
Mike Stump1eb44332009-09-09 15:08:12 +00004388
Douglas Gregorb98b1992009-08-11 05:31:07 +00004389template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004390Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004391TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004392 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4393 if (LHS.isInvalid())
4394 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004395
Douglas Gregorb98b1992009-08-11 05:31:07 +00004396 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4397 if (RHS.isInvalid())
4398 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004399
4400
Douglas Gregorb98b1992009-08-11 05:31:07 +00004401 if (!getDerived().AlwaysRebuild() &&
4402 LHS.get() == E->getLHS() &&
4403 RHS.get() == E->getRHS())
4404 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004405
Douglas Gregorb98b1992009-08-11 05:31:07 +00004406 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4407 /*FIXME:*/E->getLHS()->getLocStart(),
4408 move(RHS),
4409 E->getRBracketLoc());
4410}
Mike Stump1eb44332009-09-09 15:08:12 +00004411
4412template<typename Derived>
4413Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004414TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004415 // Transform the callee.
4416 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4417 if (Callee.isInvalid())
4418 return SemaRef.ExprError();
4419
4420 // Transform arguments.
4421 bool ArgChanged = false;
4422 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4423 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4424 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4425 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4426 if (Arg.isInvalid())
4427 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004428
Douglas Gregorb98b1992009-08-11 05:31:07 +00004429 // FIXME: Wrong source location information for the ','.
4430 FakeCommaLocs.push_back(
4431 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00004432
4433 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004434 Args.push_back(Arg.takeAs<Expr>());
4435 }
Mike Stump1eb44332009-09-09 15:08:12 +00004436
Douglas Gregorb98b1992009-08-11 05:31:07 +00004437 if (!getDerived().AlwaysRebuild() &&
4438 Callee.get() == E->getCallee() &&
4439 !ArgChanged)
4440 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004441
Douglas Gregorb98b1992009-08-11 05:31:07 +00004442 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004443 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004444 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4445 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4446 move_arg(Args),
4447 FakeCommaLocs.data(),
4448 E->getRParenLoc());
4449}
Mike Stump1eb44332009-09-09 15:08:12 +00004450
4451template<typename Derived>
4452Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004453TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004454 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4455 if (Base.isInvalid())
4456 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004457
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004458 NestedNameSpecifier *Qualifier = 0;
4459 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004460 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004461 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004462 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004463 if (Qualifier == 0)
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004464 return SemaRef.ExprError();
4465 }
Mike Stump1eb44332009-09-09 15:08:12 +00004466
Eli Friedmanf595cc42009-12-04 06:40:45 +00004467 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004468 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4469 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004470 if (!Member)
4471 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004472
John McCall6bb80172010-03-30 21:47:33 +00004473 NamedDecl *FoundDecl = E->getFoundDecl();
4474 if (FoundDecl == E->getMemberDecl()) {
4475 FoundDecl = Member;
4476 } else {
4477 FoundDecl = cast_or_null<NamedDecl>(
4478 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4479 if (!FoundDecl)
4480 return SemaRef.ExprError();
4481 }
4482
Douglas Gregorb98b1992009-08-11 05:31:07 +00004483 if (!getDerived().AlwaysRebuild() &&
4484 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004485 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004486 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004487 FoundDecl == E->getFoundDecl() &&
Anders Carlsson1f240322009-12-22 05:24:09 +00004488 !E->hasExplicitTemplateArgumentList()) {
Sean Huntc3021132010-05-05 15:23:54 +00004489
Anders Carlsson1f240322009-12-22 05:24:09 +00004490 // Mark it referenced in the new context regardless.
4491 // FIXME: this is a bit instantiation-specific.
4492 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00004493 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00004494 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004495
John McCalld5532b62009-11-23 01:53:49 +00004496 TemplateArgumentListInfo TransArgs;
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004497 if (E->hasExplicitTemplateArgumentList()) {
John McCalld5532b62009-11-23 01:53:49 +00004498 TransArgs.setLAngleLoc(E->getLAngleLoc());
4499 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004500 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004501 TemplateArgumentLoc Loc;
4502 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004503 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004504 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004505 }
4506 }
Sean Huntc3021132010-05-05 15:23:54 +00004507
Douglas Gregorb98b1992009-08-11 05:31:07 +00004508 // FIXME: Bogus source location for the operator
4509 SourceLocation FakeOperatorLoc
4510 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4511
John McCallc2233c52010-01-15 08:34:02 +00004512 // FIXME: to do this check properly, we will need to preserve the
4513 // first-qualifier-in-scope here, just in case we had a dependent
4514 // base (and therefore couldn't do the check) and a
4515 // nested-name-qualifier (and therefore could do the lookup).
4516 NamedDecl *FirstQualifierInScope = 0;
4517
Douglas Gregorb98b1992009-08-11 05:31:07 +00004518 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4519 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004520 Qualifier,
4521 E->getQualifierRange(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004522 E->getMemberLoc(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004523 Member,
John McCall6bb80172010-03-30 21:47:33 +00004524 FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00004525 (E->hasExplicitTemplateArgumentList()
4526 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004527 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004528}
Mike Stump1eb44332009-09-09 15:08:12 +00004529
Douglas Gregorb98b1992009-08-11 05:31:07 +00004530template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00004531Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004532TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004533 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4534 if (LHS.isInvalid())
4535 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004536
Douglas Gregorb98b1992009-08-11 05:31:07 +00004537 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4538 if (RHS.isInvalid())
4539 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004540
Douglas Gregorb98b1992009-08-11 05:31:07 +00004541 if (!getDerived().AlwaysRebuild() &&
4542 LHS.get() == E->getLHS() &&
4543 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004544 return SemaRef.Owned(E->Retain());
4545
Douglas Gregorb98b1992009-08-11 05:31:07 +00004546 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4547 move(LHS), move(RHS));
4548}
4549
Mike Stump1eb44332009-09-09 15:08:12 +00004550template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00004551Sema::OwningExprResult
4552TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004553 CompoundAssignOperator *E) {
4554 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004555}
Mike Stump1eb44332009-09-09 15:08:12 +00004556
Douglas Gregorb98b1992009-08-11 05:31:07 +00004557template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004558Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004559TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004560 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4561 if (Cond.isInvalid())
4562 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004563
Douglas Gregorb98b1992009-08-11 05:31:07 +00004564 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4565 if (LHS.isInvalid())
4566 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004567
Douglas Gregorb98b1992009-08-11 05:31:07 +00004568 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4569 if (RHS.isInvalid())
4570 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004571
Douglas Gregorb98b1992009-08-11 05:31:07 +00004572 if (!getDerived().AlwaysRebuild() &&
4573 Cond.get() == E->getCond() &&
4574 LHS.get() == E->getLHS() &&
4575 RHS.get() == E->getRHS())
4576 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004577
4578 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004579 E->getQuestionLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004580 move(LHS),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004581 E->getColonLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004582 move(RHS));
4583}
Mike Stump1eb44332009-09-09 15:08:12 +00004584
4585template<typename Derived>
4586Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004587TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004588 // Implicit casts are eliminated during transformation, since they
4589 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004590 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004591}
Mike Stump1eb44332009-09-09 15:08:12 +00004592
Douglas Gregorb98b1992009-08-11 05:31:07 +00004593template<typename Derived>
4594Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004595TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004596 TypeSourceInfo *OldT;
4597 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004598 {
4599 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004600 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004601 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4602 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004603
John McCall9d125032010-01-15 18:39:57 +00004604 OldT = E->getTypeInfoAsWritten();
4605 NewT = getDerived().TransformType(OldT);
4606 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004607 return SemaRef.ExprError();
4608 }
Mike Stump1eb44332009-09-09 15:08:12 +00004609
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004610 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004611 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004612 if (SubExpr.isInvalid())
4613 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004614
Douglas Gregorb98b1992009-08-11 05:31:07 +00004615 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004616 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004617 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004618 return SemaRef.Owned(E->Retain());
4619
John McCall9d125032010-01-15 18:39:57 +00004620 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4621 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004622 E->getRParenLoc(),
4623 move(SubExpr));
4624}
Mike Stump1eb44332009-09-09 15:08:12 +00004625
Douglas Gregorb98b1992009-08-11 05:31:07 +00004626template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004627Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004628TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004629 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4630 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4631 if (!NewT)
4632 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004633
Douglas Gregorb98b1992009-08-11 05:31:07 +00004634 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4635 if (Init.isInvalid())
4636 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004637
Douglas Gregorb98b1992009-08-11 05:31:07 +00004638 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004639 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004640 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00004641 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004642
John McCall1d7d8d62010-01-19 22:33:45 +00004643 // Note: the expression type doesn't necessarily match the
4644 // type-as-written, but that's okay, because it should always be
4645 // derivable from the initializer.
4646
John McCall42f56b52010-01-18 19:35:47 +00004647 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004648 /*FIXME:*/E->getInitializer()->getLocEnd(),
4649 move(Init));
4650}
Mike Stump1eb44332009-09-09 15:08:12 +00004651
Douglas Gregorb98b1992009-08-11 05:31:07 +00004652template<typename Derived>
4653Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004654TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004655 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4656 if (Base.isInvalid())
4657 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004658
Douglas Gregorb98b1992009-08-11 05:31:07 +00004659 if (!getDerived().AlwaysRebuild() &&
4660 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00004661 return SemaRef.Owned(E->Retain());
4662
Douglas Gregorb98b1992009-08-11 05:31:07 +00004663 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004664 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004665 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4666 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4667 E->getAccessorLoc(),
4668 E->getAccessor());
4669}
Mike Stump1eb44332009-09-09 15:08:12 +00004670
Douglas Gregorb98b1992009-08-11 05:31:07 +00004671template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004672Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004673TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004674 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004675
Douglas Gregorb98b1992009-08-11 05:31:07 +00004676 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4677 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4678 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4679 if (Init.isInvalid())
4680 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004681
Douglas Gregorb98b1992009-08-11 05:31:07 +00004682 InitChanged = InitChanged || Init.get() != E->getInit(I);
4683 Inits.push_back(Init.takeAs<Expr>());
4684 }
Mike Stump1eb44332009-09-09 15:08:12 +00004685
Douglas Gregorb98b1992009-08-11 05:31:07 +00004686 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004687 return SemaRef.Owned(E->Retain());
4688
Douglas Gregorb98b1992009-08-11 05:31:07 +00004689 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004690 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004691}
Mike Stump1eb44332009-09-09 15:08:12 +00004692
Douglas Gregorb98b1992009-08-11 05:31:07 +00004693template<typename Derived>
4694Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004695TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004696 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004697
Douglas Gregor43959a92009-08-20 07:17:43 +00004698 // transform the initializer value
Douglas Gregorb98b1992009-08-11 05:31:07 +00004699 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4700 if (Init.isInvalid())
4701 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004702
Douglas Gregor43959a92009-08-20 07:17:43 +00004703 // transform the designators.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004704 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4705 bool ExprChanged = false;
4706 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4707 DEnd = E->designators_end();
4708 D != DEnd; ++D) {
4709 if (D->isFieldDesignator()) {
4710 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4711 D->getDotLoc(),
4712 D->getFieldLoc()));
4713 continue;
4714 }
Mike Stump1eb44332009-09-09 15:08:12 +00004715
Douglas Gregorb98b1992009-08-11 05:31:07 +00004716 if (D->isArrayDesignator()) {
4717 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4718 if (Index.isInvalid())
4719 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004720
4721 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004722 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004723
Douglas Gregorb98b1992009-08-11 05:31:07 +00004724 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4725 ArrayExprs.push_back(Index.release());
4726 continue;
4727 }
Mike Stump1eb44332009-09-09 15:08:12 +00004728
Douglas Gregorb98b1992009-08-11 05:31:07 +00004729 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump1eb44332009-09-09 15:08:12 +00004730 OwningExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004731 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4732 if (Start.isInvalid())
4733 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004734
Douglas Gregorb98b1992009-08-11 05:31:07 +00004735 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4736 if (End.isInvalid())
4737 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004738
4739 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004740 End.get(),
4741 D->getLBracketLoc(),
4742 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004743
Douglas Gregorb98b1992009-08-11 05:31:07 +00004744 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4745 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004746
Douglas Gregorb98b1992009-08-11 05:31:07 +00004747 ArrayExprs.push_back(Start.release());
4748 ArrayExprs.push_back(End.release());
4749 }
Mike Stump1eb44332009-09-09 15:08:12 +00004750
Douglas Gregorb98b1992009-08-11 05:31:07 +00004751 if (!getDerived().AlwaysRebuild() &&
4752 Init.get() == E->getInit() &&
4753 !ExprChanged)
4754 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004755
Douglas Gregorb98b1992009-08-11 05:31:07 +00004756 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4757 E->getEqualOrColonLoc(),
4758 E->usesGNUSyntax(), move(Init));
4759}
Mike Stump1eb44332009-09-09 15:08:12 +00004760
Douglas Gregorb98b1992009-08-11 05:31:07 +00004761template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004762Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004763TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004764 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004765 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00004766
Douglas Gregor5557b252009-10-28 00:29:27 +00004767 // FIXME: Will we ever have proper type location here? Will we actually
4768 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004769 QualType T = getDerived().TransformType(E->getType());
4770 if (T.isNull())
4771 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004772
Douglas Gregorb98b1992009-08-11 05:31:07 +00004773 if (!getDerived().AlwaysRebuild() &&
4774 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004775 return SemaRef.Owned(E->Retain());
4776
Douglas Gregorb98b1992009-08-11 05:31:07 +00004777 return getDerived().RebuildImplicitValueInitExpr(T);
4778}
Mike Stump1eb44332009-09-09 15:08:12 +00004779
Douglas Gregorb98b1992009-08-11 05:31:07 +00004780template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004781Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004782TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004783 // FIXME: Do we want the type as written?
4784 QualType T;
Mike Stump1eb44332009-09-09 15:08:12 +00004785
Douglas Gregorb98b1992009-08-11 05:31:07 +00004786 {
4787 // FIXME: Source location isn't quite accurate.
4788 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4789 T = getDerived().TransformType(E->getType());
4790 if (T.isNull())
4791 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() &&
4799 T == E->getType() &&
4800 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),
4804 T, E->getRParenLoc());
4805}
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