blob: 9b8031b7fdf355d314180e7f373a2a5835223f04 [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,
445 bool IsAltiVec, bool IsPixel);
Mike Stump1eb44332009-09-09 15:08:12 +0000446
Douglas Gregor577f75a2009-08-04 16:50:30 +0000447 /// \brief Build a new extended vector type given the element type and
448 /// number of elements.
449 ///
450 /// By default, performs semantic analysis when building the vector type.
451 /// Subclasses may override this routine to provide different behavior.
452 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
453 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000454
455 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000456 /// given the element type and number of elements.
457 ///
458 /// By default, performs semantic analysis when building the vector type.
459 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000460 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000461 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000462 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000463
Douglas Gregor577f75a2009-08-04 16:50:30 +0000464 /// \brief Build a new function type.
465 ///
466 /// By default, performs semantic analysis when building the function type.
467 /// Subclasses may override this routine to provide different behavior.
468 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000469 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000470 unsigned NumParamTypes,
471 bool Variadic, unsigned Quals);
Mike Stump1eb44332009-09-09 15:08:12 +0000472
John McCalla2becad2009-10-21 00:40:46 +0000473 /// \brief Build a new unprototyped function type.
474 QualType RebuildFunctionNoProtoType(QualType ResultType);
475
John McCalled976492009-12-04 22:46:56 +0000476 /// \brief Rebuild an unresolved typename type, given the decl that
477 /// the UnresolvedUsingTypenameDecl was transformed to.
478 QualType RebuildUnresolvedUsingType(Decl *D);
479
Douglas Gregor577f75a2009-08-04 16:50:30 +0000480 /// \brief Build a new typedef type.
481 QualType RebuildTypedefType(TypedefDecl *Typedef) {
482 return SemaRef.Context.getTypeDeclType(Typedef);
483 }
484
485 /// \brief Build a new class/struct/union type.
486 QualType RebuildRecordType(RecordDecl *Record) {
487 return SemaRef.Context.getTypeDeclType(Record);
488 }
489
490 /// \brief Build a new Enum type.
491 QualType RebuildEnumType(EnumDecl *Enum) {
492 return SemaRef.Context.getTypeDeclType(Enum);
493 }
John McCall7da24312009-09-05 00:15:47 +0000494
Mike Stump1eb44332009-09-09 15:08:12 +0000495 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000496 ///
497 /// By default, performs semantic analysis when building the typeof type.
498 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000499 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000500
Mike Stump1eb44332009-09-09 15:08:12 +0000501 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000502 ///
503 /// By default, builds a new TypeOfType with the given underlying type.
504 QualType RebuildTypeOfType(QualType Underlying);
505
Mike Stump1eb44332009-09-09 15:08:12 +0000506 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000507 ///
508 /// By default, performs semantic analysis when building the decltype type.
509 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000510 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump1eb44332009-09-09 15:08:12 +0000511
Douglas Gregor577f75a2009-08-04 16:50:30 +0000512 /// \brief Build a new template specialization type.
513 ///
514 /// By default, performs semantic analysis when building the template
515 /// specialization type. Subclasses may override this routine to provide
516 /// different behavior.
517 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000518 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000519 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000520
Douglas Gregor577f75a2009-08-04 16:50:30 +0000521 /// \brief Build a new qualified name type.
522 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000523 /// By default, builds a new ElaboratedType type from the keyword,
524 /// the nested-name-specifier and the named type.
525 /// Subclasses may override this routine to provide different behavior.
526 QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword,
527 NestedNameSpecifier *NNS, QualType Named) {
528 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000529 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000530
531 /// \brief Build a new typename type that refers to a template-id.
532 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000533 /// By default, builds a new DependentNameType type from the
534 /// nested-name-specifier and the given type. Subclasses may override
535 /// this routine to provide different behavior.
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000536 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
537 NestedNameSpecifier *NNS, QualType T) {
Douglas Gregorae628892010-02-13 06:05:33 +0000538 if (NNS->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000539 // If the name is still dependent, just build a new dependent name type.
Douglas Gregorae628892010-02-13 06:05:33 +0000540 CXXScopeSpec SS;
541 SS.setScopeRep(NNS);
542 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000543 return SemaRef.Context.getDependentNameType(Keyword, NNS,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000544 cast<TemplateSpecializationType>(T));
Douglas Gregorae628892010-02-13 06:05:33 +0000545 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000546
547 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000548 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000549
550 /// \brief Build a new typename type that refers to an identifier.
551 ///
552 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000553 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000554 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000555 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000556 NestedNameSpecifier *NNS,
557 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000558 SourceLocation KeywordLoc,
559 SourceRange NNSRange,
560 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000561 CXXScopeSpec SS;
562 SS.setScopeRep(NNS);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000563 SS.setRange(NNSRange);
564
Douglas Gregor40336422010-03-31 22:19:08 +0000565 if (NNS->isDependent()) {
566 // If the name is still dependent, just build a new dependent name type.
567 if (!SemaRef.computeDeclContext(SS))
568 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
569 }
570
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000571 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000572 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
573 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000574
575 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
576
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000577 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000578 // into a non-dependent elaborated-type-specifier. Find the tag we're
579 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000580 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000581 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
582 if (!DC)
583 return QualType();
584
585 TagDecl *Tag = 0;
586 SemaRef.LookupQualifiedName(Result, DC);
587 switch (Result.getResultKind()) {
588 case LookupResult::NotFound:
589 case LookupResult::NotFoundInCurrentInstantiation:
590 break;
Sean Huntc3021132010-05-05 15:23:54 +0000591
Douglas Gregor40336422010-03-31 22:19:08 +0000592 case LookupResult::Found:
593 Tag = Result.getAsSingle<TagDecl>();
594 break;
Sean Huntc3021132010-05-05 15:23:54 +0000595
Douglas Gregor40336422010-03-31 22:19:08 +0000596 case LookupResult::FoundOverloaded:
597 case LookupResult::FoundUnresolvedValue:
598 llvm_unreachable("Tag lookup cannot find non-tags");
599 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000600
Douglas Gregor40336422010-03-31 22:19:08 +0000601 case LookupResult::Ambiguous:
602 // Let the LookupResult structure handle ambiguities.
603 return QualType();
604 }
605
606 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000607 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000608 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000609 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000610 return QualType();
611 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000612
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000613 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
614 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000615 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
616 return QualType();
617 }
618
619 // Build the elaborated-type-specifier type.
620 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000621 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000622 }
Mike Stump1eb44332009-09-09 15:08:12 +0000623
Douglas Gregordcee1a12009-08-06 05:28:30 +0000624 /// \brief Build a new nested-name-specifier given the prefix and an
625 /// identifier that names the next step in the nested-name-specifier.
626 ///
627 /// By default, performs semantic analysis when building the new
628 /// nested-name-specifier. Subclasses may override this routine to provide
629 /// different behavior.
630 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
631 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000632 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000633 QualType ObjectType,
634 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000635
636 /// \brief Build a new nested-name-specifier given the prefix and the
637 /// namespace named in the next step in the nested-name-specifier.
638 ///
639 /// By default, performs semantic analysis when building the new
640 /// nested-name-specifier. Subclasses may override this routine to provide
641 /// different behavior.
642 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
643 SourceRange Range,
644 NamespaceDecl *NS);
645
646 /// \brief Build a new nested-name-specifier given the prefix and the
647 /// type named in the next step in the nested-name-specifier.
648 ///
649 /// By default, performs semantic analysis when building the new
650 /// nested-name-specifier. Subclasses may override this routine to provide
651 /// different behavior.
652 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
653 SourceRange Range,
654 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000655 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000656
657 /// \brief Build a new template name given a nested name specifier, a flag
658 /// indicating whether the "template" keyword was provided, and the template
659 /// that the template name refers to.
660 ///
661 /// By default, builds the new template name directly. Subclasses may override
662 /// this routine to provide different behavior.
663 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
664 bool TemplateKW,
665 TemplateDecl *Template);
666
Douglas Gregord1067e52009-08-06 06:41:21 +0000667 /// \brief Build a new template name given a nested name specifier and the
668 /// name that is referred to as a template.
669 ///
670 /// By default, performs semantic analysis to determine whether the name can
671 /// be resolved to a specific template, then builds the appropriate kind of
672 /// template name. Subclasses may override this routine to provide different
673 /// behavior.
674 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000675 const IdentifierInfo &II,
676 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000677
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000678 /// \brief Build a new template name given a nested name specifier and the
679 /// overloaded operator name that is referred to as a template.
680 ///
681 /// By default, performs semantic analysis to determine whether the name can
682 /// be resolved to a specific template, then builds the appropriate kind of
683 /// template name. Subclasses may override this routine to provide different
684 /// behavior.
685 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
686 OverloadedOperatorKind Operator,
687 QualType ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +0000688
Douglas Gregor43959a92009-08-20 07:17:43 +0000689 /// \brief Build a new compound statement.
690 ///
691 /// By default, performs semantic analysis to build the new statement.
692 /// Subclasses may override this routine to provide different behavior.
693 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
694 MultiStmtArg Statements,
695 SourceLocation RBraceLoc,
696 bool IsStmtExpr) {
697 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
698 IsStmtExpr);
699 }
700
701 /// \brief Build a new case statement.
702 ///
703 /// By default, performs semantic analysis to build the new statement.
704 /// Subclasses may override this routine to provide different behavior.
705 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
706 ExprArg LHS,
707 SourceLocation EllipsisLoc,
708 ExprArg RHS,
709 SourceLocation ColonLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000710 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregor43959a92009-08-20 07:17:43 +0000711 ColonLoc);
712 }
Mike Stump1eb44332009-09-09 15:08:12 +0000713
Douglas Gregor43959a92009-08-20 07:17:43 +0000714 /// \brief Attach the body to a new case statement.
715 ///
716 /// By default, performs semantic analysis to build the new statement.
717 /// Subclasses may override this routine to provide different behavior.
718 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
719 getSema().ActOnCaseStmtBody(S.get(), move(Body));
720 return move(S);
721 }
Mike Stump1eb44332009-09-09 15:08:12 +0000722
Douglas Gregor43959a92009-08-20 07:17:43 +0000723 /// \brief Build a new default statement.
724 ///
725 /// By default, performs semantic analysis to build the new statement.
726 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000727 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000728 SourceLocation ColonLoc,
729 StmtArg SubStmt) {
Mike Stump1eb44332009-09-09 15:08:12 +0000730 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregor43959a92009-08-20 07:17:43 +0000731 /*CurScope=*/0);
732 }
Mike Stump1eb44332009-09-09 15:08:12 +0000733
Douglas Gregor43959a92009-08-20 07:17:43 +0000734 /// \brief Build a new label statement.
735 ///
736 /// By default, performs semantic analysis to build the new statement.
737 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000738 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000739 IdentifierInfo *Id,
740 SourceLocation ColonLoc,
741 StmtArg SubStmt) {
742 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
743 }
Mike Stump1eb44332009-09-09 15:08:12 +0000744
Douglas Gregor43959a92009-08-20 07:17:43 +0000745 /// \brief Build a new "if" statement.
746 ///
747 /// By default, performs semantic analysis to build the new statement.
748 /// Subclasses may override this routine to provide different behavior.
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000749 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Sean Huntc3021132010-05-05 15:23:54 +0000750 VarDecl *CondVar, StmtArg Then,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000751 SourceLocation ElseLoc, StmtArg Else) {
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000752 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000753 move(Then), ElseLoc, move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +0000754 }
Mike Stump1eb44332009-09-09 15:08:12 +0000755
Douglas Gregor43959a92009-08-20 07:17:43 +0000756 /// \brief Start building a new switch statement.
757 ///
758 /// By default, performs semantic analysis to build the new statement.
759 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor586596f2010-05-06 17:25:47 +0000760 OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
761 Sema::ExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000762 VarDecl *CondVar) {
Douglas Gregor586596f2010-05-06 17:25:47 +0000763 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond),
764 DeclPtrTy::make(CondVar));
Douglas Gregor43959a92009-08-20 07:17:43 +0000765 }
Mike Stump1eb44332009-09-09 15:08:12 +0000766
Douglas Gregor43959a92009-08-20 07:17:43 +0000767 /// \brief Attach the body to the switch statement.
768 ///
769 /// By default, performs semantic analysis to build the new statement.
770 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000771 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000772 StmtArg Switch, StmtArg Body) {
773 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
774 move(Body));
775 }
776
777 /// \brief Build a new while statement.
778 ///
779 /// By default, performs semantic analysis to build the new statement.
780 /// Subclasses may override this routine to provide different behavior.
781 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000782 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000783 VarDecl *CondVar,
Douglas Gregor43959a92009-08-20 07:17:43 +0000784 StmtArg Body) {
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000785 return getSema().ActOnWhileStmt(WhileLoc, Cond,
Douglas Gregor586596f2010-05-06 17:25:47 +0000786 DeclPtrTy::make(CondVar), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000787 }
Mike Stump1eb44332009-09-09 15:08:12 +0000788
Douglas Gregor43959a92009-08-20 07:17:43 +0000789 /// \brief Build a new do-while statement.
790 ///
791 /// By default, performs semantic analysis to build the new statement.
792 /// Subclasses may override this routine to provide different behavior.
793 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
794 SourceLocation WhileLoc,
795 SourceLocation LParenLoc,
796 ExprArg Cond,
797 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000798 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000799 move(Cond), RParenLoc);
800 }
801
802 /// \brief Build a new for statement.
803 ///
804 /// By default, performs semantic analysis to build the new statement.
805 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000806 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000807 SourceLocation LParenLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000808 StmtArg Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000809 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000810 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000811 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000812 DeclPtrTy::make(CondVar),
813 Inc, RParenLoc, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000814 }
Mike Stump1eb44332009-09-09 15:08:12 +0000815
Douglas Gregor43959a92009-08-20 07:17:43 +0000816 /// \brief Build a new goto statement.
817 ///
818 /// By default, performs semantic analysis to build the new statement.
819 /// Subclasses may override this routine to provide different behavior.
820 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
821 SourceLocation LabelLoc,
822 LabelStmt *Label) {
823 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
824 }
825
826 /// \brief Build a new indirect goto statement.
827 ///
828 /// By default, performs semantic analysis to build the new statement.
829 /// Subclasses may override this routine to provide different behavior.
830 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
831 SourceLocation StarLoc,
832 ExprArg Target) {
833 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
834 }
Mike Stump1eb44332009-09-09 15:08:12 +0000835
Douglas Gregor43959a92009-08-20 07:17:43 +0000836 /// \brief Build a new return statement.
837 ///
838 /// By default, performs semantic analysis to build the new statement.
839 /// Subclasses may override this routine to provide different behavior.
840 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
841 ExprArg Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000842
Douglas Gregor43959a92009-08-20 07:17:43 +0000843 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
844 }
Mike Stump1eb44332009-09-09 15:08:12 +0000845
Douglas Gregor43959a92009-08-20 07:17:43 +0000846 /// \brief Build a new declaration statement.
847 ///
848 /// By default, performs semantic analysis to build the new statement.
849 /// Subclasses may override this routine to provide different behavior.
850 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000851 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000852 SourceLocation EndLoc) {
853 return getSema().Owned(
854 new (getSema().Context) DeclStmt(
855 DeclGroupRef::Create(getSema().Context,
856 Decls, NumDecls),
857 StartLoc, EndLoc));
858 }
Mike Stump1eb44332009-09-09 15:08:12 +0000859
Anders Carlsson703e3942010-01-24 05:50:09 +0000860 /// \brief Build a new inline asm statement.
861 ///
862 /// By default, performs semantic analysis to build the new statement.
863 /// Subclasses may override this routine to provide different behavior.
864 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
865 bool IsSimple,
866 bool IsVolatile,
867 unsigned NumOutputs,
868 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000869 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000870 MultiExprArg Constraints,
871 MultiExprArg Exprs,
872 ExprArg AsmString,
873 MultiExprArg Clobbers,
874 SourceLocation RParenLoc,
875 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +0000876 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +0000877 NumInputs, Names, move(Constraints),
878 move(Exprs), move(AsmString), move(Clobbers),
879 RParenLoc, MSAsm);
880 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000881
882 /// \brief Build a new Objective-C @try statement.
883 ///
884 /// By default, performs semantic analysis to build the new statement.
885 /// Subclasses may override this routine to provide different behavior.
886 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
887 StmtArg TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000888 MultiStmtArg CatchStmts,
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000889 StmtArg Finally) {
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000890 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts),
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000891 move(Finally));
892 }
893
Douglas Gregorbe270a02010-04-26 17:57:08 +0000894 /// \brief Rebuild an Objective-C exception declaration.
895 ///
896 /// By default, performs semantic analysis to build the new declaration.
897 /// Subclasses may override this routine to provide different behavior.
898 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
899 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +0000900 return getSema().BuildObjCExceptionDecl(TInfo, T,
901 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +0000902 ExceptionDecl->getLocation());
903 }
Sean Huntc3021132010-05-05 15:23:54 +0000904
Douglas Gregorbe270a02010-04-26 17:57:08 +0000905 /// \brief Build a new Objective-C @catch statement.
906 ///
907 /// By default, performs semantic analysis to build the new statement.
908 /// Subclasses may override this routine to provide different behavior.
909 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
910 SourceLocation RParenLoc,
911 VarDecl *Var,
912 StmtArg Body) {
913 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
914 Sema::DeclPtrTy::make(Var),
915 move(Body));
916 }
Sean Huntc3021132010-05-05 15:23:54 +0000917
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000918 /// \brief Build a new Objective-C @finally statement.
919 ///
920 /// By default, performs semantic analysis to build the new statement.
921 /// Subclasses may override this routine to provide different behavior.
922 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
923 StmtArg Body) {
924 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
925 }
Sean Huntc3021132010-05-05 15:23:54 +0000926
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000927 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +0000928 ///
929 /// By default, performs semantic analysis to build the new statement.
930 /// Subclasses may override this routine to provide different behavior.
931 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
932 ExprArg Operand) {
933 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
934 }
Sean Huntc3021132010-05-05 15:23:54 +0000935
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000936 /// \brief Build a new Objective-C @synchronized statement.
937 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000938 /// By default, performs semantic analysis to build the new statement.
939 /// Subclasses may override this routine to provide different behavior.
940 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
941 ExprArg Object,
942 StmtArg Body) {
943 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
944 move(Body));
945 }
Douglas Gregorc3203e72010-04-22 23:10:45 +0000946
947 /// \brief Build a new Objective-C fast enumeration statement.
948 ///
949 /// By default, performs semantic analysis to build the new statement.
950 /// Subclasses may override this routine to provide different behavior.
951 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
952 SourceLocation LParenLoc,
953 StmtArg Element,
954 ExprArg Collection,
955 SourceLocation RParenLoc,
956 StmtArg Body) {
957 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
Sean Huntc3021132010-05-05 15:23:54 +0000958 move(Element),
Douglas Gregorc3203e72010-04-22 23:10:45 +0000959 move(Collection),
960 RParenLoc,
961 move(Body));
962 }
Sean Huntc3021132010-05-05 15:23:54 +0000963
Douglas Gregor43959a92009-08-20 07:17:43 +0000964 /// \brief Build a new C++ exception declaration.
965 ///
966 /// By default, performs semantic analysis to build the new decaration.
967 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000968 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000969 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000970 IdentifierInfo *Name,
971 SourceLocation Loc,
972 SourceRange TypeRange) {
Mike Stump1eb44332009-09-09 15:08:12 +0000973 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000974 TypeRange);
975 }
976
977 /// \brief Build a new C++ catch statement.
978 ///
979 /// By default, performs semantic analysis to build the new statement.
980 /// Subclasses may override this routine to provide different behavior.
981 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
982 VarDecl *ExceptionDecl,
983 StmtArg Handler) {
984 return getSema().Owned(
Mike Stump1eb44332009-09-09 15:08:12 +0000985 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregor43959a92009-08-20 07:17:43 +0000986 Handler.takeAs<Stmt>()));
987 }
Mike Stump1eb44332009-09-09 15:08:12 +0000988
Douglas Gregor43959a92009-08-20 07:17:43 +0000989 /// \brief Build a new C++ try statement.
990 ///
991 /// By default, performs semantic analysis to build the new statement.
992 /// Subclasses may override this routine to provide different behavior.
993 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
994 StmtArg TryBlock,
995 MultiStmtArg Handlers) {
996 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
997 }
Mike Stump1eb44332009-09-09 15:08:12 +0000998
Douglas Gregorb98b1992009-08-11 05:31:07 +0000999 /// \brief Build a new expression that references a declaration.
1000 ///
1001 /// By default, performs semantic analysis to build the new expression.
1002 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001003 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1004 LookupResult &R,
1005 bool RequiresADL) {
1006 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1007 }
1008
1009
1010 /// \brief Build a new expression that references a declaration.
1011 ///
1012 /// By default, performs semantic analysis to build the new expression.
1013 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora2813ce2009-10-23 18:54:35 +00001014 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1015 SourceRange QualifierRange,
John McCalldbd872f2009-12-08 09:08:17 +00001016 ValueDecl *VD, SourceLocation Loc,
1017 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001018 CXXScopeSpec SS;
1019 SS.setScopeRep(Qualifier);
1020 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001021
1022 // FIXME: loses template args.
Sean Huntc3021132010-05-05 15:23:54 +00001023
John McCalldbd872f2009-12-08 09:08:17 +00001024 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001025 }
Mike Stump1eb44332009-09-09 15:08:12 +00001026
Douglas Gregorb98b1992009-08-11 05:31:07 +00001027 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001028 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001029 /// By default, performs semantic analysis to build the new expression.
1030 /// Subclasses may override this routine to provide different behavior.
1031 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1032 SourceLocation RParen) {
1033 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1034 }
1035
Douglas Gregora71d8192009-09-04 17:36:40 +00001036 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001037 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001038 /// By default, performs semantic analysis to build the new expression.
1039 /// Subclasses may override this routine to provide different behavior.
1040 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1041 SourceLocation OperatorLoc,
1042 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001043 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001044 SourceRange QualifierRange,
1045 TypeSourceInfo *ScopeType,
1046 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001047 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001048 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001049
Douglas Gregorb98b1992009-08-11 05:31:07 +00001050 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001051 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001052 /// By default, performs semantic analysis to build the new expression.
1053 /// Subclasses may override this routine to provide different behavior.
1054 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1055 UnaryOperator::Opcode Opc,
1056 ExprArg SubExpr) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001057 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001058 }
Mike Stump1eb44332009-09-09 15:08:12 +00001059
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001060 /// \brief Build a new builtin offsetof expression.
1061 ///
1062 /// By default, performs semantic analysis to build the new expression.
1063 /// Subclasses may override this routine to provide different behavior.
1064 OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1065 TypeSourceInfo *Type,
1066 Action::OffsetOfComponent *Components,
1067 unsigned NumComponents,
1068 SourceLocation RParenLoc) {
1069 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1070 NumComponents, RParenLoc);
1071 }
Sean Huntc3021132010-05-05 15:23:54 +00001072
Douglas Gregorb98b1992009-08-11 05:31:07 +00001073 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001074 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001075 /// By default, performs semantic analysis to build the new expression.
1076 /// Subclasses may override this routine to provide different behavior.
John McCalla93c9342009-12-07 02:54:59 +00001077 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001078 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001079 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001080 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001081 }
1082
Mike Stump1eb44332009-09-09 15:08:12 +00001083 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001084 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001085 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001086 /// By default, performs semantic analysis to build the new expression.
1087 /// Subclasses may override this routine to provide different behavior.
1088 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1089 bool isSizeOf, SourceRange R) {
Mike Stump1eb44332009-09-09 15:08:12 +00001090 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001091 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1092 OpLoc, isSizeOf, R);
1093 if (Result.isInvalid())
1094 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001095
Douglas Gregorb98b1992009-08-11 05:31:07 +00001096 SubExpr.release();
1097 return move(Result);
1098 }
Mike Stump1eb44332009-09-09 15:08:12 +00001099
Douglas Gregorb98b1992009-08-11 05:31:07 +00001100 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001101 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001102 /// By default, performs semantic analysis to build the new expression.
1103 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001104 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001105 SourceLocation LBracketLoc,
1106 ExprArg RHS,
1107 SourceLocation RBracketLoc) {
1108 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump1eb44332009-09-09 15:08:12 +00001109 LBracketLoc, move(RHS),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001110 RBracketLoc);
1111 }
1112
1113 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001114 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001115 /// By default, performs semantic analysis to build the new expression.
1116 /// Subclasses may override this routine to provide different behavior.
1117 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1118 MultiExprArg Args,
1119 SourceLocation *CommaLocs,
1120 SourceLocation RParenLoc) {
1121 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1122 move(Args), CommaLocs, RParenLoc);
1123 }
1124
1125 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001126 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001127 /// By default, performs semantic analysis to build the new expression.
1128 /// Subclasses may override this routine to provide different behavior.
1129 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001130 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001131 NestedNameSpecifier *Qualifier,
1132 SourceRange QualifierRange,
1133 SourceLocation MemberLoc,
Eli Friedmanf595cc42009-12-04 06:40:45 +00001134 ValueDecl *Member,
John McCall6bb80172010-03-30 21:47:33 +00001135 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001136 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +00001137 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001138 if (!Member->getDeclName()) {
1139 // We have a reference to an unnamed field.
1140 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +00001141
Douglas Gregor83a56c42009-12-24 20:02:50 +00001142 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall6bb80172010-03-30 21:47:33 +00001143 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1144 FoundDecl, Member))
Douglas Gregor83a56c42009-12-24 20:02:50 +00001145 return getSema().ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001146
Mike Stump1eb44332009-09-09 15:08:12 +00001147 MemberExpr *ME =
Douglas Gregor83a56c42009-12-24 20:02:50 +00001148 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlssond8b285f2009-09-01 04:26:58 +00001149 Member, MemberLoc,
1150 cast<FieldDecl>(Member)->getType());
1151 return getSema().Owned(ME);
1152 }
Mike Stump1eb44332009-09-09 15:08:12 +00001153
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001154 CXXScopeSpec SS;
1155 if (Qualifier) {
1156 SS.setRange(QualifierRange);
1157 SS.setScopeRep(Qualifier);
1158 }
1159
John McCallaa81e162009-12-01 22:10:20 +00001160 QualType BaseType = ((Expr*) Base.get())->getType();
1161
John McCall6bb80172010-03-30 21:47:33 +00001162 // FIXME: this involves duplicating earlier analysis in a lot of
1163 // cases; we should avoid this when possible.
John McCallc2233c52010-01-15 08:34:02 +00001164 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1165 Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001166 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001167 R.resolveKind();
1168
John McCallaa81e162009-12-01 22:10:20 +00001169 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1170 OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001171 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001172 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001173 }
Mike Stump1eb44332009-09-09 15:08:12 +00001174
Douglas Gregorb98b1992009-08-11 05:31:07 +00001175 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001176 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001177 /// By default, performs semantic analysis to build the new expression.
1178 /// Subclasses may override this routine to provide different behavior.
1179 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1180 BinaryOperator::Opcode Opc,
1181 ExprArg LHS, ExprArg RHS) {
Sean Huntc3021132010-05-05 15:23:54 +00001182 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001183 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregorb98b1992009-08-11 05:31:07 +00001184 }
1185
1186 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001187 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001188 /// By default, performs semantic analysis to build the new expression.
1189 /// Subclasses may override this routine to provide different behavior.
1190 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1191 SourceLocation QuestionLoc,
1192 ExprArg LHS,
1193 SourceLocation ColonLoc,
1194 ExprArg RHS) {
Mike Stump1eb44332009-09-09 15:08:12 +00001195 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001196 move(LHS), move(RHS));
1197 }
1198
Douglas Gregorb98b1992009-08-11 05:31:07 +00001199 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001200 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001201 /// By default, performs semantic analysis to build the new expression.
1202 /// Subclasses may override this routine to provide different behavior.
John McCall9d125032010-01-15 18:39:57 +00001203 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1204 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001205 SourceLocation RParenLoc,
1206 ExprArg SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001207 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1208 move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001209 }
Mike Stump1eb44332009-09-09 15:08:12 +00001210
Douglas Gregorb98b1992009-08-11 05:31:07 +00001211 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001212 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001213 /// By default, performs semantic analysis to build the new expression.
1214 /// Subclasses may override this routine to provide different behavior.
1215 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001216 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001217 SourceLocation RParenLoc,
1218 ExprArg Init) {
John McCall42f56b52010-01-18 19:35:47 +00001219 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1220 move(Init));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001221 }
Mike Stump1eb44332009-09-09 15:08:12 +00001222
Douglas Gregorb98b1992009-08-11 05:31:07 +00001223 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001224 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001225 /// By default, performs semantic analysis to build the new expression.
1226 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001227 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001228 SourceLocation OpLoc,
1229 SourceLocation AccessorLoc,
1230 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001231
John McCall129e2df2009-11-30 22:42:35 +00001232 CXXScopeSpec SS;
John McCallaa81e162009-12-01 22:10:20 +00001233 QualType BaseType = ((Expr*) Base.get())->getType();
1234 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001235 OpLoc, /*IsArrow*/ false,
1236 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor2d1c2142009-11-03 19:44:04 +00001237 DeclarationName(&Accessor),
John McCall129e2df2009-11-30 22:42:35 +00001238 AccessorLoc,
1239 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001240 }
Mike Stump1eb44332009-09-09 15:08:12 +00001241
Douglas Gregorb98b1992009-08-11 05:31:07 +00001242 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001243 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001244 /// By default, performs semantic analysis to build the new expression.
1245 /// Subclasses may override this routine to provide different behavior.
1246 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1247 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001248 SourceLocation RBraceLoc,
1249 QualType ResultTy) {
1250 OwningExprResult Result
1251 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1252 if (Result.isInvalid() || ResultTy->isDependentType())
1253 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001254
Douglas Gregore48319a2009-11-09 17:16:50 +00001255 // Patch in the result type we were given, which may have been computed
1256 // when the initial InitListExpr was built.
1257 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1258 ILE->setType(ResultTy);
1259 return move(Result);
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 designated initializer 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 RebuildDesignatedInitExpr(Designation &Desig,
1267 MultiExprArg ArrayExprs,
1268 SourceLocation EqualOrColonLoc,
1269 bool GNUSyntax,
1270 ExprArg Init) {
1271 OwningExprResult Result
1272 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1273 move(Init));
1274 if (Result.isInvalid())
1275 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001276
Douglas Gregorb98b1992009-08-11 05:31:07 +00001277 ArrayExprs.release();
1278 return move(Result);
1279 }
Mike Stump1eb44332009-09-09 15:08:12 +00001280
Douglas Gregorb98b1992009-08-11 05:31:07 +00001281 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001282 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001283 /// By default, builds the implicit value initialization without performing
1284 /// any semantic analysis. Subclasses may override this routine to provide
1285 /// different behavior.
1286 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1287 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1288 }
Mike Stump1eb44332009-09-09 15:08:12 +00001289
Douglas Gregorb98b1992009-08-11 05:31:07 +00001290 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001291 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001292 /// By default, performs semantic analysis to build the new expression.
1293 /// Subclasses may override this routine to provide different behavior.
1294 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1295 QualType T, SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001296 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001297 RParenLoc);
1298 }
1299
1300 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001301 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001302 /// By default, performs semantic analysis to build the new expression.
1303 /// Subclasses may override this routine to provide different behavior.
1304 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1305 MultiExprArg SubExprs,
1306 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001307 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001308 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001309 }
Mike Stump1eb44332009-09-09 15:08:12 +00001310
Douglas Gregorb98b1992009-08-11 05:31:07 +00001311 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001312 ///
1313 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001314 /// rather than attempting to map the label statement itself.
1315 /// Subclasses may override this routine to provide different behavior.
1316 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1317 SourceLocation LabelLoc,
1318 LabelStmt *Label) {
1319 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1320 }
Mike Stump1eb44332009-09-09 15:08:12 +00001321
Douglas Gregorb98b1992009-08-11 05:31:07 +00001322 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001323 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001324 /// By default, performs semantic analysis to build the new expression.
1325 /// Subclasses may override this routine to provide different behavior.
1326 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1327 StmtArg SubStmt,
1328 SourceLocation RParenLoc) {
1329 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1330 }
Mike Stump1eb44332009-09-09 15:08:12 +00001331
Douglas Gregorb98b1992009-08-11 05:31:07 +00001332 /// \brief Build a new __builtin_types_compatible_p expression.
1333 ///
1334 /// By default, performs semantic analysis to build the new expression.
1335 /// Subclasses may override this routine to provide different behavior.
1336 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1337 QualType T1, QualType T2,
1338 SourceLocation RParenLoc) {
1339 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1340 T1.getAsOpaquePtr(),
1341 T2.getAsOpaquePtr(),
1342 RParenLoc);
1343 }
Mike Stump1eb44332009-09-09 15:08:12 +00001344
Douglas Gregorb98b1992009-08-11 05:31:07 +00001345 /// \brief Build a new __builtin_choose_expr expression.
1346 ///
1347 /// By default, performs semantic analysis to build the new expression.
1348 /// Subclasses may override this routine to provide different behavior.
1349 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1350 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1351 SourceLocation RParenLoc) {
1352 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1353 move(Cond), move(LHS), move(RHS),
1354 RParenLoc);
1355 }
Mike Stump1eb44332009-09-09 15:08:12 +00001356
Douglas Gregorb98b1992009-08-11 05:31:07 +00001357 /// \brief Build a new overloaded operator call expression.
1358 ///
1359 /// By default, performs semantic analysis to build the new expression.
1360 /// The semantic analysis provides the behavior of template instantiation,
1361 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001362 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001363 /// argument-dependent lookup, etc. Subclasses may override this routine to
1364 /// provide different behavior.
1365 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1366 SourceLocation OpLoc,
1367 ExprArg Callee,
1368 ExprArg First,
1369 ExprArg Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001370
1371 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001372 /// reinterpret_cast.
1373 ///
1374 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001375 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001376 /// Subclasses may override this routine to provide different behavior.
1377 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1378 Stmt::StmtClass Class,
1379 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001380 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001381 SourceLocation RAngleLoc,
1382 SourceLocation LParenLoc,
1383 ExprArg SubExpr,
1384 SourceLocation RParenLoc) {
1385 switch (Class) {
1386 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001387 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001388 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001389 move(SubExpr), RParenLoc);
1390
1391 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001392 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001393 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001394 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001395
Douglas Gregorb98b1992009-08-11 05:31:07 +00001396 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001397 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001398 RAngleLoc, LParenLoc,
1399 move(SubExpr),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001400 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001401
Douglas Gregorb98b1992009-08-11 05:31:07 +00001402 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001403 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001404 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001405 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001406
Douglas Gregorb98b1992009-08-11 05:31:07 +00001407 default:
1408 assert(false && "Invalid C++ named cast");
1409 break;
1410 }
Mike Stump1eb44332009-09-09 15:08:12 +00001411
Douglas Gregorb98b1992009-08-11 05:31:07 +00001412 return getSema().ExprError();
1413 }
Mike Stump1eb44332009-09-09 15:08:12 +00001414
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 /// \brief Build a new C++ static_cast expression.
1416 ///
1417 /// By default, performs semantic analysis to build the new expression.
1418 /// Subclasses may override this routine to provide different behavior.
1419 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1420 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001421 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001422 SourceLocation RAngleLoc,
1423 SourceLocation LParenLoc,
1424 ExprArg SubExpr,
1425 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001426 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1427 TInfo, move(SubExpr),
1428 SourceRange(LAngleLoc, RAngleLoc),
1429 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001430 }
1431
1432 /// \brief Build a new C++ dynamic_cast expression.
1433 ///
1434 /// By default, performs semantic analysis to build the new expression.
1435 /// Subclasses may override this routine to provide different behavior.
1436 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1437 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001438 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001439 SourceLocation RAngleLoc,
1440 SourceLocation LParenLoc,
1441 ExprArg SubExpr,
1442 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001443 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1444 TInfo, move(SubExpr),
1445 SourceRange(LAngleLoc, RAngleLoc),
1446 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001447 }
1448
1449 /// \brief Build a new C++ reinterpret_cast expression.
1450 ///
1451 /// By default, performs semantic analysis to build the new expression.
1452 /// Subclasses may override this routine to provide different behavior.
1453 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1454 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001455 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001456 SourceLocation RAngleLoc,
1457 SourceLocation LParenLoc,
1458 ExprArg SubExpr,
1459 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001460 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1461 TInfo, move(SubExpr),
1462 SourceRange(LAngleLoc, RAngleLoc),
1463 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001464 }
1465
1466 /// \brief Build a new C++ const_cast expression.
1467 ///
1468 /// By default, performs semantic analysis to build the new expression.
1469 /// Subclasses may override this routine to provide different behavior.
1470 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1471 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001472 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001473 SourceLocation RAngleLoc,
1474 SourceLocation LParenLoc,
1475 ExprArg SubExpr,
1476 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001477 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1478 TInfo, move(SubExpr),
1479 SourceRange(LAngleLoc, RAngleLoc),
1480 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001481 }
Mike Stump1eb44332009-09-09 15:08:12 +00001482
Douglas Gregorb98b1992009-08-11 05:31:07 +00001483 /// \brief Build a new C++ functional-style cast expression.
1484 ///
1485 /// By default, performs semantic analysis to build the new expression.
1486 /// Subclasses may override this routine to provide different behavior.
1487 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001488 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489 SourceLocation LParenLoc,
1490 ExprArg SubExpr,
1491 SourceLocation RParenLoc) {
Chris Lattner88650c32009-08-24 05:19:01 +00001492 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001494 TInfo->getType().getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 LParenLoc,
Chris Lattner88650c32009-08-24 05:19:01 +00001496 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump1eb44332009-09-09 15:08:12 +00001497 /*CommaLocs=*/0,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 RParenLoc);
1499 }
Mike Stump1eb44332009-09-09 15:08:12 +00001500
Douglas Gregorb98b1992009-08-11 05:31:07 +00001501 /// \brief Build a new C++ typeid(type) expression.
1502 ///
1503 /// By default, performs semantic analysis to build the new expression.
1504 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001505 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1506 SourceLocation TypeidLoc,
1507 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001508 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001509 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001510 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001511 }
Mike Stump1eb44332009-09-09 15:08:12 +00001512
Douglas Gregorb98b1992009-08-11 05:31:07 +00001513 /// \brief Build a new C++ typeid(expr) expression.
1514 ///
1515 /// By default, performs semantic analysis to build the new expression.
1516 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001517 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1518 SourceLocation TypeidLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001519 ExprArg Operand,
1520 SourceLocation RParenLoc) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001521 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand),
1522 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001523 }
1524
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 /// \brief Build a new C++ "this" expression.
1526 ///
1527 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001528 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001529 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001530 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001531 QualType ThisType,
1532 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001533 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001534 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1535 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001536 }
1537
1538 /// \brief Build a new C++ throw expression.
1539 ///
1540 /// By default, performs semantic analysis to build the new expression.
1541 /// Subclasses may override this routine to provide different behavior.
1542 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1543 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1544 }
1545
1546 /// \brief Build a new C++ default-argument expression.
1547 ///
1548 /// By default, builds a new default-argument expression, which does not
1549 /// require any semantic analysis. Subclasses may override this routine to
1550 /// provide different behavior.
Sean Huntc3021132010-05-05 15:23:54 +00001551 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001552 ParmVarDecl *Param) {
1553 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1554 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001555 }
1556
1557 /// \brief Build a new C++ zero-initialization expression.
1558 ///
1559 /// By default, performs semantic analysis to build the new expression.
1560 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001561 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001562 SourceLocation LParenLoc,
1563 QualType T,
1564 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001565 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1566 T.getAsOpaquePtr(), LParenLoc,
1567 MultiExprArg(getSema(), 0, 0),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001568 0, RParenLoc);
1569 }
Mike Stump1eb44332009-09-09 15:08:12 +00001570
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 /// \brief Build a new C++ "new" expression.
1572 ///
1573 /// By default, performs semantic analysis to build the new expression.
1574 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001575 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001576 bool UseGlobal,
1577 SourceLocation PlacementLParen,
1578 MultiExprArg PlacementArgs,
1579 SourceLocation PlacementRParen,
Mike Stump1eb44332009-09-09 15:08:12 +00001580 bool ParenTypeId,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 QualType AllocType,
1582 SourceLocation TypeLoc,
1583 SourceRange TypeRange,
1584 ExprArg ArraySize,
1585 SourceLocation ConstructorLParen,
1586 MultiExprArg ConstructorArgs,
1587 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001588 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001589 PlacementLParen,
1590 move(PlacementArgs),
1591 PlacementRParen,
1592 ParenTypeId,
1593 AllocType,
1594 TypeLoc,
1595 TypeRange,
1596 move(ArraySize),
1597 ConstructorLParen,
1598 move(ConstructorArgs),
1599 ConstructorRParen);
1600 }
Mike Stump1eb44332009-09-09 15:08:12 +00001601
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 /// \brief Build a new C++ "delete" expression.
1603 ///
1604 /// By default, performs semantic analysis to build the new expression.
1605 /// Subclasses may override this routine to provide different behavior.
1606 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1607 bool IsGlobalDelete,
1608 bool IsArrayForm,
1609 ExprArg Operand) {
1610 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1611 move(Operand));
1612 }
Mike Stump1eb44332009-09-09 15:08:12 +00001613
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 /// \brief Build a new unary type trait expression.
1615 ///
1616 /// By default, performs semantic analysis to build the new expression.
1617 /// Subclasses may override this routine to provide different behavior.
1618 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1619 SourceLocation StartLoc,
1620 SourceLocation LParenLoc,
1621 QualType T,
1622 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001623 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001624 T.getAsOpaquePtr(), RParenLoc);
1625 }
1626
Mike Stump1eb44332009-09-09 15:08:12 +00001627 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001628 /// expression.
1629 ///
1630 /// By default, performs semantic analysis to build the new expression.
1631 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001632 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001633 SourceRange QualifierRange,
1634 DeclarationName Name,
1635 SourceLocation Location,
John McCallf7a1a742009-11-24 19:00:30 +00001636 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001637 CXXScopeSpec SS;
1638 SS.setRange(QualifierRange);
1639 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001640
1641 if (TemplateArgs)
1642 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1643 *TemplateArgs);
1644
1645 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 }
1647
1648 /// \brief Build a new template-id expression.
1649 ///
1650 /// By default, performs semantic analysis to build the new expression.
1651 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001652 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1653 LookupResult &R,
1654 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001655 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001656 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001657 }
1658
1659 /// \brief Build a new object-construction expression.
1660 ///
1661 /// By default, performs semantic analysis to build the new expression.
1662 /// Subclasses may override this routine to provide different behavior.
1663 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001664 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001665 CXXConstructorDecl *Constructor,
1666 bool IsElidable,
1667 MultiExprArg Args) {
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001668 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001669 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001670 ConvertedArgs))
1671 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001672
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001673 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1674 move_arg(ConvertedArgs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001675 }
1676
1677 /// \brief Build a new object-construction expression.
1678 ///
1679 /// By default, performs semantic analysis to build the new expression.
1680 /// Subclasses may override this routine to provide different behavior.
1681 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1682 QualType T,
1683 SourceLocation LParenLoc,
1684 MultiExprArg Args,
1685 SourceLocation *Commas,
1686 SourceLocation RParenLoc) {
1687 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1688 T.getAsOpaquePtr(),
1689 LParenLoc,
1690 move(Args),
1691 Commas,
1692 RParenLoc);
1693 }
1694
1695 /// \brief Build a new object-construction expression.
1696 ///
1697 /// By default, performs semantic analysis to build the new expression.
1698 /// Subclasses may override this routine to provide different behavior.
1699 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1700 QualType T,
1701 SourceLocation LParenLoc,
1702 MultiExprArg Args,
1703 SourceLocation *Commas,
1704 SourceLocation RParenLoc) {
1705 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1706 /*FIXME*/LParenLoc),
1707 T.getAsOpaquePtr(),
1708 LParenLoc,
1709 move(Args),
1710 Commas,
1711 RParenLoc);
1712 }
Mike Stump1eb44332009-09-09 15:08:12 +00001713
Douglas Gregorb98b1992009-08-11 05:31:07 +00001714 /// \brief Build a new member reference expression.
1715 ///
1716 /// By default, performs semantic analysis to build the new expression.
1717 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001718 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001719 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001720 bool IsArrow,
1721 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001722 NestedNameSpecifier *Qualifier,
1723 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001724 NamedDecl *FirstQualifierInScope,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 DeclarationName Name,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001726 SourceLocation MemberLoc,
John McCall129e2df2009-11-30 22:42:35 +00001727 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001728 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001729 SS.setRange(QualifierRange);
1730 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001731
John McCallaa81e162009-12-01 22:10:20 +00001732 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1733 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001734 SS, FirstQualifierInScope,
1735 Name, MemberLoc, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001736 }
1737
John McCall129e2df2009-11-30 22:42:35 +00001738 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001739 ///
1740 /// By default, performs semantic analysis to build the new expression.
1741 /// Subclasses may override this routine to provide different behavior.
John McCall129e2df2009-11-30 22:42:35 +00001742 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001743 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001744 SourceLocation OperatorLoc,
1745 bool IsArrow,
1746 NestedNameSpecifier *Qualifier,
1747 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001748 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001749 LookupResult &R,
1750 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001751 CXXScopeSpec SS;
1752 SS.setRange(QualifierRange);
1753 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001754
John McCallaa81e162009-12-01 22:10:20 +00001755 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1756 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001757 SS, FirstQualifierInScope,
1758 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001759 }
Mike Stump1eb44332009-09-09 15:08:12 +00001760
Douglas Gregorb98b1992009-08-11 05:31:07 +00001761 /// \brief Build a new Objective-C @encode expression.
1762 ///
1763 /// By default, performs semantic analysis to build the new expression.
1764 /// Subclasses may override this routine to provide different behavior.
1765 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001766 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001767 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001768 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001769 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001770 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001771
Douglas Gregor92e986e2010-04-22 16:44:27 +00001772 /// \brief Build a new Objective-C class message.
1773 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1774 Selector Sel,
1775 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001776 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001777 MultiExprArg Args,
1778 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001779 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1780 ReceiverTypeInfo->getType(),
1781 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001782 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001783 move(Args));
1784 }
1785
1786 /// \brief Build a new Objective-C instance message.
1787 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1788 Selector Sel,
1789 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001790 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001791 MultiExprArg Args,
1792 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001793 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1794 return SemaRef.BuildInstanceMessage(move(Receiver),
1795 ReceiverType,
1796 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001797 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001798 move(Args));
1799 }
1800
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001801 /// \brief Build a new Objective-C ivar reference expression.
1802 ///
1803 /// By default, performs semantic analysis to build the new expression.
1804 /// Subclasses may override this routine to provide different behavior.
1805 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1806 SourceLocation IvarLoc,
1807 bool IsArrow, bool IsFreeIvar) {
1808 // FIXME: We lose track of the IsFreeIvar bit.
1809 CXXScopeSpec SS;
1810 Expr *Base = BaseArg.takeAs<Expr>();
1811 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1812 Sema::LookupMemberName);
1813 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1814 /*FIME:*/IvarLoc,
1815 SS, DeclPtrTy());
1816 if (Result.isInvalid())
1817 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001818
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001819 if (Result.get())
1820 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001821
1822 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001823 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001824 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001825 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001826 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001827 /*TemplateArgs=*/0);
1828 }
Douglas Gregore3303542010-04-26 20:47:02 +00001829
1830 /// \brief Build a new Objective-C property reference expression.
1831 ///
1832 /// By default, performs semantic analysis to build the new expression.
1833 /// Subclasses may override this routine to provide different behavior.
Sean Huntc3021132010-05-05 15:23:54 +00001834 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00001835 ObjCPropertyDecl *Property,
1836 SourceLocation PropertyLoc) {
1837 CXXScopeSpec SS;
1838 Expr *Base = BaseArg.takeAs<Expr>();
1839 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1840 Sema::LookupMemberName);
1841 bool IsArrow = false;
1842 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1843 /*FIME:*/PropertyLoc,
1844 SS, DeclPtrTy());
1845 if (Result.isInvalid())
1846 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001847
Douglas Gregore3303542010-04-26 20:47:02 +00001848 if (Result.get())
1849 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001850
1851 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregore3303542010-04-26 20:47:02 +00001852 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001853 /*FIXME:*/PropertyLoc, IsArrow,
1854 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00001855 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001856 R,
Douglas Gregore3303542010-04-26 20:47:02 +00001857 /*TemplateArgs=*/0);
1858 }
Sean Huntc3021132010-05-05 15:23:54 +00001859
1860 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001861 /// expression.
1862 ///
1863 /// By default, performs semantic analysis to build the new expression.
Sean Huntc3021132010-05-05 15:23:54 +00001864 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001865 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1866 ObjCMethodDecl *Getter,
1867 QualType T,
1868 ObjCMethodDecl *Setter,
1869 SourceLocation NameLoc,
1870 ExprArg Base) {
1871 // Since these expressions can only be value-dependent, we do not need to
1872 // perform semantic analysis again.
1873 return getSema().Owned(
1874 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1875 Setter,
1876 NameLoc,
1877 Base.takeAs<Expr>()));
1878 }
1879
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001880 /// \brief Build a new Objective-C "isa" expression.
1881 ///
1882 /// By default, performs semantic analysis to build the new expression.
1883 /// Subclasses may override this routine to provide different behavior.
1884 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1885 bool IsArrow) {
1886 CXXScopeSpec SS;
1887 Expr *Base = BaseArg.takeAs<Expr>();
1888 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1889 Sema::LookupMemberName);
1890 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1891 /*FIME:*/IsaLoc,
1892 SS, DeclPtrTy());
1893 if (Result.isInvalid())
1894 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001895
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001896 if (Result.get())
1897 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001898
1899 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001900 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001901 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001902 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001903 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001904 /*TemplateArgs=*/0);
1905 }
Sean Huntc3021132010-05-05 15:23:54 +00001906
Douglas Gregorb98b1992009-08-11 05:31:07 +00001907 /// \brief Build a new shuffle vector expression.
1908 ///
1909 /// By default, performs semantic analysis to build the new expression.
1910 /// Subclasses may override this routine to provide different behavior.
1911 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1912 MultiExprArg SubExprs,
1913 SourceLocation RParenLoc) {
1914 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001915 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001916 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1917 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1918 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1919 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001920
Douglas Gregorb98b1992009-08-11 05:31:07 +00001921 // Build a reference to the __builtin_shufflevector builtin
1922 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001923 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001924 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001925 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001926 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001927
1928 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001929 unsigned NumSubExprs = SubExprs.size();
1930 Expr **Subs = (Expr **)SubExprs.release();
1931 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1932 Subs, NumSubExprs,
1933 Builtin->getResultType(),
1934 RParenLoc);
1935 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001936
Douglas Gregorb98b1992009-08-11 05:31:07 +00001937 // Type-check the __builtin_shufflevector expression.
1938 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1939 if (Result.isInvalid())
1940 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001941
Douglas Gregorb98b1992009-08-11 05:31:07 +00001942 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001943 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001944 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001945};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001946
Douglas Gregor43959a92009-08-20 07:17:43 +00001947template<typename Derived>
1948Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1949 if (!S)
1950 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001951
Douglas Gregor43959a92009-08-20 07:17:43 +00001952 switch (S->getStmtClass()) {
1953 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001954
Douglas Gregor43959a92009-08-20 07:17:43 +00001955 // Transform individual statement nodes
1956#define STMT(Node, Parent) \
1957 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1958#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00001959#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00001960
Douglas Gregor43959a92009-08-20 07:17:43 +00001961 // Transform expressions by calling TransformExpr.
1962#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00001963#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00001964#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00001965#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00001966 {
1967 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1968 if (E.isInvalid())
1969 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001970
Anders Carlsson5ee56e92009-12-16 02:09:40 +00001971 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregor43959a92009-08-20 07:17:43 +00001972 }
Mike Stump1eb44332009-09-09 15:08:12 +00001973 }
1974
Douglas Gregor43959a92009-08-20 07:17:43 +00001975 return SemaRef.Owned(S->Retain());
1976}
Mike Stump1eb44332009-09-09 15:08:12 +00001977
1978
Douglas Gregor670444e2009-08-04 22:27:00 +00001979template<typename Derived>
John McCall454feb92009-12-08 09:21:05 +00001980Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001981 if (!E)
1982 return SemaRef.Owned(E);
1983
1984 switch (E->getStmtClass()) {
1985 case Stmt::NoStmtClass: break;
1986#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00001987#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00001988#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00001989 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00001990#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00001991 }
1992
Douglas Gregorb98b1992009-08-11 05:31:07 +00001993 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00001994}
1995
1996template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00001997NestedNameSpecifier *
1998TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00001999 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002000 QualType ObjectType,
2001 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00002002 if (!NNS)
2003 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002004
Douglas Gregor43959a92009-08-20 07:17:43 +00002005 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002006 NestedNameSpecifier *Prefix = NNS->getPrefix();
2007 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002008 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002009 ObjectType,
2010 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002011 if (!Prefix)
2012 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002013
2014 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00002015 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00002016 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00002017 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002018 }
Mike Stump1eb44332009-09-09 15:08:12 +00002019
Douglas Gregordcee1a12009-08-06 05:28:30 +00002020 switch (NNS->getKind()) {
2021 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00002022 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002023 "Identifier nested-name-specifier with no prefix or object type");
2024 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2025 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002026 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002027
2028 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002029 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002030 ObjectType,
2031 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002032
Douglas Gregordcee1a12009-08-06 05:28:30 +00002033 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002034 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002035 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002036 getDerived().TransformDecl(Range.getBegin(),
2037 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002038 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002039 Prefix == NNS->getPrefix() &&
2040 NS == NNS->getAsNamespace())
2041 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002042
Douglas Gregordcee1a12009-08-06 05:28:30 +00002043 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2044 }
Mike Stump1eb44332009-09-09 15:08:12 +00002045
Douglas Gregordcee1a12009-08-06 05:28:30 +00002046 case NestedNameSpecifier::Global:
2047 // There is no meaningful transformation that one could perform on the
2048 // global scope.
2049 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002050
Douglas Gregordcee1a12009-08-06 05:28:30 +00002051 case NestedNameSpecifier::TypeSpecWithTemplate:
2052 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002053 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor124b8782010-02-16 19:09:40 +00002054 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2055 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002056 if (T.isNull())
2057 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002058
Douglas Gregordcee1a12009-08-06 05:28:30 +00002059 if (!getDerived().AlwaysRebuild() &&
2060 Prefix == NNS->getPrefix() &&
2061 T == QualType(NNS->getAsType(), 0))
2062 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002063
2064 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2065 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002066 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002067 }
2068 }
Mike Stump1eb44332009-09-09 15:08:12 +00002069
Douglas Gregordcee1a12009-08-06 05:28:30 +00002070 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002071 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002072}
2073
2074template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002075DeclarationName
Douglas Gregor81499bb2009-09-03 22:13:48 +00002076TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +00002077 SourceLocation Loc,
2078 QualType ObjectType) {
Douglas Gregor81499bb2009-09-03 22:13:48 +00002079 if (!Name)
2080 return Name;
2081
2082 switch (Name.getNameKind()) {
2083 case DeclarationName::Identifier:
2084 case DeclarationName::ObjCZeroArgSelector:
2085 case DeclarationName::ObjCOneArgSelector:
2086 case DeclarationName::ObjCMultiArgSelector:
2087 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002088 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002089 case DeclarationName::CXXUsingDirective:
2090 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002091
Douglas Gregor81499bb2009-09-03 22:13:48 +00002092 case DeclarationName::CXXConstructorName:
2093 case DeclarationName::CXXDestructorName:
2094 case DeclarationName::CXXConversionFunctionName: {
2095 TemporaryBase Rebase(*this, Loc, Name);
Sean Huntc3021132010-05-05 15:23:54 +00002096 QualType T = getDerived().TransformType(Name.getCXXNameType(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002097 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00002098 if (T.isNull())
2099 return DeclarationName();
Mike Stump1eb44332009-09-09 15:08:12 +00002100
Douglas Gregor81499bb2009-09-03 22:13:48 +00002101 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump1eb44332009-09-09 15:08:12 +00002102 Name.getNameKind(),
Douglas Gregor81499bb2009-09-03 22:13:48 +00002103 SemaRef.Context.getCanonicalType(T));
Douglas Gregor81499bb2009-09-03 22:13:48 +00002104 }
Mike Stump1eb44332009-09-09 15:08:12 +00002105 }
2106
Douglas Gregor81499bb2009-09-03 22:13:48 +00002107 return DeclarationName();
2108}
2109
2110template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002111TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002112TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2113 QualType ObjectType) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002114 SourceLocation Loc = getDerived().getBaseLocation();
2115
Douglas Gregord1067e52009-08-06 06:41:21 +00002116 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002117 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002118 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002119 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2120 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002121 if (!NNS)
2122 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002123
Douglas Gregord1067e52009-08-06 06:41:21 +00002124 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002125 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002126 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002127 if (!TransTemplate)
2128 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002129
Douglas Gregord1067e52009-08-06 06:41:21 +00002130 if (!getDerived().AlwaysRebuild() &&
2131 NNS == QTN->getQualifier() &&
2132 TransTemplate == Template)
2133 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002134
Douglas Gregord1067e52009-08-06 06:41:21 +00002135 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2136 TransTemplate);
2137 }
Mike Stump1eb44332009-09-09 15:08:12 +00002138
John McCallf7a1a742009-11-24 19:00:30 +00002139 // These should be getting filtered out before they make it into the AST.
2140 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002141 }
Mike Stump1eb44332009-09-09 15:08:12 +00002142
Douglas Gregord1067e52009-08-06 06:41:21 +00002143 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002144 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002145 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002146 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2147 ObjectType);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002148 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00002149 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002150
Douglas Gregord1067e52009-08-06 06:41:21 +00002151 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002152 NNS == DTN->getQualifier() &&
2153 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002154 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002155
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002156 if (DTN->isIdentifier())
Sean Huntc3021132010-05-05 15:23:54 +00002157 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002158 ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +00002159
2160 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002161 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002162 }
Mike Stump1eb44332009-09-09 15:08:12 +00002163
Douglas Gregord1067e52009-08-06 06:41:21 +00002164 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002165 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002166 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002167 if (!TransTemplate)
2168 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002169
Douglas Gregord1067e52009-08-06 06:41:21 +00002170 if (!getDerived().AlwaysRebuild() &&
2171 TransTemplate == Template)
2172 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002173
Douglas Gregord1067e52009-08-06 06:41:21 +00002174 return TemplateName(TransTemplate);
2175 }
Mike Stump1eb44332009-09-09 15:08:12 +00002176
John McCallf7a1a742009-11-24 19:00:30 +00002177 // These should be getting filtered out before they reach the AST.
2178 assert(false && "overloaded function decl survived to here");
2179 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002180}
2181
2182template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002183void TreeTransform<Derived>::InventTemplateArgumentLoc(
2184 const TemplateArgument &Arg,
2185 TemplateArgumentLoc &Output) {
2186 SourceLocation Loc = getDerived().getBaseLocation();
2187 switch (Arg.getKind()) {
2188 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002189 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002190 break;
2191
2192 case TemplateArgument::Type:
2193 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002194 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002195
John McCall833ca992009-10-29 08:12:44 +00002196 break;
2197
Douglas Gregor788cd062009-11-11 01:00:40 +00002198 case TemplateArgument::Template:
2199 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2200 break;
Sean Huntc3021132010-05-05 15:23:54 +00002201
John McCall833ca992009-10-29 08:12:44 +00002202 case TemplateArgument::Expression:
2203 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2204 break;
2205
2206 case TemplateArgument::Declaration:
2207 case TemplateArgument::Integral:
2208 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002209 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002210 break;
2211 }
2212}
2213
2214template<typename Derived>
2215bool TreeTransform<Derived>::TransformTemplateArgument(
2216 const TemplateArgumentLoc &Input,
2217 TemplateArgumentLoc &Output) {
2218 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002219 switch (Arg.getKind()) {
2220 case TemplateArgument::Null:
2221 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002222 Output = Input;
2223 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002224
Douglas Gregor670444e2009-08-04 22:27:00 +00002225 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002226 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002227 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002228 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002229
2230 DI = getDerived().TransformType(DI);
2231 if (!DI) return true;
2232
2233 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2234 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002235 }
Mike Stump1eb44332009-09-09 15:08:12 +00002236
Douglas Gregor670444e2009-08-04 22:27:00 +00002237 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002238 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002239 DeclarationName Name;
2240 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2241 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002242 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002243 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002244 if (!D) return true;
2245
John McCall828bff22009-10-29 18:45:58 +00002246 Expr *SourceExpr = Input.getSourceDeclExpression();
2247 if (SourceExpr) {
2248 EnterExpressionEvaluationContext Unevaluated(getSema(),
2249 Action::Unevaluated);
2250 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2251 if (E.isInvalid())
2252 SourceExpr = NULL;
2253 else {
2254 SourceExpr = E.takeAs<Expr>();
2255 SourceExpr->Retain();
2256 }
2257 }
2258
2259 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002260 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002261 }
Mike Stump1eb44332009-09-09 15:08:12 +00002262
Douglas Gregor788cd062009-11-11 01:00:40 +00002263 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002264 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002265 TemplateName Template
2266 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2267 if (Template.isNull())
2268 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002269
Douglas Gregor788cd062009-11-11 01:00:40 +00002270 Output = TemplateArgumentLoc(TemplateArgument(Template),
2271 Input.getTemplateQualifierRange(),
2272 Input.getTemplateNameLoc());
2273 return false;
2274 }
Sean Huntc3021132010-05-05 15:23:54 +00002275
Douglas Gregor670444e2009-08-04 22:27:00 +00002276 case TemplateArgument::Expression: {
2277 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002278 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002279 Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002280
John McCall833ca992009-10-29 08:12:44 +00002281 Expr *InputExpr = Input.getSourceExpression();
2282 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2283
2284 Sema::OwningExprResult E
2285 = getDerived().TransformExpr(InputExpr);
2286 if (E.isInvalid()) return true;
2287
2288 Expr *ETaken = E.takeAs<Expr>();
John McCall828bff22009-10-29 18:45:58 +00002289 ETaken->Retain();
John McCall833ca992009-10-29 08:12:44 +00002290 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2291 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002292 }
Mike Stump1eb44332009-09-09 15:08:12 +00002293
Douglas Gregor670444e2009-08-04 22:27:00 +00002294 case TemplateArgument::Pack: {
2295 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2296 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002297 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002298 AEnd = Arg.pack_end();
2299 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002300
John McCall833ca992009-10-29 08:12:44 +00002301 // FIXME: preserve source information here when we start
2302 // caring about parameter packs.
2303
John McCall828bff22009-10-29 18:45:58 +00002304 TemplateArgumentLoc InputArg;
2305 TemplateArgumentLoc OutputArg;
2306 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2307 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002308 return true;
2309
John McCall828bff22009-10-29 18:45:58 +00002310 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002311 }
2312 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002313 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002314 true);
John McCall828bff22009-10-29 18:45:58 +00002315 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002316 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002317 }
2318 }
Mike Stump1eb44332009-09-09 15:08:12 +00002319
Douglas Gregor670444e2009-08-04 22:27:00 +00002320 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002321 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002322}
2323
Douglas Gregor577f75a2009-08-04 16:50:30 +00002324//===----------------------------------------------------------------------===//
2325// Type transformation
2326//===----------------------------------------------------------------------===//
2327
2328template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00002329QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregor124b8782010-02-16 19:09:40 +00002330 QualType ObjectType) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002331 if (getDerived().AlreadyTransformed(T))
2332 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002333
John McCalla2becad2009-10-21 00:40:46 +00002334 // Temporary workaround. All of these transformations should
2335 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002336 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002337 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002338
Douglas Gregor124b8782010-02-16 19:09:40 +00002339 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall0953e762009-09-24 19:53:00 +00002340
John McCalla2becad2009-10-21 00:40:46 +00002341 if (!NewDI)
2342 return QualType();
2343
2344 return NewDI->getType();
2345}
2346
2347template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002348TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2349 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002350 if (getDerived().AlreadyTransformed(DI->getType()))
2351 return DI;
2352
2353 TypeLocBuilder TLB;
2354
2355 TypeLoc TL = DI->getTypeLoc();
2356 TLB.reserve(TL.getFullDataSize());
2357
Douglas Gregor124b8782010-02-16 19:09:40 +00002358 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002359 if (Result.isNull())
2360 return 0;
2361
John McCalla93c9342009-12-07 02:54:59 +00002362 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002363}
2364
2365template<typename Derived>
2366QualType
Douglas Gregor124b8782010-02-16 19:09:40 +00002367TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2368 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002369 switch (T.getTypeLocClass()) {
2370#define ABSTRACT_TYPELOC(CLASS, PARENT)
2371#define TYPELOC(CLASS, PARENT) \
2372 case TypeLoc::CLASS: \
Douglas Gregor124b8782010-02-16 19:09:40 +00002373 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2374 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002375#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002376 }
Mike Stump1eb44332009-09-09 15:08:12 +00002377
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002378 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002379 return QualType();
2380}
2381
2382/// FIXME: By default, this routine adds type qualifiers only to types
2383/// that can have qualifiers, and silently suppresses those qualifiers
2384/// that are not permitted (e.g., qualifiers on reference or function
2385/// types). This is the right thing for template instantiation, but
2386/// probably not for other clients.
2387template<typename Derived>
2388QualType
2389TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002390 QualifiedTypeLoc T,
2391 QualType ObjectType) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002392 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002393
Douglas Gregor124b8782010-02-16 19:09:40 +00002394 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2395 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002396 if (Result.isNull())
2397 return QualType();
2398
2399 // Silently suppress qualifiers if the result type can't be qualified.
2400 // FIXME: this is the right thing for template instantiation, but
2401 // probably not for other clients.
2402 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002403 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002404
John McCalla2becad2009-10-21 00:40:46 +00002405 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2406
2407 TLB.push<QualifiedTypeLoc>(Result);
2408
2409 // No location information to preserve.
2410
2411 return Result;
2412}
2413
2414template <class TyLoc> static inline
2415QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2416 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2417 NewT.setNameLoc(T.getNameLoc());
2418 return T.getType();
2419}
2420
John McCalla2becad2009-10-21 00:40:46 +00002421template<typename Derived>
2422QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002423 BuiltinTypeLoc T,
2424 QualType ObjectType) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002425 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2426 NewT.setBuiltinLoc(T.getBuiltinLoc());
2427 if (T.needsExtraLocalData())
2428 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2429 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002430}
Mike Stump1eb44332009-09-09 15:08:12 +00002431
Douglas Gregor577f75a2009-08-04 16:50:30 +00002432template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002433QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002434 ComplexTypeLoc T,
2435 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002436 // FIXME: recurse?
2437 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002438}
Mike Stump1eb44332009-09-09 15:08:12 +00002439
Douglas Gregor577f75a2009-08-04 16:50:30 +00002440template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002441QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Sean Huntc3021132010-05-05 15:23:54 +00002442 PointerTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00002443 QualType ObjectType) {
Sean Huntc3021132010-05-05 15:23:54 +00002444 QualType PointeeType
2445 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002446 if (PointeeType.isNull())
2447 return QualType();
2448
2449 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00002450 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002451 // A dependent pointer type 'T *' has is being transformed such
2452 // that an Objective-C class type is being replaced for 'T'. The
2453 // resulting pointer type is an ObjCObjectPointerType, not a
2454 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00002455 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00002456
John McCallc12c5bb2010-05-15 11:32:37 +00002457 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2458 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002459 return Result;
2460 }
Sean Huntc3021132010-05-05 15:23:54 +00002461
Douglas Gregor92e986e2010-04-22 16:44:27 +00002462 if (getDerived().AlwaysRebuild() ||
2463 PointeeType != TL.getPointeeLoc().getType()) {
2464 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2465 if (Result.isNull())
2466 return QualType();
2467 }
Sean Huntc3021132010-05-05 15:23:54 +00002468
Douglas Gregor92e986e2010-04-22 16:44:27 +00002469 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2470 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00002471 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002472}
Mike Stump1eb44332009-09-09 15:08:12 +00002473
2474template<typename Derived>
2475QualType
John McCalla2becad2009-10-21 00:40:46 +00002476TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002477 BlockPointerTypeLoc TL,
2478 QualType ObjectType) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002479 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00002480 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2481 if (PointeeType.isNull())
2482 return QualType();
2483
2484 QualType Result = TL.getType();
2485 if (getDerived().AlwaysRebuild() ||
2486 PointeeType != TL.getPointeeLoc().getType()) {
2487 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002488 TL.getSigilLoc());
2489 if (Result.isNull())
2490 return QualType();
2491 }
2492
Douglas Gregor39968ad2010-04-22 16:50:51 +00002493 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002494 NewT.setSigilLoc(TL.getSigilLoc());
2495 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002496}
2497
John McCall85737a72009-10-30 00:06:24 +00002498/// Transforms a reference type. Note that somewhat paradoxically we
2499/// don't care whether the type itself is an l-value type or an r-value
2500/// type; we only care if the type was *written* as an l-value type
2501/// or an r-value type.
2502template<typename Derived>
2503QualType
2504TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002505 ReferenceTypeLoc TL,
2506 QualType ObjectType) {
John McCall85737a72009-10-30 00:06:24 +00002507 const ReferenceType *T = TL.getTypePtr();
2508
2509 // Note that this works with the pointee-as-written.
2510 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2511 if (PointeeType.isNull())
2512 return QualType();
2513
2514 QualType Result = TL.getType();
2515 if (getDerived().AlwaysRebuild() ||
2516 PointeeType != T->getPointeeTypeAsWritten()) {
2517 Result = getDerived().RebuildReferenceType(PointeeType,
2518 T->isSpelledAsLValue(),
2519 TL.getSigilLoc());
2520 if (Result.isNull())
2521 return QualType();
2522 }
2523
2524 // r-value references can be rebuilt as l-value references.
2525 ReferenceTypeLoc NewTL;
2526 if (isa<LValueReferenceType>(Result))
2527 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2528 else
2529 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2530 NewTL.setSigilLoc(TL.getSigilLoc());
2531
2532 return Result;
2533}
2534
Mike Stump1eb44332009-09-09 15:08:12 +00002535template<typename Derived>
2536QualType
John McCalla2becad2009-10-21 00:40:46 +00002537TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002538 LValueReferenceTypeLoc TL,
2539 QualType ObjectType) {
2540 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002541}
2542
Mike Stump1eb44332009-09-09 15:08:12 +00002543template<typename Derived>
2544QualType
John McCalla2becad2009-10-21 00:40:46 +00002545TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002546 RValueReferenceTypeLoc TL,
2547 QualType ObjectType) {
2548 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002549}
Mike Stump1eb44332009-09-09 15:08:12 +00002550
Douglas Gregor577f75a2009-08-04 16:50:30 +00002551template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002552QualType
John McCalla2becad2009-10-21 00:40:46 +00002553TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002554 MemberPointerTypeLoc TL,
2555 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002556 MemberPointerType *T = TL.getTypePtr();
2557
2558 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002559 if (PointeeType.isNull())
2560 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002561
John McCalla2becad2009-10-21 00:40:46 +00002562 // TODO: preserve source information for this.
2563 QualType ClassType
2564 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002565 if (ClassType.isNull())
2566 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002567
John McCalla2becad2009-10-21 00:40:46 +00002568 QualType Result = TL.getType();
2569 if (getDerived().AlwaysRebuild() ||
2570 PointeeType != T->getPointeeType() ||
2571 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002572 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2573 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002574 if (Result.isNull())
2575 return QualType();
2576 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002577
John McCalla2becad2009-10-21 00:40:46 +00002578 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2579 NewTL.setSigilLoc(TL.getSigilLoc());
2580
2581 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002582}
2583
Mike Stump1eb44332009-09-09 15:08:12 +00002584template<typename Derived>
2585QualType
John McCalla2becad2009-10-21 00:40:46 +00002586TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002587 ConstantArrayTypeLoc TL,
2588 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002589 ConstantArrayType *T = TL.getTypePtr();
2590 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002591 if (ElementType.isNull())
2592 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002593
John McCalla2becad2009-10-21 00:40:46 +00002594 QualType Result = TL.getType();
2595 if (getDerived().AlwaysRebuild() ||
2596 ElementType != T->getElementType()) {
2597 Result = getDerived().RebuildConstantArrayType(ElementType,
2598 T->getSizeModifier(),
2599 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002600 T->getIndexTypeCVRQualifiers(),
2601 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002602 if (Result.isNull())
2603 return QualType();
2604 }
Sean Huntc3021132010-05-05 15:23:54 +00002605
John McCalla2becad2009-10-21 00:40:46 +00002606 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2607 NewTL.setLBracketLoc(TL.getLBracketLoc());
2608 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002609
John McCalla2becad2009-10-21 00:40:46 +00002610 Expr *Size = TL.getSizeExpr();
2611 if (Size) {
2612 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2613 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2614 }
2615 NewTL.setSizeExpr(Size);
2616
2617 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002618}
Mike Stump1eb44332009-09-09 15:08:12 +00002619
Douglas Gregor577f75a2009-08-04 16:50:30 +00002620template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002621QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002622 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002623 IncompleteArrayTypeLoc TL,
2624 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002625 IncompleteArrayType *T = TL.getTypePtr();
2626 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002627 if (ElementType.isNull())
2628 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002629
John McCalla2becad2009-10-21 00:40:46 +00002630 QualType Result = TL.getType();
2631 if (getDerived().AlwaysRebuild() ||
2632 ElementType != T->getElementType()) {
2633 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002634 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002635 T->getIndexTypeCVRQualifiers(),
2636 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002637 if (Result.isNull())
2638 return QualType();
2639 }
Sean Huntc3021132010-05-05 15:23:54 +00002640
John McCalla2becad2009-10-21 00:40:46 +00002641 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2642 NewTL.setLBracketLoc(TL.getLBracketLoc());
2643 NewTL.setRBracketLoc(TL.getRBracketLoc());
2644 NewTL.setSizeExpr(0);
2645
2646 return Result;
2647}
2648
2649template<typename Derived>
2650QualType
2651TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002652 VariableArrayTypeLoc TL,
2653 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002654 VariableArrayType *T = TL.getTypePtr();
2655 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2656 if (ElementType.isNull())
2657 return QualType();
2658
2659 // Array bounds are not potentially evaluated contexts
2660 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2661
2662 Sema::OwningExprResult SizeResult
2663 = getDerived().TransformExpr(T->getSizeExpr());
2664 if (SizeResult.isInvalid())
2665 return QualType();
2666
2667 Expr *Size = static_cast<Expr*>(SizeResult.get());
2668
2669 QualType Result = TL.getType();
2670 if (getDerived().AlwaysRebuild() ||
2671 ElementType != T->getElementType() ||
2672 Size != T->getSizeExpr()) {
2673 Result = getDerived().RebuildVariableArrayType(ElementType,
2674 T->getSizeModifier(),
2675 move(SizeResult),
2676 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002677 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002678 if (Result.isNull())
2679 return QualType();
2680 }
2681 else SizeResult.take();
Sean Huntc3021132010-05-05 15:23:54 +00002682
John McCalla2becad2009-10-21 00:40:46 +00002683 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2684 NewTL.setLBracketLoc(TL.getLBracketLoc());
2685 NewTL.setRBracketLoc(TL.getRBracketLoc());
2686 NewTL.setSizeExpr(Size);
2687
2688 return Result;
2689}
2690
2691template<typename Derived>
2692QualType
2693TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002694 DependentSizedArrayTypeLoc TL,
2695 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002696 DependentSizedArrayType *T = TL.getTypePtr();
2697 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2698 if (ElementType.isNull())
2699 return QualType();
2700
2701 // Array bounds are not potentially evaluated contexts
2702 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2703
2704 Sema::OwningExprResult SizeResult
2705 = getDerived().TransformExpr(T->getSizeExpr());
2706 if (SizeResult.isInvalid())
2707 return QualType();
2708
2709 Expr *Size = static_cast<Expr*>(SizeResult.get());
2710
2711 QualType Result = TL.getType();
2712 if (getDerived().AlwaysRebuild() ||
2713 ElementType != T->getElementType() ||
2714 Size != T->getSizeExpr()) {
2715 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2716 T->getSizeModifier(),
2717 move(SizeResult),
2718 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002719 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002720 if (Result.isNull())
2721 return QualType();
2722 }
2723 else SizeResult.take();
2724
2725 // We might have any sort of array type now, but fortunately they
2726 // all have the same location layout.
2727 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2728 NewTL.setLBracketLoc(TL.getLBracketLoc());
2729 NewTL.setRBracketLoc(TL.getRBracketLoc());
2730 NewTL.setSizeExpr(Size);
2731
2732 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002733}
Mike Stump1eb44332009-09-09 15:08:12 +00002734
2735template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002736QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002737 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002738 DependentSizedExtVectorTypeLoc TL,
2739 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002740 DependentSizedExtVectorType *T = TL.getTypePtr();
2741
2742 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002743 QualType ElementType = getDerived().TransformType(T->getElementType());
2744 if (ElementType.isNull())
2745 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002746
Douglas Gregor670444e2009-08-04 22:27:00 +00002747 // Vector sizes are not potentially evaluated contexts
2748 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2749
Douglas Gregor577f75a2009-08-04 16:50:30 +00002750 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2751 if (Size.isInvalid())
2752 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002753
John McCalla2becad2009-10-21 00:40:46 +00002754 QualType Result = TL.getType();
2755 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002756 ElementType != T->getElementType() ||
2757 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002758 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002759 move(Size),
2760 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002761 if (Result.isNull())
2762 return QualType();
2763 }
2764 else Size.take();
2765
2766 // Result might be dependent or not.
2767 if (isa<DependentSizedExtVectorType>(Result)) {
2768 DependentSizedExtVectorTypeLoc NewTL
2769 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2770 NewTL.setNameLoc(TL.getNameLoc());
2771 } else {
2772 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2773 NewTL.setNameLoc(TL.getNameLoc());
2774 }
2775
2776 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002777}
Mike Stump1eb44332009-09-09 15:08:12 +00002778
2779template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002780QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002781 VectorTypeLoc TL,
2782 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002783 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002784 QualType ElementType = getDerived().TransformType(T->getElementType());
2785 if (ElementType.isNull())
2786 return QualType();
2787
John McCalla2becad2009-10-21 00:40:46 +00002788 QualType Result = TL.getType();
2789 if (getDerived().AlwaysRebuild() ||
2790 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002791 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2792 T->isAltiVec(), T->isPixel());
John McCalla2becad2009-10-21 00:40:46 +00002793 if (Result.isNull())
2794 return QualType();
2795 }
Sean Huntc3021132010-05-05 15:23:54 +00002796
John McCalla2becad2009-10-21 00:40:46 +00002797 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2798 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002799
John McCalla2becad2009-10-21 00:40:46 +00002800 return Result;
2801}
2802
2803template<typename Derived>
2804QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002805 ExtVectorTypeLoc TL,
2806 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002807 VectorType *T = TL.getTypePtr();
2808 QualType ElementType = getDerived().TransformType(T->getElementType());
2809 if (ElementType.isNull())
2810 return QualType();
2811
2812 QualType Result = TL.getType();
2813 if (getDerived().AlwaysRebuild() ||
2814 ElementType != T->getElementType()) {
2815 Result = getDerived().RebuildExtVectorType(ElementType,
2816 T->getNumElements(),
2817 /*FIXME*/ SourceLocation());
2818 if (Result.isNull())
2819 return QualType();
2820 }
Sean Huntc3021132010-05-05 15:23:54 +00002821
John McCalla2becad2009-10-21 00:40:46 +00002822 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2823 NewTL.setNameLoc(TL.getNameLoc());
2824
2825 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002826}
Mike Stump1eb44332009-09-09 15:08:12 +00002827
2828template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002829ParmVarDecl *
2830TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2831 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2832 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2833 if (!NewDI)
2834 return 0;
2835
2836 if (NewDI == OldDI)
2837 return OldParm;
2838 else
2839 return ParmVarDecl::Create(SemaRef.Context,
2840 OldParm->getDeclContext(),
2841 OldParm->getLocation(),
2842 OldParm->getIdentifier(),
2843 NewDI->getType(),
2844 NewDI,
2845 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00002846 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00002847 /* DefArg */ NULL);
2848}
2849
2850template<typename Derived>
2851bool TreeTransform<Derived>::
2852 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2853 llvm::SmallVectorImpl<QualType> &PTypes,
2854 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2855 FunctionProtoType *T = TL.getTypePtr();
2856
2857 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2858 ParmVarDecl *OldParm = TL.getArg(i);
2859
2860 QualType NewType;
2861 ParmVarDecl *NewParm;
2862
2863 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002864 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2865 if (!NewParm)
2866 return true;
2867 NewType = NewParm->getType();
2868
2869 // Deal with the possibility that we don't have a parameter
2870 // declaration for this parameter.
2871 } else {
2872 NewParm = 0;
2873
2874 QualType OldType = T->getArgType(i);
2875 NewType = getDerived().TransformType(OldType);
2876 if (NewType.isNull())
2877 return true;
2878 }
2879
2880 PTypes.push_back(NewType);
2881 PVars.push_back(NewParm);
2882 }
2883
2884 return false;
2885}
2886
2887template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002888QualType
John McCalla2becad2009-10-21 00:40:46 +00002889TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002890 FunctionProtoTypeLoc TL,
2891 QualType ObjectType) {
Douglas Gregor895162d2010-04-30 18:55:50 +00002892 // Transform the parameters. We do this first for the benefit of template
2893 // instantiations, so that the ParmVarDecls get/ placed into the template
2894 // instantiation scope before we transform the function type.
Douglas Gregor577f75a2009-08-04 16:50:30 +00002895 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002896 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall21ef0fa2010-03-11 09:03:00 +00002897 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2898 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +00002899
Douglas Gregor895162d2010-04-30 18:55:50 +00002900 FunctionProtoType *T = TL.getTypePtr();
2901 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2902 if (ResultType.isNull())
2903 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +00002904
John McCalla2becad2009-10-21 00:40:46 +00002905 QualType Result = TL.getType();
2906 if (getDerived().AlwaysRebuild() ||
2907 ResultType != T->getResultType() ||
2908 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2909 Result = getDerived().RebuildFunctionProtoType(ResultType,
2910 ParamTypes.data(),
2911 ParamTypes.size(),
2912 T->isVariadic(),
2913 T->getTypeQuals());
2914 if (Result.isNull())
2915 return QualType();
2916 }
Mike Stump1eb44332009-09-09 15:08:12 +00002917
John McCalla2becad2009-10-21 00:40:46 +00002918 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2919 NewTL.setLParenLoc(TL.getLParenLoc());
2920 NewTL.setRParenLoc(TL.getRParenLoc());
2921 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2922 NewTL.setArg(i, ParamDecls[i]);
2923
2924 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002925}
Mike Stump1eb44332009-09-09 15:08:12 +00002926
Douglas Gregor577f75a2009-08-04 16:50:30 +00002927template<typename Derived>
2928QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002929 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002930 FunctionNoProtoTypeLoc TL,
2931 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002932 FunctionNoProtoType *T = TL.getTypePtr();
2933 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2934 if (ResultType.isNull())
2935 return QualType();
2936
2937 QualType Result = TL.getType();
2938 if (getDerived().AlwaysRebuild() ||
2939 ResultType != T->getResultType())
2940 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2941
2942 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2943 NewTL.setLParenLoc(TL.getLParenLoc());
2944 NewTL.setRParenLoc(TL.getRParenLoc());
2945
2946 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002947}
Mike Stump1eb44332009-09-09 15:08:12 +00002948
John McCalled976492009-12-04 22:46:56 +00002949template<typename Derived> QualType
2950TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002951 UnresolvedUsingTypeLoc TL,
2952 QualType ObjectType) {
John McCalled976492009-12-04 22:46:56 +00002953 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002954 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00002955 if (!D)
2956 return QualType();
2957
2958 QualType Result = TL.getType();
2959 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2960 Result = getDerived().RebuildUnresolvedUsingType(D);
2961 if (Result.isNull())
2962 return QualType();
2963 }
2964
2965 // We might get an arbitrary type spec type back. We should at
2966 // least always get a type spec type, though.
2967 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2968 NewTL.setNameLoc(TL.getNameLoc());
2969
2970 return Result;
2971}
2972
Douglas Gregor577f75a2009-08-04 16:50:30 +00002973template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002974QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002975 TypedefTypeLoc TL,
2976 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002977 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002978 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002979 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2980 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002981 if (!Typedef)
2982 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002983
John McCalla2becad2009-10-21 00:40:46 +00002984 QualType Result = TL.getType();
2985 if (getDerived().AlwaysRebuild() ||
2986 Typedef != T->getDecl()) {
2987 Result = getDerived().RebuildTypedefType(Typedef);
2988 if (Result.isNull())
2989 return QualType();
2990 }
Mike Stump1eb44332009-09-09 15:08:12 +00002991
John McCalla2becad2009-10-21 00:40:46 +00002992 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2993 NewTL.setNameLoc(TL.getNameLoc());
2994
2995 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002996}
Mike Stump1eb44332009-09-09 15:08:12 +00002997
Douglas Gregor577f75a2009-08-04 16:50:30 +00002998template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002999QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003000 TypeOfExprTypeLoc TL,
3001 QualType ObjectType) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003002 // typeof expressions are not potentially evaluated contexts
3003 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003004
John McCallcfb708c2010-01-13 20:03:27 +00003005 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003006 if (E.isInvalid())
3007 return QualType();
3008
John McCalla2becad2009-10-21 00:40:46 +00003009 QualType Result = TL.getType();
3010 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003011 E.get() != TL.getUnderlyingExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003012 Result = getDerived().RebuildTypeOfExprType(move(E));
3013 if (Result.isNull())
3014 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003015 }
John McCalla2becad2009-10-21 00:40:46 +00003016 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003017
John McCalla2becad2009-10-21 00:40:46 +00003018 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003019 NewTL.setTypeofLoc(TL.getTypeofLoc());
3020 NewTL.setLParenLoc(TL.getLParenLoc());
3021 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003022
3023 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003024}
Mike Stump1eb44332009-09-09 15:08:12 +00003025
3026template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003027QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003028 TypeOfTypeLoc TL,
3029 QualType ObjectType) {
John McCallcfb708c2010-01-13 20:03:27 +00003030 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3031 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3032 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003033 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003034
John McCalla2becad2009-10-21 00:40:46 +00003035 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003036 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3037 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003038 if (Result.isNull())
3039 return QualType();
3040 }
Mike Stump1eb44332009-09-09 15:08:12 +00003041
John McCalla2becad2009-10-21 00:40:46 +00003042 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003043 NewTL.setTypeofLoc(TL.getTypeofLoc());
3044 NewTL.setLParenLoc(TL.getLParenLoc());
3045 NewTL.setRParenLoc(TL.getRParenLoc());
3046 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003047
3048 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003049}
Mike Stump1eb44332009-09-09 15:08:12 +00003050
3051template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003052QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003053 DecltypeTypeLoc TL,
3054 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003055 DecltypeType *T = TL.getTypePtr();
3056
Douglas Gregor670444e2009-08-04 22:27:00 +00003057 // decltype expressions are not potentially evaluated contexts
3058 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003059
Douglas Gregor577f75a2009-08-04 16:50:30 +00003060 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3061 if (E.isInvalid())
3062 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003063
John McCalla2becad2009-10-21 00:40:46 +00003064 QualType Result = TL.getType();
3065 if (getDerived().AlwaysRebuild() ||
3066 E.get() != T->getUnderlyingExpr()) {
3067 Result = getDerived().RebuildDecltypeType(move(E));
3068 if (Result.isNull())
3069 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003070 }
John McCalla2becad2009-10-21 00:40:46 +00003071 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003072
John McCalla2becad2009-10-21 00:40:46 +00003073 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3074 NewTL.setNameLoc(TL.getNameLoc());
3075
3076 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003077}
3078
3079template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003080QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003081 RecordTypeLoc TL,
3082 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003083 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003084 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003085 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3086 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003087 if (!Record)
3088 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003089
John McCalla2becad2009-10-21 00:40:46 +00003090 QualType Result = TL.getType();
3091 if (getDerived().AlwaysRebuild() ||
3092 Record != T->getDecl()) {
3093 Result = getDerived().RebuildRecordType(Record);
3094 if (Result.isNull())
3095 return QualType();
3096 }
Mike Stump1eb44332009-09-09 15:08:12 +00003097
John McCalla2becad2009-10-21 00:40:46 +00003098 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3099 NewTL.setNameLoc(TL.getNameLoc());
3100
3101 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003102}
Mike Stump1eb44332009-09-09 15:08:12 +00003103
3104template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003105QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003106 EnumTypeLoc TL,
3107 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003108 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003109 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003110 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3111 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003112 if (!Enum)
3113 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003114
John McCalla2becad2009-10-21 00:40:46 +00003115 QualType Result = TL.getType();
3116 if (getDerived().AlwaysRebuild() ||
3117 Enum != T->getDecl()) {
3118 Result = getDerived().RebuildEnumType(Enum);
3119 if (Result.isNull())
3120 return QualType();
3121 }
Mike Stump1eb44332009-09-09 15:08:12 +00003122
John McCalla2becad2009-10-21 00:40:46 +00003123 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3124 NewTL.setNameLoc(TL.getNameLoc());
3125
3126 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003127}
John McCall7da24312009-09-05 00:15:47 +00003128
John McCall3cb0ebd2010-03-10 03:28:59 +00003129template<typename Derived>
3130QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3131 TypeLocBuilder &TLB,
3132 InjectedClassNameTypeLoc TL,
3133 QualType ObjectType) {
3134 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3135 TL.getTypePtr()->getDecl());
3136 if (!D) return QualType();
3137
3138 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3139 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3140 return T;
3141}
3142
Mike Stump1eb44332009-09-09 15:08:12 +00003143
Douglas Gregor577f75a2009-08-04 16:50:30 +00003144template<typename Derived>
3145QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003146 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003147 TemplateTypeParmTypeLoc TL,
3148 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003149 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003150}
3151
Mike Stump1eb44332009-09-09 15:08:12 +00003152template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003153QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003154 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003155 SubstTemplateTypeParmTypeLoc TL,
3156 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003157 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003158}
3159
3160template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003161QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3162 const TemplateSpecializationType *TST,
3163 QualType ObjectType) {
3164 // FIXME: this entire method is a temporary workaround; callers
3165 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00003166
John McCall833ca992009-10-29 08:12:44 +00003167 // Fake up a TemplateSpecializationTypeLoc.
3168 TypeLocBuilder TLB;
3169 TemplateSpecializationTypeLoc TL
3170 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3171
John McCall828bff22009-10-29 18:45:58 +00003172 SourceLocation BaseLoc = getDerived().getBaseLocation();
3173
3174 TL.setTemplateNameLoc(BaseLoc);
3175 TL.setLAngleLoc(BaseLoc);
3176 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00003177 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3178 const TemplateArgument &TA = TST->getArg(i);
3179 TemplateArgumentLoc TAL;
3180 getDerived().InventTemplateArgumentLoc(TA, TAL);
3181 TL.setArgLocInfo(i, TAL.getLocInfo());
3182 }
3183
3184 TypeLocBuilder IgnoredTLB;
3185 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00003186}
Sean Huntc3021132010-05-05 15:23:54 +00003187
Douglas Gregordd62b152009-10-19 22:04:39 +00003188template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003189QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003190 TypeLocBuilder &TLB,
3191 TemplateSpecializationTypeLoc TL,
3192 QualType ObjectType) {
3193 const TemplateSpecializationType *T = TL.getTypePtr();
3194
Mike Stump1eb44332009-09-09 15:08:12 +00003195 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00003196 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003197 if (Template.isNull())
3198 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003199
John McCalld5532b62009-11-23 01:53:49 +00003200 TemplateArgumentListInfo NewTemplateArgs;
3201 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3202 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3203
3204 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3205 TemplateArgumentLoc Loc;
3206 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00003207 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00003208 NewTemplateArgs.addArgument(Loc);
3209 }
Mike Stump1eb44332009-09-09 15:08:12 +00003210
John McCall833ca992009-10-29 08:12:44 +00003211 // FIXME: maybe don't rebuild if all the template arguments are the same.
3212
3213 QualType Result =
3214 getDerived().RebuildTemplateSpecializationType(Template,
3215 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003216 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003217
3218 if (!Result.isNull()) {
3219 TemplateSpecializationTypeLoc NewTL
3220 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3221 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3222 NewTL.setLAngleLoc(TL.getLAngleLoc());
3223 NewTL.setRAngleLoc(TL.getRAngleLoc());
3224 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3225 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003226 }
Mike Stump1eb44332009-09-09 15:08:12 +00003227
John McCall833ca992009-10-29 08:12:44 +00003228 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003229}
Mike Stump1eb44332009-09-09 15:08:12 +00003230
3231template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003232QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003233TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3234 ElaboratedTypeLoc TL,
3235 QualType ObjectType) {
3236 ElaboratedType *T = TL.getTypePtr();
3237
3238 NestedNameSpecifier *NNS = 0;
3239 // NOTE: the qualifier in an ElaboratedType is optional.
3240 if (T->getQualifier() != 0) {
3241 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003242 TL.getQualifierRange(),
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003243 ObjectType);
3244 if (!NNS)
3245 return QualType();
3246 }
Mike Stump1eb44332009-09-09 15:08:12 +00003247
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003248 QualType NamedT;
3249 // FIXME: this test is meant to workaround a problem (failing assertion)
3250 // occurring if directly executing the code in the else branch.
3251 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3252 TemplateSpecializationTypeLoc OldNamedTL
3253 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3254 const TemplateSpecializationType* OldTST
Jim Grosbach9cbb4d82010-05-19 23:53:08 +00003255 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003256 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3257 if (NamedT.isNull())
3258 return QualType();
3259 TemplateSpecializationTypeLoc NewNamedTL
3260 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3261 NewNamedTL.copy(OldNamedTL);
3262 }
3263 else {
3264 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3265 if (NamedT.isNull())
3266 return QualType();
3267 }
Daniel Dunbara63db842010-05-14 16:34:09 +00003268
John McCalla2becad2009-10-21 00:40:46 +00003269 QualType Result = TL.getType();
3270 if (getDerived().AlwaysRebuild() ||
3271 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003272 NamedT != T->getNamedType()) {
3273 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00003274 if (Result.isNull())
3275 return QualType();
3276 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003277
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003278 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003279 NewTL.setKeywordLoc(TL.getKeywordLoc());
3280 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00003281
3282 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003283}
Mike Stump1eb44332009-09-09 15:08:12 +00003284
3285template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003286QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3287 DependentNameTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00003288 QualType ObjectType) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003289 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003290
Douglas Gregor577f75a2009-08-04 16:50:30 +00003291 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003292 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3293 TL.getQualifierRange(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003294 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003295 if (!NNS)
3296 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003297
John McCalla2becad2009-10-21 00:40:46 +00003298 QualType Result;
3299
Douglas Gregor577f75a2009-08-04 16:50:30 +00003300 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump1eb44332009-09-09 15:08:12 +00003301 QualType NewTemplateId
Douglas Gregor577f75a2009-08-04 16:50:30 +00003302 = getDerived().TransformType(QualType(TemplateId, 0));
3303 if (NewTemplateId.isNull())
3304 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003305
Douglas Gregor577f75a2009-08-04 16:50:30 +00003306 if (!getDerived().AlwaysRebuild() &&
3307 NNS == T->getQualifier() &&
3308 NewTemplateId == QualType(TemplateId, 0))
3309 return QualType(T, 0);
Mike Stump1eb44332009-09-09 15:08:12 +00003310
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003311 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
Douglas Gregor4a2023f2010-03-31 20:19:30 +00003312 NewTemplateId);
John McCalla2becad2009-10-21 00:40:46 +00003313 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003314 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3315 T->getIdentifier(),
3316 TL.getKeywordLoc(),
3317 TL.getQualifierRange(),
3318 TL.getNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003319 }
John McCalla2becad2009-10-21 00:40:46 +00003320 if (Result.isNull())
3321 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003322
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003323 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3324 QualType NamedT = ElabT->getNamedType();
3325 if (isa<TemplateSpecializationType>(NamedT)) {
3326 TemplateSpecializationTypeLoc NamedTLoc
3327 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3328 // FIXME: fill locations
3329 NamedTLoc.initializeLocal(TL.getNameLoc());
3330 } else {
3331 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3332 }
3333 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3334 NewTL.setKeywordLoc(TL.getKeywordLoc());
3335 NewTL.setQualifierRange(TL.getQualifierRange());
3336 }
3337 else {
3338 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3339 NewTL.setKeywordLoc(TL.getKeywordLoc());
3340 NewTL.setQualifierRange(TL.getQualifierRange());
3341 NewTL.setNameLoc(TL.getNameLoc());
3342 }
John McCalla2becad2009-10-21 00:40:46 +00003343 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003344}
Mike Stump1eb44332009-09-09 15:08:12 +00003345
Douglas Gregor577f75a2009-08-04 16:50:30 +00003346template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003347QualType
3348TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003349 ObjCInterfaceTypeLoc TL,
3350 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003351 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003352 TLB.pushFullCopy(TL);
3353 return TL.getType();
3354}
3355
3356template<typename Derived>
3357QualType
3358TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3359 ObjCObjectTypeLoc TL,
3360 QualType ObjectType) {
3361 // ObjCObjectType is never dependent.
3362 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003363 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003364}
Mike Stump1eb44332009-09-09 15:08:12 +00003365
3366template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003367QualType
3368TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003369 ObjCObjectPointerTypeLoc TL,
3370 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003371 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003372 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003373 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003374}
3375
Douglas Gregor577f75a2009-08-04 16:50:30 +00003376//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003377// Statement transformation
3378//===----------------------------------------------------------------------===//
3379template<typename Derived>
3380Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003381TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3382 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003383}
3384
3385template<typename Derived>
3386Sema::OwningStmtResult
3387TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3388 return getDerived().TransformCompoundStmt(S, false);
3389}
3390
3391template<typename Derived>
3392Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003393TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003394 bool IsStmtExpr) {
3395 bool SubStmtChanged = false;
3396 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3397 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3398 B != BEnd; ++B) {
3399 OwningStmtResult Result = getDerived().TransformStmt(*B);
3400 if (Result.isInvalid())
3401 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003402
Douglas Gregor43959a92009-08-20 07:17:43 +00003403 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3404 Statements.push_back(Result.takeAs<Stmt>());
3405 }
Mike Stump1eb44332009-09-09 15:08:12 +00003406
Douglas Gregor43959a92009-08-20 07:17:43 +00003407 if (!getDerived().AlwaysRebuild() &&
3408 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003409 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003410
3411 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3412 move_arg(Statements),
3413 S->getRBracLoc(),
3414 IsStmtExpr);
3415}
Mike Stump1eb44332009-09-09 15:08:12 +00003416
Douglas Gregor43959a92009-08-20 07:17:43 +00003417template<typename Derived>
3418Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003419TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman264c1f82009-11-19 03:14:00 +00003420 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3421 {
3422 // The case value expressions are not potentially evaluated.
3423 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003424
Eli Friedman264c1f82009-11-19 03:14:00 +00003425 // Transform the left-hand case value.
3426 LHS = getDerived().TransformExpr(S->getLHS());
3427 if (LHS.isInvalid())
3428 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003429
Eli Friedman264c1f82009-11-19 03:14:00 +00003430 // Transform the right-hand case value (for the GNU case-range extension).
3431 RHS = getDerived().TransformExpr(S->getRHS());
3432 if (RHS.isInvalid())
3433 return SemaRef.StmtError();
3434 }
Mike Stump1eb44332009-09-09 15:08:12 +00003435
Douglas Gregor43959a92009-08-20 07:17:43 +00003436 // Build the case statement.
3437 // Case statements are always rebuilt so that they will attached to their
3438 // transformed switch statement.
3439 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3440 move(LHS),
3441 S->getEllipsisLoc(),
3442 move(RHS),
3443 S->getColonLoc());
3444 if (Case.isInvalid())
3445 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003446
Douglas Gregor43959a92009-08-20 07:17:43 +00003447 // Transform the statement following the case
3448 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3449 if (SubStmt.isInvalid())
3450 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003451
Douglas Gregor43959a92009-08-20 07:17:43 +00003452 // Attach the body to the case statement
3453 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3454}
3455
3456template<typename Derived>
3457Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003458TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003459 // Transform the statement following the default case
3460 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3461 if (SubStmt.isInvalid())
3462 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003463
Douglas Gregor43959a92009-08-20 07:17:43 +00003464 // Default statements are always rebuilt
3465 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3466 move(SubStmt));
3467}
Mike Stump1eb44332009-09-09 15:08:12 +00003468
Douglas Gregor43959a92009-08-20 07:17:43 +00003469template<typename Derived>
3470Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003471TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003472 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3473 if (SubStmt.isInvalid())
3474 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003475
Douglas Gregor43959a92009-08-20 07:17:43 +00003476 // FIXME: Pass the real colon location in.
3477 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3478 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3479 move(SubStmt));
3480}
Mike Stump1eb44332009-09-09 15:08:12 +00003481
Douglas Gregor43959a92009-08-20 07:17:43 +00003482template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003483Sema::OwningStmtResult
3484TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003485 // Transform the condition
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003486 OwningExprResult Cond(SemaRef);
3487 VarDecl *ConditionVar = 0;
3488 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003489 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003490 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003491 getDerived().TransformDefinition(
3492 S->getConditionVariable()->getLocation(),
3493 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003494 if (!ConditionVar)
3495 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003496 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003497 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003498
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003499 if (Cond.isInvalid())
3500 return SemaRef.StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003501
3502 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003503 if (S->getCond()) {
3504 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3505 S->getIfLoc(),
3506 move(Cond));
3507 if (CondE.isInvalid())
3508 return getSema().StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003509
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003510 Cond = move(CondE);
3511 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003512 }
Sean Huntc3021132010-05-05 15:23:54 +00003513
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003514 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3515 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3516 return SemaRef.StmtError();
3517
Douglas Gregor43959a92009-08-20 07:17:43 +00003518 // Transform the "then" branch.
3519 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3520 if (Then.isInvalid())
3521 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003522
Douglas Gregor43959a92009-08-20 07:17:43 +00003523 // Transform the "else" branch.
3524 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3525 if (Else.isInvalid())
3526 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003527
Douglas Gregor43959a92009-08-20 07:17:43 +00003528 if (!getDerived().AlwaysRebuild() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003529 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003530 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003531 Then.get() == S->getThen() &&
3532 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003533 return SemaRef.Owned(S->Retain());
3534
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003535 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003536 move(Then),
Mike Stump1eb44332009-09-09 15:08:12 +00003537 S->getElseLoc(), move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +00003538}
3539
3540template<typename Derived>
3541Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003542TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003543 // Transform the condition.
Douglas Gregord3d53012009-11-24 17:07:59 +00003544 OwningExprResult Cond(SemaRef);
3545 VarDecl *ConditionVar = 0;
3546 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003547 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00003548 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003549 getDerived().TransformDefinition(
3550 S->getConditionVariable()->getLocation(),
3551 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003552 if (!ConditionVar)
3553 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003554 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003555 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003556
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003557 if (Cond.isInvalid())
3558 return SemaRef.StmtError();
3559 }
Mike Stump1eb44332009-09-09 15:08:12 +00003560
Douglas Gregor43959a92009-08-20 07:17:43 +00003561 // Rebuild the switch statement.
Douglas Gregor586596f2010-05-06 17:25:47 +00003562 OwningStmtResult Switch
3563 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond),
3564 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003565 if (Switch.isInvalid())
3566 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003567
Douglas Gregor43959a92009-08-20 07:17:43 +00003568 // Transform the body of the switch statement.
3569 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3570 if (Body.isInvalid())
3571 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003572
Douglas Gregor43959a92009-08-20 07:17:43 +00003573 // Complete the switch statement.
3574 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3575 move(Body));
3576}
Mike Stump1eb44332009-09-09 15:08:12 +00003577
Douglas Gregor43959a92009-08-20 07:17:43 +00003578template<typename Derived>
3579Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003580TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003581 // Transform the condition
Douglas Gregor5656e142009-11-24 21:15:44 +00003582 OwningExprResult Cond(SemaRef);
3583 VarDecl *ConditionVar = 0;
3584 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003585 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00003586 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003587 getDerived().TransformDefinition(
3588 S->getConditionVariable()->getLocation(),
3589 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003590 if (!ConditionVar)
3591 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003592 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003593 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003594
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003595 if (Cond.isInvalid())
3596 return SemaRef.StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003597
3598 if (S->getCond()) {
3599 // Convert the condition to a boolean value.
3600 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003601 S->getWhileLoc(),
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003602 move(Cond));
3603 if (CondE.isInvalid())
3604 return getSema().StmtError();
3605 Cond = move(CondE);
3606 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003607 }
Mike Stump1eb44332009-09-09 15:08:12 +00003608
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003609 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3610 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3611 return SemaRef.StmtError();
3612
Douglas Gregor43959a92009-08-20 07:17:43 +00003613 // Transform the body
3614 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3615 if (Body.isInvalid())
3616 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003617
Douglas Gregor43959a92009-08-20 07:17:43 +00003618 if (!getDerived().AlwaysRebuild() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003619 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003620 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003621 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003622 return SemaRef.Owned(S->Retain());
3623
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003624 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
Douglas Gregor586596f2010-05-06 17:25:47 +00003625 ConditionVar, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003626}
Mike Stump1eb44332009-09-09 15:08:12 +00003627
Douglas Gregor43959a92009-08-20 07:17:43 +00003628template<typename Derived>
3629Sema::OwningStmtResult
3630TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003631 // Transform the body
3632 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3633 if (Body.isInvalid())
3634 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003635
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003636 // Transform the condition
3637 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3638 if (Cond.isInvalid())
3639 return SemaRef.StmtError();
3640
Douglas Gregor43959a92009-08-20 07:17:43 +00003641 if (!getDerived().AlwaysRebuild() &&
3642 Cond.get() == S->getCond() &&
3643 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003644 return SemaRef.Owned(S->Retain());
3645
Douglas Gregor43959a92009-08-20 07:17:43 +00003646 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3647 /*FIXME:*/S->getWhileLoc(), move(Cond),
3648 S->getRParenLoc());
3649}
Mike Stump1eb44332009-09-09 15:08:12 +00003650
Douglas Gregor43959a92009-08-20 07:17:43 +00003651template<typename Derived>
3652Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003653TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003654 // Transform the initialization statement
3655 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3656 if (Init.isInvalid())
3657 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003658
Douglas Gregor43959a92009-08-20 07:17:43 +00003659 // Transform the condition
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003660 OwningExprResult Cond(SemaRef);
3661 VarDecl *ConditionVar = 0;
3662 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003663 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003664 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003665 getDerived().TransformDefinition(
3666 S->getConditionVariable()->getLocation(),
3667 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003668 if (!ConditionVar)
3669 return SemaRef.StmtError();
3670 } else {
3671 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003672
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003673 if (Cond.isInvalid())
3674 return SemaRef.StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003675
3676 if (S->getCond()) {
3677 // Convert the condition to a boolean value.
3678 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3679 S->getForLoc(),
3680 move(Cond));
3681 if (CondE.isInvalid())
3682 return getSema().StmtError();
3683
3684 Cond = move(CondE);
3685 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003686 }
Mike Stump1eb44332009-09-09 15:08:12 +00003687
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003688 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3689 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3690 return SemaRef.StmtError();
3691
Douglas Gregor43959a92009-08-20 07:17:43 +00003692 // Transform the increment
3693 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3694 if (Inc.isInvalid())
3695 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003696
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003697 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc));
3698 if (S->getInc() && !FullInc->get())
3699 return SemaRef.StmtError();
3700
Douglas Gregor43959a92009-08-20 07:17:43 +00003701 // Transform the body
3702 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3703 if (Body.isInvalid())
3704 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003705
Douglas Gregor43959a92009-08-20 07:17:43 +00003706 if (!getDerived().AlwaysRebuild() &&
3707 Init.get() == S->getInit() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003708 FullCond->get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003709 Inc.get() == S->getInc() &&
3710 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003711 return SemaRef.Owned(S->Retain());
3712
Douglas Gregor43959a92009-08-20 07:17:43 +00003713 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003714 move(Init), FullCond, ConditionVar,
3715 FullInc, S->getRParenLoc(), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003716}
3717
3718template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003719Sema::OwningStmtResult
3720TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003721 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003722 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003723 S->getLabel());
3724}
3725
3726template<typename Derived>
3727Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003728TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003729 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3730 if (Target.isInvalid())
3731 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003732
Douglas Gregor43959a92009-08-20 07:17:43 +00003733 if (!getDerived().AlwaysRebuild() &&
3734 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003735 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003736
3737 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3738 move(Target));
3739}
3740
3741template<typename Derived>
3742Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003743TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3744 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003745}
Mike Stump1eb44332009-09-09 15:08:12 +00003746
Douglas Gregor43959a92009-08-20 07:17:43 +00003747template<typename Derived>
3748Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003749TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3750 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003751}
Mike Stump1eb44332009-09-09 15:08:12 +00003752
Douglas Gregor43959a92009-08-20 07:17:43 +00003753template<typename Derived>
3754Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003755TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003756 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3757 if (Result.isInvalid())
3758 return SemaRef.StmtError();
3759
Mike Stump1eb44332009-09-09 15:08:12 +00003760 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003761 // to tell whether the return type of the function has changed.
3762 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3763}
Mike Stump1eb44332009-09-09 15:08:12 +00003764
Douglas Gregor43959a92009-08-20 07:17:43 +00003765template<typename Derived>
3766Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003767TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003768 bool DeclChanged = false;
3769 llvm::SmallVector<Decl *, 4> Decls;
3770 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3771 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003772 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3773 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003774 if (!Transformed)
3775 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003776
Douglas Gregor43959a92009-08-20 07:17:43 +00003777 if (Transformed != *D)
3778 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003779
Douglas Gregor43959a92009-08-20 07:17:43 +00003780 Decls.push_back(Transformed);
3781 }
Mike Stump1eb44332009-09-09 15:08:12 +00003782
Douglas Gregor43959a92009-08-20 07:17:43 +00003783 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003784 return SemaRef.Owned(S->Retain());
3785
3786 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003787 S->getStartLoc(), S->getEndLoc());
3788}
Mike Stump1eb44332009-09-09 15:08:12 +00003789
Douglas Gregor43959a92009-08-20 07:17:43 +00003790template<typename Derived>
3791Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003792TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003793 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003794 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003795}
3796
3797template<typename Derived>
3798Sema::OwningStmtResult
3799TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00003800
Anders Carlsson703e3942010-01-24 05:50:09 +00003801 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3802 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003803 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003804
Anders Carlsson703e3942010-01-24 05:50:09 +00003805 OwningExprResult AsmString(SemaRef);
3806 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3807
3808 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00003809
Anders Carlsson703e3942010-01-24 05:50:09 +00003810 // Go through the outputs.
3811 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003812 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003813
Anders Carlsson703e3942010-01-24 05:50:09 +00003814 // No need to transform the constraint literal.
3815 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003816
Anders Carlsson703e3942010-01-24 05:50:09 +00003817 // Transform the output expr.
3818 Expr *OutputExpr = S->getOutputExpr(I);
3819 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3820 if (Result.isInvalid())
3821 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003822
Anders Carlsson703e3942010-01-24 05:50:09 +00003823 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003824
Anders Carlsson703e3942010-01-24 05:50:09 +00003825 Exprs.push_back(Result.takeAs<Expr>());
3826 }
Sean Huntc3021132010-05-05 15:23:54 +00003827
Anders Carlsson703e3942010-01-24 05:50:09 +00003828 // Go through the inputs.
3829 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003830 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003831
Anders Carlsson703e3942010-01-24 05:50:09 +00003832 // No need to transform the constraint literal.
3833 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003834
Anders Carlsson703e3942010-01-24 05:50:09 +00003835 // Transform the input expr.
3836 Expr *InputExpr = S->getInputExpr(I);
3837 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3838 if (Result.isInvalid())
3839 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003840
Anders Carlsson703e3942010-01-24 05:50:09 +00003841 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003842
Anders Carlsson703e3942010-01-24 05:50:09 +00003843 Exprs.push_back(Result.takeAs<Expr>());
3844 }
Sean Huntc3021132010-05-05 15:23:54 +00003845
Anders Carlsson703e3942010-01-24 05:50:09 +00003846 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3847 return SemaRef.Owned(S->Retain());
3848
3849 // Go through the clobbers.
3850 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3851 Clobbers.push_back(S->getClobber(I)->Retain());
3852
3853 // No need to transform the asm string literal.
3854 AsmString = SemaRef.Owned(S->getAsmString());
3855
3856 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3857 S->isSimple(),
3858 S->isVolatile(),
3859 S->getNumOutputs(),
3860 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003861 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003862 move_arg(Constraints),
3863 move_arg(Exprs),
3864 move(AsmString),
3865 move_arg(Clobbers),
3866 S->getRParenLoc(),
3867 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003868}
3869
3870
3871template<typename Derived>
3872Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003873TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003874 // Transform the body of the @try.
3875 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3876 if (TryBody.isInvalid())
3877 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003878
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003879 // Transform the @catch statements (if present).
3880 bool AnyCatchChanged = false;
3881 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3882 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3883 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003884 if (Catch.isInvalid())
3885 return SemaRef.StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003886 if (Catch.get() != S->getCatchStmt(I))
3887 AnyCatchChanged = true;
3888 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003889 }
Sean Huntc3021132010-05-05 15:23:54 +00003890
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003891 // Transform the @finally statement (if present).
3892 OwningStmtResult Finally(SemaRef);
3893 if (S->getFinallyStmt()) {
3894 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3895 if (Finally.isInvalid())
3896 return SemaRef.StmtError();
3897 }
3898
3899 // If nothing changed, just retain this statement.
3900 if (!getDerived().AlwaysRebuild() &&
3901 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003902 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003903 Finally.get() == S->getFinallyStmt())
3904 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003905
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003906 // Build a new statement.
3907 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003908 move_arg(CatchStmts), move(Finally));
Douglas Gregor43959a92009-08-20 07:17:43 +00003909}
Mike Stump1eb44332009-09-09 15:08:12 +00003910
Douglas Gregor43959a92009-08-20 07:17:43 +00003911template<typename Derived>
3912Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003913TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00003914 // Transform the @catch parameter, if there is one.
3915 VarDecl *Var = 0;
3916 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3917 TypeSourceInfo *TSInfo = 0;
3918 if (FromVar->getTypeSourceInfo()) {
3919 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3920 if (!TSInfo)
3921 return SemaRef.StmtError();
3922 }
Sean Huntc3021132010-05-05 15:23:54 +00003923
Douglas Gregorbe270a02010-04-26 17:57:08 +00003924 QualType T;
3925 if (TSInfo)
3926 T = TSInfo->getType();
3927 else {
3928 T = getDerived().TransformType(FromVar->getType());
3929 if (T.isNull())
Sean Huntc3021132010-05-05 15:23:54 +00003930 return SemaRef.StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00003931 }
Sean Huntc3021132010-05-05 15:23:54 +00003932
Douglas Gregorbe270a02010-04-26 17:57:08 +00003933 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3934 if (!Var)
3935 return SemaRef.StmtError();
3936 }
Sean Huntc3021132010-05-05 15:23:54 +00003937
Douglas Gregorbe270a02010-04-26 17:57:08 +00003938 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3939 if (Body.isInvalid())
3940 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003941
3942 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00003943 S->getRParenLoc(),
3944 Var, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003945}
Mike Stump1eb44332009-09-09 15:08:12 +00003946
Douglas Gregor43959a92009-08-20 07:17:43 +00003947template<typename Derived>
3948Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003949TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003950 // Transform the body.
3951 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
3952 if (Body.isInvalid())
3953 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003954
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003955 // If nothing changed, just retain this statement.
3956 if (!getDerived().AlwaysRebuild() &&
3957 Body.get() == S->getFinallyBody())
3958 return SemaRef.Owned(S->Retain());
3959
3960 // Build a new statement.
3961 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
3962 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003963}
Mike Stump1eb44332009-09-09 15:08:12 +00003964
Douglas Gregor43959a92009-08-20 07:17:43 +00003965template<typename Derived>
3966Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003967TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregord1377b22010-04-22 21:44:01 +00003968 OwningExprResult Operand(SemaRef);
3969 if (S->getThrowExpr()) {
3970 Operand = getDerived().TransformExpr(S->getThrowExpr());
3971 if (Operand.isInvalid())
3972 return getSema().StmtError();
3973 }
Sean Huntc3021132010-05-05 15:23:54 +00003974
Douglas Gregord1377b22010-04-22 21:44:01 +00003975 if (!getDerived().AlwaysRebuild() &&
3976 Operand.get() == S->getThrowExpr())
3977 return getSema().Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003978
Douglas Gregord1377b22010-04-22 21:44:01 +00003979 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregor43959a92009-08-20 07:17:43 +00003980}
Mike Stump1eb44332009-09-09 15:08:12 +00003981
Douglas Gregor43959a92009-08-20 07:17:43 +00003982template<typename Derived>
3983Sema::OwningStmtResult
3984TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003985 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00003986 // Transform the object we are locking.
3987 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
3988 if (Object.isInvalid())
3989 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003990
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00003991 // Transform the body.
3992 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
3993 if (Body.isInvalid())
3994 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003995
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00003996 // If nothing change, just retain the current statement.
3997 if (!getDerived().AlwaysRebuild() &&
3998 Object.get() == S->getSynchExpr() &&
3999 Body.get() == S->getSynchBody())
4000 return SemaRef.Owned(S->Retain());
4001
4002 // Build a new statement.
4003 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
4004 move(Object), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004005}
4006
4007template<typename Derived>
4008Sema::OwningStmtResult
4009TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004010 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004011 // Transform the element statement.
4012 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
4013 if (Element.isInvalid())
4014 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004015
Douglas Gregorc3203e72010-04-22 23:10:45 +00004016 // Transform the collection expression.
4017 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
4018 if (Collection.isInvalid())
4019 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004020
Douglas Gregorc3203e72010-04-22 23:10:45 +00004021 // Transform the body.
4022 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
4023 if (Body.isInvalid())
4024 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004025
Douglas Gregorc3203e72010-04-22 23:10:45 +00004026 // If nothing changed, just retain this statement.
4027 if (!getDerived().AlwaysRebuild() &&
4028 Element.get() == S->getElement() &&
4029 Collection.get() == S->getCollection() &&
4030 Body.get() == S->getBody())
4031 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004032
Douglas Gregorc3203e72010-04-22 23:10:45 +00004033 // Build a new statement.
4034 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4035 /*FIXME:*/S->getForLoc(),
4036 move(Element),
4037 move(Collection),
4038 S->getRParenLoc(),
4039 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004040}
4041
4042
4043template<typename Derived>
4044Sema::OwningStmtResult
4045TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4046 // Transform the exception declaration, if any.
4047 VarDecl *Var = 0;
4048 if (S->getExceptionDecl()) {
4049 VarDecl *ExceptionDecl = S->getExceptionDecl();
4050 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4051 ExceptionDecl->getDeclName());
4052
4053 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4054 if (T.isNull())
4055 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004056
Douglas Gregor43959a92009-08-20 07:17:43 +00004057 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4058 T,
John McCalla93c9342009-12-07 02:54:59 +00004059 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004060 ExceptionDecl->getIdentifier(),
4061 ExceptionDecl->getLocation(),
4062 /*FIXME: Inaccurate*/
4063 SourceRange(ExceptionDecl->getLocation()));
4064 if (!Var || Var->isInvalidDecl()) {
4065 if (Var)
4066 Var->Destroy(SemaRef.Context);
4067 return SemaRef.StmtError();
4068 }
4069 }
Mike Stump1eb44332009-09-09 15:08:12 +00004070
Douglas Gregor43959a92009-08-20 07:17:43 +00004071 // Transform the actual exception handler.
4072 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
4073 if (Handler.isInvalid()) {
4074 if (Var)
4075 Var->Destroy(SemaRef.Context);
4076 return SemaRef.StmtError();
4077 }
Mike Stump1eb44332009-09-09 15:08:12 +00004078
Douglas Gregor43959a92009-08-20 07:17:43 +00004079 if (!getDerived().AlwaysRebuild() &&
4080 !Var &&
4081 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00004082 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004083
4084 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4085 Var,
4086 move(Handler));
4087}
Mike Stump1eb44332009-09-09 15:08:12 +00004088
Douglas Gregor43959a92009-08-20 07:17:43 +00004089template<typename Derived>
4090Sema::OwningStmtResult
4091TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4092 // Transform the try block itself.
Mike Stump1eb44332009-09-09 15:08:12 +00004093 OwningStmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004094 = getDerived().TransformCompoundStmt(S->getTryBlock());
4095 if (TryBlock.isInvalid())
4096 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004097
Douglas Gregor43959a92009-08-20 07:17:43 +00004098 // Transform the handlers.
4099 bool HandlerChanged = false;
4100 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4101 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump1eb44332009-09-09 15:08:12 +00004102 OwningStmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004103 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4104 if (Handler.isInvalid())
4105 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004106
Douglas Gregor43959a92009-08-20 07:17:43 +00004107 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4108 Handlers.push_back(Handler.takeAs<Stmt>());
4109 }
Mike Stump1eb44332009-09-09 15:08:12 +00004110
Douglas Gregor43959a92009-08-20 07:17:43 +00004111 if (!getDerived().AlwaysRebuild() &&
4112 TryBlock.get() == S->getTryBlock() &&
4113 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004114 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004115
4116 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump1eb44332009-09-09 15:08:12 +00004117 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004118}
Mike Stump1eb44332009-09-09 15:08:12 +00004119
Douglas Gregor43959a92009-08-20 07:17:43 +00004120//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004121// Expression transformation
4122//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004123template<typename Derived>
4124Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004125TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004126 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004127}
Mike Stump1eb44332009-09-09 15:08:12 +00004128
4129template<typename Derived>
4130Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004131TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004132 NestedNameSpecifier *Qualifier = 0;
4133 if (E->getQualifier()) {
4134 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004135 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004136 if (!Qualifier)
4137 return SemaRef.ExprError();
4138 }
John McCalldbd872f2009-12-08 09:08:17 +00004139
4140 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004141 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4142 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004143 if (!ND)
4144 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004145
Sean Huntc3021132010-05-05 15:23:54 +00004146 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004147 Qualifier == E->getQualifier() &&
4148 ND == E->getDecl() &&
John McCalldbd872f2009-12-08 09:08:17 +00004149 !E->hasExplicitTemplateArgumentList()) {
4150
4151 // Mark it referenced in the new context regardless.
4152 // FIXME: this is a bit instantiation-specific.
4153 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4154
Mike Stump1eb44332009-09-09 15:08:12 +00004155 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004156 }
John McCalldbd872f2009-12-08 09:08:17 +00004157
4158 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4159 if (E->hasExplicitTemplateArgumentList()) {
4160 TemplateArgs = &TransArgs;
4161 TransArgs.setLAngleLoc(E->getLAngleLoc());
4162 TransArgs.setRAngleLoc(E->getRAngleLoc());
4163 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4164 TemplateArgumentLoc Loc;
4165 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4166 return SemaRef.ExprError();
4167 TransArgs.addArgument(Loc);
4168 }
4169 }
4170
Douglas Gregora2813ce2009-10-23 18:54:35 +00004171 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCalldbd872f2009-12-08 09:08:17 +00004172 ND, E->getLocation(), TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004173}
Mike Stump1eb44332009-09-09 15:08:12 +00004174
Douglas Gregorb98b1992009-08-11 05:31:07 +00004175template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004176Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004177TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004178 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004179}
Mike Stump1eb44332009-09-09 15:08:12 +00004180
Douglas Gregorb98b1992009-08-11 05:31:07 +00004181template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004182Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004183TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004184 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004185}
Mike Stump1eb44332009-09-09 15:08:12 +00004186
Douglas Gregorb98b1992009-08-11 05:31:07 +00004187template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004188Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004189TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004190 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004191}
Mike Stump1eb44332009-09-09 15:08:12 +00004192
Douglas Gregorb98b1992009-08-11 05:31:07 +00004193template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004194Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004195TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004196 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004197}
Mike Stump1eb44332009-09-09 15:08:12 +00004198
Douglas Gregorb98b1992009-08-11 05:31:07 +00004199template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004200Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004201TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004202 return SemaRef.Owned(E->Retain());
4203}
4204
4205template<typename Derived>
4206Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004207TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004208 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4209 if (SubExpr.isInvalid())
4210 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004211
Douglas Gregorb98b1992009-08-11 05:31:07 +00004212 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004213 return SemaRef.Owned(E->Retain());
4214
4215 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004216 E->getRParen());
4217}
4218
Mike Stump1eb44332009-09-09 15:08:12 +00004219template<typename Derived>
4220Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004221TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4222 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004223 if (SubExpr.isInvalid())
4224 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004225
Douglas Gregorb98b1992009-08-11 05:31:07 +00004226 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004227 return SemaRef.Owned(E->Retain());
4228
Douglas Gregorb98b1992009-08-11 05:31:07 +00004229 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4230 E->getOpcode(),
4231 move(SubExpr));
4232}
Mike Stump1eb44332009-09-09 15:08:12 +00004233
Douglas Gregorb98b1992009-08-11 05:31:07 +00004234template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004235Sema::OwningExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004236TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4237 // Transform the type.
4238 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4239 if (!Type)
4240 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004241
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004242 // Transform all of the components into components similar to what the
4243 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004244 // FIXME: It would be slightly more efficient in the non-dependent case to
4245 // just map FieldDecls, rather than requiring the rebuilder to look for
4246 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004247 // template code that we don't care.
4248 bool ExprChanged = false;
4249 typedef Action::OffsetOfComponent Component;
4250 typedef OffsetOfExpr::OffsetOfNode Node;
4251 llvm::SmallVector<Component, 4> Components;
4252 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4253 const Node &ON = E->getComponent(I);
4254 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004255 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004256 Comp.LocStart = ON.getRange().getBegin();
4257 Comp.LocEnd = ON.getRange().getEnd();
4258 switch (ON.getKind()) {
4259 case Node::Array: {
4260 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4261 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4262 if (Index.isInvalid())
4263 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004264
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004265 ExprChanged = ExprChanged || Index.get() != FromIndex;
4266 Comp.isBrackets = true;
4267 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4268 break;
4269 }
Sean Huntc3021132010-05-05 15:23:54 +00004270
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004271 case Node::Field:
4272 case Node::Identifier:
4273 Comp.isBrackets = false;
4274 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004275 if (!Comp.U.IdentInfo)
4276 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004277
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004278 break;
Sean Huntc3021132010-05-05 15:23:54 +00004279
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004280 case Node::Base:
4281 // Will be recomputed during the rebuild.
4282 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004283 }
Sean Huntc3021132010-05-05 15:23:54 +00004284
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004285 Components.push_back(Comp);
4286 }
Sean Huntc3021132010-05-05 15:23:54 +00004287
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004288 // If nothing changed, retain the existing expression.
4289 if (!getDerived().AlwaysRebuild() &&
4290 Type == E->getTypeSourceInfo() &&
4291 !ExprChanged)
4292 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004293
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004294 // Build a new offsetof expression.
4295 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4296 Components.data(), Components.size(),
4297 E->getRParenLoc());
4298}
4299
4300template<typename Derived>
4301Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004302TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004303 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004304 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004305
John McCalla93c9342009-12-07 02:54:59 +00004306 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004307 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004308 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004309
John McCall5ab75172009-11-04 07:28:41 +00004310 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004311 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004312
John McCall5ab75172009-11-04 07:28:41 +00004313 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004314 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004315 E->getSourceRange());
4316 }
Mike Stump1eb44332009-09-09 15:08:12 +00004317
Douglas Gregorb98b1992009-08-11 05:31:07 +00004318 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00004319 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004320 // C++0x [expr.sizeof]p1:
4321 // The operand is either an expression, which is an unevaluated operand
4322 // [...]
4323 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004324
Douglas Gregorb98b1992009-08-11 05:31:07 +00004325 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4326 if (SubExpr.isInvalid())
4327 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004328
Douglas Gregorb98b1992009-08-11 05:31:07 +00004329 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4330 return SemaRef.Owned(E->Retain());
4331 }
Mike Stump1eb44332009-09-09 15:08:12 +00004332
Douglas Gregorb98b1992009-08-11 05:31:07 +00004333 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4334 E->isSizeOf(),
4335 E->getSourceRange());
4336}
Mike Stump1eb44332009-09-09 15:08:12 +00004337
Douglas Gregorb98b1992009-08-11 05:31:07 +00004338template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004339Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004340TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004341 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4342 if (LHS.isInvalid())
4343 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004344
Douglas Gregorb98b1992009-08-11 05:31:07 +00004345 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4346 if (RHS.isInvalid())
4347 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004348
4349
Douglas Gregorb98b1992009-08-11 05:31:07 +00004350 if (!getDerived().AlwaysRebuild() &&
4351 LHS.get() == E->getLHS() &&
4352 RHS.get() == E->getRHS())
4353 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004354
Douglas Gregorb98b1992009-08-11 05:31:07 +00004355 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4356 /*FIXME:*/E->getLHS()->getLocStart(),
4357 move(RHS),
4358 E->getRBracketLoc());
4359}
Mike Stump1eb44332009-09-09 15:08:12 +00004360
4361template<typename Derived>
4362Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004363TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004364 // Transform the callee.
4365 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4366 if (Callee.isInvalid())
4367 return SemaRef.ExprError();
4368
4369 // Transform arguments.
4370 bool ArgChanged = false;
4371 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4372 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4373 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4374 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4375 if (Arg.isInvalid())
4376 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004377
Douglas Gregorb98b1992009-08-11 05:31:07 +00004378 // FIXME: Wrong source location information for the ','.
4379 FakeCommaLocs.push_back(
4380 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00004381
4382 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004383 Args.push_back(Arg.takeAs<Expr>());
4384 }
Mike Stump1eb44332009-09-09 15:08:12 +00004385
Douglas Gregorb98b1992009-08-11 05:31:07 +00004386 if (!getDerived().AlwaysRebuild() &&
4387 Callee.get() == E->getCallee() &&
4388 !ArgChanged)
4389 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004390
Douglas Gregorb98b1992009-08-11 05:31:07 +00004391 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004392 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004393 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4394 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4395 move_arg(Args),
4396 FakeCommaLocs.data(),
4397 E->getRParenLoc());
4398}
Mike Stump1eb44332009-09-09 15:08:12 +00004399
4400template<typename Derived>
4401Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004402TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004403 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4404 if (Base.isInvalid())
4405 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004406
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004407 NestedNameSpecifier *Qualifier = 0;
4408 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004409 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004410 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004411 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004412 if (Qualifier == 0)
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004413 return SemaRef.ExprError();
4414 }
Mike Stump1eb44332009-09-09 15:08:12 +00004415
Eli Friedmanf595cc42009-12-04 06:40:45 +00004416 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004417 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4418 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004419 if (!Member)
4420 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004421
John McCall6bb80172010-03-30 21:47:33 +00004422 NamedDecl *FoundDecl = E->getFoundDecl();
4423 if (FoundDecl == E->getMemberDecl()) {
4424 FoundDecl = Member;
4425 } else {
4426 FoundDecl = cast_or_null<NamedDecl>(
4427 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4428 if (!FoundDecl)
4429 return SemaRef.ExprError();
4430 }
4431
Douglas Gregorb98b1992009-08-11 05:31:07 +00004432 if (!getDerived().AlwaysRebuild() &&
4433 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004434 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004435 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004436 FoundDecl == E->getFoundDecl() &&
Anders Carlsson1f240322009-12-22 05:24:09 +00004437 !E->hasExplicitTemplateArgumentList()) {
Sean Huntc3021132010-05-05 15:23:54 +00004438
Anders Carlsson1f240322009-12-22 05:24:09 +00004439 // Mark it referenced in the new context regardless.
4440 // FIXME: this is a bit instantiation-specific.
4441 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00004442 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00004443 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004444
John McCalld5532b62009-11-23 01:53:49 +00004445 TemplateArgumentListInfo TransArgs;
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004446 if (E->hasExplicitTemplateArgumentList()) {
John McCalld5532b62009-11-23 01:53:49 +00004447 TransArgs.setLAngleLoc(E->getLAngleLoc());
4448 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004449 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004450 TemplateArgumentLoc Loc;
4451 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004452 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004453 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004454 }
4455 }
Sean Huntc3021132010-05-05 15:23:54 +00004456
Douglas Gregorb98b1992009-08-11 05:31:07 +00004457 // FIXME: Bogus source location for the operator
4458 SourceLocation FakeOperatorLoc
4459 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4460
John McCallc2233c52010-01-15 08:34:02 +00004461 // FIXME: to do this check properly, we will need to preserve the
4462 // first-qualifier-in-scope here, just in case we had a dependent
4463 // base (and therefore couldn't do the check) and a
4464 // nested-name-qualifier (and therefore could do the lookup).
4465 NamedDecl *FirstQualifierInScope = 0;
4466
Douglas Gregorb98b1992009-08-11 05:31:07 +00004467 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4468 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004469 Qualifier,
4470 E->getQualifierRange(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004471 E->getMemberLoc(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004472 Member,
John McCall6bb80172010-03-30 21:47:33 +00004473 FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00004474 (E->hasExplicitTemplateArgumentList()
4475 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004476 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004477}
Mike Stump1eb44332009-09-09 15:08:12 +00004478
Douglas Gregorb98b1992009-08-11 05:31:07 +00004479template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00004480Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004481TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004482 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4483 if (LHS.isInvalid())
4484 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004485
Douglas Gregorb98b1992009-08-11 05:31:07 +00004486 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4487 if (RHS.isInvalid())
4488 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004489
Douglas Gregorb98b1992009-08-11 05:31:07 +00004490 if (!getDerived().AlwaysRebuild() &&
4491 LHS.get() == E->getLHS() &&
4492 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004493 return SemaRef.Owned(E->Retain());
4494
Douglas Gregorb98b1992009-08-11 05:31:07 +00004495 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4496 move(LHS), move(RHS));
4497}
4498
Mike Stump1eb44332009-09-09 15:08:12 +00004499template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00004500Sema::OwningExprResult
4501TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004502 CompoundAssignOperator *E) {
4503 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004504}
Mike Stump1eb44332009-09-09 15:08:12 +00004505
Douglas Gregorb98b1992009-08-11 05:31:07 +00004506template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004507Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004508TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004509 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4510 if (Cond.isInvalid())
4511 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004512
Douglas Gregorb98b1992009-08-11 05:31:07 +00004513 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4514 if (LHS.isInvalid())
4515 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004516
Douglas Gregorb98b1992009-08-11 05:31:07 +00004517 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4518 if (RHS.isInvalid())
4519 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004520
Douglas Gregorb98b1992009-08-11 05:31:07 +00004521 if (!getDerived().AlwaysRebuild() &&
4522 Cond.get() == E->getCond() &&
4523 LHS.get() == E->getLHS() &&
4524 RHS.get() == E->getRHS())
4525 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004526
4527 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004528 E->getQuestionLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004529 move(LHS),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004530 E->getColonLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004531 move(RHS));
4532}
Mike Stump1eb44332009-09-09 15:08:12 +00004533
4534template<typename Derived>
4535Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004536TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004537 // Implicit casts are eliminated during transformation, since they
4538 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004539 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004540}
Mike Stump1eb44332009-09-09 15:08:12 +00004541
Douglas Gregorb98b1992009-08-11 05:31:07 +00004542template<typename Derived>
4543Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004544TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004545 TypeSourceInfo *OldT;
4546 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004547 {
4548 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004549 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004550 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4551 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004552
John McCall9d125032010-01-15 18:39:57 +00004553 OldT = E->getTypeInfoAsWritten();
4554 NewT = getDerived().TransformType(OldT);
4555 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004556 return SemaRef.ExprError();
4557 }
Mike Stump1eb44332009-09-09 15:08:12 +00004558
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004559 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004560 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004561 if (SubExpr.isInvalid())
4562 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004563
Douglas Gregorb98b1992009-08-11 05:31:07 +00004564 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004565 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004566 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004567 return SemaRef.Owned(E->Retain());
4568
John McCall9d125032010-01-15 18:39:57 +00004569 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4570 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004571 E->getRParenLoc(),
4572 move(SubExpr));
4573}
Mike Stump1eb44332009-09-09 15:08:12 +00004574
Douglas Gregorb98b1992009-08-11 05:31:07 +00004575template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004576Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004577TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004578 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4579 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4580 if (!NewT)
4581 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004582
Douglas Gregorb98b1992009-08-11 05:31:07 +00004583 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4584 if (Init.isInvalid())
4585 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004586
Douglas Gregorb98b1992009-08-11 05:31:07 +00004587 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004588 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004589 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00004590 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004591
John McCall1d7d8d62010-01-19 22:33:45 +00004592 // Note: the expression type doesn't necessarily match the
4593 // type-as-written, but that's okay, because it should always be
4594 // derivable from the initializer.
4595
John McCall42f56b52010-01-18 19:35:47 +00004596 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004597 /*FIXME:*/E->getInitializer()->getLocEnd(),
4598 move(Init));
4599}
Mike Stump1eb44332009-09-09 15:08:12 +00004600
Douglas Gregorb98b1992009-08-11 05:31:07 +00004601template<typename Derived>
4602Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004603TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004604 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4605 if (Base.isInvalid())
4606 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004607
Douglas Gregorb98b1992009-08-11 05:31:07 +00004608 if (!getDerived().AlwaysRebuild() &&
4609 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00004610 return SemaRef.Owned(E->Retain());
4611
Douglas Gregorb98b1992009-08-11 05:31:07 +00004612 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004613 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004614 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4615 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4616 E->getAccessorLoc(),
4617 E->getAccessor());
4618}
Mike Stump1eb44332009-09-09 15:08:12 +00004619
Douglas Gregorb98b1992009-08-11 05:31:07 +00004620template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004621Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004622TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004623 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004624
Douglas Gregorb98b1992009-08-11 05:31:07 +00004625 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4626 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4627 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4628 if (Init.isInvalid())
4629 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004630
Douglas Gregorb98b1992009-08-11 05:31:07 +00004631 InitChanged = InitChanged || Init.get() != E->getInit(I);
4632 Inits.push_back(Init.takeAs<Expr>());
4633 }
Mike Stump1eb44332009-09-09 15:08:12 +00004634
Douglas Gregorb98b1992009-08-11 05:31:07 +00004635 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004636 return SemaRef.Owned(E->Retain());
4637
Douglas Gregorb98b1992009-08-11 05:31:07 +00004638 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004639 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004640}
Mike Stump1eb44332009-09-09 15:08:12 +00004641
Douglas Gregorb98b1992009-08-11 05:31:07 +00004642template<typename Derived>
4643Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004644TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004645 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004646
Douglas Gregor43959a92009-08-20 07:17:43 +00004647 // transform the initializer value
Douglas Gregorb98b1992009-08-11 05:31:07 +00004648 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4649 if (Init.isInvalid())
4650 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004651
Douglas Gregor43959a92009-08-20 07:17:43 +00004652 // transform the designators.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004653 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4654 bool ExprChanged = false;
4655 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4656 DEnd = E->designators_end();
4657 D != DEnd; ++D) {
4658 if (D->isFieldDesignator()) {
4659 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4660 D->getDotLoc(),
4661 D->getFieldLoc()));
4662 continue;
4663 }
Mike Stump1eb44332009-09-09 15:08:12 +00004664
Douglas Gregorb98b1992009-08-11 05:31:07 +00004665 if (D->isArrayDesignator()) {
4666 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4667 if (Index.isInvalid())
4668 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004669
4670 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004671 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004672
Douglas Gregorb98b1992009-08-11 05:31:07 +00004673 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4674 ArrayExprs.push_back(Index.release());
4675 continue;
4676 }
Mike Stump1eb44332009-09-09 15:08:12 +00004677
Douglas Gregorb98b1992009-08-11 05:31:07 +00004678 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump1eb44332009-09-09 15:08:12 +00004679 OwningExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004680 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4681 if (Start.isInvalid())
4682 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004683
Douglas Gregorb98b1992009-08-11 05:31:07 +00004684 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4685 if (End.isInvalid())
4686 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004687
4688 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004689 End.get(),
4690 D->getLBracketLoc(),
4691 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004692
Douglas Gregorb98b1992009-08-11 05:31:07 +00004693 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4694 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004695
Douglas Gregorb98b1992009-08-11 05:31:07 +00004696 ArrayExprs.push_back(Start.release());
4697 ArrayExprs.push_back(End.release());
4698 }
Mike Stump1eb44332009-09-09 15:08:12 +00004699
Douglas Gregorb98b1992009-08-11 05:31:07 +00004700 if (!getDerived().AlwaysRebuild() &&
4701 Init.get() == E->getInit() &&
4702 !ExprChanged)
4703 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004704
Douglas Gregorb98b1992009-08-11 05:31:07 +00004705 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4706 E->getEqualOrColonLoc(),
4707 E->usesGNUSyntax(), move(Init));
4708}
Mike Stump1eb44332009-09-09 15:08:12 +00004709
Douglas Gregorb98b1992009-08-11 05:31:07 +00004710template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004711Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004712TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004713 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004714 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00004715
Douglas Gregor5557b252009-10-28 00:29:27 +00004716 // FIXME: Will we ever have proper type location here? Will we actually
4717 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004718 QualType T = getDerived().TransformType(E->getType());
4719 if (T.isNull())
4720 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004721
Douglas Gregorb98b1992009-08-11 05:31:07 +00004722 if (!getDerived().AlwaysRebuild() &&
4723 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004724 return SemaRef.Owned(E->Retain());
4725
Douglas Gregorb98b1992009-08-11 05:31:07 +00004726 return getDerived().RebuildImplicitValueInitExpr(T);
4727}
Mike Stump1eb44332009-09-09 15:08:12 +00004728
Douglas Gregorb98b1992009-08-11 05:31:07 +00004729template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004730Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004731TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004732 // FIXME: Do we want the type as written?
4733 QualType T;
Mike Stump1eb44332009-09-09 15:08:12 +00004734
Douglas Gregorb98b1992009-08-11 05:31:07 +00004735 {
4736 // FIXME: Source location isn't quite accurate.
4737 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4738 T = getDerived().TransformType(E->getType());
4739 if (T.isNull())
4740 return SemaRef.ExprError();
4741 }
Mike Stump1eb44332009-09-09 15:08:12 +00004742
Douglas Gregorb98b1992009-08-11 05:31:07 +00004743 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4744 if (SubExpr.isInvalid())
4745 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004746
Douglas Gregorb98b1992009-08-11 05:31:07 +00004747 if (!getDerived().AlwaysRebuild() &&
4748 T == E->getType() &&
4749 SubExpr.get() == E->getSubExpr())
4750 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004751
Douglas Gregorb98b1992009-08-11 05:31:07 +00004752 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4753 T, E->getRParenLoc());
4754}
4755
4756template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004757Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004758TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004759 bool ArgumentChanged = false;
4760 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4761 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4762 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4763 if (Init.isInvalid())
4764 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004765
Douglas Gregorb98b1992009-08-11 05:31:07 +00004766 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4767 Inits.push_back(Init.takeAs<Expr>());
4768 }
Mike Stump1eb44332009-09-09 15:08:12 +00004769
Douglas Gregorb98b1992009-08-11 05:31:07 +00004770 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4771 move_arg(Inits),
4772 E->getRParenLoc());
4773}
Mike Stump1eb44332009-09-09 15:08:12 +00004774
Douglas Gregorb98b1992009-08-11 05:31:07 +00004775/// \brief Transform an address-of-label expression.
4776///
4777/// By default, the transformation of an address-of-label expression always
4778/// rebuilds the expression, so that the label identifier can be resolved to
4779/// the corresponding label statement by semantic analysis.
4780template<typename Derived>
4781Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004782TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004783 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4784 E->getLabel());
4785}
Mike Stump1eb44332009-09-09 15:08:12 +00004786
4787template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00004788Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004789TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004790 OwningStmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004791 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4792 if (SubStmt.isInvalid())
4793 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004794
Douglas Gregorb98b1992009-08-11 05:31:07 +00004795 if (!getDerived().AlwaysRebuild() &&
4796 SubStmt.get() == E->getSubStmt())
4797 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004798
4799 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004800 move(SubStmt),
4801 E->getRParenLoc());
4802}
Mike Stump1eb44332009-09-09 15:08:12 +00004803
Douglas Gregorb98b1992009-08-11 05:31:07 +00004804template<typename Derived>
4805Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004806TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004807 QualType T1, T2;
4808 {
4809 // FIXME: Source location isn't quite accurate.
4810 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004811
Douglas Gregorb98b1992009-08-11 05:31:07 +00004812 T1 = getDerived().TransformType(E->getArgType1());
4813 if (T1.isNull())
4814 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004815
Douglas Gregorb98b1992009-08-11 05:31:07 +00004816 T2 = getDerived().TransformType(E->getArgType2());
4817 if (T2.isNull())
4818 return SemaRef.ExprError();
4819 }
4820
4821 if (!getDerived().AlwaysRebuild() &&
4822 T1 == E->getArgType1() &&
4823 T2 == E->getArgType2())
Mike Stump1eb44332009-09-09 15:08:12 +00004824 return SemaRef.Owned(E->Retain());
4825
Douglas Gregorb98b1992009-08-11 05:31:07 +00004826 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4827 T1, T2, E->getRParenLoc());
4828}
Mike Stump1eb44332009-09-09 15:08:12 +00004829
Douglas Gregorb98b1992009-08-11 05:31:07 +00004830template<typename Derived>
4831Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004832TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004833 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4834 if (Cond.isInvalid())
4835 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004836
Douglas Gregorb98b1992009-08-11 05:31:07 +00004837 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4838 if (LHS.isInvalid())
4839 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004840
Douglas Gregorb98b1992009-08-11 05:31:07 +00004841 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4842 if (RHS.isInvalid())
4843 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004844
Douglas Gregorb98b1992009-08-11 05:31:07 +00004845 if (!getDerived().AlwaysRebuild() &&
4846 Cond.get() == E->getCond() &&
4847 LHS.get() == E->getLHS() &&
4848 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004849 return SemaRef.Owned(E->Retain());
4850
Douglas Gregorb98b1992009-08-11 05:31:07 +00004851 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4852 move(Cond), move(LHS), move(RHS),
4853 E->getRParenLoc());
4854}
Mike Stump1eb44332009-09-09 15:08:12 +00004855
Douglas Gregorb98b1992009-08-11 05:31:07 +00004856template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004857Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004858TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004859 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004860}
4861
4862template<typename Derived>
4863Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004864TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004865 switch (E->getOperator()) {
4866 case OO_New:
4867 case OO_Delete:
4868 case OO_Array_New:
4869 case OO_Array_Delete:
4870 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4871 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004872
Douglas Gregor668d6d92009-12-13 20:44:55 +00004873 case OO_Call: {
4874 // This is a call to an object's operator().
4875 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4876
4877 // Transform the object itself.
4878 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4879 if (Object.isInvalid())
4880 return SemaRef.ExprError();
4881
4882 // FIXME: Poor location information
4883 SourceLocation FakeLParenLoc
4884 = SemaRef.PP.getLocForEndOfToken(
4885 static_cast<Expr *>(Object.get())->getLocEnd());
4886
4887 // Transform the call arguments.
4888 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4889 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4890 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004891 if (getDerived().DropCallArgument(E->getArg(I)))
4892 break;
Sean Huntc3021132010-05-05 15:23:54 +00004893
Douglas Gregor668d6d92009-12-13 20:44:55 +00004894 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4895 if (Arg.isInvalid())
4896 return SemaRef.ExprError();
4897
4898 // FIXME: Poor source location information.
4899 SourceLocation FakeCommaLoc
4900 = SemaRef.PP.getLocForEndOfToken(
4901 static_cast<Expr *>(Arg.get())->getLocEnd());
4902 FakeCommaLocs.push_back(FakeCommaLoc);
4903 Args.push_back(Arg.release());
4904 }
4905
4906 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4907 move_arg(Args),
4908 FakeCommaLocs.data(),
4909 E->getLocEnd());
4910 }
4911
4912#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4913 case OO_##Name:
4914#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4915#include "clang/Basic/OperatorKinds.def"
4916 case OO_Subscript:
4917 // Handled below.
4918 break;
4919
4920 case OO_Conditional:
4921 llvm_unreachable("conditional operator is not actually overloadable");
4922 return SemaRef.ExprError();
4923
4924 case OO_None:
4925 case NUM_OVERLOADED_OPERATORS:
4926 llvm_unreachable("not an overloaded operator?");
4927 return SemaRef.ExprError();
4928 }
4929
Douglas Gregorb98b1992009-08-11 05:31:07 +00004930 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4931 if (Callee.isInvalid())
4932 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004933
John McCall454feb92009-12-08 09:21:05 +00004934 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004935 if (First.isInvalid())
4936 return SemaRef.ExprError();
4937
4938 OwningExprResult Second(SemaRef);
4939 if (E->getNumArgs() == 2) {
4940 Second = getDerived().TransformExpr(E->getArg(1));
4941 if (Second.isInvalid())
4942 return SemaRef.ExprError();
4943 }
Mike Stump1eb44332009-09-09 15:08:12 +00004944
Douglas Gregorb98b1992009-08-11 05:31:07 +00004945 if (!getDerived().AlwaysRebuild() &&
4946 Callee.get() == E->getCallee() &&
4947 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00004948 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4949 return SemaRef.Owned(E->Retain());
4950
Douglas Gregorb98b1992009-08-11 05:31:07 +00004951 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4952 E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004953 move(Callee),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004954 move(First),
4955 move(Second));
4956}
Mike Stump1eb44332009-09-09 15:08:12 +00004957
Douglas Gregorb98b1992009-08-11 05:31:07 +00004958template<typename Derived>
4959Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004960TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4961 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004962}
Mike Stump1eb44332009-09-09 15:08:12 +00004963
Douglas Gregorb98b1992009-08-11 05:31:07 +00004964template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004965Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004966TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004967 TypeSourceInfo *OldT;
4968 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004969 {
4970 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004971 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004972 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4973 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004974
John McCall9d125032010-01-15 18:39:57 +00004975 OldT = E->getTypeInfoAsWritten();
4976 NewT = getDerived().TransformType(OldT);
4977 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004978 return SemaRef.ExprError();
4979 }
Mike Stump1eb44332009-09-09 15:08:12 +00004980
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004981 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004982 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004983 if (SubExpr.isInvalid())
4984 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004985
Douglas Gregorb98b1992009-08-11 05:31:07 +00004986 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004987 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004988 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004989 return SemaRef.Owned(E->Retain());
4990
Douglas Gregorb98b1992009-08-11 05:31:07 +00004991 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00004992 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004993 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4994 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4995 SourceLocation FakeRParenLoc
4996 = SemaRef.PP.getLocForEndOfToken(
4997 E->getSubExpr()->getSourceRange().getEnd());
4998 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004999 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005000 FakeLAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00005001 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005002 FakeRAngleLoc,
5003 FakeRAngleLoc,
5004 move(SubExpr),
5005 FakeRParenLoc);
5006}
Mike Stump1eb44332009-09-09 15:08:12 +00005007
Douglas Gregorb98b1992009-08-11 05:31:07 +00005008template<typename Derived>
5009Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005010TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5011 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005012}
Mike Stump1eb44332009-09-09 15:08:12 +00005013
5014template<typename Derived>
5015Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005016TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5017 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005018}
5019
Douglas Gregorb98b1992009-08-11 05:31:07 +00005020template<typename Derived>
5021Sema::OwningExprResult
5022TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005023 CXXReinterpretCastExpr *E) {
5024 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005025}
Mike Stump1eb44332009-09-09 15:08:12 +00005026
Douglas Gregorb98b1992009-08-11 05:31:07 +00005027template<typename Derived>
5028Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005029TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5030 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005031}
Mike Stump1eb44332009-09-09 15:08:12 +00005032
Douglas Gregorb98b1992009-08-11 05:31:07 +00005033template<typename Derived>
5034Sema::OwningExprResult
5035TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005036 CXXFunctionalCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00005037 TypeSourceInfo *OldT;
5038 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005039 {
5040 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005041
John McCall9d125032010-01-15 18:39:57 +00005042 OldT = E->getTypeInfoAsWritten();
5043 NewT = getDerived().TransformType(OldT);
5044 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005045 return SemaRef.ExprError();
5046 }
Mike Stump1eb44332009-09-09 15:08:12 +00005047
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005048 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005049 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005050 if (SubExpr.isInvalid())
5051 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005052
Douglas Gregorb98b1992009-08-11 05:31:07 +00005053 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00005054 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005055 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005056 return SemaRef.Owned(E->Retain());
5057
Douglas Gregorb98b1992009-08-11 05:31:07 +00005058 // FIXME: The end of the type's source range is wrong
5059 return getDerived().RebuildCXXFunctionalCastExpr(
5060 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall9d125032010-01-15 18:39:57 +00005061 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005062 /*FIXME:*/E->getSubExpr()->getLocStart(),
5063 move(SubExpr),
5064 E->getRParenLoc());
5065}
Mike Stump1eb44332009-09-09 15:08:12 +00005066
Douglas Gregorb98b1992009-08-11 05:31:07 +00005067template<typename Derived>
5068Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005069TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005070 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005071 TypeSourceInfo *TInfo
5072 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5073 if (!TInfo)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005074 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005075
Douglas Gregorb98b1992009-08-11 05:31:07 +00005076 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005077 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregorb98b1992009-08-11 05:31:07 +00005078 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005079
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005080 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5081 E->getLocStart(),
5082 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005083 E->getLocEnd());
5084 }
Mike Stump1eb44332009-09-09 15:08:12 +00005085
Douglas Gregorb98b1992009-08-11 05:31:07 +00005086 // We don't know whether the expression is potentially evaluated until
5087 // after we perform semantic analysis, so the expression is potentially
5088 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005089 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005090 Action::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005091
Douglas Gregorb98b1992009-08-11 05:31:07 +00005092 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5093 if (SubExpr.isInvalid())
5094 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005095
Douglas Gregorb98b1992009-08-11 05:31:07 +00005096 if (!getDerived().AlwaysRebuild() &&
5097 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00005098 return SemaRef.Owned(E->Retain());
5099
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005100 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5101 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005102 move(SubExpr),
5103 E->getLocEnd());
5104}
5105
5106template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005107Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005108TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005109 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005110}
Mike Stump1eb44332009-09-09 15:08:12 +00005111
Douglas Gregorb98b1992009-08-11 05:31:07 +00005112template<typename Derived>
5113Sema::OwningExprResult
5114TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005115 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005116 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005117}
Mike Stump1eb44332009-09-09 15:08:12 +00005118
Douglas Gregorb98b1992009-08-11 05:31:07 +00005119template<typename Derived>
5120Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005121TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005122 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005123
Douglas Gregorb98b1992009-08-11 05:31:07 +00005124 QualType T = getDerived().TransformType(E->getType());
5125 if (T.isNull())
5126 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005127
Douglas Gregorb98b1992009-08-11 05:31:07 +00005128 if (!getDerived().AlwaysRebuild() &&
5129 T == E->getType())
5130 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005131
Douglas Gregor828a1972010-01-07 23:12:05 +00005132 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005133}
Mike Stump1eb44332009-09-09 15:08:12 +00005134
Douglas Gregorb98b1992009-08-11 05:31:07 +00005135template<typename Derived>
5136Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005137TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005138 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5139 if (SubExpr.isInvalid())
5140 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005141
Douglas Gregorb98b1992009-08-11 05:31:07 +00005142 if (!getDerived().AlwaysRebuild() &&
5143 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005144 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005145
5146 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5147}
Mike Stump1eb44332009-09-09 15:08:12 +00005148
Douglas Gregorb98b1992009-08-11 05:31:07 +00005149template<typename Derived>
5150Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005151TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005152 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005153 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5154 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005155 if (!Param)
5156 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005157
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005158 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005159 Param == E->getParam())
5160 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005161
Douglas Gregor036aed12009-12-23 23:03:06 +00005162 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
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
John McCall454feb92009-12-08 09:21:05 +00005167TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005168 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5169
5170 QualType T = getDerived().TransformType(E->getType());
5171 if (T.isNull())
5172 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005173
Douglas Gregorb98b1992009-08-11 05:31:07 +00005174 if (!getDerived().AlwaysRebuild() &&
5175 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00005176 return SemaRef.Owned(E->Retain());
5177
5178 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005179 /*FIXME:*/E->getTypeBeginLoc(),
5180 T,
5181 E->getRParenLoc());
5182}
Mike Stump1eb44332009-09-09 15:08:12 +00005183
Douglas Gregorb98b1992009-08-11 05:31:07 +00005184template<typename Derived>
5185Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005186TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005187 // Transform the type that we're allocating
5188 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5189 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5190 if (AllocType.isNull())
5191 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005192
Douglas Gregorb98b1992009-08-11 05:31:07 +00005193 // Transform the size of the array we're allocating (if any).
5194 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5195 if (ArraySize.isInvalid())
5196 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005197
Douglas Gregorb98b1992009-08-11 05:31:07 +00005198 // Transform the placement arguments (if any).
5199 bool ArgumentChanged = false;
5200 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5201 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5202 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5203 if (Arg.isInvalid())
5204 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005205
Douglas Gregorb98b1992009-08-11 05:31:07 +00005206 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5207 PlacementArgs.push_back(Arg.take());
5208 }
Mike Stump1eb44332009-09-09 15:08:12 +00005209
Douglas Gregor43959a92009-08-20 07:17:43 +00005210 // transform the constructor arguments (if any).
Douglas Gregorb98b1992009-08-11 05:31:07 +00005211 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5212 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005213 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5214 break;
5215
Douglas Gregorb98b1992009-08-11 05:31:07 +00005216 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5217 if (Arg.isInvalid())
5218 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005219
Douglas Gregorb98b1992009-08-11 05:31:07 +00005220 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5221 ConstructorArgs.push_back(Arg.take());
5222 }
Mike Stump1eb44332009-09-09 15:08:12 +00005223
Douglas Gregor1af74512010-02-26 00:38:10 +00005224 // Transform constructor, new operator, and delete operator.
5225 CXXConstructorDecl *Constructor = 0;
5226 if (E->getConstructor()) {
5227 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005228 getDerived().TransformDecl(E->getLocStart(),
5229 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005230 if (!Constructor)
5231 return SemaRef.ExprError();
5232 }
5233
5234 FunctionDecl *OperatorNew = 0;
5235 if (E->getOperatorNew()) {
5236 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005237 getDerived().TransformDecl(E->getLocStart(),
5238 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005239 if (!OperatorNew)
5240 return SemaRef.ExprError();
5241 }
5242
5243 FunctionDecl *OperatorDelete = 0;
5244 if (E->getOperatorDelete()) {
5245 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005246 getDerived().TransformDecl(E->getLocStart(),
5247 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005248 if (!OperatorDelete)
5249 return SemaRef.ExprError();
5250 }
Sean Huntc3021132010-05-05 15:23:54 +00005251
Douglas Gregorb98b1992009-08-11 05:31:07 +00005252 if (!getDerived().AlwaysRebuild() &&
5253 AllocType == E->getAllocatedType() &&
5254 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005255 Constructor == E->getConstructor() &&
5256 OperatorNew == E->getOperatorNew() &&
5257 OperatorDelete == E->getOperatorDelete() &&
5258 !ArgumentChanged) {
5259 // Mark any declarations we need as referenced.
5260 // FIXME: instantiation-specific.
5261 if (Constructor)
5262 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5263 if (OperatorNew)
5264 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5265 if (OperatorDelete)
5266 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005267 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005268 }
Mike Stump1eb44332009-09-09 15:08:12 +00005269
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005270 if (!ArraySize.get()) {
5271 // If no array size was specified, but the new expression was
5272 // instantiated with an array type (e.g., "new T" where T is
5273 // instantiated with "int[4]"), extract the outer bound from the
5274 // array type as our array size. We do this with constant and
5275 // dependently-sized array types.
5276 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5277 if (!ArrayT) {
5278 // Do nothing
5279 } else if (const ConstantArrayType *ConsArrayT
5280 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005281 ArraySize
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005282 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Sean Huntc3021132010-05-05 15:23:54 +00005283 ConsArrayT->getSize(),
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005284 SemaRef.Context.getSizeType(),
5285 /*FIXME:*/E->getLocStart()));
5286 AllocType = ConsArrayT->getElementType();
5287 } else if (const DependentSizedArrayType *DepArrayT
5288 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5289 if (DepArrayT->getSizeExpr()) {
5290 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5291 AllocType = DepArrayT->getElementType();
5292 }
5293 }
5294 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005295 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5296 E->isGlobalNew(),
5297 /*FIXME:*/E->getLocStart(),
5298 move_arg(PlacementArgs),
5299 /*FIXME:*/E->getLocStart(),
5300 E->isParenTypeId(),
5301 AllocType,
5302 /*FIXME:*/E->getLocStart(),
5303 /*FIXME:*/SourceRange(),
5304 move(ArraySize),
5305 /*FIXME:*/E->getLocStart(),
5306 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005307 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005308}
Mike Stump1eb44332009-09-09 15:08:12 +00005309
Douglas Gregorb98b1992009-08-11 05:31:07 +00005310template<typename Derived>
5311Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005312TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005313 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5314 if (Operand.isInvalid())
5315 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005316
Douglas Gregor1af74512010-02-26 00:38:10 +00005317 // Transform the delete operator, if known.
5318 FunctionDecl *OperatorDelete = 0;
5319 if (E->getOperatorDelete()) {
5320 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005321 getDerived().TransformDecl(E->getLocStart(),
5322 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005323 if (!OperatorDelete)
5324 return SemaRef.ExprError();
5325 }
Sean Huntc3021132010-05-05 15:23:54 +00005326
Douglas Gregorb98b1992009-08-11 05:31:07 +00005327 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005328 Operand.get() == E->getArgument() &&
5329 OperatorDelete == E->getOperatorDelete()) {
5330 // Mark any declarations we need as referenced.
5331 // FIXME: instantiation-specific.
5332 if (OperatorDelete)
5333 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005334 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005335 }
Mike Stump1eb44332009-09-09 15:08:12 +00005336
Douglas Gregorb98b1992009-08-11 05:31:07 +00005337 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5338 E->isGlobalDelete(),
5339 E->isArrayForm(),
5340 move(Operand));
5341}
Mike Stump1eb44332009-09-09 15:08:12 +00005342
Douglas Gregorb98b1992009-08-11 05:31:07 +00005343template<typename Derived>
5344Sema::OwningExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005345TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005346 CXXPseudoDestructorExpr *E) {
Douglas Gregora71d8192009-09-04 17:36:40 +00005347 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5348 if (Base.isInvalid())
5349 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005350
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005351 Sema::TypeTy *ObjectTypePtr = 0;
5352 bool MayBePseudoDestructor = false;
Sean Huntc3021132010-05-05 15:23:54 +00005353 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005354 E->getOperatorLoc(),
5355 E->isArrow()? tok::arrow : tok::period,
5356 ObjectTypePtr,
5357 MayBePseudoDestructor);
5358 if (Base.isInvalid())
5359 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005360
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005361 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregora71d8192009-09-04 17:36:40 +00005362 NestedNameSpecifier *Qualifier
5363 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00005364 E->getQualifierRange(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005365 ObjectType);
Douglas Gregora71d8192009-09-04 17:36:40 +00005366 if (E->getQualifier() && !Qualifier)
5367 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005368
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005369 PseudoDestructorTypeStorage Destroyed;
5370 if (E->getDestroyedTypeInfo()) {
5371 TypeSourceInfo *DestroyedTypeInfo
5372 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5373 if (!DestroyedTypeInfo)
5374 return SemaRef.ExprError();
5375 Destroyed = DestroyedTypeInfo;
5376 } else if (ObjectType->isDependentType()) {
5377 // We aren't likely to be able to resolve the identifier down to a type
5378 // now anyway, so just retain the identifier.
5379 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5380 E->getDestroyedTypeLoc());
5381 } else {
5382 // Look for a destructor known with the given name.
5383 CXXScopeSpec SS;
5384 if (Qualifier) {
5385 SS.setScopeRep(Qualifier);
5386 SS.setRange(E->getQualifierRange());
5387 }
Sean Huntc3021132010-05-05 15:23:54 +00005388
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005389 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5390 *E->getDestroyedTypeIdentifier(),
5391 E->getDestroyedTypeLoc(),
5392 /*Scope=*/0,
5393 SS, ObjectTypePtr,
5394 false);
5395 if (!T)
5396 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005397
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005398 Destroyed
5399 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5400 E->getDestroyedTypeLoc());
5401 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005402
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005403 TypeSourceInfo *ScopeTypeInfo = 0;
5404 if (E->getScopeTypeInfo()) {
Sean Huntc3021132010-05-05 15:23:54 +00005405 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005406 ObjectType);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005407 if (!ScopeTypeInfo)
Douglas Gregora71d8192009-09-04 17:36:40 +00005408 return SemaRef.ExprError();
5409 }
Sean Huntc3021132010-05-05 15:23:54 +00005410
Douglas Gregora71d8192009-09-04 17:36:40 +00005411 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5412 E->getOperatorLoc(),
5413 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005414 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005415 E->getQualifierRange(),
5416 ScopeTypeInfo,
5417 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005418 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005419 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00005420}
Mike Stump1eb44332009-09-09 15:08:12 +00005421
Douglas Gregora71d8192009-09-04 17:36:40 +00005422template<typename Derived>
5423Sema::OwningExprResult
John McCallba135432009-11-21 08:51:07 +00005424TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00005425 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00005426 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5427
5428 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5429 Sema::LookupOrdinaryName);
5430
5431 // Transform all the decls.
5432 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5433 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005434 NamedDecl *InstD = static_cast<NamedDecl*>(
5435 getDerived().TransformDecl(Old->getNameLoc(),
5436 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005437 if (!InstD) {
5438 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5439 // This can happen because of dependent hiding.
5440 if (isa<UsingShadowDecl>(*I))
5441 continue;
5442 else
5443 return SemaRef.ExprError();
5444 }
John McCallf7a1a742009-11-24 19:00:30 +00005445
5446 // Expand using declarations.
5447 if (isa<UsingDecl>(InstD)) {
5448 UsingDecl *UD = cast<UsingDecl>(InstD);
5449 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5450 E = UD->shadow_end(); I != E; ++I)
5451 R.addDecl(*I);
5452 continue;
5453 }
5454
5455 R.addDecl(InstD);
5456 }
5457
5458 // Resolve a kind, but don't do any further analysis. If it's
5459 // ambiguous, the callee needs to deal with it.
5460 R.resolveKind();
5461
5462 // Rebuild the nested-name qualifier, if present.
5463 CXXScopeSpec SS;
5464 NestedNameSpecifier *Qualifier = 0;
5465 if (Old->getQualifier()) {
5466 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005467 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00005468 if (!Qualifier)
5469 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005470
John McCallf7a1a742009-11-24 19:00:30 +00005471 SS.setScopeRep(Qualifier);
5472 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00005473 }
5474
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005475 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00005476 CXXRecordDecl *NamingClass
5477 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5478 Old->getNameLoc(),
5479 Old->getNamingClass()));
5480 if (!NamingClass)
5481 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005482
Douglas Gregor66c45152010-04-27 16:10:10 +00005483 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00005484 }
5485
5486 // If we have no template arguments, it's a normal declaration name.
5487 if (!Old->hasExplicitTemplateArgs())
5488 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5489
5490 // If we have template arguments, rebuild them, then rebuild the
5491 // templateid expression.
5492 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5493 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5494 TemplateArgumentLoc Loc;
5495 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5496 return SemaRef.ExprError();
5497 TransArgs.addArgument(Loc);
5498 }
5499
5500 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5501 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005502}
Mike Stump1eb44332009-09-09 15:08:12 +00005503
Douglas Gregorb98b1992009-08-11 05:31:07 +00005504template<typename Derived>
5505Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005506TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005507 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005508
Douglas Gregorb98b1992009-08-11 05:31:07 +00005509 QualType T = getDerived().TransformType(E->getQueriedType());
5510 if (T.isNull())
5511 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005512
Douglas Gregorb98b1992009-08-11 05:31:07 +00005513 if (!getDerived().AlwaysRebuild() &&
5514 T == E->getQueriedType())
5515 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005516
Douglas Gregorb98b1992009-08-11 05:31:07 +00005517 // FIXME: Bad location information
5518 SourceLocation FakeLParenLoc
5519 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump1eb44332009-09-09 15:08:12 +00005520
5521 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005522 E->getLocStart(),
5523 /*FIXME:*/FakeLParenLoc,
5524 T,
5525 E->getLocEnd());
5526}
Mike Stump1eb44332009-09-09 15:08:12 +00005527
Douglas Gregorb98b1992009-08-11 05:31:07 +00005528template<typename Derived>
5529Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00005530TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall454feb92009-12-08 09:21:05 +00005531 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005532 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00005533 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005534 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005535 if (!NNS)
5536 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005537
5538 DeclarationName Name
Douglas Gregor81499bb2009-09-03 22:13:48 +00005539 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5540 if (!Name)
5541 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005542
John McCallf7a1a742009-11-24 19:00:30 +00005543 if (!E->hasExplicitTemplateArgs()) {
5544 if (!getDerived().AlwaysRebuild() &&
5545 NNS == E->getQualifier() &&
5546 Name == E->getDeclName())
5547 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005548
John McCallf7a1a742009-11-24 19:00:30 +00005549 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5550 E->getQualifierRange(),
5551 Name, E->getLocation(),
5552 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00005553 }
John McCalld5532b62009-11-23 01:53:49 +00005554
5555 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005556 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005557 TemplateArgumentLoc Loc;
5558 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb98b1992009-08-11 05:31:07 +00005559 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005560 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005561 }
5562
John McCallf7a1a742009-11-24 19:00:30 +00005563 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5564 E->getQualifierRange(),
5565 Name, E->getLocation(),
5566 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005567}
5568
5569template<typename Derived>
5570Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005571TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00005572 // CXXConstructExprs are always implicit, so when we have a
5573 // 1-argument construction we just transform that argument.
5574 if (E->getNumArgs() == 1 ||
5575 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5576 return getDerived().TransformExpr(E->getArg(0));
5577
Douglas Gregorb98b1992009-08-11 05:31:07 +00005578 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5579
5580 QualType T = getDerived().TransformType(E->getType());
5581 if (T.isNull())
5582 return SemaRef.ExprError();
5583
5584 CXXConstructorDecl *Constructor
5585 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005586 getDerived().TransformDecl(E->getLocStart(),
5587 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005588 if (!Constructor)
5589 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005590
Douglas Gregorb98b1992009-08-11 05:31:07 +00005591 bool ArgumentChanged = false;
5592 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005593 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005594 ArgEnd = E->arg_end();
5595 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005596 if (getDerived().DropCallArgument(*Arg)) {
5597 ArgumentChanged = true;
5598 break;
5599 }
5600
Douglas Gregorb98b1992009-08-11 05:31:07 +00005601 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5602 if (TransArg.isInvalid())
5603 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005604
Douglas Gregorb98b1992009-08-11 05:31:07 +00005605 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5606 Args.push_back(TransArg.takeAs<Expr>());
5607 }
5608
5609 if (!getDerived().AlwaysRebuild() &&
5610 T == E->getType() &&
5611 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005612 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005613 // Mark the constructor as referenced.
5614 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005615 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005616 return SemaRef.Owned(E->Retain());
Douglas Gregorc845aad2010-02-26 00:01:57 +00005617 }
Mike Stump1eb44332009-09-09 15:08:12 +00005618
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005619 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5620 Constructor, E->isElidable(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005621 move_arg(Args));
5622}
Mike Stump1eb44332009-09-09 15:08:12 +00005623
Douglas Gregorb98b1992009-08-11 05:31:07 +00005624/// \brief Transform a C++ temporary-binding expression.
5625///
Douglas Gregor51326552009-12-24 18:51:59 +00005626/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5627/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005628template<typename Derived>
5629Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005630TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005631 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005632}
Mike Stump1eb44332009-09-09 15:08:12 +00005633
Anders Carlssoneb60edf2010-01-29 02:39:32 +00005634/// \brief Transform a C++ reference-binding expression.
5635///
5636/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5637/// transform the subexpression and return that.
5638template<typename Derived>
5639Sema::OwningExprResult
5640TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5641 return getDerived().TransformExpr(E->getSubExpr());
5642}
5643
Mike Stump1eb44332009-09-09 15:08:12 +00005644/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00005645/// be destroyed after the expression is evaluated.
5646///
Douglas Gregor51326552009-12-24 18:51:59 +00005647/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5648/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005649template<typename Derived>
5650Sema::OwningExprResult
5651TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00005652 CXXExprWithTemporaries *E) {
5653 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005654}
Mike Stump1eb44332009-09-09 15:08:12 +00005655
Douglas Gregorb98b1992009-08-11 05:31:07 +00005656template<typename Derived>
5657Sema::OwningExprResult
5658TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall454feb92009-12-08 09:21:05 +00005659 CXXTemporaryObjectExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005660 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5661 QualType T = getDerived().TransformType(E->getType());
5662 if (T.isNull())
5663 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005664
Douglas Gregorb98b1992009-08-11 05:31:07 +00005665 CXXConstructorDecl *Constructor
5666 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00005667 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005668 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005669 if (!Constructor)
5670 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005671
Douglas Gregorb98b1992009-08-11 05:31:07 +00005672 bool ArgumentChanged = false;
5673 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5674 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005675 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005676 ArgEnd = E->arg_end();
5677 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005678 if (getDerived().DropCallArgument(*Arg)) {
5679 ArgumentChanged = true;
5680 break;
5681 }
5682
Douglas Gregorb98b1992009-08-11 05:31:07 +00005683 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5684 if (TransArg.isInvalid())
5685 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005686
Douglas Gregorb98b1992009-08-11 05:31:07 +00005687 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5688 Args.push_back((Expr *)TransArg.release());
5689 }
Mike Stump1eb44332009-09-09 15:08:12 +00005690
Douglas Gregorb98b1992009-08-11 05:31:07 +00005691 if (!getDerived().AlwaysRebuild() &&
5692 T == E->getType() &&
5693 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005694 !ArgumentChanged) {
5695 // FIXME: Instantiation-specific
5696 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carrutha3ce8ae2010-03-31 18:34:58 +00005697 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor91be6f52010-03-02 17:18:33 +00005698 }
Mike Stump1eb44332009-09-09 15:08:12 +00005699
Douglas Gregorb98b1992009-08-11 05:31:07 +00005700 // FIXME: Bogus location information
5701 SourceLocation CommaLoc;
5702 if (Args.size() > 1) {
5703 Expr *First = (Expr *)Args[0];
Mike Stump1eb44332009-09-09 15:08:12 +00005704 CommaLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005705 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5706 }
5707 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5708 T,
5709 /*FIXME:*/E->getTypeBeginLoc(),
5710 move_arg(Args),
5711 &CommaLoc,
5712 E->getLocEnd());
5713}
Mike Stump1eb44332009-09-09 15:08:12 +00005714
Douglas Gregorb98b1992009-08-11 05:31:07 +00005715template<typename Derived>
5716Sema::OwningExprResult
5717TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005718 CXXUnresolvedConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005719 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5720 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5721 if (T.isNull())
5722 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005723
Douglas Gregorb98b1992009-08-11 05:31:07 +00005724 bool ArgumentChanged = false;
5725 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5726 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5727 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5728 ArgEnd = E->arg_end();
5729 Arg != ArgEnd; ++Arg) {
5730 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5731 if (TransArg.isInvalid())
5732 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005733
Douglas Gregorb98b1992009-08-11 05:31:07 +00005734 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5735 FakeCommaLocs.push_back(
5736 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5737 Args.push_back(TransArg.takeAs<Expr>());
5738 }
Mike Stump1eb44332009-09-09 15:08:12 +00005739
Douglas Gregorb98b1992009-08-11 05:31:07 +00005740 if (!getDerived().AlwaysRebuild() &&
5741 T == E->getTypeAsWritten() &&
5742 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005743 return SemaRef.Owned(E->Retain());
5744
Douglas Gregorb98b1992009-08-11 05:31:07 +00005745 // FIXME: we're faking the locations of the commas
5746 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5747 T,
5748 E->getLParenLoc(),
5749 move_arg(Args),
5750 FakeCommaLocs.data(),
5751 E->getRParenLoc());
5752}
Mike Stump1eb44332009-09-09 15:08:12 +00005753
Douglas Gregorb98b1992009-08-11 05:31:07 +00005754template<typename Derived>
5755Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00005756TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall454feb92009-12-08 09:21:05 +00005757 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005758 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005759 OwningExprResult Base(SemaRef, (Expr*) 0);
5760 Expr *OldBase;
5761 QualType BaseType;
5762 QualType ObjectType;
5763 if (!E->isImplicitAccess()) {
5764 OldBase = E->getBase();
5765 Base = getDerived().TransformExpr(OldBase);
5766 if (Base.isInvalid())
5767 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005768
John McCallaa81e162009-12-01 22:10:20 +00005769 // Start the member reference and compute the object's type.
5770 Sema::TypeTy *ObjectTy = 0;
Douglas Gregord4dca082010-02-24 18:44:31 +00005771 bool MayBePseudoDestructor = false;
John McCallaa81e162009-12-01 22:10:20 +00005772 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5773 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005774 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005775 ObjectTy,
5776 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005777 if (Base.isInvalid())
5778 return SemaRef.ExprError();
5779
5780 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5781 BaseType = ((Expr*) Base.get())->getType();
5782 } else {
5783 OldBase = 0;
5784 BaseType = getDerived().TransformType(E->getBaseType());
5785 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5786 }
Mike Stump1eb44332009-09-09 15:08:12 +00005787
Douglas Gregor6cd21982009-10-20 05:58:46 +00005788 // Transform the first part of the nested-name-specifier that qualifies
5789 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005790 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005791 = getDerived().TransformFirstQualifierInScope(
5792 E->getFirstQualifierFoundInScope(),
5793 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005794
Douglas Gregora38c6872009-09-03 16:14:30 +00005795 NestedNameSpecifier *Qualifier = 0;
5796 if (E->getQualifier()) {
5797 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5798 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005799 ObjectType,
5800 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005801 if (!Qualifier)
5802 return SemaRef.ExprError();
5803 }
Mike Stump1eb44332009-09-09 15:08:12 +00005804
5805 DeclarationName Name
Douglas Gregordd62b152009-10-19 22:04:39 +00005806 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCallaa81e162009-12-01 22:10:20 +00005807 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00005808 if (!Name)
5809 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005810
John McCallaa81e162009-12-01 22:10:20 +00005811 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005812 // This is a reference to a member without an explicitly-specified
5813 // template argument list. Optimize for this common case.
5814 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005815 Base.get() == OldBase &&
5816 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005817 Qualifier == E->getQualifier() &&
5818 Name == E->getMember() &&
5819 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005820 return SemaRef.Owned(E->Retain());
5821
John McCall865d4472009-11-19 22:55:06 +00005822 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005823 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005824 E->isArrow(),
5825 E->getOperatorLoc(),
5826 Qualifier,
5827 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005828 FirstQualifierInScope,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005829 Name,
5830 E->getMemberLoc(),
John McCall129e2df2009-11-30 22:42:35 +00005831 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005832 }
5833
John McCalld5532b62009-11-23 01:53:49 +00005834 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005835 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005836 TemplateArgumentLoc Loc;
5837 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005838 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005839 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005840 }
Mike Stump1eb44332009-09-09 15:08:12 +00005841
John McCall865d4472009-11-19 22:55:06 +00005842 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005843 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005844 E->isArrow(),
5845 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005846 Qualifier,
5847 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005848 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005849 Name,
5850 E->getMemberLoc(),
5851 &TransArgs);
5852}
5853
5854template<typename Derived>
5855Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005856TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005857 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005858 OwningExprResult Base(SemaRef, (Expr*) 0);
5859 QualType BaseType;
5860 if (!Old->isImplicitAccess()) {
5861 Base = getDerived().TransformExpr(Old->getBase());
5862 if (Base.isInvalid())
5863 return SemaRef.ExprError();
5864 BaseType = ((Expr*) Base.get())->getType();
5865 } else {
5866 BaseType = getDerived().TransformType(Old->getBaseType());
5867 }
John McCall129e2df2009-11-30 22:42:35 +00005868
5869 NestedNameSpecifier *Qualifier = 0;
5870 if (Old->getQualifier()) {
5871 Qualifier
5872 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005873 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00005874 if (Qualifier == 0)
5875 return SemaRef.ExprError();
5876 }
5877
5878 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5879 Sema::LookupOrdinaryName);
5880
5881 // Transform all the decls.
5882 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5883 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005884 NamedDecl *InstD = static_cast<NamedDecl*>(
5885 getDerived().TransformDecl(Old->getMemberLoc(),
5886 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005887 if (!InstD) {
5888 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5889 // This can happen because of dependent hiding.
5890 if (isa<UsingShadowDecl>(*I))
5891 continue;
5892 else
5893 return SemaRef.ExprError();
5894 }
John McCall129e2df2009-11-30 22:42:35 +00005895
5896 // Expand using declarations.
5897 if (isa<UsingDecl>(InstD)) {
5898 UsingDecl *UD = cast<UsingDecl>(InstD);
5899 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5900 E = UD->shadow_end(); I != E; ++I)
5901 R.addDecl(*I);
5902 continue;
5903 }
5904
5905 R.addDecl(InstD);
5906 }
5907
5908 R.resolveKind();
5909
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005910 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00005911 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00005912 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005913 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00005914 Old->getMemberLoc(),
5915 Old->getNamingClass()));
5916 if (!NamingClass)
5917 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005918
Douglas Gregor66c45152010-04-27 16:10:10 +00005919 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005920 }
Sean Huntc3021132010-05-05 15:23:54 +00005921
John McCall129e2df2009-11-30 22:42:35 +00005922 TemplateArgumentListInfo TransArgs;
5923 if (Old->hasExplicitTemplateArgs()) {
5924 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5925 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5926 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5927 TemplateArgumentLoc Loc;
5928 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5929 Loc))
5930 return SemaRef.ExprError();
5931 TransArgs.addArgument(Loc);
5932 }
5933 }
John McCallc2233c52010-01-15 08:34:02 +00005934
5935 // FIXME: to do this check properly, we will need to preserve the
5936 // first-qualifier-in-scope here, just in case we had a dependent
5937 // base (and therefore couldn't do the check) and a
5938 // nested-name-qualifier (and therefore could do the lookup).
5939 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00005940
John McCall129e2df2009-11-30 22:42:35 +00005941 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005942 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00005943 Old->getOperatorLoc(),
5944 Old->isArrow(),
5945 Qualifier,
5946 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00005947 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005948 R,
5949 (Old->hasExplicitTemplateArgs()
5950 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005951}
5952
5953template<typename Derived>
5954Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005955TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005956 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005957}
5958
Mike Stump1eb44332009-09-09 15:08:12 +00005959template<typename Derived>
5960Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005961TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00005962 TypeSourceInfo *EncodedTypeInfo
5963 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5964 if (!EncodedTypeInfo)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005965 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005966
Douglas Gregorb98b1992009-08-11 05:31:07 +00005967 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00005968 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump1eb44332009-09-09 15:08:12 +00005969 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005970
5971 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00005972 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005973 E->getRParenLoc());
5974}
Mike Stump1eb44332009-09-09 15:08:12 +00005975
Douglas Gregorb98b1992009-08-11 05:31:07 +00005976template<typename Derived>
5977Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005978TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00005979 // Transform arguments.
5980 bool ArgChanged = false;
5981 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5982 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5983 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5984 if (Arg.isInvalid())
5985 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005986
Douglas Gregor92e986e2010-04-22 16:44:27 +00005987 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5988 Args.push_back(Arg.takeAs<Expr>());
5989 }
5990
5991 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5992 // Class message: transform the receiver type.
5993 TypeSourceInfo *ReceiverTypeInfo
5994 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5995 if (!ReceiverTypeInfo)
5996 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005997
Douglas Gregor92e986e2010-04-22 16:44:27 +00005998 // If nothing changed, just retain the existing message send.
5999 if (!getDerived().AlwaysRebuild() &&
6000 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6001 return SemaRef.Owned(E->Retain());
6002
6003 // Build a new class message send.
6004 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6005 E->getSelector(),
6006 E->getMethodDecl(),
6007 E->getLeftLoc(),
6008 move_arg(Args),
6009 E->getRightLoc());
6010 }
6011
6012 // Instance message: transform the receiver
6013 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6014 "Only class and instance messages may be instantiated");
6015 OwningExprResult Receiver
6016 = getDerived().TransformExpr(E->getInstanceReceiver());
6017 if (Receiver.isInvalid())
6018 return SemaRef.ExprError();
6019
6020 // If nothing changed, just retain the existing message send.
6021 if (!getDerived().AlwaysRebuild() &&
6022 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6023 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006024
Douglas Gregor92e986e2010-04-22 16:44:27 +00006025 // Build a new instance message send.
6026 return getDerived().RebuildObjCMessageExpr(move(Receiver),
6027 E->getSelector(),
6028 E->getMethodDecl(),
6029 E->getLeftLoc(),
6030 move_arg(Args),
6031 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006032}
6033
Mike Stump1eb44332009-09-09 15:08:12 +00006034template<typename Derived>
6035Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006036TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006037 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006038}
6039
Mike Stump1eb44332009-09-09 15:08:12 +00006040template<typename Derived>
6041Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006042TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006043 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006044}
6045
Mike Stump1eb44332009-09-09 15:08:12 +00006046template<typename Derived>
6047Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006048TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006049 // Transform the base expression.
6050 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6051 if (Base.isInvalid())
6052 return SemaRef.ExprError();
6053
6054 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006055
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006056 // If nothing changed, just retain the existing expression.
6057 if (!getDerived().AlwaysRebuild() &&
6058 Base.get() == E->getBase())
6059 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006060
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006061 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6062 E->getLocation(),
6063 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006064}
6065
Mike Stump1eb44332009-09-09 15:08:12 +00006066template<typename Derived>
6067Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006068TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregore3303542010-04-26 20:47:02 +00006069 // Transform the base expression.
6070 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6071 if (Base.isInvalid())
6072 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006073
Douglas Gregore3303542010-04-26 20:47:02 +00006074 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006075
Douglas Gregore3303542010-04-26 20:47:02 +00006076 // If nothing changed, just retain the existing expression.
6077 if (!getDerived().AlwaysRebuild() &&
6078 Base.get() == E->getBase())
6079 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006080
Douglas Gregore3303542010-04-26 20:47:02 +00006081 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6082 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006083}
6084
Mike Stump1eb44332009-09-09 15:08:12 +00006085template<typename Derived>
6086Sema::OwningExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00006087TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00006088 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006089 // If this implicit setter/getter refers to class methods, it cannot have any
6090 // dependent parts. Just retain the existing declaration.
6091 if (E->getInterfaceDecl())
6092 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006093
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006094 // Transform the base expression.
6095 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6096 if (Base.isInvalid())
6097 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006098
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006099 // We don't need to transform the getters/setters; they will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006100
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006101 // If nothing changed, just retain the existing expression.
6102 if (!getDerived().AlwaysRebuild() &&
6103 Base.get() == E->getBase())
6104 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006105
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006106 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6107 E->getGetterMethod(),
6108 E->getType(),
6109 E->getSetterMethod(),
6110 E->getLocation(),
6111 move(Base));
Sean Huntc3021132010-05-05 15:23:54 +00006112
Douglas Gregorb98b1992009-08-11 05:31:07 +00006113}
6114
Mike Stump1eb44332009-09-09 15:08:12 +00006115template<typename Derived>
6116Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006117TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006118 // Can never occur in a dependent context.
Mike Stump1eb44332009-09-09 15:08:12 +00006119 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006120}
6121
Mike Stump1eb44332009-09-09 15:08:12 +00006122template<typename Derived>
6123Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006124TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006125 // Transform the base expression.
6126 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6127 if (Base.isInvalid())
6128 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006129
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006130 // If nothing changed, just retain the existing expression.
6131 if (!getDerived().AlwaysRebuild() &&
6132 Base.get() == E->getBase())
6133 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006134
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006135 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6136 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006137}
6138
Mike Stump1eb44332009-09-09 15:08:12 +00006139template<typename Derived>
6140Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006141TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006142 bool ArgumentChanged = false;
6143 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6144 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6145 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6146 if (SubExpr.isInvalid())
6147 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006148
Douglas Gregorb98b1992009-08-11 05:31:07 +00006149 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6150 SubExprs.push_back(SubExpr.takeAs<Expr>());
6151 }
Mike Stump1eb44332009-09-09 15:08:12 +00006152
Douglas Gregorb98b1992009-08-11 05:31:07 +00006153 if (!getDerived().AlwaysRebuild() &&
6154 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00006155 return SemaRef.Owned(E->Retain());
6156
Douglas Gregorb98b1992009-08-11 05:31:07 +00006157 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6158 move_arg(SubExprs),
6159 E->getRParenLoc());
6160}
6161
Mike Stump1eb44332009-09-09 15:08:12 +00006162template<typename Derived>
6163Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006164TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006165 // FIXME: Implement this!
6166 assert(false && "Cannot transform block expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00006167 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006168}
6169
Mike Stump1eb44332009-09-09 15:08:12 +00006170template<typename Derived>
6171Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006172TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006173 // FIXME: Implement this!
6174 assert(false && "Cannot transform block-related expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00006175 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006176}
Mike Stump1eb44332009-09-09 15:08:12 +00006177
Douglas Gregorb98b1992009-08-11 05:31:07 +00006178//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006179// Type reconstruction
6180//===----------------------------------------------------------------------===//
6181
Mike Stump1eb44332009-09-09 15:08:12 +00006182template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006183QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6184 SourceLocation Star) {
6185 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006186 getDerived().getBaseEntity());
6187}
6188
Mike Stump1eb44332009-09-09 15:08:12 +00006189template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006190QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6191 SourceLocation Star) {
6192 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006193 getDerived().getBaseEntity());
6194}
6195
Mike Stump1eb44332009-09-09 15:08:12 +00006196template<typename Derived>
6197QualType
John McCall85737a72009-10-30 00:06:24 +00006198TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6199 bool WrittenAsLValue,
6200 SourceLocation Sigil) {
6201 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
6202 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006203}
6204
6205template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006206QualType
John McCall85737a72009-10-30 00:06:24 +00006207TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6208 QualType ClassType,
6209 SourceLocation Sigil) {
John McCall0953e762009-09-24 19:53:00 +00006210 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall85737a72009-10-30 00:06:24 +00006211 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006212}
6213
6214template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006215QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006216TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6217 ArrayType::ArraySizeModifier SizeMod,
6218 const llvm::APInt *Size,
6219 Expr *SizeExpr,
6220 unsigned IndexTypeQuals,
6221 SourceRange BracketsRange) {
6222 if (SizeExpr || !Size)
6223 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6224 IndexTypeQuals, BracketsRange,
6225 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006226
6227 QualType Types[] = {
6228 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6229 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6230 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006231 };
6232 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6233 QualType SizeType;
6234 for (unsigned I = 0; I != NumTypes; ++I)
6235 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6236 SizeType = Types[I];
6237 break;
6238 }
Mike Stump1eb44332009-09-09 15:08:12 +00006239
Douglas Gregor577f75a2009-08-04 16:50:30 +00006240 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006241 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006242 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006243 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006244}
Mike Stump1eb44332009-09-09 15:08:12 +00006245
Douglas Gregor577f75a2009-08-04 16:50:30 +00006246template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006247QualType
6248TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006249 ArrayType::ArraySizeModifier SizeMod,
6250 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00006251 unsigned IndexTypeQuals,
6252 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006253 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00006254 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006255}
6256
6257template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006258QualType
Mike Stump1eb44332009-09-09 15:08:12 +00006259TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006260 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00006261 unsigned IndexTypeQuals,
6262 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006263 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00006264 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006265}
Mike Stump1eb44332009-09-09 15:08:12 +00006266
Douglas Gregor577f75a2009-08-04 16:50:30 +00006267template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006268QualType
6269TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006270 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006271 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006272 unsigned IndexTypeQuals,
6273 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006274 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006275 SizeExpr.takeAs<Expr>(),
6276 IndexTypeQuals, BracketsRange);
6277}
6278
6279template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006280QualType
6281TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006282 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006283 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006284 unsigned IndexTypeQuals,
6285 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006286 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006287 SizeExpr.takeAs<Expr>(),
6288 IndexTypeQuals, BracketsRange);
6289}
6290
6291template<typename Derived>
6292QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson82287d12010-02-05 00:12:22 +00006293 unsigned NumElements,
6294 bool IsAltiVec, bool IsPixel) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006295 // FIXME: semantic checking!
John Thompson82287d12010-02-05 00:12:22 +00006296 return SemaRef.Context.getVectorType(ElementType, NumElements,
6297 IsAltiVec, IsPixel);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006298}
Mike Stump1eb44332009-09-09 15:08:12 +00006299
Douglas Gregor577f75a2009-08-04 16:50:30 +00006300template<typename Derived>
6301QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6302 unsigned NumElements,
6303 SourceLocation AttributeLoc) {
6304 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6305 NumElements, true);
6306 IntegerLiteral *VectorSize
Mike Stump1eb44332009-09-09 15:08:12 +00006307 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006308 AttributeLoc);
6309 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6310 AttributeLoc);
6311}
Mike Stump1eb44332009-09-09 15:08:12 +00006312
Douglas Gregor577f75a2009-08-04 16:50:30 +00006313template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006314QualType
6315TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006316 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006317 SourceLocation AttributeLoc) {
6318 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6319}
Mike Stump1eb44332009-09-09 15:08:12 +00006320
Douglas Gregor577f75a2009-08-04 16:50:30 +00006321template<typename Derived>
6322QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00006323 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006324 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00006325 bool Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006326 unsigned Quals) {
Mike Stump1eb44332009-09-09 15:08:12 +00006327 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006328 Quals,
6329 getDerived().getBaseLocation(),
6330 getDerived().getBaseEntity());
6331}
Mike Stump1eb44332009-09-09 15:08:12 +00006332
Douglas Gregor577f75a2009-08-04 16:50:30 +00006333template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00006334QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6335 return SemaRef.Context.getFunctionNoProtoType(T);
6336}
6337
6338template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00006339QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6340 assert(D && "no decl found");
6341 if (D->isInvalidDecl()) return QualType();
6342
Douglas Gregor92e986e2010-04-22 16:44:27 +00006343 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00006344 TypeDecl *Ty;
6345 if (isa<UsingDecl>(D)) {
6346 UsingDecl *Using = cast<UsingDecl>(D);
6347 assert(Using->isTypeName() &&
6348 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6349
6350 // A valid resolved using typename decl points to exactly one type decl.
6351 assert(++Using->shadow_begin() == Using->shadow_end());
6352 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00006353
John McCalled976492009-12-04 22:46:56 +00006354 } else {
6355 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6356 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6357 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6358 }
6359
6360 return SemaRef.Context.getTypeDeclType(Ty);
6361}
6362
6363template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00006364QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006365 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6366}
6367
6368template<typename Derived>
6369QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6370 return SemaRef.Context.getTypeOfType(Underlying);
6371}
6372
6373template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00006374QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006375 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6376}
6377
6378template<typename Derived>
6379QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00006380 TemplateName Template,
6381 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00006382 const TemplateArgumentListInfo &TemplateArgs) {
6383 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006384}
Mike Stump1eb44332009-09-09 15:08:12 +00006385
Douglas Gregordcee1a12009-08-06 05:28:30 +00006386template<typename Derived>
6387NestedNameSpecifier *
6388TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6389 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00006390 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006391 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00006392 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00006393 CXXScopeSpec SS;
6394 // FIXME: The source location information is all wrong.
6395 SS.setRange(Range);
6396 SS.setScopeRep(Prefix);
6397 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00006398 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00006399 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006400 ObjectType,
6401 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00006402 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00006403}
6404
6405template<typename Derived>
6406NestedNameSpecifier *
6407TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6408 SourceRange Range,
6409 NamespaceDecl *NS) {
6410 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6411}
6412
6413template<typename Derived>
6414NestedNameSpecifier *
6415TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6416 SourceRange Range,
6417 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00006418 QualType T) {
6419 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00006420 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00006421 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00006422 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6423 T.getTypePtr());
6424 }
Mike Stump1eb44332009-09-09 15:08:12 +00006425
Douglas Gregordcee1a12009-08-06 05:28:30 +00006426 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6427 return 0;
6428}
Mike Stump1eb44332009-09-09 15:08:12 +00006429
Douglas Gregord1067e52009-08-06 06:41:21 +00006430template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006431TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006432TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6433 bool TemplateKW,
6434 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00006435 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00006436 Template);
6437}
6438
6439template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006440TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006441TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006442 const IdentifierInfo &II,
6443 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00006444 CXXScopeSpec SS;
6445 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump1eb44332009-09-09 15:08:12 +00006446 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00006447 UnqualifiedId Name;
6448 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006449 return getSema().ActOnDependentTemplateName(
6450 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006451 SS,
Douglas Gregor014e88d2009-11-03 23:16:33 +00006452 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00006453 ObjectType.getAsOpaquePtr(),
6454 /*EnteringContext=*/false)
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006455 .template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00006456}
Mike Stump1eb44332009-09-09 15:08:12 +00006457
Douglas Gregorb98b1992009-08-11 05:31:07 +00006458template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006459TemplateName
6460TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6461 OverloadedOperatorKind Operator,
6462 QualType ObjectType) {
6463 CXXScopeSpec SS;
6464 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6465 SS.setScopeRep(Qualifier);
6466 UnqualifiedId Name;
6467 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6468 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6469 Operator, SymbolLocations);
6470 return getSema().ActOnDependentTemplateName(
6471 /*FIXME:*/getDerived().getBaseLocation(),
6472 SS,
6473 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00006474 ObjectType.getAsOpaquePtr(),
6475 /*EnteringContext=*/false)
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006476 .template getAsVal<TemplateName>();
6477}
Sean Huntc3021132010-05-05 15:23:54 +00006478
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006479template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006480Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006481TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6482 SourceLocation OpLoc,
6483 ExprArg Callee,
6484 ExprArg First,
6485 ExprArg Second) {
6486 Expr *FirstExpr = (Expr *)First.get();
6487 Expr *SecondExpr = (Expr *)Second.get();
John McCallba135432009-11-21 08:51:07 +00006488 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006489 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00006490
Douglas Gregorb98b1992009-08-11 05:31:07 +00006491 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00006492 if (Op == OO_Subscript) {
6493 if (!FirstExpr->getType()->isOverloadableType() &&
6494 !SecondExpr->getType()->isOverloadableType())
6495 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCallba135432009-11-21 08:51:07 +00006496 CalleeExpr->getLocStart(),
Sebastian Redlf322ed62009-10-29 20:17:01 +00006497 move(Second), OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00006498 } else if (Op == OO_Arrow) {
6499 // -> is never a builtin operation.
6500 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redlf322ed62009-10-29 20:17:01 +00006501 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502 if (!FirstExpr->getType()->isOverloadableType()) {
6503 // The argument is not of overloadable type, so try to create a
6504 // built-in unary operation.
Mike Stump1eb44332009-09-09 15:08:12 +00006505 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006506 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00006507
Douglas Gregorb98b1992009-08-11 05:31:07 +00006508 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6509 }
6510 } else {
Mike Stump1eb44332009-09-09 15:08:12 +00006511 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006512 !SecondExpr->getType()->isOverloadableType()) {
6513 // Neither of the arguments is an overloadable type, so try to
6514 // create a built-in binary operation.
6515 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00006516 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006517 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6518 if (Result.isInvalid())
6519 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006520
Douglas Gregorb98b1992009-08-11 05:31:07 +00006521 First.release();
6522 Second.release();
6523 return move(Result);
6524 }
6525 }
Mike Stump1eb44332009-09-09 15:08:12 +00006526
6527 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00006528 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00006529 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00006530
John McCallba135432009-11-21 08:51:07 +00006531 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6532 assert(ULE->requiresADL());
6533
6534 // FIXME: Do we have to check
6535 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00006536 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00006537 } else {
John McCall6e266892010-01-26 03:27:55 +00006538 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCallba135432009-11-21 08:51:07 +00006539 }
Mike Stump1eb44332009-09-09 15:08:12 +00006540
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541 // Add any functions found via argument-dependent lookup.
6542 Expr *Args[2] = { FirstExpr, SecondExpr };
6543 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00006544
Douglas Gregorb98b1992009-08-11 05:31:07 +00006545 // Create the overloaded operator invocation for unary operators.
6546 if (NumArgs == 1 || isPostIncDec) {
Mike Stump1eb44332009-09-09 15:08:12 +00006547 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006548 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6549 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6550 }
Mike Stump1eb44332009-09-09 15:08:12 +00006551
Sebastian Redlf322ed62009-10-29 20:17:01 +00006552 if (Op == OO_Subscript)
John McCallba135432009-11-21 08:51:07 +00006553 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6554 OpLoc,
6555 move(First),
6556 move(Second));
Sebastian Redlf322ed62009-10-29 20:17:01 +00006557
Douglas Gregorb98b1992009-08-11 05:31:07 +00006558 // Create the overloaded operator invocation for binary operators.
Mike Stump1eb44332009-09-09 15:08:12 +00006559 BinaryOperator::Opcode Opc =
Douglas Gregorb98b1992009-08-11 05:31:07 +00006560 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00006561 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006562 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6563 if (Result.isInvalid())
6564 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006565
Douglas Gregorb98b1992009-08-11 05:31:07 +00006566 First.release();
6567 Second.release();
Mike Stump1eb44332009-09-09 15:08:12 +00006568 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006569}
Mike Stump1eb44332009-09-09 15:08:12 +00006570
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006571template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00006572Sema::OwningExprResult
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006573TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6574 SourceLocation OperatorLoc,
6575 bool isArrow,
6576 NestedNameSpecifier *Qualifier,
6577 SourceRange QualifierRange,
6578 TypeSourceInfo *ScopeType,
6579 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006580 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006581 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006582 CXXScopeSpec SS;
6583 if (Qualifier) {
6584 SS.setRange(QualifierRange);
6585 SS.setScopeRep(Qualifier);
6586 }
6587
6588 Expr *BaseE = (Expr *)Base.get();
6589 QualType BaseType = BaseE->getType();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006590 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006591 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00006592 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00006593 !BaseType->getAs<PointerType>()->getPointeeType()
6594 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006595 // This pseudo-destructor expression is still a pseudo-destructor.
6596 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6597 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006598 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006599 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006600 /*FIXME?*/true);
6601 }
Sean Huntc3021132010-05-05 15:23:54 +00006602
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006603 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006604 DeclarationName Name
6605 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6606 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
Sean Huntc3021132010-05-05 15:23:54 +00006607
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006608 // FIXME: the ScopeType should be tacked onto SS.
Sean Huntc3021132010-05-05 15:23:54 +00006609
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006610 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6611 OperatorLoc, isArrow,
6612 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006613 Name, Destroyed.getLocation(),
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006614 /*TemplateArgs*/ 0);
6615}
6616
Douglas Gregor577f75a2009-08-04 16:50:30 +00006617} // end namespace clang
6618
6619#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H