blob: a86510055fed4b02918da148f99d905c98a3c2da [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
16#include "Sema.h"
John McCalle66edc12009-11-24 19:00:30 +000017#include "Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000020#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000021#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000023#include "clang/AST/Stmt.h"
24#include "clang/AST/StmtCXX.h"
25#include "clang/AST/StmtObjC.h"
John McCall550e0c22009-10-21 00:40:46 +000026#include "clang/AST/TypeLocBuilder.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000027#include "clang/Parse/Ownership.h"
28#include "clang/Parse/Designator.h"
29#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000030#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000031#include <algorithm>
32
33namespace clang {
Mike Stump11289f42009-09-09 15:08:12 +000034
Douglas Gregord6ff3322009-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 Stump11289f42009-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 Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +000048/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +000063/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000064/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-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 Gregorebe10102009-08-20 07:17:43 +000071/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000072/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000073/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +000081/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-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 Gregord6ff3322009-08-04 16:50:30 +000086template<typename Derived>
87class TreeTransform {
88protected:
89 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000090
91public:
Douglas Gregora16548e2009-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 Gregorebe10102009-08-20 07:17:43 +000097 typedef Sema::MultiStmtArg MultiStmtArg;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +000098 typedef Sema::DeclPtrTy DeclPtrTy;
99
Douglas Gregord6ff3322009-08-04 16:50:30 +0000100 /// \brief Initializes a new tree transformer.
101 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000102
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000107 const Derived &getDerived() const {
108 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000114
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000121
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000125 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 /// provide an alternative implementation that provides better location
127 /// information.
128 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000129
Douglas Gregord6ff3322009-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 Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +0000143
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregora16548e2009-08-11 05:31:07 +0000151 public:
152 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000153 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 OldLocation = Self.getDerived().getBaseLocation();
155 OldEntity = Self.getDerived().getBaseEntity();
156 Self.getDerived().setBase(Location, Entity);
157 }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregora16548e2009-08-11 05:31:07 +0000159 ~TemporaryBase() {
160 Self.getDerived().setBase(OldLocation, OldEntity);
161 }
162 };
Mike Stump11289f42009-09-09 15:08:12 +0000163
164 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000165 /// transformed.
166 ///
167 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000168 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-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 Gregord196a582009-12-14 19:27:10 +0000175 /// \brief Determine whether the given call argument should be dropped, e.g.,
176 /// because it is a default argument.
177 ///
178 /// Subclasses can provide an alternative implementation of this routine to
179 /// determine which kinds of call arguments get dropped. By default,
180 /// CXXDefaultArgument nodes are dropped (prior to transformation).
181 bool DropCallArgument(Expr *E) {
182 return E->isDefaultArgument();
183 }
184
Douglas Gregord6ff3322009-08-04 16:50:30 +0000185 /// \brief Transforms the given type into another type.
186 ///
John McCall550e0c22009-10-21 00:40:46 +0000187 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000188 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-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 McCallbcd03502009-12-07 02:54:59 +0000191 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000192 ///
193 /// \returns the transformed type.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000194 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000195
John McCall550e0c22009-10-21 00:40:46 +0000196 /// \brief Transforms the given type-with-location into a new
197 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000198 ///
John McCall550e0c22009-10-21 00:40:46 +0000199 /// By default, this routine transforms a type by delegating to the
200 /// appropriate TransformXXXType to build a new type. Subclasses
201 /// may override this function (to take over all type
202 /// transformations) or some set of the TransformXXXType functions
203 /// to alter the transformation.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
205 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000206
207 /// \brief Transform the given type-with-location into a new
208 /// type, collecting location information in the given builder
209 /// as necessary.
210 ///
Douglas Gregorfe17d252010-02-16 19:09:40 +0000211 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
212 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000213
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000214 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000215 ///
Mike Stump11289f42009-09-09 15:08:12 +0000216 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-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 Gregora16548e2009-08-11 05:31:07 +0000223 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000224
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000225 /// \brief Transform the given expression.
226 ///
Douglas Gregora16548e2009-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 McCall47f29ea2009-12-08 09:21:05 +0000233 OwningExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000234
Douglas Gregord6ff3322009-08-04 16:50:30 +0000235 /// \brief Transform the given declaration, which is referenced from a type
236 /// or expression.
237 ///
Douglas Gregor1135c352009-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 Gregora04f2ca2010-03-01 15:56:25 +0000240 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000241
242 /// \brief Transform the definition of the given declaration.
243 ///
Mike Stump11289f42009-09-09 15:08:12 +0000244 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000245 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000246 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
Douglas Gregor25289362010-03-01 17:25:41 +0000247 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000248 }
Mike Stump11289f42009-09-09 15:08:12 +0000249
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000250 /// \brief Transform the given declaration, which was the first part of a
251 /// nested-name-specifier in a member access expression.
252 ///
253 /// This specific declaration transformation only applies to the first
254 /// identifier in a nested-name-specifier of a member access expression, e.g.,
255 /// the \c T in \c x->T::member
256 ///
257 /// By default, invokes TransformDecl() to transform the declaration.
258 /// Subclasses may override this function to provide alternate behavior.
259 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000260 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000261 }
262
Douglas Gregord6ff3322009-08-04 16:50:30 +0000263 /// \brief Transform the given nested-name-specifier.
264 ///
Mike Stump11289f42009-09-09 15:08:12 +0000265 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000266 /// nested-name-specifier. Subclasses may override this function to provide
267 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000268 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000269 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000270 QualType ObjectType = QualType(),
271 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000272
Douglas Gregorf816bd72009-09-03 22:13:48 +0000273 /// \brief Transform the given declaration name.
274 ///
275 /// By default, transforms the types of conversion function, constructor,
276 /// and destructor names and then (if needed) rebuilds the declaration name.
277 /// Identifiers and selectors are returned unmodified. Sublcasses may
278 /// override this function to provide alternate behavior.
279 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +0000280 SourceLocation Loc,
281 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000284 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000285 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000286 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000287 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000288 TemplateName TransformTemplateName(TemplateName Name,
289 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000290
Douglas Gregord6ff3322009-08-04 16:50:30 +0000291 /// \brief Transform the given template argument.
292 ///
Mike Stump11289f42009-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 Gregore922c772009-08-04 22:27:00 +0000295 /// new template argument from the transformed result. Subclasses may
296 /// override this function to provide alternate behavior.
John McCall0ad16662009-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 McCallbcd03502009-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 McCall0ad16662009-10-29 08:12:44 +0000309 getDerived().getBaseLocation());
310 }
Mike Stump11289f42009-09-09 15:08:12 +0000311
John McCall550e0c22009-10-21 00:40:46 +0000312#define ABSTRACT_TYPELOC(CLASS, PARENT)
313#define TYPELOC(CLASS, PARENT) \
Douglas Gregorfe17d252010-02-16 19:09:40 +0000314 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
315 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000316#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000317
John McCall58f10c32010-03-11 09:03:00 +0000318 /// \brief Transforms the parameters of a function type into the
319 /// given vectors.
320 ///
321 /// The result vectors should be kept in sync; null entries in the
322 /// variables vector are acceptable.
323 ///
324 /// Return true on error.
325 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
326 llvm::SmallVectorImpl<QualType> &PTypes,
327 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
328
329 /// \brief Transforms a single function-type parameter. Return null
330 /// on error.
331 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
332
Douglas Gregorfe17d252010-02-16 19:09:40 +0000333 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
334 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000335
Douglas Gregorc59e5612009-10-19 22:04:39 +0000336 QualType
337 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
338 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000339
Douglas Gregorebe10102009-08-20 07:17:43 +0000340 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Zhongxing Xu105dfb52010-04-21 06:32:25 +0000341 OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000342
Douglas Gregorebe10102009-08-20 07:17:43 +0000343#define STMT(Node, Parent) \
344 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000345#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +0000346 OwningExprResult Transform##Node(Node *E);
Douglas Gregora16548e2009-08-11 05:31:07 +0000347#define ABSTRACT_EXPR(Node, Parent)
348#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000349
Douglas Gregord6ff3322009-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 McCall70dd5f62009-10-30 00:06:24 +0000354 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000355
356 /// \brief Build a new block pointer type given its pointee type.
357 ///
Mike Stump11289f42009-09-09 15:08:12 +0000358 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000359 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000360 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000361
John McCall70dd5f62009-10-30 00:06:24 +0000362 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000363 ///
John McCall70dd5f62009-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 Gregord6ff3322009-08-04 16:50:30 +0000367 ///
John McCall70dd5f62009-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 Stump11289f42009-09-09 15:08:12 +0000373
Douglas Gregord6ff3322009-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 McCall70dd5f62009-10-30 00:06:24 +0000379 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
380 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000381
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000388 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000395
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000401 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000402 ArrayType::ArraySizeModifier SizeMod,
403 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000404 unsigned IndexTypeQuals,
405 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000406
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000412 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000413 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000414 unsigned IndexTypeQuals,
415 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416
Mike Stump11289f42009-09-09 15:08:12 +0000417 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000422 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000424 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 unsigned IndexTypeQuals,
426 SourceRange BracketsRange);
427
Mike Stump11289f42009-09-09 15:08:12 +0000428 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000433 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000434 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000435 ExprArg SizeExpr,
Douglas Gregord6ff3322009-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 Thompson22334602010-02-05 00:12:22 +0000444 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
445 bool IsAltiVec, bool IsPixel);
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000454
455 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000460 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000461 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000463
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000469 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000470 unsigned NumParamTypes,
471 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000472
John McCall550e0c22009-10-21 00:40:46 +0000473 /// \brief Build a new unprototyped function type.
474 QualType RebuildFunctionNoProtoType(QualType ResultType);
475
John McCallb96ec562009-12-04 22:46:56 +0000476 /// \brief Rebuild an unresolved typename type, given the decl that
477 /// the UnresolvedUsingTypenameDecl was transformed to.
478 QualType RebuildUnresolvedUsingType(Decl *D);
479
Douglas Gregord6ff3322009-08-04 16:50:30 +0000480 /// \brief Build a new typedef type.
481 QualType RebuildTypedefType(TypedefDecl *Typedef) {
482 return SemaRef.Context.getTypeDeclType(Typedef);
483 }
484
485 /// \brief Build a new class/struct/union type.
486 QualType RebuildRecordType(RecordDecl *Record) {
487 return SemaRef.Context.getTypeDeclType(Record);
488 }
489
490 /// \brief Build a new Enum type.
491 QualType RebuildEnumType(EnumDecl *Enum) {
492 return SemaRef.Context.getTypeDeclType(Enum);
493 }
John McCallfcc33b02009-09-05 00:15:47 +0000494
495 /// \brief Build a new elaborated type.
496 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
497 return SemaRef.Context.getElaboratedType(T, Tag);
498 }
Mike Stump11289f42009-09-09 15:08:12 +0000499
500 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501 ///
502 /// By default, performs semantic analysis when building the typeof type.
503 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000504 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000505
Mike Stump11289f42009-09-09 15:08:12 +0000506 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000507 ///
508 /// By default, builds a new TypeOfType with the given underlying type.
509 QualType RebuildTypeOfType(QualType Underlying);
510
Mike Stump11289f42009-09-09 15:08:12 +0000511 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 ///
513 /// By default, performs semantic analysis when building the decltype type.
514 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000515 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000516
Douglas Gregord6ff3322009-08-04 16:50:30 +0000517 /// \brief Build a new template specialization type.
518 ///
519 /// By default, performs semantic analysis when building the template
520 /// specialization type. Subclasses may override this routine to provide
521 /// different behavior.
522 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000523 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000524 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000525
Douglas Gregord6ff3322009-08-04 16:50:30 +0000526 /// \brief Build a new qualified name type.
527 ///
Mike Stump11289f42009-09-09 15:08:12 +0000528 /// By default, builds a new QualifiedNameType type from the
529 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000530 /// this routine to provide different behavior.
531 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
532 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000533 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000534
535 /// \brief Build a new typename type that refers to a template-id.
536 ///
Douglas Gregore677daf2010-03-31 22:19:08 +0000537 /// By default, builds a new DependentNameType type from the
538 /// nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000539 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000540 /// different behavior.
Douglas Gregor02085352010-03-31 20:19:30 +0000541 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
542 NestedNameSpecifier *NNS, QualType T) {
Douglas Gregor04922cb2010-02-13 06:05:33 +0000543 if (NNS->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000544 // If the name is still dependent, just build a new dependent name type.
Douglas Gregor04922cb2010-02-13 06:05:33 +0000545 CXXScopeSpec SS;
546 SS.setScopeRep(NNS);
547 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor02085352010-03-31 20:19:30 +0000548 return SemaRef.Context.getDependentNameType(Keyword, NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000549 cast<TemplateSpecializationType>(T));
Douglas Gregor04922cb2010-02-13 06:05:33 +0000550 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000551
Douglas Gregor02085352010-03-31 20:19:30 +0000552 // FIXME: Handle elaborated-type-specifiers separately.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000553 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000554 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000555
556 /// \brief Build a new typename type that refers to an identifier.
557 ///
558 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000559 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 /// different behavior.
Douglas Gregor02085352010-03-31 20:19:30 +0000561 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
562 NestedNameSpecifier *NNS,
563 const IdentifierInfo *Id,
564 SourceRange SR) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000565 CXXScopeSpec SS;
566 SS.setScopeRep(NNS);
567
568 if (NNS->isDependent()) {
569 // If the name is still dependent, just build a new dependent name type.
570 if (!SemaRef.computeDeclContext(SS))
571 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
572 }
573
574 TagDecl::TagKind Kind = TagDecl::TK_enum;
575 switch (Keyword) {
576 case ETK_None:
577 // FIXME: Note the lack of the "typename" specifier!
578 // Fall through
579 case ETK_Typename:
580 return SemaRef.CheckTypenameType(NNS, *Id, SR);
581
582 case ETK_Class: Kind = TagDecl::TK_class; break;
583 case ETK_Struct: Kind = TagDecl::TK_struct; break;
584 case ETK_Union: Kind = TagDecl::TK_union; break;
585 case ETK_Enum: Kind = TagDecl::TK_enum; break;
586 }
587
588 // We had a dependent elaborated-type-specifier that as been transformed
589 // into a non-dependent elaborated-type-specifier. Find the tag we're
590 // referring to.
591 LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName);
592 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
593 if (!DC)
594 return QualType();
595
596 TagDecl *Tag = 0;
597 SemaRef.LookupQualifiedName(Result, DC);
598 switch (Result.getResultKind()) {
599 case LookupResult::NotFound:
600 case LookupResult::NotFoundInCurrentInstantiation:
601 break;
602
603 case LookupResult::Found:
604 Tag = Result.getAsSingle<TagDecl>();
605 break;
606
607 case LookupResult::FoundOverloaded:
608 case LookupResult::FoundUnresolvedValue:
609 llvm_unreachable("Tag lookup cannot find non-tags");
610 return QualType();
611
612 case LookupResult::Ambiguous:
613 // Let the LookupResult structure handle ambiguities.
614 return QualType();
615 }
616
617 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000618 // FIXME: Would be nice to highlight just the source range.
Douglas Gregore677daf2010-03-31 22:19:08 +0000619 SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000620 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000621 return QualType();
622 }
623
624 // FIXME: Terrible location information
625 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) {
626 SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id;
627 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
628 return QualType();
629 }
630
631 // Build the elaborated-type-specifier type.
632 QualType T = SemaRef.Context.getTypeDeclType(Tag);
633 T = SemaRef.Context.getQualifiedNameType(NNS, T);
634 return SemaRef.Context.getElaboratedType(T, Kind);
Douglas Gregor1135c352009-08-06 05:28:30 +0000635 }
Mike Stump11289f42009-09-09 15:08:12 +0000636
Douglas Gregor1135c352009-08-06 05:28:30 +0000637 /// \brief Build a new nested-name-specifier given the prefix and an
638 /// identifier that names the next step in the nested-name-specifier.
639 ///
640 /// By default, performs semantic analysis when building the new
641 /// nested-name-specifier. Subclasses may override this routine to provide
642 /// different behavior.
643 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
644 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000645 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000646 QualType ObjectType,
647 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000648
649 /// \brief Build a new nested-name-specifier given the prefix and the
650 /// namespace named in the next step in the nested-name-specifier.
651 ///
652 /// By default, performs semantic analysis when building the new
653 /// nested-name-specifier. Subclasses may override this routine to provide
654 /// different behavior.
655 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
656 SourceRange Range,
657 NamespaceDecl *NS);
658
659 /// \brief Build a new nested-name-specifier given the prefix and the
660 /// type named in the next step in the nested-name-specifier.
661 ///
662 /// By default, performs semantic analysis when building the new
663 /// nested-name-specifier. Subclasses may override this routine to provide
664 /// different behavior.
665 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
666 SourceRange Range,
667 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000668 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000669
670 /// \brief Build a new template name given a nested name specifier, a flag
671 /// indicating whether the "template" keyword was provided, and the template
672 /// that the template name refers to.
673 ///
674 /// By default, builds the new template name directly. Subclasses may override
675 /// this routine to provide different behavior.
676 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
677 bool TemplateKW,
678 TemplateDecl *Template);
679
Douglas Gregor71dc5092009-08-06 06:41:21 +0000680 /// \brief Build a new template name given a nested name specifier and the
681 /// name that is referred to as a template.
682 ///
683 /// By default, performs semantic analysis to determine whether the name can
684 /// be resolved to a specific template, then builds the appropriate kind of
685 /// template name. Subclasses may override this routine to provide different
686 /// behavior.
687 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000688 const IdentifierInfo &II,
689 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000690
Douglas Gregor71395fa2009-11-04 00:56:37 +0000691 /// \brief Build a new template name given a nested name specifier and the
692 /// overloaded operator name that is referred to as a template.
693 ///
694 /// By default, performs semantic analysis to determine whether the name can
695 /// be resolved to a specific template, then builds the appropriate kind of
696 /// template name. Subclasses may override this routine to provide different
697 /// behavior.
698 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
699 OverloadedOperatorKind Operator,
700 QualType ObjectType);
701
Douglas Gregorebe10102009-08-20 07:17:43 +0000702 /// \brief Build a new compound statement.
703 ///
704 /// By default, performs semantic analysis to build the new statement.
705 /// Subclasses may override this routine to provide different behavior.
706 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
707 MultiStmtArg Statements,
708 SourceLocation RBraceLoc,
709 bool IsStmtExpr) {
710 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
711 IsStmtExpr);
712 }
713
714 /// \brief Build a new case statement.
715 ///
716 /// By default, performs semantic analysis to build the new statement.
717 /// Subclasses may override this routine to provide different behavior.
718 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
719 ExprArg LHS,
720 SourceLocation EllipsisLoc,
721 ExprArg RHS,
722 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000723 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000724 ColonLoc);
725 }
Mike Stump11289f42009-09-09 15:08:12 +0000726
Douglas Gregorebe10102009-08-20 07:17:43 +0000727 /// \brief Attach the body to a new case statement.
728 ///
729 /// By default, performs semantic analysis to build the new statement.
730 /// Subclasses may override this routine to provide different behavior.
731 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
732 getSema().ActOnCaseStmtBody(S.get(), move(Body));
733 return move(S);
734 }
Mike Stump11289f42009-09-09 15:08:12 +0000735
Douglas Gregorebe10102009-08-20 07:17:43 +0000736 /// \brief Build a new default statement.
737 ///
738 /// By default, performs semantic analysis to build the new statement.
739 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000740 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000741 SourceLocation ColonLoc,
742 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000743 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000744 /*CurScope=*/0);
745 }
Mike Stump11289f42009-09-09 15:08:12 +0000746
Douglas Gregorebe10102009-08-20 07:17:43 +0000747 /// \brief Build a new label statement.
748 ///
749 /// By default, performs semantic analysis to build the new statement.
750 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000751 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000752 IdentifierInfo *Id,
753 SourceLocation ColonLoc,
754 StmtArg SubStmt) {
755 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
756 }
Mike Stump11289f42009-09-09 15:08:12 +0000757
Douglas Gregorebe10102009-08-20 07:17:43 +0000758 /// \brief Build a new "if" statement.
759 ///
760 /// By default, performs semantic analysis to build the new statement.
761 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000762 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000763 VarDecl *CondVar, StmtArg Then,
764 SourceLocation ElseLoc, StmtArg Else) {
765 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
766 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000767 }
Mike Stump11289f42009-09-09 15:08:12 +0000768
Douglas Gregorebe10102009-08-20 07:17:43 +0000769 /// \brief Start building a new switch statement.
770 ///
771 /// By default, performs semantic analysis to build the new statement.
772 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000773 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
774 VarDecl *CondVar) {
775 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000776 }
Mike Stump11289f42009-09-09 15:08:12 +0000777
Douglas Gregorebe10102009-08-20 07:17:43 +0000778 /// \brief Attach the body to the switch statement.
779 ///
780 /// By default, performs semantic analysis to build the new statement.
781 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000782 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000783 StmtArg Switch, StmtArg Body) {
784 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
785 move(Body));
786 }
787
788 /// \brief Build a new while statement.
789 ///
790 /// By default, performs semantic analysis to build the new statement.
791 /// Subclasses may override this routine to provide different behavior.
792 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
793 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000794 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000795 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000796 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
797 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000798 }
Mike Stump11289f42009-09-09 15:08:12 +0000799
Douglas Gregorebe10102009-08-20 07:17:43 +0000800 /// \brief Build a new do-while statement.
801 ///
802 /// By default, performs semantic analysis to build the new statement.
803 /// Subclasses may override this routine to provide different behavior.
804 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
805 SourceLocation WhileLoc,
806 SourceLocation LParenLoc,
807 ExprArg Cond,
808 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000809 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000810 move(Cond), RParenLoc);
811 }
812
813 /// \brief Build a new for statement.
814 ///
815 /// By default, performs semantic analysis to build the new statement.
816 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000817 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000818 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000819 StmtArg Init, Sema::FullExprArg Cond,
820 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000821 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000822 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
823 DeclPtrTy::make(CondVar),
824 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000825 }
Mike Stump11289f42009-09-09 15:08:12 +0000826
Douglas Gregorebe10102009-08-20 07:17:43 +0000827 /// \brief Build a new goto statement.
828 ///
829 /// By default, performs semantic analysis to build the new statement.
830 /// Subclasses may override this routine to provide different behavior.
831 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
832 SourceLocation LabelLoc,
833 LabelStmt *Label) {
834 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
835 }
836
837 /// \brief Build a new indirect goto statement.
838 ///
839 /// By default, performs semantic analysis to build the new statement.
840 /// Subclasses may override this routine to provide different behavior.
841 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
842 SourceLocation StarLoc,
843 ExprArg Target) {
844 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
845 }
Mike Stump11289f42009-09-09 15:08:12 +0000846
Douglas Gregorebe10102009-08-20 07:17:43 +0000847 /// \brief Build a new return statement.
848 ///
849 /// By default, performs semantic analysis to build the new statement.
850 /// Subclasses may override this routine to provide different behavior.
851 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
852 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000853
Douglas Gregorebe10102009-08-20 07:17:43 +0000854 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
855 }
Mike Stump11289f42009-09-09 15:08:12 +0000856
Douglas Gregorebe10102009-08-20 07:17:43 +0000857 /// \brief Build a new declaration statement.
858 ///
859 /// By default, performs semantic analysis to build the new statement.
860 /// Subclasses may override this routine to provide different behavior.
861 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000862 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000863 SourceLocation EndLoc) {
864 return getSema().Owned(
865 new (getSema().Context) DeclStmt(
866 DeclGroupRef::Create(getSema().Context,
867 Decls, NumDecls),
868 StartLoc, EndLoc));
869 }
Mike Stump11289f42009-09-09 15:08:12 +0000870
Anders Carlssonaaeef072010-01-24 05:50:09 +0000871 /// \brief Build a new inline asm statement.
872 ///
873 /// By default, performs semantic analysis to build the new statement.
874 /// Subclasses may override this routine to provide different behavior.
875 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
876 bool IsSimple,
877 bool IsVolatile,
878 unsigned NumOutputs,
879 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000880 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000881 MultiExprArg Constraints,
882 MultiExprArg Exprs,
883 ExprArg AsmString,
884 MultiExprArg Clobbers,
885 SourceLocation RParenLoc,
886 bool MSAsm) {
887 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
888 NumInputs, Names, move(Constraints),
889 move(Exprs), move(AsmString), move(Clobbers),
890 RParenLoc, MSAsm);
891 }
892
Douglas Gregorebe10102009-08-20 07:17:43 +0000893 /// \brief Build a new C++ exception declaration.
894 ///
895 /// By default, performs semantic analysis to build the new decaration.
896 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000897 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000898 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000899 IdentifierInfo *Name,
900 SourceLocation Loc,
901 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000902 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000903 TypeRange);
904 }
905
906 /// \brief Build a new C++ catch statement.
907 ///
908 /// By default, performs semantic analysis to build the new statement.
909 /// Subclasses may override this routine to provide different behavior.
910 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
911 VarDecl *ExceptionDecl,
912 StmtArg Handler) {
913 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000914 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000915 Handler.takeAs<Stmt>()));
916 }
Mike Stump11289f42009-09-09 15:08:12 +0000917
Douglas Gregorebe10102009-08-20 07:17:43 +0000918 /// \brief Build a new C++ try statement.
919 ///
920 /// By default, performs semantic analysis to build the new statement.
921 /// Subclasses may override this routine to provide different behavior.
922 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
923 StmtArg TryBlock,
924 MultiStmtArg Handlers) {
925 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
926 }
Mike Stump11289f42009-09-09 15:08:12 +0000927
Douglas Gregora16548e2009-08-11 05:31:07 +0000928 /// \brief Build a new expression that references a declaration.
929 ///
930 /// By default, performs semantic analysis to build the new expression.
931 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +0000932 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
933 LookupResult &R,
934 bool RequiresADL) {
935 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
936 }
937
938
939 /// \brief Build a new expression that references a declaration.
940 ///
941 /// By default, performs semantic analysis to build the new expression.
942 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000943 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
944 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +0000945 ValueDecl *VD, SourceLocation Loc,
946 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000947 CXXScopeSpec SS;
948 SS.setScopeRep(Qualifier);
949 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +0000950
951 // FIXME: loses template args.
952
953 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +0000954 }
Mike Stump11289f42009-09-09 15:08:12 +0000955
Douglas Gregora16548e2009-08-11 05:31:07 +0000956 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000957 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000958 /// By default, performs semantic analysis to build the new expression.
959 /// Subclasses may override this routine to provide different behavior.
960 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
961 SourceLocation RParen) {
962 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
963 }
964
Douglas Gregorad8a3362009-09-04 17:36:40 +0000965 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000966 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000967 /// By default, performs semantic analysis to build the new expression.
968 /// Subclasses may override this routine to provide different behavior.
969 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
970 SourceLocation OperatorLoc,
971 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +0000972 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +0000973 SourceRange QualifierRange,
974 TypeSourceInfo *ScopeType,
975 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +0000976 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +0000977 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +0000978
Douglas Gregora16548e2009-08-11 05:31:07 +0000979 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000980 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000981 /// By default, performs semantic analysis to build the new expression.
982 /// Subclasses may override this routine to provide different behavior.
983 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
984 UnaryOperator::Opcode Opc,
985 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000986 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +0000987 }
Mike Stump11289f42009-09-09 15:08:12 +0000988
Douglas Gregora16548e2009-08-11 05:31:07 +0000989 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000990 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000991 /// By default, performs semantic analysis to build the new expression.
992 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +0000993 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +0000994 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000995 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +0000996 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +0000997 }
998
Mike Stump11289f42009-09-09 15:08:12 +0000999 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001000 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001001 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001002 /// By default, performs semantic analysis to build the new expression.
1003 /// Subclasses may override this routine to provide different behavior.
1004 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1005 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +00001006 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001007 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1008 OpLoc, isSizeOf, R);
1009 if (Result.isInvalid())
1010 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001011
Douglas Gregora16548e2009-08-11 05:31:07 +00001012 SubExpr.release();
1013 return move(Result);
1014 }
Mike Stump11289f42009-09-09 15:08:12 +00001015
Douglas Gregora16548e2009-08-11 05:31:07 +00001016 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001017 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001018 /// By default, performs semantic analysis to build the new expression.
1019 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001020 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001021 SourceLocation LBracketLoc,
1022 ExprArg RHS,
1023 SourceLocation RBracketLoc) {
1024 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +00001025 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +00001026 RBracketLoc);
1027 }
1028
1029 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001030 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001031 /// By default, performs semantic analysis to build the new expression.
1032 /// Subclasses may override this routine to provide different behavior.
1033 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1034 MultiExprArg Args,
1035 SourceLocation *CommaLocs,
1036 SourceLocation RParenLoc) {
1037 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1038 move(Args), CommaLocs, RParenLoc);
1039 }
1040
1041 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001042 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001043 /// By default, performs semantic analysis to build the new expression.
1044 /// Subclasses may override this routine to provide different behavior.
1045 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001046 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001047 NestedNameSpecifier *Qualifier,
1048 SourceRange QualifierRange,
1049 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001050 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001051 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001052 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001053 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001054 if (!Member->getDeclName()) {
1055 // We have a reference to an unnamed field.
1056 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001057
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001058 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +00001059 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1060 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001061 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001062
Mike Stump11289f42009-09-09 15:08:12 +00001063 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001064 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +00001065 Member, MemberLoc,
1066 cast<FieldDecl>(Member)->getType());
1067 return getSema().Owned(ME);
1068 }
Mike Stump11289f42009-09-09 15:08:12 +00001069
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001070 CXXScopeSpec SS;
1071 if (Qualifier) {
1072 SS.setRange(QualifierRange);
1073 SS.setScopeRep(Qualifier);
1074 }
1075
John McCall2d74de92009-12-01 22:10:20 +00001076 QualType BaseType = ((Expr*) Base.get())->getType();
1077
John McCall16df1e52010-03-30 21:47:33 +00001078 // FIXME: this involves duplicating earlier analysis in a lot of
1079 // cases; we should avoid this when possible.
John McCall38836f02010-01-15 08:34:02 +00001080 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1081 Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001082 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001083 R.resolveKind();
1084
John McCall2d74de92009-12-01 22:10:20 +00001085 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1086 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001087 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001088 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001089 }
Mike Stump11289f42009-09-09 15:08:12 +00001090
Douglas Gregora16548e2009-08-11 05:31:07 +00001091 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001092 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001093 /// By default, performs semantic analysis to build the new expression.
1094 /// Subclasses may override this routine to provide different behavior.
1095 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1096 BinaryOperator::Opcode Opc,
1097 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001098 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1099 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001100 }
1101
1102 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001103 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001104 /// By default, performs semantic analysis to build the new expression.
1105 /// Subclasses may override this routine to provide different behavior.
1106 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1107 SourceLocation QuestionLoc,
1108 ExprArg LHS,
1109 SourceLocation ColonLoc,
1110 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001111 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001112 move(LHS), move(RHS));
1113 }
1114
Douglas Gregora16548e2009-08-11 05:31:07 +00001115 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001116 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001117 /// By default, performs semantic analysis to build the new expression.
1118 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001119 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1120 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001121 SourceLocation RParenLoc,
1122 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001123 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1124 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001125 }
Mike Stump11289f42009-09-09 15:08:12 +00001126
Douglas Gregora16548e2009-08-11 05:31:07 +00001127 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001128 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001129 /// By default, performs semantic analysis to build the new expression.
1130 /// Subclasses may override this routine to provide different behavior.
1131 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001132 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001133 SourceLocation RParenLoc,
1134 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001135 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1136 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001137 }
Mike Stump11289f42009-09-09 15:08:12 +00001138
Douglas Gregora16548e2009-08-11 05:31:07 +00001139 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001140 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001141 /// By default, performs semantic analysis to build the new expression.
1142 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001143 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001144 SourceLocation OpLoc,
1145 SourceLocation AccessorLoc,
1146 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001147
John McCall10eae182009-11-30 22:42:35 +00001148 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001149 QualType BaseType = ((Expr*) Base.get())->getType();
1150 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001151 OpLoc, /*IsArrow*/ false,
1152 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001153 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001154 AccessorLoc,
1155 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001156 }
Mike Stump11289f42009-09-09 15:08:12 +00001157
Douglas Gregora16548e2009-08-11 05:31:07 +00001158 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001159 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001160 /// By default, performs semantic analysis to build the new expression.
1161 /// Subclasses may override this routine to provide different behavior.
1162 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1163 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001164 SourceLocation RBraceLoc,
1165 QualType ResultTy) {
1166 OwningExprResult Result
1167 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1168 if (Result.isInvalid() || ResultTy->isDependentType())
1169 return move(Result);
1170
1171 // Patch in the result type we were given, which may have been computed
1172 // when the initial InitListExpr was built.
1173 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1174 ILE->setType(ResultTy);
1175 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001176 }
Mike Stump11289f42009-09-09 15:08:12 +00001177
Douglas Gregora16548e2009-08-11 05:31:07 +00001178 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001179 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001180 /// By default, performs semantic analysis to build the new expression.
1181 /// Subclasses may override this routine to provide different behavior.
1182 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1183 MultiExprArg ArrayExprs,
1184 SourceLocation EqualOrColonLoc,
1185 bool GNUSyntax,
1186 ExprArg Init) {
1187 OwningExprResult Result
1188 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1189 move(Init));
1190 if (Result.isInvalid())
1191 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001192
Douglas Gregora16548e2009-08-11 05:31:07 +00001193 ArrayExprs.release();
1194 return move(Result);
1195 }
Mike Stump11289f42009-09-09 15:08:12 +00001196
Douglas Gregora16548e2009-08-11 05:31:07 +00001197 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001198 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001199 /// By default, builds the implicit value initialization without performing
1200 /// any semantic analysis. Subclasses may override this routine to provide
1201 /// different behavior.
1202 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1203 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1204 }
Mike Stump11289f42009-09-09 15:08:12 +00001205
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001207 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001208 /// By default, performs semantic analysis to build the new expression.
1209 /// Subclasses may override this routine to provide different behavior.
1210 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1211 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001212 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001213 RParenLoc);
1214 }
1215
1216 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001217 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001218 /// By default, performs semantic analysis to build the new expression.
1219 /// Subclasses may override this routine to provide different behavior.
1220 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1221 MultiExprArg SubExprs,
1222 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001223 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1224 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001225 }
Mike Stump11289f42009-09-09 15:08:12 +00001226
Douglas Gregora16548e2009-08-11 05:31:07 +00001227 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001228 ///
1229 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001230 /// rather than attempting to map the label statement itself.
1231 /// Subclasses may override this routine to provide different behavior.
1232 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1233 SourceLocation LabelLoc,
1234 LabelStmt *Label) {
1235 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1236 }
Mike Stump11289f42009-09-09 15:08:12 +00001237
Douglas Gregora16548e2009-08-11 05:31:07 +00001238 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001239 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001240 /// By default, performs semantic analysis to build the new expression.
1241 /// Subclasses may override this routine to provide different behavior.
1242 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1243 StmtArg SubStmt,
1244 SourceLocation RParenLoc) {
1245 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1246 }
Mike Stump11289f42009-09-09 15:08:12 +00001247
Douglas Gregora16548e2009-08-11 05:31:07 +00001248 /// \brief Build a new __builtin_types_compatible_p expression.
1249 ///
1250 /// By default, performs semantic analysis to build the new expression.
1251 /// Subclasses may override this routine to provide different behavior.
1252 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1253 QualType T1, QualType T2,
1254 SourceLocation RParenLoc) {
1255 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1256 T1.getAsOpaquePtr(),
1257 T2.getAsOpaquePtr(),
1258 RParenLoc);
1259 }
Mike Stump11289f42009-09-09 15:08:12 +00001260
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 /// \brief Build a new __builtin_choose_expr expression.
1262 ///
1263 /// By default, performs semantic analysis to build the new expression.
1264 /// Subclasses may override this routine to provide different behavior.
1265 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1266 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1267 SourceLocation RParenLoc) {
1268 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1269 move(Cond), move(LHS), move(RHS),
1270 RParenLoc);
1271 }
Mike Stump11289f42009-09-09 15:08:12 +00001272
Douglas Gregora16548e2009-08-11 05:31:07 +00001273 /// \brief Build a new overloaded operator call expression.
1274 ///
1275 /// By default, performs semantic analysis to build the new expression.
1276 /// The semantic analysis provides the behavior of template instantiation,
1277 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001278 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001279 /// argument-dependent lookup, etc. Subclasses may override this routine to
1280 /// provide different behavior.
1281 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1282 SourceLocation OpLoc,
1283 ExprArg Callee,
1284 ExprArg First,
1285 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001286
1287 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001288 /// reinterpret_cast.
1289 ///
1290 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001291 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001292 /// Subclasses may override this routine to provide different behavior.
1293 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1294 Stmt::StmtClass Class,
1295 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001296 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001297 SourceLocation RAngleLoc,
1298 SourceLocation LParenLoc,
1299 ExprArg SubExpr,
1300 SourceLocation RParenLoc) {
1301 switch (Class) {
1302 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001303 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001304 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001305 move(SubExpr), RParenLoc);
1306
1307 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001308 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001309 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001310 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001311
Douglas Gregora16548e2009-08-11 05:31:07 +00001312 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001313 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001314 RAngleLoc, LParenLoc,
1315 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001316 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001317
Douglas Gregora16548e2009-08-11 05:31:07 +00001318 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001319 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001320 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001322
Douglas Gregora16548e2009-08-11 05:31:07 +00001323 default:
1324 assert(false && "Invalid C++ named cast");
1325 break;
1326 }
Mike Stump11289f42009-09-09 15:08:12 +00001327
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 return getSema().ExprError();
1329 }
Mike Stump11289f42009-09-09 15:08:12 +00001330
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 /// \brief Build a new C++ static_cast expression.
1332 ///
1333 /// By default, performs semantic analysis to build the new expression.
1334 /// Subclasses may override this routine to provide different behavior.
1335 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1336 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001337 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 SourceLocation RAngleLoc,
1339 SourceLocation LParenLoc,
1340 ExprArg SubExpr,
1341 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001342 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1343 TInfo, move(SubExpr),
1344 SourceRange(LAngleLoc, RAngleLoc),
1345 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001346 }
1347
1348 /// \brief Build a new C++ dynamic_cast expression.
1349 ///
1350 /// By default, performs semantic analysis to build the new expression.
1351 /// Subclasses may override this routine to provide different behavior.
1352 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1353 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001354 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 SourceLocation RAngleLoc,
1356 SourceLocation LParenLoc,
1357 ExprArg SubExpr,
1358 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001359 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1360 TInfo, move(SubExpr),
1361 SourceRange(LAngleLoc, RAngleLoc),
1362 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001363 }
1364
1365 /// \brief Build a new C++ reinterpret_cast expression.
1366 ///
1367 /// By default, performs semantic analysis to build the new expression.
1368 /// Subclasses may override this routine to provide different behavior.
1369 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1370 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001371 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001372 SourceLocation RAngleLoc,
1373 SourceLocation LParenLoc,
1374 ExprArg SubExpr,
1375 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001376 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1377 TInfo, move(SubExpr),
1378 SourceRange(LAngleLoc, RAngleLoc),
1379 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001380 }
1381
1382 /// \brief Build a new C++ const_cast expression.
1383 ///
1384 /// By default, performs semantic analysis to build the new expression.
1385 /// Subclasses may override this routine to provide different behavior.
1386 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1387 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001388 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001389 SourceLocation RAngleLoc,
1390 SourceLocation LParenLoc,
1391 ExprArg SubExpr,
1392 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001393 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1394 TInfo, move(SubExpr),
1395 SourceRange(LAngleLoc, RAngleLoc),
1396 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001397 }
Mike Stump11289f42009-09-09 15:08:12 +00001398
Douglas Gregora16548e2009-08-11 05:31:07 +00001399 /// \brief Build a new C++ functional-style cast expression.
1400 ///
1401 /// By default, performs semantic analysis to build the new expression.
1402 /// Subclasses may override this routine to provide different behavior.
1403 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001404 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001405 SourceLocation LParenLoc,
1406 ExprArg SubExpr,
1407 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001408 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001410 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001411 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001412 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001413 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001414 RParenLoc);
1415 }
Mike Stump11289f42009-09-09 15:08:12 +00001416
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 /// \brief Build a new C++ typeid(type) expression.
1418 ///
1419 /// By default, performs semantic analysis to build the new expression.
1420 /// Subclasses may override this routine to provide different behavior.
1421 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1422 SourceLocation LParenLoc,
1423 QualType T,
1424 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001425 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 T.getAsOpaquePtr(), RParenLoc);
1427 }
Mike Stump11289f42009-09-09 15:08:12 +00001428
Douglas Gregora16548e2009-08-11 05:31:07 +00001429 /// \brief Build a new C++ typeid(expr) expression.
1430 ///
1431 /// By default, performs semantic analysis to build the new expression.
1432 /// Subclasses may override this routine to provide different behavior.
1433 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1434 SourceLocation LParenLoc,
1435 ExprArg Operand,
1436 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001437 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001438 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1439 RParenLoc);
1440 if (Result.isInvalid())
1441 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001442
Douglas Gregora16548e2009-08-11 05:31:07 +00001443 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1444 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001445 }
1446
Douglas Gregora16548e2009-08-11 05:31:07 +00001447 /// \brief Build a new C++ "this" expression.
1448 ///
1449 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001450 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001451 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001452 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001453 QualType ThisType,
1454 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001455 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001456 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1457 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001458 }
1459
1460 /// \brief Build a new C++ throw expression.
1461 ///
1462 /// By default, performs semantic analysis to build the new expression.
1463 /// Subclasses may override this routine to provide different behavior.
1464 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1465 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1466 }
1467
1468 /// \brief Build a new C++ default-argument expression.
1469 ///
1470 /// By default, builds a new default-argument expression, which does not
1471 /// require any semantic analysis. Subclasses may override this routine to
1472 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001473 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1474 ParmVarDecl *Param) {
1475 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1476 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001477 }
1478
1479 /// \brief Build a new C++ zero-initialization expression.
1480 ///
1481 /// By default, performs semantic analysis to build the new expression.
1482 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001483 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001484 SourceLocation LParenLoc,
1485 QualType T,
1486 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001487 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1488 T.getAsOpaquePtr(), LParenLoc,
1489 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001490 0, RParenLoc);
1491 }
Mike Stump11289f42009-09-09 15:08:12 +00001492
Douglas Gregora16548e2009-08-11 05:31:07 +00001493 /// \brief Build a new C++ "new" expression.
1494 ///
1495 /// By default, performs semantic analysis to build the new expression.
1496 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001497 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001498 bool UseGlobal,
1499 SourceLocation PlacementLParen,
1500 MultiExprArg PlacementArgs,
1501 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001502 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001503 QualType AllocType,
1504 SourceLocation TypeLoc,
1505 SourceRange TypeRange,
1506 ExprArg ArraySize,
1507 SourceLocation ConstructorLParen,
1508 MultiExprArg ConstructorArgs,
1509 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001510 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 PlacementLParen,
1512 move(PlacementArgs),
1513 PlacementRParen,
1514 ParenTypeId,
1515 AllocType,
1516 TypeLoc,
1517 TypeRange,
1518 move(ArraySize),
1519 ConstructorLParen,
1520 move(ConstructorArgs),
1521 ConstructorRParen);
1522 }
Mike Stump11289f42009-09-09 15:08:12 +00001523
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 /// \brief Build a new C++ "delete" expression.
1525 ///
1526 /// By default, performs semantic analysis to build the new expression.
1527 /// Subclasses may override this routine to provide different behavior.
1528 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1529 bool IsGlobalDelete,
1530 bool IsArrayForm,
1531 ExprArg Operand) {
1532 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1533 move(Operand));
1534 }
Mike Stump11289f42009-09-09 15:08:12 +00001535
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 /// \brief Build a new unary type trait expression.
1537 ///
1538 /// By default, performs semantic analysis to build the new expression.
1539 /// Subclasses may override this routine to provide different behavior.
1540 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1541 SourceLocation StartLoc,
1542 SourceLocation LParenLoc,
1543 QualType T,
1544 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001545 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001546 T.getAsOpaquePtr(), RParenLoc);
1547 }
1548
Mike Stump11289f42009-09-09 15:08:12 +00001549 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001550 /// expression.
1551 ///
1552 /// By default, performs semantic analysis to build the new expression.
1553 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001554 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001555 SourceRange QualifierRange,
1556 DeclarationName Name,
1557 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001558 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 CXXScopeSpec SS;
1560 SS.setRange(QualifierRange);
1561 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001562
1563 if (TemplateArgs)
1564 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1565 *TemplateArgs);
1566
1567 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 }
1569
1570 /// \brief Build a new template-id expression.
1571 ///
1572 /// By default, performs semantic analysis to build the new expression.
1573 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001574 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1575 LookupResult &R,
1576 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001577 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001578 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001579 }
1580
1581 /// \brief Build a new object-construction expression.
1582 ///
1583 /// By default, performs semantic analysis to build the new expression.
1584 /// Subclasses may override this routine to provide different behavior.
1585 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001586 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 CXXConstructorDecl *Constructor,
1588 bool IsElidable,
1589 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001590 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1591 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1592 ConvertedArgs))
1593 return getSema().ExprError();
1594
1595 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1596 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001597 }
1598
1599 /// \brief Build a new object-construction expression.
1600 ///
1601 /// By default, performs semantic analysis to build the new expression.
1602 /// Subclasses may override this routine to provide different behavior.
1603 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1604 QualType T,
1605 SourceLocation LParenLoc,
1606 MultiExprArg Args,
1607 SourceLocation *Commas,
1608 SourceLocation RParenLoc) {
1609 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1610 T.getAsOpaquePtr(),
1611 LParenLoc,
1612 move(Args),
1613 Commas,
1614 RParenLoc);
1615 }
1616
1617 /// \brief Build a new object-construction expression.
1618 ///
1619 /// By default, performs semantic analysis to build the new expression.
1620 /// Subclasses may override this routine to provide different behavior.
1621 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1622 QualType T,
1623 SourceLocation LParenLoc,
1624 MultiExprArg Args,
1625 SourceLocation *Commas,
1626 SourceLocation RParenLoc) {
1627 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1628 /*FIXME*/LParenLoc),
1629 T.getAsOpaquePtr(),
1630 LParenLoc,
1631 move(Args),
1632 Commas,
1633 RParenLoc);
1634 }
Mike Stump11289f42009-09-09 15:08:12 +00001635
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 /// \brief Build a new member reference expression.
1637 ///
1638 /// By default, performs semantic analysis to build the new expression.
1639 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001640 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001641 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 bool IsArrow,
1643 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001644 NestedNameSpecifier *Qualifier,
1645 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001646 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001648 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001649 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001651 SS.setRange(QualifierRange);
1652 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001653
John McCall2d74de92009-12-01 22:10:20 +00001654 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1655 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001656 SS, FirstQualifierInScope,
1657 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 }
1659
John McCall10eae182009-11-30 22:42:35 +00001660 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001661 ///
1662 /// By default, performs semantic analysis to build the new expression.
1663 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001664 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001665 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001666 SourceLocation OperatorLoc,
1667 bool IsArrow,
1668 NestedNameSpecifier *Qualifier,
1669 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001670 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001671 LookupResult &R,
1672 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001673 CXXScopeSpec SS;
1674 SS.setRange(QualifierRange);
1675 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001676
John McCall2d74de92009-12-01 22:10:20 +00001677 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1678 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001679 SS, FirstQualifierInScope,
1680 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001681 }
Mike Stump11289f42009-09-09 15:08:12 +00001682
Douglas Gregora16548e2009-08-11 05:31:07 +00001683 /// \brief Build a new Objective-C @encode expression.
1684 ///
1685 /// By default, performs semantic analysis to build the new expression.
1686 /// Subclasses may override this routine to provide different behavior.
1687 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001688 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001689 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001690 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001692 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001693
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001694 /// \brief Build a new Objective-C class message.
1695 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1696 Selector Sel,
1697 ObjCMethodDecl *Method,
1698 SourceLocation LBracLoc,
1699 MultiExprArg Args,
1700 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001701 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1702 ReceiverTypeInfo->getType(),
1703 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001704 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001705 move(Args));
1706 }
1707
1708 /// \brief Build a new Objective-C instance message.
1709 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1710 Selector Sel,
1711 ObjCMethodDecl *Method,
1712 SourceLocation LBracLoc,
1713 MultiExprArg Args,
1714 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001715 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1716 return SemaRef.BuildInstanceMessage(move(Receiver),
1717 ReceiverType,
1718 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001719 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001720 move(Args));
1721 }
1722
Douglas Gregora16548e2009-08-11 05:31:07 +00001723 /// \brief Build a new shuffle vector expression.
1724 ///
1725 /// By default, performs semantic analysis to build the new expression.
1726 /// Subclasses may override this routine to provide different behavior.
1727 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1728 MultiExprArg SubExprs,
1729 SourceLocation RParenLoc) {
1730 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001731 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1733 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1734 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1735 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001736
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 // Build a reference to the __builtin_shufflevector builtin
1738 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001739 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001740 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001741 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001742 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001743
1744 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001745 unsigned NumSubExprs = SubExprs.size();
1746 Expr **Subs = (Expr **)SubExprs.release();
1747 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1748 Subs, NumSubExprs,
1749 Builtin->getResultType(),
1750 RParenLoc);
1751 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001752
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 // Type-check the __builtin_shufflevector expression.
1754 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1755 if (Result.isInvalid())
1756 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001757
Douglas Gregora16548e2009-08-11 05:31:07 +00001758 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001759 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001760 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001761};
Douglas Gregora16548e2009-08-11 05:31:07 +00001762
Douglas Gregorebe10102009-08-20 07:17:43 +00001763template<typename Derived>
1764Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1765 if (!S)
1766 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001767
Douglas Gregorebe10102009-08-20 07:17:43 +00001768 switch (S->getStmtClass()) {
1769 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001770
Douglas Gregorebe10102009-08-20 07:17:43 +00001771 // Transform individual statement nodes
1772#define STMT(Node, Parent) \
1773 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1774#define EXPR(Node, Parent)
1775#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001776
Douglas Gregorebe10102009-08-20 07:17:43 +00001777 // Transform expressions by calling TransformExpr.
1778#define STMT(Node, Parent)
John McCall2adddca2010-02-03 00:55:45 +00001779#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorebe10102009-08-20 07:17:43 +00001780#define EXPR(Node, Parent) case Stmt::Node##Class:
1781#include "clang/AST/StmtNodes.def"
1782 {
1783 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1784 if (E.isInvalid())
1785 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001786
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001787 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001788 }
Mike Stump11289f42009-09-09 15:08:12 +00001789 }
1790
Douglas Gregorebe10102009-08-20 07:17:43 +00001791 return SemaRef.Owned(S->Retain());
1792}
Mike Stump11289f42009-09-09 15:08:12 +00001793
1794
Douglas Gregore922c772009-08-04 22:27:00 +00001795template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001796Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001797 if (!E)
1798 return SemaRef.Owned(E);
1799
1800 switch (E->getStmtClass()) {
1801 case Stmt::NoStmtClass: break;
1802#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall2adddca2010-02-03 00:55:45 +00001803#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregora16548e2009-08-11 05:31:07 +00001804#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001805 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001806#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001807 }
1808
Douglas Gregora16548e2009-08-11 05:31:07 +00001809 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001810}
1811
1812template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001813NestedNameSpecifier *
1814TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001815 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001816 QualType ObjectType,
1817 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001818 if (!NNS)
1819 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001820
Douglas Gregorebe10102009-08-20 07:17:43 +00001821 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001822 NestedNameSpecifier *Prefix = NNS->getPrefix();
1823 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001824 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001825 ObjectType,
1826 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001827 if (!Prefix)
1828 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001829
1830 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001831 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001832 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001833 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001834 }
Mike Stump11289f42009-09-09 15:08:12 +00001835
Douglas Gregor1135c352009-08-06 05:28:30 +00001836 switch (NNS->getKind()) {
1837 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001838 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001839 "Identifier nested-name-specifier with no prefix or object type");
1840 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1841 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001842 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001843
1844 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001845 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001846 ObjectType,
1847 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001848
Douglas Gregor1135c352009-08-06 05:28:30 +00001849 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001850 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001851 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001852 getDerived().TransformDecl(Range.getBegin(),
1853 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001854 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001855 Prefix == NNS->getPrefix() &&
1856 NS == NNS->getAsNamespace())
1857 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001858
Douglas Gregor1135c352009-08-06 05:28:30 +00001859 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1860 }
Mike Stump11289f42009-09-09 15:08:12 +00001861
Douglas Gregor1135c352009-08-06 05:28:30 +00001862 case NestedNameSpecifier::Global:
1863 // There is no meaningful transformation that one could perform on the
1864 // global scope.
1865 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001866
Douglas Gregor1135c352009-08-06 05:28:30 +00001867 case NestedNameSpecifier::TypeSpecWithTemplate:
1868 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001869 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00001870 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
1871 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001872 if (T.isNull())
1873 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001874
Douglas Gregor1135c352009-08-06 05:28:30 +00001875 if (!getDerived().AlwaysRebuild() &&
1876 Prefix == NNS->getPrefix() &&
1877 T == QualType(NNS->getAsType(), 0))
1878 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001879
1880 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1881 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00001882 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001883 }
1884 }
Mike Stump11289f42009-09-09 15:08:12 +00001885
Douglas Gregor1135c352009-08-06 05:28:30 +00001886 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001887 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001888}
1889
1890template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001891DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001892TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001893 SourceLocation Loc,
1894 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001895 if (!Name)
1896 return Name;
1897
1898 switch (Name.getNameKind()) {
1899 case DeclarationName::Identifier:
1900 case DeclarationName::ObjCZeroArgSelector:
1901 case DeclarationName::ObjCOneArgSelector:
1902 case DeclarationName::ObjCMultiArgSelector:
1903 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001904 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001905 case DeclarationName::CXXUsingDirective:
1906 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001907
Douglas Gregorf816bd72009-09-03 22:13:48 +00001908 case DeclarationName::CXXConstructorName:
1909 case DeclarationName::CXXDestructorName:
1910 case DeclarationName::CXXConversionFunctionName: {
1911 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorfe17d252010-02-16 19:09:40 +00001912 QualType T = getDerived().TransformType(Name.getCXXNameType(),
1913 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00001914 if (T.isNull())
1915 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001916
Douglas Gregorf816bd72009-09-03 22:13:48 +00001917 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001918 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001919 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001920 }
Mike Stump11289f42009-09-09 15:08:12 +00001921 }
1922
Douglas Gregorf816bd72009-09-03 22:13:48 +00001923 return DeclarationName();
1924}
1925
1926template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001927TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001928TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1929 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001930 SourceLocation Loc = getDerived().getBaseLocation();
1931
Douglas Gregor71dc5092009-08-06 06:41:21 +00001932 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001933 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001934 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001935 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1936 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001937 if (!NNS)
1938 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001939
Douglas Gregor71dc5092009-08-06 06:41:21 +00001940 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001941 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001942 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001943 if (!TransTemplate)
1944 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001945
Douglas Gregor71dc5092009-08-06 06:41:21 +00001946 if (!getDerived().AlwaysRebuild() &&
1947 NNS == QTN->getQualifier() &&
1948 TransTemplate == Template)
1949 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001950
Douglas Gregor71dc5092009-08-06 06:41:21 +00001951 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1952 TransTemplate);
1953 }
Mike Stump11289f42009-09-09 15:08:12 +00001954
John McCalle66edc12009-11-24 19:00:30 +00001955 // These should be getting filtered out before they make it into the AST.
1956 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001957 }
Mike Stump11289f42009-09-09 15:08:12 +00001958
Douglas Gregor71dc5092009-08-06 06:41:21 +00001959 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001960 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001961 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001962 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1963 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00001964 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001965 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001966
Douglas Gregor71dc5092009-08-06 06:41:21 +00001967 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001968 NNS == DTN->getQualifier() &&
1969 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001970 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001971
Douglas Gregor71395fa2009-11-04 00:56:37 +00001972 if (DTN->isIdentifier())
1973 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1974 ObjectType);
1975
1976 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1977 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001978 }
Mike Stump11289f42009-09-09 15:08:12 +00001979
Douglas Gregor71dc5092009-08-06 06:41:21 +00001980 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001981 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001982 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001983 if (!TransTemplate)
1984 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001985
Douglas Gregor71dc5092009-08-06 06:41:21 +00001986 if (!getDerived().AlwaysRebuild() &&
1987 TransTemplate == Template)
1988 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001989
Douglas Gregor71dc5092009-08-06 06:41:21 +00001990 return TemplateName(TransTemplate);
1991 }
Mike Stump11289f42009-09-09 15:08:12 +00001992
John McCalle66edc12009-11-24 19:00:30 +00001993 // These should be getting filtered out before they reach the AST.
1994 assert(false && "overloaded function decl survived to here");
1995 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00001996}
1997
1998template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001999void TreeTransform<Derived>::InventTemplateArgumentLoc(
2000 const TemplateArgument &Arg,
2001 TemplateArgumentLoc &Output) {
2002 SourceLocation Loc = getDerived().getBaseLocation();
2003 switch (Arg.getKind()) {
2004 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002005 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002006 break;
2007
2008 case TemplateArgument::Type:
2009 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002010 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00002011
2012 break;
2013
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002014 case TemplateArgument::Template:
2015 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2016 break;
2017
John McCall0ad16662009-10-29 08:12:44 +00002018 case TemplateArgument::Expression:
2019 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2020 break;
2021
2022 case TemplateArgument::Declaration:
2023 case TemplateArgument::Integral:
2024 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002025 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002026 break;
2027 }
2028}
2029
2030template<typename Derived>
2031bool TreeTransform<Derived>::TransformTemplateArgument(
2032 const TemplateArgumentLoc &Input,
2033 TemplateArgumentLoc &Output) {
2034 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002035 switch (Arg.getKind()) {
2036 case TemplateArgument::Null:
2037 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002038 Output = Input;
2039 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002040
Douglas Gregore922c772009-08-04 22:27:00 +00002041 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002042 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002043 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002044 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002045
2046 DI = getDerived().TransformType(DI);
2047 if (!DI) return true;
2048
2049 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2050 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002051 }
Mike Stump11289f42009-09-09 15:08:12 +00002052
Douglas Gregore922c772009-08-04 22:27:00 +00002053 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002054 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002055 DeclarationName Name;
2056 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2057 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002058 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002059 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002060 if (!D) return true;
2061
John McCall0d07eb32009-10-29 18:45:58 +00002062 Expr *SourceExpr = Input.getSourceDeclExpression();
2063 if (SourceExpr) {
2064 EnterExpressionEvaluationContext Unevaluated(getSema(),
2065 Action::Unevaluated);
2066 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2067 if (E.isInvalid())
2068 SourceExpr = NULL;
2069 else {
2070 SourceExpr = E.takeAs<Expr>();
2071 SourceExpr->Retain();
2072 }
2073 }
2074
2075 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002076 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002077 }
Mike Stump11289f42009-09-09 15:08:12 +00002078
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002079 case TemplateArgument::Template: {
2080 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
2081 TemplateName Template
2082 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2083 if (Template.isNull())
2084 return true;
2085
2086 Output = TemplateArgumentLoc(TemplateArgument(Template),
2087 Input.getTemplateQualifierRange(),
2088 Input.getTemplateNameLoc());
2089 return false;
2090 }
2091
Douglas Gregore922c772009-08-04 22:27:00 +00002092 case TemplateArgument::Expression: {
2093 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002094 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002095 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002096
John McCall0ad16662009-10-29 08:12:44 +00002097 Expr *InputExpr = Input.getSourceExpression();
2098 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2099
2100 Sema::OwningExprResult E
2101 = getDerived().TransformExpr(InputExpr);
2102 if (E.isInvalid()) return true;
2103
2104 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002105 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002106 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2107 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002108 }
Mike Stump11289f42009-09-09 15:08:12 +00002109
Douglas Gregore922c772009-08-04 22:27:00 +00002110 case TemplateArgument::Pack: {
2111 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2112 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002113 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002114 AEnd = Arg.pack_end();
2115 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002116
John McCall0ad16662009-10-29 08:12:44 +00002117 // FIXME: preserve source information here when we start
2118 // caring about parameter packs.
2119
John McCall0d07eb32009-10-29 18:45:58 +00002120 TemplateArgumentLoc InputArg;
2121 TemplateArgumentLoc OutputArg;
2122 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2123 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002124 return true;
2125
John McCall0d07eb32009-10-29 18:45:58 +00002126 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002127 }
2128 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002129 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002130 true);
John McCall0d07eb32009-10-29 18:45:58 +00002131 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002132 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002133 }
2134 }
Mike Stump11289f42009-09-09 15:08:12 +00002135
Douglas Gregore922c772009-08-04 22:27:00 +00002136 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002137 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002138}
2139
Douglas Gregord6ff3322009-08-04 16:50:30 +00002140//===----------------------------------------------------------------------===//
2141// Type transformation
2142//===----------------------------------------------------------------------===//
2143
2144template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002145QualType TreeTransform<Derived>::TransformType(QualType T,
2146 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002147 if (getDerived().AlreadyTransformed(T))
2148 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002149
John McCall550e0c22009-10-21 00:40:46 +00002150 // Temporary workaround. All of these transformations should
2151 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002152 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002153 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002154
Douglas Gregorfe17d252010-02-16 19:09:40 +00002155 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002156
John McCall550e0c22009-10-21 00:40:46 +00002157 if (!NewDI)
2158 return QualType();
2159
2160 return NewDI->getType();
2161}
2162
2163template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002164TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2165 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002166 if (getDerived().AlreadyTransformed(DI->getType()))
2167 return DI;
2168
2169 TypeLocBuilder TLB;
2170
2171 TypeLoc TL = DI->getTypeLoc();
2172 TLB.reserve(TL.getFullDataSize());
2173
Douglas Gregorfe17d252010-02-16 19:09:40 +00002174 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002175 if (Result.isNull())
2176 return 0;
2177
John McCallbcd03502009-12-07 02:54:59 +00002178 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002179}
2180
2181template<typename Derived>
2182QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002183TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2184 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002185 switch (T.getTypeLocClass()) {
2186#define ABSTRACT_TYPELOC(CLASS, PARENT)
2187#define TYPELOC(CLASS, PARENT) \
2188 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002189 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2190 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002191#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002192 }
Mike Stump11289f42009-09-09 15:08:12 +00002193
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002194 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002195 return QualType();
2196}
2197
2198/// FIXME: By default, this routine adds type qualifiers only to types
2199/// that can have qualifiers, and silently suppresses those qualifiers
2200/// that are not permitted (e.g., qualifiers on reference or function
2201/// types). This is the right thing for template instantiation, but
2202/// probably not for other clients.
2203template<typename Derived>
2204QualType
2205TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002206 QualifiedTypeLoc T,
2207 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002208 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002209
Douglas Gregorfe17d252010-02-16 19:09:40 +00002210 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2211 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002212 if (Result.isNull())
2213 return QualType();
2214
2215 // Silently suppress qualifiers if the result type can't be qualified.
2216 // FIXME: this is the right thing for template instantiation, but
2217 // probably not for other clients.
2218 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002219 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002220
John McCall550e0c22009-10-21 00:40:46 +00002221 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2222
2223 TLB.push<QualifiedTypeLoc>(Result);
2224
2225 // No location information to preserve.
2226
2227 return Result;
2228}
2229
2230template <class TyLoc> static inline
2231QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2232 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2233 NewT.setNameLoc(T.getNameLoc());
2234 return T.getType();
2235}
2236
John McCall550e0c22009-10-21 00:40:46 +00002237template<typename Derived>
2238QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002239 BuiltinTypeLoc T,
2240 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002241 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2242 NewT.setBuiltinLoc(T.getBuiltinLoc());
2243 if (T.needsExtraLocalData())
2244 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2245 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002246}
Mike Stump11289f42009-09-09 15:08:12 +00002247
Douglas Gregord6ff3322009-08-04 16:50:30 +00002248template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002249QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002250 ComplexTypeLoc T,
2251 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002252 // FIXME: recurse?
2253 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002254}
Mike Stump11289f42009-09-09 15:08:12 +00002255
Douglas Gregord6ff3322009-08-04 16:50:30 +00002256template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002257QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002258 PointerTypeLoc TL,
2259 QualType ObjectType) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002260 QualType PointeeType
2261 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2262 if (PointeeType.isNull())
2263 return QualType();
2264
2265 QualType Result = TL.getType();
2266 if (PointeeType->isObjCInterfaceType()) {
2267 // A dependent pointer type 'T *' has is being transformed such
2268 // that an Objective-C class type is being replaced for 'T'. The
2269 // resulting pointer type is an ObjCObjectPointerType, not a
2270 // PointerType.
2271 const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>();
2272 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType,
2273 const_cast<ObjCProtocolDecl **>(
2274 IFace->qual_begin()),
2275 IFace->getNumProtocols());
2276
2277 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2278 NewT.setStarLoc(TL.getSigilLoc());
2279 NewT.setHasProtocolsAsWritten(false);
2280 NewT.setLAngleLoc(SourceLocation());
2281 NewT.setRAngleLoc(SourceLocation());
2282 NewT.setHasBaseTypeAsWritten(true);
2283 return Result;
2284 }
2285
2286 if (getDerived().AlwaysRebuild() ||
2287 PointeeType != TL.getPointeeLoc().getType()) {
2288 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2289 if (Result.isNull())
2290 return QualType();
2291 }
2292
2293 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2294 NewT.setSigilLoc(TL.getSigilLoc());
2295 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002296}
Mike Stump11289f42009-09-09 15:08:12 +00002297
2298template<typename Derived>
2299QualType
John McCall550e0c22009-10-21 00:40:46 +00002300TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002301 BlockPointerTypeLoc TL,
2302 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002303 QualType PointeeType
2304 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2305 if (PointeeType.isNull())
2306 return QualType();
2307
2308 QualType Result = TL.getType();
2309 if (getDerived().AlwaysRebuild() ||
2310 PointeeType != TL.getPointeeLoc().getType()) {
2311 Result = getDerived().RebuildBlockPointerType(PointeeType,
2312 TL.getSigilLoc());
2313 if (Result.isNull())
2314 return QualType();
2315 }
2316
Douglas Gregor049211a2010-04-22 16:50:51 +00002317 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002318 NewT.setSigilLoc(TL.getSigilLoc());
2319 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002320}
2321
John McCall70dd5f62009-10-30 00:06:24 +00002322/// Transforms a reference type. Note that somewhat paradoxically we
2323/// don't care whether the type itself is an l-value type or an r-value
2324/// type; we only care if the type was *written* as an l-value type
2325/// or an r-value type.
2326template<typename Derived>
2327QualType
2328TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002329 ReferenceTypeLoc TL,
2330 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002331 const ReferenceType *T = TL.getTypePtr();
2332
2333 // Note that this works with the pointee-as-written.
2334 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2335 if (PointeeType.isNull())
2336 return QualType();
2337
2338 QualType Result = TL.getType();
2339 if (getDerived().AlwaysRebuild() ||
2340 PointeeType != T->getPointeeTypeAsWritten()) {
2341 Result = getDerived().RebuildReferenceType(PointeeType,
2342 T->isSpelledAsLValue(),
2343 TL.getSigilLoc());
2344 if (Result.isNull())
2345 return QualType();
2346 }
2347
2348 // r-value references can be rebuilt as l-value references.
2349 ReferenceTypeLoc NewTL;
2350 if (isa<LValueReferenceType>(Result))
2351 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2352 else
2353 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2354 NewTL.setSigilLoc(TL.getSigilLoc());
2355
2356 return Result;
2357}
2358
Mike Stump11289f42009-09-09 15:08:12 +00002359template<typename Derived>
2360QualType
John McCall550e0c22009-10-21 00:40:46 +00002361TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002362 LValueReferenceTypeLoc TL,
2363 QualType ObjectType) {
2364 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002365}
2366
Mike Stump11289f42009-09-09 15:08:12 +00002367template<typename Derived>
2368QualType
John McCall550e0c22009-10-21 00:40:46 +00002369TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002370 RValueReferenceTypeLoc TL,
2371 QualType ObjectType) {
2372 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002373}
Mike Stump11289f42009-09-09 15:08:12 +00002374
Douglas Gregord6ff3322009-08-04 16:50:30 +00002375template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002376QualType
John McCall550e0c22009-10-21 00:40:46 +00002377TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002378 MemberPointerTypeLoc TL,
2379 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002380 MemberPointerType *T = TL.getTypePtr();
2381
2382 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002383 if (PointeeType.isNull())
2384 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002385
John McCall550e0c22009-10-21 00:40:46 +00002386 // TODO: preserve source information for this.
2387 QualType ClassType
2388 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002389 if (ClassType.isNull())
2390 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002391
John McCall550e0c22009-10-21 00:40:46 +00002392 QualType Result = TL.getType();
2393 if (getDerived().AlwaysRebuild() ||
2394 PointeeType != T->getPointeeType() ||
2395 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002396 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2397 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002398 if (Result.isNull())
2399 return QualType();
2400 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002401
John McCall550e0c22009-10-21 00:40:46 +00002402 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2403 NewTL.setSigilLoc(TL.getSigilLoc());
2404
2405 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002406}
2407
Mike Stump11289f42009-09-09 15:08:12 +00002408template<typename Derived>
2409QualType
John McCall550e0c22009-10-21 00:40:46 +00002410TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002411 ConstantArrayTypeLoc TL,
2412 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002413 ConstantArrayType *T = TL.getTypePtr();
2414 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002415 if (ElementType.isNull())
2416 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002417
John McCall550e0c22009-10-21 00:40:46 +00002418 QualType Result = TL.getType();
2419 if (getDerived().AlwaysRebuild() ||
2420 ElementType != T->getElementType()) {
2421 Result = getDerived().RebuildConstantArrayType(ElementType,
2422 T->getSizeModifier(),
2423 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002424 T->getIndexTypeCVRQualifiers(),
2425 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002426 if (Result.isNull())
2427 return QualType();
2428 }
2429
2430 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2431 NewTL.setLBracketLoc(TL.getLBracketLoc());
2432 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002433
John McCall550e0c22009-10-21 00:40:46 +00002434 Expr *Size = TL.getSizeExpr();
2435 if (Size) {
2436 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2437 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2438 }
2439 NewTL.setSizeExpr(Size);
2440
2441 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002442}
Mike Stump11289f42009-09-09 15:08:12 +00002443
Douglas Gregord6ff3322009-08-04 16:50:30 +00002444template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002445QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002446 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002447 IncompleteArrayTypeLoc TL,
2448 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002449 IncompleteArrayType *T = TL.getTypePtr();
2450 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002451 if (ElementType.isNull())
2452 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002453
John McCall550e0c22009-10-21 00:40:46 +00002454 QualType Result = TL.getType();
2455 if (getDerived().AlwaysRebuild() ||
2456 ElementType != T->getElementType()) {
2457 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002458 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002459 T->getIndexTypeCVRQualifiers(),
2460 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002461 if (Result.isNull())
2462 return QualType();
2463 }
2464
2465 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2466 NewTL.setLBracketLoc(TL.getLBracketLoc());
2467 NewTL.setRBracketLoc(TL.getRBracketLoc());
2468 NewTL.setSizeExpr(0);
2469
2470 return Result;
2471}
2472
2473template<typename Derived>
2474QualType
2475TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002476 VariableArrayTypeLoc TL,
2477 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002478 VariableArrayType *T = TL.getTypePtr();
2479 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2480 if (ElementType.isNull())
2481 return QualType();
2482
2483 // Array bounds are not potentially evaluated contexts
2484 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2485
2486 Sema::OwningExprResult SizeResult
2487 = getDerived().TransformExpr(T->getSizeExpr());
2488 if (SizeResult.isInvalid())
2489 return QualType();
2490
2491 Expr *Size = static_cast<Expr*>(SizeResult.get());
2492
2493 QualType Result = TL.getType();
2494 if (getDerived().AlwaysRebuild() ||
2495 ElementType != T->getElementType() ||
2496 Size != T->getSizeExpr()) {
2497 Result = getDerived().RebuildVariableArrayType(ElementType,
2498 T->getSizeModifier(),
2499 move(SizeResult),
2500 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002501 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002502 if (Result.isNull())
2503 return QualType();
2504 }
2505 else SizeResult.take();
2506
2507 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2508 NewTL.setLBracketLoc(TL.getLBracketLoc());
2509 NewTL.setRBracketLoc(TL.getRBracketLoc());
2510 NewTL.setSizeExpr(Size);
2511
2512 return Result;
2513}
2514
2515template<typename Derived>
2516QualType
2517TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002518 DependentSizedArrayTypeLoc TL,
2519 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002520 DependentSizedArrayType *T = TL.getTypePtr();
2521 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2522 if (ElementType.isNull())
2523 return QualType();
2524
2525 // Array bounds are not potentially evaluated contexts
2526 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2527
2528 Sema::OwningExprResult SizeResult
2529 = getDerived().TransformExpr(T->getSizeExpr());
2530 if (SizeResult.isInvalid())
2531 return QualType();
2532
2533 Expr *Size = static_cast<Expr*>(SizeResult.get());
2534
2535 QualType Result = TL.getType();
2536 if (getDerived().AlwaysRebuild() ||
2537 ElementType != T->getElementType() ||
2538 Size != T->getSizeExpr()) {
2539 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2540 T->getSizeModifier(),
2541 move(SizeResult),
2542 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002543 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002544 if (Result.isNull())
2545 return QualType();
2546 }
2547 else SizeResult.take();
2548
2549 // We might have any sort of array type now, but fortunately they
2550 // all have the same location layout.
2551 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2552 NewTL.setLBracketLoc(TL.getLBracketLoc());
2553 NewTL.setRBracketLoc(TL.getRBracketLoc());
2554 NewTL.setSizeExpr(Size);
2555
2556 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002557}
Mike Stump11289f42009-09-09 15:08:12 +00002558
2559template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002560QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002561 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002562 DependentSizedExtVectorTypeLoc TL,
2563 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002564 DependentSizedExtVectorType *T = TL.getTypePtr();
2565
2566 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002567 QualType ElementType = getDerived().TransformType(T->getElementType());
2568 if (ElementType.isNull())
2569 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002570
Douglas Gregore922c772009-08-04 22:27:00 +00002571 // Vector sizes are not potentially evaluated contexts
2572 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2573
Douglas Gregord6ff3322009-08-04 16:50:30 +00002574 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2575 if (Size.isInvalid())
2576 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002577
John McCall550e0c22009-10-21 00:40:46 +00002578 QualType Result = TL.getType();
2579 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002580 ElementType != T->getElementType() ||
2581 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002582 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002583 move(Size),
2584 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002585 if (Result.isNull())
2586 return QualType();
2587 }
2588 else Size.take();
2589
2590 // Result might be dependent or not.
2591 if (isa<DependentSizedExtVectorType>(Result)) {
2592 DependentSizedExtVectorTypeLoc NewTL
2593 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2594 NewTL.setNameLoc(TL.getNameLoc());
2595 } else {
2596 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2597 NewTL.setNameLoc(TL.getNameLoc());
2598 }
2599
2600 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002601}
Mike Stump11289f42009-09-09 15:08:12 +00002602
2603template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002604QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002605 VectorTypeLoc TL,
2606 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002607 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002608 QualType ElementType = getDerived().TransformType(T->getElementType());
2609 if (ElementType.isNull())
2610 return QualType();
2611
John McCall550e0c22009-10-21 00:40:46 +00002612 QualType Result = TL.getType();
2613 if (getDerived().AlwaysRebuild() ||
2614 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002615 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2616 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002617 if (Result.isNull())
2618 return QualType();
2619 }
2620
2621 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2622 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002623
John McCall550e0c22009-10-21 00:40:46 +00002624 return Result;
2625}
2626
2627template<typename Derived>
2628QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002629 ExtVectorTypeLoc TL,
2630 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002631 VectorType *T = TL.getTypePtr();
2632 QualType ElementType = getDerived().TransformType(T->getElementType());
2633 if (ElementType.isNull())
2634 return QualType();
2635
2636 QualType Result = TL.getType();
2637 if (getDerived().AlwaysRebuild() ||
2638 ElementType != T->getElementType()) {
2639 Result = getDerived().RebuildExtVectorType(ElementType,
2640 T->getNumElements(),
2641 /*FIXME*/ SourceLocation());
2642 if (Result.isNull())
2643 return QualType();
2644 }
2645
2646 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2647 NewTL.setNameLoc(TL.getNameLoc());
2648
2649 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002650}
Mike Stump11289f42009-09-09 15:08:12 +00002651
2652template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002653ParmVarDecl *
2654TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2655 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2656 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2657 if (!NewDI)
2658 return 0;
2659
2660 if (NewDI == OldDI)
2661 return OldParm;
2662 else
2663 return ParmVarDecl::Create(SemaRef.Context,
2664 OldParm->getDeclContext(),
2665 OldParm->getLocation(),
2666 OldParm->getIdentifier(),
2667 NewDI->getType(),
2668 NewDI,
2669 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002670 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002671 /* DefArg */ NULL);
2672}
2673
2674template<typename Derived>
2675bool TreeTransform<Derived>::
2676 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2677 llvm::SmallVectorImpl<QualType> &PTypes,
2678 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2679 FunctionProtoType *T = TL.getTypePtr();
2680
2681 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2682 ParmVarDecl *OldParm = TL.getArg(i);
2683
2684 QualType NewType;
2685 ParmVarDecl *NewParm;
2686
2687 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002688 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2689 if (!NewParm)
2690 return true;
2691 NewType = NewParm->getType();
2692
2693 // Deal with the possibility that we don't have a parameter
2694 // declaration for this parameter.
2695 } else {
2696 NewParm = 0;
2697
2698 QualType OldType = T->getArgType(i);
2699 NewType = getDerived().TransformType(OldType);
2700 if (NewType.isNull())
2701 return true;
2702 }
2703
2704 PTypes.push_back(NewType);
2705 PVars.push_back(NewParm);
2706 }
2707
2708 return false;
2709}
2710
2711template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002712QualType
John McCall550e0c22009-10-21 00:40:46 +00002713TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002714 FunctionProtoTypeLoc TL,
2715 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002716 FunctionProtoType *T = TL.getTypePtr();
2717 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002718 if (ResultType.isNull())
2719 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002720
John McCall550e0c22009-10-21 00:40:46 +00002721 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002722 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002723 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002724 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2725 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002726
John McCall550e0c22009-10-21 00:40:46 +00002727 QualType Result = TL.getType();
2728 if (getDerived().AlwaysRebuild() ||
2729 ResultType != T->getResultType() ||
2730 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2731 Result = getDerived().RebuildFunctionProtoType(ResultType,
2732 ParamTypes.data(),
2733 ParamTypes.size(),
2734 T->isVariadic(),
2735 T->getTypeQuals());
2736 if (Result.isNull())
2737 return QualType();
2738 }
Mike Stump11289f42009-09-09 15:08:12 +00002739
John McCall550e0c22009-10-21 00:40:46 +00002740 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2741 NewTL.setLParenLoc(TL.getLParenLoc());
2742 NewTL.setRParenLoc(TL.getRParenLoc());
2743 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2744 NewTL.setArg(i, ParamDecls[i]);
2745
2746 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002747}
Mike Stump11289f42009-09-09 15:08:12 +00002748
Douglas Gregord6ff3322009-08-04 16:50:30 +00002749template<typename Derived>
2750QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002751 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002752 FunctionNoProtoTypeLoc TL,
2753 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002754 FunctionNoProtoType *T = TL.getTypePtr();
2755 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2756 if (ResultType.isNull())
2757 return QualType();
2758
2759 QualType Result = TL.getType();
2760 if (getDerived().AlwaysRebuild() ||
2761 ResultType != T->getResultType())
2762 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2763
2764 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2765 NewTL.setLParenLoc(TL.getLParenLoc());
2766 NewTL.setRParenLoc(TL.getRParenLoc());
2767
2768 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002769}
Mike Stump11289f42009-09-09 15:08:12 +00002770
John McCallb96ec562009-12-04 22:46:56 +00002771template<typename Derived> QualType
2772TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002773 UnresolvedUsingTypeLoc TL,
2774 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002775 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002776 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002777 if (!D)
2778 return QualType();
2779
2780 QualType Result = TL.getType();
2781 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2782 Result = getDerived().RebuildUnresolvedUsingType(D);
2783 if (Result.isNull())
2784 return QualType();
2785 }
2786
2787 // We might get an arbitrary type spec type back. We should at
2788 // least always get a type spec type, though.
2789 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2790 NewTL.setNameLoc(TL.getNameLoc());
2791
2792 return Result;
2793}
2794
Douglas Gregord6ff3322009-08-04 16:50:30 +00002795template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002796QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002797 TypedefTypeLoc TL,
2798 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002799 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002800 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002801 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2802 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002803 if (!Typedef)
2804 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002805
John McCall550e0c22009-10-21 00:40:46 +00002806 QualType Result = TL.getType();
2807 if (getDerived().AlwaysRebuild() ||
2808 Typedef != T->getDecl()) {
2809 Result = getDerived().RebuildTypedefType(Typedef);
2810 if (Result.isNull())
2811 return QualType();
2812 }
Mike Stump11289f42009-09-09 15:08:12 +00002813
John McCall550e0c22009-10-21 00:40:46 +00002814 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2815 NewTL.setNameLoc(TL.getNameLoc());
2816
2817 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002818}
Mike Stump11289f42009-09-09 15:08:12 +00002819
Douglas Gregord6ff3322009-08-04 16:50:30 +00002820template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002821QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002822 TypeOfExprTypeLoc TL,
2823 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00002824 // typeof expressions are not potentially evaluated contexts
2825 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002826
John McCalle8595032010-01-13 20:03:27 +00002827 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002828 if (E.isInvalid())
2829 return QualType();
2830
John McCall550e0c22009-10-21 00:40:46 +00002831 QualType Result = TL.getType();
2832 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00002833 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002834 Result = getDerived().RebuildTypeOfExprType(move(E));
2835 if (Result.isNull())
2836 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002837 }
John McCall550e0c22009-10-21 00:40:46 +00002838 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002839
John McCall550e0c22009-10-21 00:40:46 +00002840 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002841 NewTL.setTypeofLoc(TL.getTypeofLoc());
2842 NewTL.setLParenLoc(TL.getLParenLoc());
2843 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00002844
2845 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002846}
Mike Stump11289f42009-09-09 15:08:12 +00002847
2848template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002849QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002850 TypeOfTypeLoc TL,
2851 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00002852 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2853 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2854 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00002855 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002856
John McCall550e0c22009-10-21 00:40:46 +00002857 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00002858 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2859 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00002860 if (Result.isNull())
2861 return QualType();
2862 }
Mike Stump11289f42009-09-09 15:08:12 +00002863
John McCall550e0c22009-10-21 00:40:46 +00002864 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002865 NewTL.setTypeofLoc(TL.getTypeofLoc());
2866 NewTL.setLParenLoc(TL.getLParenLoc());
2867 NewTL.setRParenLoc(TL.getRParenLoc());
2868 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00002869
2870 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002871}
Mike Stump11289f42009-09-09 15:08:12 +00002872
2873template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002874QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002875 DecltypeTypeLoc TL,
2876 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002877 DecltypeType *T = TL.getTypePtr();
2878
Douglas Gregore922c772009-08-04 22:27:00 +00002879 // decltype expressions are not potentially evaluated contexts
2880 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002881
Douglas Gregord6ff3322009-08-04 16:50:30 +00002882 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2883 if (E.isInvalid())
2884 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002885
John McCall550e0c22009-10-21 00:40:46 +00002886 QualType Result = TL.getType();
2887 if (getDerived().AlwaysRebuild() ||
2888 E.get() != T->getUnderlyingExpr()) {
2889 Result = getDerived().RebuildDecltypeType(move(E));
2890 if (Result.isNull())
2891 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002892 }
John McCall550e0c22009-10-21 00:40:46 +00002893 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002894
John McCall550e0c22009-10-21 00:40:46 +00002895 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2896 NewTL.setNameLoc(TL.getNameLoc());
2897
2898 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002899}
2900
2901template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002902QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002903 RecordTypeLoc TL,
2904 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002905 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002906 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002907 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2908 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002909 if (!Record)
2910 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002911
John McCall550e0c22009-10-21 00:40:46 +00002912 QualType Result = TL.getType();
2913 if (getDerived().AlwaysRebuild() ||
2914 Record != T->getDecl()) {
2915 Result = getDerived().RebuildRecordType(Record);
2916 if (Result.isNull())
2917 return QualType();
2918 }
Mike Stump11289f42009-09-09 15:08:12 +00002919
John McCall550e0c22009-10-21 00:40:46 +00002920 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2921 NewTL.setNameLoc(TL.getNameLoc());
2922
2923 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002924}
Mike Stump11289f42009-09-09 15:08:12 +00002925
2926template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002927QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002928 EnumTypeLoc TL,
2929 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002930 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002931 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002932 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2933 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002934 if (!Enum)
2935 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002936
John McCall550e0c22009-10-21 00:40:46 +00002937 QualType Result = TL.getType();
2938 if (getDerived().AlwaysRebuild() ||
2939 Enum != T->getDecl()) {
2940 Result = getDerived().RebuildEnumType(Enum);
2941 if (Result.isNull())
2942 return QualType();
2943 }
Mike Stump11289f42009-09-09 15:08:12 +00002944
John McCall550e0c22009-10-21 00:40:46 +00002945 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2946 NewTL.setNameLoc(TL.getNameLoc());
2947
2948 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002949}
John McCallfcc33b02009-09-05 00:15:47 +00002950
2951template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002952QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002953 ElaboratedTypeLoc TL,
2954 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002955 ElaboratedType *T = TL.getTypePtr();
2956
2957 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002958 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2959 if (Underlying.isNull())
2960 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002961
John McCall550e0c22009-10-21 00:40:46 +00002962 QualType Result = TL.getType();
2963 if (getDerived().AlwaysRebuild() ||
2964 Underlying != T->getUnderlyingType()) {
2965 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2966 if (Result.isNull())
2967 return QualType();
2968 }
Mike Stump11289f42009-09-09 15:08:12 +00002969
John McCall550e0c22009-10-21 00:40:46 +00002970 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2971 NewTL.setNameLoc(TL.getNameLoc());
2972
2973 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002974}
Mike Stump11289f42009-09-09 15:08:12 +00002975
John McCalle78aac42010-03-10 03:28:59 +00002976template<typename Derived>
2977QualType TreeTransform<Derived>::TransformInjectedClassNameType(
2978 TypeLocBuilder &TLB,
2979 InjectedClassNameTypeLoc TL,
2980 QualType ObjectType) {
2981 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
2982 TL.getTypePtr()->getDecl());
2983 if (!D) return QualType();
2984
2985 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
2986 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
2987 return T;
2988}
2989
Mike Stump11289f42009-09-09 15:08:12 +00002990
Douglas Gregord6ff3322009-08-04 16:50:30 +00002991template<typename Derived>
2992QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002993 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002994 TemplateTypeParmTypeLoc TL,
2995 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002996 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002997}
2998
Mike Stump11289f42009-09-09 15:08:12 +00002999template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003000QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003001 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003002 SubstTemplateTypeParmTypeLoc TL,
3003 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003004 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003005}
3006
3007template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003008QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3009 const TemplateSpecializationType *TST,
3010 QualType ObjectType) {
3011 // FIXME: this entire method is a temporary workaround; callers
3012 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003013
John McCall0ad16662009-10-29 08:12:44 +00003014 // Fake up a TemplateSpecializationTypeLoc.
3015 TypeLocBuilder TLB;
3016 TemplateSpecializationTypeLoc TL
3017 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3018
John McCall0d07eb32009-10-29 18:45:58 +00003019 SourceLocation BaseLoc = getDerived().getBaseLocation();
3020
3021 TL.setTemplateNameLoc(BaseLoc);
3022 TL.setLAngleLoc(BaseLoc);
3023 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003024 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3025 const TemplateArgument &TA = TST->getArg(i);
3026 TemplateArgumentLoc TAL;
3027 getDerived().InventTemplateArgumentLoc(TA, TAL);
3028 TL.setArgLocInfo(i, TAL.getLocInfo());
3029 }
3030
3031 TypeLocBuilder IgnoredTLB;
3032 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003033}
3034
3035template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003036QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003037 TypeLocBuilder &TLB,
3038 TemplateSpecializationTypeLoc TL,
3039 QualType ObjectType) {
3040 const TemplateSpecializationType *T = TL.getTypePtr();
3041
Mike Stump11289f42009-09-09 15:08:12 +00003042 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003043 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003044 if (Template.isNull())
3045 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003046
John McCall6b51f282009-11-23 01:53:49 +00003047 TemplateArgumentListInfo NewTemplateArgs;
3048 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3049 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3050
3051 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3052 TemplateArgumentLoc Loc;
3053 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003054 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003055 NewTemplateArgs.addArgument(Loc);
3056 }
Mike Stump11289f42009-09-09 15:08:12 +00003057
John McCall0ad16662009-10-29 08:12:44 +00003058 // FIXME: maybe don't rebuild if all the template arguments are the same.
3059
3060 QualType Result =
3061 getDerived().RebuildTemplateSpecializationType(Template,
3062 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003063 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003064
3065 if (!Result.isNull()) {
3066 TemplateSpecializationTypeLoc NewTL
3067 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3068 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3069 NewTL.setLAngleLoc(TL.getLAngleLoc());
3070 NewTL.setRAngleLoc(TL.getRAngleLoc());
3071 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3072 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003073 }
Mike Stump11289f42009-09-09 15:08:12 +00003074
John McCall0ad16662009-10-29 08:12:44 +00003075 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003076}
Mike Stump11289f42009-09-09 15:08:12 +00003077
3078template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003079QualType
3080TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003081 QualifiedNameTypeLoc TL,
3082 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003083 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003084 NestedNameSpecifier *NNS
3085 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00003086 SourceRange(),
3087 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003088 if (!NNS)
3089 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003090
Douglas Gregord6ff3322009-08-04 16:50:30 +00003091 QualType Named = getDerived().TransformType(T->getNamedType());
3092 if (Named.isNull())
3093 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003094
John McCall550e0c22009-10-21 00:40:46 +00003095 QualType Result = TL.getType();
3096 if (getDerived().AlwaysRebuild() ||
3097 NNS != T->getQualifier() ||
3098 Named != T->getNamedType()) {
3099 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
3100 if (Result.isNull())
3101 return QualType();
3102 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003103
John McCall550e0c22009-10-21 00:40:46 +00003104 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
3105 NewTL.setNameLoc(TL.getNameLoc());
3106
3107 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003108}
Mike Stump11289f42009-09-09 15:08:12 +00003109
3110template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003111QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3112 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003113 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003114 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003115
3116 /* FIXME: preserve source information better than this */
3117 SourceRange SR(TL.getNameLoc());
3118
Douglas Gregord6ff3322009-08-04 16:50:30 +00003119 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00003120 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003121 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003122 if (!NNS)
3123 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003124
John McCall550e0c22009-10-21 00:40:46 +00003125 QualType Result;
3126
Douglas Gregord6ff3322009-08-04 16:50:30 +00003127 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00003128 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00003129 = getDerived().TransformType(QualType(TemplateId, 0));
3130 if (NewTemplateId.isNull())
3131 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003132
Douglas Gregord6ff3322009-08-04 16:50:30 +00003133 if (!getDerived().AlwaysRebuild() &&
3134 NNS == T->getQualifier() &&
3135 NewTemplateId == QualType(TemplateId, 0))
3136 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00003137
Douglas Gregor02085352010-03-31 20:19:30 +00003138 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3139 NewTemplateId);
John McCall550e0c22009-10-21 00:40:46 +00003140 } else {
Douglas Gregor02085352010-03-31 20:19:30 +00003141 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3142 T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003143 }
John McCall550e0c22009-10-21 00:40:46 +00003144 if (Result.isNull())
3145 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003146
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003147 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003148 NewTL.setNameLoc(TL.getNameLoc());
3149
3150 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003151}
Mike Stump11289f42009-09-09 15:08:12 +00003152
Douglas Gregord6ff3322009-08-04 16:50:30 +00003153template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003154QualType
3155TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003156 ObjCInterfaceTypeLoc TL,
3157 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003158 // ObjCInterfaceType is never dependent.
3159 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003160}
Mike Stump11289f42009-09-09 15:08:12 +00003161
3162template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003163QualType
3164TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003165 ObjCObjectPointerTypeLoc TL,
3166 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003167 // ObjCObjectPointerType is never dependent.
3168 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003169}
3170
Douglas Gregord6ff3322009-08-04 16:50:30 +00003171//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003172// Statement transformation
3173//===----------------------------------------------------------------------===//
3174template<typename Derived>
3175Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003176TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3177 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003178}
3179
3180template<typename Derived>
3181Sema::OwningStmtResult
3182TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3183 return getDerived().TransformCompoundStmt(S, false);
3184}
3185
3186template<typename Derived>
3187Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003188TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003189 bool IsStmtExpr) {
3190 bool SubStmtChanged = false;
3191 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3192 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3193 B != BEnd; ++B) {
3194 OwningStmtResult Result = getDerived().TransformStmt(*B);
3195 if (Result.isInvalid())
3196 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003197
Douglas Gregorebe10102009-08-20 07:17:43 +00003198 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3199 Statements.push_back(Result.takeAs<Stmt>());
3200 }
Mike Stump11289f42009-09-09 15:08:12 +00003201
Douglas Gregorebe10102009-08-20 07:17:43 +00003202 if (!getDerived().AlwaysRebuild() &&
3203 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003204 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003205
3206 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3207 move_arg(Statements),
3208 S->getRBracLoc(),
3209 IsStmtExpr);
3210}
Mike Stump11289f42009-09-09 15:08:12 +00003211
Douglas Gregorebe10102009-08-20 07:17:43 +00003212template<typename Derived>
3213Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003214TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003215 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3216 {
3217 // The case value expressions are not potentially evaluated.
3218 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003219
Eli Friedman06577382009-11-19 03:14:00 +00003220 // Transform the left-hand case value.
3221 LHS = getDerived().TransformExpr(S->getLHS());
3222 if (LHS.isInvalid())
3223 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003224
Eli Friedman06577382009-11-19 03:14:00 +00003225 // Transform the right-hand case value (for the GNU case-range extension).
3226 RHS = getDerived().TransformExpr(S->getRHS());
3227 if (RHS.isInvalid())
3228 return SemaRef.StmtError();
3229 }
Mike Stump11289f42009-09-09 15:08:12 +00003230
Douglas Gregorebe10102009-08-20 07:17:43 +00003231 // Build the case statement.
3232 // Case statements are always rebuilt so that they will attached to their
3233 // transformed switch statement.
3234 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3235 move(LHS),
3236 S->getEllipsisLoc(),
3237 move(RHS),
3238 S->getColonLoc());
3239 if (Case.isInvalid())
3240 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003241
Douglas Gregorebe10102009-08-20 07:17:43 +00003242 // Transform the statement following the case
3243 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3244 if (SubStmt.isInvalid())
3245 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003246
Douglas Gregorebe10102009-08-20 07:17:43 +00003247 // Attach the body to the case statement
3248 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3249}
3250
3251template<typename Derived>
3252Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003253TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003254 // Transform the statement following the default case
3255 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3256 if (SubStmt.isInvalid())
3257 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003258
Douglas Gregorebe10102009-08-20 07:17:43 +00003259 // Default statements are always rebuilt
3260 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3261 move(SubStmt));
3262}
Mike Stump11289f42009-09-09 15:08:12 +00003263
Douglas Gregorebe10102009-08-20 07:17:43 +00003264template<typename Derived>
3265Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003266TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003267 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3268 if (SubStmt.isInvalid())
3269 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003270
Douglas Gregorebe10102009-08-20 07:17:43 +00003271 // FIXME: Pass the real colon location in.
3272 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3273 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3274 move(SubStmt));
3275}
Mike Stump11289f42009-09-09 15:08:12 +00003276
Douglas Gregorebe10102009-08-20 07:17:43 +00003277template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003278Sema::OwningStmtResult
3279TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003280 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003281 OwningExprResult Cond(SemaRef);
3282 VarDecl *ConditionVar = 0;
3283 if (S->getConditionVariable()) {
3284 ConditionVar
3285 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003286 getDerived().TransformDefinition(
3287 S->getConditionVariable()->getLocation(),
3288 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003289 if (!ConditionVar)
3290 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003291 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003292 Cond = getDerived().TransformExpr(S->getCond());
3293
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003294 if (Cond.isInvalid())
3295 return SemaRef.StmtError();
3296 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003297
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003298 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003299
Douglas Gregorebe10102009-08-20 07:17:43 +00003300 // Transform the "then" branch.
3301 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3302 if (Then.isInvalid())
3303 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003304
Douglas Gregorebe10102009-08-20 07:17:43 +00003305 // Transform the "else" branch.
3306 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3307 if (Else.isInvalid())
3308 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003309
Douglas Gregorebe10102009-08-20 07:17:43 +00003310 if (!getDerived().AlwaysRebuild() &&
3311 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003312 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003313 Then.get() == S->getThen() &&
3314 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003315 return SemaRef.Owned(S->Retain());
3316
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003317 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3318 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003319 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003320}
3321
3322template<typename Derived>
3323Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003324TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003325 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003326 OwningExprResult Cond(SemaRef);
3327 VarDecl *ConditionVar = 0;
3328 if (S->getConditionVariable()) {
3329 ConditionVar
3330 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003331 getDerived().TransformDefinition(
3332 S->getConditionVariable()->getLocation(),
3333 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003334 if (!ConditionVar)
3335 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003336 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003337 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003338
3339 if (Cond.isInvalid())
3340 return SemaRef.StmtError();
3341 }
Mike Stump11289f42009-09-09 15:08:12 +00003342
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003343 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003344
Douglas Gregorebe10102009-08-20 07:17:43 +00003345 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003346 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3347 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003348 if (Switch.isInvalid())
3349 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003350
Douglas Gregorebe10102009-08-20 07:17:43 +00003351 // Transform the body of the switch statement.
3352 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3353 if (Body.isInvalid())
3354 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003355
Douglas Gregorebe10102009-08-20 07:17:43 +00003356 // Complete the switch statement.
3357 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3358 move(Body));
3359}
Mike Stump11289f42009-09-09 15:08:12 +00003360
Douglas Gregorebe10102009-08-20 07:17:43 +00003361template<typename Derived>
3362Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003363TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003364 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003365 OwningExprResult Cond(SemaRef);
3366 VarDecl *ConditionVar = 0;
3367 if (S->getConditionVariable()) {
3368 ConditionVar
3369 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003370 getDerived().TransformDefinition(
3371 S->getConditionVariable()->getLocation(),
3372 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003373 if (!ConditionVar)
3374 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003375 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003376 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003377
3378 if (Cond.isInvalid())
3379 return SemaRef.StmtError();
3380 }
Mike Stump11289f42009-09-09 15:08:12 +00003381
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003382 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003383
Douglas Gregorebe10102009-08-20 07:17:43 +00003384 // Transform the body
3385 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3386 if (Body.isInvalid())
3387 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003388
Douglas Gregorebe10102009-08-20 07:17:43 +00003389 if (!getDerived().AlwaysRebuild() &&
3390 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003391 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003392 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003393 return SemaRef.Owned(S->Retain());
3394
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003395 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3396 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003397}
Mike Stump11289f42009-09-09 15:08:12 +00003398
Douglas Gregorebe10102009-08-20 07:17:43 +00003399template<typename Derived>
3400Sema::OwningStmtResult
3401TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3402 // Transform the condition
3403 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3404 if (Cond.isInvalid())
3405 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003406
Douglas Gregorebe10102009-08-20 07:17:43 +00003407 // Transform the body
3408 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3409 if (Body.isInvalid())
3410 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003411
Douglas Gregorebe10102009-08-20 07:17:43 +00003412 if (!getDerived().AlwaysRebuild() &&
3413 Cond.get() == S->getCond() &&
3414 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003415 return SemaRef.Owned(S->Retain());
3416
Douglas Gregorebe10102009-08-20 07:17:43 +00003417 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3418 /*FIXME:*/S->getWhileLoc(), move(Cond),
3419 S->getRParenLoc());
3420}
Mike Stump11289f42009-09-09 15:08:12 +00003421
Douglas Gregorebe10102009-08-20 07:17:43 +00003422template<typename Derived>
3423Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003424TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003425 // Transform the initialization statement
3426 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3427 if (Init.isInvalid())
3428 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003429
Douglas Gregorebe10102009-08-20 07:17:43 +00003430 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003431 OwningExprResult Cond(SemaRef);
3432 VarDecl *ConditionVar = 0;
3433 if (S->getConditionVariable()) {
3434 ConditionVar
3435 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003436 getDerived().TransformDefinition(
3437 S->getConditionVariable()->getLocation(),
3438 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003439 if (!ConditionVar)
3440 return SemaRef.StmtError();
3441 } else {
3442 Cond = getDerived().TransformExpr(S->getCond());
3443
3444 if (Cond.isInvalid())
3445 return SemaRef.StmtError();
3446 }
Mike Stump11289f42009-09-09 15:08:12 +00003447
Douglas Gregorebe10102009-08-20 07:17:43 +00003448 // Transform the increment
3449 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3450 if (Inc.isInvalid())
3451 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003452
Douglas Gregorebe10102009-08-20 07:17:43 +00003453 // Transform the body
3454 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3455 if (Body.isInvalid())
3456 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003457
Douglas Gregorebe10102009-08-20 07:17:43 +00003458 if (!getDerived().AlwaysRebuild() &&
3459 Init.get() == S->getInit() &&
3460 Cond.get() == S->getCond() &&
3461 Inc.get() == S->getInc() &&
3462 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003463 return SemaRef.Owned(S->Retain());
3464
Douglas Gregorebe10102009-08-20 07:17:43 +00003465 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003466 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003467 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003468 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003469 S->getRParenLoc(), move(Body));
3470}
3471
3472template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003473Sema::OwningStmtResult
3474TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003475 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003476 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003477 S->getLabel());
3478}
3479
3480template<typename Derived>
3481Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003482TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003483 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3484 if (Target.isInvalid())
3485 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003486
Douglas Gregorebe10102009-08-20 07:17:43 +00003487 if (!getDerived().AlwaysRebuild() &&
3488 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003489 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003490
3491 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3492 move(Target));
3493}
3494
3495template<typename Derived>
3496Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003497TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3498 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003499}
Mike Stump11289f42009-09-09 15:08:12 +00003500
Douglas Gregorebe10102009-08-20 07:17:43 +00003501template<typename Derived>
3502Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003503TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3504 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003505}
Mike Stump11289f42009-09-09 15:08:12 +00003506
Douglas Gregorebe10102009-08-20 07:17:43 +00003507template<typename Derived>
3508Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003509TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003510 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3511 if (Result.isInvalid())
3512 return SemaRef.StmtError();
3513
Mike Stump11289f42009-09-09 15:08:12 +00003514 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003515 // to tell whether the return type of the function has changed.
3516 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3517}
Mike Stump11289f42009-09-09 15:08:12 +00003518
Douglas Gregorebe10102009-08-20 07:17:43 +00003519template<typename Derived>
3520Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003521TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003522 bool DeclChanged = false;
3523 llvm::SmallVector<Decl *, 4> Decls;
3524 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3525 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003526 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3527 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003528 if (!Transformed)
3529 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003530
Douglas Gregorebe10102009-08-20 07:17:43 +00003531 if (Transformed != *D)
3532 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003533
Douglas Gregorebe10102009-08-20 07:17:43 +00003534 Decls.push_back(Transformed);
3535 }
Mike Stump11289f42009-09-09 15:08:12 +00003536
Douglas Gregorebe10102009-08-20 07:17:43 +00003537 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003538 return SemaRef.Owned(S->Retain());
3539
3540 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003541 S->getStartLoc(), S->getEndLoc());
3542}
Mike Stump11289f42009-09-09 15:08:12 +00003543
Douglas Gregorebe10102009-08-20 07:17:43 +00003544template<typename Derived>
3545Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003546TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003547 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003548 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003549}
3550
3551template<typename Derived>
3552Sema::OwningStmtResult
3553TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003554
3555 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3556 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003557 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003558
Anders Carlssonaaeef072010-01-24 05:50:09 +00003559 OwningExprResult AsmString(SemaRef);
3560 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3561
3562 bool ExprsChanged = false;
3563
3564 // Go through the outputs.
3565 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003566 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003567
Anders Carlssonaaeef072010-01-24 05:50:09 +00003568 // No need to transform the constraint literal.
3569 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3570
3571 // Transform the output expr.
3572 Expr *OutputExpr = S->getOutputExpr(I);
3573 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3574 if (Result.isInvalid())
3575 return SemaRef.StmtError();
3576
3577 ExprsChanged |= Result.get() != OutputExpr;
3578
3579 Exprs.push_back(Result.takeAs<Expr>());
3580 }
3581
3582 // Go through the inputs.
3583 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003584 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003585
Anders Carlssonaaeef072010-01-24 05:50:09 +00003586 // No need to transform the constraint literal.
3587 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3588
3589 // Transform the input expr.
3590 Expr *InputExpr = S->getInputExpr(I);
3591 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3592 if (Result.isInvalid())
3593 return SemaRef.StmtError();
3594
3595 ExprsChanged |= Result.get() != InputExpr;
3596
3597 Exprs.push_back(Result.takeAs<Expr>());
3598 }
3599
3600 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3601 return SemaRef.Owned(S->Retain());
3602
3603 // Go through the clobbers.
3604 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3605 Clobbers.push_back(S->getClobber(I)->Retain());
3606
3607 // No need to transform the asm string literal.
3608 AsmString = SemaRef.Owned(S->getAsmString());
3609
3610 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3611 S->isSimple(),
3612 S->isVolatile(),
3613 S->getNumOutputs(),
3614 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003615 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003616 move_arg(Constraints),
3617 move_arg(Exprs),
3618 move(AsmString),
3619 move_arg(Clobbers),
3620 S->getRParenLoc(),
3621 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003622}
3623
3624
3625template<typename Derived>
3626Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003627TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003628 // FIXME: Implement this
3629 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003630 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003631}
Mike Stump11289f42009-09-09 15:08:12 +00003632
Douglas Gregorebe10102009-08-20 07:17:43 +00003633template<typename Derived>
3634Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003635TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003636 // FIXME: Implement this
3637 assert(false && "Cannot transform an Objective-C @catch statement");
3638 return SemaRef.Owned(S->Retain());
3639}
Mike Stump11289f42009-09-09 15:08:12 +00003640
Douglas Gregorebe10102009-08-20 07:17:43 +00003641template<typename Derived>
3642Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003643TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003644 // FIXME: Implement this
3645 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003646 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003647}
Mike Stump11289f42009-09-09 15:08:12 +00003648
Douglas Gregorebe10102009-08-20 07:17:43 +00003649template<typename Derived>
3650Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003651TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003652 // FIXME: Implement this
3653 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003654 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003655}
Mike Stump11289f42009-09-09 15:08:12 +00003656
Douglas Gregorebe10102009-08-20 07:17:43 +00003657template<typename Derived>
3658Sema::OwningStmtResult
3659TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003660 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003661 // FIXME: Implement this
3662 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003663 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003664}
3665
3666template<typename Derived>
3667Sema::OwningStmtResult
3668TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003669 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003670 // FIXME: Implement this
3671 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003672 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003673}
3674
3675
3676template<typename Derived>
3677Sema::OwningStmtResult
3678TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3679 // Transform the exception declaration, if any.
3680 VarDecl *Var = 0;
3681 if (S->getExceptionDecl()) {
3682 VarDecl *ExceptionDecl = S->getExceptionDecl();
3683 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3684 ExceptionDecl->getDeclName());
3685
3686 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3687 if (T.isNull())
3688 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003689
Douglas Gregorebe10102009-08-20 07:17:43 +00003690 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3691 T,
John McCallbcd03502009-12-07 02:54:59 +00003692 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003693 ExceptionDecl->getIdentifier(),
3694 ExceptionDecl->getLocation(),
3695 /*FIXME: Inaccurate*/
3696 SourceRange(ExceptionDecl->getLocation()));
3697 if (!Var || Var->isInvalidDecl()) {
3698 if (Var)
3699 Var->Destroy(SemaRef.Context);
3700 return SemaRef.StmtError();
3701 }
3702 }
Mike Stump11289f42009-09-09 15:08:12 +00003703
Douglas Gregorebe10102009-08-20 07:17:43 +00003704 // Transform the actual exception handler.
3705 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3706 if (Handler.isInvalid()) {
3707 if (Var)
3708 Var->Destroy(SemaRef.Context);
3709 return SemaRef.StmtError();
3710 }
Mike Stump11289f42009-09-09 15:08:12 +00003711
Douglas Gregorebe10102009-08-20 07:17:43 +00003712 if (!getDerived().AlwaysRebuild() &&
3713 !Var &&
3714 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003715 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003716
3717 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3718 Var,
3719 move(Handler));
3720}
Mike Stump11289f42009-09-09 15:08:12 +00003721
Douglas Gregorebe10102009-08-20 07:17:43 +00003722template<typename Derived>
3723Sema::OwningStmtResult
3724TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3725 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003726 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003727 = getDerived().TransformCompoundStmt(S->getTryBlock());
3728 if (TryBlock.isInvalid())
3729 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003730
Douglas Gregorebe10102009-08-20 07:17:43 +00003731 // Transform the handlers.
3732 bool HandlerChanged = false;
3733 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3734 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003735 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003736 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3737 if (Handler.isInvalid())
3738 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003739
Douglas Gregorebe10102009-08-20 07:17:43 +00003740 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3741 Handlers.push_back(Handler.takeAs<Stmt>());
3742 }
Mike Stump11289f42009-09-09 15:08:12 +00003743
Douglas Gregorebe10102009-08-20 07:17:43 +00003744 if (!getDerived().AlwaysRebuild() &&
3745 TryBlock.get() == S->getTryBlock() &&
3746 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003747 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003748
3749 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003750 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003751}
Mike Stump11289f42009-09-09 15:08:12 +00003752
Douglas Gregorebe10102009-08-20 07:17:43 +00003753//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003754// Expression transformation
3755//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003756template<typename Derived>
3757Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003758TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003759 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003760}
Mike Stump11289f42009-09-09 15:08:12 +00003761
3762template<typename Derived>
3763Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003764TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003765 NestedNameSpecifier *Qualifier = 0;
3766 if (E->getQualifier()) {
3767 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003768 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003769 if (!Qualifier)
3770 return SemaRef.ExprError();
3771 }
John McCallce546572009-12-08 09:08:17 +00003772
3773 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003774 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
3775 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003776 if (!ND)
3777 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003778
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003779 if (!getDerived().AlwaysRebuild() &&
3780 Qualifier == E->getQualifier() &&
3781 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003782 !E->hasExplicitTemplateArgumentList()) {
3783
3784 // Mark it referenced in the new context regardless.
3785 // FIXME: this is a bit instantiation-specific.
3786 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3787
Mike Stump11289f42009-09-09 15:08:12 +00003788 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003789 }
John McCallce546572009-12-08 09:08:17 +00003790
3791 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3792 if (E->hasExplicitTemplateArgumentList()) {
3793 TemplateArgs = &TransArgs;
3794 TransArgs.setLAngleLoc(E->getLAngleLoc());
3795 TransArgs.setRAngleLoc(E->getRAngleLoc());
3796 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3797 TemplateArgumentLoc Loc;
3798 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3799 return SemaRef.ExprError();
3800 TransArgs.addArgument(Loc);
3801 }
3802 }
3803
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003804 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003805 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003806}
Mike Stump11289f42009-09-09 15:08:12 +00003807
Douglas Gregora16548e2009-08-11 05:31:07 +00003808template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003809Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003810TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003811 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003812}
Mike Stump11289f42009-09-09 15:08:12 +00003813
Douglas Gregora16548e2009-08-11 05:31:07 +00003814template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003815Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003816TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003817 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003818}
Mike Stump11289f42009-09-09 15:08:12 +00003819
Douglas Gregora16548e2009-08-11 05:31:07 +00003820template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003821Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003822TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003823 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003824}
Mike Stump11289f42009-09-09 15:08:12 +00003825
Douglas Gregora16548e2009-08-11 05:31:07 +00003826template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003827Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003828TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003829 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003830}
Mike Stump11289f42009-09-09 15:08:12 +00003831
Douglas Gregora16548e2009-08-11 05:31:07 +00003832template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003833Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003834TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003835 return SemaRef.Owned(E->Retain());
3836}
3837
3838template<typename Derived>
3839Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003840TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003841 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3842 if (SubExpr.isInvalid())
3843 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003844
Douglas Gregora16548e2009-08-11 05:31:07 +00003845 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003846 return SemaRef.Owned(E->Retain());
3847
3848 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003849 E->getRParen());
3850}
3851
Mike Stump11289f42009-09-09 15:08:12 +00003852template<typename Derived>
3853Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003854TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3855 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003856 if (SubExpr.isInvalid())
3857 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003858
Douglas Gregora16548e2009-08-11 05:31:07 +00003859 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003860 return SemaRef.Owned(E->Retain());
3861
Douglas Gregora16548e2009-08-11 05:31:07 +00003862 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3863 E->getOpcode(),
3864 move(SubExpr));
3865}
Mike Stump11289f42009-09-09 15:08:12 +00003866
Douglas Gregora16548e2009-08-11 05:31:07 +00003867template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003868Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003869TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003870 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003871 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003872
John McCallbcd03502009-12-07 02:54:59 +00003873 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003874 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003875 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003876
John McCall4c98fd82009-11-04 07:28:41 +00003877 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003878 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003879
John McCall4c98fd82009-11-04 07:28:41 +00003880 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003881 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003882 E->getSourceRange());
3883 }
Mike Stump11289f42009-09-09 15:08:12 +00003884
Douglas Gregora16548e2009-08-11 05:31:07 +00003885 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003886 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003887 // C++0x [expr.sizeof]p1:
3888 // The operand is either an expression, which is an unevaluated operand
3889 // [...]
3890 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003891
Douglas Gregora16548e2009-08-11 05:31:07 +00003892 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3893 if (SubExpr.isInvalid())
3894 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003895
Douglas Gregora16548e2009-08-11 05:31:07 +00003896 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3897 return SemaRef.Owned(E->Retain());
3898 }
Mike Stump11289f42009-09-09 15:08:12 +00003899
Douglas Gregora16548e2009-08-11 05:31:07 +00003900 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3901 E->isSizeOf(),
3902 E->getSourceRange());
3903}
Mike Stump11289f42009-09-09 15:08:12 +00003904
Douglas Gregora16548e2009-08-11 05:31:07 +00003905template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003906Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003907TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003908 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3909 if (LHS.isInvalid())
3910 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003911
Douglas Gregora16548e2009-08-11 05:31:07 +00003912 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3913 if (RHS.isInvalid())
3914 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003915
3916
Douglas Gregora16548e2009-08-11 05:31:07 +00003917 if (!getDerived().AlwaysRebuild() &&
3918 LHS.get() == E->getLHS() &&
3919 RHS.get() == E->getRHS())
3920 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003921
Douglas Gregora16548e2009-08-11 05:31:07 +00003922 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3923 /*FIXME:*/E->getLHS()->getLocStart(),
3924 move(RHS),
3925 E->getRBracketLoc());
3926}
Mike Stump11289f42009-09-09 15:08:12 +00003927
3928template<typename Derived>
3929Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003930TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003931 // Transform the callee.
3932 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3933 if (Callee.isInvalid())
3934 return SemaRef.ExprError();
3935
3936 // Transform arguments.
3937 bool ArgChanged = false;
3938 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3939 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3940 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3941 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3942 if (Arg.isInvalid())
3943 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003944
Douglas Gregora16548e2009-08-11 05:31:07 +00003945 // FIXME: Wrong source location information for the ','.
3946 FakeCommaLocs.push_back(
3947 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003948
3949 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003950 Args.push_back(Arg.takeAs<Expr>());
3951 }
Mike Stump11289f42009-09-09 15:08:12 +00003952
Douglas Gregora16548e2009-08-11 05:31:07 +00003953 if (!getDerived().AlwaysRebuild() &&
3954 Callee.get() == E->getCallee() &&
3955 !ArgChanged)
3956 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003957
Douglas Gregora16548e2009-08-11 05:31:07 +00003958 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003959 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003960 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3961 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3962 move_arg(Args),
3963 FakeCommaLocs.data(),
3964 E->getRParenLoc());
3965}
Mike Stump11289f42009-09-09 15:08:12 +00003966
3967template<typename Derived>
3968Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003969TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003970 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3971 if (Base.isInvalid())
3972 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003973
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003974 NestedNameSpecifier *Qualifier = 0;
3975 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003976 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003977 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003978 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003979 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003980 return SemaRef.ExprError();
3981 }
Mike Stump11289f42009-09-09 15:08:12 +00003982
Eli Friedman2cfcef62009-12-04 06:40:45 +00003983 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003984 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
3985 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003986 if (!Member)
3987 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003988
John McCall16df1e52010-03-30 21:47:33 +00003989 NamedDecl *FoundDecl = E->getFoundDecl();
3990 if (FoundDecl == E->getMemberDecl()) {
3991 FoundDecl = Member;
3992 } else {
3993 FoundDecl = cast_or_null<NamedDecl>(
3994 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
3995 if (!FoundDecl)
3996 return SemaRef.ExprError();
3997 }
3998
Douglas Gregora16548e2009-08-11 05:31:07 +00003999 if (!getDerived().AlwaysRebuild() &&
4000 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004001 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004002 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004003 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004004 !E->hasExplicitTemplateArgumentList()) {
4005
4006 // Mark it referenced in the new context regardless.
4007 // FIXME: this is a bit instantiation-specific.
4008 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004009 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004010 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004011
John McCall6b51f282009-11-23 01:53:49 +00004012 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004013 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00004014 TransArgs.setLAngleLoc(E->getLAngleLoc());
4015 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004016 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004017 TemplateArgumentLoc Loc;
4018 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004019 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004020 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004021 }
4022 }
4023
Douglas Gregora16548e2009-08-11 05:31:07 +00004024 // FIXME: Bogus source location for the operator
4025 SourceLocation FakeOperatorLoc
4026 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4027
John McCall38836f02010-01-15 08:34:02 +00004028 // FIXME: to do this check properly, we will need to preserve the
4029 // first-qualifier-in-scope here, just in case we had a dependent
4030 // base (and therefore couldn't do the check) and a
4031 // nested-name-qualifier (and therefore could do the lookup).
4032 NamedDecl *FirstQualifierInScope = 0;
4033
Douglas Gregora16548e2009-08-11 05:31:07 +00004034 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4035 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004036 Qualifier,
4037 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004038 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004039 Member,
John McCall16df1e52010-03-30 21:47:33 +00004040 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00004041 (E->hasExplicitTemplateArgumentList()
4042 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004043 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004044}
Mike Stump11289f42009-09-09 15:08:12 +00004045
Douglas Gregora16548e2009-08-11 05:31:07 +00004046template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004047Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004048TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004049 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4050 if (LHS.isInvalid())
4051 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004052
Douglas Gregora16548e2009-08-11 05:31:07 +00004053 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4054 if (RHS.isInvalid())
4055 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004056
Douglas Gregora16548e2009-08-11 05:31:07 +00004057 if (!getDerived().AlwaysRebuild() &&
4058 LHS.get() == E->getLHS() &&
4059 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004060 return SemaRef.Owned(E->Retain());
4061
Douglas Gregora16548e2009-08-11 05:31:07 +00004062 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4063 move(LHS), move(RHS));
4064}
4065
Mike Stump11289f42009-09-09 15:08:12 +00004066template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004067Sema::OwningExprResult
4068TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004069 CompoundAssignOperator *E) {
4070 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004071}
Mike Stump11289f42009-09-09 15:08:12 +00004072
Douglas Gregora16548e2009-08-11 05:31:07 +00004073template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004074Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004075TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004076 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4077 if (Cond.isInvalid())
4078 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004079
Douglas Gregora16548e2009-08-11 05:31:07 +00004080 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4081 if (LHS.isInvalid())
4082 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004083
Douglas Gregora16548e2009-08-11 05:31:07 +00004084 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4085 if (RHS.isInvalid())
4086 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004087
Douglas Gregora16548e2009-08-11 05:31:07 +00004088 if (!getDerived().AlwaysRebuild() &&
4089 Cond.get() == E->getCond() &&
4090 LHS.get() == E->getLHS() &&
4091 RHS.get() == E->getRHS())
4092 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004093
4094 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004095 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004096 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004097 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004098 move(RHS));
4099}
Mike Stump11289f42009-09-09 15:08:12 +00004100
4101template<typename Derived>
4102Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004103TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004104 // Implicit casts are eliminated during transformation, since they
4105 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004106 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004107}
Mike Stump11289f42009-09-09 15:08:12 +00004108
Douglas Gregora16548e2009-08-11 05:31:07 +00004109template<typename Derived>
4110Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004111TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004112 TypeSourceInfo *OldT;
4113 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004114 {
4115 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004116 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004117 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4118 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004119
John McCall97513962010-01-15 18:39:57 +00004120 OldT = E->getTypeInfoAsWritten();
4121 NewT = getDerived().TransformType(OldT);
4122 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004123 return SemaRef.ExprError();
4124 }
Mike Stump11289f42009-09-09 15:08:12 +00004125
Douglas Gregor6131b442009-12-12 18:16:41 +00004126 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004127 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004128 if (SubExpr.isInvalid())
4129 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004130
Douglas Gregora16548e2009-08-11 05:31:07 +00004131 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004132 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004133 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004134 return SemaRef.Owned(E->Retain());
4135
John McCall97513962010-01-15 18:39:57 +00004136 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4137 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004138 E->getRParenLoc(),
4139 move(SubExpr));
4140}
Mike Stump11289f42009-09-09 15:08:12 +00004141
Douglas Gregora16548e2009-08-11 05:31:07 +00004142template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004143Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004144TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004145 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4146 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4147 if (!NewT)
4148 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004149
Douglas Gregora16548e2009-08-11 05:31:07 +00004150 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4151 if (Init.isInvalid())
4152 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004153
Douglas Gregora16548e2009-08-11 05:31:07 +00004154 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004155 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004156 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004157 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004158
John McCall5d7aa7f2010-01-19 22:33:45 +00004159 // Note: the expression type doesn't necessarily match the
4160 // type-as-written, but that's okay, because it should always be
4161 // derivable from the initializer.
4162
John McCalle15bbff2010-01-18 19:35:47 +00004163 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004164 /*FIXME:*/E->getInitializer()->getLocEnd(),
4165 move(Init));
4166}
Mike Stump11289f42009-09-09 15:08:12 +00004167
Douglas Gregora16548e2009-08-11 05:31:07 +00004168template<typename Derived>
4169Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004170TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004171 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4172 if (Base.isInvalid())
4173 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004174
Douglas Gregora16548e2009-08-11 05:31:07 +00004175 if (!getDerived().AlwaysRebuild() &&
4176 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004177 return SemaRef.Owned(E->Retain());
4178
Douglas Gregora16548e2009-08-11 05:31:07 +00004179 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004180 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004181 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4182 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4183 E->getAccessorLoc(),
4184 E->getAccessor());
4185}
Mike Stump11289f42009-09-09 15:08:12 +00004186
Douglas Gregora16548e2009-08-11 05:31:07 +00004187template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004188Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004189TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004190 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004191
Douglas Gregora16548e2009-08-11 05:31:07 +00004192 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4193 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4194 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4195 if (Init.isInvalid())
4196 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004197
Douglas Gregora16548e2009-08-11 05:31:07 +00004198 InitChanged = InitChanged || Init.get() != E->getInit(I);
4199 Inits.push_back(Init.takeAs<Expr>());
4200 }
Mike Stump11289f42009-09-09 15:08:12 +00004201
Douglas Gregora16548e2009-08-11 05:31:07 +00004202 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004203 return SemaRef.Owned(E->Retain());
4204
Douglas Gregora16548e2009-08-11 05:31:07 +00004205 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004206 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004207}
Mike Stump11289f42009-09-09 15:08:12 +00004208
Douglas Gregora16548e2009-08-11 05:31:07 +00004209template<typename Derived>
4210Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004211TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004212 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004213
Douglas Gregorebe10102009-08-20 07:17:43 +00004214 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004215 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4216 if (Init.isInvalid())
4217 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004218
Douglas Gregorebe10102009-08-20 07:17:43 +00004219 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004220 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4221 bool ExprChanged = false;
4222 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4223 DEnd = E->designators_end();
4224 D != DEnd; ++D) {
4225 if (D->isFieldDesignator()) {
4226 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4227 D->getDotLoc(),
4228 D->getFieldLoc()));
4229 continue;
4230 }
Mike Stump11289f42009-09-09 15:08:12 +00004231
Douglas Gregora16548e2009-08-11 05:31:07 +00004232 if (D->isArrayDesignator()) {
4233 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4234 if (Index.isInvalid())
4235 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004236
4237 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004238 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004239
Douglas Gregora16548e2009-08-11 05:31:07 +00004240 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4241 ArrayExprs.push_back(Index.release());
4242 continue;
4243 }
Mike Stump11289f42009-09-09 15:08:12 +00004244
Douglas Gregora16548e2009-08-11 05:31:07 +00004245 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004246 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004247 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4248 if (Start.isInvalid())
4249 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004250
Douglas Gregora16548e2009-08-11 05:31:07 +00004251 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4252 if (End.isInvalid())
4253 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004254
4255 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004256 End.get(),
4257 D->getLBracketLoc(),
4258 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004259
Douglas Gregora16548e2009-08-11 05:31:07 +00004260 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4261 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004262
Douglas Gregora16548e2009-08-11 05:31:07 +00004263 ArrayExprs.push_back(Start.release());
4264 ArrayExprs.push_back(End.release());
4265 }
Mike Stump11289f42009-09-09 15:08:12 +00004266
Douglas Gregora16548e2009-08-11 05:31:07 +00004267 if (!getDerived().AlwaysRebuild() &&
4268 Init.get() == E->getInit() &&
4269 !ExprChanged)
4270 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004271
Douglas Gregora16548e2009-08-11 05:31:07 +00004272 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4273 E->getEqualOrColonLoc(),
4274 E->usesGNUSyntax(), move(Init));
4275}
Mike Stump11289f42009-09-09 15:08:12 +00004276
Douglas Gregora16548e2009-08-11 05:31:07 +00004277template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004278Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004279TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004280 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004281 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4282
4283 // FIXME: Will we ever have proper type location here? Will we actually
4284 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004285 QualType T = getDerived().TransformType(E->getType());
4286 if (T.isNull())
4287 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004288
Douglas Gregora16548e2009-08-11 05:31:07 +00004289 if (!getDerived().AlwaysRebuild() &&
4290 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004291 return SemaRef.Owned(E->Retain());
4292
Douglas Gregora16548e2009-08-11 05:31:07 +00004293 return getDerived().RebuildImplicitValueInitExpr(T);
4294}
Mike Stump11289f42009-09-09 15:08:12 +00004295
Douglas Gregora16548e2009-08-11 05:31:07 +00004296template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004297Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004298TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004299 // FIXME: Do we want the type as written?
4300 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004301
Douglas Gregora16548e2009-08-11 05:31:07 +00004302 {
4303 // FIXME: Source location isn't quite accurate.
4304 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4305 T = getDerived().TransformType(E->getType());
4306 if (T.isNull())
4307 return SemaRef.ExprError();
4308 }
Mike Stump11289f42009-09-09 15:08:12 +00004309
Douglas Gregora16548e2009-08-11 05:31:07 +00004310 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4311 if (SubExpr.isInvalid())
4312 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004313
Douglas Gregora16548e2009-08-11 05:31:07 +00004314 if (!getDerived().AlwaysRebuild() &&
4315 T == E->getType() &&
4316 SubExpr.get() == E->getSubExpr())
4317 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004318
Douglas Gregora16548e2009-08-11 05:31:07 +00004319 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4320 T, E->getRParenLoc());
4321}
4322
4323template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004324Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004325TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004326 bool ArgumentChanged = false;
4327 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4328 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4329 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4330 if (Init.isInvalid())
4331 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004332
Douglas Gregora16548e2009-08-11 05:31:07 +00004333 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4334 Inits.push_back(Init.takeAs<Expr>());
4335 }
Mike Stump11289f42009-09-09 15:08:12 +00004336
Douglas Gregora16548e2009-08-11 05:31:07 +00004337 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4338 move_arg(Inits),
4339 E->getRParenLoc());
4340}
Mike Stump11289f42009-09-09 15:08:12 +00004341
Douglas Gregora16548e2009-08-11 05:31:07 +00004342/// \brief Transform an address-of-label expression.
4343///
4344/// By default, the transformation of an address-of-label expression always
4345/// rebuilds the expression, so that the label identifier can be resolved to
4346/// the corresponding label statement by semantic analysis.
4347template<typename Derived>
4348Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004349TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004350 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4351 E->getLabel());
4352}
Mike Stump11289f42009-09-09 15:08:12 +00004353
4354template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004355Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004356TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004357 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004358 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4359 if (SubStmt.isInvalid())
4360 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004361
Douglas Gregora16548e2009-08-11 05:31:07 +00004362 if (!getDerived().AlwaysRebuild() &&
4363 SubStmt.get() == E->getSubStmt())
4364 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004365
4366 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004367 move(SubStmt),
4368 E->getRParenLoc());
4369}
Mike Stump11289f42009-09-09 15:08:12 +00004370
Douglas Gregora16548e2009-08-11 05:31:07 +00004371template<typename Derived>
4372Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004373TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004374 QualType T1, T2;
4375 {
4376 // FIXME: Source location isn't quite accurate.
4377 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004378
Douglas Gregora16548e2009-08-11 05:31:07 +00004379 T1 = getDerived().TransformType(E->getArgType1());
4380 if (T1.isNull())
4381 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004382
Douglas Gregora16548e2009-08-11 05:31:07 +00004383 T2 = getDerived().TransformType(E->getArgType2());
4384 if (T2.isNull())
4385 return SemaRef.ExprError();
4386 }
4387
4388 if (!getDerived().AlwaysRebuild() &&
4389 T1 == E->getArgType1() &&
4390 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004391 return SemaRef.Owned(E->Retain());
4392
Douglas Gregora16548e2009-08-11 05:31:07 +00004393 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4394 T1, T2, E->getRParenLoc());
4395}
Mike Stump11289f42009-09-09 15:08:12 +00004396
Douglas Gregora16548e2009-08-11 05:31:07 +00004397template<typename Derived>
4398Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004399TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004400 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4401 if (Cond.isInvalid())
4402 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004403
Douglas Gregora16548e2009-08-11 05:31:07 +00004404 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4405 if (LHS.isInvalid())
4406 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004407
Douglas Gregora16548e2009-08-11 05:31:07 +00004408 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4409 if (RHS.isInvalid())
4410 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004411
Douglas Gregora16548e2009-08-11 05:31:07 +00004412 if (!getDerived().AlwaysRebuild() &&
4413 Cond.get() == E->getCond() &&
4414 LHS.get() == E->getLHS() &&
4415 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004416 return SemaRef.Owned(E->Retain());
4417
Douglas Gregora16548e2009-08-11 05:31:07 +00004418 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4419 move(Cond), move(LHS), move(RHS),
4420 E->getRParenLoc());
4421}
Mike Stump11289f42009-09-09 15:08:12 +00004422
Douglas Gregora16548e2009-08-11 05:31:07 +00004423template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004424Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004425TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004426 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004427}
4428
4429template<typename Derived>
4430Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004431TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004432 switch (E->getOperator()) {
4433 case OO_New:
4434 case OO_Delete:
4435 case OO_Array_New:
4436 case OO_Array_Delete:
4437 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4438 return SemaRef.ExprError();
4439
4440 case OO_Call: {
4441 // This is a call to an object's operator().
4442 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4443
4444 // Transform the object itself.
4445 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4446 if (Object.isInvalid())
4447 return SemaRef.ExprError();
4448
4449 // FIXME: Poor location information
4450 SourceLocation FakeLParenLoc
4451 = SemaRef.PP.getLocForEndOfToken(
4452 static_cast<Expr *>(Object.get())->getLocEnd());
4453
4454 // Transform the call arguments.
4455 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4456 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4457 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004458 if (getDerived().DropCallArgument(E->getArg(I)))
4459 break;
4460
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004461 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4462 if (Arg.isInvalid())
4463 return SemaRef.ExprError();
4464
4465 // FIXME: Poor source location information.
4466 SourceLocation FakeCommaLoc
4467 = SemaRef.PP.getLocForEndOfToken(
4468 static_cast<Expr *>(Arg.get())->getLocEnd());
4469 FakeCommaLocs.push_back(FakeCommaLoc);
4470 Args.push_back(Arg.release());
4471 }
4472
4473 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4474 move_arg(Args),
4475 FakeCommaLocs.data(),
4476 E->getLocEnd());
4477 }
4478
4479#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4480 case OO_##Name:
4481#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4482#include "clang/Basic/OperatorKinds.def"
4483 case OO_Subscript:
4484 // Handled below.
4485 break;
4486
4487 case OO_Conditional:
4488 llvm_unreachable("conditional operator is not actually overloadable");
4489 return SemaRef.ExprError();
4490
4491 case OO_None:
4492 case NUM_OVERLOADED_OPERATORS:
4493 llvm_unreachable("not an overloaded operator?");
4494 return SemaRef.ExprError();
4495 }
4496
Douglas Gregora16548e2009-08-11 05:31:07 +00004497 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4498 if (Callee.isInvalid())
4499 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004500
John McCall47f29ea2009-12-08 09:21:05 +00004501 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004502 if (First.isInvalid())
4503 return SemaRef.ExprError();
4504
4505 OwningExprResult Second(SemaRef);
4506 if (E->getNumArgs() == 2) {
4507 Second = getDerived().TransformExpr(E->getArg(1));
4508 if (Second.isInvalid())
4509 return SemaRef.ExprError();
4510 }
Mike Stump11289f42009-09-09 15:08:12 +00004511
Douglas Gregora16548e2009-08-11 05:31:07 +00004512 if (!getDerived().AlwaysRebuild() &&
4513 Callee.get() == E->getCallee() &&
4514 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004515 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4516 return SemaRef.Owned(E->Retain());
4517
Douglas Gregora16548e2009-08-11 05:31:07 +00004518 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4519 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004520 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004521 move(First),
4522 move(Second));
4523}
Mike Stump11289f42009-09-09 15:08:12 +00004524
Douglas Gregora16548e2009-08-11 05:31:07 +00004525template<typename Derived>
4526Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004527TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4528 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004529}
Mike Stump11289f42009-09-09 15:08:12 +00004530
Douglas Gregora16548e2009-08-11 05:31:07 +00004531template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004532Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004533TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004534 TypeSourceInfo *OldT;
4535 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004536 {
4537 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004538 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004539 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4540 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004541
John McCall97513962010-01-15 18:39:57 +00004542 OldT = E->getTypeInfoAsWritten();
4543 NewT = getDerived().TransformType(OldT);
4544 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004545 return SemaRef.ExprError();
4546 }
Mike Stump11289f42009-09-09 15:08:12 +00004547
Douglas Gregor6131b442009-12-12 18:16:41 +00004548 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004549 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004550 if (SubExpr.isInvalid())
4551 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004552
Douglas Gregora16548e2009-08-11 05:31:07 +00004553 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004554 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004555 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004556 return SemaRef.Owned(E->Retain());
4557
Douglas Gregora16548e2009-08-11 05:31:07 +00004558 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004559 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004560 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4561 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4562 SourceLocation FakeRParenLoc
4563 = SemaRef.PP.getLocForEndOfToken(
4564 E->getSubExpr()->getSourceRange().getEnd());
4565 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004566 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004567 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004568 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004569 FakeRAngleLoc,
4570 FakeRAngleLoc,
4571 move(SubExpr),
4572 FakeRParenLoc);
4573}
Mike Stump11289f42009-09-09 15:08:12 +00004574
Douglas Gregora16548e2009-08-11 05:31:07 +00004575template<typename Derived>
4576Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004577TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4578 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004579}
Mike Stump11289f42009-09-09 15:08:12 +00004580
4581template<typename Derived>
4582Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004583TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4584 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004585}
4586
Douglas Gregora16548e2009-08-11 05:31:07 +00004587template<typename Derived>
4588Sema::OwningExprResult
4589TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004590 CXXReinterpretCastExpr *E) {
4591 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004592}
Mike Stump11289f42009-09-09 15:08:12 +00004593
Douglas Gregora16548e2009-08-11 05:31:07 +00004594template<typename Derived>
4595Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004596TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4597 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004598}
Mike Stump11289f42009-09-09 15:08:12 +00004599
Douglas Gregora16548e2009-08-11 05:31:07 +00004600template<typename Derived>
4601Sema::OwningExprResult
4602TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004603 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004604 TypeSourceInfo *OldT;
4605 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004606 {
4607 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004608
John McCall97513962010-01-15 18:39:57 +00004609 OldT = E->getTypeInfoAsWritten();
4610 NewT = getDerived().TransformType(OldT);
4611 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004612 return SemaRef.ExprError();
4613 }
Mike Stump11289f42009-09-09 15:08:12 +00004614
Douglas Gregor6131b442009-12-12 18:16:41 +00004615 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004616 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004617 if (SubExpr.isInvalid())
4618 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004619
Douglas Gregora16548e2009-08-11 05:31:07 +00004620 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004621 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004622 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004623 return SemaRef.Owned(E->Retain());
4624
Douglas Gregora16548e2009-08-11 05:31:07 +00004625 // FIXME: The end of the type's source range is wrong
4626 return getDerived().RebuildCXXFunctionalCastExpr(
4627 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004628 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004629 /*FIXME:*/E->getSubExpr()->getLocStart(),
4630 move(SubExpr),
4631 E->getRParenLoc());
4632}
Mike Stump11289f42009-09-09 15:08:12 +00004633
Douglas Gregora16548e2009-08-11 05:31:07 +00004634template<typename Derived>
4635Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004636TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004637 if (E->isTypeOperand()) {
4638 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004639
Douglas Gregora16548e2009-08-11 05:31:07 +00004640 QualType T = getDerived().TransformType(E->getTypeOperand());
4641 if (T.isNull())
4642 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004643
Douglas Gregora16548e2009-08-11 05:31:07 +00004644 if (!getDerived().AlwaysRebuild() &&
4645 T == E->getTypeOperand())
4646 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004647
Douglas Gregora16548e2009-08-11 05:31:07 +00004648 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4649 /*FIXME:*/E->getLocStart(),
4650 T,
4651 E->getLocEnd());
4652 }
Mike Stump11289f42009-09-09 15:08:12 +00004653
Douglas Gregora16548e2009-08-11 05:31:07 +00004654 // We don't know whether the expression is potentially evaluated until
4655 // after we perform semantic analysis, so the expression is potentially
4656 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004657 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004658 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004659
Douglas Gregora16548e2009-08-11 05:31:07 +00004660 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4661 if (SubExpr.isInvalid())
4662 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004663
Douglas Gregora16548e2009-08-11 05:31:07 +00004664 if (!getDerived().AlwaysRebuild() &&
4665 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004666 return SemaRef.Owned(E->Retain());
4667
Douglas Gregora16548e2009-08-11 05:31:07 +00004668 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4669 /*FIXME:*/E->getLocStart(),
4670 move(SubExpr),
4671 E->getLocEnd());
4672}
4673
4674template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004675Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004676TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004677 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004678}
Mike Stump11289f42009-09-09 15:08:12 +00004679
Douglas Gregora16548e2009-08-11 05:31:07 +00004680template<typename Derived>
4681Sema::OwningExprResult
4682TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004683 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004684 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004685}
Mike Stump11289f42009-09-09 15:08:12 +00004686
Douglas Gregora16548e2009-08-11 05:31:07 +00004687template<typename Derived>
4688Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004689TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004690 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004691
Douglas Gregora16548e2009-08-11 05:31:07 +00004692 QualType T = getDerived().TransformType(E->getType());
4693 if (T.isNull())
4694 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004695
Douglas Gregora16548e2009-08-11 05:31:07 +00004696 if (!getDerived().AlwaysRebuild() &&
4697 T == E->getType())
4698 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004699
Douglas Gregorb15af892010-01-07 23:12:05 +00004700 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004701}
Mike Stump11289f42009-09-09 15:08:12 +00004702
Douglas Gregora16548e2009-08-11 05:31:07 +00004703template<typename Derived>
4704Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004705TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004706 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4707 if (SubExpr.isInvalid())
4708 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004709
Douglas Gregora16548e2009-08-11 05:31:07 +00004710 if (!getDerived().AlwaysRebuild() &&
4711 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004712 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004713
4714 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4715}
Mike Stump11289f42009-09-09 15:08:12 +00004716
Douglas Gregora16548e2009-08-11 05:31:07 +00004717template<typename Derived>
4718Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004719TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004720 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004721 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
4722 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004723 if (!Param)
4724 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004725
Chandler Carruth794da4c2010-02-08 06:42:49 +00004726 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004727 Param == E->getParam())
4728 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004729
Douglas Gregor033f6752009-12-23 23:03:06 +00004730 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00004731}
Mike Stump11289f42009-09-09 15:08:12 +00004732
Douglas Gregora16548e2009-08-11 05:31:07 +00004733template<typename Derived>
4734Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004735TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004736 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4737
4738 QualType T = getDerived().TransformType(E->getType());
4739 if (T.isNull())
4740 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004741
Douglas Gregora16548e2009-08-11 05:31:07 +00004742 if (!getDerived().AlwaysRebuild() &&
4743 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004744 return SemaRef.Owned(E->Retain());
4745
4746 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004747 /*FIXME:*/E->getTypeBeginLoc(),
4748 T,
4749 E->getRParenLoc());
4750}
Mike Stump11289f42009-09-09 15:08:12 +00004751
Douglas Gregora16548e2009-08-11 05:31:07 +00004752template<typename Derived>
4753Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004754TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004755 // Transform the type that we're allocating
4756 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4757 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4758 if (AllocType.isNull())
4759 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004760
Douglas Gregora16548e2009-08-11 05:31:07 +00004761 // Transform the size of the array we're allocating (if any).
4762 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4763 if (ArraySize.isInvalid())
4764 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004765
Douglas Gregora16548e2009-08-11 05:31:07 +00004766 // Transform the placement arguments (if any).
4767 bool ArgumentChanged = false;
4768 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4769 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4770 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4771 if (Arg.isInvalid())
4772 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004773
Douglas Gregora16548e2009-08-11 05:31:07 +00004774 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4775 PlacementArgs.push_back(Arg.take());
4776 }
Mike Stump11289f42009-09-09 15:08:12 +00004777
Douglas Gregorebe10102009-08-20 07:17:43 +00004778 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004779 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4780 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4781 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4782 if (Arg.isInvalid())
4783 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004784
Douglas Gregora16548e2009-08-11 05:31:07 +00004785 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4786 ConstructorArgs.push_back(Arg.take());
4787 }
Mike Stump11289f42009-09-09 15:08:12 +00004788
Douglas Gregord2d9da02010-02-26 00:38:10 +00004789 // Transform constructor, new operator, and delete operator.
4790 CXXConstructorDecl *Constructor = 0;
4791 if (E->getConstructor()) {
4792 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004793 getDerived().TransformDecl(E->getLocStart(),
4794 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004795 if (!Constructor)
4796 return SemaRef.ExprError();
4797 }
4798
4799 FunctionDecl *OperatorNew = 0;
4800 if (E->getOperatorNew()) {
4801 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004802 getDerived().TransformDecl(E->getLocStart(),
4803 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004804 if (!OperatorNew)
4805 return SemaRef.ExprError();
4806 }
4807
4808 FunctionDecl *OperatorDelete = 0;
4809 if (E->getOperatorDelete()) {
4810 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004811 getDerived().TransformDecl(E->getLocStart(),
4812 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004813 if (!OperatorDelete)
4814 return SemaRef.ExprError();
4815 }
4816
Douglas Gregora16548e2009-08-11 05:31:07 +00004817 if (!getDerived().AlwaysRebuild() &&
4818 AllocType == E->getAllocatedType() &&
4819 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004820 Constructor == E->getConstructor() &&
4821 OperatorNew == E->getOperatorNew() &&
4822 OperatorDelete == E->getOperatorDelete() &&
4823 !ArgumentChanged) {
4824 // Mark any declarations we need as referenced.
4825 // FIXME: instantiation-specific.
4826 if (Constructor)
4827 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
4828 if (OperatorNew)
4829 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
4830 if (OperatorDelete)
4831 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004832 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004833 }
Mike Stump11289f42009-09-09 15:08:12 +00004834
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004835 if (!ArraySize.get()) {
4836 // If no array size was specified, but the new expression was
4837 // instantiated with an array type (e.g., "new T" where T is
4838 // instantiated with "int[4]"), extract the outer bound from the
4839 // array type as our array size. We do this with constant and
4840 // dependently-sized array types.
4841 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4842 if (!ArrayT) {
4843 // Do nothing
4844 } else if (const ConstantArrayType *ConsArrayT
4845 = dyn_cast<ConstantArrayType>(ArrayT)) {
4846 ArraySize
4847 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4848 ConsArrayT->getSize(),
4849 SemaRef.Context.getSizeType(),
4850 /*FIXME:*/E->getLocStart()));
4851 AllocType = ConsArrayT->getElementType();
4852 } else if (const DependentSizedArrayType *DepArrayT
4853 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4854 if (DepArrayT->getSizeExpr()) {
4855 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4856 AllocType = DepArrayT->getElementType();
4857 }
4858 }
4859 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004860 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4861 E->isGlobalNew(),
4862 /*FIXME:*/E->getLocStart(),
4863 move_arg(PlacementArgs),
4864 /*FIXME:*/E->getLocStart(),
4865 E->isParenTypeId(),
4866 AllocType,
4867 /*FIXME:*/E->getLocStart(),
4868 /*FIXME:*/SourceRange(),
4869 move(ArraySize),
4870 /*FIXME:*/E->getLocStart(),
4871 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004872 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004873}
Mike Stump11289f42009-09-09 15:08:12 +00004874
Douglas Gregora16548e2009-08-11 05:31:07 +00004875template<typename Derived>
4876Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004877TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004878 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4879 if (Operand.isInvalid())
4880 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004881
Douglas Gregord2d9da02010-02-26 00:38:10 +00004882 // Transform the delete operator, if known.
4883 FunctionDecl *OperatorDelete = 0;
4884 if (E->getOperatorDelete()) {
4885 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004886 getDerived().TransformDecl(E->getLocStart(),
4887 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004888 if (!OperatorDelete)
4889 return SemaRef.ExprError();
4890 }
4891
Douglas Gregora16548e2009-08-11 05:31:07 +00004892 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004893 Operand.get() == E->getArgument() &&
4894 OperatorDelete == E->getOperatorDelete()) {
4895 // Mark any declarations we need as referenced.
4896 // FIXME: instantiation-specific.
4897 if (OperatorDelete)
4898 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004899 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004900 }
Mike Stump11289f42009-09-09 15:08:12 +00004901
Douglas Gregora16548e2009-08-11 05:31:07 +00004902 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4903 E->isGlobalDelete(),
4904 E->isArrayForm(),
4905 move(Operand));
4906}
Mike Stump11289f42009-09-09 15:08:12 +00004907
Douglas Gregora16548e2009-08-11 05:31:07 +00004908template<typename Derived>
4909Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004910TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004911 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004912 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4913 if (Base.isInvalid())
4914 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004915
Douglas Gregor678f90d2010-02-25 01:56:36 +00004916 Sema::TypeTy *ObjectTypePtr = 0;
4917 bool MayBePseudoDestructor = false;
4918 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4919 E->getOperatorLoc(),
4920 E->isArrow()? tok::arrow : tok::period,
4921 ObjectTypePtr,
4922 MayBePseudoDestructor);
4923 if (Base.isInvalid())
4924 return SemaRef.ExprError();
4925
4926 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004927 NestedNameSpecifier *Qualifier
4928 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00004929 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00004930 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004931 if (E->getQualifier() && !Qualifier)
4932 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004933
Douglas Gregor678f90d2010-02-25 01:56:36 +00004934 PseudoDestructorTypeStorage Destroyed;
4935 if (E->getDestroyedTypeInfo()) {
4936 TypeSourceInfo *DestroyedTypeInfo
4937 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
4938 if (!DestroyedTypeInfo)
4939 return SemaRef.ExprError();
4940 Destroyed = DestroyedTypeInfo;
4941 } else if (ObjectType->isDependentType()) {
4942 // We aren't likely to be able to resolve the identifier down to a type
4943 // now anyway, so just retain the identifier.
4944 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
4945 E->getDestroyedTypeLoc());
4946 } else {
4947 // Look for a destructor known with the given name.
4948 CXXScopeSpec SS;
4949 if (Qualifier) {
4950 SS.setScopeRep(Qualifier);
4951 SS.setRange(E->getQualifierRange());
4952 }
4953
4954 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
4955 *E->getDestroyedTypeIdentifier(),
4956 E->getDestroyedTypeLoc(),
4957 /*Scope=*/0,
4958 SS, ObjectTypePtr,
4959 false);
4960 if (!T)
4961 return SemaRef.ExprError();
4962
4963 Destroyed
4964 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
4965 E->getDestroyedTypeLoc());
4966 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004967
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004968 TypeSourceInfo *ScopeTypeInfo = 0;
4969 if (E->getScopeTypeInfo()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00004970 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
4971 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004972 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00004973 return SemaRef.ExprError();
4974 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004975
Douglas Gregorad8a3362009-09-04 17:36:40 +00004976 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4977 E->getOperatorLoc(),
4978 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00004979 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004980 E->getQualifierRange(),
4981 ScopeTypeInfo,
4982 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00004983 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00004984 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004985}
Mike Stump11289f42009-09-09 15:08:12 +00004986
Douglas Gregorad8a3362009-09-04 17:36:40 +00004987template<typename Derived>
4988Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004989TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004990 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00004991 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4992
4993 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4994 Sema::LookupOrdinaryName);
4995
4996 // Transform all the decls.
4997 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4998 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004999 NamedDecl *InstD = static_cast<NamedDecl*>(
5000 getDerived().TransformDecl(Old->getNameLoc(),
5001 *I));
John McCall84d87672009-12-10 09:41:52 +00005002 if (!InstD) {
5003 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5004 // This can happen because of dependent hiding.
5005 if (isa<UsingShadowDecl>(*I))
5006 continue;
5007 else
5008 return SemaRef.ExprError();
5009 }
John McCalle66edc12009-11-24 19:00:30 +00005010
5011 // Expand using declarations.
5012 if (isa<UsingDecl>(InstD)) {
5013 UsingDecl *UD = cast<UsingDecl>(InstD);
5014 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5015 E = UD->shadow_end(); I != E; ++I)
5016 R.addDecl(*I);
5017 continue;
5018 }
5019
5020 R.addDecl(InstD);
5021 }
5022
5023 // Resolve a kind, but don't do any further analysis. If it's
5024 // ambiguous, the callee needs to deal with it.
5025 R.resolveKind();
5026
5027 // Rebuild the nested-name qualifier, if present.
5028 CXXScopeSpec SS;
5029 NestedNameSpecifier *Qualifier = 0;
5030 if (Old->getQualifier()) {
5031 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005032 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005033 if (!Qualifier)
5034 return SemaRef.ExprError();
5035
5036 SS.setScopeRep(Qualifier);
5037 SS.setRange(Old->getQualifierRange());
5038 }
5039
5040 // If we have no template arguments, it's a normal declaration name.
5041 if (!Old->hasExplicitTemplateArgs())
5042 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5043
5044 // If we have template arguments, rebuild them, then rebuild the
5045 // templateid expression.
5046 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5047 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5048 TemplateArgumentLoc Loc;
5049 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5050 return SemaRef.ExprError();
5051 TransArgs.addArgument(Loc);
5052 }
5053
5054 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5055 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005056}
Mike Stump11289f42009-09-09 15:08:12 +00005057
Douglas Gregora16548e2009-08-11 05:31:07 +00005058template<typename Derived>
5059Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005060TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005061 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005062
Douglas Gregora16548e2009-08-11 05:31:07 +00005063 QualType T = getDerived().TransformType(E->getQueriedType());
5064 if (T.isNull())
5065 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005066
Douglas Gregora16548e2009-08-11 05:31:07 +00005067 if (!getDerived().AlwaysRebuild() &&
5068 T == E->getQueriedType())
5069 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005070
Douglas Gregora16548e2009-08-11 05:31:07 +00005071 // FIXME: Bad location information
5072 SourceLocation FakeLParenLoc
5073 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005074
5075 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005076 E->getLocStart(),
5077 /*FIXME:*/FakeLParenLoc,
5078 T,
5079 E->getLocEnd());
5080}
Mike Stump11289f42009-09-09 15:08:12 +00005081
Douglas Gregora16548e2009-08-11 05:31:07 +00005082template<typename Derived>
5083Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005084TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005085 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005086 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005087 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005088 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005089 if (!NNS)
5090 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005091
5092 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005093 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5094 if (!Name)
5095 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005096
John McCalle66edc12009-11-24 19:00:30 +00005097 if (!E->hasExplicitTemplateArgs()) {
5098 if (!getDerived().AlwaysRebuild() &&
5099 NNS == E->getQualifier() &&
5100 Name == E->getDeclName())
5101 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005102
John McCalle66edc12009-11-24 19:00:30 +00005103 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5104 E->getQualifierRange(),
5105 Name, E->getLocation(),
5106 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005107 }
John McCall6b51f282009-11-23 01:53:49 +00005108
5109 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005110 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005111 TemplateArgumentLoc Loc;
5112 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005113 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005114 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005115 }
5116
John McCalle66edc12009-11-24 19:00:30 +00005117 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5118 E->getQualifierRange(),
5119 Name, E->getLocation(),
5120 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005121}
5122
5123template<typename Derived>
5124Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005125TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005126 // CXXConstructExprs are always implicit, so when we have a
5127 // 1-argument construction we just transform that argument.
5128 if (E->getNumArgs() == 1 ||
5129 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5130 return getDerived().TransformExpr(E->getArg(0));
5131
Douglas Gregora16548e2009-08-11 05:31:07 +00005132 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5133
5134 QualType T = getDerived().TransformType(E->getType());
5135 if (T.isNull())
5136 return SemaRef.ExprError();
5137
5138 CXXConstructorDecl *Constructor
5139 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005140 getDerived().TransformDecl(E->getLocStart(),
5141 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005142 if (!Constructor)
5143 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005144
Douglas Gregora16548e2009-08-11 05:31:07 +00005145 bool ArgumentChanged = false;
5146 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005147 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005148 ArgEnd = E->arg_end();
5149 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005150 if (getDerived().DropCallArgument(*Arg)) {
5151 ArgumentChanged = true;
5152 break;
5153 }
5154
Douglas Gregora16548e2009-08-11 05:31:07 +00005155 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5156 if (TransArg.isInvalid())
5157 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005158
Douglas Gregora16548e2009-08-11 05:31:07 +00005159 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5160 Args.push_back(TransArg.takeAs<Expr>());
5161 }
5162
5163 if (!getDerived().AlwaysRebuild() &&
5164 T == E->getType() &&
5165 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005166 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005167 // Mark the constructor as referenced.
5168 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005169 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005170 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005171 }
Mike Stump11289f42009-09-09 15:08:12 +00005172
Douglas Gregordb121ba2009-12-14 16:27:04 +00005173 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5174 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005175 move_arg(Args));
5176}
Mike Stump11289f42009-09-09 15:08:12 +00005177
Douglas Gregora16548e2009-08-11 05:31:07 +00005178/// \brief Transform a C++ temporary-binding expression.
5179///
Douglas Gregor363b1512009-12-24 18:51:59 +00005180/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5181/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005182template<typename Derived>
5183Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005184TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005185 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005186}
Mike Stump11289f42009-09-09 15:08:12 +00005187
Anders Carlssonba6c4372010-01-29 02:39:32 +00005188/// \brief Transform a C++ reference-binding expression.
5189///
5190/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5191/// transform the subexpression and return that.
5192template<typename Derived>
5193Sema::OwningExprResult
5194TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5195 return getDerived().TransformExpr(E->getSubExpr());
5196}
5197
Mike Stump11289f42009-09-09 15:08:12 +00005198/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005199/// be destroyed after the expression is evaluated.
5200///
Douglas Gregor363b1512009-12-24 18:51:59 +00005201/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5202/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005203template<typename Derived>
5204Sema::OwningExprResult
5205TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005206 CXXExprWithTemporaries *E) {
5207 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005208}
Mike Stump11289f42009-09-09 15:08:12 +00005209
Douglas Gregora16548e2009-08-11 05:31:07 +00005210template<typename Derived>
5211Sema::OwningExprResult
5212TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005213 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005214 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5215 QualType T = getDerived().TransformType(E->getType());
5216 if (T.isNull())
5217 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005218
Douglas Gregora16548e2009-08-11 05:31:07 +00005219 CXXConstructorDecl *Constructor
5220 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005221 getDerived().TransformDecl(E->getLocStart(),
5222 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005223 if (!Constructor)
5224 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005225
Douglas Gregora16548e2009-08-11 05:31:07 +00005226 bool ArgumentChanged = false;
5227 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5228 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005229 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005230 ArgEnd = E->arg_end();
5231 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005232 if (getDerived().DropCallArgument(*Arg)) {
5233 ArgumentChanged = true;
5234 break;
5235 }
5236
Douglas Gregora16548e2009-08-11 05:31:07 +00005237 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5238 if (TransArg.isInvalid())
5239 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005240
Douglas Gregora16548e2009-08-11 05:31:07 +00005241 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5242 Args.push_back((Expr *)TransArg.release());
5243 }
Mike Stump11289f42009-09-09 15:08:12 +00005244
Douglas Gregora16548e2009-08-11 05:31:07 +00005245 if (!getDerived().AlwaysRebuild() &&
5246 T == E->getType() &&
5247 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005248 !ArgumentChanged) {
5249 // FIXME: Instantiation-specific
5250 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005251 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005252 }
Mike Stump11289f42009-09-09 15:08:12 +00005253
Douglas Gregora16548e2009-08-11 05:31:07 +00005254 // FIXME: Bogus location information
5255 SourceLocation CommaLoc;
5256 if (Args.size() > 1) {
5257 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005258 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005259 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5260 }
5261 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5262 T,
5263 /*FIXME:*/E->getTypeBeginLoc(),
5264 move_arg(Args),
5265 &CommaLoc,
5266 E->getLocEnd());
5267}
Mike Stump11289f42009-09-09 15:08:12 +00005268
Douglas Gregora16548e2009-08-11 05:31:07 +00005269template<typename Derived>
5270Sema::OwningExprResult
5271TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005272 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005273 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5274 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5275 if (T.isNull())
5276 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005277
Douglas Gregora16548e2009-08-11 05:31:07 +00005278 bool ArgumentChanged = false;
5279 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5280 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5281 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5282 ArgEnd = E->arg_end();
5283 Arg != ArgEnd; ++Arg) {
5284 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5285 if (TransArg.isInvalid())
5286 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005287
Douglas Gregora16548e2009-08-11 05:31:07 +00005288 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5289 FakeCommaLocs.push_back(
5290 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5291 Args.push_back(TransArg.takeAs<Expr>());
5292 }
Mike Stump11289f42009-09-09 15:08:12 +00005293
Douglas Gregora16548e2009-08-11 05:31:07 +00005294 if (!getDerived().AlwaysRebuild() &&
5295 T == E->getTypeAsWritten() &&
5296 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005297 return SemaRef.Owned(E->Retain());
5298
Douglas Gregora16548e2009-08-11 05:31:07 +00005299 // FIXME: we're faking the locations of the commas
5300 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5301 T,
5302 E->getLParenLoc(),
5303 move_arg(Args),
5304 FakeCommaLocs.data(),
5305 E->getRParenLoc());
5306}
Mike Stump11289f42009-09-09 15:08:12 +00005307
Douglas Gregora16548e2009-08-11 05:31:07 +00005308template<typename Derived>
5309Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005310TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005311 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005312 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005313 OwningExprResult Base(SemaRef, (Expr*) 0);
5314 Expr *OldBase;
5315 QualType BaseType;
5316 QualType ObjectType;
5317 if (!E->isImplicitAccess()) {
5318 OldBase = E->getBase();
5319 Base = getDerived().TransformExpr(OldBase);
5320 if (Base.isInvalid())
5321 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005322
John McCall2d74de92009-12-01 22:10:20 +00005323 // Start the member reference and compute the object's type.
5324 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005325 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005326 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5327 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005328 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005329 ObjectTy,
5330 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005331 if (Base.isInvalid())
5332 return SemaRef.ExprError();
5333
5334 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5335 BaseType = ((Expr*) Base.get())->getType();
5336 } else {
5337 OldBase = 0;
5338 BaseType = getDerived().TransformType(E->getBaseType());
5339 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5340 }
Mike Stump11289f42009-09-09 15:08:12 +00005341
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005342 // Transform the first part of the nested-name-specifier that qualifies
5343 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005344 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005345 = getDerived().TransformFirstQualifierInScope(
5346 E->getFirstQualifierFoundInScope(),
5347 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005348
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005349 NestedNameSpecifier *Qualifier = 0;
5350 if (E->getQualifier()) {
5351 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5352 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005353 ObjectType,
5354 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005355 if (!Qualifier)
5356 return SemaRef.ExprError();
5357 }
Mike Stump11289f42009-09-09 15:08:12 +00005358
5359 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005360 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005361 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005362 if (!Name)
5363 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005364
John McCall2d74de92009-12-01 22:10:20 +00005365 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005366 // This is a reference to a member without an explicitly-specified
5367 // template argument list. Optimize for this common case.
5368 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005369 Base.get() == OldBase &&
5370 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005371 Qualifier == E->getQualifier() &&
5372 Name == E->getMember() &&
5373 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005374 return SemaRef.Owned(E->Retain());
5375
John McCall8cd78132009-11-19 22:55:06 +00005376 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005377 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005378 E->isArrow(),
5379 E->getOperatorLoc(),
5380 Qualifier,
5381 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005382 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005383 Name,
5384 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005385 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005386 }
5387
John McCall6b51f282009-11-23 01:53:49 +00005388 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005389 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005390 TemplateArgumentLoc Loc;
5391 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005392 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005393 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005394 }
Mike Stump11289f42009-09-09 15:08:12 +00005395
John McCall8cd78132009-11-19 22:55:06 +00005396 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005397 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005398 E->isArrow(),
5399 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005400 Qualifier,
5401 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005402 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005403 Name,
5404 E->getMemberLoc(),
5405 &TransArgs);
5406}
5407
5408template<typename Derived>
5409Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005410TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005411 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005412 OwningExprResult Base(SemaRef, (Expr*) 0);
5413 QualType BaseType;
5414 if (!Old->isImplicitAccess()) {
5415 Base = getDerived().TransformExpr(Old->getBase());
5416 if (Base.isInvalid())
5417 return SemaRef.ExprError();
5418 BaseType = ((Expr*) Base.get())->getType();
5419 } else {
5420 BaseType = getDerived().TransformType(Old->getBaseType());
5421 }
John McCall10eae182009-11-30 22:42:35 +00005422
5423 NestedNameSpecifier *Qualifier = 0;
5424 if (Old->getQualifier()) {
5425 Qualifier
5426 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005427 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005428 if (Qualifier == 0)
5429 return SemaRef.ExprError();
5430 }
5431
5432 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5433 Sema::LookupOrdinaryName);
5434
5435 // Transform all the decls.
5436 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5437 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005438 NamedDecl *InstD = static_cast<NamedDecl*>(
5439 getDerived().TransformDecl(Old->getMemberLoc(),
5440 *I));
John McCall84d87672009-12-10 09:41:52 +00005441 if (!InstD) {
5442 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5443 // This can happen because of dependent hiding.
5444 if (isa<UsingShadowDecl>(*I))
5445 continue;
5446 else
5447 return SemaRef.ExprError();
5448 }
John McCall10eae182009-11-30 22:42:35 +00005449
5450 // Expand using declarations.
5451 if (isa<UsingDecl>(InstD)) {
5452 UsingDecl *UD = cast<UsingDecl>(InstD);
5453 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5454 E = UD->shadow_end(); I != E; ++I)
5455 R.addDecl(*I);
5456 continue;
5457 }
5458
5459 R.addDecl(InstD);
5460 }
5461
5462 R.resolveKind();
5463
5464 TemplateArgumentListInfo TransArgs;
5465 if (Old->hasExplicitTemplateArgs()) {
5466 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5467 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5468 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5469 TemplateArgumentLoc Loc;
5470 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5471 Loc))
5472 return SemaRef.ExprError();
5473 TransArgs.addArgument(Loc);
5474 }
5475 }
John McCall38836f02010-01-15 08:34:02 +00005476
5477 // FIXME: to do this check properly, we will need to preserve the
5478 // first-qualifier-in-scope here, just in case we had a dependent
5479 // base (and therefore couldn't do the check) and a
5480 // nested-name-qualifier (and therefore could do the lookup).
5481 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005482
5483 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005484 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005485 Old->getOperatorLoc(),
5486 Old->isArrow(),
5487 Qualifier,
5488 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005489 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005490 R,
5491 (Old->hasExplicitTemplateArgs()
5492 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005493}
5494
5495template<typename Derived>
5496Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005497TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005498 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005499}
5500
Mike Stump11289f42009-09-09 15:08:12 +00005501template<typename Derived>
5502Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005503TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00005504 TypeSourceInfo *EncodedTypeInfo
5505 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5506 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005507 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005508
Douglas Gregora16548e2009-08-11 05:31:07 +00005509 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00005510 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005511 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005512
5513 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00005514 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005515 E->getRParenLoc());
5516}
Mike Stump11289f42009-09-09 15:08:12 +00005517
Douglas Gregora16548e2009-08-11 05:31:07 +00005518template<typename Derived>
5519Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005520TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005521 // Transform arguments.
5522 bool ArgChanged = false;
5523 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5524 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5525 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5526 if (Arg.isInvalid())
5527 return SemaRef.ExprError();
5528
5529 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5530 Args.push_back(Arg.takeAs<Expr>());
5531 }
5532
5533 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5534 // Class message: transform the receiver type.
5535 TypeSourceInfo *ReceiverTypeInfo
5536 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5537 if (!ReceiverTypeInfo)
5538 return SemaRef.ExprError();
5539
5540 // If nothing changed, just retain the existing message send.
5541 if (!getDerived().AlwaysRebuild() &&
5542 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
5543 return SemaRef.Owned(E->Retain());
5544
5545 // Build a new class message send.
5546 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
5547 E->getSelector(),
5548 E->getMethodDecl(),
5549 E->getLeftLoc(),
5550 move_arg(Args),
5551 E->getRightLoc());
5552 }
5553
5554 // Instance message: transform the receiver
5555 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
5556 "Only class and instance messages may be instantiated");
5557 OwningExprResult Receiver
5558 = getDerived().TransformExpr(E->getInstanceReceiver());
5559 if (Receiver.isInvalid())
5560 return SemaRef.ExprError();
5561
5562 // If nothing changed, just retain the existing message send.
5563 if (!getDerived().AlwaysRebuild() &&
5564 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
5565 return SemaRef.Owned(E->Retain());
5566
5567 // Build a new instance message send.
5568 return getDerived().RebuildObjCMessageExpr(move(Receiver),
5569 E->getSelector(),
5570 E->getMethodDecl(),
5571 E->getLeftLoc(),
5572 move_arg(Args),
5573 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005574}
5575
Mike Stump11289f42009-09-09 15:08:12 +00005576template<typename Derived>
5577Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005578TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005579 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005580}
5581
Mike Stump11289f42009-09-09 15:08:12 +00005582template<typename Derived>
5583Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005584TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005585 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005586}
5587
Mike Stump11289f42009-09-09 15:08:12 +00005588template<typename Derived>
5589Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005590TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005591 // FIXME: Implement this!
5592 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005593 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005594}
5595
Mike Stump11289f42009-09-09 15:08:12 +00005596template<typename Derived>
5597Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005598TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005599 // FIXME: Implement this!
5600 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005601 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005602}
5603
Mike Stump11289f42009-09-09 15:08:12 +00005604template<typename Derived>
5605Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005606TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005607 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005608 // FIXME: Implement this!
5609 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005610 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005611}
5612
Mike Stump11289f42009-09-09 15:08:12 +00005613template<typename Derived>
5614Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005615TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005616 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00005617 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005618}
5619
Mike Stump11289f42009-09-09 15:08:12 +00005620template<typename Derived>
5621Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005622TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005623 // FIXME: Implement this!
5624 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005625 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005626}
5627
Mike Stump11289f42009-09-09 15:08:12 +00005628template<typename Derived>
5629Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005630TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005631 bool ArgumentChanged = false;
5632 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5633 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5634 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5635 if (SubExpr.isInvalid())
5636 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005637
Douglas Gregora16548e2009-08-11 05:31:07 +00005638 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5639 SubExprs.push_back(SubExpr.takeAs<Expr>());
5640 }
Mike Stump11289f42009-09-09 15:08:12 +00005641
Douglas Gregora16548e2009-08-11 05:31:07 +00005642 if (!getDerived().AlwaysRebuild() &&
5643 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005644 return SemaRef.Owned(E->Retain());
5645
Douglas Gregora16548e2009-08-11 05:31:07 +00005646 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5647 move_arg(SubExprs),
5648 E->getRParenLoc());
5649}
5650
Mike Stump11289f42009-09-09 15:08:12 +00005651template<typename Derived>
5652Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005653TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005654 // FIXME: Implement this!
5655 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005656 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005657}
5658
Mike Stump11289f42009-09-09 15:08:12 +00005659template<typename Derived>
5660Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005661TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005662 // FIXME: Implement this!
5663 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005664 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005665}
Mike Stump11289f42009-09-09 15:08:12 +00005666
Douglas Gregora16548e2009-08-11 05:31:07 +00005667//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005668// Type reconstruction
5669//===----------------------------------------------------------------------===//
5670
Mike Stump11289f42009-09-09 15:08:12 +00005671template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005672QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5673 SourceLocation Star) {
5674 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005675 getDerived().getBaseEntity());
5676}
5677
Mike Stump11289f42009-09-09 15:08:12 +00005678template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005679QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5680 SourceLocation Star) {
5681 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005682 getDerived().getBaseEntity());
5683}
5684
Mike Stump11289f42009-09-09 15:08:12 +00005685template<typename Derived>
5686QualType
John McCall70dd5f62009-10-30 00:06:24 +00005687TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5688 bool WrittenAsLValue,
5689 SourceLocation Sigil) {
5690 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5691 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005692}
5693
5694template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005695QualType
John McCall70dd5f62009-10-30 00:06:24 +00005696TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5697 QualType ClassType,
5698 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005699 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005700 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005701}
5702
5703template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005704QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005705TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5706 ArrayType::ArraySizeModifier SizeMod,
5707 const llvm::APInt *Size,
5708 Expr *SizeExpr,
5709 unsigned IndexTypeQuals,
5710 SourceRange BracketsRange) {
5711 if (SizeExpr || !Size)
5712 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5713 IndexTypeQuals, BracketsRange,
5714 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005715
5716 QualType Types[] = {
5717 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5718 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5719 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005720 };
5721 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5722 QualType SizeType;
5723 for (unsigned I = 0; I != NumTypes; ++I)
5724 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5725 SizeType = Types[I];
5726 break;
5727 }
Mike Stump11289f42009-09-09 15:08:12 +00005728
Douglas Gregord6ff3322009-08-04 16:50:30 +00005729 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005730 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005731 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005732 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005733}
Mike Stump11289f42009-09-09 15:08:12 +00005734
Douglas Gregord6ff3322009-08-04 16:50:30 +00005735template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005736QualType
5737TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005738 ArrayType::ArraySizeModifier SizeMod,
5739 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005740 unsigned IndexTypeQuals,
5741 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005742 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005743 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005744}
5745
5746template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005747QualType
Mike Stump11289f42009-09-09 15:08:12 +00005748TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005749 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005750 unsigned IndexTypeQuals,
5751 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005752 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005753 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005754}
Mike Stump11289f42009-09-09 15:08:12 +00005755
Douglas Gregord6ff3322009-08-04 16:50:30 +00005756template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005757QualType
5758TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005759 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005760 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005761 unsigned IndexTypeQuals,
5762 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005763 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005764 SizeExpr.takeAs<Expr>(),
5765 IndexTypeQuals, BracketsRange);
5766}
5767
5768template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005769QualType
5770TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005771 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005772 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005773 unsigned IndexTypeQuals,
5774 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005775 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005776 SizeExpr.takeAs<Expr>(),
5777 IndexTypeQuals, BracketsRange);
5778}
5779
5780template<typename Derived>
5781QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00005782 unsigned NumElements,
5783 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005784 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00005785 return SemaRef.Context.getVectorType(ElementType, NumElements,
5786 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005787}
Mike Stump11289f42009-09-09 15:08:12 +00005788
Douglas Gregord6ff3322009-08-04 16:50:30 +00005789template<typename Derived>
5790QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5791 unsigned NumElements,
5792 SourceLocation AttributeLoc) {
5793 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5794 NumElements, true);
5795 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005796 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005797 AttributeLoc);
5798 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5799 AttributeLoc);
5800}
Mike Stump11289f42009-09-09 15:08:12 +00005801
Douglas Gregord6ff3322009-08-04 16:50:30 +00005802template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005803QualType
5804TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005805 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005806 SourceLocation AttributeLoc) {
5807 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5808}
Mike Stump11289f42009-09-09 15:08:12 +00005809
Douglas Gregord6ff3322009-08-04 16:50:30 +00005810template<typename Derived>
5811QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005812 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005813 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005814 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005815 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005816 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005817 Quals,
5818 getDerived().getBaseLocation(),
5819 getDerived().getBaseEntity());
5820}
Mike Stump11289f42009-09-09 15:08:12 +00005821
Douglas Gregord6ff3322009-08-04 16:50:30 +00005822template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005823QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5824 return SemaRef.Context.getFunctionNoProtoType(T);
5825}
5826
5827template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005828QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5829 assert(D && "no decl found");
5830 if (D->isInvalidDecl()) return QualType();
5831
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005832 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00005833 TypeDecl *Ty;
5834 if (isa<UsingDecl>(D)) {
5835 UsingDecl *Using = cast<UsingDecl>(D);
5836 assert(Using->isTypeName() &&
5837 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5838
5839 // A valid resolved using typename decl points to exactly one type decl.
5840 assert(++Using->shadow_begin() == Using->shadow_end());
5841 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5842
5843 } else {
5844 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5845 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5846 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5847 }
5848
5849 return SemaRef.Context.getTypeDeclType(Ty);
5850}
5851
5852template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005853QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005854 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5855}
5856
5857template<typename Derived>
5858QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5859 return SemaRef.Context.getTypeOfType(Underlying);
5860}
5861
5862template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005863QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005864 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5865}
5866
5867template<typename Derived>
5868QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005869 TemplateName Template,
5870 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005871 const TemplateArgumentListInfo &TemplateArgs) {
5872 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005873}
Mike Stump11289f42009-09-09 15:08:12 +00005874
Douglas Gregor1135c352009-08-06 05:28:30 +00005875template<typename Derived>
5876NestedNameSpecifier *
5877TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5878 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005879 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005880 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005881 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005882 CXXScopeSpec SS;
5883 // FIXME: The source location information is all wrong.
5884 SS.setRange(Range);
5885 SS.setScopeRep(Prefix);
5886 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005887 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005888 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005889 ObjectType,
5890 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005891 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005892}
5893
5894template<typename Derived>
5895NestedNameSpecifier *
5896TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5897 SourceRange Range,
5898 NamespaceDecl *NS) {
5899 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5900}
5901
5902template<typename Derived>
5903NestedNameSpecifier *
5904TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5905 SourceRange Range,
5906 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005907 QualType T) {
5908 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00005909 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005910 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005911 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5912 T.getTypePtr());
5913 }
Mike Stump11289f42009-09-09 15:08:12 +00005914
Douglas Gregor1135c352009-08-06 05:28:30 +00005915 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5916 return 0;
5917}
Mike Stump11289f42009-09-09 15:08:12 +00005918
Douglas Gregor71dc5092009-08-06 06:41:21 +00005919template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005920TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005921TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5922 bool TemplateKW,
5923 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005924 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005925 Template);
5926}
5927
5928template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005929TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005930TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005931 const IdentifierInfo &II,
5932 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005933 CXXScopeSpec SS;
5934 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005935 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005936 UnqualifiedId Name;
5937 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005938 return getSema().ActOnDependentTemplateName(
5939 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005940 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005941 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005942 ObjectType.getAsOpaquePtr(),
5943 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005944 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005945}
Mike Stump11289f42009-09-09 15:08:12 +00005946
Douglas Gregora16548e2009-08-11 05:31:07 +00005947template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005948TemplateName
5949TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5950 OverloadedOperatorKind Operator,
5951 QualType ObjectType) {
5952 CXXScopeSpec SS;
5953 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5954 SS.setScopeRep(Qualifier);
5955 UnqualifiedId Name;
5956 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5957 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5958 Operator, SymbolLocations);
5959 return getSema().ActOnDependentTemplateName(
5960 /*FIXME:*/getDerived().getBaseLocation(),
5961 SS,
5962 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005963 ObjectType.getAsOpaquePtr(),
5964 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005965 .template getAsVal<TemplateName>();
5966}
5967
5968template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005969Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005970TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5971 SourceLocation OpLoc,
5972 ExprArg Callee,
5973 ExprArg First,
5974 ExprArg Second) {
5975 Expr *FirstExpr = (Expr *)First.get();
5976 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005977 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005978 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005979
Douglas Gregora16548e2009-08-11 05:31:07 +00005980 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005981 if (Op == OO_Subscript) {
5982 if (!FirstExpr->getType()->isOverloadableType() &&
5983 !SecondExpr->getType()->isOverloadableType())
5984 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005985 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005986 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005987 } else if (Op == OO_Arrow) {
5988 // -> is never a builtin operation.
5989 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005990 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005991 if (!FirstExpr->getType()->isOverloadableType()) {
5992 // The argument is not of overloadable type, so try to create a
5993 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005994 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005995 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005996
Douglas Gregora16548e2009-08-11 05:31:07 +00005997 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5998 }
5999 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006000 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006001 !SecondExpr->getType()->isOverloadableType()) {
6002 // Neither of the arguments is an overloadable type, so try to
6003 // create a built-in binary operation.
6004 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006005 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006006 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6007 if (Result.isInvalid())
6008 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006009
Douglas Gregora16548e2009-08-11 05:31:07 +00006010 First.release();
6011 Second.release();
6012 return move(Result);
6013 }
6014 }
Mike Stump11289f42009-09-09 15:08:12 +00006015
6016 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006017 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006018 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006019
John McCalld14a8642009-11-21 08:51:07 +00006020 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6021 assert(ULE->requiresADL());
6022
6023 // FIXME: Do we have to check
6024 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006025 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006026 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006027 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006028 }
Mike Stump11289f42009-09-09 15:08:12 +00006029
Douglas Gregora16548e2009-08-11 05:31:07 +00006030 // Add any functions found via argument-dependent lookup.
6031 Expr *Args[2] = { FirstExpr, SecondExpr };
6032 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006033
Douglas Gregora16548e2009-08-11 05:31:07 +00006034 // Create the overloaded operator invocation for unary operators.
6035 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006036 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006037 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6038 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6039 }
Mike Stump11289f42009-09-09 15:08:12 +00006040
Sebastian Redladba46e2009-10-29 20:17:01 +00006041 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006042 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6043 OpLoc,
6044 move(First),
6045 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006046
Douglas Gregora16548e2009-08-11 05:31:07 +00006047 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006048 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006049 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006050 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006051 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6052 if (Result.isInvalid())
6053 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006054
Douglas Gregora16548e2009-08-11 05:31:07 +00006055 First.release();
6056 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006057 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006058}
Mike Stump11289f42009-09-09 15:08:12 +00006059
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006060template<typename Derived>
6061Sema::OwningExprResult
6062TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6063 SourceLocation OperatorLoc,
6064 bool isArrow,
6065 NestedNameSpecifier *Qualifier,
6066 SourceRange QualifierRange,
6067 TypeSourceInfo *ScopeType,
6068 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006069 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006070 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006071 CXXScopeSpec SS;
6072 if (Qualifier) {
6073 SS.setRange(QualifierRange);
6074 SS.setScopeRep(Qualifier);
6075 }
6076
6077 Expr *BaseE = (Expr *)Base.get();
6078 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006079 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006080 (!isArrow && !BaseType->getAs<RecordType>()) ||
6081 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006082 !BaseType->getAs<PointerType>()->getPointeeType()
6083 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006084 // This pseudo-destructor expression is still a pseudo-destructor.
6085 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6086 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006087 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006088 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006089 /*FIXME?*/true);
6090 }
6091
Douglas Gregor678f90d2010-02-25 01:56:36 +00006092 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006093 DeclarationName Name
6094 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6095 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
6096
6097 // FIXME: the ScopeType should be tacked onto SS.
6098
6099 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6100 OperatorLoc, isArrow,
6101 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006102 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006103 /*TemplateArgs*/ 0);
6104}
6105
Douglas Gregord6ff3322009-08-04 16:50:30 +00006106} // end namespace clang
6107
6108#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H