blob: 2f8d075c2ac4eac2d574f57c38970ac9d6737b6b [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
Douglas Gregore737f502010-08-12 20:07:10 +000016#include "clang/Sema/Sema.h"
17#include "clang/Sema/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.
Abramo Bagnara25777432010-08-11 22:01:17 +0000279 DeclarationNameInfo
280 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
281 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000282
Douglas Gregor577f75a2009-08-04 16:50:30 +0000283 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000284 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000285 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000286 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000287 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000288 TemplateName TransformTemplateName(TemplateName Name,
289 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000290
Douglas Gregor577f75a2009-08-04 16:50:30 +0000291 /// \brief Transform the given template argument.
292 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000293 /// By default, this operation transforms the type, expression, or
294 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000295 /// new template argument from the transformed result. Subclasses may
296 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000297 ///
298 /// Returns true if there was an error.
299 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
300 TemplateArgumentLoc &Output);
301
302 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
303 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
304 TemplateArgumentLoc &ArgLoc);
305
John McCalla93c9342009-12-07 02:54:59 +0000306 /// \brief Fakes up a TypeSourceInfo for a type.
307 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
308 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000309 getDerived().getBaseLocation());
310 }
Mike Stump1eb44332009-09-09 15:08:12 +0000311
John McCalla2becad2009-10-21 00:40:46 +0000312#define ABSTRACT_TYPELOC(CLASS, PARENT)
313#define TYPELOC(CLASS, PARENT) \
Douglas Gregor124b8782010-02-16 19:09:40 +0000314 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
315 QualType ObjectType = QualType());
John McCalla2becad2009-10-21 00:40:46 +0000316#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000317
John McCall21ef0fa2010-03-11 09:03:00 +0000318 /// \brief Transforms the parameters of a function type into the
319 /// given vectors.
320 ///
321 /// The result vectors should be kept in sync; null entries in the
322 /// variables vector are acceptable.
323 ///
324 /// Return true on error.
325 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
326 llvm::SmallVectorImpl<QualType> &PTypes,
327 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
328
329 /// \brief Transforms a single function-type parameter. Return null
330 /// on error.
331 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
332
Sean Huntc3021132010-05-05 15:23:54 +0000333 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +0000334 QualType ObjectType);
John McCall85737a72009-10-30 00:06:24 +0000335
Sean Huntc3021132010-05-05 15:23:54 +0000336 QualType
Douglas Gregordd62b152009-10-19 22:04:39 +0000337 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
338 QualType ObjectType);
John McCall833ca992009-10-29 08:12:44 +0000339
Douglas Gregor43959a92009-08-20 07:17:43 +0000340 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Zhongxing Xud8383d42010-04-21 06:32:25 +0000341 OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000342
Douglas Gregor43959a92009-08-20 07:17:43 +0000343#define STMT(Node, Parent) \
344 OwningStmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000345#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +0000346 OwningExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000347#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000348#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000349
Douglas Gregor577f75a2009-08-04 16:50:30 +0000350 /// \brief Build a new pointer type given its pointee type.
351 ///
352 /// By default, performs semantic analysis when building the pointer type.
353 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000354 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000355
356 /// \brief Build a new block pointer type given its pointee type.
357 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000358 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000359 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000360 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000361
John McCall85737a72009-10-30 00:06:24 +0000362 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000363 ///
John McCall85737a72009-10-30 00:06:24 +0000364 /// By default, performs semantic analysis when building the
365 /// reference type. Subclasses may override this routine to provide
366 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000367 ///
John McCall85737a72009-10-30 00:06:24 +0000368 /// \param LValue whether the type was written with an lvalue sigil
369 /// or an rvalue sigil.
370 QualType RebuildReferenceType(QualType ReferentType,
371 bool LValue,
372 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000373
Douglas Gregor577f75a2009-08-04 16:50:30 +0000374 /// \brief Build a new member pointer type given the pointee type and the
375 /// class type it refers into.
376 ///
377 /// By default, performs semantic analysis when building the member pointer
378 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000379 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
380 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000381
Douglas Gregor577f75a2009-08-04 16:50:30 +0000382 /// \brief Build a new array type given the element type, size
383 /// modifier, size of the array (if known), size expression, and index type
384 /// qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000388 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000389 QualType RebuildArrayType(QualType ElementType,
390 ArrayType::ArraySizeModifier SizeMod,
391 const llvm::APInt *Size,
392 Expr *SizeExpr,
393 unsigned IndexTypeQuals,
394 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000395
Douglas Gregor577f75a2009-08-04 16:50:30 +0000396 /// \brief Build a new constant array type given the element type, size
397 /// modifier, (known) size of the array, and index type qualifiers.
398 ///
399 /// By default, performs semantic analysis when building the array type.
400 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000401 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000402 ArrayType::ArraySizeModifier SizeMod,
403 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000404 unsigned IndexTypeQuals,
405 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000406
Douglas Gregor577f75a2009-08-04 16:50:30 +0000407 /// \brief Build a new incomplete array type given the element type, size
408 /// modifier, and index type qualifiers.
409 ///
410 /// By default, performs semantic analysis when building the array type.
411 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000412 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000413 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000414 unsigned IndexTypeQuals,
415 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000416
Mike Stump1eb44332009-09-09 15:08:12 +0000417 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000418 /// size modifier, size expression, and index type qualifiers.
419 ///
420 /// By default, performs semantic analysis when building the array type.
421 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000422 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000423 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000424 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000425 unsigned IndexTypeQuals,
426 SourceRange BracketsRange);
427
Mike Stump1eb44332009-09-09 15:08:12 +0000428 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000429 /// size modifier, size expression, and index type qualifiers.
430 ///
431 /// By default, performs semantic analysis when building the array type.
432 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000433 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000434 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000435 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000436 unsigned IndexTypeQuals,
437 SourceRange BracketsRange);
438
439 /// \brief Build a new vector type given the element type and
440 /// number of elements.
441 ///
442 /// By default, performs semantic analysis when building the vector type.
443 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000444 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Chris Lattner788b0fd2010-06-23 06:00:24 +0000445 VectorType::AltiVecSpecific AltiVecSpec);
Mike Stump1eb44332009-09-09 15:08:12 +0000446
Douglas Gregor577f75a2009-08-04 16:50:30 +0000447 /// \brief Build a new extended vector type given the element type and
448 /// number of elements.
449 ///
450 /// By default, performs semantic analysis when building the vector type.
451 /// Subclasses may override this routine to provide different behavior.
452 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
453 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000454
455 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000456 /// given the element type and number of elements.
457 ///
458 /// By default, performs semantic analysis when building the vector type.
459 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000460 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000461 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000462 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000463
Douglas Gregor577f75a2009-08-04 16:50:30 +0000464 /// \brief Build a new function type.
465 ///
466 /// By default, performs semantic analysis when building the function type.
467 /// Subclasses may override this routine to provide different behavior.
468 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000469 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000470 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000471 bool Variadic, unsigned Quals,
472 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000473
John McCalla2becad2009-10-21 00:40:46 +0000474 /// \brief Build a new unprototyped function type.
475 QualType RebuildFunctionNoProtoType(QualType ResultType);
476
John McCalled976492009-12-04 22:46:56 +0000477 /// \brief Rebuild an unresolved typename type, given the decl that
478 /// the UnresolvedUsingTypenameDecl was transformed to.
479 QualType RebuildUnresolvedUsingType(Decl *D);
480
Douglas Gregor577f75a2009-08-04 16:50:30 +0000481 /// \brief Build a new typedef type.
482 QualType RebuildTypedefType(TypedefDecl *Typedef) {
483 return SemaRef.Context.getTypeDeclType(Typedef);
484 }
485
486 /// \brief Build a new class/struct/union type.
487 QualType RebuildRecordType(RecordDecl *Record) {
488 return SemaRef.Context.getTypeDeclType(Record);
489 }
490
491 /// \brief Build a new Enum type.
492 QualType RebuildEnumType(EnumDecl *Enum) {
493 return SemaRef.Context.getTypeDeclType(Enum);
494 }
John McCall7da24312009-09-05 00:15:47 +0000495
Mike Stump1eb44332009-09-09 15:08:12 +0000496 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000497 ///
498 /// By default, performs semantic analysis when building the typeof type.
499 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000500 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000501
Mike Stump1eb44332009-09-09 15:08:12 +0000502 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000503 ///
504 /// By default, builds a new TypeOfType with the given underlying type.
505 QualType RebuildTypeOfType(QualType Underlying);
506
Mike Stump1eb44332009-09-09 15:08:12 +0000507 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000508 ///
509 /// By default, performs semantic analysis when building the decltype type.
510 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000511 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump1eb44332009-09-09 15:08:12 +0000512
Douglas Gregor577f75a2009-08-04 16:50:30 +0000513 /// \brief Build a new template specialization type.
514 ///
515 /// By default, performs semantic analysis when building the template
516 /// specialization type. Subclasses may override this routine to provide
517 /// different behavior.
518 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000519 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000520 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000521
Douglas Gregor577f75a2009-08-04 16:50:30 +0000522 /// \brief Build a new qualified name type.
523 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000524 /// By default, builds a new ElaboratedType type from the keyword,
525 /// the nested-name-specifier and the named type.
526 /// Subclasses may override this routine to provide different behavior.
527 QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword,
528 NestedNameSpecifier *NNS, QualType Named) {
529 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000530 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000531
532 /// \brief Build a new typename type that refers to a template-id.
533 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000534 /// By default, builds a new DependentNameType type from the
535 /// nested-name-specifier and the given type. Subclasses may override
536 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000537 QualType RebuildDependentTemplateSpecializationType(
538 ElaboratedTypeKeyword Keyword,
539 NestedNameSpecifier *NNS,
540 const IdentifierInfo *Name,
541 SourceLocation NameLoc,
542 const TemplateArgumentListInfo &Args) {
543 // Rebuild the template name.
544 // TODO: avoid TemplateName abstraction
545 TemplateName InstName =
546 getDerived().RebuildTemplateName(NNS, *Name, QualType());
547
Douglas Gregor96fb42e2010-06-18 22:12:56 +0000548 if (InstName.isNull())
549 return QualType();
550
John McCall33500952010-06-11 00:33:02 +0000551 // If it's still dependent, make a dependent specialization.
552 if (InstName.getAsDependentTemplateName())
553 return SemaRef.Context.getDependentTemplateSpecializationType(
554 Keyword, NNS, Name, Args);
555
556 // Otherwise, make an elaborated type wrapping a non-dependent
557 // specialization.
558 QualType T =
559 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
560 if (T.isNull()) return QualType();
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000561
Abramo Bagnara22f638a2010-08-10 13:46:45 +0000562 // NOTE: NNS is already recorded in template specialization type T.
563 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000564 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000565
566 /// \brief Build a new typename type that refers to an identifier.
567 ///
568 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000569 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000570 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000571 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000572 NestedNameSpecifier *NNS,
573 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000574 SourceLocation KeywordLoc,
575 SourceRange NNSRange,
576 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000577 CXXScopeSpec SS;
578 SS.setScopeRep(NNS);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000579 SS.setRange(NNSRange);
580
Douglas Gregor40336422010-03-31 22:19:08 +0000581 if (NNS->isDependent()) {
582 // If the name is still dependent, just build a new dependent name type.
583 if (!SemaRef.computeDeclContext(SS))
584 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
585 }
586
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000587 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000588 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
589 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000590
591 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
592
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000593 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000594 // into a non-dependent elaborated-type-specifier. Find the tag we're
595 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000596 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000597 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
598 if (!DC)
599 return QualType();
600
John McCall56138762010-05-27 06:40:31 +0000601 if (SemaRef.RequireCompleteDeclContext(SS, DC))
602 return QualType();
603
Douglas Gregor40336422010-03-31 22:19:08 +0000604 TagDecl *Tag = 0;
605 SemaRef.LookupQualifiedName(Result, DC);
606 switch (Result.getResultKind()) {
607 case LookupResult::NotFound:
608 case LookupResult::NotFoundInCurrentInstantiation:
609 break;
Sean Huntc3021132010-05-05 15:23:54 +0000610
Douglas Gregor40336422010-03-31 22:19:08 +0000611 case LookupResult::Found:
612 Tag = Result.getAsSingle<TagDecl>();
613 break;
Sean Huntc3021132010-05-05 15:23:54 +0000614
Douglas Gregor40336422010-03-31 22:19:08 +0000615 case LookupResult::FoundOverloaded:
616 case LookupResult::FoundUnresolvedValue:
617 llvm_unreachable("Tag lookup cannot find non-tags");
618 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000619
Douglas Gregor40336422010-03-31 22:19:08 +0000620 case LookupResult::Ambiguous:
621 // Let the LookupResult structure handle ambiguities.
622 return QualType();
623 }
624
625 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000626 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000627 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000628 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000629 return QualType();
630 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000631
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000632 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
633 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000634 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
635 return QualType();
636 }
637
638 // Build the elaborated-type-specifier type.
639 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000640 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000641 }
Mike Stump1eb44332009-09-09 15:08:12 +0000642
Douglas Gregordcee1a12009-08-06 05:28:30 +0000643 /// \brief Build a new nested-name-specifier given the prefix and an
644 /// identifier that names the next step in the nested-name-specifier.
645 ///
646 /// By default, performs semantic analysis when building the new
647 /// nested-name-specifier. Subclasses may override this routine to provide
648 /// different behavior.
649 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
650 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000651 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000652 QualType ObjectType,
653 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000654
655 /// \brief Build a new nested-name-specifier given the prefix and the
656 /// namespace named in the next step in the nested-name-specifier.
657 ///
658 /// By default, performs semantic analysis when building the new
659 /// nested-name-specifier. Subclasses may override this routine to provide
660 /// different behavior.
661 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
662 SourceRange Range,
663 NamespaceDecl *NS);
664
665 /// \brief Build a new nested-name-specifier given the prefix and the
666 /// type named in the next step in the nested-name-specifier.
667 ///
668 /// By default, performs semantic analysis when building the new
669 /// nested-name-specifier. Subclasses may override this routine to provide
670 /// different behavior.
671 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
672 SourceRange Range,
673 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000674 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000675
676 /// \brief Build a new template name given a nested name specifier, a flag
677 /// indicating whether the "template" keyword was provided, and the template
678 /// that the template name refers to.
679 ///
680 /// By default, builds the new template name directly. Subclasses may override
681 /// this routine to provide different behavior.
682 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
683 bool TemplateKW,
684 TemplateDecl *Template);
685
Douglas Gregord1067e52009-08-06 06:41:21 +0000686 /// \brief Build a new template name given a nested name specifier and the
687 /// name that is referred to as a template.
688 ///
689 /// By default, performs semantic analysis to determine whether the name can
690 /// be resolved to a specific template, then builds the appropriate kind of
691 /// template name. Subclasses may override this routine to provide different
692 /// behavior.
693 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000694 const IdentifierInfo &II,
695 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000696
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000697 /// \brief Build a new template name given a nested name specifier and the
698 /// overloaded operator name that is referred to as a template.
699 ///
700 /// By default, performs semantic analysis to determine whether the name can
701 /// be resolved to a specific template, then builds the appropriate kind of
702 /// template name. Subclasses may override this routine to provide different
703 /// behavior.
704 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
705 OverloadedOperatorKind Operator,
706 QualType ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +0000707
Douglas Gregor43959a92009-08-20 07:17:43 +0000708 /// \brief Build a new compound statement.
709 ///
710 /// By default, performs semantic analysis to build the new statement.
711 /// Subclasses may override this routine to provide different behavior.
712 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
713 MultiStmtArg Statements,
714 SourceLocation RBraceLoc,
715 bool IsStmtExpr) {
716 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
717 IsStmtExpr);
718 }
719
720 /// \brief Build a new case statement.
721 ///
722 /// By default, performs semantic analysis to build the new statement.
723 /// Subclasses may override this routine to provide different behavior.
724 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
725 ExprArg LHS,
726 SourceLocation EllipsisLoc,
727 ExprArg RHS,
728 SourceLocation ColonLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000729 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregor43959a92009-08-20 07:17:43 +0000730 ColonLoc);
731 }
Mike Stump1eb44332009-09-09 15:08:12 +0000732
Douglas Gregor43959a92009-08-20 07:17:43 +0000733 /// \brief Attach the body to a new case statement.
734 ///
735 /// By default, performs semantic analysis to build the new statement.
736 /// Subclasses may override this routine to provide different behavior.
737 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
738 getSema().ActOnCaseStmtBody(S.get(), move(Body));
739 return move(S);
740 }
Mike Stump1eb44332009-09-09 15:08:12 +0000741
Douglas Gregor43959a92009-08-20 07:17:43 +0000742 /// \brief Build a new default statement.
743 ///
744 /// By default, performs semantic analysis to build the new statement.
745 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000746 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000747 SourceLocation ColonLoc,
748 StmtArg SubStmt) {
Mike Stump1eb44332009-09-09 15:08:12 +0000749 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregor43959a92009-08-20 07:17:43 +0000750 /*CurScope=*/0);
751 }
Mike Stump1eb44332009-09-09 15:08:12 +0000752
Douglas Gregor43959a92009-08-20 07:17:43 +0000753 /// \brief Build a new label statement.
754 ///
755 /// By default, performs semantic analysis to build the new statement.
756 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000757 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000758 IdentifierInfo *Id,
759 SourceLocation ColonLoc,
760 StmtArg SubStmt) {
761 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
762 }
Mike Stump1eb44332009-09-09 15:08:12 +0000763
Douglas Gregor43959a92009-08-20 07:17:43 +0000764 /// \brief Build a new "if" statement.
765 ///
766 /// By default, performs semantic analysis to build the new statement.
767 /// Subclasses may override this routine to provide different behavior.
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000768 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Sean Huntc3021132010-05-05 15:23:54 +0000769 VarDecl *CondVar, StmtArg Then,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000770 SourceLocation ElseLoc, StmtArg Else) {
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000771 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000772 move(Then), ElseLoc, move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +0000773 }
Mike Stump1eb44332009-09-09 15:08:12 +0000774
Douglas Gregor43959a92009-08-20 07:17:43 +0000775 /// \brief Start building a new switch statement.
776 ///
777 /// By default, performs semantic analysis to build the new statement.
778 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor586596f2010-05-06 17:25:47 +0000779 OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
780 Sema::ExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000781 VarDecl *CondVar) {
Douglas Gregor586596f2010-05-06 17:25:47 +0000782 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond),
783 DeclPtrTy::make(CondVar));
Douglas Gregor43959a92009-08-20 07:17:43 +0000784 }
Mike Stump1eb44332009-09-09 15:08:12 +0000785
Douglas Gregor43959a92009-08-20 07:17:43 +0000786 /// \brief Attach the body to the switch statement.
787 ///
788 /// By default, performs semantic analysis to build the new statement.
789 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000790 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000791 StmtArg Switch, StmtArg Body) {
792 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
793 move(Body));
794 }
795
796 /// \brief Build a new while statement.
797 ///
798 /// By default, performs semantic analysis to build the new statement.
799 /// Subclasses may override this routine to provide different behavior.
800 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000801 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000802 VarDecl *CondVar,
Douglas Gregor43959a92009-08-20 07:17:43 +0000803 StmtArg Body) {
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000804 return getSema().ActOnWhileStmt(WhileLoc, Cond,
Douglas Gregor586596f2010-05-06 17:25:47 +0000805 DeclPtrTy::make(CondVar), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000806 }
Mike Stump1eb44332009-09-09 15:08:12 +0000807
Douglas Gregor43959a92009-08-20 07:17:43 +0000808 /// \brief Build a new do-while statement.
809 ///
810 /// By default, performs semantic analysis to build the new statement.
811 /// Subclasses may override this routine to provide different behavior.
812 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
813 SourceLocation WhileLoc,
814 SourceLocation LParenLoc,
815 ExprArg Cond,
816 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000817 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000818 move(Cond), RParenLoc);
819 }
820
821 /// \brief Build a new for statement.
822 ///
823 /// By default, performs semantic analysis to build the new statement.
824 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000825 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000826 SourceLocation LParenLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000827 StmtArg Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000828 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000829 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000830 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000831 DeclPtrTy::make(CondVar),
832 Inc, RParenLoc, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000833 }
Mike Stump1eb44332009-09-09 15:08:12 +0000834
Douglas Gregor43959a92009-08-20 07:17:43 +0000835 /// \brief Build a new goto statement.
836 ///
837 /// By default, performs semantic analysis to build the new statement.
838 /// Subclasses may override this routine to provide different behavior.
839 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
840 SourceLocation LabelLoc,
841 LabelStmt *Label) {
842 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
843 }
844
845 /// \brief Build a new indirect goto statement.
846 ///
847 /// By default, performs semantic analysis to build the new statement.
848 /// Subclasses may override this routine to provide different behavior.
849 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
850 SourceLocation StarLoc,
851 ExprArg Target) {
852 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
853 }
Mike Stump1eb44332009-09-09 15:08:12 +0000854
Douglas Gregor43959a92009-08-20 07:17:43 +0000855 /// \brief Build a new return statement.
856 ///
857 /// By default, performs semantic analysis to build the new statement.
858 /// Subclasses may override this routine to provide different behavior.
859 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
860 ExprArg Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000861
Douglas Gregor43959a92009-08-20 07:17:43 +0000862 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
863 }
Mike Stump1eb44332009-09-09 15:08:12 +0000864
Douglas Gregor43959a92009-08-20 07:17:43 +0000865 /// \brief Build a new declaration statement.
866 ///
867 /// By default, performs semantic analysis to build the new statement.
868 /// Subclasses may override this routine to provide different behavior.
869 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000870 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000871 SourceLocation EndLoc) {
872 return getSema().Owned(
873 new (getSema().Context) DeclStmt(
874 DeclGroupRef::Create(getSema().Context,
875 Decls, NumDecls),
876 StartLoc, EndLoc));
877 }
Mike Stump1eb44332009-09-09 15:08:12 +0000878
Anders Carlsson703e3942010-01-24 05:50:09 +0000879 /// \brief Build a new inline asm statement.
880 ///
881 /// By default, performs semantic analysis to build the new statement.
882 /// Subclasses may override this routine to provide different behavior.
883 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
884 bool IsSimple,
885 bool IsVolatile,
886 unsigned NumOutputs,
887 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000888 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000889 MultiExprArg Constraints,
890 MultiExprArg Exprs,
891 ExprArg AsmString,
892 MultiExprArg Clobbers,
893 SourceLocation RParenLoc,
894 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +0000895 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +0000896 NumInputs, Names, move(Constraints),
897 move(Exprs), move(AsmString), move(Clobbers),
898 RParenLoc, MSAsm);
899 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000900
901 /// \brief Build a new Objective-C @try statement.
902 ///
903 /// By default, performs semantic analysis to build the new statement.
904 /// Subclasses may override this routine to provide different behavior.
905 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
906 StmtArg TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000907 MultiStmtArg CatchStmts,
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000908 StmtArg Finally) {
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000909 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts),
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000910 move(Finally));
911 }
912
Douglas Gregorbe270a02010-04-26 17:57:08 +0000913 /// \brief Rebuild an Objective-C exception declaration.
914 ///
915 /// By default, performs semantic analysis to build the new declaration.
916 /// Subclasses may override this routine to provide different behavior.
917 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
918 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +0000919 return getSema().BuildObjCExceptionDecl(TInfo, T,
920 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +0000921 ExceptionDecl->getLocation());
922 }
Sean Huntc3021132010-05-05 15:23:54 +0000923
Douglas Gregorbe270a02010-04-26 17:57:08 +0000924 /// \brief Build a new Objective-C @catch statement.
925 ///
926 /// By default, performs semantic analysis to build the new statement.
927 /// Subclasses may override this routine to provide different behavior.
928 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
929 SourceLocation RParenLoc,
930 VarDecl *Var,
931 StmtArg Body) {
932 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
933 Sema::DeclPtrTy::make(Var),
934 move(Body));
935 }
Sean Huntc3021132010-05-05 15:23:54 +0000936
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000937 /// \brief Build a new Objective-C @finally statement.
938 ///
939 /// By default, performs semantic analysis to build the new statement.
940 /// Subclasses may override this routine to provide different behavior.
941 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
942 StmtArg Body) {
943 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
944 }
Sean Huntc3021132010-05-05 15:23:54 +0000945
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000946 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +0000947 ///
948 /// By default, performs semantic analysis to build the new statement.
949 /// Subclasses may override this routine to provide different behavior.
950 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
951 ExprArg Operand) {
952 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
953 }
Sean Huntc3021132010-05-05 15:23:54 +0000954
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000955 /// \brief Build a new Objective-C @synchronized statement.
956 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +0000957 /// By default, performs semantic analysis to build the new statement.
958 /// Subclasses may override this routine to provide different behavior.
959 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
960 ExprArg Object,
961 StmtArg Body) {
962 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
963 move(Body));
964 }
Douglas Gregorc3203e72010-04-22 23:10:45 +0000965
966 /// \brief Build a new Objective-C fast enumeration statement.
967 ///
968 /// By default, performs semantic analysis to build the new statement.
969 /// Subclasses may override this routine to provide different behavior.
970 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
971 SourceLocation LParenLoc,
972 StmtArg Element,
973 ExprArg Collection,
974 SourceLocation RParenLoc,
975 StmtArg Body) {
976 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
Sean Huntc3021132010-05-05 15:23:54 +0000977 move(Element),
Douglas Gregorc3203e72010-04-22 23:10:45 +0000978 move(Collection),
979 RParenLoc,
980 move(Body));
981 }
Sean Huntc3021132010-05-05 15:23:54 +0000982
Douglas Gregor43959a92009-08-20 07:17:43 +0000983 /// \brief Build a new C++ exception declaration.
984 ///
985 /// By default, performs semantic analysis to build the new decaration.
986 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000987 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000988 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000989 IdentifierInfo *Name,
990 SourceLocation Loc,
991 SourceRange TypeRange) {
Mike Stump1eb44332009-09-09 15:08:12 +0000992 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000993 TypeRange);
994 }
995
996 /// \brief Build a new C++ catch statement.
997 ///
998 /// By default, performs semantic analysis to build the new statement.
999 /// Subclasses may override this routine to provide different behavior.
1000 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1001 VarDecl *ExceptionDecl,
1002 StmtArg Handler) {
1003 return getSema().Owned(
Mike Stump1eb44332009-09-09 15:08:12 +00001004 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregor43959a92009-08-20 07:17:43 +00001005 Handler.takeAs<Stmt>()));
1006 }
Mike Stump1eb44332009-09-09 15:08:12 +00001007
Douglas Gregor43959a92009-08-20 07:17:43 +00001008 /// \brief Build a new C++ try statement.
1009 ///
1010 /// By default, performs semantic analysis to build the new statement.
1011 /// Subclasses may override this routine to provide different behavior.
1012 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1013 StmtArg TryBlock,
1014 MultiStmtArg Handlers) {
1015 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
1016 }
Mike Stump1eb44332009-09-09 15:08:12 +00001017
Douglas Gregorb98b1992009-08-11 05:31:07 +00001018 /// \brief Build a new expression that references a declaration.
1019 ///
1020 /// By default, performs semantic analysis to build the new expression.
1021 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001022 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1023 LookupResult &R,
1024 bool RequiresADL) {
1025 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1026 }
1027
1028
1029 /// \brief Build a new expression that references a declaration.
1030 ///
1031 /// By default, performs semantic analysis to build the new expression.
1032 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora2813ce2009-10-23 18:54:35 +00001033 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1034 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001035 ValueDecl *VD,
1036 const DeclarationNameInfo &NameInfo,
John McCalldbd872f2009-12-08 09:08:17 +00001037 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001038 CXXScopeSpec SS;
1039 SS.setScopeRep(Qualifier);
1040 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001041
1042 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001043
1044 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001045 }
Mike Stump1eb44332009-09-09 15:08:12 +00001046
Douglas Gregorb98b1992009-08-11 05:31:07 +00001047 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001048 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001049 /// By default, performs semantic analysis to build the new expression.
1050 /// Subclasses may override this routine to provide different behavior.
1051 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1052 SourceLocation RParen) {
1053 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1054 }
1055
Douglas Gregora71d8192009-09-04 17:36:40 +00001056 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001057 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001058 /// By default, performs semantic analysis to build the new expression.
1059 /// Subclasses may override this routine to provide different behavior.
1060 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1061 SourceLocation OperatorLoc,
1062 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001063 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001064 SourceRange QualifierRange,
1065 TypeSourceInfo *ScopeType,
1066 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001067 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001068 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001069
Douglas Gregorb98b1992009-08-11 05:31:07 +00001070 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001071 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001072 /// By default, performs semantic analysis to build the new expression.
1073 /// Subclasses may override this routine to provide different behavior.
1074 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1075 UnaryOperator::Opcode Opc,
1076 ExprArg SubExpr) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001077 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001078 }
Mike Stump1eb44332009-09-09 15:08:12 +00001079
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001080 /// \brief Build a new builtin offsetof expression.
1081 ///
1082 /// By default, performs semantic analysis to build the new expression.
1083 /// Subclasses may override this routine to provide different behavior.
1084 OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1085 TypeSourceInfo *Type,
1086 Action::OffsetOfComponent *Components,
1087 unsigned NumComponents,
1088 SourceLocation RParenLoc) {
1089 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1090 NumComponents, RParenLoc);
1091 }
Sean Huntc3021132010-05-05 15:23:54 +00001092
Douglas Gregorb98b1992009-08-11 05:31:07 +00001093 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001094 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001095 /// By default, performs semantic analysis to build the new expression.
1096 /// Subclasses may override this routine to provide different behavior.
John McCalla93c9342009-12-07 02:54:59 +00001097 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001098 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001099 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001100 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001101 }
1102
Mike Stump1eb44332009-09-09 15:08:12 +00001103 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001104 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001105 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001106 /// By default, performs semantic analysis to build the new expression.
1107 /// Subclasses may override this routine to provide different behavior.
1108 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1109 bool isSizeOf, SourceRange R) {
Mike Stump1eb44332009-09-09 15:08:12 +00001110 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001111 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1112 OpLoc, isSizeOf, R);
1113 if (Result.isInvalid())
1114 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001115
Douglas Gregorb98b1992009-08-11 05:31:07 +00001116 SubExpr.release();
1117 return move(Result);
1118 }
Mike Stump1eb44332009-09-09 15:08:12 +00001119
Douglas Gregorb98b1992009-08-11 05:31:07 +00001120 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001121 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001122 /// By default, performs semantic analysis to build the new expression.
1123 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001124 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001125 SourceLocation LBracketLoc,
1126 ExprArg RHS,
1127 SourceLocation RBracketLoc) {
1128 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump1eb44332009-09-09 15:08:12 +00001129 LBracketLoc, move(RHS),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001130 RBracketLoc);
1131 }
1132
1133 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001134 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001135 /// By default, performs semantic analysis to build the new expression.
1136 /// Subclasses may override this routine to provide different behavior.
1137 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1138 MultiExprArg Args,
1139 SourceLocation *CommaLocs,
1140 SourceLocation RParenLoc) {
1141 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1142 move(Args), CommaLocs, RParenLoc);
1143 }
1144
1145 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001146 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001147 /// By default, performs semantic analysis to build the new expression.
1148 /// Subclasses may override this routine to provide different behavior.
1149 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001150 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001151 NestedNameSpecifier *Qualifier,
1152 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001153 const DeclarationNameInfo &MemberNameInfo,
Eli Friedmanf595cc42009-12-04 06:40:45 +00001154 ValueDecl *Member,
John McCall6bb80172010-03-30 21:47:33 +00001155 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001156 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +00001157 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001158 if (!Member->getDeclName()) {
1159 // We have a reference to an unnamed field.
1160 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +00001161
Douglas Gregor83a56c42009-12-24 20:02:50 +00001162 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall6bb80172010-03-30 21:47:33 +00001163 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1164 FoundDecl, Member))
Douglas Gregor83a56c42009-12-24 20:02:50 +00001165 return getSema().ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001166
Mike Stump1eb44332009-09-09 15:08:12 +00001167 MemberExpr *ME =
Douglas Gregor83a56c42009-12-24 20:02:50 +00001168 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001169 Member, MemberNameInfo,
Anders Carlssond8b285f2009-09-01 04:26:58 +00001170 cast<FieldDecl>(Member)->getType());
1171 return getSema().Owned(ME);
1172 }
Mike Stump1eb44332009-09-09 15:08:12 +00001173
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001174 CXXScopeSpec SS;
1175 if (Qualifier) {
1176 SS.setRange(QualifierRange);
1177 SS.setScopeRep(Qualifier);
1178 }
1179
Douglas Gregor83c9abc2010-06-22 02:41:05 +00001180 Expr *BaseExpr = Base.takeAs<Expr>();
1181 getSema().DefaultFunctionArrayConversion(BaseExpr);
1182 QualType BaseType = BaseExpr->getType();
John McCallaa81e162009-12-01 22:10:20 +00001183
John McCall6bb80172010-03-30 21:47:33 +00001184 // FIXME: this involves duplicating earlier analysis in a lot of
1185 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001186 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001187 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001188 R.resolveKind();
1189
Douglas Gregor83c9abc2010-06-22 02:41:05 +00001190 return getSema().BuildMemberReferenceExpr(getSema().Owned(BaseExpr),
1191 BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001192 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001193 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001194 }
Mike Stump1eb44332009-09-09 15:08:12 +00001195
Douglas Gregorb98b1992009-08-11 05:31:07 +00001196 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001197 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001198 /// By default, performs semantic analysis to build the new expression.
1199 /// Subclasses may override this routine to provide different behavior.
1200 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1201 BinaryOperator::Opcode Opc,
1202 ExprArg LHS, ExprArg RHS) {
Sean Huntc3021132010-05-05 15:23:54 +00001203 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001204 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregorb98b1992009-08-11 05:31:07 +00001205 }
1206
1207 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001208 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001209 /// By default, performs semantic analysis to build the new expression.
1210 /// Subclasses may override this routine to provide different behavior.
1211 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1212 SourceLocation QuestionLoc,
1213 ExprArg LHS,
1214 SourceLocation ColonLoc,
1215 ExprArg RHS) {
Mike Stump1eb44332009-09-09 15:08:12 +00001216 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001217 move(LHS), move(RHS));
1218 }
1219
Douglas Gregorb98b1992009-08-11 05:31:07 +00001220 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001221 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001222 /// By default, performs semantic analysis to build the new expression.
1223 /// Subclasses may override this routine to provide different behavior.
John McCall9d125032010-01-15 18:39:57 +00001224 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1225 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001226 SourceLocation RParenLoc,
1227 ExprArg SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001228 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1229 move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001230 }
Mike Stump1eb44332009-09-09 15:08:12 +00001231
Douglas Gregorb98b1992009-08-11 05:31:07 +00001232 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001233 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001234 /// By default, performs semantic analysis to build the new expression.
1235 /// Subclasses may override this routine to provide different behavior.
1236 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001237 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001238 SourceLocation RParenLoc,
1239 ExprArg Init) {
John McCall42f56b52010-01-18 19:35:47 +00001240 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1241 move(Init));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001242 }
Mike Stump1eb44332009-09-09 15:08:12 +00001243
Douglas Gregorb98b1992009-08-11 05:31:07 +00001244 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001245 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001246 /// By default, performs semantic analysis to build the new expression.
1247 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001248 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001249 SourceLocation OpLoc,
1250 SourceLocation AccessorLoc,
1251 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001252
John McCall129e2df2009-11-30 22:42:35 +00001253 CXXScopeSpec SS;
John McCallaa81e162009-12-01 22:10:20 +00001254 QualType BaseType = ((Expr*) Base.get())->getType();
Abramo Bagnara25777432010-08-11 22:01:17 +00001255 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallaa81e162009-12-01 22:10:20 +00001256 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001257 OpLoc, /*IsArrow*/ false,
1258 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001259 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001260 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001261 }
Mike Stump1eb44332009-09-09 15:08:12 +00001262
Douglas Gregorb98b1992009-08-11 05:31:07 +00001263 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001264 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001265 /// By default, performs semantic analysis to build the new expression.
1266 /// Subclasses may override this routine to provide different behavior.
1267 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1268 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001269 SourceLocation RBraceLoc,
1270 QualType ResultTy) {
1271 OwningExprResult Result
1272 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1273 if (Result.isInvalid() || ResultTy->isDependentType())
1274 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001275
Douglas Gregore48319a2009-11-09 17:16:50 +00001276 // Patch in the result type we were given, which may have been computed
1277 // when the initial InitListExpr was built.
1278 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1279 ILE->setType(ResultTy);
1280 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001281 }
Mike Stump1eb44332009-09-09 15:08:12 +00001282
Douglas Gregorb98b1992009-08-11 05:31:07 +00001283 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001284 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001285 /// By default, performs semantic analysis to build the new expression.
1286 /// Subclasses may override this routine to provide different behavior.
1287 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1288 MultiExprArg ArrayExprs,
1289 SourceLocation EqualOrColonLoc,
1290 bool GNUSyntax,
1291 ExprArg Init) {
1292 OwningExprResult Result
1293 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1294 move(Init));
1295 if (Result.isInvalid())
1296 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001297
Douglas Gregorb98b1992009-08-11 05:31:07 +00001298 ArrayExprs.release();
1299 return move(Result);
1300 }
Mike Stump1eb44332009-09-09 15:08:12 +00001301
Douglas Gregorb98b1992009-08-11 05:31:07 +00001302 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001303 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001304 /// By default, builds the implicit value initialization without performing
1305 /// any semantic analysis. Subclasses may override this routine to provide
1306 /// different behavior.
1307 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1308 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1309 }
Mike Stump1eb44332009-09-09 15:08:12 +00001310
Douglas Gregorb98b1992009-08-11 05:31:07 +00001311 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001312 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001313 /// By default, performs semantic analysis to build the new expression.
1314 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001315 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
1316 ExprArg SubExpr, TypeSourceInfo *TInfo,
1317 SourceLocation RParenLoc) {
1318 return getSema().BuildVAArgExpr(BuiltinLoc,
1319 move(SubExpr), TInfo,
1320 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001321 }
1322
1323 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001324 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001325 /// By default, performs semantic analysis to build the new expression.
1326 /// Subclasses may override this routine to provide different behavior.
1327 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1328 MultiExprArg SubExprs,
1329 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001330 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001331 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001332 }
Mike Stump1eb44332009-09-09 15:08:12 +00001333
Douglas Gregorb98b1992009-08-11 05:31:07 +00001334 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001335 ///
1336 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001337 /// rather than attempting to map the label statement itself.
1338 /// Subclasses may override this routine to provide different behavior.
1339 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1340 SourceLocation LabelLoc,
1341 LabelStmt *Label) {
1342 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1343 }
Mike Stump1eb44332009-09-09 15:08:12 +00001344
Douglas Gregorb98b1992009-08-11 05:31:07 +00001345 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001346 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001347 /// By default, performs semantic analysis to build the new expression.
1348 /// Subclasses may override this routine to provide different behavior.
1349 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1350 StmtArg SubStmt,
1351 SourceLocation RParenLoc) {
1352 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1353 }
Mike Stump1eb44332009-09-09 15:08:12 +00001354
Douglas Gregorb98b1992009-08-11 05:31:07 +00001355 /// \brief Build a new __builtin_types_compatible_p expression.
1356 ///
1357 /// By default, performs semantic analysis to build the new expression.
1358 /// Subclasses may override this routine to provide different behavior.
1359 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001360 TypeSourceInfo *TInfo1,
1361 TypeSourceInfo *TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001362 SourceLocation RParenLoc) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00001363 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1364 TInfo1, TInfo2,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001365 RParenLoc);
1366 }
Mike Stump1eb44332009-09-09 15:08:12 +00001367
Douglas Gregorb98b1992009-08-11 05:31:07 +00001368 /// \brief Build a new __builtin_choose_expr expression.
1369 ///
1370 /// By default, performs semantic analysis to build the new expression.
1371 /// Subclasses may override this routine to provide different behavior.
1372 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1373 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1374 SourceLocation RParenLoc) {
1375 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1376 move(Cond), move(LHS), move(RHS),
1377 RParenLoc);
1378 }
Mike Stump1eb44332009-09-09 15:08:12 +00001379
Douglas Gregorb98b1992009-08-11 05:31:07 +00001380 /// \brief Build a new overloaded operator call expression.
1381 ///
1382 /// By default, performs semantic analysis to build the new expression.
1383 /// The semantic analysis provides the behavior of template instantiation,
1384 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001385 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001386 /// argument-dependent lookup, etc. Subclasses may override this routine to
1387 /// provide different behavior.
1388 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1389 SourceLocation OpLoc,
1390 ExprArg Callee,
1391 ExprArg First,
1392 ExprArg Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001393
1394 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001395 /// reinterpret_cast.
1396 ///
1397 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001398 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001399 /// Subclasses may override this routine to provide different behavior.
1400 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1401 Stmt::StmtClass Class,
1402 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001403 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001404 SourceLocation RAngleLoc,
1405 SourceLocation LParenLoc,
1406 ExprArg SubExpr,
1407 SourceLocation RParenLoc) {
1408 switch (Class) {
1409 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001410 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001411 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001412 move(SubExpr), RParenLoc);
1413
1414 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001415 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001416 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001418
Douglas Gregorb98b1992009-08-11 05:31:07 +00001419 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001420 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001421 RAngleLoc, LParenLoc,
1422 move(SubExpr),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001423 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001424
Douglas Gregorb98b1992009-08-11 05:31:07 +00001425 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001426 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001427 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001428 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001429
Douglas Gregorb98b1992009-08-11 05:31:07 +00001430 default:
1431 assert(false && "Invalid C++ named cast");
1432 break;
1433 }
Mike Stump1eb44332009-09-09 15:08:12 +00001434
Douglas Gregorb98b1992009-08-11 05:31:07 +00001435 return getSema().ExprError();
1436 }
Mike Stump1eb44332009-09-09 15:08:12 +00001437
Douglas Gregorb98b1992009-08-11 05:31:07 +00001438 /// \brief Build a new C++ static_cast expression.
1439 ///
1440 /// By default, performs semantic analysis to build the new expression.
1441 /// Subclasses may override this routine to provide different behavior.
1442 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1443 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001444 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001445 SourceLocation RAngleLoc,
1446 SourceLocation LParenLoc,
1447 ExprArg SubExpr,
1448 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001449 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1450 TInfo, move(SubExpr),
1451 SourceRange(LAngleLoc, RAngleLoc),
1452 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001453 }
1454
1455 /// \brief Build a new C++ dynamic_cast expression.
1456 ///
1457 /// By default, performs semantic analysis to build the new expression.
1458 /// Subclasses may override this routine to provide different behavior.
1459 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1460 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001461 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001462 SourceLocation RAngleLoc,
1463 SourceLocation LParenLoc,
1464 ExprArg SubExpr,
1465 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001466 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1467 TInfo, move(SubExpr),
1468 SourceRange(LAngleLoc, RAngleLoc),
1469 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001470 }
1471
1472 /// \brief Build a new C++ reinterpret_cast expression.
1473 ///
1474 /// By default, performs semantic analysis to build the new expression.
1475 /// Subclasses may override this routine to provide different behavior.
1476 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1477 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001478 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001479 SourceLocation RAngleLoc,
1480 SourceLocation LParenLoc,
1481 ExprArg SubExpr,
1482 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001483 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1484 TInfo, move(SubExpr),
1485 SourceRange(LAngleLoc, RAngleLoc),
1486 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 }
1488
1489 /// \brief Build a new C++ const_cast expression.
1490 ///
1491 /// By default, performs semantic analysis to build the new expression.
1492 /// Subclasses may override this routine to provide different behavior.
1493 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1494 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001495 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001496 SourceLocation RAngleLoc,
1497 SourceLocation LParenLoc,
1498 ExprArg SubExpr,
1499 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001500 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1501 TInfo, move(SubExpr),
1502 SourceRange(LAngleLoc, RAngleLoc),
1503 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001504 }
Mike Stump1eb44332009-09-09 15:08:12 +00001505
Douglas Gregorb98b1992009-08-11 05:31:07 +00001506 /// \brief Build a new C++ functional-style cast expression.
1507 ///
1508 /// By default, performs semantic analysis to build the new expression.
1509 /// Subclasses may override this routine to provide different behavior.
1510 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001511 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 SourceLocation LParenLoc,
1513 ExprArg SubExpr,
1514 SourceLocation RParenLoc) {
Chris Lattner88650c32009-08-24 05:19:01 +00001515 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001516 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001517 TInfo->getType().getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 LParenLoc,
Chris Lattner88650c32009-08-24 05:19:01 +00001519 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump1eb44332009-09-09 15:08:12 +00001520 /*CommaLocs=*/0,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001521 RParenLoc);
1522 }
Mike Stump1eb44332009-09-09 15:08:12 +00001523
Douglas Gregorb98b1992009-08-11 05:31:07 +00001524 /// \brief Build a new C++ typeid(type) expression.
1525 ///
1526 /// By default, performs semantic analysis to build the new expression.
1527 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001528 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1529 SourceLocation TypeidLoc,
1530 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001531 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001532 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001533 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001534 }
Mike Stump1eb44332009-09-09 15:08:12 +00001535
Douglas Gregorb98b1992009-08-11 05:31:07 +00001536 /// \brief Build a new C++ typeid(expr) expression.
1537 ///
1538 /// By default, performs semantic analysis to build the new expression.
1539 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001540 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1541 SourceLocation TypeidLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001542 ExprArg Operand,
1543 SourceLocation RParenLoc) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001544 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand),
1545 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001546 }
1547
Douglas Gregorb98b1992009-08-11 05:31:07 +00001548 /// \brief Build a new C++ "this" expression.
1549 ///
1550 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001551 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001552 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001553 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001554 QualType ThisType,
1555 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001556 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001557 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1558 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 }
1560
1561 /// \brief Build a new C++ throw expression.
1562 ///
1563 /// By default, performs semantic analysis to build the new expression.
1564 /// Subclasses may override this routine to provide different behavior.
1565 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1566 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1567 }
1568
1569 /// \brief Build a new C++ default-argument expression.
1570 ///
1571 /// By default, builds a new default-argument expression, which does not
1572 /// require any semantic analysis. Subclasses may override this routine to
1573 /// provide different behavior.
Sean Huntc3021132010-05-05 15:23:54 +00001574 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001575 ParmVarDecl *Param) {
1576 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1577 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 }
1579
1580 /// \brief Build a new C++ zero-initialization expression.
1581 ///
1582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
Douglas Gregored8abf12010-07-08 06:14:04 +00001584 OwningExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001585 SourceLocation LParenLoc,
1586 QualType T,
1587 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001588 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1589 T.getAsOpaquePtr(), LParenLoc,
1590 MultiExprArg(getSema(), 0, 0),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001591 0, RParenLoc);
1592 }
Mike Stump1eb44332009-09-09 15:08:12 +00001593
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 /// \brief Build a new C++ "new" expression.
1595 ///
1596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001598 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 bool UseGlobal,
1600 SourceLocation PlacementLParen,
1601 MultiExprArg PlacementArgs,
1602 SourceLocation PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001603 SourceRange TypeIdParens,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 QualType AllocType,
1605 SourceLocation TypeLoc,
1606 SourceRange TypeRange,
1607 ExprArg ArraySize,
1608 SourceLocation ConstructorLParen,
1609 MultiExprArg ConstructorArgs,
1610 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001611 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 PlacementLParen,
1613 move(PlacementArgs),
1614 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001615 TypeIdParens,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 AllocType,
1617 TypeLoc,
1618 TypeRange,
1619 move(ArraySize),
1620 ConstructorLParen,
1621 move(ConstructorArgs),
1622 ConstructorRParen);
1623 }
Mike Stump1eb44332009-09-09 15:08:12 +00001624
Douglas Gregorb98b1992009-08-11 05:31:07 +00001625 /// \brief Build a new C++ "delete" expression.
1626 ///
1627 /// By default, performs semantic analysis to build the new expression.
1628 /// Subclasses may override this routine to provide different behavior.
1629 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1630 bool IsGlobalDelete,
1631 bool IsArrayForm,
1632 ExprArg Operand) {
1633 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1634 move(Operand));
1635 }
Mike Stump1eb44332009-09-09 15:08:12 +00001636
Douglas Gregorb98b1992009-08-11 05:31:07 +00001637 /// \brief Build a new unary type trait expression.
1638 ///
1639 /// By default, performs semantic analysis to build the new expression.
1640 /// Subclasses may override this routine to provide different behavior.
1641 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1642 SourceLocation StartLoc,
1643 SourceLocation LParenLoc,
1644 QualType T,
1645 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001646 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001647 T.getAsOpaquePtr(), RParenLoc);
1648 }
1649
Mike Stump1eb44332009-09-09 15:08:12 +00001650 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001651 /// expression.
1652 ///
1653 /// By default, performs semantic analysis to build the new expression.
1654 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001655 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001656 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001657 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001658 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 CXXScopeSpec SS;
1660 SS.setRange(QualifierRange);
1661 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001662
1663 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001664 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001665 *TemplateArgs);
1666
Abramo Bagnara25777432010-08-11 22:01:17 +00001667 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 }
1669
1670 /// \brief Build a new template-id expression.
1671 ///
1672 /// By default, performs semantic analysis to build the new expression.
1673 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001674 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1675 LookupResult &R,
1676 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001677 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001678 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 }
1680
1681 /// \brief Build a new object-construction expression.
1682 ///
1683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
1685 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001686 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 CXXConstructorDecl *Constructor,
1688 bool IsElidable,
1689 MultiExprArg Args) {
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001690 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001691 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001692 ConvertedArgs))
1693 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001694
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001695 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1696 move_arg(ConvertedArgs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 }
1698
1699 /// \brief Build a new object-construction expression.
1700 ///
1701 /// By default, performs semantic analysis to build the new expression.
1702 /// Subclasses may override this routine to provide different behavior.
1703 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1704 QualType T,
1705 SourceLocation LParenLoc,
1706 MultiExprArg Args,
1707 SourceLocation *Commas,
1708 SourceLocation RParenLoc) {
1709 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1710 T.getAsOpaquePtr(),
1711 LParenLoc,
1712 move(Args),
1713 Commas,
1714 RParenLoc);
1715 }
1716
1717 /// \brief Build a new object-construction expression.
1718 ///
1719 /// By default, performs semantic analysis to build the new expression.
1720 /// Subclasses may override this routine to provide different behavior.
1721 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1722 QualType T,
1723 SourceLocation LParenLoc,
1724 MultiExprArg Args,
1725 SourceLocation *Commas,
1726 SourceLocation RParenLoc) {
1727 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1728 /*FIXME*/LParenLoc),
1729 T.getAsOpaquePtr(),
1730 LParenLoc,
1731 move(Args),
1732 Commas,
1733 RParenLoc);
1734 }
Mike Stump1eb44332009-09-09 15:08:12 +00001735
Douglas Gregorb98b1992009-08-11 05:31:07 +00001736 /// \brief Build a new member reference expression.
1737 ///
1738 /// By default, performs semantic analysis to build the new expression.
1739 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001740 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001741 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001742 bool IsArrow,
1743 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001744 NestedNameSpecifier *Qualifier,
1745 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001746 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001747 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001748 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001749 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001750 SS.setRange(QualifierRange);
1751 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001752
John McCallaa81e162009-12-01 22:10:20 +00001753 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1754 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001755 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001756 MemberNameInfo,
1757 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001758 }
1759
John McCall129e2df2009-11-30 22:42:35 +00001760 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001761 ///
1762 /// By default, performs semantic analysis to build the new expression.
1763 /// Subclasses may override this routine to provide different behavior.
John McCall129e2df2009-11-30 22:42:35 +00001764 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001765 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001766 SourceLocation OperatorLoc,
1767 bool IsArrow,
1768 NestedNameSpecifier *Qualifier,
1769 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001770 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001771 LookupResult &R,
1772 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001773 CXXScopeSpec SS;
1774 SS.setRange(QualifierRange);
1775 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001776
John McCallaa81e162009-12-01 22:10:20 +00001777 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1778 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001779 SS, FirstQualifierInScope,
1780 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001781 }
Mike Stump1eb44332009-09-09 15:08:12 +00001782
Douglas Gregorb98b1992009-08-11 05:31:07 +00001783 /// \brief Build a new Objective-C @encode expression.
1784 ///
1785 /// By default, performs semantic analysis to build the new expression.
1786 /// Subclasses may override this routine to provide different behavior.
1787 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001788 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001790 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001792 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793
Douglas Gregor92e986e2010-04-22 16:44:27 +00001794 /// \brief Build a new Objective-C class message.
1795 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1796 Selector Sel,
1797 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001798 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001799 MultiExprArg Args,
1800 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001801 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1802 ReceiverTypeInfo->getType(),
1803 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001804 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001805 move(Args));
1806 }
1807
1808 /// \brief Build a new Objective-C instance message.
1809 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1810 Selector Sel,
1811 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001812 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001813 MultiExprArg Args,
1814 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001815 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1816 return SemaRef.BuildInstanceMessage(move(Receiver),
1817 ReceiverType,
1818 /*SuperLoc=*/SourceLocation(),
Douglas Gregorf49bb082010-04-22 17:01:48 +00001819 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001820 move(Args));
1821 }
1822
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001823 /// \brief Build a new Objective-C ivar reference expression.
1824 ///
1825 /// By default, performs semantic analysis to build the new expression.
1826 /// Subclasses may override this routine to provide different behavior.
1827 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1828 SourceLocation IvarLoc,
1829 bool IsArrow, bool IsFreeIvar) {
1830 // FIXME: We lose track of the IsFreeIvar bit.
1831 CXXScopeSpec SS;
1832 Expr *Base = BaseArg.takeAs<Expr>();
1833 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1834 Sema::LookupMemberName);
1835 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1836 /*FIME:*/IvarLoc,
John McCallad00b772010-06-16 08:42:20 +00001837 SS, DeclPtrTy(),
1838 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001839 if (Result.isInvalid())
1840 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001841
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001842 if (Result.get())
1843 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001844
1845 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001846 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001847 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001848 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001849 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001850 /*TemplateArgs=*/0);
1851 }
Douglas Gregore3303542010-04-26 20:47:02 +00001852
1853 /// \brief Build a new Objective-C property reference expression.
1854 ///
1855 /// By default, performs semantic analysis to build the new expression.
1856 /// Subclasses may override this routine to provide different behavior.
Sean Huntc3021132010-05-05 15:23:54 +00001857 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00001858 ObjCPropertyDecl *Property,
1859 SourceLocation PropertyLoc) {
1860 CXXScopeSpec SS;
1861 Expr *Base = BaseArg.takeAs<Expr>();
1862 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1863 Sema::LookupMemberName);
1864 bool IsArrow = false;
1865 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1866 /*FIME:*/PropertyLoc,
John McCallad00b772010-06-16 08:42:20 +00001867 SS, DeclPtrTy(),
1868 false);
Douglas Gregore3303542010-04-26 20:47:02 +00001869 if (Result.isInvalid())
1870 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001871
Douglas Gregore3303542010-04-26 20:47:02 +00001872 if (Result.get())
1873 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001874
1875 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregore3303542010-04-26 20:47:02 +00001876 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001877 /*FIXME:*/PropertyLoc, IsArrow,
1878 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00001879 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001880 R,
Douglas Gregore3303542010-04-26 20:47:02 +00001881 /*TemplateArgs=*/0);
1882 }
Sean Huntc3021132010-05-05 15:23:54 +00001883
1884 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001885 /// expression.
1886 ///
1887 /// By default, performs semantic analysis to build the new expression.
Sean Huntc3021132010-05-05 15:23:54 +00001888 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001889 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1890 ObjCMethodDecl *Getter,
1891 QualType T,
1892 ObjCMethodDecl *Setter,
1893 SourceLocation NameLoc,
1894 ExprArg Base) {
1895 // Since these expressions can only be value-dependent, we do not need to
1896 // perform semantic analysis again.
1897 return getSema().Owned(
1898 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1899 Setter,
1900 NameLoc,
1901 Base.takeAs<Expr>()));
1902 }
1903
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001904 /// \brief Build a new Objective-C "isa" expression.
1905 ///
1906 /// By default, performs semantic analysis to build the new expression.
1907 /// Subclasses may override this routine to provide different behavior.
1908 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1909 bool IsArrow) {
1910 CXXScopeSpec SS;
1911 Expr *Base = BaseArg.takeAs<Expr>();
1912 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1913 Sema::LookupMemberName);
1914 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1915 /*FIME:*/IsaLoc,
John McCallad00b772010-06-16 08:42:20 +00001916 SS, DeclPtrTy(),
1917 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001918 if (Result.isInvalid())
1919 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001920
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001921 if (Result.get())
1922 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001923
1924 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001925 Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001926 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001927 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001928 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001929 /*TemplateArgs=*/0);
1930 }
Sean Huntc3021132010-05-05 15:23:54 +00001931
Douglas Gregorb98b1992009-08-11 05:31:07 +00001932 /// \brief Build a new shuffle vector expression.
1933 ///
1934 /// By default, performs semantic analysis to build the new expression.
1935 /// Subclasses may override this routine to provide different behavior.
1936 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1937 MultiExprArg SubExprs,
1938 SourceLocation RParenLoc) {
1939 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001940 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001941 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1942 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1943 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1944 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001945
Douglas Gregorb98b1992009-08-11 05:31:07 +00001946 // Build a reference to the __builtin_shufflevector builtin
1947 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001948 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001949 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001950 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001951 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001952
1953 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001954 unsigned NumSubExprs = SubExprs.size();
1955 Expr **Subs = (Expr **)SubExprs.release();
1956 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1957 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00001958 Builtin->getCallResultType(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001959 RParenLoc);
1960 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001961
Douglas Gregorb98b1992009-08-11 05:31:07 +00001962 // Type-check the __builtin_shufflevector expression.
1963 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1964 if (Result.isInvalid())
1965 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001966
Douglas Gregorb98b1992009-08-11 05:31:07 +00001967 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001968 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001969 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001970};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001971
Douglas Gregor43959a92009-08-20 07:17:43 +00001972template<typename Derived>
1973Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1974 if (!S)
1975 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001976
Douglas Gregor43959a92009-08-20 07:17:43 +00001977 switch (S->getStmtClass()) {
1978 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001979
Douglas Gregor43959a92009-08-20 07:17:43 +00001980 // Transform individual statement nodes
1981#define STMT(Node, Parent) \
1982 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1983#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00001984#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00001985
Douglas Gregor43959a92009-08-20 07:17:43 +00001986 // Transform expressions by calling TransformExpr.
1987#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00001988#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00001989#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00001990#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00001991 {
1992 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1993 if (E.isInvalid())
1994 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001995
Anders Carlsson5ee56e92009-12-16 02:09:40 +00001996 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregor43959a92009-08-20 07:17:43 +00001997 }
Mike Stump1eb44332009-09-09 15:08:12 +00001998 }
1999
Douglas Gregor43959a92009-08-20 07:17:43 +00002000 return SemaRef.Owned(S->Retain());
2001}
Mike Stump1eb44332009-09-09 15:08:12 +00002002
2003
Douglas Gregor670444e2009-08-04 22:27:00 +00002004template<typename Derived>
John McCall454feb92009-12-08 09:21:05 +00002005Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002006 if (!E)
2007 return SemaRef.Owned(E);
2008
2009 switch (E->getStmtClass()) {
2010 case Stmt::NoStmtClass: break;
2011#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002012#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002013#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002014 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002015#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002016 }
2017
Douglas Gregorb98b1992009-08-11 05:31:07 +00002018 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002019}
2020
2021template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002022NestedNameSpecifier *
2023TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002024 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002025 QualType ObjectType,
2026 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00002027 if (!NNS)
2028 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002029
Douglas Gregor43959a92009-08-20 07:17:43 +00002030 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002031 NestedNameSpecifier *Prefix = NNS->getPrefix();
2032 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002033 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002034 ObjectType,
2035 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002036 if (!Prefix)
2037 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002038
2039 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00002040 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00002041 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00002042 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002043 }
Mike Stump1eb44332009-09-09 15:08:12 +00002044
Douglas Gregordcee1a12009-08-06 05:28:30 +00002045 switch (NNS->getKind()) {
2046 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00002047 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002048 "Identifier nested-name-specifier with no prefix or object type");
2049 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2050 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002051 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002052
2053 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002054 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002055 ObjectType,
2056 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002057
Douglas Gregordcee1a12009-08-06 05:28:30 +00002058 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002059 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002060 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002061 getDerived().TransformDecl(Range.getBegin(),
2062 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002063 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002064 Prefix == NNS->getPrefix() &&
2065 NS == NNS->getAsNamespace())
2066 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002067
Douglas Gregordcee1a12009-08-06 05:28:30 +00002068 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2069 }
Mike Stump1eb44332009-09-09 15:08:12 +00002070
Douglas Gregordcee1a12009-08-06 05:28:30 +00002071 case NestedNameSpecifier::Global:
2072 // There is no meaningful transformation that one could perform on the
2073 // global scope.
2074 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002075
Douglas Gregordcee1a12009-08-06 05:28:30 +00002076 case NestedNameSpecifier::TypeSpecWithTemplate:
2077 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002078 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor124b8782010-02-16 19:09:40 +00002079 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2080 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002081 if (T.isNull())
2082 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002083
Douglas Gregordcee1a12009-08-06 05:28:30 +00002084 if (!getDerived().AlwaysRebuild() &&
2085 Prefix == NNS->getPrefix() &&
2086 T == QualType(NNS->getAsType(), 0))
2087 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002088
2089 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2090 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002091 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002092 }
2093 }
Mike Stump1eb44332009-09-09 15:08:12 +00002094
Douglas Gregordcee1a12009-08-06 05:28:30 +00002095 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002096 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002097}
2098
2099template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002100DeclarationNameInfo
2101TreeTransform<Derived>
2102::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2103 QualType ObjectType) {
2104 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002105 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002106 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002107
2108 switch (Name.getNameKind()) {
2109 case DeclarationName::Identifier:
2110 case DeclarationName::ObjCZeroArgSelector:
2111 case DeclarationName::ObjCOneArgSelector:
2112 case DeclarationName::ObjCMultiArgSelector:
2113 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002114 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002115 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002116 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002117
Douglas Gregor81499bb2009-09-03 22:13:48 +00002118 case DeclarationName::CXXConstructorName:
2119 case DeclarationName::CXXDestructorName:
2120 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002121 TypeSourceInfo *NewTInfo;
2122 CanQualType NewCanTy;
2123 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2124 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2125 if (!NewTInfo)
2126 return DeclarationNameInfo();
2127 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2128 }
2129 else {
2130 NewTInfo = 0;
2131 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2132 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2133 ObjectType);
2134 if (NewT.isNull())
2135 return DeclarationNameInfo();
2136 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2137 }
Mike Stump1eb44332009-09-09 15:08:12 +00002138
Abramo Bagnara25777432010-08-11 22:01:17 +00002139 DeclarationName NewName
2140 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2141 NewCanTy);
2142 DeclarationNameInfo NewNameInfo(NameInfo);
2143 NewNameInfo.setName(NewName);
2144 NewNameInfo.setNamedTypeInfo(NewTInfo);
2145 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002146 }
Mike Stump1eb44332009-09-09 15:08:12 +00002147 }
2148
Abramo Bagnara25777432010-08-11 22:01:17 +00002149 assert(0 && "Unknown name kind.");
2150 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002151}
2152
2153template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002154TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002155TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2156 QualType ObjectType) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002157 SourceLocation Loc = getDerived().getBaseLocation();
2158
Douglas Gregord1067e52009-08-06 06:41:21 +00002159 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002160 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002161 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002162 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2163 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002164 if (!NNS)
2165 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002166
Douglas Gregord1067e52009-08-06 06:41:21 +00002167 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002168 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002169 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002170 if (!TransTemplate)
2171 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002172
Douglas Gregord1067e52009-08-06 06:41:21 +00002173 if (!getDerived().AlwaysRebuild() &&
2174 NNS == QTN->getQualifier() &&
2175 TransTemplate == Template)
2176 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002177
Douglas Gregord1067e52009-08-06 06:41:21 +00002178 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2179 TransTemplate);
2180 }
Mike Stump1eb44332009-09-09 15:08:12 +00002181
John McCallf7a1a742009-11-24 19:00:30 +00002182 // These should be getting filtered out before they make it into the AST.
2183 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002184 }
Mike Stump1eb44332009-09-09 15:08:12 +00002185
Douglas Gregord1067e52009-08-06 06:41:21 +00002186 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002187 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002188 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002189 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2190 ObjectType);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002191 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00002192 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002193
Douglas Gregord1067e52009-08-06 06:41:21 +00002194 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002195 NNS == DTN->getQualifier() &&
2196 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002197 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002198
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002199 if (DTN->isIdentifier())
Sean Huntc3021132010-05-05 15:23:54 +00002200 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002201 ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +00002202
2203 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002204 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002205 }
Mike Stump1eb44332009-09-09 15:08:12 +00002206
Douglas Gregord1067e52009-08-06 06:41:21 +00002207 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002208 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002209 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002210 if (!TransTemplate)
2211 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002212
Douglas Gregord1067e52009-08-06 06:41:21 +00002213 if (!getDerived().AlwaysRebuild() &&
2214 TransTemplate == Template)
2215 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002216
Douglas Gregord1067e52009-08-06 06:41:21 +00002217 return TemplateName(TransTemplate);
2218 }
Mike Stump1eb44332009-09-09 15:08:12 +00002219
John McCallf7a1a742009-11-24 19:00:30 +00002220 // These should be getting filtered out before they reach the AST.
2221 assert(false && "overloaded function decl survived to here");
2222 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002223}
2224
2225template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002226void TreeTransform<Derived>::InventTemplateArgumentLoc(
2227 const TemplateArgument &Arg,
2228 TemplateArgumentLoc &Output) {
2229 SourceLocation Loc = getDerived().getBaseLocation();
2230 switch (Arg.getKind()) {
2231 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002232 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002233 break;
2234
2235 case TemplateArgument::Type:
2236 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002237 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002238
John McCall833ca992009-10-29 08:12:44 +00002239 break;
2240
Douglas Gregor788cd062009-11-11 01:00:40 +00002241 case TemplateArgument::Template:
2242 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2243 break;
Sean Huntc3021132010-05-05 15:23:54 +00002244
John McCall833ca992009-10-29 08:12:44 +00002245 case TemplateArgument::Expression:
2246 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2247 break;
2248
2249 case TemplateArgument::Declaration:
2250 case TemplateArgument::Integral:
2251 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002252 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002253 break;
2254 }
2255}
2256
2257template<typename Derived>
2258bool TreeTransform<Derived>::TransformTemplateArgument(
2259 const TemplateArgumentLoc &Input,
2260 TemplateArgumentLoc &Output) {
2261 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002262 switch (Arg.getKind()) {
2263 case TemplateArgument::Null:
2264 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002265 Output = Input;
2266 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002267
Douglas Gregor670444e2009-08-04 22:27:00 +00002268 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002269 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002270 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002271 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002272
2273 DI = getDerived().TransformType(DI);
2274 if (!DI) return true;
2275
2276 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2277 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002278 }
Mike Stump1eb44332009-09-09 15:08:12 +00002279
Douglas Gregor670444e2009-08-04 22:27:00 +00002280 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002281 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002282 DeclarationName Name;
2283 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2284 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002285 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002286 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002287 if (!D) return true;
2288
John McCall828bff22009-10-29 18:45:58 +00002289 Expr *SourceExpr = Input.getSourceDeclExpression();
2290 if (SourceExpr) {
2291 EnterExpressionEvaluationContext Unevaluated(getSema(),
2292 Action::Unevaluated);
2293 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2294 if (E.isInvalid())
2295 SourceExpr = NULL;
2296 else {
2297 SourceExpr = E.takeAs<Expr>();
2298 SourceExpr->Retain();
2299 }
2300 }
2301
2302 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002303 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002304 }
Mike Stump1eb44332009-09-09 15:08:12 +00002305
Douglas Gregor788cd062009-11-11 01:00:40 +00002306 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002307 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002308 TemplateName Template
2309 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2310 if (Template.isNull())
2311 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002312
Douglas Gregor788cd062009-11-11 01:00:40 +00002313 Output = TemplateArgumentLoc(TemplateArgument(Template),
2314 Input.getTemplateQualifierRange(),
2315 Input.getTemplateNameLoc());
2316 return false;
2317 }
Sean Huntc3021132010-05-05 15:23:54 +00002318
Douglas Gregor670444e2009-08-04 22:27:00 +00002319 case TemplateArgument::Expression: {
2320 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002321 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002322 Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002323
John McCall833ca992009-10-29 08:12:44 +00002324 Expr *InputExpr = Input.getSourceExpression();
2325 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2326
2327 Sema::OwningExprResult E
2328 = getDerived().TransformExpr(InputExpr);
2329 if (E.isInvalid()) return true;
2330
2331 Expr *ETaken = E.takeAs<Expr>();
John McCall828bff22009-10-29 18:45:58 +00002332 ETaken->Retain();
John McCall833ca992009-10-29 08:12:44 +00002333 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2334 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002335 }
Mike Stump1eb44332009-09-09 15:08:12 +00002336
Douglas Gregor670444e2009-08-04 22:27:00 +00002337 case TemplateArgument::Pack: {
2338 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2339 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002340 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002341 AEnd = Arg.pack_end();
2342 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002343
John McCall833ca992009-10-29 08:12:44 +00002344 // FIXME: preserve source information here when we start
2345 // caring about parameter packs.
2346
John McCall828bff22009-10-29 18:45:58 +00002347 TemplateArgumentLoc InputArg;
2348 TemplateArgumentLoc OutputArg;
2349 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2350 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002351 return true;
2352
John McCall828bff22009-10-29 18:45:58 +00002353 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002354 }
2355 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002356 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002357 true);
John McCall828bff22009-10-29 18:45:58 +00002358 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002359 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002360 }
2361 }
Mike Stump1eb44332009-09-09 15:08:12 +00002362
Douglas Gregor670444e2009-08-04 22:27:00 +00002363 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002364 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002365}
2366
Douglas Gregor577f75a2009-08-04 16:50:30 +00002367//===----------------------------------------------------------------------===//
2368// Type transformation
2369//===----------------------------------------------------------------------===//
2370
2371template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00002372QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregor124b8782010-02-16 19:09:40 +00002373 QualType ObjectType) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002374 if (getDerived().AlreadyTransformed(T))
2375 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002376
John McCalla2becad2009-10-21 00:40:46 +00002377 // Temporary workaround. All of these transformations should
2378 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002379 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002380 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002381
Douglas Gregor124b8782010-02-16 19:09:40 +00002382 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall0953e762009-09-24 19:53:00 +00002383
John McCalla2becad2009-10-21 00:40:46 +00002384 if (!NewDI)
2385 return QualType();
2386
2387 return NewDI->getType();
2388}
2389
2390template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002391TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2392 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002393 if (getDerived().AlreadyTransformed(DI->getType()))
2394 return DI;
2395
2396 TypeLocBuilder TLB;
2397
2398 TypeLoc TL = DI->getTypeLoc();
2399 TLB.reserve(TL.getFullDataSize());
2400
Douglas Gregor124b8782010-02-16 19:09:40 +00002401 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002402 if (Result.isNull())
2403 return 0;
2404
John McCalla93c9342009-12-07 02:54:59 +00002405 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002406}
2407
2408template<typename Derived>
2409QualType
Douglas Gregor124b8782010-02-16 19:09:40 +00002410TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2411 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002412 switch (T.getTypeLocClass()) {
2413#define ABSTRACT_TYPELOC(CLASS, PARENT)
2414#define TYPELOC(CLASS, PARENT) \
2415 case TypeLoc::CLASS: \
Douglas Gregor124b8782010-02-16 19:09:40 +00002416 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2417 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002418#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002419 }
Mike Stump1eb44332009-09-09 15:08:12 +00002420
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002421 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002422 return QualType();
2423}
2424
2425/// FIXME: By default, this routine adds type qualifiers only to types
2426/// that can have qualifiers, and silently suppresses those qualifiers
2427/// that are not permitted (e.g., qualifiers on reference or function
2428/// types). This is the right thing for template instantiation, but
2429/// probably not for other clients.
2430template<typename Derived>
2431QualType
2432TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002433 QualifiedTypeLoc T,
2434 QualType ObjectType) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002435 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002436
Douglas Gregor124b8782010-02-16 19:09:40 +00002437 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2438 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002439 if (Result.isNull())
2440 return QualType();
2441
2442 // Silently suppress qualifiers if the result type can't be qualified.
2443 // FIXME: this is the right thing for template instantiation, but
2444 // probably not for other clients.
2445 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002446 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002447
John McCall28654742010-06-05 06:41:15 +00002448 if (!Quals.empty()) {
2449 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2450 TLB.push<QualifiedTypeLoc>(Result);
2451 // No location information to preserve.
2452 }
John McCalla2becad2009-10-21 00:40:46 +00002453
2454 return Result;
2455}
2456
2457template <class TyLoc> static inline
2458QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2459 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2460 NewT.setNameLoc(T.getNameLoc());
2461 return T.getType();
2462}
2463
John McCalla2becad2009-10-21 00:40:46 +00002464template<typename Derived>
2465QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002466 BuiltinTypeLoc T,
2467 QualType ObjectType) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002468 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2469 NewT.setBuiltinLoc(T.getBuiltinLoc());
2470 if (T.needsExtraLocalData())
2471 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2472 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002473}
Mike Stump1eb44332009-09-09 15:08:12 +00002474
Douglas Gregor577f75a2009-08-04 16:50:30 +00002475template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002476QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002477 ComplexTypeLoc T,
2478 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002479 // FIXME: recurse?
2480 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002481}
Mike Stump1eb44332009-09-09 15:08:12 +00002482
Douglas Gregor577f75a2009-08-04 16:50:30 +00002483template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002484QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Sean Huntc3021132010-05-05 15:23:54 +00002485 PointerTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00002486 QualType ObjectType) {
Sean Huntc3021132010-05-05 15:23:54 +00002487 QualType PointeeType
2488 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002489 if (PointeeType.isNull())
2490 return QualType();
2491
2492 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00002493 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002494 // A dependent pointer type 'T *' has is being transformed such
2495 // that an Objective-C class type is being replaced for 'T'. The
2496 // resulting pointer type is an ObjCObjectPointerType, not a
2497 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00002498 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00002499
John McCallc12c5bb2010-05-15 11:32:37 +00002500 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2501 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002502 return Result;
2503 }
Sean Huntc3021132010-05-05 15:23:54 +00002504
Douglas Gregor92e986e2010-04-22 16:44:27 +00002505 if (getDerived().AlwaysRebuild() ||
2506 PointeeType != TL.getPointeeLoc().getType()) {
2507 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2508 if (Result.isNull())
2509 return QualType();
2510 }
Sean Huntc3021132010-05-05 15:23:54 +00002511
Douglas Gregor92e986e2010-04-22 16:44:27 +00002512 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2513 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00002514 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002515}
Mike Stump1eb44332009-09-09 15:08:12 +00002516
2517template<typename Derived>
2518QualType
John McCalla2becad2009-10-21 00:40:46 +00002519TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002520 BlockPointerTypeLoc TL,
2521 QualType ObjectType) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002522 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00002523 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2524 if (PointeeType.isNull())
2525 return QualType();
2526
2527 QualType Result = TL.getType();
2528 if (getDerived().AlwaysRebuild() ||
2529 PointeeType != TL.getPointeeLoc().getType()) {
2530 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002531 TL.getSigilLoc());
2532 if (Result.isNull())
2533 return QualType();
2534 }
2535
Douglas Gregor39968ad2010-04-22 16:50:51 +00002536 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002537 NewT.setSigilLoc(TL.getSigilLoc());
2538 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002539}
2540
John McCall85737a72009-10-30 00:06:24 +00002541/// Transforms a reference type. Note that somewhat paradoxically we
2542/// don't care whether the type itself is an l-value type or an r-value
2543/// type; we only care if the type was *written* as an l-value type
2544/// or an r-value type.
2545template<typename Derived>
2546QualType
2547TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002548 ReferenceTypeLoc TL,
2549 QualType ObjectType) {
John McCall85737a72009-10-30 00:06:24 +00002550 const ReferenceType *T = TL.getTypePtr();
2551
2552 // Note that this works with the pointee-as-written.
2553 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2554 if (PointeeType.isNull())
2555 return QualType();
2556
2557 QualType Result = TL.getType();
2558 if (getDerived().AlwaysRebuild() ||
2559 PointeeType != T->getPointeeTypeAsWritten()) {
2560 Result = getDerived().RebuildReferenceType(PointeeType,
2561 T->isSpelledAsLValue(),
2562 TL.getSigilLoc());
2563 if (Result.isNull())
2564 return QualType();
2565 }
2566
2567 // r-value references can be rebuilt as l-value references.
2568 ReferenceTypeLoc NewTL;
2569 if (isa<LValueReferenceType>(Result))
2570 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2571 else
2572 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2573 NewTL.setSigilLoc(TL.getSigilLoc());
2574
2575 return Result;
2576}
2577
Mike Stump1eb44332009-09-09 15:08:12 +00002578template<typename Derived>
2579QualType
John McCalla2becad2009-10-21 00:40:46 +00002580TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002581 LValueReferenceTypeLoc TL,
2582 QualType ObjectType) {
2583 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002584}
2585
Mike Stump1eb44332009-09-09 15:08:12 +00002586template<typename Derived>
2587QualType
John McCalla2becad2009-10-21 00:40:46 +00002588TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002589 RValueReferenceTypeLoc TL,
2590 QualType ObjectType) {
2591 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002592}
Mike Stump1eb44332009-09-09 15:08:12 +00002593
Douglas Gregor577f75a2009-08-04 16:50:30 +00002594template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002595QualType
John McCalla2becad2009-10-21 00:40:46 +00002596TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002597 MemberPointerTypeLoc TL,
2598 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002599 MemberPointerType *T = TL.getTypePtr();
2600
2601 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002602 if (PointeeType.isNull())
2603 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002604
John McCalla2becad2009-10-21 00:40:46 +00002605 // TODO: preserve source information for this.
2606 QualType ClassType
2607 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002608 if (ClassType.isNull())
2609 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002610
John McCalla2becad2009-10-21 00:40:46 +00002611 QualType Result = TL.getType();
2612 if (getDerived().AlwaysRebuild() ||
2613 PointeeType != T->getPointeeType() ||
2614 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002615 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2616 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002617 if (Result.isNull())
2618 return QualType();
2619 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002620
John McCalla2becad2009-10-21 00:40:46 +00002621 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2622 NewTL.setSigilLoc(TL.getSigilLoc());
2623
2624 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002625}
2626
Mike Stump1eb44332009-09-09 15:08:12 +00002627template<typename Derived>
2628QualType
John McCalla2becad2009-10-21 00:40:46 +00002629TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002630 ConstantArrayTypeLoc TL,
2631 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002632 ConstantArrayType *T = TL.getTypePtr();
2633 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002634 if (ElementType.isNull())
2635 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002636
John McCalla2becad2009-10-21 00:40:46 +00002637 QualType Result = TL.getType();
2638 if (getDerived().AlwaysRebuild() ||
2639 ElementType != T->getElementType()) {
2640 Result = getDerived().RebuildConstantArrayType(ElementType,
2641 T->getSizeModifier(),
2642 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002643 T->getIndexTypeCVRQualifiers(),
2644 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002645 if (Result.isNull())
2646 return QualType();
2647 }
Sean Huntc3021132010-05-05 15:23:54 +00002648
John McCalla2becad2009-10-21 00:40:46 +00002649 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2650 NewTL.setLBracketLoc(TL.getLBracketLoc());
2651 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002652
John McCalla2becad2009-10-21 00:40:46 +00002653 Expr *Size = TL.getSizeExpr();
2654 if (Size) {
2655 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2656 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2657 }
2658 NewTL.setSizeExpr(Size);
2659
2660 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002661}
Mike Stump1eb44332009-09-09 15:08:12 +00002662
Douglas Gregor577f75a2009-08-04 16:50:30 +00002663template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002664QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002665 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002666 IncompleteArrayTypeLoc TL,
2667 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002668 IncompleteArrayType *T = TL.getTypePtr();
2669 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002670 if (ElementType.isNull())
2671 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002672
John McCalla2becad2009-10-21 00:40:46 +00002673 QualType Result = TL.getType();
2674 if (getDerived().AlwaysRebuild() ||
2675 ElementType != T->getElementType()) {
2676 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002677 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002678 T->getIndexTypeCVRQualifiers(),
2679 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002680 if (Result.isNull())
2681 return QualType();
2682 }
Sean Huntc3021132010-05-05 15:23:54 +00002683
John McCalla2becad2009-10-21 00:40:46 +00002684 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2685 NewTL.setLBracketLoc(TL.getLBracketLoc());
2686 NewTL.setRBracketLoc(TL.getRBracketLoc());
2687 NewTL.setSizeExpr(0);
2688
2689 return Result;
2690}
2691
2692template<typename Derived>
2693QualType
2694TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002695 VariableArrayTypeLoc TL,
2696 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002697 VariableArrayType *T = TL.getTypePtr();
2698 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2699 if (ElementType.isNull())
2700 return QualType();
2701
2702 // Array bounds are not potentially evaluated contexts
2703 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2704
2705 Sema::OwningExprResult SizeResult
2706 = getDerived().TransformExpr(T->getSizeExpr());
2707 if (SizeResult.isInvalid())
2708 return QualType();
2709
2710 Expr *Size = static_cast<Expr*>(SizeResult.get());
2711
2712 QualType Result = TL.getType();
2713 if (getDerived().AlwaysRebuild() ||
2714 ElementType != T->getElementType() ||
2715 Size != T->getSizeExpr()) {
2716 Result = getDerived().RebuildVariableArrayType(ElementType,
2717 T->getSizeModifier(),
2718 move(SizeResult),
2719 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002720 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002721 if (Result.isNull())
2722 return QualType();
2723 }
2724 else SizeResult.take();
Sean Huntc3021132010-05-05 15:23:54 +00002725
John McCalla2becad2009-10-21 00:40:46 +00002726 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2727 NewTL.setLBracketLoc(TL.getLBracketLoc());
2728 NewTL.setRBracketLoc(TL.getRBracketLoc());
2729 NewTL.setSizeExpr(Size);
2730
2731 return Result;
2732}
2733
2734template<typename Derived>
2735QualType
2736TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002737 DependentSizedArrayTypeLoc TL,
2738 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002739 DependentSizedArrayType *T = TL.getTypePtr();
2740 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2741 if (ElementType.isNull())
2742 return QualType();
2743
2744 // Array bounds are not potentially evaluated contexts
2745 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2746
2747 Sema::OwningExprResult SizeResult
2748 = getDerived().TransformExpr(T->getSizeExpr());
2749 if (SizeResult.isInvalid())
2750 return QualType();
2751
2752 Expr *Size = static_cast<Expr*>(SizeResult.get());
2753
2754 QualType Result = TL.getType();
2755 if (getDerived().AlwaysRebuild() ||
2756 ElementType != T->getElementType() ||
2757 Size != T->getSizeExpr()) {
2758 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2759 T->getSizeModifier(),
2760 move(SizeResult),
2761 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002762 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002763 if (Result.isNull())
2764 return QualType();
2765 }
2766 else SizeResult.take();
2767
2768 // We might have any sort of array type now, but fortunately they
2769 // all have the same location layout.
2770 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2771 NewTL.setLBracketLoc(TL.getLBracketLoc());
2772 NewTL.setRBracketLoc(TL.getRBracketLoc());
2773 NewTL.setSizeExpr(Size);
2774
2775 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002776}
Mike Stump1eb44332009-09-09 15:08:12 +00002777
2778template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002779QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002780 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002781 DependentSizedExtVectorTypeLoc TL,
2782 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002783 DependentSizedExtVectorType *T = TL.getTypePtr();
2784
2785 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002786 QualType ElementType = getDerived().TransformType(T->getElementType());
2787 if (ElementType.isNull())
2788 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002789
Douglas Gregor670444e2009-08-04 22:27:00 +00002790 // Vector sizes are not potentially evaluated contexts
2791 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2792
Douglas Gregor577f75a2009-08-04 16:50:30 +00002793 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2794 if (Size.isInvalid())
2795 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002796
John McCalla2becad2009-10-21 00:40:46 +00002797 QualType Result = TL.getType();
2798 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002799 ElementType != T->getElementType() ||
2800 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002801 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002802 move(Size),
2803 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002804 if (Result.isNull())
2805 return QualType();
2806 }
2807 else Size.take();
2808
2809 // Result might be dependent or not.
2810 if (isa<DependentSizedExtVectorType>(Result)) {
2811 DependentSizedExtVectorTypeLoc NewTL
2812 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2813 NewTL.setNameLoc(TL.getNameLoc());
2814 } else {
2815 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2816 NewTL.setNameLoc(TL.getNameLoc());
2817 }
2818
2819 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002820}
Mike Stump1eb44332009-09-09 15:08:12 +00002821
2822template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002823QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002824 VectorTypeLoc TL,
2825 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002826 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002827 QualType ElementType = getDerived().TransformType(T->getElementType());
2828 if (ElementType.isNull())
2829 return QualType();
2830
John McCalla2becad2009-10-21 00:40:46 +00002831 QualType Result = TL.getType();
2832 if (getDerived().AlwaysRebuild() ||
2833 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002834 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner788b0fd2010-06-23 06:00:24 +00002835 T->getAltiVecSpecific());
John McCalla2becad2009-10-21 00:40:46 +00002836 if (Result.isNull())
2837 return QualType();
2838 }
Sean Huntc3021132010-05-05 15:23:54 +00002839
John McCalla2becad2009-10-21 00:40:46 +00002840 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2841 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002842
John McCalla2becad2009-10-21 00:40:46 +00002843 return Result;
2844}
2845
2846template<typename Derived>
2847QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002848 ExtVectorTypeLoc TL,
2849 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002850 VectorType *T = TL.getTypePtr();
2851 QualType ElementType = getDerived().TransformType(T->getElementType());
2852 if (ElementType.isNull())
2853 return QualType();
2854
2855 QualType Result = TL.getType();
2856 if (getDerived().AlwaysRebuild() ||
2857 ElementType != T->getElementType()) {
2858 Result = getDerived().RebuildExtVectorType(ElementType,
2859 T->getNumElements(),
2860 /*FIXME*/ SourceLocation());
2861 if (Result.isNull())
2862 return QualType();
2863 }
Sean Huntc3021132010-05-05 15:23:54 +00002864
John McCalla2becad2009-10-21 00:40:46 +00002865 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2866 NewTL.setNameLoc(TL.getNameLoc());
2867
2868 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002869}
Mike Stump1eb44332009-09-09 15:08:12 +00002870
2871template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002872ParmVarDecl *
2873TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2874 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2875 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2876 if (!NewDI)
2877 return 0;
2878
2879 if (NewDI == OldDI)
2880 return OldParm;
2881 else
2882 return ParmVarDecl::Create(SemaRef.Context,
2883 OldParm->getDeclContext(),
2884 OldParm->getLocation(),
2885 OldParm->getIdentifier(),
2886 NewDI->getType(),
2887 NewDI,
2888 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00002889 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00002890 /* DefArg */ NULL);
2891}
2892
2893template<typename Derived>
2894bool TreeTransform<Derived>::
2895 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2896 llvm::SmallVectorImpl<QualType> &PTypes,
2897 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2898 FunctionProtoType *T = TL.getTypePtr();
2899
2900 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2901 ParmVarDecl *OldParm = TL.getArg(i);
2902
2903 QualType NewType;
2904 ParmVarDecl *NewParm;
2905
2906 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002907 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2908 if (!NewParm)
2909 return true;
2910 NewType = NewParm->getType();
2911
2912 // Deal with the possibility that we don't have a parameter
2913 // declaration for this parameter.
2914 } else {
2915 NewParm = 0;
2916
2917 QualType OldType = T->getArgType(i);
2918 NewType = getDerived().TransformType(OldType);
2919 if (NewType.isNull())
2920 return true;
2921 }
2922
2923 PTypes.push_back(NewType);
2924 PVars.push_back(NewParm);
2925 }
2926
2927 return false;
2928}
2929
2930template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002931QualType
John McCalla2becad2009-10-21 00:40:46 +00002932TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002933 FunctionProtoTypeLoc TL,
2934 QualType ObjectType) {
Douglas Gregor895162d2010-04-30 18:55:50 +00002935 // Transform the parameters. We do this first for the benefit of template
2936 // instantiations, so that the ParmVarDecls get/ placed into the template
2937 // instantiation scope before we transform the function type.
Douglas Gregor577f75a2009-08-04 16:50:30 +00002938 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002939 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall21ef0fa2010-03-11 09:03:00 +00002940 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2941 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +00002942
Douglas Gregor895162d2010-04-30 18:55:50 +00002943 FunctionProtoType *T = TL.getTypePtr();
2944 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2945 if (ResultType.isNull())
2946 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +00002947
John McCalla2becad2009-10-21 00:40:46 +00002948 QualType Result = TL.getType();
2949 if (getDerived().AlwaysRebuild() ||
2950 ResultType != T->getResultType() ||
2951 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2952 Result = getDerived().RebuildFunctionProtoType(ResultType,
2953 ParamTypes.data(),
2954 ParamTypes.size(),
2955 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00002956 T->getTypeQuals(),
2957 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00002958 if (Result.isNull())
2959 return QualType();
2960 }
Mike Stump1eb44332009-09-09 15:08:12 +00002961
John McCalla2becad2009-10-21 00:40:46 +00002962 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2963 NewTL.setLParenLoc(TL.getLParenLoc());
2964 NewTL.setRParenLoc(TL.getRParenLoc());
2965 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2966 NewTL.setArg(i, ParamDecls[i]);
2967
2968 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002969}
Mike Stump1eb44332009-09-09 15:08:12 +00002970
Douglas Gregor577f75a2009-08-04 16:50:30 +00002971template<typename Derived>
2972QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002973 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002974 FunctionNoProtoTypeLoc TL,
2975 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002976 FunctionNoProtoType *T = TL.getTypePtr();
2977 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2978 if (ResultType.isNull())
2979 return QualType();
2980
2981 QualType Result = TL.getType();
2982 if (getDerived().AlwaysRebuild() ||
2983 ResultType != T->getResultType())
2984 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2985
2986 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2987 NewTL.setLParenLoc(TL.getLParenLoc());
2988 NewTL.setRParenLoc(TL.getRParenLoc());
2989
2990 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002991}
Mike Stump1eb44332009-09-09 15:08:12 +00002992
John McCalled976492009-12-04 22:46:56 +00002993template<typename Derived> QualType
2994TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002995 UnresolvedUsingTypeLoc TL,
2996 QualType ObjectType) {
John McCalled976492009-12-04 22:46:56 +00002997 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002998 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00002999 if (!D)
3000 return QualType();
3001
3002 QualType Result = TL.getType();
3003 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3004 Result = getDerived().RebuildUnresolvedUsingType(D);
3005 if (Result.isNull())
3006 return QualType();
3007 }
3008
3009 // We might get an arbitrary type spec type back. We should at
3010 // least always get a type spec type, though.
3011 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3012 NewTL.setNameLoc(TL.getNameLoc());
3013
3014 return Result;
3015}
3016
Douglas Gregor577f75a2009-08-04 16:50:30 +00003017template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003018QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003019 TypedefTypeLoc TL,
3020 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003021 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003022 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003023 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3024 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003025 if (!Typedef)
3026 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003027
John McCalla2becad2009-10-21 00:40:46 +00003028 QualType Result = TL.getType();
3029 if (getDerived().AlwaysRebuild() ||
3030 Typedef != T->getDecl()) {
3031 Result = getDerived().RebuildTypedefType(Typedef);
3032 if (Result.isNull())
3033 return QualType();
3034 }
Mike Stump1eb44332009-09-09 15:08:12 +00003035
John McCalla2becad2009-10-21 00:40:46 +00003036 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3037 NewTL.setNameLoc(TL.getNameLoc());
3038
3039 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003040}
Mike Stump1eb44332009-09-09 15:08:12 +00003041
Douglas Gregor577f75a2009-08-04 16:50:30 +00003042template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003043QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003044 TypeOfExprTypeLoc TL,
3045 QualType ObjectType) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003046 // typeof expressions are not potentially evaluated contexts
3047 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003048
John McCallcfb708c2010-01-13 20:03:27 +00003049 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003050 if (E.isInvalid())
3051 return QualType();
3052
John McCalla2becad2009-10-21 00:40:46 +00003053 QualType Result = TL.getType();
3054 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003055 E.get() != TL.getUnderlyingExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003056 Result = getDerived().RebuildTypeOfExprType(move(E));
3057 if (Result.isNull())
3058 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003059 }
John McCalla2becad2009-10-21 00:40:46 +00003060 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003061
John McCalla2becad2009-10-21 00:40:46 +00003062 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003063 NewTL.setTypeofLoc(TL.getTypeofLoc());
3064 NewTL.setLParenLoc(TL.getLParenLoc());
3065 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003066
3067 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003068}
Mike Stump1eb44332009-09-09 15:08:12 +00003069
3070template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003071QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003072 TypeOfTypeLoc TL,
3073 QualType ObjectType) {
John McCallcfb708c2010-01-13 20:03:27 +00003074 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3075 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3076 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003077 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003078
John McCalla2becad2009-10-21 00:40:46 +00003079 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003080 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3081 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003082 if (Result.isNull())
3083 return QualType();
3084 }
Mike Stump1eb44332009-09-09 15:08:12 +00003085
John McCalla2becad2009-10-21 00:40:46 +00003086 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003087 NewTL.setTypeofLoc(TL.getTypeofLoc());
3088 NewTL.setLParenLoc(TL.getLParenLoc());
3089 NewTL.setRParenLoc(TL.getRParenLoc());
3090 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003091
3092 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003093}
Mike Stump1eb44332009-09-09 15:08:12 +00003094
3095template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003096QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003097 DecltypeTypeLoc TL,
3098 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003099 DecltypeType *T = TL.getTypePtr();
3100
Douglas Gregor670444e2009-08-04 22:27:00 +00003101 // decltype expressions are not potentially evaluated contexts
3102 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003103
Douglas Gregor577f75a2009-08-04 16:50:30 +00003104 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3105 if (E.isInvalid())
3106 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003107
John McCalla2becad2009-10-21 00:40:46 +00003108 QualType Result = TL.getType();
3109 if (getDerived().AlwaysRebuild() ||
3110 E.get() != T->getUnderlyingExpr()) {
3111 Result = getDerived().RebuildDecltypeType(move(E));
3112 if (Result.isNull())
3113 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003114 }
John McCalla2becad2009-10-21 00:40:46 +00003115 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003116
John McCalla2becad2009-10-21 00:40:46 +00003117 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3118 NewTL.setNameLoc(TL.getNameLoc());
3119
3120 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003121}
3122
3123template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003124QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003125 RecordTypeLoc TL,
3126 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003127 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003128 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003129 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3130 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003131 if (!Record)
3132 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003133
John McCalla2becad2009-10-21 00:40:46 +00003134 QualType Result = TL.getType();
3135 if (getDerived().AlwaysRebuild() ||
3136 Record != T->getDecl()) {
3137 Result = getDerived().RebuildRecordType(Record);
3138 if (Result.isNull())
3139 return QualType();
3140 }
Mike Stump1eb44332009-09-09 15:08:12 +00003141
John McCalla2becad2009-10-21 00:40:46 +00003142 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3143 NewTL.setNameLoc(TL.getNameLoc());
3144
3145 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003146}
Mike Stump1eb44332009-09-09 15:08:12 +00003147
3148template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003149QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003150 EnumTypeLoc TL,
3151 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003152 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003153 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003154 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3155 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003156 if (!Enum)
3157 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003158
John McCalla2becad2009-10-21 00:40:46 +00003159 QualType Result = TL.getType();
3160 if (getDerived().AlwaysRebuild() ||
3161 Enum != T->getDecl()) {
3162 Result = getDerived().RebuildEnumType(Enum);
3163 if (Result.isNull())
3164 return QualType();
3165 }
Mike Stump1eb44332009-09-09 15:08:12 +00003166
John McCalla2becad2009-10-21 00:40:46 +00003167 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3168 NewTL.setNameLoc(TL.getNameLoc());
3169
3170 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003171}
John McCall7da24312009-09-05 00:15:47 +00003172
John McCall3cb0ebd2010-03-10 03:28:59 +00003173template<typename Derived>
3174QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3175 TypeLocBuilder &TLB,
3176 InjectedClassNameTypeLoc TL,
3177 QualType ObjectType) {
3178 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3179 TL.getTypePtr()->getDecl());
3180 if (!D) return QualType();
3181
3182 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3183 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3184 return T;
3185}
3186
Mike Stump1eb44332009-09-09 15:08:12 +00003187
Douglas Gregor577f75a2009-08-04 16:50:30 +00003188template<typename Derived>
3189QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003190 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003191 TemplateTypeParmTypeLoc TL,
3192 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003193 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003194}
3195
Mike Stump1eb44332009-09-09 15:08:12 +00003196template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003197QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003198 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003199 SubstTemplateTypeParmTypeLoc TL,
3200 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00003201 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003202}
3203
3204template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003205QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3206 const TemplateSpecializationType *TST,
3207 QualType ObjectType) {
3208 // FIXME: this entire method is a temporary workaround; callers
3209 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00003210
John McCall833ca992009-10-29 08:12:44 +00003211 // Fake up a TemplateSpecializationTypeLoc.
3212 TypeLocBuilder TLB;
3213 TemplateSpecializationTypeLoc TL
3214 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3215
John McCall828bff22009-10-29 18:45:58 +00003216 SourceLocation BaseLoc = getDerived().getBaseLocation();
3217
3218 TL.setTemplateNameLoc(BaseLoc);
3219 TL.setLAngleLoc(BaseLoc);
3220 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00003221 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3222 const TemplateArgument &TA = TST->getArg(i);
3223 TemplateArgumentLoc TAL;
3224 getDerived().InventTemplateArgumentLoc(TA, TAL);
3225 TL.setArgLocInfo(i, TAL.getLocInfo());
3226 }
3227
3228 TypeLocBuilder IgnoredTLB;
3229 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00003230}
Sean Huntc3021132010-05-05 15:23:54 +00003231
Douglas Gregordd62b152009-10-19 22:04:39 +00003232template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003233QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003234 TypeLocBuilder &TLB,
3235 TemplateSpecializationTypeLoc TL,
3236 QualType ObjectType) {
3237 const TemplateSpecializationType *T = TL.getTypePtr();
3238
Mike Stump1eb44332009-09-09 15:08:12 +00003239 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00003240 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003241 if (Template.isNull())
3242 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003243
John McCalld5532b62009-11-23 01:53:49 +00003244 TemplateArgumentListInfo NewTemplateArgs;
3245 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3246 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3247
3248 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3249 TemplateArgumentLoc Loc;
3250 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00003251 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00003252 NewTemplateArgs.addArgument(Loc);
3253 }
Mike Stump1eb44332009-09-09 15:08:12 +00003254
John McCall833ca992009-10-29 08:12:44 +00003255 // FIXME: maybe don't rebuild if all the template arguments are the same.
3256
3257 QualType Result =
3258 getDerived().RebuildTemplateSpecializationType(Template,
3259 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003260 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003261
3262 if (!Result.isNull()) {
3263 TemplateSpecializationTypeLoc NewTL
3264 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3265 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3266 NewTL.setLAngleLoc(TL.getLAngleLoc());
3267 NewTL.setRAngleLoc(TL.getRAngleLoc());
3268 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3269 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003270 }
Mike Stump1eb44332009-09-09 15:08:12 +00003271
John McCall833ca992009-10-29 08:12:44 +00003272 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003273}
Mike Stump1eb44332009-09-09 15:08:12 +00003274
3275template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003276QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003277TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3278 ElaboratedTypeLoc TL,
3279 QualType ObjectType) {
3280 ElaboratedType *T = TL.getTypePtr();
3281
3282 NestedNameSpecifier *NNS = 0;
3283 // NOTE: the qualifier in an ElaboratedType is optional.
3284 if (T->getQualifier() != 0) {
3285 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003286 TL.getQualifierRange(),
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003287 ObjectType);
3288 if (!NNS)
3289 return QualType();
3290 }
Mike Stump1eb44332009-09-09 15:08:12 +00003291
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003292 QualType NamedT;
3293 // FIXME: this test is meant to workaround a problem (failing assertion)
3294 // occurring if directly executing the code in the else branch.
3295 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3296 TemplateSpecializationTypeLoc OldNamedTL
3297 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3298 const TemplateSpecializationType* OldTST
Jim Grosbach9cbb4d82010-05-19 23:53:08 +00003299 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003300 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3301 if (NamedT.isNull())
3302 return QualType();
3303 TemplateSpecializationTypeLoc NewNamedTL
3304 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3305 NewNamedTL.copy(OldNamedTL);
3306 }
3307 else {
3308 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3309 if (NamedT.isNull())
3310 return QualType();
3311 }
Daniel Dunbara63db842010-05-14 16:34:09 +00003312
John McCalla2becad2009-10-21 00:40:46 +00003313 QualType Result = TL.getType();
3314 if (getDerived().AlwaysRebuild() ||
3315 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003316 NamedT != T->getNamedType()) {
3317 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00003318 if (Result.isNull())
3319 return QualType();
3320 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003321
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003322 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003323 NewTL.setKeywordLoc(TL.getKeywordLoc());
3324 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00003325
3326 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003327}
Mike Stump1eb44332009-09-09 15:08:12 +00003328
3329template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003330QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3331 DependentNameTypeLoc TL,
Douglas Gregor124b8782010-02-16 19:09:40 +00003332 QualType ObjectType) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003333 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003334
Douglas Gregor577f75a2009-08-04 16:50:30 +00003335 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003336 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3337 TL.getQualifierRange(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003338 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003339 if (!NNS)
3340 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003341
John McCall33500952010-06-11 00:33:02 +00003342 QualType Result
3343 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3344 T->getIdentifier(),
3345 TL.getKeywordLoc(),
3346 TL.getQualifierRange(),
3347 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003348 if (Result.isNull())
3349 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003350
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003351 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3352 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00003353 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3354
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003355 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3356 NewTL.setKeywordLoc(TL.getKeywordLoc());
3357 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003358 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003359 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3360 NewTL.setKeywordLoc(TL.getKeywordLoc());
3361 NewTL.setQualifierRange(TL.getQualifierRange());
3362 NewTL.setNameLoc(TL.getNameLoc());
3363 }
John McCalla2becad2009-10-21 00:40:46 +00003364 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003365}
Mike Stump1eb44332009-09-09 15:08:12 +00003366
Douglas Gregor577f75a2009-08-04 16:50:30 +00003367template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00003368QualType TreeTransform<Derived>::
3369 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3370 DependentTemplateSpecializationTypeLoc TL,
3371 QualType ObjectType) {
3372 DependentTemplateSpecializationType *T = TL.getTypePtr();
3373
3374 NestedNameSpecifier *NNS
3375 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3376 TL.getQualifierRange(),
3377 ObjectType);
3378 if (!NNS)
3379 return QualType();
3380
3381 TemplateArgumentListInfo NewTemplateArgs;
3382 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3383 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3384
3385 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3386 TemplateArgumentLoc Loc;
3387 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3388 return QualType();
3389 NewTemplateArgs.addArgument(Loc);
3390 }
3391
3392 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
3393 T->getKeyword(),
3394 NNS,
3395 T->getIdentifier(),
3396 TL.getNameLoc(),
3397 NewTemplateArgs);
3398 if (Result.isNull())
3399 return QualType();
3400
3401 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3402 QualType NamedT = ElabT->getNamedType();
3403
3404 // Copy information relevant to the template specialization.
3405 TemplateSpecializationTypeLoc NamedTL
3406 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3407 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3408 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3409 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3410 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3411
3412 // Copy information relevant to the elaborated type.
3413 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3414 NewTL.setKeywordLoc(TL.getKeywordLoc());
3415 NewTL.setQualifierRange(TL.getQualifierRange());
3416 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00003417 TypeLoc NewTL(Result, TL.getOpaqueData());
3418 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00003419 }
3420 return Result;
3421}
3422
3423template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003424QualType
3425TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003426 ObjCInterfaceTypeLoc TL,
3427 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003428 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003429 TLB.pushFullCopy(TL);
3430 return TL.getType();
3431}
3432
3433template<typename Derived>
3434QualType
3435TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3436 ObjCObjectTypeLoc TL,
3437 QualType ObjectType) {
3438 // ObjCObjectType is never dependent.
3439 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003440 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003441}
Mike Stump1eb44332009-09-09 15:08:12 +00003442
3443template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003444QualType
3445TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003446 ObjCObjectPointerTypeLoc TL,
3447 QualType ObjectType) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003448 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003449 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003450 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003451}
3452
Douglas Gregor577f75a2009-08-04 16:50:30 +00003453//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003454// Statement transformation
3455//===----------------------------------------------------------------------===//
3456template<typename Derived>
3457Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003458TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3459 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003460}
3461
3462template<typename Derived>
3463Sema::OwningStmtResult
3464TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3465 return getDerived().TransformCompoundStmt(S, false);
3466}
3467
3468template<typename Derived>
3469Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003470TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003471 bool IsStmtExpr) {
3472 bool SubStmtChanged = false;
3473 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3474 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3475 B != BEnd; ++B) {
3476 OwningStmtResult Result = getDerived().TransformStmt(*B);
3477 if (Result.isInvalid())
3478 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003479
Douglas Gregor43959a92009-08-20 07:17:43 +00003480 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3481 Statements.push_back(Result.takeAs<Stmt>());
3482 }
Mike Stump1eb44332009-09-09 15:08:12 +00003483
Douglas Gregor43959a92009-08-20 07:17:43 +00003484 if (!getDerived().AlwaysRebuild() &&
3485 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003486 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003487
3488 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3489 move_arg(Statements),
3490 S->getRBracLoc(),
3491 IsStmtExpr);
3492}
Mike Stump1eb44332009-09-09 15:08:12 +00003493
Douglas Gregor43959a92009-08-20 07:17:43 +00003494template<typename Derived>
3495Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003496TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman264c1f82009-11-19 03:14:00 +00003497 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3498 {
3499 // The case value expressions are not potentially evaluated.
3500 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003501
Eli Friedman264c1f82009-11-19 03:14:00 +00003502 // Transform the left-hand case value.
3503 LHS = getDerived().TransformExpr(S->getLHS());
3504 if (LHS.isInvalid())
3505 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003506
Eli Friedman264c1f82009-11-19 03:14:00 +00003507 // Transform the right-hand case value (for the GNU case-range extension).
3508 RHS = getDerived().TransformExpr(S->getRHS());
3509 if (RHS.isInvalid())
3510 return SemaRef.StmtError();
3511 }
Mike Stump1eb44332009-09-09 15:08:12 +00003512
Douglas Gregor43959a92009-08-20 07:17:43 +00003513 // Build the case statement.
3514 // Case statements are always rebuilt so that they will attached to their
3515 // transformed switch statement.
3516 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3517 move(LHS),
3518 S->getEllipsisLoc(),
3519 move(RHS),
3520 S->getColonLoc());
3521 if (Case.isInvalid())
3522 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003523
Douglas Gregor43959a92009-08-20 07:17:43 +00003524 // Transform the statement following the case
3525 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3526 if (SubStmt.isInvalid())
3527 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003528
Douglas Gregor43959a92009-08-20 07:17:43 +00003529 // Attach the body to the case statement
3530 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3531}
3532
3533template<typename Derived>
3534Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003535TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003536 // Transform the statement following the default case
3537 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3538 if (SubStmt.isInvalid())
3539 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003540
Douglas Gregor43959a92009-08-20 07:17:43 +00003541 // Default statements are always rebuilt
3542 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3543 move(SubStmt));
3544}
Mike Stump1eb44332009-09-09 15:08:12 +00003545
Douglas Gregor43959a92009-08-20 07:17:43 +00003546template<typename Derived>
3547Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003548TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003549 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3550 if (SubStmt.isInvalid())
3551 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003552
Douglas Gregor43959a92009-08-20 07:17:43 +00003553 // FIXME: Pass the real colon location in.
3554 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3555 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3556 move(SubStmt));
3557}
Mike Stump1eb44332009-09-09 15:08:12 +00003558
Douglas Gregor43959a92009-08-20 07:17:43 +00003559template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003560Sema::OwningStmtResult
3561TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003562 // Transform the condition
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003563 OwningExprResult Cond(SemaRef);
3564 VarDecl *ConditionVar = 0;
3565 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003566 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003567 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003568 getDerived().TransformDefinition(
3569 S->getConditionVariable()->getLocation(),
3570 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003571 if (!ConditionVar)
3572 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003573 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003574 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003575
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003576 if (Cond.isInvalid())
3577 return SemaRef.StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003578
3579 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003580 if (S->getCond()) {
3581 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3582 S->getIfLoc(),
3583 move(Cond));
3584 if (CondE.isInvalid())
3585 return getSema().StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003586
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003587 Cond = move(CondE);
3588 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003589 }
Sean Huntc3021132010-05-05 15:23:54 +00003590
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003591 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3592 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3593 return SemaRef.StmtError();
3594
Douglas Gregor43959a92009-08-20 07:17:43 +00003595 // Transform the "then" branch.
3596 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3597 if (Then.isInvalid())
3598 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003599
Douglas Gregor43959a92009-08-20 07:17:43 +00003600 // Transform the "else" branch.
3601 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3602 if (Else.isInvalid())
3603 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003604
Douglas Gregor43959a92009-08-20 07:17:43 +00003605 if (!getDerived().AlwaysRebuild() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003606 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003607 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003608 Then.get() == S->getThen() &&
3609 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003610 return SemaRef.Owned(S->Retain());
3611
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003612 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003613 move(Then),
Mike Stump1eb44332009-09-09 15:08:12 +00003614 S->getElseLoc(), move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +00003615}
3616
3617template<typename Derived>
3618Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003619TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003620 // Transform the condition.
Douglas Gregord3d53012009-11-24 17:07:59 +00003621 OwningExprResult Cond(SemaRef);
3622 VarDecl *ConditionVar = 0;
3623 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003624 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00003625 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003626 getDerived().TransformDefinition(
3627 S->getConditionVariable()->getLocation(),
3628 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003629 if (!ConditionVar)
3630 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003631 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003632 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003633
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003634 if (Cond.isInvalid())
3635 return SemaRef.StmtError();
3636 }
Mike Stump1eb44332009-09-09 15:08:12 +00003637
Douglas Gregor43959a92009-08-20 07:17:43 +00003638 // Rebuild the switch statement.
Douglas Gregor586596f2010-05-06 17:25:47 +00003639 OwningStmtResult Switch
3640 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond),
3641 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003642 if (Switch.isInvalid())
3643 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003644
Douglas Gregor43959a92009-08-20 07:17:43 +00003645 // Transform the body of the switch statement.
3646 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3647 if (Body.isInvalid())
3648 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003649
Douglas Gregor43959a92009-08-20 07:17:43 +00003650 // Complete the switch statement.
3651 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3652 move(Body));
3653}
Mike Stump1eb44332009-09-09 15:08:12 +00003654
Douglas Gregor43959a92009-08-20 07:17:43 +00003655template<typename Derived>
3656Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003657TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003658 // Transform the condition
Douglas Gregor5656e142009-11-24 21:15:44 +00003659 OwningExprResult Cond(SemaRef);
3660 VarDecl *ConditionVar = 0;
3661 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003662 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00003663 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003664 getDerived().TransformDefinition(
3665 S->getConditionVariable()->getLocation(),
3666 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003667 if (!ConditionVar)
3668 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003669 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003670 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003671
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003672 if (Cond.isInvalid())
3673 return SemaRef.StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003674
3675 if (S->getCond()) {
3676 // Convert the condition to a boolean value.
3677 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003678 S->getWhileLoc(),
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003679 move(Cond));
3680 if (CondE.isInvalid())
3681 return getSema().StmtError();
3682 Cond = move(CondE);
3683 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003684 }
Mike Stump1eb44332009-09-09 15:08:12 +00003685
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003686 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3687 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3688 return SemaRef.StmtError();
3689
Douglas Gregor43959a92009-08-20 07:17:43 +00003690 // Transform the body
3691 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3692 if (Body.isInvalid())
3693 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003694
Douglas Gregor43959a92009-08-20 07:17:43 +00003695 if (!getDerived().AlwaysRebuild() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003696 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003697 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003698 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003699 return SemaRef.Owned(S->Retain());
3700
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003701 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
Douglas Gregor586596f2010-05-06 17:25:47 +00003702 ConditionVar, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003703}
Mike Stump1eb44332009-09-09 15:08:12 +00003704
Douglas Gregor43959a92009-08-20 07:17:43 +00003705template<typename Derived>
3706Sema::OwningStmtResult
3707TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003708 // Transform the body
3709 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3710 if (Body.isInvalid())
3711 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003712
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003713 // Transform the condition
3714 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3715 if (Cond.isInvalid())
3716 return SemaRef.StmtError();
3717
Douglas Gregor43959a92009-08-20 07:17:43 +00003718 if (!getDerived().AlwaysRebuild() &&
3719 Cond.get() == S->getCond() &&
3720 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003721 return SemaRef.Owned(S->Retain());
3722
Douglas Gregor43959a92009-08-20 07:17:43 +00003723 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3724 /*FIXME:*/S->getWhileLoc(), move(Cond),
3725 S->getRParenLoc());
3726}
Mike Stump1eb44332009-09-09 15:08:12 +00003727
Douglas Gregor43959a92009-08-20 07:17:43 +00003728template<typename Derived>
3729Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003730TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003731 // Transform the initialization statement
3732 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3733 if (Init.isInvalid())
3734 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003735
Douglas Gregor43959a92009-08-20 07:17:43 +00003736 // Transform the condition
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003737 OwningExprResult Cond(SemaRef);
3738 VarDecl *ConditionVar = 0;
3739 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003740 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003741 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003742 getDerived().TransformDefinition(
3743 S->getConditionVariable()->getLocation(),
3744 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003745 if (!ConditionVar)
3746 return SemaRef.StmtError();
3747 } else {
3748 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00003749
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003750 if (Cond.isInvalid())
3751 return SemaRef.StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00003752
3753 if (S->getCond()) {
3754 // Convert the condition to a boolean value.
3755 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3756 S->getForLoc(),
3757 move(Cond));
3758 if (CondE.isInvalid())
3759 return getSema().StmtError();
3760
3761 Cond = move(CondE);
3762 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003763 }
Mike Stump1eb44332009-09-09 15:08:12 +00003764
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003765 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3766 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3767 return SemaRef.StmtError();
3768
Douglas Gregor43959a92009-08-20 07:17:43 +00003769 // Transform the increment
3770 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3771 if (Inc.isInvalid())
3772 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003773
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003774 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc));
3775 if (S->getInc() && !FullInc->get())
3776 return SemaRef.StmtError();
3777
Douglas Gregor43959a92009-08-20 07:17:43 +00003778 // Transform the body
3779 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3780 if (Body.isInvalid())
3781 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003782
Douglas Gregor43959a92009-08-20 07:17:43 +00003783 if (!getDerived().AlwaysRebuild() &&
3784 Init.get() == S->getInit() &&
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003785 FullCond->get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003786 Inc.get() == S->getInc() &&
3787 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003788 return SemaRef.Owned(S->Retain());
3789
Douglas Gregor43959a92009-08-20 07:17:43 +00003790 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregoreaa18e42010-05-08 22:20:28 +00003791 move(Init), FullCond, ConditionVar,
3792 FullInc, S->getRParenLoc(), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003793}
3794
3795template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003796Sema::OwningStmtResult
3797TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003798 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003799 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003800 S->getLabel());
3801}
3802
3803template<typename Derived>
3804Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003805TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003806 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3807 if (Target.isInvalid())
3808 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003809
Douglas Gregor43959a92009-08-20 07:17:43 +00003810 if (!getDerived().AlwaysRebuild() &&
3811 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003812 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003813
3814 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3815 move(Target));
3816}
3817
3818template<typename Derived>
3819Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003820TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3821 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003822}
Mike Stump1eb44332009-09-09 15:08:12 +00003823
Douglas Gregor43959a92009-08-20 07:17:43 +00003824template<typename Derived>
3825Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003826TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3827 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003828}
Mike Stump1eb44332009-09-09 15:08:12 +00003829
Douglas Gregor43959a92009-08-20 07:17:43 +00003830template<typename Derived>
3831Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003832TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003833 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3834 if (Result.isInvalid())
3835 return SemaRef.StmtError();
3836
Mike Stump1eb44332009-09-09 15:08:12 +00003837 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003838 // to tell whether the return type of the function has changed.
3839 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3840}
Mike Stump1eb44332009-09-09 15:08:12 +00003841
Douglas Gregor43959a92009-08-20 07:17:43 +00003842template<typename Derived>
3843Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003844TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003845 bool DeclChanged = false;
3846 llvm::SmallVector<Decl *, 4> Decls;
3847 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3848 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003849 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3850 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003851 if (!Transformed)
3852 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003853
Douglas Gregor43959a92009-08-20 07:17:43 +00003854 if (Transformed != *D)
3855 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003856
Douglas Gregor43959a92009-08-20 07:17:43 +00003857 Decls.push_back(Transformed);
3858 }
Mike Stump1eb44332009-09-09 15:08:12 +00003859
Douglas Gregor43959a92009-08-20 07:17:43 +00003860 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003861 return SemaRef.Owned(S->Retain());
3862
3863 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003864 S->getStartLoc(), S->getEndLoc());
3865}
Mike Stump1eb44332009-09-09 15:08:12 +00003866
Douglas Gregor43959a92009-08-20 07:17:43 +00003867template<typename Derived>
3868Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003869TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003870 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003871 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003872}
3873
3874template<typename Derived>
3875Sema::OwningStmtResult
3876TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00003877
Anders Carlsson703e3942010-01-24 05:50:09 +00003878 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3879 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003880 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003881
Anders Carlsson703e3942010-01-24 05:50:09 +00003882 OwningExprResult AsmString(SemaRef);
3883 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3884
3885 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00003886
Anders Carlsson703e3942010-01-24 05:50:09 +00003887 // Go through the outputs.
3888 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003889 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003890
Anders Carlsson703e3942010-01-24 05:50:09 +00003891 // No need to transform the constraint literal.
3892 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003893
Anders Carlsson703e3942010-01-24 05:50:09 +00003894 // Transform the output expr.
3895 Expr *OutputExpr = S->getOutputExpr(I);
3896 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3897 if (Result.isInvalid())
3898 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003899
Anders Carlsson703e3942010-01-24 05:50:09 +00003900 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003901
Anders Carlsson703e3942010-01-24 05:50:09 +00003902 Exprs.push_back(Result.takeAs<Expr>());
3903 }
Sean Huntc3021132010-05-05 15:23:54 +00003904
Anders Carlsson703e3942010-01-24 05:50:09 +00003905 // Go through the inputs.
3906 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003907 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00003908
Anders Carlsson703e3942010-01-24 05:50:09 +00003909 // No need to transform the constraint literal.
3910 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003911
Anders Carlsson703e3942010-01-24 05:50:09 +00003912 // Transform the input expr.
3913 Expr *InputExpr = S->getInputExpr(I);
3914 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3915 if (Result.isInvalid())
3916 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003917
Anders Carlsson703e3942010-01-24 05:50:09 +00003918 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00003919
Anders Carlsson703e3942010-01-24 05:50:09 +00003920 Exprs.push_back(Result.takeAs<Expr>());
3921 }
Sean Huntc3021132010-05-05 15:23:54 +00003922
Anders Carlsson703e3942010-01-24 05:50:09 +00003923 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3924 return SemaRef.Owned(S->Retain());
3925
3926 // Go through the clobbers.
3927 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3928 Clobbers.push_back(S->getClobber(I)->Retain());
3929
3930 // No need to transform the asm string literal.
3931 AsmString = SemaRef.Owned(S->getAsmString());
3932
3933 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3934 S->isSimple(),
3935 S->isVolatile(),
3936 S->getNumOutputs(),
3937 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003938 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003939 move_arg(Constraints),
3940 move_arg(Exprs),
3941 move(AsmString),
3942 move_arg(Clobbers),
3943 S->getRParenLoc(),
3944 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003945}
3946
3947
3948template<typename Derived>
3949Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003950TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003951 // Transform the body of the @try.
3952 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3953 if (TryBody.isInvalid())
3954 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00003955
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003956 // Transform the @catch statements (if present).
3957 bool AnyCatchChanged = false;
3958 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3959 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3960 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003961 if (Catch.isInvalid())
3962 return SemaRef.StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003963 if (Catch.get() != S->getCatchStmt(I))
3964 AnyCatchChanged = true;
3965 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003966 }
Sean Huntc3021132010-05-05 15:23:54 +00003967
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003968 // Transform the @finally statement (if present).
3969 OwningStmtResult Finally(SemaRef);
3970 if (S->getFinallyStmt()) {
3971 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3972 if (Finally.isInvalid())
3973 return SemaRef.StmtError();
3974 }
3975
3976 // If nothing changed, just retain this statement.
3977 if (!getDerived().AlwaysRebuild() &&
3978 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003979 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003980 Finally.get() == S->getFinallyStmt())
3981 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00003982
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00003983 // Build a new statement.
3984 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00003985 move_arg(CatchStmts), move(Finally));
Douglas Gregor43959a92009-08-20 07:17:43 +00003986}
Mike Stump1eb44332009-09-09 15:08:12 +00003987
Douglas Gregor43959a92009-08-20 07:17:43 +00003988template<typename Derived>
3989Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003990TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00003991 // Transform the @catch parameter, if there is one.
3992 VarDecl *Var = 0;
3993 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3994 TypeSourceInfo *TSInfo = 0;
3995 if (FromVar->getTypeSourceInfo()) {
3996 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3997 if (!TSInfo)
3998 return SemaRef.StmtError();
3999 }
Sean Huntc3021132010-05-05 15:23:54 +00004000
Douglas Gregorbe270a02010-04-26 17:57:08 +00004001 QualType T;
4002 if (TSInfo)
4003 T = TSInfo->getType();
4004 else {
4005 T = getDerived().TransformType(FromVar->getType());
4006 if (T.isNull())
Sean Huntc3021132010-05-05 15:23:54 +00004007 return SemaRef.StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004008 }
Sean Huntc3021132010-05-05 15:23:54 +00004009
Douglas Gregorbe270a02010-04-26 17:57:08 +00004010 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4011 if (!Var)
4012 return SemaRef.StmtError();
4013 }
Sean Huntc3021132010-05-05 15:23:54 +00004014
Douglas Gregorbe270a02010-04-26 17:57:08 +00004015 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
4016 if (Body.isInvalid())
4017 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004018
4019 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004020 S->getRParenLoc(),
4021 Var, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004022}
Mike Stump1eb44332009-09-09 15:08:12 +00004023
Douglas Gregor43959a92009-08-20 07:17:43 +00004024template<typename Derived>
4025Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004026TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004027 // Transform the body.
4028 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
4029 if (Body.isInvalid())
4030 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004031
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004032 // If nothing changed, just retain this statement.
4033 if (!getDerived().AlwaysRebuild() &&
4034 Body.get() == S->getFinallyBody())
4035 return SemaRef.Owned(S->Retain());
4036
4037 // Build a new statement.
4038 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
4039 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004040}
Mike Stump1eb44332009-09-09 15:08:12 +00004041
Douglas Gregor43959a92009-08-20 07:17:43 +00004042template<typename Derived>
4043Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004044TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregord1377b22010-04-22 21:44:01 +00004045 OwningExprResult Operand(SemaRef);
4046 if (S->getThrowExpr()) {
4047 Operand = getDerived().TransformExpr(S->getThrowExpr());
4048 if (Operand.isInvalid())
4049 return getSema().StmtError();
4050 }
Sean Huntc3021132010-05-05 15:23:54 +00004051
Douglas Gregord1377b22010-04-22 21:44:01 +00004052 if (!getDerived().AlwaysRebuild() &&
4053 Operand.get() == S->getThrowExpr())
4054 return getSema().Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004055
Douglas Gregord1377b22010-04-22 21:44:01 +00004056 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregor43959a92009-08-20 07:17:43 +00004057}
Mike Stump1eb44332009-09-09 15:08:12 +00004058
Douglas Gregor43959a92009-08-20 07:17:43 +00004059template<typename Derived>
4060Sema::OwningStmtResult
4061TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004062 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004063 // Transform the object we are locking.
4064 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
4065 if (Object.isInvalid())
4066 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004067
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004068 // Transform the body.
4069 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
4070 if (Body.isInvalid())
4071 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004072
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004073 // If nothing change, just retain the current statement.
4074 if (!getDerived().AlwaysRebuild() &&
4075 Object.get() == S->getSynchExpr() &&
4076 Body.get() == S->getSynchBody())
4077 return SemaRef.Owned(S->Retain());
4078
4079 // Build a new statement.
4080 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
4081 move(Object), move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004082}
4083
4084template<typename Derived>
4085Sema::OwningStmtResult
4086TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004087 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004088 // Transform the element statement.
4089 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
4090 if (Element.isInvalid())
4091 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004092
Douglas Gregorc3203e72010-04-22 23:10:45 +00004093 // Transform the collection expression.
4094 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
4095 if (Collection.isInvalid())
4096 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004097
Douglas Gregorc3203e72010-04-22 23:10:45 +00004098 // Transform the body.
4099 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
4100 if (Body.isInvalid())
4101 return SemaRef.StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004102
Douglas Gregorc3203e72010-04-22 23:10:45 +00004103 // If nothing changed, just retain this statement.
4104 if (!getDerived().AlwaysRebuild() &&
4105 Element.get() == S->getElement() &&
4106 Collection.get() == S->getCollection() &&
4107 Body.get() == S->getBody())
4108 return SemaRef.Owned(S->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004109
Douglas Gregorc3203e72010-04-22 23:10:45 +00004110 // Build a new statement.
4111 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4112 /*FIXME:*/S->getForLoc(),
4113 move(Element),
4114 move(Collection),
4115 S->getRParenLoc(),
4116 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00004117}
4118
4119
4120template<typename Derived>
4121Sema::OwningStmtResult
4122TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4123 // Transform the exception declaration, if any.
4124 VarDecl *Var = 0;
4125 if (S->getExceptionDecl()) {
4126 VarDecl *ExceptionDecl = S->getExceptionDecl();
4127 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4128 ExceptionDecl->getDeclName());
4129
4130 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4131 if (T.isNull())
4132 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004133
Douglas Gregor43959a92009-08-20 07:17:43 +00004134 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4135 T,
John McCalla93c9342009-12-07 02:54:59 +00004136 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004137 ExceptionDecl->getIdentifier(),
4138 ExceptionDecl->getLocation(),
4139 /*FIXME: Inaccurate*/
4140 SourceRange(ExceptionDecl->getLocation()));
Douglas Gregorff331c12010-07-25 18:17:45 +00004141 if (!Var || Var->isInvalidDecl())
Douglas Gregor43959a92009-08-20 07:17:43 +00004142 return SemaRef.StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004143 }
Mike Stump1eb44332009-09-09 15:08:12 +00004144
Douglas Gregor43959a92009-08-20 07:17:43 +00004145 // Transform the actual exception handler.
4146 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00004147 if (Handler.isInvalid())
Douglas Gregor43959a92009-08-20 07:17:43 +00004148 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004149
Douglas Gregor43959a92009-08-20 07:17:43 +00004150 if (!getDerived().AlwaysRebuild() &&
4151 !Var &&
4152 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00004153 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004154
4155 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4156 Var,
4157 move(Handler));
4158}
Mike Stump1eb44332009-09-09 15:08:12 +00004159
Douglas Gregor43959a92009-08-20 07:17:43 +00004160template<typename Derived>
4161Sema::OwningStmtResult
4162TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4163 // Transform the try block itself.
Mike Stump1eb44332009-09-09 15:08:12 +00004164 OwningStmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004165 = getDerived().TransformCompoundStmt(S->getTryBlock());
4166 if (TryBlock.isInvalid())
4167 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004168
Douglas Gregor43959a92009-08-20 07:17:43 +00004169 // Transform the handlers.
4170 bool HandlerChanged = false;
4171 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4172 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump1eb44332009-09-09 15:08:12 +00004173 OwningStmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004174 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4175 if (Handler.isInvalid())
4176 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004177
Douglas Gregor43959a92009-08-20 07:17:43 +00004178 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4179 Handlers.push_back(Handler.takeAs<Stmt>());
4180 }
Mike Stump1eb44332009-09-09 15:08:12 +00004181
Douglas Gregor43959a92009-08-20 07:17:43 +00004182 if (!getDerived().AlwaysRebuild() &&
4183 TryBlock.get() == S->getTryBlock() &&
4184 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004185 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00004186
4187 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump1eb44332009-09-09 15:08:12 +00004188 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004189}
Mike Stump1eb44332009-09-09 15:08:12 +00004190
Douglas Gregor43959a92009-08-20 07:17:43 +00004191//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004192// Expression transformation
4193//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004194template<typename Derived>
4195Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004196TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004197 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004198}
Mike Stump1eb44332009-09-09 15:08:12 +00004199
4200template<typename Derived>
4201Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004202TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004203 NestedNameSpecifier *Qualifier = 0;
4204 if (E->getQualifier()) {
4205 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004206 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004207 if (!Qualifier)
4208 return SemaRef.ExprError();
4209 }
John McCalldbd872f2009-12-08 09:08:17 +00004210
4211 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004212 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4213 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004214 if (!ND)
4215 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004216
Abramo Bagnara25777432010-08-11 22:01:17 +00004217 DeclarationNameInfo NameInfo
4218 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
4219 if (!NameInfo.getName())
4220 return SemaRef.ExprError();
4221
4222 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004223 Qualifier == E->getQualifier() &&
4224 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00004225 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCalldbd872f2009-12-08 09:08:17 +00004226 !E->hasExplicitTemplateArgumentList()) {
4227
4228 // Mark it referenced in the new context regardless.
4229 // FIXME: this is a bit instantiation-specific.
4230 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4231
Mike Stump1eb44332009-09-09 15:08:12 +00004232 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004233 }
John McCalldbd872f2009-12-08 09:08:17 +00004234
4235 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4236 if (E->hasExplicitTemplateArgumentList()) {
4237 TemplateArgs = &TransArgs;
4238 TransArgs.setLAngleLoc(E->getLAngleLoc());
4239 TransArgs.setRAngleLoc(E->getRAngleLoc());
4240 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4241 TemplateArgumentLoc Loc;
4242 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4243 return SemaRef.ExprError();
4244 TransArgs.addArgument(Loc);
4245 }
4246 }
4247
Douglas Gregora2813ce2009-10-23 18:54:35 +00004248 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004249 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004250}
Mike Stump1eb44332009-09-09 15:08:12 +00004251
Douglas Gregorb98b1992009-08-11 05:31:07 +00004252template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004253Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004254TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004255 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004256}
Mike Stump1eb44332009-09-09 15:08:12 +00004257
Douglas Gregorb98b1992009-08-11 05:31:07 +00004258template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004259Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004260TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004261 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004262}
Mike Stump1eb44332009-09-09 15:08:12 +00004263
Douglas Gregorb98b1992009-08-11 05:31:07 +00004264template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004265Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004266TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004267 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004268}
Mike Stump1eb44332009-09-09 15:08:12 +00004269
Douglas Gregorb98b1992009-08-11 05:31:07 +00004270template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004271Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004272TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004273 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004274}
Mike Stump1eb44332009-09-09 15:08:12 +00004275
Douglas Gregorb98b1992009-08-11 05:31:07 +00004276template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004277Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004278TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004279 return SemaRef.Owned(E->Retain());
4280}
4281
4282template<typename Derived>
4283Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004284TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004285 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4286 if (SubExpr.isInvalid())
4287 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004288
Douglas Gregorb98b1992009-08-11 05:31:07 +00004289 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004290 return SemaRef.Owned(E->Retain());
4291
4292 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004293 E->getRParen());
4294}
4295
Mike Stump1eb44332009-09-09 15:08:12 +00004296template<typename Derived>
4297Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004298TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4299 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004300 if (SubExpr.isInvalid())
4301 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004302
Douglas Gregorb98b1992009-08-11 05:31:07 +00004303 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004304 return SemaRef.Owned(E->Retain());
4305
Douglas Gregorb98b1992009-08-11 05:31:07 +00004306 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4307 E->getOpcode(),
4308 move(SubExpr));
4309}
Mike Stump1eb44332009-09-09 15:08:12 +00004310
Douglas Gregorb98b1992009-08-11 05:31:07 +00004311template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004312Sema::OwningExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004313TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4314 // Transform the type.
4315 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4316 if (!Type)
4317 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004318
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004319 // Transform all of the components into components similar to what the
4320 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004321 // FIXME: It would be slightly more efficient in the non-dependent case to
4322 // just map FieldDecls, rather than requiring the rebuilder to look for
4323 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004324 // template code that we don't care.
4325 bool ExprChanged = false;
4326 typedef Action::OffsetOfComponent Component;
4327 typedef OffsetOfExpr::OffsetOfNode Node;
4328 llvm::SmallVector<Component, 4> Components;
4329 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4330 const Node &ON = E->getComponent(I);
4331 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004332 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004333 Comp.LocStart = ON.getRange().getBegin();
4334 Comp.LocEnd = ON.getRange().getEnd();
4335 switch (ON.getKind()) {
4336 case Node::Array: {
4337 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4338 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4339 if (Index.isInvalid())
4340 return getSema().ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004341
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004342 ExprChanged = ExprChanged || Index.get() != FromIndex;
4343 Comp.isBrackets = true;
4344 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4345 break;
4346 }
Sean Huntc3021132010-05-05 15:23:54 +00004347
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004348 case Node::Field:
4349 case Node::Identifier:
4350 Comp.isBrackets = false;
4351 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004352 if (!Comp.U.IdentInfo)
4353 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004354
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004355 break;
Sean Huntc3021132010-05-05 15:23:54 +00004356
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004357 case Node::Base:
4358 // Will be recomputed during the rebuild.
4359 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004360 }
Sean Huntc3021132010-05-05 15:23:54 +00004361
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004362 Components.push_back(Comp);
4363 }
Sean Huntc3021132010-05-05 15:23:54 +00004364
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004365 // If nothing changed, retain the existing expression.
4366 if (!getDerived().AlwaysRebuild() &&
4367 Type == E->getTypeSourceInfo() &&
4368 !ExprChanged)
4369 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00004370
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004371 // Build a new offsetof expression.
4372 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4373 Components.data(), Components.size(),
4374 E->getRParenLoc());
4375}
4376
4377template<typename Derived>
4378Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004379TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004380 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004381 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004382
John McCalla93c9342009-12-07 02:54:59 +00004383 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004384 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004385 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004386
John McCall5ab75172009-11-04 07:28:41 +00004387 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004388 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004389
John McCall5ab75172009-11-04 07:28:41 +00004390 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004391 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004392 E->getSourceRange());
4393 }
Mike Stump1eb44332009-09-09 15:08:12 +00004394
Douglas Gregorb98b1992009-08-11 05:31:07 +00004395 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00004396 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004397 // C++0x [expr.sizeof]p1:
4398 // The operand is either an expression, which is an unevaluated operand
4399 // [...]
4400 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004401
Douglas Gregorb98b1992009-08-11 05:31:07 +00004402 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4403 if (SubExpr.isInvalid())
4404 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004405
Douglas Gregorb98b1992009-08-11 05:31:07 +00004406 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4407 return SemaRef.Owned(E->Retain());
4408 }
Mike Stump1eb44332009-09-09 15:08:12 +00004409
Douglas Gregorb98b1992009-08-11 05:31:07 +00004410 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4411 E->isSizeOf(),
4412 E->getSourceRange());
4413}
Mike Stump1eb44332009-09-09 15:08:12 +00004414
Douglas Gregorb98b1992009-08-11 05:31:07 +00004415template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004416Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004417TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004418 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4419 if (LHS.isInvalid())
4420 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004421
Douglas Gregorb98b1992009-08-11 05:31:07 +00004422 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4423 if (RHS.isInvalid())
4424 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004425
4426
Douglas Gregorb98b1992009-08-11 05:31:07 +00004427 if (!getDerived().AlwaysRebuild() &&
4428 LHS.get() == E->getLHS() &&
4429 RHS.get() == E->getRHS())
4430 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004431
Douglas Gregorb98b1992009-08-11 05:31:07 +00004432 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4433 /*FIXME:*/E->getLHS()->getLocStart(),
4434 move(RHS),
4435 E->getRBracketLoc());
4436}
Mike Stump1eb44332009-09-09 15:08:12 +00004437
4438template<typename Derived>
4439Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004440TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004441 // Transform the callee.
4442 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4443 if (Callee.isInvalid())
4444 return SemaRef.ExprError();
4445
4446 // Transform arguments.
4447 bool ArgChanged = false;
4448 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4449 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4450 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4451 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4452 if (Arg.isInvalid())
4453 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004454
Douglas Gregorb98b1992009-08-11 05:31:07 +00004455 // FIXME: Wrong source location information for the ','.
4456 FakeCommaLocs.push_back(
4457 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00004458
4459 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004460 Args.push_back(Arg.takeAs<Expr>());
4461 }
Mike Stump1eb44332009-09-09 15:08:12 +00004462
Douglas Gregorb98b1992009-08-11 05:31:07 +00004463 if (!getDerived().AlwaysRebuild() &&
4464 Callee.get() == E->getCallee() &&
4465 !ArgChanged)
4466 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004467
Douglas Gregorb98b1992009-08-11 05:31:07 +00004468 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004469 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004470 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4471 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4472 move_arg(Args),
4473 FakeCommaLocs.data(),
4474 E->getRParenLoc());
4475}
Mike Stump1eb44332009-09-09 15:08:12 +00004476
4477template<typename Derived>
4478Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004479TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004480 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4481 if (Base.isInvalid())
4482 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004483
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004484 NestedNameSpecifier *Qualifier = 0;
4485 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004486 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004487 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004488 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004489 if (Qualifier == 0)
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004490 return SemaRef.ExprError();
4491 }
Mike Stump1eb44332009-09-09 15:08:12 +00004492
Eli Friedmanf595cc42009-12-04 06:40:45 +00004493 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004494 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4495 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004496 if (!Member)
4497 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004498
John McCall6bb80172010-03-30 21:47:33 +00004499 NamedDecl *FoundDecl = E->getFoundDecl();
4500 if (FoundDecl == E->getMemberDecl()) {
4501 FoundDecl = Member;
4502 } else {
4503 FoundDecl = cast_or_null<NamedDecl>(
4504 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4505 if (!FoundDecl)
4506 return SemaRef.ExprError();
4507 }
4508
Douglas Gregorb98b1992009-08-11 05:31:07 +00004509 if (!getDerived().AlwaysRebuild() &&
4510 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004511 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004512 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004513 FoundDecl == E->getFoundDecl() &&
Anders Carlsson1f240322009-12-22 05:24:09 +00004514 !E->hasExplicitTemplateArgumentList()) {
Sean Huntc3021132010-05-05 15:23:54 +00004515
Anders Carlsson1f240322009-12-22 05:24:09 +00004516 // Mark it referenced in the new context regardless.
4517 // FIXME: this is a bit instantiation-specific.
4518 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00004519 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00004520 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004521
John McCalld5532b62009-11-23 01:53:49 +00004522 TemplateArgumentListInfo TransArgs;
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004523 if (E->hasExplicitTemplateArgumentList()) {
John McCalld5532b62009-11-23 01:53:49 +00004524 TransArgs.setLAngleLoc(E->getLAngleLoc());
4525 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004526 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004527 TemplateArgumentLoc Loc;
4528 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004529 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004530 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004531 }
4532 }
Sean Huntc3021132010-05-05 15:23:54 +00004533
Douglas Gregorb98b1992009-08-11 05:31:07 +00004534 // FIXME: Bogus source location for the operator
4535 SourceLocation FakeOperatorLoc
4536 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4537
John McCallc2233c52010-01-15 08:34:02 +00004538 // FIXME: to do this check properly, we will need to preserve the
4539 // first-qualifier-in-scope here, just in case we had a dependent
4540 // base (and therefore couldn't do the check) and a
4541 // nested-name-qualifier (and therefore could do the lookup).
4542 NamedDecl *FirstQualifierInScope = 0;
4543
Douglas Gregorb98b1992009-08-11 05:31:07 +00004544 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4545 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004546 Qualifier,
4547 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004548 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004549 Member,
John McCall6bb80172010-03-30 21:47:33 +00004550 FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00004551 (E->hasExplicitTemplateArgumentList()
4552 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004553 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004554}
Mike Stump1eb44332009-09-09 15:08:12 +00004555
Douglas Gregorb98b1992009-08-11 05:31:07 +00004556template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00004557Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004558TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004559 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4560 if (LHS.isInvalid())
4561 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004562
Douglas Gregorb98b1992009-08-11 05:31:07 +00004563 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4564 if (RHS.isInvalid())
4565 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004566
Douglas Gregorb98b1992009-08-11 05:31:07 +00004567 if (!getDerived().AlwaysRebuild() &&
4568 LHS.get() == E->getLHS() &&
4569 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004570 return SemaRef.Owned(E->Retain());
4571
Douglas Gregorb98b1992009-08-11 05:31:07 +00004572 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4573 move(LHS), move(RHS));
4574}
4575
Mike Stump1eb44332009-09-09 15:08:12 +00004576template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00004577Sema::OwningExprResult
4578TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00004579 CompoundAssignOperator *E) {
4580 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004581}
Mike Stump1eb44332009-09-09 15:08:12 +00004582
Douglas Gregorb98b1992009-08-11 05:31:07 +00004583template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004584Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004585TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004586 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4587 if (Cond.isInvalid())
4588 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004589
Douglas Gregorb98b1992009-08-11 05:31:07 +00004590 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4591 if (LHS.isInvalid())
4592 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004593
Douglas Gregorb98b1992009-08-11 05:31:07 +00004594 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4595 if (RHS.isInvalid())
4596 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004597
Douglas Gregorb98b1992009-08-11 05:31:07 +00004598 if (!getDerived().AlwaysRebuild() &&
4599 Cond.get() == E->getCond() &&
4600 LHS.get() == E->getLHS() &&
4601 RHS.get() == E->getRHS())
4602 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004603
4604 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004605 E->getQuestionLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004606 move(LHS),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00004607 E->getColonLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004608 move(RHS));
4609}
Mike Stump1eb44332009-09-09 15:08:12 +00004610
4611template<typename Derived>
4612Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004613TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004614 // Implicit casts are eliminated during transformation, since they
4615 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00004616 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004617}
Mike Stump1eb44332009-09-09 15:08:12 +00004618
Douglas Gregorb98b1992009-08-11 05:31:07 +00004619template<typename Derived>
4620Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004621TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004622 TypeSourceInfo *OldT;
4623 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004624 {
4625 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004626 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004627 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4628 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004629
John McCall9d125032010-01-15 18:39:57 +00004630 OldT = E->getTypeInfoAsWritten();
4631 NewT = getDerived().TransformType(OldT);
4632 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004633 return SemaRef.ExprError();
4634 }
Mike Stump1eb44332009-09-09 15:08:12 +00004635
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004636 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004637 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004638 if (SubExpr.isInvalid())
4639 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004640
Douglas Gregorb98b1992009-08-11 05:31:07 +00004641 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004642 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004643 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004644 return SemaRef.Owned(E->Retain());
4645
John McCall9d125032010-01-15 18:39:57 +00004646 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4647 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004648 E->getRParenLoc(),
4649 move(SubExpr));
4650}
Mike Stump1eb44332009-09-09 15:08:12 +00004651
Douglas Gregorb98b1992009-08-11 05:31:07 +00004652template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004653Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004654TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004655 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4656 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4657 if (!NewT)
4658 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004659
Douglas Gregorb98b1992009-08-11 05:31:07 +00004660 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4661 if (Init.isInvalid())
4662 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004663
Douglas Gregorb98b1992009-08-11 05:31:07 +00004664 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004665 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004666 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00004667 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004668
John McCall1d7d8d62010-01-19 22:33:45 +00004669 // Note: the expression type doesn't necessarily match the
4670 // type-as-written, but that's okay, because it should always be
4671 // derivable from the initializer.
4672
John McCall42f56b52010-01-18 19:35:47 +00004673 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004674 /*FIXME:*/E->getInitializer()->getLocEnd(),
4675 move(Init));
4676}
Mike Stump1eb44332009-09-09 15:08:12 +00004677
Douglas Gregorb98b1992009-08-11 05:31:07 +00004678template<typename Derived>
4679Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004680TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004681 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4682 if (Base.isInvalid())
4683 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004684
Douglas Gregorb98b1992009-08-11 05:31:07 +00004685 if (!getDerived().AlwaysRebuild() &&
4686 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00004687 return SemaRef.Owned(E->Retain());
4688
Douglas Gregorb98b1992009-08-11 05:31:07 +00004689 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004690 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004691 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4692 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4693 E->getAccessorLoc(),
4694 E->getAccessor());
4695}
Mike Stump1eb44332009-09-09 15:08:12 +00004696
Douglas Gregorb98b1992009-08-11 05:31:07 +00004697template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004698Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004699TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004700 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004701
Douglas Gregorb98b1992009-08-11 05:31:07 +00004702 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4703 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4704 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4705 if (Init.isInvalid())
4706 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004707
Douglas Gregorb98b1992009-08-11 05:31:07 +00004708 InitChanged = InitChanged || Init.get() != E->getInit(I);
4709 Inits.push_back(Init.takeAs<Expr>());
4710 }
Mike Stump1eb44332009-09-09 15:08:12 +00004711
Douglas Gregorb98b1992009-08-11 05:31:07 +00004712 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004713 return SemaRef.Owned(E->Retain());
4714
Douglas Gregorb98b1992009-08-11 05:31:07 +00004715 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004716 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004717}
Mike Stump1eb44332009-09-09 15:08:12 +00004718
Douglas Gregorb98b1992009-08-11 05:31:07 +00004719template<typename Derived>
4720Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004721TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004722 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004723
Douglas Gregor43959a92009-08-20 07:17:43 +00004724 // transform the initializer value
Douglas Gregorb98b1992009-08-11 05:31:07 +00004725 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4726 if (Init.isInvalid())
4727 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004728
Douglas Gregor43959a92009-08-20 07:17:43 +00004729 // transform the designators.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004730 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4731 bool ExprChanged = false;
4732 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4733 DEnd = E->designators_end();
4734 D != DEnd; ++D) {
4735 if (D->isFieldDesignator()) {
4736 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4737 D->getDotLoc(),
4738 D->getFieldLoc()));
4739 continue;
4740 }
Mike Stump1eb44332009-09-09 15:08:12 +00004741
Douglas Gregorb98b1992009-08-11 05:31:07 +00004742 if (D->isArrayDesignator()) {
4743 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4744 if (Index.isInvalid())
4745 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004746
4747 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004748 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004749
Douglas Gregorb98b1992009-08-11 05:31:07 +00004750 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4751 ArrayExprs.push_back(Index.release());
4752 continue;
4753 }
Mike Stump1eb44332009-09-09 15:08:12 +00004754
Douglas Gregorb98b1992009-08-11 05:31:07 +00004755 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump1eb44332009-09-09 15:08:12 +00004756 OwningExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004757 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4758 if (Start.isInvalid())
4759 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004760
Douglas Gregorb98b1992009-08-11 05:31:07 +00004761 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4762 if (End.isInvalid())
4763 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004764
4765 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004766 End.get(),
4767 D->getLBracketLoc(),
4768 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004769
Douglas Gregorb98b1992009-08-11 05:31:07 +00004770 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4771 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004772
Douglas Gregorb98b1992009-08-11 05:31:07 +00004773 ArrayExprs.push_back(Start.release());
4774 ArrayExprs.push_back(End.release());
4775 }
Mike Stump1eb44332009-09-09 15:08:12 +00004776
Douglas Gregorb98b1992009-08-11 05:31:07 +00004777 if (!getDerived().AlwaysRebuild() &&
4778 Init.get() == E->getInit() &&
4779 !ExprChanged)
4780 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004781
Douglas Gregorb98b1992009-08-11 05:31:07 +00004782 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4783 E->getEqualOrColonLoc(),
4784 E->usesGNUSyntax(), move(Init));
4785}
Mike Stump1eb44332009-09-09 15:08:12 +00004786
Douglas Gregorb98b1992009-08-11 05:31:07 +00004787template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004788Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004789TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004790 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004791 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00004792
Douglas Gregor5557b252009-10-28 00:29:27 +00004793 // FIXME: Will we ever have proper type location here? Will we actually
4794 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004795 QualType T = getDerived().TransformType(E->getType());
4796 if (T.isNull())
4797 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004798
Douglas Gregorb98b1992009-08-11 05:31:07 +00004799 if (!getDerived().AlwaysRebuild() &&
4800 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004801 return SemaRef.Owned(E->Retain());
4802
Douglas Gregorb98b1992009-08-11 05:31:07 +00004803 return getDerived().RebuildImplicitValueInitExpr(T);
4804}
Mike Stump1eb44332009-09-09 15:08:12 +00004805
Douglas Gregorb98b1992009-08-11 05:31:07 +00004806template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004807Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004808TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004809 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4810 if (!TInfo)
4811 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004812
Douglas Gregorb98b1992009-08-11 05:31:07 +00004813 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4814 if (SubExpr.isInvalid())
4815 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004816
Douglas Gregorb98b1992009-08-11 05:31:07 +00004817 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004818 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004819 SubExpr.get() == E->getSubExpr())
4820 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004821
Douglas Gregorb98b1992009-08-11 05:31:07 +00004822 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00004823 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004824}
4825
4826template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004827Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004828TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004829 bool ArgumentChanged = false;
4830 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4831 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4832 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4833 if (Init.isInvalid())
4834 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004835
Douglas Gregorb98b1992009-08-11 05:31:07 +00004836 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4837 Inits.push_back(Init.takeAs<Expr>());
4838 }
Mike Stump1eb44332009-09-09 15:08:12 +00004839
Douglas Gregorb98b1992009-08-11 05:31:07 +00004840 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4841 move_arg(Inits),
4842 E->getRParenLoc());
4843}
Mike Stump1eb44332009-09-09 15:08:12 +00004844
Douglas Gregorb98b1992009-08-11 05:31:07 +00004845/// \brief Transform an address-of-label expression.
4846///
4847/// By default, the transformation of an address-of-label expression always
4848/// rebuilds the expression, so that the label identifier can be resolved to
4849/// the corresponding label statement by semantic analysis.
4850template<typename Derived>
4851Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004852TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004853 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4854 E->getLabel());
4855}
Mike Stump1eb44332009-09-09 15:08:12 +00004856
4857template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00004858Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004859TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004860 OwningStmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004861 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4862 if (SubStmt.isInvalid())
4863 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004864
Douglas Gregorb98b1992009-08-11 05:31:07 +00004865 if (!getDerived().AlwaysRebuild() &&
4866 SubStmt.get() == E->getSubStmt())
4867 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004868
4869 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004870 move(SubStmt),
4871 E->getRParenLoc());
4872}
Mike Stump1eb44332009-09-09 15:08:12 +00004873
Douglas Gregorb98b1992009-08-11 05:31:07 +00004874template<typename Derived>
4875Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004876TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004877 TypeSourceInfo *TInfo1;
4878 TypeSourceInfo *TInfo2;
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004879
4880 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4881 if (!TInfo1)
4882 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004883
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00004884 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4885 if (!TInfo2)
4886 return SemaRef.ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004887
4888 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004889 TInfo1 == E->getArgTInfo1() &&
4890 TInfo2 == E->getArgTInfo2())
Mike Stump1eb44332009-09-09 15:08:12 +00004891 return SemaRef.Owned(E->Retain());
4892
Douglas Gregorb98b1992009-08-11 05:31:07 +00004893 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara3fcb73d2010-08-10 08:50:03 +00004894 TInfo1, TInfo2,
4895 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004896}
Mike Stump1eb44332009-09-09 15:08:12 +00004897
Douglas Gregorb98b1992009-08-11 05:31:07 +00004898template<typename Derived>
4899Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004900TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004901 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4902 if (Cond.isInvalid())
4903 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004904
Douglas Gregorb98b1992009-08-11 05:31:07 +00004905 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4906 if (LHS.isInvalid())
4907 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004908
Douglas Gregorb98b1992009-08-11 05:31:07 +00004909 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4910 if (RHS.isInvalid())
4911 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004912
Douglas Gregorb98b1992009-08-11 05:31:07 +00004913 if (!getDerived().AlwaysRebuild() &&
4914 Cond.get() == E->getCond() &&
4915 LHS.get() == E->getLHS() &&
4916 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004917 return SemaRef.Owned(E->Retain());
4918
Douglas Gregorb98b1992009-08-11 05:31:07 +00004919 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4920 move(Cond), move(LHS), move(RHS),
4921 E->getRParenLoc());
4922}
Mike Stump1eb44332009-09-09 15:08:12 +00004923
Douglas Gregorb98b1992009-08-11 05:31:07 +00004924template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004925Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004926TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004927 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004928}
4929
4930template<typename Derived>
4931Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004932TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004933 switch (E->getOperator()) {
4934 case OO_New:
4935 case OO_Delete:
4936 case OO_Array_New:
4937 case OO_Array_Delete:
4938 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4939 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004940
Douglas Gregor668d6d92009-12-13 20:44:55 +00004941 case OO_Call: {
4942 // This is a call to an object's operator().
4943 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4944
4945 // Transform the object itself.
4946 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4947 if (Object.isInvalid())
4948 return SemaRef.ExprError();
4949
4950 // FIXME: Poor location information
4951 SourceLocation FakeLParenLoc
4952 = SemaRef.PP.getLocForEndOfToken(
4953 static_cast<Expr *>(Object.get())->getLocEnd());
4954
4955 // Transform the call arguments.
4956 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4957 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4958 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004959 if (getDerived().DropCallArgument(E->getArg(I)))
4960 break;
Sean Huntc3021132010-05-05 15:23:54 +00004961
Douglas Gregor668d6d92009-12-13 20:44:55 +00004962 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4963 if (Arg.isInvalid())
4964 return SemaRef.ExprError();
4965
4966 // FIXME: Poor source location information.
4967 SourceLocation FakeCommaLoc
4968 = SemaRef.PP.getLocForEndOfToken(
4969 static_cast<Expr *>(Arg.get())->getLocEnd());
4970 FakeCommaLocs.push_back(FakeCommaLoc);
4971 Args.push_back(Arg.release());
4972 }
4973
4974 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4975 move_arg(Args),
4976 FakeCommaLocs.data(),
4977 E->getLocEnd());
4978 }
4979
4980#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4981 case OO_##Name:
4982#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4983#include "clang/Basic/OperatorKinds.def"
4984 case OO_Subscript:
4985 // Handled below.
4986 break;
4987
4988 case OO_Conditional:
4989 llvm_unreachable("conditional operator is not actually overloadable");
4990 return SemaRef.ExprError();
4991
4992 case OO_None:
4993 case NUM_OVERLOADED_OPERATORS:
4994 llvm_unreachable("not an overloaded operator?");
4995 return SemaRef.ExprError();
4996 }
4997
Douglas Gregorb98b1992009-08-11 05:31:07 +00004998 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4999 if (Callee.isInvalid())
5000 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005001
John McCall454feb92009-12-08 09:21:05 +00005002 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005003 if (First.isInvalid())
5004 return SemaRef.ExprError();
5005
5006 OwningExprResult Second(SemaRef);
5007 if (E->getNumArgs() == 2) {
5008 Second = getDerived().TransformExpr(E->getArg(1));
5009 if (Second.isInvalid())
5010 return SemaRef.ExprError();
5011 }
Mike Stump1eb44332009-09-09 15:08:12 +00005012
Douglas Gregorb98b1992009-08-11 05:31:07 +00005013 if (!getDerived().AlwaysRebuild() &&
5014 Callee.get() == E->getCallee() &&
5015 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005016 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
5017 return SemaRef.Owned(E->Retain());
5018
Douglas Gregorb98b1992009-08-11 05:31:07 +00005019 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5020 E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005021 move(Callee),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005022 move(First),
5023 move(Second));
5024}
Mike Stump1eb44332009-09-09 15:08:12 +00005025
Douglas Gregorb98b1992009-08-11 05:31:07 +00005026template<typename Derived>
5027Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005028TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5029 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005030}
Mike Stump1eb44332009-09-09 15:08:12 +00005031
Douglas Gregorb98b1992009-08-11 05:31:07 +00005032template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005033Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005034TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00005035 TypeSourceInfo *OldT;
5036 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005037 {
5038 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00005039 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005040 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5041 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005042
John McCall9d125032010-01-15 18:39:57 +00005043 OldT = E->getTypeInfoAsWritten();
5044 NewT = getDerived().TransformType(OldT);
5045 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005046 return SemaRef.ExprError();
5047 }
Mike Stump1eb44332009-09-09 15:08:12 +00005048
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005049 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005050 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005051 if (SubExpr.isInvalid())
5052 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005053
Douglas Gregorb98b1992009-08-11 05:31:07 +00005054 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00005055 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005056 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005057 return SemaRef.Owned(E->Retain());
5058
Douglas Gregorb98b1992009-08-11 05:31:07 +00005059 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005060 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005061 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5062 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5063 SourceLocation FakeRParenLoc
5064 = SemaRef.PP.getLocForEndOfToken(
5065 E->getSubExpr()->getSourceRange().getEnd());
5066 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005067 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005068 FakeLAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00005069 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005070 FakeRAngleLoc,
5071 FakeRAngleLoc,
5072 move(SubExpr),
5073 FakeRParenLoc);
5074}
Mike Stump1eb44332009-09-09 15:08:12 +00005075
Douglas Gregorb98b1992009-08-11 05:31:07 +00005076template<typename Derived>
5077Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005078TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5079 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005080}
Mike Stump1eb44332009-09-09 15:08:12 +00005081
5082template<typename Derived>
5083Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005084TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5085 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005086}
5087
Douglas Gregorb98b1992009-08-11 05:31:07 +00005088template<typename Derived>
5089Sema::OwningExprResult
5090TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005091 CXXReinterpretCastExpr *E) {
5092 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005093}
Mike Stump1eb44332009-09-09 15:08:12 +00005094
Douglas Gregorb98b1992009-08-11 05:31:07 +00005095template<typename Derived>
5096Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005097TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5098 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005099}
Mike Stump1eb44332009-09-09 15:08:12 +00005100
Douglas Gregorb98b1992009-08-11 05:31:07 +00005101template<typename Derived>
5102Sema::OwningExprResult
5103TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005104 CXXFunctionalCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00005105 TypeSourceInfo *OldT;
5106 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005107 {
5108 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005109
John McCall9d125032010-01-15 18:39:57 +00005110 OldT = E->getTypeInfoAsWritten();
5111 NewT = getDerived().TransformType(OldT);
5112 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005113 return SemaRef.ExprError();
5114 }
Mike Stump1eb44332009-09-09 15:08:12 +00005115
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005116 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005117 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005118 if (SubExpr.isInvalid())
5119 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005120
Douglas Gregorb98b1992009-08-11 05:31:07 +00005121 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00005122 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005123 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005124 return SemaRef.Owned(E->Retain());
5125
Douglas Gregorb98b1992009-08-11 05:31:07 +00005126 // FIXME: The end of the type's source range is wrong
5127 return getDerived().RebuildCXXFunctionalCastExpr(
5128 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall9d125032010-01-15 18:39:57 +00005129 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005130 /*FIXME:*/E->getSubExpr()->getLocStart(),
5131 move(SubExpr),
5132 E->getRParenLoc());
5133}
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>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005138 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005139 TypeSourceInfo *TInfo
5140 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5141 if (!TInfo)
Douglas Gregorb98b1992009-08-11 05:31:07 +00005142 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005143
Douglas Gregorb98b1992009-08-11 05:31:07 +00005144 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005145 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregorb98b1992009-08-11 05:31:07 +00005146 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005147
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005148 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5149 E->getLocStart(),
5150 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005151 E->getLocEnd());
5152 }
Mike Stump1eb44332009-09-09 15:08:12 +00005153
Douglas Gregorb98b1992009-08-11 05:31:07 +00005154 // We don't know whether the expression is potentially evaluated until
5155 // after we perform semantic analysis, so the expression is potentially
5156 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005157 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005158 Action::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005159
Douglas Gregorb98b1992009-08-11 05:31:07 +00005160 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5161 if (SubExpr.isInvalid())
5162 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005163
Douglas Gregorb98b1992009-08-11 05:31:07 +00005164 if (!getDerived().AlwaysRebuild() &&
5165 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00005166 return SemaRef.Owned(E->Retain());
5167
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005168 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5169 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005170 move(SubExpr),
5171 E->getLocEnd());
5172}
5173
5174template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005175Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005176TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005177 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005178}
Mike Stump1eb44332009-09-09 15:08:12 +00005179
Douglas Gregorb98b1992009-08-11 05:31:07 +00005180template<typename Derived>
5181Sema::OwningExprResult
5182TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005183 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005184 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005185}
Mike Stump1eb44332009-09-09 15:08:12 +00005186
Douglas Gregorb98b1992009-08-11 05:31:07 +00005187template<typename Derived>
5188Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005189TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005190 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005191
Douglas Gregorb98b1992009-08-11 05:31:07 +00005192 QualType T = getDerived().TransformType(E->getType());
5193 if (T.isNull())
5194 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005195
Douglas Gregorb98b1992009-08-11 05:31:07 +00005196 if (!getDerived().AlwaysRebuild() &&
5197 T == E->getType())
5198 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005199
Douglas Gregor828a1972010-01-07 23:12:05 +00005200 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005201}
Mike Stump1eb44332009-09-09 15:08:12 +00005202
Douglas Gregorb98b1992009-08-11 05:31:07 +00005203template<typename Derived>
5204Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005205TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005206 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5207 if (SubExpr.isInvalid())
5208 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005209
Douglas Gregorb98b1992009-08-11 05:31:07 +00005210 if (!getDerived().AlwaysRebuild() &&
5211 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00005212 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005213
5214 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5215}
Mike Stump1eb44332009-09-09 15:08:12 +00005216
Douglas Gregorb98b1992009-08-11 05:31:07 +00005217template<typename Derived>
5218Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005219TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005220 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005221 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5222 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005223 if (!Param)
5224 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005225
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005226 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005227 Param == E->getParam())
5228 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005229
Douglas Gregor036aed12009-12-23 23:03:06 +00005230 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005231}
Mike Stump1eb44332009-09-09 15:08:12 +00005232
Douglas Gregorb98b1992009-08-11 05:31:07 +00005233template<typename Derived>
5234Sema::OwningExprResult
Douglas Gregored8abf12010-07-08 06:14:04 +00005235TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005236 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5237
5238 QualType T = getDerived().TransformType(E->getType());
5239 if (T.isNull())
5240 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005241
Douglas Gregorb98b1992009-08-11 05:31:07 +00005242 if (!getDerived().AlwaysRebuild() &&
5243 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00005244 return SemaRef.Owned(E->Retain());
5245
Douglas Gregored8abf12010-07-08 06:14:04 +00005246 return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(),
5247 /*FIXME:*/E->getTypeBeginLoc(),
5248 T,
5249 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005250}
Mike Stump1eb44332009-09-09 15:08:12 +00005251
Douglas Gregorb98b1992009-08-11 05:31:07 +00005252template<typename Derived>
5253Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005254TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005255 // Transform the type that we're allocating
5256 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5257 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5258 if (AllocType.isNull())
5259 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005260
Douglas Gregorb98b1992009-08-11 05:31:07 +00005261 // Transform the size of the array we're allocating (if any).
5262 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5263 if (ArraySize.isInvalid())
5264 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005265
Douglas Gregorb98b1992009-08-11 05:31:07 +00005266 // Transform the placement arguments (if any).
5267 bool ArgumentChanged = false;
5268 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5269 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5270 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5271 if (Arg.isInvalid())
5272 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005273
Douglas Gregorb98b1992009-08-11 05:31:07 +00005274 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5275 PlacementArgs.push_back(Arg.take());
5276 }
Mike Stump1eb44332009-09-09 15:08:12 +00005277
Douglas Gregor43959a92009-08-20 07:17:43 +00005278 // transform the constructor arguments (if any).
Douglas Gregorb98b1992009-08-11 05:31:07 +00005279 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5280 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005281 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5282 break;
5283
Douglas Gregorb98b1992009-08-11 05:31:07 +00005284 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5285 if (Arg.isInvalid())
5286 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005287
Douglas Gregorb98b1992009-08-11 05:31:07 +00005288 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5289 ConstructorArgs.push_back(Arg.take());
5290 }
Mike Stump1eb44332009-09-09 15:08:12 +00005291
Douglas Gregor1af74512010-02-26 00:38:10 +00005292 // Transform constructor, new operator, and delete operator.
5293 CXXConstructorDecl *Constructor = 0;
5294 if (E->getConstructor()) {
5295 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005296 getDerived().TransformDecl(E->getLocStart(),
5297 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005298 if (!Constructor)
5299 return SemaRef.ExprError();
5300 }
5301
5302 FunctionDecl *OperatorNew = 0;
5303 if (E->getOperatorNew()) {
5304 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005305 getDerived().TransformDecl(E->getLocStart(),
5306 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005307 if (!OperatorNew)
5308 return SemaRef.ExprError();
5309 }
5310
5311 FunctionDecl *OperatorDelete = 0;
5312 if (E->getOperatorDelete()) {
5313 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005314 getDerived().TransformDecl(E->getLocStart(),
5315 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005316 if (!OperatorDelete)
5317 return SemaRef.ExprError();
5318 }
Sean Huntc3021132010-05-05 15:23:54 +00005319
Douglas Gregorb98b1992009-08-11 05:31:07 +00005320 if (!getDerived().AlwaysRebuild() &&
5321 AllocType == E->getAllocatedType() &&
5322 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005323 Constructor == E->getConstructor() &&
5324 OperatorNew == E->getOperatorNew() &&
5325 OperatorDelete == E->getOperatorDelete() &&
5326 !ArgumentChanged) {
5327 // Mark any declarations we need as referenced.
5328 // FIXME: instantiation-specific.
5329 if (Constructor)
5330 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5331 if (OperatorNew)
5332 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5333 if (OperatorDelete)
5334 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005335 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005336 }
Mike Stump1eb44332009-09-09 15:08:12 +00005337
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005338 if (!ArraySize.get()) {
5339 // If no array size was specified, but the new expression was
5340 // instantiated with an array type (e.g., "new T" where T is
5341 // instantiated with "int[4]"), extract the outer bound from the
5342 // array type as our array size. We do this with constant and
5343 // dependently-sized array types.
5344 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5345 if (!ArrayT) {
5346 // Do nothing
5347 } else if (const ConstantArrayType *ConsArrayT
5348 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005349 ArraySize
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005350 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Sean Huntc3021132010-05-05 15:23:54 +00005351 ConsArrayT->getSize(),
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005352 SemaRef.Context.getSizeType(),
5353 /*FIXME:*/E->getLocStart()));
5354 AllocType = ConsArrayT->getElementType();
5355 } else if (const DependentSizedArrayType *DepArrayT
5356 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5357 if (DepArrayT->getSizeExpr()) {
5358 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5359 AllocType = DepArrayT->getElementType();
5360 }
5361 }
5362 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005363 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5364 E->isGlobalNew(),
5365 /*FIXME:*/E->getLocStart(),
5366 move_arg(PlacementArgs),
5367 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00005368 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005369 AllocType,
5370 /*FIXME:*/E->getLocStart(),
5371 /*FIXME:*/SourceRange(),
5372 move(ArraySize),
5373 /*FIXME:*/E->getLocStart(),
5374 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005375 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005376}
Mike Stump1eb44332009-09-09 15:08:12 +00005377
Douglas Gregorb98b1992009-08-11 05:31:07 +00005378template<typename Derived>
5379Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005380TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005381 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5382 if (Operand.isInvalid())
5383 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005384
Douglas Gregor1af74512010-02-26 00:38:10 +00005385 // Transform the delete operator, if known.
5386 FunctionDecl *OperatorDelete = 0;
5387 if (E->getOperatorDelete()) {
5388 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005389 getDerived().TransformDecl(E->getLocStart(),
5390 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005391 if (!OperatorDelete)
5392 return SemaRef.ExprError();
5393 }
Sean Huntc3021132010-05-05 15:23:54 +00005394
Douglas Gregorb98b1992009-08-11 05:31:07 +00005395 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005396 Operand.get() == E->getArgument() &&
5397 OperatorDelete == E->getOperatorDelete()) {
5398 // Mark any declarations we need as referenced.
5399 // FIXME: instantiation-specific.
5400 if (OperatorDelete)
5401 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00005402 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00005403 }
Mike Stump1eb44332009-09-09 15:08:12 +00005404
Douglas Gregorb98b1992009-08-11 05:31:07 +00005405 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5406 E->isGlobalDelete(),
5407 E->isArrayForm(),
5408 move(Operand));
5409}
Mike Stump1eb44332009-09-09 15:08:12 +00005410
Douglas Gregorb98b1992009-08-11 05:31:07 +00005411template<typename Derived>
5412Sema::OwningExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005413TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005414 CXXPseudoDestructorExpr *E) {
Douglas Gregora71d8192009-09-04 17:36:40 +00005415 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5416 if (Base.isInvalid())
5417 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005418
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005419 Sema::TypeTy *ObjectTypePtr = 0;
5420 bool MayBePseudoDestructor = false;
Sean Huntc3021132010-05-05 15:23:54 +00005421 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005422 E->getOperatorLoc(),
5423 E->isArrow()? tok::arrow : tok::period,
5424 ObjectTypePtr,
5425 MayBePseudoDestructor);
5426 if (Base.isInvalid())
5427 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005428
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005429 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregora71d8192009-09-04 17:36:40 +00005430 NestedNameSpecifier *Qualifier
5431 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00005432 E->getQualifierRange(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005433 ObjectType);
Douglas Gregora71d8192009-09-04 17:36:40 +00005434 if (E->getQualifier() && !Qualifier)
5435 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005436
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005437 PseudoDestructorTypeStorage Destroyed;
5438 if (E->getDestroyedTypeInfo()) {
5439 TypeSourceInfo *DestroyedTypeInfo
5440 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5441 if (!DestroyedTypeInfo)
5442 return SemaRef.ExprError();
5443 Destroyed = DestroyedTypeInfo;
5444 } else if (ObjectType->isDependentType()) {
5445 // We aren't likely to be able to resolve the identifier down to a type
5446 // now anyway, so just retain the identifier.
5447 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5448 E->getDestroyedTypeLoc());
5449 } else {
5450 // Look for a destructor known with the given name.
5451 CXXScopeSpec SS;
5452 if (Qualifier) {
5453 SS.setScopeRep(Qualifier);
5454 SS.setRange(E->getQualifierRange());
5455 }
Sean Huntc3021132010-05-05 15:23:54 +00005456
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005457 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5458 *E->getDestroyedTypeIdentifier(),
5459 E->getDestroyedTypeLoc(),
5460 /*Scope=*/0,
5461 SS, ObjectTypePtr,
5462 false);
5463 if (!T)
5464 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005465
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005466 Destroyed
5467 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5468 E->getDestroyedTypeLoc());
5469 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005470
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005471 TypeSourceInfo *ScopeTypeInfo = 0;
5472 if (E->getScopeTypeInfo()) {
Sean Huntc3021132010-05-05 15:23:54 +00005473 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005474 ObjectType);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005475 if (!ScopeTypeInfo)
Douglas Gregora71d8192009-09-04 17:36:40 +00005476 return SemaRef.ExprError();
5477 }
Sean Huntc3021132010-05-05 15:23:54 +00005478
Douglas Gregora71d8192009-09-04 17:36:40 +00005479 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5480 E->getOperatorLoc(),
5481 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005482 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005483 E->getQualifierRange(),
5484 ScopeTypeInfo,
5485 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005486 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005487 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00005488}
Mike Stump1eb44332009-09-09 15:08:12 +00005489
Douglas Gregora71d8192009-09-04 17:36:40 +00005490template<typename Derived>
5491Sema::OwningExprResult
John McCallba135432009-11-21 08:51:07 +00005492TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00005493 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00005494 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5495
5496 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5497 Sema::LookupOrdinaryName);
5498
5499 // Transform all the decls.
5500 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5501 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005502 NamedDecl *InstD = static_cast<NamedDecl*>(
5503 getDerived().TransformDecl(Old->getNameLoc(),
5504 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005505 if (!InstD) {
5506 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5507 // This can happen because of dependent hiding.
5508 if (isa<UsingShadowDecl>(*I))
5509 continue;
5510 else
5511 return SemaRef.ExprError();
5512 }
John McCallf7a1a742009-11-24 19:00:30 +00005513
5514 // Expand using declarations.
5515 if (isa<UsingDecl>(InstD)) {
5516 UsingDecl *UD = cast<UsingDecl>(InstD);
5517 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5518 E = UD->shadow_end(); I != E; ++I)
5519 R.addDecl(*I);
5520 continue;
5521 }
5522
5523 R.addDecl(InstD);
5524 }
5525
5526 // Resolve a kind, but don't do any further analysis. If it's
5527 // ambiguous, the callee needs to deal with it.
5528 R.resolveKind();
5529
5530 // Rebuild the nested-name qualifier, if present.
5531 CXXScopeSpec SS;
5532 NestedNameSpecifier *Qualifier = 0;
5533 if (Old->getQualifier()) {
5534 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005535 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00005536 if (!Qualifier)
5537 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005538
John McCallf7a1a742009-11-24 19:00:30 +00005539 SS.setScopeRep(Qualifier);
5540 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00005541 }
5542
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005543 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00005544 CXXRecordDecl *NamingClass
5545 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5546 Old->getNameLoc(),
5547 Old->getNamingClass()));
5548 if (!NamingClass)
5549 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005550
Douglas Gregor66c45152010-04-27 16:10:10 +00005551 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00005552 }
5553
5554 // If we have no template arguments, it's a normal declaration name.
5555 if (!Old->hasExplicitTemplateArgs())
5556 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5557
5558 // If we have template arguments, rebuild them, then rebuild the
5559 // templateid expression.
5560 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5561 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5562 TemplateArgumentLoc Loc;
5563 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5564 return SemaRef.ExprError();
5565 TransArgs.addArgument(Loc);
5566 }
5567
5568 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5569 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005570}
Mike Stump1eb44332009-09-09 15:08:12 +00005571
Douglas Gregorb98b1992009-08-11 05:31:07 +00005572template<typename Derived>
5573Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005574TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005575 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00005576
Douglas Gregorb98b1992009-08-11 05:31:07 +00005577 QualType T = getDerived().TransformType(E->getQueriedType());
5578 if (T.isNull())
5579 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005580
Douglas Gregorb98b1992009-08-11 05:31:07 +00005581 if (!getDerived().AlwaysRebuild() &&
5582 T == E->getQueriedType())
5583 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005584
Douglas Gregorb98b1992009-08-11 05:31:07 +00005585 // FIXME: Bad location information
5586 SourceLocation FakeLParenLoc
5587 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump1eb44332009-09-09 15:08:12 +00005588
5589 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005590 E->getLocStart(),
5591 /*FIXME:*/FakeLParenLoc,
5592 T,
5593 E->getLocEnd());
5594}
Mike Stump1eb44332009-09-09 15:08:12 +00005595
Douglas Gregorb98b1992009-08-11 05:31:07 +00005596template<typename Derived>
5597Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00005598TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005599 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005600 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00005601 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005602 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005603 if (!NNS)
5604 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005605
Abramo Bagnara25777432010-08-11 22:01:17 +00005606 DeclarationNameInfo NameInfo
5607 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5608 if (!NameInfo.getName())
Douglas Gregor81499bb2009-09-03 22:13:48 +00005609 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005610
John McCallf7a1a742009-11-24 19:00:30 +00005611 if (!E->hasExplicitTemplateArgs()) {
5612 if (!getDerived().AlwaysRebuild() &&
5613 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005614 // Note: it is sufficient to compare the Name component of NameInfo:
5615 // if name has not changed, DNLoc has not changed either.
5616 NameInfo.getName() == E->getDeclName())
John McCallf7a1a742009-11-24 19:00:30 +00005617 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00005618
John McCallf7a1a742009-11-24 19:00:30 +00005619 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5620 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005621 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005622 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00005623 }
John McCalld5532b62009-11-23 01:53:49 +00005624
5625 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005626 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005627 TemplateArgumentLoc Loc;
5628 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb98b1992009-08-11 05:31:07 +00005629 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005630 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005631 }
5632
John McCallf7a1a742009-11-24 19:00:30 +00005633 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5634 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005635 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00005636 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005637}
5638
5639template<typename Derived>
5640Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005641TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00005642 // CXXConstructExprs are always implicit, so when we have a
5643 // 1-argument construction we just transform that argument.
5644 if (E->getNumArgs() == 1 ||
5645 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5646 return getDerived().TransformExpr(E->getArg(0));
5647
Douglas Gregorb98b1992009-08-11 05:31:07 +00005648 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5649
5650 QualType T = getDerived().TransformType(E->getType());
5651 if (T.isNull())
5652 return SemaRef.ExprError();
5653
5654 CXXConstructorDecl *Constructor
5655 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005656 getDerived().TransformDecl(E->getLocStart(),
5657 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005658 if (!Constructor)
5659 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005660
Douglas Gregorb98b1992009-08-11 05:31:07 +00005661 bool ArgumentChanged = false;
5662 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005663 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005664 ArgEnd = E->arg_end();
5665 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005666 if (getDerived().DropCallArgument(*Arg)) {
5667 ArgumentChanged = true;
5668 break;
5669 }
5670
Douglas Gregorb98b1992009-08-11 05:31:07 +00005671 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5672 if (TransArg.isInvalid())
5673 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005674
Douglas Gregorb98b1992009-08-11 05:31:07 +00005675 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5676 Args.push_back(TransArg.takeAs<Expr>());
5677 }
5678
5679 if (!getDerived().AlwaysRebuild() &&
5680 T == E->getType() &&
5681 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005682 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005683 // Mark the constructor as referenced.
5684 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005685 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005686 return SemaRef.Owned(E->Retain());
Douglas Gregorc845aad2010-02-26 00:01:57 +00005687 }
Mike Stump1eb44332009-09-09 15:08:12 +00005688
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005689 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5690 Constructor, E->isElidable(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005691 move_arg(Args));
5692}
Mike Stump1eb44332009-09-09 15:08:12 +00005693
Douglas Gregorb98b1992009-08-11 05:31:07 +00005694/// \brief Transform a C++ temporary-binding expression.
5695///
Douglas Gregor51326552009-12-24 18:51:59 +00005696/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5697/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005698template<typename Derived>
5699Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005700TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005701 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005702}
Mike Stump1eb44332009-09-09 15:08:12 +00005703
Anders Carlssoneb60edf2010-01-29 02:39:32 +00005704/// \brief Transform a C++ reference-binding expression.
5705///
5706/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5707/// transform the subexpression and return that.
5708template<typename Derived>
5709Sema::OwningExprResult
5710TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5711 return getDerived().TransformExpr(E->getSubExpr());
5712}
5713
Mike Stump1eb44332009-09-09 15:08:12 +00005714/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00005715/// be destroyed after the expression is evaluated.
5716///
Douglas Gregor51326552009-12-24 18:51:59 +00005717/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5718/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005719template<typename Derived>
5720Sema::OwningExprResult
5721TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00005722 CXXExprWithTemporaries *E) {
5723 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005724}
Mike Stump1eb44332009-09-09 15:08:12 +00005725
Douglas Gregorb98b1992009-08-11 05:31:07 +00005726template<typename Derived>
5727Sema::OwningExprResult
5728TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall454feb92009-12-08 09:21:05 +00005729 CXXTemporaryObjectExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005730 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5731 QualType T = getDerived().TransformType(E->getType());
5732 if (T.isNull())
5733 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005734
Douglas Gregorb98b1992009-08-11 05:31:07 +00005735 CXXConstructorDecl *Constructor
5736 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00005737 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005738 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005739 if (!Constructor)
5740 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005741
Douglas Gregorb98b1992009-08-11 05:31:07 +00005742 bool ArgumentChanged = false;
5743 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5744 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005745 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005746 ArgEnd = E->arg_end();
5747 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005748 if (getDerived().DropCallArgument(*Arg)) {
5749 ArgumentChanged = true;
5750 break;
5751 }
5752
Douglas Gregorb98b1992009-08-11 05:31:07 +00005753 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5754 if (TransArg.isInvalid())
5755 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005756
Douglas Gregorb98b1992009-08-11 05:31:07 +00005757 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5758 Args.push_back((Expr *)TransArg.release());
5759 }
Mike Stump1eb44332009-09-09 15:08:12 +00005760
Douglas Gregorb98b1992009-08-11 05:31:07 +00005761 if (!getDerived().AlwaysRebuild() &&
5762 T == E->getType() &&
5763 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005764 !ArgumentChanged) {
5765 // FIXME: Instantiation-specific
5766 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carrutha3ce8ae2010-03-31 18:34:58 +00005767 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor91be6f52010-03-02 17:18:33 +00005768 }
Mike Stump1eb44332009-09-09 15:08:12 +00005769
Douglas Gregorb98b1992009-08-11 05:31:07 +00005770 // FIXME: Bogus location information
5771 SourceLocation CommaLoc;
5772 if (Args.size() > 1) {
5773 Expr *First = (Expr *)Args[0];
Mike Stump1eb44332009-09-09 15:08:12 +00005774 CommaLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005775 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5776 }
5777 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5778 T,
5779 /*FIXME:*/E->getTypeBeginLoc(),
5780 move_arg(Args),
5781 &CommaLoc,
5782 E->getLocEnd());
5783}
Mike Stump1eb44332009-09-09 15:08:12 +00005784
Douglas Gregorb98b1992009-08-11 05:31:07 +00005785template<typename Derived>
5786Sema::OwningExprResult
5787TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005788 CXXUnresolvedConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005789 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5790 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5791 if (T.isNull())
5792 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005793
Douglas Gregorb98b1992009-08-11 05:31:07 +00005794 bool ArgumentChanged = false;
5795 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5796 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5797 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5798 ArgEnd = E->arg_end();
5799 Arg != ArgEnd; ++Arg) {
5800 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5801 if (TransArg.isInvalid())
5802 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005803
Douglas Gregorb98b1992009-08-11 05:31:07 +00005804 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5805 FakeCommaLocs.push_back(
5806 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5807 Args.push_back(TransArg.takeAs<Expr>());
5808 }
Mike Stump1eb44332009-09-09 15:08:12 +00005809
Douglas Gregorb98b1992009-08-11 05:31:07 +00005810 if (!getDerived().AlwaysRebuild() &&
5811 T == E->getTypeAsWritten() &&
5812 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005813 return SemaRef.Owned(E->Retain());
5814
Douglas Gregorb98b1992009-08-11 05:31:07 +00005815 // FIXME: we're faking the locations of the commas
5816 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5817 T,
5818 E->getLParenLoc(),
5819 move_arg(Args),
5820 FakeCommaLocs.data(),
5821 E->getRParenLoc());
5822}
Mike Stump1eb44332009-09-09 15:08:12 +00005823
Douglas Gregorb98b1992009-08-11 05:31:07 +00005824template<typename Derived>
5825Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00005826TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00005827 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005828 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005829 OwningExprResult Base(SemaRef, (Expr*) 0);
5830 Expr *OldBase;
5831 QualType BaseType;
5832 QualType ObjectType;
5833 if (!E->isImplicitAccess()) {
5834 OldBase = E->getBase();
5835 Base = getDerived().TransformExpr(OldBase);
5836 if (Base.isInvalid())
5837 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005838
John McCallaa81e162009-12-01 22:10:20 +00005839 // Start the member reference and compute the object's type.
5840 Sema::TypeTy *ObjectTy = 0;
Douglas Gregord4dca082010-02-24 18:44:31 +00005841 bool MayBePseudoDestructor = false;
John McCallaa81e162009-12-01 22:10:20 +00005842 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5843 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005844 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005845 ObjectTy,
5846 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005847 if (Base.isInvalid())
5848 return SemaRef.ExprError();
5849
5850 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5851 BaseType = ((Expr*) Base.get())->getType();
5852 } else {
5853 OldBase = 0;
5854 BaseType = getDerived().TransformType(E->getBaseType());
5855 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5856 }
Mike Stump1eb44332009-09-09 15:08:12 +00005857
Douglas Gregor6cd21982009-10-20 05:58:46 +00005858 // Transform the first part of the nested-name-specifier that qualifies
5859 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005860 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005861 = getDerived().TransformFirstQualifierInScope(
5862 E->getFirstQualifierFoundInScope(),
5863 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005864
Douglas Gregora38c6872009-09-03 16:14:30 +00005865 NestedNameSpecifier *Qualifier = 0;
5866 if (E->getQualifier()) {
5867 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5868 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005869 ObjectType,
5870 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005871 if (!Qualifier)
5872 return SemaRef.ExprError();
5873 }
Mike Stump1eb44332009-09-09 15:08:12 +00005874
Abramo Bagnara25777432010-08-11 22:01:17 +00005875 DeclarationNameInfo NameInfo
5876 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5877 ObjectType);
5878 if (!NameInfo.getName())
Douglas Gregor81499bb2009-09-03 22:13:48 +00005879 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005880
John McCallaa81e162009-12-01 22:10:20 +00005881 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005882 // This is a reference to a member without an explicitly-specified
5883 // template argument list. Optimize for this common case.
5884 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005885 Base.get() == OldBase &&
5886 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005887 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005888 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005889 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005890 return SemaRef.Owned(E->Retain());
5891
John McCall865d4472009-11-19 22:55:06 +00005892 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005893 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005894 E->isArrow(),
5895 E->getOperatorLoc(),
5896 Qualifier,
5897 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005898 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005899 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005900 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005901 }
5902
John McCalld5532b62009-11-23 01:53:49 +00005903 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005904 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005905 TemplateArgumentLoc Loc;
5906 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005907 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005908 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005909 }
Mike Stump1eb44332009-09-09 15:08:12 +00005910
John McCall865d4472009-11-19 22:55:06 +00005911 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005912 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005913 E->isArrow(),
5914 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005915 Qualifier,
5916 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005917 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00005918 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00005919 &TransArgs);
5920}
5921
5922template<typename Derived>
5923Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005924TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005925 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005926 OwningExprResult Base(SemaRef, (Expr*) 0);
5927 QualType BaseType;
5928 if (!Old->isImplicitAccess()) {
5929 Base = getDerived().TransformExpr(Old->getBase());
5930 if (Base.isInvalid())
5931 return SemaRef.ExprError();
5932 BaseType = ((Expr*) Base.get())->getType();
5933 } else {
5934 BaseType = getDerived().TransformType(Old->getBaseType());
5935 }
John McCall129e2df2009-11-30 22:42:35 +00005936
5937 NestedNameSpecifier *Qualifier = 0;
5938 if (Old->getQualifier()) {
5939 Qualifier
5940 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005941 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00005942 if (Qualifier == 0)
5943 return SemaRef.ExprError();
5944 }
5945
Abramo Bagnara25777432010-08-11 22:01:17 +00005946 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00005947 Sema::LookupOrdinaryName);
5948
5949 // Transform all the decls.
5950 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5951 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005952 NamedDecl *InstD = static_cast<NamedDecl*>(
5953 getDerived().TransformDecl(Old->getMemberLoc(),
5954 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005955 if (!InstD) {
5956 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5957 // This can happen because of dependent hiding.
5958 if (isa<UsingShadowDecl>(*I))
5959 continue;
5960 else
5961 return SemaRef.ExprError();
5962 }
John McCall129e2df2009-11-30 22:42:35 +00005963
5964 // Expand using declarations.
5965 if (isa<UsingDecl>(InstD)) {
5966 UsingDecl *UD = cast<UsingDecl>(InstD);
5967 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5968 E = UD->shadow_end(); I != E; ++I)
5969 R.addDecl(*I);
5970 continue;
5971 }
5972
5973 R.addDecl(InstD);
5974 }
5975
5976 R.resolveKind();
5977
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005978 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00005979 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00005980 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005981 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00005982 Old->getMemberLoc(),
5983 Old->getNamingClass()));
5984 if (!NamingClass)
5985 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005986
Douglas Gregor66c45152010-04-27 16:10:10 +00005987 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005988 }
Sean Huntc3021132010-05-05 15:23:54 +00005989
John McCall129e2df2009-11-30 22:42:35 +00005990 TemplateArgumentListInfo TransArgs;
5991 if (Old->hasExplicitTemplateArgs()) {
5992 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5993 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5994 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5995 TemplateArgumentLoc Loc;
5996 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5997 Loc))
5998 return SemaRef.ExprError();
5999 TransArgs.addArgument(Loc);
6000 }
6001 }
John McCallc2233c52010-01-15 08:34:02 +00006002
6003 // FIXME: to do this check properly, we will need to preserve the
6004 // first-qualifier-in-scope here, just in case we had a dependent
6005 // base (and therefore couldn't do the check) and a
6006 // nested-name-qualifier (and therefore could do the lookup).
6007 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00006008
John McCall129e2df2009-11-30 22:42:35 +00006009 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00006010 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00006011 Old->getOperatorLoc(),
6012 Old->isArrow(),
6013 Qualifier,
6014 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006015 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006016 R,
6017 (Old->hasExplicitTemplateArgs()
6018 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006019}
6020
6021template<typename Derived>
6022Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006023TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006024 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006025}
6026
Mike Stump1eb44332009-09-09 15:08:12 +00006027template<typename Derived>
6028Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006029TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006030 TypeSourceInfo *EncodedTypeInfo
6031 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6032 if (!EncodedTypeInfo)
Douglas Gregorb98b1992009-08-11 05:31:07 +00006033 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006034
Douglas Gregorb98b1992009-08-11 05:31:07 +00006035 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006036 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump1eb44332009-09-09 15:08:12 +00006037 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006038
6039 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006040 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006041 E->getRParenLoc());
6042}
Mike Stump1eb44332009-09-09 15:08:12 +00006043
Douglas Gregorb98b1992009-08-11 05:31:07 +00006044template<typename Derived>
6045Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006046TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006047 // Transform arguments.
6048 bool ArgChanged = false;
6049 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
6050 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
6051 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
6052 if (Arg.isInvalid())
6053 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006054
Douglas Gregor92e986e2010-04-22 16:44:27 +00006055 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
6056 Args.push_back(Arg.takeAs<Expr>());
6057 }
6058
6059 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6060 // Class message: transform the receiver type.
6061 TypeSourceInfo *ReceiverTypeInfo
6062 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6063 if (!ReceiverTypeInfo)
6064 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006065
Douglas Gregor92e986e2010-04-22 16:44:27 +00006066 // If nothing changed, just retain the existing message send.
6067 if (!getDerived().AlwaysRebuild() &&
6068 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6069 return SemaRef.Owned(E->Retain());
6070
6071 // Build a new class message send.
6072 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6073 E->getSelector(),
6074 E->getMethodDecl(),
6075 E->getLeftLoc(),
6076 move_arg(Args),
6077 E->getRightLoc());
6078 }
6079
6080 // Instance message: transform the receiver
6081 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6082 "Only class and instance messages may be instantiated");
6083 OwningExprResult Receiver
6084 = getDerived().TransformExpr(E->getInstanceReceiver());
6085 if (Receiver.isInvalid())
6086 return SemaRef.ExprError();
6087
6088 // If nothing changed, just retain the existing message send.
6089 if (!getDerived().AlwaysRebuild() &&
6090 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6091 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006092
Douglas Gregor92e986e2010-04-22 16:44:27 +00006093 // Build a new instance message send.
6094 return getDerived().RebuildObjCMessageExpr(move(Receiver),
6095 E->getSelector(),
6096 E->getMethodDecl(),
6097 E->getLeftLoc(),
6098 move_arg(Args),
6099 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006100}
6101
Mike Stump1eb44332009-09-09 15:08:12 +00006102template<typename Derived>
6103Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006104TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006105 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006106}
6107
Mike Stump1eb44332009-09-09 15:08:12 +00006108template<typename Derived>
6109Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006110TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006111 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006112}
6113
Mike Stump1eb44332009-09-09 15:08:12 +00006114template<typename Derived>
6115Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006116TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006117 // Transform the base expression.
6118 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6119 if (Base.isInvalid())
6120 return SemaRef.ExprError();
6121
6122 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006123
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006124 // If nothing changed, just retain the existing expression.
6125 if (!getDerived().AlwaysRebuild() &&
6126 Base.get() == E->getBase())
6127 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006128
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006129 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6130 E->getLocation(),
6131 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006132}
6133
Mike Stump1eb44332009-09-09 15:08:12 +00006134template<typename Derived>
6135Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006136TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregore3303542010-04-26 20:47:02 +00006137 // Transform the base expression.
6138 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6139 if (Base.isInvalid())
6140 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006141
Douglas Gregore3303542010-04-26 20:47:02 +00006142 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006143
Douglas Gregore3303542010-04-26 20:47:02 +00006144 // If nothing changed, just retain the existing expression.
6145 if (!getDerived().AlwaysRebuild() &&
6146 Base.get() == E->getBase())
6147 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006148
Douglas Gregore3303542010-04-26 20:47:02 +00006149 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6150 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006151}
6152
Mike Stump1eb44332009-09-09 15:08:12 +00006153template<typename Derived>
6154Sema::OwningExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00006155TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00006156 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006157 // If this implicit setter/getter refers to class methods, it cannot have any
6158 // dependent parts. Just retain the existing declaration.
6159 if (E->getInterfaceDecl())
6160 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006161
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006162 // Transform the base expression.
6163 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6164 if (Base.isInvalid())
6165 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006166
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006167 // We don't need to transform the getters/setters; they will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006168
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006169 // If nothing changed, just retain the existing expression.
6170 if (!getDerived().AlwaysRebuild() &&
6171 Base.get() == E->getBase())
6172 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006173
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00006174 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6175 E->getGetterMethod(),
6176 E->getType(),
6177 E->getSetterMethod(),
6178 E->getLocation(),
6179 move(Base));
Sean Huntc3021132010-05-05 15:23:54 +00006180
Douglas Gregorb98b1992009-08-11 05:31:07 +00006181}
6182
Mike Stump1eb44332009-09-09 15:08:12 +00006183template<typename Derived>
6184Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006185TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregoref57c612010-04-22 17:28:13 +00006186 // Can never occur in a dependent context.
Mike Stump1eb44332009-09-09 15:08:12 +00006187 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006188}
6189
Mike Stump1eb44332009-09-09 15:08:12 +00006190template<typename Derived>
6191Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006192TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006193 // Transform the base expression.
6194 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6195 if (Base.isInvalid())
6196 return SemaRef.ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006197
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006198 // If nothing changed, just retain the existing expression.
6199 if (!getDerived().AlwaysRebuild() &&
6200 Base.get() == E->getBase())
6201 return SemaRef.Owned(E->Retain());
Sean Huntc3021132010-05-05 15:23:54 +00006202
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006203 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6204 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006205}
6206
Mike Stump1eb44332009-09-09 15:08:12 +00006207template<typename Derived>
6208Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006209TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006210 bool ArgumentChanged = false;
6211 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6212 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6213 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6214 if (SubExpr.isInvalid())
6215 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006216
Douglas Gregorb98b1992009-08-11 05:31:07 +00006217 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6218 SubExprs.push_back(SubExpr.takeAs<Expr>());
6219 }
Mike Stump1eb44332009-09-09 15:08:12 +00006220
Douglas Gregorb98b1992009-08-11 05:31:07 +00006221 if (!getDerived().AlwaysRebuild() &&
6222 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00006223 return SemaRef.Owned(E->Retain());
6224
Douglas Gregorb98b1992009-08-11 05:31:07 +00006225 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6226 move_arg(SubExprs),
6227 E->getRParenLoc());
6228}
6229
Mike Stump1eb44332009-09-09 15:08:12 +00006230template<typename Derived>
6231Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006232TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006233 SourceLocation CaretLoc(E->getExprLoc());
6234
6235 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6236 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6237 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6238 llvm::SmallVector<ParmVarDecl*, 4> Params;
6239 llvm::SmallVector<QualType, 4> ParamTypes;
6240
6241 // Parameter substitution.
6242 const BlockDecl *BD = E->getBlockDecl();
6243 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6244 EN = BD->param_end(); P != EN; ++P) {
6245 ParmVarDecl *OldParm = (*P);
6246 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6247 QualType NewType = NewParm->getType();
6248 Params.push_back(NewParm);
6249 ParamTypes.push_back(NewParm->getType());
6250 }
6251
6252 const FunctionType *BExprFunctionType = E->getFunctionType();
6253 QualType BExprResultType = BExprFunctionType->getResultType();
6254 if (!BExprResultType.isNull()) {
6255 if (!BExprResultType->isDependentType())
6256 CurBlock->ReturnType = BExprResultType;
6257 else if (BExprResultType != SemaRef.Context.DependentTy)
6258 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6259 }
6260
6261 // Transform the body
6262 OwningStmtResult Body = getDerived().TransformStmt(E->getBody());
6263 if (Body.isInvalid())
6264 return SemaRef.ExprError();
6265 // Set the parameters on the block decl.
6266 if (!Params.empty())
6267 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6268
6269 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6270 CurBlock->ReturnType,
6271 ParamTypes.data(),
6272 ParamTypes.size(),
6273 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006274 0,
6275 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006276
6277 CurBlock->FunctionType = FunctionType;
6278 return SemaRef.ActOnBlockStmtExpr(CaretLoc, move(Body), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006279}
6280
Mike Stump1eb44332009-09-09 15:08:12 +00006281template<typename Derived>
6282Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00006283TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006284 NestedNameSpecifier *Qualifier = 0;
6285
6286 ValueDecl *ND
6287 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6288 E->getDecl()));
6289 if (!ND)
6290 return SemaRef.ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00006291
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006292 if (!getDerived().AlwaysRebuild() &&
6293 ND == E->getDecl()) {
6294 // Mark it referenced in the new context regardless.
6295 // FIXME: this is a bit instantiation-specific.
6296 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6297
6298 return SemaRef.Owned(E->Retain());
6299 }
6300
Abramo Bagnara25777432010-08-11 22:01:17 +00006301 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006302 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006303 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006304}
Mike Stump1eb44332009-09-09 15:08:12 +00006305
Douglas Gregorb98b1992009-08-11 05:31:07 +00006306//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006307// Type reconstruction
6308//===----------------------------------------------------------------------===//
6309
Mike Stump1eb44332009-09-09 15:08:12 +00006310template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006311QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6312 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006313 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006314 getDerived().getBaseEntity());
6315}
6316
Mike Stump1eb44332009-09-09 15:08:12 +00006317template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006318QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6319 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006320 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006321 getDerived().getBaseEntity());
6322}
6323
Mike Stump1eb44332009-09-09 15:08:12 +00006324template<typename Derived>
6325QualType
John McCall85737a72009-10-30 00:06:24 +00006326TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6327 bool WrittenAsLValue,
6328 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006329 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00006330 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006331}
6332
6333template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006334QualType
John McCall85737a72009-10-30 00:06:24 +00006335TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6336 QualType ClassType,
6337 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006338 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00006339 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006340}
6341
6342template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006343QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006344TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6345 ArrayType::ArraySizeModifier SizeMod,
6346 const llvm::APInt *Size,
6347 Expr *SizeExpr,
6348 unsigned IndexTypeQuals,
6349 SourceRange BracketsRange) {
6350 if (SizeExpr || !Size)
6351 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6352 IndexTypeQuals, BracketsRange,
6353 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006354
6355 QualType Types[] = {
6356 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6357 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6358 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006359 };
6360 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6361 QualType SizeType;
6362 for (unsigned I = 0; I != NumTypes; ++I)
6363 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6364 SizeType = Types[I];
6365 break;
6366 }
Mike Stump1eb44332009-09-09 15:08:12 +00006367
Douglas Gregor577f75a2009-08-04 16:50:30 +00006368 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006369 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006370 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006371 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006372}
Mike Stump1eb44332009-09-09 15:08:12 +00006373
Douglas Gregor577f75a2009-08-04 16:50:30 +00006374template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006375QualType
6376TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006377 ArrayType::ArraySizeModifier SizeMod,
6378 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00006379 unsigned IndexTypeQuals,
6380 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006381 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00006382 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006383}
6384
6385template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006386QualType
Mike Stump1eb44332009-09-09 15:08:12 +00006387TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006388 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00006389 unsigned IndexTypeQuals,
6390 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006391 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00006392 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006393}
Mike Stump1eb44332009-09-09 15:08:12 +00006394
Douglas Gregor577f75a2009-08-04 16:50:30 +00006395template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006396QualType
6397TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006398 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006399 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006400 unsigned IndexTypeQuals,
6401 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006402 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006403 SizeExpr.takeAs<Expr>(),
6404 IndexTypeQuals, BracketsRange);
6405}
6406
6407template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006408QualType
6409TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006410 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006411 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006412 unsigned IndexTypeQuals,
6413 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006414 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006415 SizeExpr.takeAs<Expr>(),
6416 IndexTypeQuals, BracketsRange);
6417}
6418
6419template<typename Derived>
6420QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner788b0fd2010-06-23 06:00:24 +00006421 unsigned NumElements,
6422 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006423 // FIXME: semantic checking!
Chris Lattner788b0fd2010-06-23 06:00:24 +00006424 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006425}
Mike Stump1eb44332009-09-09 15:08:12 +00006426
Douglas Gregor577f75a2009-08-04 16:50:30 +00006427template<typename Derived>
6428QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6429 unsigned NumElements,
6430 SourceLocation AttributeLoc) {
6431 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6432 NumElements, true);
6433 IntegerLiteral *VectorSize
Mike Stump1eb44332009-09-09 15:08:12 +00006434 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006435 AttributeLoc);
6436 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6437 AttributeLoc);
6438}
Mike Stump1eb44332009-09-09 15:08:12 +00006439
Douglas Gregor577f75a2009-08-04 16:50:30 +00006440template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006441QualType
6442TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006443 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006444 SourceLocation AttributeLoc) {
6445 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6446}
Mike Stump1eb44332009-09-09 15:08:12 +00006447
Douglas Gregor577f75a2009-08-04 16:50:30 +00006448template<typename Derived>
6449QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00006450 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006451 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00006452 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00006453 unsigned Quals,
6454 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00006455 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006456 Quals,
6457 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006458 getDerived().getBaseEntity(),
6459 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006460}
Mike Stump1eb44332009-09-09 15:08:12 +00006461
Douglas Gregor577f75a2009-08-04 16:50:30 +00006462template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00006463QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6464 return SemaRef.Context.getFunctionNoProtoType(T);
6465}
6466
6467template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00006468QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6469 assert(D && "no decl found");
6470 if (D->isInvalidDecl()) return QualType();
6471
Douglas Gregor92e986e2010-04-22 16:44:27 +00006472 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00006473 TypeDecl *Ty;
6474 if (isa<UsingDecl>(D)) {
6475 UsingDecl *Using = cast<UsingDecl>(D);
6476 assert(Using->isTypeName() &&
6477 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6478
6479 // A valid resolved using typename decl points to exactly one type decl.
6480 assert(++Using->shadow_begin() == Using->shadow_end());
6481 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00006482
John McCalled976492009-12-04 22:46:56 +00006483 } else {
6484 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6485 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6486 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6487 }
6488
6489 return SemaRef.Context.getTypeDeclType(Ty);
6490}
6491
6492template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00006493QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006494 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6495}
6496
6497template<typename Derived>
6498QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6499 return SemaRef.Context.getTypeOfType(Underlying);
6500}
6501
6502template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00006503QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006504 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6505}
6506
6507template<typename Derived>
6508QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00006509 TemplateName Template,
6510 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00006511 const TemplateArgumentListInfo &TemplateArgs) {
6512 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006513}
Mike Stump1eb44332009-09-09 15:08:12 +00006514
Douglas Gregordcee1a12009-08-06 05:28:30 +00006515template<typename Derived>
6516NestedNameSpecifier *
6517TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6518 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00006519 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006520 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00006521 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00006522 CXXScopeSpec SS;
6523 // FIXME: The source location information is all wrong.
6524 SS.setRange(Range);
6525 SS.setScopeRep(Prefix);
6526 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00006527 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00006528 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006529 ObjectType,
6530 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00006531 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00006532}
6533
6534template<typename Derived>
6535NestedNameSpecifier *
6536TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6537 SourceRange Range,
6538 NamespaceDecl *NS) {
6539 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6540}
6541
6542template<typename Derived>
6543NestedNameSpecifier *
6544TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6545 SourceRange Range,
6546 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00006547 QualType T) {
6548 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00006549 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00006550 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00006551 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6552 T.getTypePtr());
6553 }
Mike Stump1eb44332009-09-09 15:08:12 +00006554
Douglas Gregordcee1a12009-08-06 05:28:30 +00006555 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6556 return 0;
6557}
Mike Stump1eb44332009-09-09 15:08:12 +00006558
Douglas Gregord1067e52009-08-06 06:41:21 +00006559template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006560TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006561TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6562 bool TemplateKW,
6563 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00006564 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00006565 Template);
6566}
6567
6568template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006569TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006570TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006571 const IdentifierInfo &II,
6572 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00006573 CXXScopeSpec SS;
6574 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump1eb44332009-09-09 15:08:12 +00006575 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00006576 UnqualifiedId Name;
6577 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00006578 Sema::TemplateTy Template;
6579 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6580 /*FIXME:*/getDerived().getBaseLocation(),
6581 SS,
6582 Name,
6583 ObjectType.getAsOpaquePtr(),
6584 /*EnteringContext=*/false,
6585 Template);
6586 return Template.template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00006587}
Mike Stump1eb44332009-09-09 15:08:12 +00006588
Douglas Gregorb98b1992009-08-11 05:31:07 +00006589template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006590TemplateName
6591TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6592 OverloadedOperatorKind Operator,
6593 QualType ObjectType) {
6594 CXXScopeSpec SS;
6595 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6596 SS.setScopeRep(Qualifier);
6597 UnqualifiedId Name;
6598 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6599 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6600 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00006601 Sema::TemplateTy Template;
6602 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006603 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006604 SS,
6605 Name,
6606 ObjectType.getAsOpaquePtr(),
6607 /*EnteringContext=*/false,
6608 Template);
6609 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006610}
Sean Huntc3021132010-05-05 15:23:54 +00006611
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006612template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006613Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006614TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6615 SourceLocation OpLoc,
6616 ExprArg Callee,
6617 ExprArg First,
6618 ExprArg Second) {
6619 Expr *FirstExpr = (Expr *)First.get();
6620 Expr *SecondExpr = (Expr *)Second.get();
John McCallba135432009-11-21 08:51:07 +00006621 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00006623
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00006625 if (Op == OO_Subscript) {
6626 if (!FirstExpr->getType()->isOverloadableType() &&
6627 !SecondExpr->getType()->isOverloadableType())
6628 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCallba135432009-11-21 08:51:07 +00006629 CalleeExpr->getLocStart(),
Sebastian Redlf322ed62009-10-29 20:17:01 +00006630 move(Second), OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00006631 } else if (Op == OO_Arrow) {
6632 // -> is never a builtin operation.
6633 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redlf322ed62009-10-29 20:17:01 +00006634 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 if (!FirstExpr->getType()->isOverloadableType()) {
6636 // The argument is not of overloadable type, so try to create a
6637 // built-in unary operation.
Mike Stump1eb44332009-09-09 15:08:12 +00006638 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006639 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00006640
Douglas Gregorb98b1992009-08-11 05:31:07 +00006641 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6642 }
6643 } else {
Mike Stump1eb44332009-09-09 15:08:12 +00006644 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006645 !SecondExpr->getType()->isOverloadableType()) {
6646 // Neither of the arguments is an overloadable type, so try to
6647 // create a built-in binary operation.
6648 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00006649 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006650 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6651 if (Result.isInvalid())
6652 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006653
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654 First.release();
6655 Second.release();
6656 return move(Result);
6657 }
6658 }
Mike Stump1eb44332009-09-09 15:08:12 +00006659
6660 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00006661 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00006662 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00006663
John McCallba135432009-11-21 08:51:07 +00006664 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6665 assert(ULE->requiresADL());
6666
6667 // FIXME: Do we have to check
6668 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00006669 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00006670 } else {
John McCall6e266892010-01-26 03:27:55 +00006671 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCallba135432009-11-21 08:51:07 +00006672 }
Mike Stump1eb44332009-09-09 15:08:12 +00006673
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674 // Add any functions found via argument-dependent lookup.
6675 Expr *Args[2] = { FirstExpr, SecondExpr };
6676 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00006677
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678 // Create the overloaded operator invocation for unary operators.
6679 if (NumArgs == 1 || isPostIncDec) {
Mike Stump1eb44332009-09-09 15:08:12 +00006680 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006681 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6682 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6683 }
Mike Stump1eb44332009-09-09 15:08:12 +00006684
Sebastian Redlf322ed62009-10-29 20:17:01 +00006685 if (Op == OO_Subscript)
John McCallba135432009-11-21 08:51:07 +00006686 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6687 OpLoc,
6688 move(First),
6689 move(Second));
Sebastian Redlf322ed62009-10-29 20:17:01 +00006690
Douglas Gregorb98b1992009-08-11 05:31:07 +00006691 // Create the overloaded operator invocation for binary operators.
Mike Stump1eb44332009-09-09 15:08:12 +00006692 BinaryOperator::Opcode Opc =
Douglas Gregorb98b1992009-08-11 05:31:07 +00006693 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00006694 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6696 if (Result.isInvalid())
6697 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006698
Douglas Gregorb98b1992009-08-11 05:31:07 +00006699 First.release();
6700 Second.release();
Mike Stump1eb44332009-09-09 15:08:12 +00006701 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006702}
Mike Stump1eb44332009-09-09 15:08:12 +00006703
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006704template<typename Derived>
Sean Huntc3021132010-05-05 15:23:54 +00006705Sema::OwningExprResult
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006706TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6707 SourceLocation OperatorLoc,
6708 bool isArrow,
6709 NestedNameSpecifier *Qualifier,
6710 SourceRange QualifierRange,
6711 TypeSourceInfo *ScopeType,
6712 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006713 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006714 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006715 CXXScopeSpec SS;
6716 if (Qualifier) {
6717 SS.setRange(QualifierRange);
6718 SS.setScopeRep(Qualifier);
6719 }
6720
6721 Expr *BaseE = (Expr *)Base.get();
6722 QualType BaseType = BaseE->getType();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006723 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006724 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00006725 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00006726 !BaseType->getAs<PointerType>()->getPointeeType()
6727 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006728 // This pseudo-destructor expression is still a pseudo-destructor.
6729 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6730 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006731 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006732 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006733 /*FIXME?*/true);
6734 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006735
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006736 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00006737 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6738 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6739 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6740 NameInfo.setNamedTypeInfo(DestroyedType);
6741
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006742 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00006743
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006744 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6745 OperatorLoc, isArrow,
6746 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00006747 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006748 /*TemplateArgs*/ 0);
6749}
6750
Douglas Gregor577f75a2009-08-04 16:50:30 +00006751} // end namespace clang
6752
6753#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H