blob: fbb41d83d2d13e94b5be9065e96fc2a69f6456ef [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 Objective-C protocol 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 RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1728 SourceLocation AtLoc,
1729 SourceLocation ProtoLoc,
1730 SourceLocation LParenLoc,
1731 SourceLocation RParenLoc) {
1732 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1733 Protocol->getIdentifier(),
1734 AtLoc,
1735 ProtoLoc,
1736 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001737 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 }
Mike Stump11289f42009-09-09 15:08:12 +00001739
Douglas Gregora16548e2009-08-11 05:31:07 +00001740 /// \brief Build a new shuffle vector expression.
1741 ///
1742 /// By default, performs semantic analysis to build the new expression.
1743 /// Subclasses may override this routine to provide different behavior.
1744 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1745 MultiExprArg SubExprs,
1746 SourceLocation RParenLoc) {
1747 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001748 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1750 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1751 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1752 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001753
Douglas Gregora16548e2009-08-11 05:31:07 +00001754 // Build a reference to the __builtin_shufflevector builtin
1755 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001756 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001757 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001758 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001759 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001760
1761 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001762 unsigned NumSubExprs = SubExprs.size();
1763 Expr **Subs = (Expr **)SubExprs.release();
1764 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1765 Subs, NumSubExprs,
1766 Builtin->getResultType(),
1767 RParenLoc);
1768 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001769
Douglas Gregora16548e2009-08-11 05:31:07 +00001770 // Type-check the __builtin_shufflevector expression.
1771 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1772 if (Result.isInvalid())
1773 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001774
Douglas Gregora16548e2009-08-11 05:31:07 +00001775 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001776 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001777 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001778};
Douglas Gregora16548e2009-08-11 05:31:07 +00001779
Douglas Gregorebe10102009-08-20 07:17:43 +00001780template<typename Derived>
1781Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1782 if (!S)
1783 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001784
Douglas Gregorebe10102009-08-20 07:17:43 +00001785 switch (S->getStmtClass()) {
1786 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001787
Douglas Gregorebe10102009-08-20 07:17:43 +00001788 // Transform individual statement nodes
1789#define STMT(Node, Parent) \
1790 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1791#define EXPR(Node, Parent)
1792#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001793
Douglas Gregorebe10102009-08-20 07:17:43 +00001794 // Transform expressions by calling TransformExpr.
1795#define STMT(Node, Parent)
John McCall2adddca2010-02-03 00:55:45 +00001796#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorebe10102009-08-20 07:17:43 +00001797#define EXPR(Node, Parent) case Stmt::Node##Class:
1798#include "clang/AST/StmtNodes.def"
1799 {
1800 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1801 if (E.isInvalid())
1802 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001803
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001804 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001805 }
Mike Stump11289f42009-09-09 15:08:12 +00001806 }
1807
Douglas Gregorebe10102009-08-20 07:17:43 +00001808 return SemaRef.Owned(S->Retain());
1809}
Mike Stump11289f42009-09-09 15:08:12 +00001810
1811
Douglas Gregore922c772009-08-04 22:27:00 +00001812template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001813Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001814 if (!E)
1815 return SemaRef.Owned(E);
1816
1817 switch (E->getStmtClass()) {
1818 case Stmt::NoStmtClass: break;
1819#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall2adddca2010-02-03 00:55:45 +00001820#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregora16548e2009-08-11 05:31:07 +00001821#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001822 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001823#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001824 }
1825
Douglas Gregora16548e2009-08-11 05:31:07 +00001826 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001827}
1828
1829template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001830NestedNameSpecifier *
1831TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001832 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001833 QualType ObjectType,
1834 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001835 if (!NNS)
1836 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001837
Douglas Gregorebe10102009-08-20 07:17:43 +00001838 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001839 NestedNameSpecifier *Prefix = NNS->getPrefix();
1840 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001841 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001842 ObjectType,
1843 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001844 if (!Prefix)
1845 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001846
1847 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001848 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001849 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001850 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001851 }
Mike Stump11289f42009-09-09 15:08:12 +00001852
Douglas Gregor1135c352009-08-06 05:28:30 +00001853 switch (NNS->getKind()) {
1854 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001855 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001856 "Identifier nested-name-specifier with no prefix or object type");
1857 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1858 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001859 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001860
1861 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001862 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001863 ObjectType,
1864 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001865
Douglas Gregor1135c352009-08-06 05:28:30 +00001866 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001867 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001868 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001869 getDerived().TransformDecl(Range.getBegin(),
1870 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001871 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001872 Prefix == NNS->getPrefix() &&
1873 NS == NNS->getAsNamespace())
1874 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001875
Douglas Gregor1135c352009-08-06 05:28:30 +00001876 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1877 }
Mike Stump11289f42009-09-09 15:08:12 +00001878
Douglas Gregor1135c352009-08-06 05:28:30 +00001879 case NestedNameSpecifier::Global:
1880 // There is no meaningful transformation that one could perform on the
1881 // global scope.
1882 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001883
Douglas Gregor1135c352009-08-06 05:28:30 +00001884 case NestedNameSpecifier::TypeSpecWithTemplate:
1885 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001886 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00001887 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
1888 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001889 if (T.isNull())
1890 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001891
Douglas Gregor1135c352009-08-06 05:28:30 +00001892 if (!getDerived().AlwaysRebuild() &&
1893 Prefix == NNS->getPrefix() &&
1894 T == QualType(NNS->getAsType(), 0))
1895 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001896
1897 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1898 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00001899 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001900 }
1901 }
Mike Stump11289f42009-09-09 15:08:12 +00001902
Douglas Gregor1135c352009-08-06 05:28:30 +00001903 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001904 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001905}
1906
1907template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001908DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001909TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001910 SourceLocation Loc,
1911 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001912 if (!Name)
1913 return Name;
1914
1915 switch (Name.getNameKind()) {
1916 case DeclarationName::Identifier:
1917 case DeclarationName::ObjCZeroArgSelector:
1918 case DeclarationName::ObjCOneArgSelector:
1919 case DeclarationName::ObjCMultiArgSelector:
1920 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001921 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001922 case DeclarationName::CXXUsingDirective:
1923 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001924
Douglas Gregorf816bd72009-09-03 22:13:48 +00001925 case DeclarationName::CXXConstructorName:
1926 case DeclarationName::CXXDestructorName:
1927 case DeclarationName::CXXConversionFunctionName: {
1928 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorfe17d252010-02-16 19:09:40 +00001929 QualType T = getDerived().TransformType(Name.getCXXNameType(),
1930 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00001931 if (T.isNull())
1932 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001933
Douglas Gregorf816bd72009-09-03 22:13:48 +00001934 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001935 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001936 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001937 }
Mike Stump11289f42009-09-09 15:08:12 +00001938 }
1939
Douglas Gregorf816bd72009-09-03 22:13:48 +00001940 return DeclarationName();
1941}
1942
1943template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001944TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001945TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1946 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001947 SourceLocation Loc = getDerived().getBaseLocation();
1948
Douglas Gregor71dc5092009-08-06 06:41:21 +00001949 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001950 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001951 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001952 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1953 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001954 if (!NNS)
1955 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001956
Douglas Gregor71dc5092009-08-06 06:41:21 +00001957 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001958 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001959 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001960 if (!TransTemplate)
1961 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001962
Douglas Gregor71dc5092009-08-06 06:41:21 +00001963 if (!getDerived().AlwaysRebuild() &&
1964 NNS == QTN->getQualifier() &&
1965 TransTemplate == Template)
1966 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001967
Douglas Gregor71dc5092009-08-06 06:41:21 +00001968 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1969 TransTemplate);
1970 }
Mike Stump11289f42009-09-09 15:08:12 +00001971
John McCalle66edc12009-11-24 19:00:30 +00001972 // These should be getting filtered out before they make it into the AST.
1973 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001974 }
Mike Stump11289f42009-09-09 15:08:12 +00001975
Douglas Gregor71dc5092009-08-06 06:41:21 +00001976 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001977 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001978 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001979 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1980 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00001981 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001982 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001983
Douglas Gregor71dc5092009-08-06 06:41:21 +00001984 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001985 NNS == DTN->getQualifier() &&
1986 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001987 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001988
Douglas Gregor71395fa2009-11-04 00:56:37 +00001989 if (DTN->isIdentifier())
1990 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1991 ObjectType);
1992
1993 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1994 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001995 }
Mike Stump11289f42009-09-09 15:08:12 +00001996
Douglas Gregor71dc5092009-08-06 06:41:21 +00001997 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001998 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001999 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002000 if (!TransTemplate)
2001 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002002
Douglas Gregor71dc5092009-08-06 06:41:21 +00002003 if (!getDerived().AlwaysRebuild() &&
2004 TransTemplate == Template)
2005 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002006
Douglas Gregor71dc5092009-08-06 06:41:21 +00002007 return TemplateName(TransTemplate);
2008 }
Mike Stump11289f42009-09-09 15:08:12 +00002009
John McCalle66edc12009-11-24 19:00:30 +00002010 // These should be getting filtered out before they reach the AST.
2011 assert(false && "overloaded function decl survived to here");
2012 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002013}
2014
2015template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002016void TreeTransform<Derived>::InventTemplateArgumentLoc(
2017 const TemplateArgument &Arg,
2018 TemplateArgumentLoc &Output) {
2019 SourceLocation Loc = getDerived().getBaseLocation();
2020 switch (Arg.getKind()) {
2021 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002022 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002023 break;
2024
2025 case TemplateArgument::Type:
2026 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002027 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00002028
2029 break;
2030
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002031 case TemplateArgument::Template:
2032 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2033 break;
2034
John McCall0ad16662009-10-29 08:12:44 +00002035 case TemplateArgument::Expression:
2036 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2037 break;
2038
2039 case TemplateArgument::Declaration:
2040 case TemplateArgument::Integral:
2041 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002042 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002043 break;
2044 }
2045}
2046
2047template<typename Derived>
2048bool TreeTransform<Derived>::TransformTemplateArgument(
2049 const TemplateArgumentLoc &Input,
2050 TemplateArgumentLoc &Output) {
2051 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002052 switch (Arg.getKind()) {
2053 case TemplateArgument::Null:
2054 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002055 Output = Input;
2056 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002057
Douglas Gregore922c772009-08-04 22:27:00 +00002058 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002059 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002060 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002061 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002062
2063 DI = getDerived().TransformType(DI);
2064 if (!DI) return true;
2065
2066 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2067 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002068 }
Mike Stump11289f42009-09-09 15:08:12 +00002069
Douglas Gregore922c772009-08-04 22:27:00 +00002070 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002071 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002072 DeclarationName Name;
2073 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2074 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002075 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002076 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002077 if (!D) return true;
2078
John McCall0d07eb32009-10-29 18:45:58 +00002079 Expr *SourceExpr = Input.getSourceDeclExpression();
2080 if (SourceExpr) {
2081 EnterExpressionEvaluationContext Unevaluated(getSema(),
2082 Action::Unevaluated);
2083 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2084 if (E.isInvalid())
2085 SourceExpr = NULL;
2086 else {
2087 SourceExpr = E.takeAs<Expr>();
2088 SourceExpr->Retain();
2089 }
2090 }
2091
2092 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002093 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002094 }
Mike Stump11289f42009-09-09 15:08:12 +00002095
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002096 case TemplateArgument::Template: {
2097 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
2098 TemplateName Template
2099 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2100 if (Template.isNull())
2101 return true;
2102
2103 Output = TemplateArgumentLoc(TemplateArgument(Template),
2104 Input.getTemplateQualifierRange(),
2105 Input.getTemplateNameLoc());
2106 return false;
2107 }
2108
Douglas Gregore922c772009-08-04 22:27:00 +00002109 case TemplateArgument::Expression: {
2110 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002111 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002112 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002113
John McCall0ad16662009-10-29 08:12:44 +00002114 Expr *InputExpr = Input.getSourceExpression();
2115 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2116
2117 Sema::OwningExprResult E
2118 = getDerived().TransformExpr(InputExpr);
2119 if (E.isInvalid()) return true;
2120
2121 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002122 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002123 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2124 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002125 }
Mike Stump11289f42009-09-09 15:08:12 +00002126
Douglas Gregore922c772009-08-04 22:27:00 +00002127 case TemplateArgument::Pack: {
2128 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2129 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002130 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002131 AEnd = Arg.pack_end();
2132 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002133
John McCall0ad16662009-10-29 08:12:44 +00002134 // FIXME: preserve source information here when we start
2135 // caring about parameter packs.
2136
John McCall0d07eb32009-10-29 18:45:58 +00002137 TemplateArgumentLoc InputArg;
2138 TemplateArgumentLoc OutputArg;
2139 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2140 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002141 return true;
2142
John McCall0d07eb32009-10-29 18:45:58 +00002143 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002144 }
2145 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002146 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002147 true);
John McCall0d07eb32009-10-29 18:45:58 +00002148 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002149 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002150 }
2151 }
Mike Stump11289f42009-09-09 15:08:12 +00002152
Douglas Gregore922c772009-08-04 22:27:00 +00002153 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002154 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002155}
2156
Douglas Gregord6ff3322009-08-04 16:50:30 +00002157//===----------------------------------------------------------------------===//
2158// Type transformation
2159//===----------------------------------------------------------------------===//
2160
2161template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002162QualType TreeTransform<Derived>::TransformType(QualType T,
2163 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002164 if (getDerived().AlreadyTransformed(T))
2165 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002166
John McCall550e0c22009-10-21 00:40:46 +00002167 // Temporary workaround. All of these transformations should
2168 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002169 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002170 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002171
Douglas Gregorfe17d252010-02-16 19:09:40 +00002172 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002173
John McCall550e0c22009-10-21 00:40:46 +00002174 if (!NewDI)
2175 return QualType();
2176
2177 return NewDI->getType();
2178}
2179
2180template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002181TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2182 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002183 if (getDerived().AlreadyTransformed(DI->getType()))
2184 return DI;
2185
2186 TypeLocBuilder TLB;
2187
2188 TypeLoc TL = DI->getTypeLoc();
2189 TLB.reserve(TL.getFullDataSize());
2190
Douglas Gregorfe17d252010-02-16 19:09:40 +00002191 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002192 if (Result.isNull())
2193 return 0;
2194
John McCallbcd03502009-12-07 02:54:59 +00002195 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002196}
2197
2198template<typename Derived>
2199QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002200TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2201 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002202 switch (T.getTypeLocClass()) {
2203#define ABSTRACT_TYPELOC(CLASS, PARENT)
2204#define TYPELOC(CLASS, PARENT) \
2205 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002206 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2207 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002208#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002209 }
Mike Stump11289f42009-09-09 15:08:12 +00002210
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002211 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002212 return QualType();
2213}
2214
2215/// FIXME: By default, this routine adds type qualifiers only to types
2216/// that can have qualifiers, and silently suppresses those qualifiers
2217/// that are not permitted (e.g., qualifiers on reference or function
2218/// types). This is the right thing for template instantiation, but
2219/// probably not for other clients.
2220template<typename Derived>
2221QualType
2222TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002223 QualifiedTypeLoc T,
2224 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002225 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002226
Douglas Gregorfe17d252010-02-16 19:09:40 +00002227 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2228 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002229 if (Result.isNull())
2230 return QualType();
2231
2232 // Silently suppress qualifiers if the result type can't be qualified.
2233 // FIXME: this is the right thing for template instantiation, but
2234 // probably not for other clients.
2235 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002236 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002237
John McCall550e0c22009-10-21 00:40:46 +00002238 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2239
2240 TLB.push<QualifiedTypeLoc>(Result);
2241
2242 // No location information to preserve.
2243
2244 return Result;
2245}
2246
2247template <class TyLoc> static inline
2248QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2249 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2250 NewT.setNameLoc(T.getNameLoc());
2251 return T.getType();
2252}
2253
John McCall550e0c22009-10-21 00:40:46 +00002254template<typename Derived>
2255QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002256 BuiltinTypeLoc T,
2257 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002258 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2259 NewT.setBuiltinLoc(T.getBuiltinLoc());
2260 if (T.needsExtraLocalData())
2261 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2262 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002263}
Mike Stump11289f42009-09-09 15:08:12 +00002264
Douglas Gregord6ff3322009-08-04 16:50:30 +00002265template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002266QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002267 ComplexTypeLoc T,
2268 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002269 // FIXME: recurse?
2270 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002271}
Mike Stump11289f42009-09-09 15:08:12 +00002272
Douglas Gregord6ff3322009-08-04 16:50:30 +00002273template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002274QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002275 PointerTypeLoc TL,
2276 QualType ObjectType) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002277 QualType PointeeType
2278 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2279 if (PointeeType.isNull())
2280 return QualType();
2281
2282 QualType Result = TL.getType();
2283 if (PointeeType->isObjCInterfaceType()) {
2284 // A dependent pointer type 'T *' has is being transformed such
2285 // that an Objective-C class type is being replaced for 'T'. The
2286 // resulting pointer type is an ObjCObjectPointerType, not a
2287 // PointerType.
2288 const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>();
2289 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType,
2290 const_cast<ObjCProtocolDecl **>(
2291 IFace->qual_begin()),
2292 IFace->getNumProtocols());
2293
2294 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2295 NewT.setStarLoc(TL.getSigilLoc());
2296 NewT.setHasProtocolsAsWritten(false);
2297 NewT.setLAngleLoc(SourceLocation());
2298 NewT.setRAngleLoc(SourceLocation());
2299 NewT.setHasBaseTypeAsWritten(true);
2300 return Result;
2301 }
2302
2303 if (getDerived().AlwaysRebuild() ||
2304 PointeeType != TL.getPointeeLoc().getType()) {
2305 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2306 if (Result.isNull())
2307 return QualType();
2308 }
2309
2310 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2311 NewT.setSigilLoc(TL.getSigilLoc());
2312 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002313}
Mike Stump11289f42009-09-09 15:08:12 +00002314
2315template<typename Derived>
2316QualType
John McCall550e0c22009-10-21 00:40:46 +00002317TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002318 BlockPointerTypeLoc TL,
2319 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002320 QualType PointeeType
2321 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2322 if (PointeeType.isNull())
2323 return QualType();
2324
2325 QualType Result = TL.getType();
2326 if (getDerived().AlwaysRebuild() ||
2327 PointeeType != TL.getPointeeLoc().getType()) {
2328 Result = getDerived().RebuildBlockPointerType(PointeeType,
2329 TL.getSigilLoc());
2330 if (Result.isNull())
2331 return QualType();
2332 }
2333
Douglas Gregor049211a2010-04-22 16:50:51 +00002334 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002335 NewT.setSigilLoc(TL.getSigilLoc());
2336 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002337}
2338
John McCall70dd5f62009-10-30 00:06:24 +00002339/// Transforms a reference type. Note that somewhat paradoxically we
2340/// don't care whether the type itself is an l-value type or an r-value
2341/// type; we only care if the type was *written* as an l-value type
2342/// or an r-value type.
2343template<typename Derived>
2344QualType
2345TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002346 ReferenceTypeLoc TL,
2347 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002348 const ReferenceType *T = TL.getTypePtr();
2349
2350 // Note that this works with the pointee-as-written.
2351 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2352 if (PointeeType.isNull())
2353 return QualType();
2354
2355 QualType Result = TL.getType();
2356 if (getDerived().AlwaysRebuild() ||
2357 PointeeType != T->getPointeeTypeAsWritten()) {
2358 Result = getDerived().RebuildReferenceType(PointeeType,
2359 T->isSpelledAsLValue(),
2360 TL.getSigilLoc());
2361 if (Result.isNull())
2362 return QualType();
2363 }
2364
2365 // r-value references can be rebuilt as l-value references.
2366 ReferenceTypeLoc NewTL;
2367 if (isa<LValueReferenceType>(Result))
2368 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2369 else
2370 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2371 NewTL.setSigilLoc(TL.getSigilLoc());
2372
2373 return Result;
2374}
2375
Mike Stump11289f42009-09-09 15:08:12 +00002376template<typename Derived>
2377QualType
John McCall550e0c22009-10-21 00:40:46 +00002378TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002379 LValueReferenceTypeLoc TL,
2380 QualType ObjectType) {
2381 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002382}
2383
Mike Stump11289f42009-09-09 15:08:12 +00002384template<typename Derived>
2385QualType
John McCall550e0c22009-10-21 00:40:46 +00002386TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002387 RValueReferenceTypeLoc TL,
2388 QualType ObjectType) {
2389 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002390}
Mike Stump11289f42009-09-09 15:08:12 +00002391
Douglas Gregord6ff3322009-08-04 16:50:30 +00002392template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002393QualType
John McCall550e0c22009-10-21 00:40:46 +00002394TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002395 MemberPointerTypeLoc TL,
2396 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002397 MemberPointerType *T = TL.getTypePtr();
2398
2399 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002400 if (PointeeType.isNull())
2401 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002402
John McCall550e0c22009-10-21 00:40:46 +00002403 // TODO: preserve source information for this.
2404 QualType ClassType
2405 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002406 if (ClassType.isNull())
2407 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002408
John McCall550e0c22009-10-21 00:40:46 +00002409 QualType Result = TL.getType();
2410 if (getDerived().AlwaysRebuild() ||
2411 PointeeType != T->getPointeeType() ||
2412 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002413 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2414 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002415 if (Result.isNull())
2416 return QualType();
2417 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002418
John McCall550e0c22009-10-21 00:40:46 +00002419 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2420 NewTL.setSigilLoc(TL.getSigilLoc());
2421
2422 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002423}
2424
Mike Stump11289f42009-09-09 15:08:12 +00002425template<typename Derived>
2426QualType
John McCall550e0c22009-10-21 00:40:46 +00002427TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002428 ConstantArrayTypeLoc TL,
2429 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002430 ConstantArrayType *T = TL.getTypePtr();
2431 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002432 if (ElementType.isNull())
2433 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002434
John McCall550e0c22009-10-21 00:40:46 +00002435 QualType Result = TL.getType();
2436 if (getDerived().AlwaysRebuild() ||
2437 ElementType != T->getElementType()) {
2438 Result = getDerived().RebuildConstantArrayType(ElementType,
2439 T->getSizeModifier(),
2440 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002441 T->getIndexTypeCVRQualifiers(),
2442 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002443 if (Result.isNull())
2444 return QualType();
2445 }
2446
2447 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2448 NewTL.setLBracketLoc(TL.getLBracketLoc());
2449 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002450
John McCall550e0c22009-10-21 00:40:46 +00002451 Expr *Size = TL.getSizeExpr();
2452 if (Size) {
2453 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2454 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2455 }
2456 NewTL.setSizeExpr(Size);
2457
2458 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002459}
Mike Stump11289f42009-09-09 15:08:12 +00002460
Douglas Gregord6ff3322009-08-04 16:50:30 +00002461template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002462QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002463 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002464 IncompleteArrayTypeLoc TL,
2465 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002466 IncompleteArrayType *T = TL.getTypePtr();
2467 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002468 if (ElementType.isNull())
2469 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002470
John McCall550e0c22009-10-21 00:40:46 +00002471 QualType Result = TL.getType();
2472 if (getDerived().AlwaysRebuild() ||
2473 ElementType != T->getElementType()) {
2474 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002475 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002476 T->getIndexTypeCVRQualifiers(),
2477 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002478 if (Result.isNull())
2479 return QualType();
2480 }
2481
2482 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2483 NewTL.setLBracketLoc(TL.getLBracketLoc());
2484 NewTL.setRBracketLoc(TL.getRBracketLoc());
2485 NewTL.setSizeExpr(0);
2486
2487 return Result;
2488}
2489
2490template<typename Derived>
2491QualType
2492TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002493 VariableArrayTypeLoc TL,
2494 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002495 VariableArrayType *T = TL.getTypePtr();
2496 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2497 if (ElementType.isNull())
2498 return QualType();
2499
2500 // Array bounds are not potentially evaluated contexts
2501 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2502
2503 Sema::OwningExprResult SizeResult
2504 = getDerived().TransformExpr(T->getSizeExpr());
2505 if (SizeResult.isInvalid())
2506 return QualType();
2507
2508 Expr *Size = static_cast<Expr*>(SizeResult.get());
2509
2510 QualType Result = TL.getType();
2511 if (getDerived().AlwaysRebuild() ||
2512 ElementType != T->getElementType() ||
2513 Size != T->getSizeExpr()) {
2514 Result = getDerived().RebuildVariableArrayType(ElementType,
2515 T->getSizeModifier(),
2516 move(SizeResult),
2517 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002518 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002519 if (Result.isNull())
2520 return QualType();
2521 }
2522 else SizeResult.take();
2523
2524 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2525 NewTL.setLBracketLoc(TL.getLBracketLoc());
2526 NewTL.setRBracketLoc(TL.getRBracketLoc());
2527 NewTL.setSizeExpr(Size);
2528
2529 return Result;
2530}
2531
2532template<typename Derived>
2533QualType
2534TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002535 DependentSizedArrayTypeLoc TL,
2536 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002537 DependentSizedArrayType *T = TL.getTypePtr();
2538 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2539 if (ElementType.isNull())
2540 return QualType();
2541
2542 // Array bounds are not potentially evaluated contexts
2543 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2544
2545 Sema::OwningExprResult SizeResult
2546 = getDerived().TransformExpr(T->getSizeExpr());
2547 if (SizeResult.isInvalid())
2548 return QualType();
2549
2550 Expr *Size = static_cast<Expr*>(SizeResult.get());
2551
2552 QualType Result = TL.getType();
2553 if (getDerived().AlwaysRebuild() ||
2554 ElementType != T->getElementType() ||
2555 Size != T->getSizeExpr()) {
2556 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2557 T->getSizeModifier(),
2558 move(SizeResult),
2559 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002560 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002561 if (Result.isNull())
2562 return QualType();
2563 }
2564 else SizeResult.take();
2565
2566 // We might have any sort of array type now, but fortunately they
2567 // all have the same location layout.
2568 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2569 NewTL.setLBracketLoc(TL.getLBracketLoc());
2570 NewTL.setRBracketLoc(TL.getRBracketLoc());
2571 NewTL.setSizeExpr(Size);
2572
2573 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002574}
Mike Stump11289f42009-09-09 15:08:12 +00002575
2576template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002577QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002578 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002579 DependentSizedExtVectorTypeLoc TL,
2580 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002581 DependentSizedExtVectorType *T = TL.getTypePtr();
2582
2583 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002584 QualType ElementType = getDerived().TransformType(T->getElementType());
2585 if (ElementType.isNull())
2586 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002587
Douglas Gregore922c772009-08-04 22:27:00 +00002588 // Vector sizes are not potentially evaluated contexts
2589 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2590
Douglas Gregord6ff3322009-08-04 16:50:30 +00002591 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2592 if (Size.isInvalid())
2593 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002594
John McCall550e0c22009-10-21 00:40:46 +00002595 QualType Result = TL.getType();
2596 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002597 ElementType != T->getElementType() ||
2598 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002599 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002600 move(Size),
2601 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002602 if (Result.isNull())
2603 return QualType();
2604 }
2605 else Size.take();
2606
2607 // Result might be dependent or not.
2608 if (isa<DependentSizedExtVectorType>(Result)) {
2609 DependentSizedExtVectorTypeLoc NewTL
2610 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2611 NewTL.setNameLoc(TL.getNameLoc());
2612 } else {
2613 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2614 NewTL.setNameLoc(TL.getNameLoc());
2615 }
2616
2617 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002618}
Mike Stump11289f42009-09-09 15:08:12 +00002619
2620template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002621QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002622 VectorTypeLoc TL,
2623 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002624 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002625 QualType ElementType = getDerived().TransformType(T->getElementType());
2626 if (ElementType.isNull())
2627 return QualType();
2628
John McCall550e0c22009-10-21 00:40:46 +00002629 QualType Result = TL.getType();
2630 if (getDerived().AlwaysRebuild() ||
2631 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002632 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2633 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002634 if (Result.isNull())
2635 return QualType();
2636 }
2637
2638 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2639 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002640
John McCall550e0c22009-10-21 00:40:46 +00002641 return Result;
2642}
2643
2644template<typename Derived>
2645QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002646 ExtVectorTypeLoc TL,
2647 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002648 VectorType *T = TL.getTypePtr();
2649 QualType ElementType = getDerived().TransformType(T->getElementType());
2650 if (ElementType.isNull())
2651 return QualType();
2652
2653 QualType Result = TL.getType();
2654 if (getDerived().AlwaysRebuild() ||
2655 ElementType != T->getElementType()) {
2656 Result = getDerived().RebuildExtVectorType(ElementType,
2657 T->getNumElements(),
2658 /*FIXME*/ SourceLocation());
2659 if (Result.isNull())
2660 return QualType();
2661 }
2662
2663 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2664 NewTL.setNameLoc(TL.getNameLoc());
2665
2666 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002667}
Mike Stump11289f42009-09-09 15:08:12 +00002668
2669template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002670ParmVarDecl *
2671TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2672 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2673 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2674 if (!NewDI)
2675 return 0;
2676
2677 if (NewDI == OldDI)
2678 return OldParm;
2679 else
2680 return ParmVarDecl::Create(SemaRef.Context,
2681 OldParm->getDeclContext(),
2682 OldParm->getLocation(),
2683 OldParm->getIdentifier(),
2684 NewDI->getType(),
2685 NewDI,
2686 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002687 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002688 /* DefArg */ NULL);
2689}
2690
2691template<typename Derived>
2692bool TreeTransform<Derived>::
2693 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2694 llvm::SmallVectorImpl<QualType> &PTypes,
2695 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2696 FunctionProtoType *T = TL.getTypePtr();
2697
2698 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2699 ParmVarDecl *OldParm = TL.getArg(i);
2700
2701 QualType NewType;
2702 ParmVarDecl *NewParm;
2703
2704 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002705 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2706 if (!NewParm)
2707 return true;
2708 NewType = NewParm->getType();
2709
2710 // Deal with the possibility that we don't have a parameter
2711 // declaration for this parameter.
2712 } else {
2713 NewParm = 0;
2714
2715 QualType OldType = T->getArgType(i);
2716 NewType = getDerived().TransformType(OldType);
2717 if (NewType.isNull())
2718 return true;
2719 }
2720
2721 PTypes.push_back(NewType);
2722 PVars.push_back(NewParm);
2723 }
2724
2725 return false;
2726}
2727
2728template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002729QualType
John McCall550e0c22009-10-21 00:40:46 +00002730TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002731 FunctionProtoTypeLoc TL,
2732 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002733 FunctionProtoType *T = TL.getTypePtr();
2734 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002735 if (ResultType.isNull())
2736 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002737
John McCall550e0c22009-10-21 00:40:46 +00002738 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002739 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002740 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002741 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2742 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002743
John McCall550e0c22009-10-21 00:40:46 +00002744 QualType Result = TL.getType();
2745 if (getDerived().AlwaysRebuild() ||
2746 ResultType != T->getResultType() ||
2747 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2748 Result = getDerived().RebuildFunctionProtoType(ResultType,
2749 ParamTypes.data(),
2750 ParamTypes.size(),
2751 T->isVariadic(),
2752 T->getTypeQuals());
2753 if (Result.isNull())
2754 return QualType();
2755 }
Mike Stump11289f42009-09-09 15:08:12 +00002756
John McCall550e0c22009-10-21 00:40:46 +00002757 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2758 NewTL.setLParenLoc(TL.getLParenLoc());
2759 NewTL.setRParenLoc(TL.getRParenLoc());
2760 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2761 NewTL.setArg(i, ParamDecls[i]);
2762
2763 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002764}
Mike Stump11289f42009-09-09 15:08:12 +00002765
Douglas Gregord6ff3322009-08-04 16:50:30 +00002766template<typename Derived>
2767QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002768 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002769 FunctionNoProtoTypeLoc TL,
2770 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002771 FunctionNoProtoType *T = TL.getTypePtr();
2772 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2773 if (ResultType.isNull())
2774 return QualType();
2775
2776 QualType Result = TL.getType();
2777 if (getDerived().AlwaysRebuild() ||
2778 ResultType != T->getResultType())
2779 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2780
2781 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2782 NewTL.setLParenLoc(TL.getLParenLoc());
2783 NewTL.setRParenLoc(TL.getRParenLoc());
2784
2785 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002786}
Mike Stump11289f42009-09-09 15:08:12 +00002787
John McCallb96ec562009-12-04 22:46:56 +00002788template<typename Derived> QualType
2789TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002790 UnresolvedUsingTypeLoc TL,
2791 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002792 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002793 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002794 if (!D)
2795 return QualType();
2796
2797 QualType Result = TL.getType();
2798 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2799 Result = getDerived().RebuildUnresolvedUsingType(D);
2800 if (Result.isNull())
2801 return QualType();
2802 }
2803
2804 // We might get an arbitrary type spec type back. We should at
2805 // least always get a type spec type, though.
2806 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2807 NewTL.setNameLoc(TL.getNameLoc());
2808
2809 return Result;
2810}
2811
Douglas Gregord6ff3322009-08-04 16:50:30 +00002812template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002813QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002814 TypedefTypeLoc TL,
2815 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002816 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002817 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002818 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2819 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002820 if (!Typedef)
2821 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002822
John McCall550e0c22009-10-21 00:40:46 +00002823 QualType Result = TL.getType();
2824 if (getDerived().AlwaysRebuild() ||
2825 Typedef != T->getDecl()) {
2826 Result = getDerived().RebuildTypedefType(Typedef);
2827 if (Result.isNull())
2828 return QualType();
2829 }
Mike Stump11289f42009-09-09 15:08:12 +00002830
John McCall550e0c22009-10-21 00:40:46 +00002831 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2832 NewTL.setNameLoc(TL.getNameLoc());
2833
2834 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002835}
Mike Stump11289f42009-09-09 15:08:12 +00002836
Douglas Gregord6ff3322009-08-04 16:50:30 +00002837template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002838QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002839 TypeOfExprTypeLoc TL,
2840 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00002841 // typeof expressions are not potentially evaluated contexts
2842 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002843
John McCalle8595032010-01-13 20:03:27 +00002844 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002845 if (E.isInvalid())
2846 return QualType();
2847
John McCall550e0c22009-10-21 00:40:46 +00002848 QualType Result = TL.getType();
2849 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00002850 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002851 Result = getDerived().RebuildTypeOfExprType(move(E));
2852 if (Result.isNull())
2853 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002854 }
John McCall550e0c22009-10-21 00:40:46 +00002855 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002856
John McCall550e0c22009-10-21 00:40:46 +00002857 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002858 NewTL.setTypeofLoc(TL.getTypeofLoc());
2859 NewTL.setLParenLoc(TL.getLParenLoc());
2860 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00002861
2862 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002863}
Mike Stump11289f42009-09-09 15:08:12 +00002864
2865template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002866QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002867 TypeOfTypeLoc TL,
2868 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00002869 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2870 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2871 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00002872 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002873
John McCall550e0c22009-10-21 00:40:46 +00002874 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00002875 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2876 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00002877 if (Result.isNull())
2878 return QualType();
2879 }
Mike Stump11289f42009-09-09 15:08:12 +00002880
John McCall550e0c22009-10-21 00:40:46 +00002881 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002882 NewTL.setTypeofLoc(TL.getTypeofLoc());
2883 NewTL.setLParenLoc(TL.getLParenLoc());
2884 NewTL.setRParenLoc(TL.getRParenLoc());
2885 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00002886
2887 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002888}
Mike Stump11289f42009-09-09 15:08:12 +00002889
2890template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002891QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002892 DecltypeTypeLoc TL,
2893 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002894 DecltypeType *T = TL.getTypePtr();
2895
Douglas Gregore922c772009-08-04 22:27:00 +00002896 // decltype expressions are not potentially evaluated contexts
2897 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002898
Douglas Gregord6ff3322009-08-04 16:50:30 +00002899 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2900 if (E.isInvalid())
2901 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002902
John McCall550e0c22009-10-21 00:40:46 +00002903 QualType Result = TL.getType();
2904 if (getDerived().AlwaysRebuild() ||
2905 E.get() != T->getUnderlyingExpr()) {
2906 Result = getDerived().RebuildDecltypeType(move(E));
2907 if (Result.isNull())
2908 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002909 }
John McCall550e0c22009-10-21 00:40:46 +00002910 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002911
John McCall550e0c22009-10-21 00:40:46 +00002912 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2913 NewTL.setNameLoc(TL.getNameLoc());
2914
2915 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002916}
2917
2918template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002919QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002920 RecordTypeLoc TL,
2921 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002922 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002923 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002924 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2925 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002926 if (!Record)
2927 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002928
John McCall550e0c22009-10-21 00:40:46 +00002929 QualType Result = TL.getType();
2930 if (getDerived().AlwaysRebuild() ||
2931 Record != T->getDecl()) {
2932 Result = getDerived().RebuildRecordType(Record);
2933 if (Result.isNull())
2934 return QualType();
2935 }
Mike Stump11289f42009-09-09 15:08:12 +00002936
John McCall550e0c22009-10-21 00:40:46 +00002937 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2938 NewTL.setNameLoc(TL.getNameLoc());
2939
2940 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002941}
Mike Stump11289f42009-09-09 15:08:12 +00002942
2943template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002944QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002945 EnumTypeLoc TL,
2946 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002947 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002948 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002949 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2950 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002951 if (!Enum)
2952 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002953
John McCall550e0c22009-10-21 00:40:46 +00002954 QualType Result = TL.getType();
2955 if (getDerived().AlwaysRebuild() ||
2956 Enum != T->getDecl()) {
2957 Result = getDerived().RebuildEnumType(Enum);
2958 if (Result.isNull())
2959 return QualType();
2960 }
Mike Stump11289f42009-09-09 15:08:12 +00002961
John McCall550e0c22009-10-21 00:40:46 +00002962 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2963 NewTL.setNameLoc(TL.getNameLoc());
2964
2965 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002966}
John McCallfcc33b02009-09-05 00:15:47 +00002967
2968template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002969QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002970 ElaboratedTypeLoc TL,
2971 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002972 ElaboratedType *T = TL.getTypePtr();
2973
2974 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002975 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2976 if (Underlying.isNull())
2977 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002978
John McCall550e0c22009-10-21 00:40:46 +00002979 QualType Result = TL.getType();
2980 if (getDerived().AlwaysRebuild() ||
2981 Underlying != T->getUnderlyingType()) {
2982 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2983 if (Result.isNull())
2984 return QualType();
2985 }
Mike Stump11289f42009-09-09 15:08:12 +00002986
John McCall550e0c22009-10-21 00:40:46 +00002987 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2988 NewTL.setNameLoc(TL.getNameLoc());
2989
2990 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002991}
Mike Stump11289f42009-09-09 15:08:12 +00002992
John McCalle78aac42010-03-10 03:28:59 +00002993template<typename Derived>
2994QualType TreeTransform<Derived>::TransformInjectedClassNameType(
2995 TypeLocBuilder &TLB,
2996 InjectedClassNameTypeLoc TL,
2997 QualType ObjectType) {
2998 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
2999 TL.getTypePtr()->getDecl());
3000 if (!D) return QualType();
3001
3002 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3003 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3004 return T;
3005}
3006
Mike Stump11289f42009-09-09 15:08:12 +00003007
Douglas Gregord6ff3322009-08-04 16:50:30 +00003008template<typename Derived>
3009QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003010 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003011 TemplateTypeParmTypeLoc TL,
3012 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003013 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003014}
3015
Mike Stump11289f42009-09-09 15:08:12 +00003016template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003017QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003018 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003019 SubstTemplateTypeParmTypeLoc TL,
3020 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003021 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003022}
3023
3024template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003025QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3026 const TemplateSpecializationType *TST,
3027 QualType ObjectType) {
3028 // FIXME: this entire method is a temporary workaround; callers
3029 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003030
John McCall0ad16662009-10-29 08:12:44 +00003031 // Fake up a TemplateSpecializationTypeLoc.
3032 TypeLocBuilder TLB;
3033 TemplateSpecializationTypeLoc TL
3034 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3035
John McCall0d07eb32009-10-29 18:45:58 +00003036 SourceLocation BaseLoc = getDerived().getBaseLocation();
3037
3038 TL.setTemplateNameLoc(BaseLoc);
3039 TL.setLAngleLoc(BaseLoc);
3040 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003041 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3042 const TemplateArgument &TA = TST->getArg(i);
3043 TemplateArgumentLoc TAL;
3044 getDerived().InventTemplateArgumentLoc(TA, TAL);
3045 TL.setArgLocInfo(i, TAL.getLocInfo());
3046 }
3047
3048 TypeLocBuilder IgnoredTLB;
3049 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003050}
3051
3052template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003053QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003054 TypeLocBuilder &TLB,
3055 TemplateSpecializationTypeLoc TL,
3056 QualType ObjectType) {
3057 const TemplateSpecializationType *T = TL.getTypePtr();
3058
Mike Stump11289f42009-09-09 15:08:12 +00003059 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003060 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003061 if (Template.isNull())
3062 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003063
John McCall6b51f282009-11-23 01:53:49 +00003064 TemplateArgumentListInfo NewTemplateArgs;
3065 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3066 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3067
3068 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3069 TemplateArgumentLoc Loc;
3070 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003071 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003072 NewTemplateArgs.addArgument(Loc);
3073 }
Mike Stump11289f42009-09-09 15:08:12 +00003074
John McCall0ad16662009-10-29 08:12:44 +00003075 // FIXME: maybe don't rebuild if all the template arguments are the same.
3076
3077 QualType Result =
3078 getDerived().RebuildTemplateSpecializationType(Template,
3079 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003080 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003081
3082 if (!Result.isNull()) {
3083 TemplateSpecializationTypeLoc NewTL
3084 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3085 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3086 NewTL.setLAngleLoc(TL.getLAngleLoc());
3087 NewTL.setRAngleLoc(TL.getRAngleLoc());
3088 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3089 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003090 }
Mike Stump11289f42009-09-09 15:08:12 +00003091
John McCall0ad16662009-10-29 08:12:44 +00003092 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003093}
Mike Stump11289f42009-09-09 15:08:12 +00003094
3095template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003096QualType
3097TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003098 QualifiedNameTypeLoc TL,
3099 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003100 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003101 NestedNameSpecifier *NNS
3102 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00003103 SourceRange(),
3104 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003105 if (!NNS)
3106 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003107
Douglas Gregord6ff3322009-08-04 16:50:30 +00003108 QualType Named = getDerived().TransformType(T->getNamedType());
3109 if (Named.isNull())
3110 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003111
John McCall550e0c22009-10-21 00:40:46 +00003112 QualType Result = TL.getType();
3113 if (getDerived().AlwaysRebuild() ||
3114 NNS != T->getQualifier() ||
3115 Named != T->getNamedType()) {
3116 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
3117 if (Result.isNull())
3118 return QualType();
3119 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003120
John McCall550e0c22009-10-21 00:40:46 +00003121 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
3122 NewTL.setNameLoc(TL.getNameLoc());
3123
3124 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003125}
Mike Stump11289f42009-09-09 15:08:12 +00003126
3127template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003128QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3129 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003130 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003131 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003132
3133 /* FIXME: preserve source information better than this */
3134 SourceRange SR(TL.getNameLoc());
3135
Douglas Gregord6ff3322009-08-04 16:50:30 +00003136 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00003137 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003138 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003139 if (!NNS)
3140 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003141
John McCall550e0c22009-10-21 00:40:46 +00003142 QualType Result;
3143
Douglas Gregord6ff3322009-08-04 16:50:30 +00003144 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00003145 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00003146 = getDerived().TransformType(QualType(TemplateId, 0));
3147 if (NewTemplateId.isNull())
3148 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003149
Douglas Gregord6ff3322009-08-04 16:50:30 +00003150 if (!getDerived().AlwaysRebuild() &&
3151 NNS == T->getQualifier() &&
3152 NewTemplateId == QualType(TemplateId, 0))
3153 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00003154
Douglas Gregor02085352010-03-31 20:19:30 +00003155 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3156 NewTemplateId);
John McCall550e0c22009-10-21 00:40:46 +00003157 } else {
Douglas Gregor02085352010-03-31 20:19:30 +00003158 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3159 T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003160 }
John McCall550e0c22009-10-21 00:40:46 +00003161 if (Result.isNull())
3162 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003163
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003164 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003165 NewTL.setNameLoc(TL.getNameLoc());
3166
3167 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003168}
Mike Stump11289f42009-09-09 15:08:12 +00003169
Douglas Gregord6ff3322009-08-04 16:50:30 +00003170template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003171QualType
3172TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003173 ObjCInterfaceTypeLoc TL,
3174 QualType ObjectType) {
John McCallfc93cf92009-10-22 22:37:11 +00003175 assert(false && "TransformObjCInterfaceType unimplemented");
3176 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003177}
Mike Stump11289f42009-09-09 15:08:12 +00003178
3179template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003180QualType
3181TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003182 ObjCObjectPointerTypeLoc TL,
3183 QualType ObjectType) {
John McCallfc93cf92009-10-22 22:37:11 +00003184 assert(false && "TransformObjCObjectPointerType unimplemented");
3185 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003186}
3187
Douglas Gregord6ff3322009-08-04 16:50:30 +00003188//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003189// Statement transformation
3190//===----------------------------------------------------------------------===//
3191template<typename Derived>
3192Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003193TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3194 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003195}
3196
3197template<typename Derived>
3198Sema::OwningStmtResult
3199TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3200 return getDerived().TransformCompoundStmt(S, false);
3201}
3202
3203template<typename Derived>
3204Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003205TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003206 bool IsStmtExpr) {
3207 bool SubStmtChanged = false;
3208 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3209 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3210 B != BEnd; ++B) {
3211 OwningStmtResult Result = getDerived().TransformStmt(*B);
3212 if (Result.isInvalid())
3213 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003214
Douglas Gregorebe10102009-08-20 07:17:43 +00003215 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3216 Statements.push_back(Result.takeAs<Stmt>());
3217 }
Mike Stump11289f42009-09-09 15:08:12 +00003218
Douglas Gregorebe10102009-08-20 07:17:43 +00003219 if (!getDerived().AlwaysRebuild() &&
3220 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003221 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003222
3223 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3224 move_arg(Statements),
3225 S->getRBracLoc(),
3226 IsStmtExpr);
3227}
Mike Stump11289f42009-09-09 15:08:12 +00003228
Douglas Gregorebe10102009-08-20 07:17:43 +00003229template<typename Derived>
3230Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003231TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003232 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3233 {
3234 // The case value expressions are not potentially evaluated.
3235 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003236
Eli Friedman06577382009-11-19 03:14:00 +00003237 // Transform the left-hand case value.
3238 LHS = getDerived().TransformExpr(S->getLHS());
3239 if (LHS.isInvalid())
3240 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003241
Eli Friedman06577382009-11-19 03:14:00 +00003242 // Transform the right-hand case value (for the GNU case-range extension).
3243 RHS = getDerived().TransformExpr(S->getRHS());
3244 if (RHS.isInvalid())
3245 return SemaRef.StmtError();
3246 }
Mike Stump11289f42009-09-09 15:08:12 +00003247
Douglas Gregorebe10102009-08-20 07:17:43 +00003248 // Build the case statement.
3249 // Case statements are always rebuilt so that they will attached to their
3250 // transformed switch statement.
3251 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3252 move(LHS),
3253 S->getEllipsisLoc(),
3254 move(RHS),
3255 S->getColonLoc());
3256 if (Case.isInvalid())
3257 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003258
Douglas Gregorebe10102009-08-20 07:17:43 +00003259 // Transform the statement following the case
3260 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3261 if (SubStmt.isInvalid())
3262 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003263
Douglas Gregorebe10102009-08-20 07:17:43 +00003264 // Attach the body to the case statement
3265 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3266}
3267
3268template<typename Derived>
3269Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003270TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003271 // Transform the statement following the default case
3272 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3273 if (SubStmt.isInvalid())
3274 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003275
Douglas Gregorebe10102009-08-20 07:17:43 +00003276 // Default statements are always rebuilt
3277 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3278 move(SubStmt));
3279}
Mike Stump11289f42009-09-09 15:08:12 +00003280
Douglas Gregorebe10102009-08-20 07:17:43 +00003281template<typename Derived>
3282Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003283TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003284 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3285 if (SubStmt.isInvalid())
3286 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003287
Douglas Gregorebe10102009-08-20 07:17:43 +00003288 // FIXME: Pass the real colon location in.
3289 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3290 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3291 move(SubStmt));
3292}
Mike Stump11289f42009-09-09 15:08:12 +00003293
Douglas Gregorebe10102009-08-20 07:17:43 +00003294template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003295Sema::OwningStmtResult
3296TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003297 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003298 OwningExprResult Cond(SemaRef);
3299 VarDecl *ConditionVar = 0;
3300 if (S->getConditionVariable()) {
3301 ConditionVar
3302 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003303 getDerived().TransformDefinition(
3304 S->getConditionVariable()->getLocation(),
3305 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003306 if (!ConditionVar)
3307 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003308 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003309 Cond = getDerived().TransformExpr(S->getCond());
3310
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003311 if (Cond.isInvalid())
3312 return SemaRef.StmtError();
3313 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003314
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003315 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003316
Douglas Gregorebe10102009-08-20 07:17:43 +00003317 // Transform the "then" branch.
3318 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3319 if (Then.isInvalid())
3320 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003321
Douglas Gregorebe10102009-08-20 07:17:43 +00003322 // Transform the "else" branch.
3323 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3324 if (Else.isInvalid())
3325 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003326
Douglas Gregorebe10102009-08-20 07:17:43 +00003327 if (!getDerived().AlwaysRebuild() &&
3328 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003329 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003330 Then.get() == S->getThen() &&
3331 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003332 return SemaRef.Owned(S->Retain());
3333
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003334 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3335 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003336 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003337}
3338
3339template<typename Derived>
3340Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003341TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003342 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003343 OwningExprResult Cond(SemaRef);
3344 VarDecl *ConditionVar = 0;
3345 if (S->getConditionVariable()) {
3346 ConditionVar
3347 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003348 getDerived().TransformDefinition(
3349 S->getConditionVariable()->getLocation(),
3350 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003351 if (!ConditionVar)
3352 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003353 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003354 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003355
3356 if (Cond.isInvalid())
3357 return SemaRef.StmtError();
3358 }
Mike Stump11289f42009-09-09 15:08:12 +00003359
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003360 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003361
Douglas Gregorebe10102009-08-20 07:17:43 +00003362 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003363 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3364 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003365 if (Switch.isInvalid())
3366 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003367
Douglas Gregorebe10102009-08-20 07:17:43 +00003368 // Transform the body of the switch statement.
3369 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3370 if (Body.isInvalid())
3371 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003372
Douglas Gregorebe10102009-08-20 07:17:43 +00003373 // Complete the switch statement.
3374 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3375 move(Body));
3376}
Mike Stump11289f42009-09-09 15:08:12 +00003377
Douglas Gregorebe10102009-08-20 07:17:43 +00003378template<typename Derived>
3379Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003380TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003381 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003382 OwningExprResult Cond(SemaRef);
3383 VarDecl *ConditionVar = 0;
3384 if (S->getConditionVariable()) {
3385 ConditionVar
3386 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003387 getDerived().TransformDefinition(
3388 S->getConditionVariable()->getLocation(),
3389 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003390 if (!ConditionVar)
3391 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003392 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003393 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003394
3395 if (Cond.isInvalid())
3396 return SemaRef.StmtError();
3397 }
Mike Stump11289f42009-09-09 15:08:12 +00003398
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003399 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003400
Douglas Gregorebe10102009-08-20 07:17:43 +00003401 // Transform the body
3402 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3403 if (Body.isInvalid())
3404 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003405
Douglas Gregorebe10102009-08-20 07:17:43 +00003406 if (!getDerived().AlwaysRebuild() &&
3407 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003408 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003409 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003410 return SemaRef.Owned(S->Retain());
3411
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003412 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3413 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003414}
Mike Stump11289f42009-09-09 15:08:12 +00003415
Douglas Gregorebe10102009-08-20 07:17:43 +00003416template<typename Derived>
3417Sema::OwningStmtResult
3418TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3419 // Transform the condition
3420 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3421 if (Cond.isInvalid())
3422 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003423
Douglas Gregorebe10102009-08-20 07:17:43 +00003424 // Transform the body
3425 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3426 if (Body.isInvalid())
3427 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003428
Douglas Gregorebe10102009-08-20 07:17:43 +00003429 if (!getDerived().AlwaysRebuild() &&
3430 Cond.get() == S->getCond() &&
3431 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003432 return SemaRef.Owned(S->Retain());
3433
Douglas Gregorebe10102009-08-20 07:17:43 +00003434 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3435 /*FIXME:*/S->getWhileLoc(), move(Cond),
3436 S->getRParenLoc());
3437}
Mike Stump11289f42009-09-09 15:08:12 +00003438
Douglas Gregorebe10102009-08-20 07:17:43 +00003439template<typename Derived>
3440Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003441TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003442 // Transform the initialization statement
3443 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3444 if (Init.isInvalid())
3445 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003446
Douglas Gregorebe10102009-08-20 07:17:43 +00003447 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003448 OwningExprResult Cond(SemaRef);
3449 VarDecl *ConditionVar = 0;
3450 if (S->getConditionVariable()) {
3451 ConditionVar
3452 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003453 getDerived().TransformDefinition(
3454 S->getConditionVariable()->getLocation(),
3455 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003456 if (!ConditionVar)
3457 return SemaRef.StmtError();
3458 } else {
3459 Cond = getDerived().TransformExpr(S->getCond());
3460
3461 if (Cond.isInvalid())
3462 return SemaRef.StmtError();
3463 }
Mike Stump11289f42009-09-09 15:08:12 +00003464
Douglas Gregorebe10102009-08-20 07:17:43 +00003465 // Transform the increment
3466 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3467 if (Inc.isInvalid())
3468 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003469
Douglas Gregorebe10102009-08-20 07:17:43 +00003470 // Transform the body
3471 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3472 if (Body.isInvalid())
3473 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003474
Douglas Gregorebe10102009-08-20 07:17:43 +00003475 if (!getDerived().AlwaysRebuild() &&
3476 Init.get() == S->getInit() &&
3477 Cond.get() == S->getCond() &&
3478 Inc.get() == S->getInc() &&
3479 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003480 return SemaRef.Owned(S->Retain());
3481
Douglas Gregorebe10102009-08-20 07:17:43 +00003482 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003483 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003484 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003485 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003486 S->getRParenLoc(), move(Body));
3487}
3488
3489template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003490Sema::OwningStmtResult
3491TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003492 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003493 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003494 S->getLabel());
3495}
3496
3497template<typename Derived>
3498Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003499TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003500 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3501 if (Target.isInvalid())
3502 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003503
Douglas Gregorebe10102009-08-20 07:17:43 +00003504 if (!getDerived().AlwaysRebuild() &&
3505 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003506 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003507
3508 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3509 move(Target));
3510}
3511
3512template<typename Derived>
3513Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003514TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3515 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003516}
Mike Stump11289f42009-09-09 15:08:12 +00003517
Douglas Gregorebe10102009-08-20 07:17:43 +00003518template<typename Derived>
3519Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003520TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3521 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003522}
Mike Stump11289f42009-09-09 15:08:12 +00003523
Douglas Gregorebe10102009-08-20 07:17:43 +00003524template<typename Derived>
3525Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003526TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003527 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3528 if (Result.isInvalid())
3529 return SemaRef.StmtError();
3530
Mike Stump11289f42009-09-09 15:08:12 +00003531 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003532 // to tell whether the return type of the function has changed.
3533 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3534}
Mike Stump11289f42009-09-09 15:08:12 +00003535
Douglas Gregorebe10102009-08-20 07:17:43 +00003536template<typename Derived>
3537Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003538TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003539 bool DeclChanged = false;
3540 llvm::SmallVector<Decl *, 4> Decls;
3541 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3542 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003543 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3544 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003545 if (!Transformed)
3546 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003547
Douglas Gregorebe10102009-08-20 07:17:43 +00003548 if (Transformed != *D)
3549 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003550
Douglas Gregorebe10102009-08-20 07:17:43 +00003551 Decls.push_back(Transformed);
3552 }
Mike Stump11289f42009-09-09 15:08:12 +00003553
Douglas Gregorebe10102009-08-20 07:17:43 +00003554 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003555 return SemaRef.Owned(S->Retain());
3556
3557 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003558 S->getStartLoc(), S->getEndLoc());
3559}
Mike Stump11289f42009-09-09 15:08:12 +00003560
Douglas Gregorebe10102009-08-20 07:17:43 +00003561template<typename Derived>
3562Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003563TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003564 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003565 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003566}
3567
3568template<typename Derived>
3569Sema::OwningStmtResult
3570TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003571
3572 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3573 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003574 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003575
Anders Carlssonaaeef072010-01-24 05:50:09 +00003576 OwningExprResult AsmString(SemaRef);
3577 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3578
3579 bool ExprsChanged = false;
3580
3581 // Go through the outputs.
3582 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003583 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003584
Anders Carlssonaaeef072010-01-24 05:50:09 +00003585 // No need to transform the constraint literal.
3586 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3587
3588 // Transform the output expr.
3589 Expr *OutputExpr = S->getOutputExpr(I);
3590 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3591 if (Result.isInvalid())
3592 return SemaRef.StmtError();
3593
3594 ExprsChanged |= Result.get() != OutputExpr;
3595
3596 Exprs.push_back(Result.takeAs<Expr>());
3597 }
3598
3599 // Go through the inputs.
3600 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003601 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003602
Anders Carlssonaaeef072010-01-24 05:50:09 +00003603 // No need to transform the constraint literal.
3604 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3605
3606 // Transform the input expr.
3607 Expr *InputExpr = S->getInputExpr(I);
3608 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3609 if (Result.isInvalid())
3610 return SemaRef.StmtError();
3611
3612 ExprsChanged |= Result.get() != InputExpr;
3613
3614 Exprs.push_back(Result.takeAs<Expr>());
3615 }
3616
3617 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3618 return SemaRef.Owned(S->Retain());
3619
3620 // Go through the clobbers.
3621 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3622 Clobbers.push_back(S->getClobber(I)->Retain());
3623
3624 // No need to transform the asm string literal.
3625 AsmString = SemaRef.Owned(S->getAsmString());
3626
3627 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3628 S->isSimple(),
3629 S->isVolatile(),
3630 S->getNumOutputs(),
3631 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003632 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003633 move_arg(Constraints),
3634 move_arg(Exprs),
3635 move(AsmString),
3636 move_arg(Clobbers),
3637 S->getRParenLoc(),
3638 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003639}
3640
3641
3642template<typename Derived>
3643Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003644TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003645 // FIXME: Implement this
3646 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003647 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003648}
Mike Stump11289f42009-09-09 15:08:12 +00003649
Douglas Gregorebe10102009-08-20 07:17:43 +00003650template<typename Derived>
3651Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003652TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003653 // FIXME: Implement this
3654 assert(false && "Cannot transform an Objective-C @catch statement");
3655 return SemaRef.Owned(S->Retain());
3656}
Mike Stump11289f42009-09-09 15:08:12 +00003657
Douglas Gregorebe10102009-08-20 07:17:43 +00003658template<typename Derived>
3659Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003660TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003661 // FIXME: Implement this
3662 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003663 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003664}
Mike Stump11289f42009-09-09 15:08:12 +00003665
Douglas Gregorebe10102009-08-20 07:17:43 +00003666template<typename Derived>
3667Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003668TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003669 // FIXME: Implement this
3670 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003671 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003672}
Mike Stump11289f42009-09-09 15:08:12 +00003673
Douglas Gregorebe10102009-08-20 07:17:43 +00003674template<typename Derived>
3675Sema::OwningStmtResult
3676TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003677 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003678 // FIXME: Implement this
3679 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003680 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003681}
3682
3683template<typename Derived>
3684Sema::OwningStmtResult
3685TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003686 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003687 // FIXME: Implement this
3688 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003689 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003690}
3691
3692
3693template<typename Derived>
3694Sema::OwningStmtResult
3695TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3696 // Transform the exception declaration, if any.
3697 VarDecl *Var = 0;
3698 if (S->getExceptionDecl()) {
3699 VarDecl *ExceptionDecl = S->getExceptionDecl();
3700 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3701 ExceptionDecl->getDeclName());
3702
3703 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3704 if (T.isNull())
3705 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003706
Douglas Gregorebe10102009-08-20 07:17:43 +00003707 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3708 T,
John McCallbcd03502009-12-07 02:54:59 +00003709 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003710 ExceptionDecl->getIdentifier(),
3711 ExceptionDecl->getLocation(),
3712 /*FIXME: Inaccurate*/
3713 SourceRange(ExceptionDecl->getLocation()));
3714 if (!Var || Var->isInvalidDecl()) {
3715 if (Var)
3716 Var->Destroy(SemaRef.Context);
3717 return SemaRef.StmtError();
3718 }
3719 }
Mike Stump11289f42009-09-09 15:08:12 +00003720
Douglas Gregorebe10102009-08-20 07:17:43 +00003721 // Transform the actual exception handler.
3722 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3723 if (Handler.isInvalid()) {
3724 if (Var)
3725 Var->Destroy(SemaRef.Context);
3726 return SemaRef.StmtError();
3727 }
Mike Stump11289f42009-09-09 15:08:12 +00003728
Douglas Gregorebe10102009-08-20 07:17:43 +00003729 if (!getDerived().AlwaysRebuild() &&
3730 !Var &&
3731 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003732 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003733
3734 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3735 Var,
3736 move(Handler));
3737}
Mike Stump11289f42009-09-09 15:08:12 +00003738
Douglas Gregorebe10102009-08-20 07:17:43 +00003739template<typename Derived>
3740Sema::OwningStmtResult
3741TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3742 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003743 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003744 = getDerived().TransformCompoundStmt(S->getTryBlock());
3745 if (TryBlock.isInvalid())
3746 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003747
Douglas Gregorebe10102009-08-20 07:17:43 +00003748 // Transform the handlers.
3749 bool HandlerChanged = false;
3750 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3751 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003752 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003753 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3754 if (Handler.isInvalid())
3755 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003756
Douglas Gregorebe10102009-08-20 07:17:43 +00003757 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3758 Handlers.push_back(Handler.takeAs<Stmt>());
3759 }
Mike Stump11289f42009-09-09 15:08:12 +00003760
Douglas Gregorebe10102009-08-20 07:17:43 +00003761 if (!getDerived().AlwaysRebuild() &&
3762 TryBlock.get() == S->getTryBlock() &&
3763 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003764 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003765
3766 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003767 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003768}
Mike Stump11289f42009-09-09 15:08:12 +00003769
Douglas Gregorebe10102009-08-20 07:17:43 +00003770//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003771// Expression transformation
3772//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003773template<typename Derived>
3774Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003775TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003776 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003777}
Mike Stump11289f42009-09-09 15:08:12 +00003778
3779template<typename Derived>
3780Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003781TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003782 NestedNameSpecifier *Qualifier = 0;
3783 if (E->getQualifier()) {
3784 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003785 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003786 if (!Qualifier)
3787 return SemaRef.ExprError();
3788 }
John McCallce546572009-12-08 09:08:17 +00003789
3790 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003791 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
3792 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003793 if (!ND)
3794 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003795
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003796 if (!getDerived().AlwaysRebuild() &&
3797 Qualifier == E->getQualifier() &&
3798 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003799 !E->hasExplicitTemplateArgumentList()) {
3800
3801 // Mark it referenced in the new context regardless.
3802 // FIXME: this is a bit instantiation-specific.
3803 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3804
Mike Stump11289f42009-09-09 15:08:12 +00003805 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003806 }
John McCallce546572009-12-08 09:08:17 +00003807
3808 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3809 if (E->hasExplicitTemplateArgumentList()) {
3810 TemplateArgs = &TransArgs;
3811 TransArgs.setLAngleLoc(E->getLAngleLoc());
3812 TransArgs.setRAngleLoc(E->getRAngleLoc());
3813 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3814 TemplateArgumentLoc Loc;
3815 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3816 return SemaRef.ExprError();
3817 TransArgs.addArgument(Loc);
3818 }
3819 }
3820
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003821 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003822 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003823}
Mike Stump11289f42009-09-09 15:08:12 +00003824
Douglas Gregora16548e2009-08-11 05:31:07 +00003825template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003826Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003827TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003828 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003829}
Mike Stump11289f42009-09-09 15:08:12 +00003830
Douglas Gregora16548e2009-08-11 05:31:07 +00003831template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003832Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003833TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003834 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003835}
Mike Stump11289f42009-09-09 15:08:12 +00003836
Douglas Gregora16548e2009-08-11 05:31:07 +00003837template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003838Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003839TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003840 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003841}
Mike Stump11289f42009-09-09 15:08:12 +00003842
Douglas Gregora16548e2009-08-11 05:31:07 +00003843template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003844Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003845TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003846 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003847}
Mike Stump11289f42009-09-09 15:08:12 +00003848
Douglas Gregora16548e2009-08-11 05:31:07 +00003849template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003850Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003851TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003852 return SemaRef.Owned(E->Retain());
3853}
3854
3855template<typename Derived>
3856Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003857TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003858 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3859 if (SubExpr.isInvalid())
3860 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003861
Douglas Gregora16548e2009-08-11 05:31:07 +00003862 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003863 return SemaRef.Owned(E->Retain());
3864
3865 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003866 E->getRParen());
3867}
3868
Mike Stump11289f42009-09-09 15:08:12 +00003869template<typename Derived>
3870Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003871TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3872 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003873 if (SubExpr.isInvalid())
3874 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003875
Douglas Gregora16548e2009-08-11 05:31:07 +00003876 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003877 return SemaRef.Owned(E->Retain());
3878
Douglas Gregora16548e2009-08-11 05:31:07 +00003879 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3880 E->getOpcode(),
3881 move(SubExpr));
3882}
Mike Stump11289f42009-09-09 15:08:12 +00003883
Douglas Gregora16548e2009-08-11 05:31:07 +00003884template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003885Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003886TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003887 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003888 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003889
John McCallbcd03502009-12-07 02:54:59 +00003890 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003891 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003892 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003893
John McCall4c98fd82009-11-04 07:28:41 +00003894 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003895 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003896
John McCall4c98fd82009-11-04 07:28:41 +00003897 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003898 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003899 E->getSourceRange());
3900 }
Mike Stump11289f42009-09-09 15:08:12 +00003901
Douglas Gregora16548e2009-08-11 05:31:07 +00003902 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003903 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003904 // C++0x [expr.sizeof]p1:
3905 // The operand is either an expression, which is an unevaluated operand
3906 // [...]
3907 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003908
Douglas Gregora16548e2009-08-11 05:31:07 +00003909 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3910 if (SubExpr.isInvalid())
3911 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003912
Douglas Gregora16548e2009-08-11 05:31:07 +00003913 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3914 return SemaRef.Owned(E->Retain());
3915 }
Mike Stump11289f42009-09-09 15:08:12 +00003916
Douglas Gregora16548e2009-08-11 05:31:07 +00003917 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3918 E->isSizeOf(),
3919 E->getSourceRange());
3920}
Mike Stump11289f42009-09-09 15:08:12 +00003921
Douglas Gregora16548e2009-08-11 05:31:07 +00003922template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003923Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003924TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003925 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3926 if (LHS.isInvalid())
3927 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003928
Douglas Gregora16548e2009-08-11 05:31:07 +00003929 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3930 if (RHS.isInvalid())
3931 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003932
3933
Douglas Gregora16548e2009-08-11 05:31:07 +00003934 if (!getDerived().AlwaysRebuild() &&
3935 LHS.get() == E->getLHS() &&
3936 RHS.get() == E->getRHS())
3937 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003938
Douglas Gregora16548e2009-08-11 05:31:07 +00003939 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3940 /*FIXME:*/E->getLHS()->getLocStart(),
3941 move(RHS),
3942 E->getRBracketLoc());
3943}
Mike Stump11289f42009-09-09 15:08:12 +00003944
3945template<typename Derived>
3946Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003947TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003948 // Transform the callee.
3949 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3950 if (Callee.isInvalid())
3951 return SemaRef.ExprError();
3952
3953 // Transform arguments.
3954 bool ArgChanged = false;
3955 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3956 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3957 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3958 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3959 if (Arg.isInvalid())
3960 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003961
Douglas Gregora16548e2009-08-11 05:31:07 +00003962 // FIXME: Wrong source location information for the ','.
3963 FakeCommaLocs.push_back(
3964 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003965
3966 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003967 Args.push_back(Arg.takeAs<Expr>());
3968 }
Mike Stump11289f42009-09-09 15:08:12 +00003969
Douglas Gregora16548e2009-08-11 05:31:07 +00003970 if (!getDerived().AlwaysRebuild() &&
3971 Callee.get() == E->getCallee() &&
3972 !ArgChanged)
3973 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003974
Douglas Gregora16548e2009-08-11 05:31:07 +00003975 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003976 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003977 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3978 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3979 move_arg(Args),
3980 FakeCommaLocs.data(),
3981 E->getRParenLoc());
3982}
Mike Stump11289f42009-09-09 15:08:12 +00003983
3984template<typename Derived>
3985Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003986TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003987 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3988 if (Base.isInvalid())
3989 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003990
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003991 NestedNameSpecifier *Qualifier = 0;
3992 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003993 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003994 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003995 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003996 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003997 return SemaRef.ExprError();
3998 }
Mike Stump11289f42009-09-09 15:08:12 +00003999
Eli Friedman2cfcef62009-12-04 06:40:45 +00004000 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004001 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4002 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004003 if (!Member)
4004 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004005
John McCall16df1e52010-03-30 21:47:33 +00004006 NamedDecl *FoundDecl = E->getFoundDecl();
4007 if (FoundDecl == E->getMemberDecl()) {
4008 FoundDecl = Member;
4009 } else {
4010 FoundDecl = cast_or_null<NamedDecl>(
4011 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4012 if (!FoundDecl)
4013 return SemaRef.ExprError();
4014 }
4015
Douglas Gregora16548e2009-08-11 05:31:07 +00004016 if (!getDerived().AlwaysRebuild() &&
4017 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004018 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004019 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004020 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004021 !E->hasExplicitTemplateArgumentList()) {
4022
4023 // Mark it referenced in the new context regardless.
4024 // FIXME: this is a bit instantiation-specific.
4025 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004026 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004027 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004028
John McCall6b51f282009-11-23 01:53:49 +00004029 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004030 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00004031 TransArgs.setLAngleLoc(E->getLAngleLoc());
4032 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004033 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004034 TemplateArgumentLoc Loc;
4035 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004036 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004037 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004038 }
4039 }
4040
Douglas Gregora16548e2009-08-11 05:31:07 +00004041 // FIXME: Bogus source location for the operator
4042 SourceLocation FakeOperatorLoc
4043 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4044
John McCall38836f02010-01-15 08:34:02 +00004045 // FIXME: to do this check properly, we will need to preserve the
4046 // first-qualifier-in-scope here, just in case we had a dependent
4047 // base (and therefore couldn't do the check) and a
4048 // nested-name-qualifier (and therefore could do the lookup).
4049 NamedDecl *FirstQualifierInScope = 0;
4050
Douglas Gregora16548e2009-08-11 05:31:07 +00004051 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4052 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004053 Qualifier,
4054 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004055 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004056 Member,
John McCall16df1e52010-03-30 21:47:33 +00004057 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00004058 (E->hasExplicitTemplateArgumentList()
4059 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004060 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004061}
Mike Stump11289f42009-09-09 15:08:12 +00004062
Douglas Gregora16548e2009-08-11 05:31:07 +00004063template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004064Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004065TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004066 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4067 if (LHS.isInvalid())
4068 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004069
Douglas Gregora16548e2009-08-11 05:31:07 +00004070 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4071 if (RHS.isInvalid())
4072 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004073
Douglas Gregora16548e2009-08-11 05:31:07 +00004074 if (!getDerived().AlwaysRebuild() &&
4075 LHS.get() == E->getLHS() &&
4076 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004077 return SemaRef.Owned(E->Retain());
4078
Douglas Gregora16548e2009-08-11 05:31:07 +00004079 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4080 move(LHS), move(RHS));
4081}
4082
Mike Stump11289f42009-09-09 15:08:12 +00004083template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004084Sema::OwningExprResult
4085TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004086 CompoundAssignOperator *E) {
4087 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004088}
Mike Stump11289f42009-09-09 15:08:12 +00004089
Douglas Gregora16548e2009-08-11 05:31:07 +00004090template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004091Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004092TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004093 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4094 if (Cond.isInvalid())
4095 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004096
Douglas Gregora16548e2009-08-11 05:31:07 +00004097 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4098 if (LHS.isInvalid())
4099 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004100
Douglas Gregora16548e2009-08-11 05:31:07 +00004101 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4102 if (RHS.isInvalid())
4103 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004104
Douglas Gregora16548e2009-08-11 05:31:07 +00004105 if (!getDerived().AlwaysRebuild() &&
4106 Cond.get() == E->getCond() &&
4107 LHS.get() == E->getLHS() &&
4108 RHS.get() == E->getRHS())
4109 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004110
4111 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004112 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004113 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004114 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004115 move(RHS));
4116}
Mike Stump11289f42009-09-09 15:08:12 +00004117
4118template<typename Derived>
4119Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004120TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004121 // Implicit casts are eliminated during transformation, since they
4122 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004123 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004124}
Mike Stump11289f42009-09-09 15:08:12 +00004125
Douglas Gregora16548e2009-08-11 05:31:07 +00004126template<typename Derived>
4127Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004128TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004129 TypeSourceInfo *OldT;
4130 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004131 {
4132 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004133 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004134 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4135 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004136
John McCall97513962010-01-15 18:39:57 +00004137 OldT = E->getTypeInfoAsWritten();
4138 NewT = getDerived().TransformType(OldT);
4139 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004140 return SemaRef.ExprError();
4141 }
Mike Stump11289f42009-09-09 15:08:12 +00004142
Douglas Gregor6131b442009-12-12 18:16:41 +00004143 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004144 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004145 if (SubExpr.isInvalid())
4146 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004147
Douglas Gregora16548e2009-08-11 05:31:07 +00004148 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004149 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004150 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004151 return SemaRef.Owned(E->Retain());
4152
John McCall97513962010-01-15 18:39:57 +00004153 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4154 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004155 E->getRParenLoc(),
4156 move(SubExpr));
4157}
Mike Stump11289f42009-09-09 15:08:12 +00004158
Douglas Gregora16548e2009-08-11 05:31:07 +00004159template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004160Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004161TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004162 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4163 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4164 if (!NewT)
4165 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004166
Douglas Gregora16548e2009-08-11 05:31:07 +00004167 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4168 if (Init.isInvalid())
4169 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004170
Douglas Gregora16548e2009-08-11 05:31:07 +00004171 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004172 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004173 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004174 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004175
John McCall5d7aa7f2010-01-19 22:33:45 +00004176 // Note: the expression type doesn't necessarily match the
4177 // type-as-written, but that's okay, because it should always be
4178 // derivable from the initializer.
4179
John McCalle15bbff2010-01-18 19:35:47 +00004180 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004181 /*FIXME:*/E->getInitializer()->getLocEnd(),
4182 move(Init));
4183}
Mike Stump11289f42009-09-09 15:08:12 +00004184
Douglas Gregora16548e2009-08-11 05:31:07 +00004185template<typename Derived>
4186Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004187TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004188 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4189 if (Base.isInvalid())
4190 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004191
Douglas Gregora16548e2009-08-11 05:31:07 +00004192 if (!getDerived().AlwaysRebuild() &&
4193 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004194 return SemaRef.Owned(E->Retain());
4195
Douglas Gregora16548e2009-08-11 05:31:07 +00004196 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004197 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004198 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4199 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4200 E->getAccessorLoc(),
4201 E->getAccessor());
4202}
Mike Stump11289f42009-09-09 15:08:12 +00004203
Douglas Gregora16548e2009-08-11 05:31:07 +00004204template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004205Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004206TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004207 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004208
Douglas Gregora16548e2009-08-11 05:31:07 +00004209 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4210 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4211 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4212 if (Init.isInvalid())
4213 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004214
Douglas Gregora16548e2009-08-11 05:31:07 +00004215 InitChanged = InitChanged || Init.get() != E->getInit(I);
4216 Inits.push_back(Init.takeAs<Expr>());
4217 }
Mike Stump11289f42009-09-09 15:08:12 +00004218
Douglas Gregora16548e2009-08-11 05:31:07 +00004219 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004220 return SemaRef.Owned(E->Retain());
4221
Douglas Gregora16548e2009-08-11 05:31:07 +00004222 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004223 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004224}
Mike Stump11289f42009-09-09 15:08:12 +00004225
Douglas Gregora16548e2009-08-11 05:31:07 +00004226template<typename Derived>
4227Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004228TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004229 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004230
Douglas Gregorebe10102009-08-20 07:17:43 +00004231 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004232 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4233 if (Init.isInvalid())
4234 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004235
Douglas Gregorebe10102009-08-20 07:17:43 +00004236 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004237 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4238 bool ExprChanged = false;
4239 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4240 DEnd = E->designators_end();
4241 D != DEnd; ++D) {
4242 if (D->isFieldDesignator()) {
4243 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4244 D->getDotLoc(),
4245 D->getFieldLoc()));
4246 continue;
4247 }
Mike Stump11289f42009-09-09 15:08:12 +00004248
Douglas Gregora16548e2009-08-11 05:31:07 +00004249 if (D->isArrayDesignator()) {
4250 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4251 if (Index.isInvalid())
4252 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004253
4254 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004255 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004256
Douglas Gregora16548e2009-08-11 05:31:07 +00004257 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4258 ArrayExprs.push_back(Index.release());
4259 continue;
4260 }
Mike Stump11289f42009-09-09 15:08:12 +00004261
Douglas Gregora16548e2009-08-11 05:31:07 +00004262 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004263 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004264 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4265 if (Start.isInvalid())
4266 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004267
Douglas Gregora16548e2009-08-11 05:31:07 +00004268 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4269 if (End.isInvalid())
4270 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004271
4272 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004273 End.get(),
4274 D->getLBracketLoc(),
4275 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004276
Douglas Gregora16548e2009-08-11 05:31:07 +00004277 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4278 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004279
Douglas Gregora16548e2009-08-11 05:31:07 +00004280 ArrayExprs.push_back(Start.release());
4281 ArrayExprs.push_back(End.release());
4282 }
Mike Stump11289f42009-09-09 15:08:12 +00004283
Douglas Gregora16548e2009-08-11 05:31:07 +00004284 if (!getDerived().AlwaysRebuild() &&
4285 Init.get() == E->getInit() &&
4286 !ExprChanged)
4287 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004288
Douglas Gregora16548e2009-08-11 05:31:07 +00004289 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4290 E->getEqualOrColonLoc(),
4291 E->usesGNUSyntax(), move(Init));
4292}
Mike Stump11289f42009-09-09 15:08:12 +00004293
Douglas Gregora16548e2009-08-11 05:31:07 +00004294template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004295Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004296TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004297 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004298 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4299
4300 // FIXME: Will we ever have proper type location here? Will we actually
4301 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004302 QualType T = getDerived().TransformType(E->getType());
4303 if (T.isNull())
4304 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004305
Douglas Gregora16548e2009-08-11 05:31:07 +00004306 if (!getDerived().AlwaysRebuild() &&
4307 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004308 return SemaRef.Owned(E->Retain());
4309
Douglas Gregora16548e2009-08-11 05:31:07 +00004310 return getDerived().RebuildImplicitValueInitExpr(T);
4311}
Mike Stump11289f42009-09-09 15:08:12 +00004312
Douglas Gregora16548e2009-08-11 05:31:07 +00004313template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004314Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004315TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004316 // FIXME: Do we want the type as written?
4317 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004318
Douglas Gregora16548e2009-08-11 05:31:07 +00004319 {
4320 // FIXME: Source location isn't quite accurate.
4321 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4322 T = getDerived().TransformType(E->getType());
4323 if (T.isNull())
4324 return SemaRef.ExprError();
4325 }
Mike Stump11289f42009-09-09 15:08:12 +00004326
Douglas Gregora16548e2009-08-11 05:31:07 +00004327 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4328 if (SubExpr.isInvalid())
4329 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004330
Douglas Gregora16548e2009-08-11 05:31:07 +00004331 if (!getDerived().AlwaysRebuild() &&
4332 T == E->getType() &&
4333 SubExpr.get() == E->getSubExpr())
4334 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004335
Douglas Gregora16548e2009-08-11 05:31:07 +00004336 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4337 T, E->getRParenLoc());
4338}
4339
4340template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004341Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004342TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004343 bool ArgumentChanged = false;
4344 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4345 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4346 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4347 if (Init.isInvalid())
4348 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004349
Douglas Gregora16548e2009-08-11 05:31:07 +00004350 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4351 Inits.push_back(Init.takeAs<Expr>());
4352 }
Mike Stump11289f42009-09-09 15:08:12 +00004353
Douglas Gregora16548e2009-08-11 05:31:07 +00004354 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4355 move_arg(Inits),
4356 E->getRParenLoc());
4357}
Mike Stump11289f42009-09-09 15:08:12 +00004358
Douglas Gregora16548e2009-08-11 05:31:07 +00004359/// \brief Transform an address-of-label expression.
4360///
4361/// By default, the transformation of an address-of-label expression always
4362/// rebuilds the expression, so that the label identifier can be resolved to
4363/// the corresponding label statement by semantic analysis.
4364template<typename Derived>
4365Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004366TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004367 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4368 E->getLabel());
4369}
Mike Stump11289f42009-09-09 15:08:12 +00004370
4371template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004372Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004373TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004374 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004375 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4376 if (SubStmt.isInvalid())
4377 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004378
Douglas Gregora16548e2009-08-11 05:31:07 +00004379 if (!getDerived().AlwaysRebuild() &&
4380 SubStmt.get() == E->getSubStmt())
4381 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004382
4383 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004384 move(SubStmt),
4385 E->getRParenLoc());
4386}
Mike Stump11289f42009-09-09 15:08:12 +00004387
Douglas Gregora16548e2009-08-11 05:31:07 +00004388template<typename Derived>
4389Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004390TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004391 QualType T1, T2;
4392 {
4393 // FIXME: Source location isn't quite accurate.
4394 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004395
Douglas Gregora16548e2009-08-11 05:31:07 +00004396 T1 = getDerived().TransformType(E->getArgType1());
4397 if (T1.isNull())
4398 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004399
Douglas Gregora16548e2009-08-11 05:31:07 +00004400 T2 = getDerived().TransformType(E->getArgType2());
4401 if (T2.isNull())
4402 return SemaRef.ExprError();
4403 }
4404
4405 if (!getDerived().AlwaysRebuild() &&
4406 T1 == E->getArgType1() &&
4407 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004408 return SemaRef.Owned(E->Retain());
4409
Douglas Gregora16548e2009-08-11 05:31:07 +00004410 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4411 T1, T2, E->getRParenLoc());
4412}
Mike Stump11289f42009-09-09 15:08:12 +00004413
Douglas Gregora16548e2009-08-11 05:31:07 +00004414template<typename Derived>
4415Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004416TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004417 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4418 if (Cond.isInvalid())
4419 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004420
Douglas Gregora16548e2009-08-11 05:31:07 +00004421 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4422 if (LHS.isInvalid())
4423 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004424
Douglas Gregora16548e2009-08-11 05:31:07 +00004425 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4426 if (RHS.isInvalid())
4427 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004428
Douglas Gregora16548e2009-08-11 05:31:07 +00004429 if (!getDerived().AlwaysRebuild() &&
4430 Cond.get() == E->getCond() &&
4431 LHS.get() == E->getLHS() &&
4432 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004433 return SemaRef.Owned(E->Retain());
4434
Douglas Gregora16548e2009-08-11 05:31:07 +00004435 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4436 move(Cond), move(LHS), move(RHS),
4437 E->getRParenLoc());
4438}
Mike Stump11289f42009-09-09 15:08:12 +00004439
Douglas Gregora16548e2009-08-11 05:31:07 +00004440template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004441Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004442TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004443 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004444}
4445
4446template<typename Derived>
4447Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004448TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004449 switch (E->getOperator()) {
4450 case OO_New:
4451 case OO_Delete:
4452 case OO_Array_New:
4453 case OO_Array_Delete:
4454 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4455 return SemaRef.ExprError();
4456
4457 case OO_Call: {
4458 // This is a call to an object's operator().
4459 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4460
4461 // Transform the object itself.
4462 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4463 if (Object.isInvalid())
4464 return SemaRef.ExprError();
4465
4466 // FIXME: Poor location information
4467 SourceLocation FakeLParenLoc
4468 = SemaRef.PP.getLocForEndOfToken(
4469 static_cast<Expr *>(Object.get())->getLocEnd());
4470
4471 // Transform the call arguments.
4472 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4473 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4474 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004475 if (getDerived().DropCallArgument(E->getArg(I)))
4476 break;
4477
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004478 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4479 if (Arg.isInvalid())
4480 return SemaRef.ExprError();
4481
4482 // FIXME: Poor source location information.
4483 SourceLocation FakeCommaLoc
4484 = SemaRef.PP.getLocForEndOfToken(
4485 static_cast<Expr *>(Arg.get())->getLocEnd());
4486 FakeCommaLocs.push_back(FakeCommaLoc);
4487 Args.push_back(Arg.release());
4488 }
4489
4490 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4491 move_arg(Args),
4492 FakeCommaLocs.data(),
4493 E->getLocEnd());
4494 }
4495
4496#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4497 case OO_##Name:
4498#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4499#include "clang/Basic/OperatorKinds.def"
4500 case OO_Subscript:
4501 // Handled below.
4502 break;
4503
4504 case OO_Conditional:
4505 llvm_unreachable("conditional operator is not actually overloadable");
4506 return SemaRef.ExprError();
4507
4508 case OO_None:
4509 case NUM_OVERLOADED_OPERATORS:
4510 llvm_unreachable("not an overloaded operator?");
4511 return SemaRef.ExprError();
4512 }
4513
Douglas Gregora16548e2009-08-11 05:31:07 +00004514 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4515 if (Callee.isInvalid())
4516 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004517
John McCall47f29ea2009-12-08 09:21:05 +00004518 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004519 if (First.isInvalid())
4520 return SemaRef.ExprError();
4521
4522 OwningExprResult Second(SemaRef);
4523 if (E->getNumArgs() == 2) {
4524 Second = getDerived().TransformExpr(E->getArg(1));
4525 if (Second.isInvalid())
4526 return SemaRef.ExprError();
4527 }
Mike Stump11289f42009-09-09 15:08:12 +00004528
Douglas Gregora16548e2009-08-11 05:31:07 +00004529 if (!getDerived().AlwaysRebuild() &&
4530 Callee.get() == E->getCallee() &&
4531 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004532 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4533 return SemaRef.Owned(E->Retain());
4534
Douglas Gregora16548e2009-08-11 05:31:07 +00004535 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4536 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004537 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004538 move(First),
4539 move(Second));
4540}
Mike Stump11289f42009-09-09 15:08:12 +00004541
Douglas Gregora16548e2009-08-11 05:31:07 +00004542template<typename Derived>
4543Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004544TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4545 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004546}
Mike Stump11289f42009-09-09 15:08:12 +00004547
Douglas Gregora16548e2009-08-11 05:31:07 +00004548template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004549Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004550TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004551 TypeSourceInfo *OldT;
4552 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004553 {
4554 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004555 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004556 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4557 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004558
John McCall97513962010-01-15 18:39:57 +00004559 OldT = E->getTypeInfoAsWritten();
4560 NewT = getDerived().TransformType(OldT);
4561 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004562 return SemaRef.ExprError();
4563 }
Mike Stump11289f42009-09-09 15:08:12 +00004564
Douglas Gregor6131b442009-12-12 18:16:41 +00004565 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004566 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004567 if (SubExpr.isInvalid())
4568 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004569
Douglas Gregora16548e2009-08-11 05:31:07 +00004570 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004571 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004572 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004573 return SemaRef.Owned(E->Retain());
4574
Douglas Gregora16548e2009-08-11 05:31:07 +00004575 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004576 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004577 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4578 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4579 SourceLocation FakeRParenLoc
4580 = SemaRef.PP.getLocForEndOfToken(
4581 E->getSubExpr()->getSourceRange().getEnd());
4582 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004583 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004584 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004585 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004586 FakeRAngleLoc,
4587 FakeRAngleLoc,
4588 move(SubExpr),
4589 FakeRParenLoc);
4590}
Mike Stump11289f42009-09-09 15:08:12 +00004591
Douglas Gregora16548e2009-08-11 05:31:07 +00004592template<typename Derived>
4593Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004594TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4595 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004596}
Mike Stump11289f42009-09-09 15:08:12 +00004597
4598template<typename Derived>
4599Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004600TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4601 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004602}
4603
Douglas Gregora16548e2009-08-11 05:31:07 +00004604template<typename Derived>
4605Sema::OwningExprResult
4606TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004607 CXXReinterpretCastExpr *E) {
4608 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004609}
Mike Stump11289f42009-09-09 15:08:12 +00004610
Douglas Gregora16548e2009-08-11 05:31:07 +00004611template<typename Derived>
4612Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004613TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4614 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004615}
Mike Stump11289f42009-09-09 15:08:12 +00004616
Douglas Gregora16548e2009-08-11 05:31:07 +00004617template<typename Derived>
4618Sema::OwningExprResult
4619TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004620 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004621 TypeSourceInfo *OldT;
4622 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004623 {
4624 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004625
John McCall97513962010-01-15 18:39:57 +00004626 OldT = E->getTypeInfoAsWritten();
4627 NewT = getDerived().TransformType(OldT);
4628 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004629 return SemaRef.ExprError();
4630 }
Mike Stump11289f42009-09-09 15:08:12 +00004631
Douglas Gregor6131b442009-12-12 18:16:41 +00004632 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004633 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004634 if (SubExpr.isInvalid())
4635 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004636
Douglas Gregora16548e2009-08-11 05:31:07 +00004637 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004638 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004639 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004640 return SemaRef.Owned(E->Retain());
4641
Douglas Gregora16548e2009-08-11 05:31:07 +00004642 // FIXME: The end of the type's source range is wrong
4643 return getDerived().RebuildCXXFunctionalCastExpr(
4644 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004645 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004646 /*FIXME:*/E->getSubExpr()->getLocStart(),
4647 move(SubExpr),
4648 E->getRParenLoc());
4649}
Mike Stump11289f42009-09-09 15:08:12 +00004650
Douglas Gregora16548e2009-08-11 05:31:07 +00004651template<typename Derived>
4652Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004653TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004654 if (E->isTypeOperand()) {
4655 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004656
Douglas Gregora16548e2009-08-11 05:31:07 +00004657 QualType T = getDerived().TransformType(E->getTypeOperand());
4658 if (T.isNull())
4659 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004660
Douglas Gregora16548e2009-08-11 05:31:07 +00004661 if (!getDerived().AlwaysRebuild() &&
4662 T == E->getTypeOperand())
4663 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004664
Douglas Gregora16548e2009-08-11 05:31:07 +00004665 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4666 /*FIXME:*/E->getLocStart(),
4667 T,
4668 E->getLocEnd());
4669 }
Mike Stump11289f42009-09-09 15:08:12 +00004670
Douglas Gregora16548e2009-08-11 05:31:07 +00004671 // We don't know whether the expression is potentially evaluated until
4672 // after we perform semantic analysis, so the expression is potentially
4673 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004674 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004675 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004676
Douglas Gregora16548e2009-08-11 05:31:07 +00004677 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4678 if (SubExpr.isInvalid())
4679 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004680
Douglas Gregora16548e2009-08-11 05:31:07 +00004681 if (!getDerived().AlwaysRebuild() &&
4682 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004683 return SemaRef.Owned(E->Retain());
4684
Douglas Gregora16548e2009-08-11 05:31:07 +00004685 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4686 /*FIXME:*/E->getLocStart(),
4687 move(SubExpr),
4688 E->getLocEnd());
4689}
4690
4691template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004692Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004693TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004694 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004695}
Mike Stump11289f42009-09-09 15:08:12 +00004696
Douglas Gregora16548e2009-08-11 05:31:07 +00004697template<typename Derived>
4698Sema::OwningExprResult
4699TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004700 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004701 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004702}
Mike Stump11289f42009-09-09 15:08:12 +00004703
Douglas Gregora16548e2009-08-11 05:31:07 +00004704template<typename Derived>
4705Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004706TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004707 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004708
Douglas Gregora16548e2009-08-11 05:31:07 +00004709 QualType T = getDerived().TransformType(E->getType());
4710 if (T.isNull())
4711 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004712
Douglas Gregora16548e2009-08-11 05:31:07 +00004713 if (!getDerived().AlwaysRebuild() &&
4714 T == E->getType())
4715 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004716
Douglas Gregorb15af892010-01-07 23:12:05 +00004717 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004718}
Mike Stump11289f42009-09-09 15:08:12 +00004719
Douglas Gregora16548e2009-08-11 05:31:07 +00004720template<typename Derived>
4721Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004722TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004723 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4724 if (SubExpr.isInvalid())
4725 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004726
Douglas Gregora16548e2009-08-11 05:31:07 +00004727 if (!getDerived().AlwaysRebuild() &&
4728 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004729 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004730
4731 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4732}
Mike Stump11289f42009-09-09 15:08:12 +00004733
Douglas Gregora16548e2009-08-11 05:31:07 +00004734template<typename Derived>
4735Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004736TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004737 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004738 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
4739 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004740 if (!Param)
4741 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004742
Chandler Carruth794da4c2010-02-08 06:42:49 +00004743 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004744 Param == E->getParam())
4745 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004746
Douglas Gregor033f6752009-12-23 23:03:06 +00004747 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00004748}
Mike Stump11289f42009-09-09 15:08:12 +00004749
Douglas Gregora16548e2009-08-11 05:31:07 +00004750template<typename Derived>
4751Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004752TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004753 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4754
4755 QualType T = getDerived().TransformType(E->getType());
4756 if (T.isNull())
4757 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004758
Douglas Gregora16548e2009-08-11 05:31:07 +00004759 if (!getDerived().AlwaysRebuild() &&
4760 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004761 return SemaRef.Owned(E->Retain());
4762
4763 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004764 /*FIXME:*/E->getTypeBeginLoc(),
4765 T,
4766 E->getRParenLoc());
4767}
Mike Stump11289f42009-09-09 15:08:12 +00004768
Douglas Gregora16548e2009-08-11 05:31:07 +00004769template<typename Derived>
4770Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004771TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004772 // Transform the type that we're allocating
4773 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4774 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4775 if (AllocType.isNull())
4776 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004777
Douglas Gregora16548e2009-08-11 05:31:07 +00004778 // Transform the size of the array we're allocating (if any).
4779 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4780 if (ArraySize.isInvalid())
4781 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004782
Douglas Gregora16548e2009-08-11 05:31:07 +00004783 // Transform the placement arguments (if any).
4784 bool ArgumentChanged = false;
4785 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4786 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4787 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4788 if (Arg.isInvalid())
4789 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004790
Douglas Gregora16548e2009-08-11 05:31:07 +00004791 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4792 PlacementArgs.push_back(Arg.take());
4793 }
Mike Stump11289f42009-09-09 15:08:12 +00004794
Douglas Gregorebe10102009-08-20 07:17:43 +00004795 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004796 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4797 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4798 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4799 if (Arg.isInvalid())
4800 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004801
Douglas Gregora16548e2009-08-11 05:31:07 +00004802 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4803 ConstructorArgs.push_back(Arg.take());
4804 }
Mike Stump11289f42009-09-09 15:08:12 +00004805
Douglas Gregord2d9da02010-02-26 00:38:10 +00004806 // Transform constructor, new operator, and delete operator.
4807 CXXConstructorDecl *Constructor = 0;
4808 if (E->getConstructor()) {
4809 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004810 getDerived().TransformDecl(E->getLocStart(),
4811 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004812 if (!Constructor)
4813 return SemaRef.ExprError();
4814 }
4815
4816 FunctionDecl *OperatorNew = 0;
4817 if (E->getOperatorNew()) {
4818 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004819 getDerived().TransformDecl(E->getLocStart(),
4820 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004821 if (!OperatorNew)
4822 return SemaRef.ExprError();
4823 }
4824
4825 FunctionDecl *OperatorDelete = 0;
4826 if (E->getOperatorDelete()) {
4827 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004828 getDerived().TransformDecl(E->getLocStart(),
4829 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004830 if (!OperatorDelete)
4831 return SemaRef.ExprError();
4832 }
4833
Douglas Gregora16548e2009-08-11 05:31:07 +00004834 if (!getDerived().AlwaysRebuild() &&
4835 AllocType == E->getAllocatedType() &&
4836 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004837 Constructor == E->getConstructor() &&
4838 OperatorNew == E->getOperatorNew() &&
4839 OperatorDelete == E->getOperatorDelete() &&
4840 !ArgumentChanged) {
4841 // Mark any declarations we need as referenced.
4842 // FIXME: instantiation-specific.
4843 if (Constructor)
4844 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
4845 if (OperatorNew)
4846 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
4847 if (OperatorDelete)
4848 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004849 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004850 }
Mike Stump11289f42009-09-09 15:08:12 +00004851
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004852 if (!ArraySize.get()) {
4853 // If no array size was specified, but the new expression was
4854 // instantiated with an array type (e.g., "new T" where T is
4855 // instantiated with "int[4]"), extract the outer bound from the
4856 // array type as our array size. We do this with constant and
4857 // dependently-sized array types.
4858 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4859 if (!ArrayT) {
4860 // Do nothing
4861 } else if (const ConstantArrayType *ConsArrayT
4862 = dyn_cast<ConstantArrayType>(ArrayT)) {
4863 ArraySize
4864 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4865 ConsArrayT->getSize(),
4866 SemaRef.Context.getSizeType(),
4867 /*FIXME:*/E->getLocStart()));
4868 AllocType = ConsArrayT->getElementType();
4869 } else if (const DependentSizedArrayType *DepArrayT
4870 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4871 if (DepArrayT->getSizeExpr()) {
4872 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4873 AllocType = DepArrayT->getElementType();
4874 }
4875 }
4876 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004877 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4878 E->isGlobalNew(),
4879 /*FIXME:*/E->getLocStart(),
4880 move_arg(PlacementArgs),
4881 /*FIXME:*/E->getLocStart(),
4882 E->isParenTypeId(),
4883 AllocType,
4884 /*FIXME:*/E->getLocStart(),
4885 /*FIXME:*/SourceRange(),
4886 move(ArraySize),
4887 /*FIXME:*/E->getLocStart(),
4888 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004889 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004890}
Mike Stump11289f42009-09-09 15:08:12 +00004891
Douglas Gregora16548e2009-08-11 05:31:07 +00004892template<typename Derived>
4893Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004894TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004895 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4896 if (Operand.isInvalid())
4897 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004898
Douglas Gregord2d9da02010-02-26 00:38:10 +00004899 // Transform the delete operator, if known.
4900 FunctionDecl *OperatorDelete = 0;
4901 if (E->getOperatorDelete()) {
4902 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004903 getDerived().TransformDecl(E->getLocStart(),
4904 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004905 if (!OperatorDelete)
4906 return SemaRef.ExprError();
4907 }
4908
Douglas Gregora16548e2009-08-11 05:31:07 +00004909 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004910 Operand.get() == E->getArgument() &&
4911 OperatorDelete == E->getOperatorDelete()) {
4912 // Mark any declarations we need as referenced.
4913 // FIXME: instantiation-specific.
4914 if (OperatorDelete)
4915 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004916 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004917 }
Mike Stump11289f42009-09-09 15:08:12 +00004918
Douglas Gregora16548e2009-08-11 05:31:07 +00004919 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4920 E->isGlobalDelete(),
4921 E->isArrayForm(),
4922 move(Operand));
4923}
Mike Stump11289f42009-09-09 15:08:12 +00004924
Douglas Gregora16548e2009-08-11 05:31:07 +00004925template<typename Derived>
4926Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004927TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004928 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004929 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4930 if (Base.isInvalid())
4931 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004932
Douglas Gregor678f90d2010-02-25 01:56:36 +00004933 Sema::TypeTy *ObjectTypePtr = 0;
4934 bool MayBePseudoDestructor = false;
4935 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4936 E->getOperatorLoc(),
4937 E->isArrow()? tok::arrow : tok::period,
4938 ObjectTypePtr,
4939 MayBePseudoDestructor);
4940 if (Base.isInvalid())
4941 return SemaRef.ExprError();
4942
4943 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004944 NestedNameSpecifier *Qualifier
4945 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00004946 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00004947 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004948 if (E->getQualifier() && !Qualifier)
4949 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004950
Douglas Gregor678f90d2010-02-25 01:56:36 +00004951 PseudoDestructorTypeStorage Destroyed;
4952 if (E->getDestroyedTypeInfo()) {
4953 TypeSourceInfo *DestroyedTypeInfo
4954 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
4955 if (!DestroyedTypeInfo)
4956 return SemaRef.ExprError();
4957 Destroyed = DestroyedTypeInfo;
4958 } else if (ObjectType->isDependentType()) {
4959 // We aren't likely to be able to resolve the identifier down to a type
4960 // now anyway, so just retain the identifier.
4961 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
4962 E->getDestroyedTypeLoc());
4963 } else {
4964 // Look for a destructor known with the given name.
4965 CXXScopeSpec SS;
4966 if (Qualifier) {
4967 SS.setScopeRep(Qualifier);
4968 SS.setRange(E->getQualifierRange());
4969 }
4970
4971 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
4972 *E->getDestroyedTypeIdentifier(),
4973 E->getDestroyedTypeLoc(),
4974 /*Scope=*/0,
4975 SS, ObjectTypePtr,
4976 false);
4977 if (!T)
4978 return SemaRef.ExprError();
4979
4980 Destroyed
4981 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
4982 E->getDestroyedTypeLoc());
4983 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004984
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004985 TypeSourceInfo *ScopeTypeInfo = 0;
4986 if (E->getScopeTypeInfo()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00004987 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
4988 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004989 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00004990 return SemaRef.ExprError();
4991 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004992
Douglas Gregorad8a3362009-09-04 17:36:40 +00004993 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4994 E->getOperatorLoc(),
4995 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00004996 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004997 E->getQualifierRange(),
4998 ScopeTypeInfo,
4999 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005000 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005001 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005002}
Mike Stump11289f42009-09-09 15:08:12 +00005003
Douglas Gregorad8a3362009-09-04 17:36:40 +00005004template<typename Derived>
5005Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005006TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005007 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005008 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5009
5010 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5011 Sema::LookupOrdinaryName);
5012
5013 // Transform all the decls.
5014 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5015 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005016 NamedDecl *InstD = static_cast<NamedDecl*>(
5017 getDerived().TransformDecl(Old->getNameLoc(),
5018 *I));
John McCall84d87672009-12-10 09:41:52 +00005019 if (!InstD) {
5020 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5021 // This can happen because of dependent hiding.
5022 if (isa<UsingShadowDecl>(*I))
5023 continue;
5024 else
5025 return SemaRef.ExprError();
5026 }
John McCalle66edc12009-11-24 19:00:30 +00005027
5028 // Expand using declarations.
5029 if (isa<UsingDecl>(InstD)) {
5030 UsingDecl *UD = cast<UsingDecl>(InstD);
5031 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5032 E = UD->shadow_end(); I != E; ++I)
5033 R.addDecl(*I);
5034 continue;
5035 }
5036
5037 R.addDecl(InstD);
5038 }
5039
5040 // Resolve a kind, but don't do any further analysis. If it's
5041 // ambiguous, the callee needs to deal with it.
5042 R.resolveKind();
5043
5044 // Rebuild the nested-name qualifier, if present.
5045 CXXScopeSpec SS;
5046 NestedNameSpecifier *Qualifier = 0;
5047 if (Old->getQualifier()) {
5048 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005049 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005050 if (!Qualifier)
5051 return SemaRef.ExprError();
5052
5053 SS.setScopeRep(Qualifier);
5054 SS.setRange(Old->getQualifierRange());
5055 }
5056
5057 // If we have no template arguments, it's a normal declaration name.
5058 if (!Old->hasExplicitTemplateArgs())
5059 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5060
5061 // If we have template arguments, rebuild them, then rebuild the
5062 // templateid expression.
5063 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5064 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5065 TemplateArgumentLoc Loc;
5066 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5067 return SemaRef.ExprError();
5068 TransArgs.addArgument(Loc);
5069 }
5070
5071 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5072 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005073}
Mike Stump11289f42009-09-09 15:08:12 +00005074
Douglas Gregora16548e2009-08-11 05:31:07 +00005075template<typename Derived>
5076Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005077TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005078 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005079
Douglas Gregora16548e2009-08-11 05:31:07 +00005080 QualType T = getDerived().TransformType(E->getQueriedType());
5081 if (T.isNull())
5082 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005083
Douglas Gregora16548e2009-08-11 05:31:07 +00005084 if (!getDerived().AlwaysRebuild() &&
5085 T == E->getQueriedType())
5086 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005087
Douglas Gregora16548e2009-08-11 05:31:07 +00005088 // FIXME: Bad location information
5089 SourceLocation FakeLParenLoc
5090 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005091
5092 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005093 E->getLocStart(),
5094 /*FIXME:*/FakeLParenLoc,
5095 T,
5096 E->getLocEnd());
5097}
Mike Stump11289f42009-09-09 15:08:12 +00005098
Douglas Gregora16548e2009-08-11 05:31:07 +00005099template<typename Derived>
5100Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005101TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005102 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005103 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005104 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005105 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005106 if (!NNS)
5107 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005108
5109 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005110 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5111 if (!Name)
5112 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005113
John McCalle66edc12009-11-24 19:00:30 +00005114 if (!E->hasExplicitTemplateArgs()) {
5115 if (!getDerived().AlwaysRebuild() &&
5116 NNS == E->getQualifier() &&
5117 Name == E->getDeclName())
5118 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005119
John McCalle66edc12009-11-24 19:00:30 +00005120 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5121 E->getQualifierRange(),
5122 Name, E->getLocation(),
5123 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005124 }
John McCall6b51f282009-11-23 01:53:49 +00005125
5126 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005127 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005128 TemplateArgumentLoc Loc;
5129 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005130 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005131 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005132 }
5133
John McCalle66edc12009-11-24 19:00:30 +00005134 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5135 E->getQualifierRange(),
5136 Name, E->getLocation(),
5137 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005138}
5139
5140template<typename Derived>
5141Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005142TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005143 // CXXConstructExprs are always implicit, so when we have a
5144 // 1-argument construction we just transform that argument.
5145 if (E->getNumArgs() == 1 ||
5146 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5147 return getDerived().TransformExpr(E->getArg(0));
5148
Douglas Gregora16548e2009-08-11 05:31:07 +00005149 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5150
5151 QualType T = getDerived().TransformType(E->getType());
5152 if (T.isNull())
5153 return SemaRef.ExprError();
5154
5155 CXXConstructorDecl *Constructor
5156 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005157 getDerived().TransformDecl(E->getLocStart(),
5158 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005159 if (!Constructor)
5160 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005161
Douglas Gregora16548e2009-08-11 05:31:07 +00005162 bool ArgumentChanged = false;
5163 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005164 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005165 ArgEnd = E->arg_end();
5166 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005167 if (getDerived().DropCallArgument(*Arg)) {
5168 ArgumentChanged = true;
5169 break;
5170 }
5171
Douglas Gregora16548e2009-08-11 05:31:07 +00005172 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5173 if (TransArg.isInvalid())
5174 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005175
Douglas Gregora16548e2009-08-11 05:31:07 +00005176 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5177 Args.push_back(TransArg.takeAs<Expr>());
5178 }
5179
5180 if (!getDerived().AlwaysRebuild() &&
5181 T == E->getType() &&
5182 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005183 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005184 // Mark the constructor as referenced.
5185 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005186 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005187 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005188 }
Mike Stump11289f42009-09-09 15:08:12 +00005189
Douglas Gregordb121ba2009-12-14 16:27:04 +00005190 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5191 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005192 move_arg(Args));
5193}
Mike Stump11289f42009-09-09 15:08:12 +00005194
Douglas Gregora16548e2009-08-11 05:31:07 +00005195/// \brief Transform a C++ temporary-binding expression.
5196///
Douglas Gregor363b1512009-12-24 18:51:59 +00005197/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5198/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005199template<typename Derived>
5200Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005201TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005202 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005203}
Mike Stump11289f42009-09-09 15:08:12 +00005204
Anders Carlssonba6c4372010-01-29 02:39:32 +00005205/// \brief Transform a C++ reference-binding expression.
5206///
5207/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5208/// transform the subexpression and return that.
5209template<typename Derived>
5210Sema::OwningExprResult
5211TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5212 return getDerived().TransformExpr(E->getSubExpr());
5213}
5214
Mike Stump11289f42009-09-09 15:08:12 +00005215/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005216/// be destroyed after the expression is evaluated.
5217///
Douglas Gregor363b1512009-12-24 18:51:59 +00005218/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5219/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005220template<typename Derived>
5221Sema::OwningExprResult
5222TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005223 CXXExprWithTemporaries *E) {
5224 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005225}
Mike Stump11289f42009-09-09 15:08:12 +00005226
Douglas Gregora16548e2009-08-11 05:31:07 +00005227template<typename Derived>
5228Sema::OwningExprResult
5229TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005230 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005231 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5232 QualType T = getDerived().TransformType(E->getType());
5233 if (T.isNull())
5234 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005235
Douglas Gregora16548e2009-08-11 05:31:07 +00005236 CXXConstructorDecl *Constructor
5237 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005238 getDerived().TransformDecl(E->getLocStart(),
5239 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005240 if (!Constructor)
5241 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005242
Douglas Gregora16548e2009-08-11 05:31:07 +00005243 bool ArgumentChanged = false;
5244 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5245 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005246 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005247 ArgEnd = E->arg_end();
5248 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005249 if (getDerived().DropCallArgument(*Arg)) {
5250 ArgumentChanged = true;
5251 break;
5252 }
5253
Douglas Gregora16548e2009-08-11 05:31:07 +00005254 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5255 if (TransArg.isInvalid())
5256 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005257
Douglas Gregora16548e2009-08-11 05:31:07 +00005258 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5259 Args.push_back((Expr *)TransArg.release());
5260 }
Mike Stump11289f42009-09-09 15:08:12 +00005261
Douglas Gregora16548e2009-08-11 05:31:07 +00005262 if (!getDerived().AlwaysRebuild() &&
5263 T == E->getType() &&
5264 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005265 !ArgumentChanged) {
5266 // FIXME: Instantiation-specific
5267 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005268 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005269 }
Mike Stump11289f42009-09-09 15:08:12 +00005270
Douglas Gregora16548e2009-08-11 05:31:07 +00005271 // FIXME: Bogus location information
5272 SourceLocation CommaLoc;
5273 if (Args.size() > 1) {
5274 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005275 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005276 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5277 }
5278 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5279 T,
5280 /*FIXME:*/E->getTypeBeginLoc(),
5281 move_arg(Args),
5282 &CommaLoc,
5283 E->getLocEnd());
5284}
Mike Stump11289f42009-09-09 15:08:12 +00005285
Douglas Gregora16548e2009-08-11 05:31:07 +00005286template<typename Derived>
5287Sema::OwningExprResult
5288TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005289 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005290 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5291 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5292 if (T.isNull())
5293 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005294
Douglas Gregora16548e2009-08-11 05:31:07 +00005295 bool ArgumentChanged = false;
5296 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5297 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5298 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5299 ArgEnd = E->arg_end();
5300 Arg != ArgEnd; ++Arg) {
5301 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5302 if (TransArg.isInvalid())
5303 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005304
Douglas Gregora16548e2009-08-11 05:31:07 +00005305 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5306 FakeCommaLocs.push_back(
5307 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5308 Args.push_back(TransArg.takeAs<Expr>());
5309 }
Mike Stump11289f42009-09-09 15:08:12 +00005310
Douglas Gregora16548e2009-08-11 05:31:07 +00005311 if (!getDerived().AlwaysRebuild() &&
5312 T == E->getTypeAsWritten() &&
5313 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005314 return SemaRef.Owned(E->Retain());
5315
Douglas Gregora16548e2009-08-11 05:31:07 +00005316 // FIXME: we're faking the locations of the commas
5317 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5318 T,
5319 E->getLParenLoc(),
5320 move_arg(Args),
5321 FakeCommaLocs.data(),
5322 E->getRParenLoc());
5323}
Mike Stump11289f42009-09-09 15:08:12 +00005324
Douglas Gregora16548e2009-08-11 05:31:07 +00005325template<typename Derived>
5326Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005327TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005328 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005329 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005330 OwningExprResult Base(SemaRef, (Expr*) 0);
5331 Expr *OldBase;
5332 QualType BaseType;
5333 QualType ObjectType;
5334 if (!E->isImplicitAccess()) {
5335 OldBase = E->getBase();
5336 Base = getDerived().TransformExpr(OldBase);
5337 if (Base.isInvalid())
5338 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005339
John McCall2d74de92009-12-01 22:10:20 +00005340 // Start the member reference and compute the object's type.
5341 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005342 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005343 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5344 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005345 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005346 ObjectTy,
5347 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005348 if (Base.isInvalid())
5349 return SemaRef.ExprError();
5350
5351 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5352 BaseType = ((Expr*) Base.get())->getType();
5353 } else {
5354 OldBase = 0;
5355 BaseType = getDerived().TransformType(E->getBaseType());
5356 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5357 }
Mike Stump11289f42009-09-09 15:08:12 +00005358
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005359 // Transform the first part of the nested-name-specifier that qualifies
5360 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005361 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005362 = getDerived().TransformFirstQualifierInScope(
5363 E->getFirstQualifierFoundInScope(),
5364 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005365
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005366 NestedNameSpecifier *Qualifier = 0;
5367 if (E->getQualifier()) {
5368 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5369 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005370 ObjectType,
5371 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005372 if (!Qualifier)
5373 return SemaRef.ExprError();
5374 }
Mike Stump11289f42009-09-09 15:08:12 +00005375
5376 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005377 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005378 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005379 if (!Name)
5380 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005381
John McCall2d74de92009-12-01 22:10:20 +00005382 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005383 // This is a reference to a member without an explicitly-specified
5384 // template argument list. Optimize for this common case.
5385 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005386 Base.get() == OldBase &&
5387 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005388 Qualifier == E->getQualifier() &&
5389 Name == E->getMember() &&
5390 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005391 return SemaRef.Owned(E->Retain());
5392
John McCall8cd78132009-11-19 22:55:06 +00005393 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005394 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005395 E->isArrow(),
5396 E->getOperatorLoc(),
5397 Qualifier,
5398 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005399 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005400 Name,
5401 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005402 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005403 }
5404
John McCall6b51f282009-11-23 01:53:49 +00005405 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005406 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005407 TemplateArgumentLoc Loc;
5408 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005409 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005410 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005411 }
Mike Stump11289f42009-09-09 15:08:12 +00005412
John McCall8cd78132009-11-19 22:55:06 +00005413 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005414 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005415 E->isArrow(),
5416 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005417 Qualifier,
5418 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005419 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005420 Name,
5421 E->getMemberLoc(),
5422 &TransArgs);
5423}
5424
5425template<typename Derived>
5426Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005427TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005428 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005429 OwningExprResult Base(SemaRef, (Expr*) 0);
5430 QualType BaseType;
5431 if (!Old->isImplicitAccess()) {
5432 Base = getDerived().TransformExpr(Old->getBase());
5433 if (Base.isInvalid())
5434 return SemaRef.ExprError();
5435 BaseType = ((Expr*) Base.get())->getType();
5436 } else {
5437 BaseType = getDerived().TransformType(Old->getBaseType());
5438 }
John McCall10eae182009-11-30 22:42:35 +00005439
5440 NestedNameSpecifier *Qualifier = 0;
5441 if (Old->getQualifier()) {
5442 Qualifier
5443 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005444 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005445 if (Qualifier == 0)
5446 return SemaRef.ExprError();
5447 }
5448
5449 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5450 Sema::LookupOrdinaryName);
5451
5452 // Transform all the decls.
5453 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5454 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005455 NamedDecl *InstD = static_cast<NamedDecl*>(
5456 getDerived().TransformDecl(Old->getMemberLoc(),
5457 *I));
John McCall84d87672009-12-10 09:41:52 +00005458 if (!InstD) {
5459 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5460 // This can happen because of dependent hiding.
5461 if (isa<UsingShadowDecl>(*I))
5462 continue;
5463 else
5464 return SemaRef.ExprError();
5465 }
John McCall10eae182009-11-30 22:42:35 +00005466
5467 // Expand using declarations.
5468 if (isa<UsingDecl>(InstD)) {
5469 UsingDecl *UD = cast<UsingDecl>(InstD);
5470 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5471 E = UD->shadow_end(); I != E; ++I)
5472 R.addDecl(*I);
5473 continue;
5474 }
5475
5476 R.addDecl(InstD);
5477 }
5478
5479 R.resolveKind();
5480
5481 TemplateArgumentListInfo TransArgs;
5482 if (Old->hasExplicitTemplateArgs()) {
5483 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5484 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5485 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5486 TemplateArgumentLoc Loc;
5487 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5488 Loc))
5489 return SemaRef.ExprError();
5490 TransArgs.addArgument(Loc);
5491 }
5492 }
John McCall38836f02010-01-15 08:34:02 +00005493
5494 // FIXME: to do this check properly, we will need to preserve the
5495 // first-qualifier-in-scope here, just in case we had a dependent
5496 // base (and therefore couldn't do the check) and a
5497 // nested-name-qualifier (and therefore could do the lookup).
5498 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005499
5500 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005501 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005502 Old->getOperatorLoc(),
5503 Old->isArrow(),
5504 Qualifier,
5505 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005506 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005507 R,
5508 (Old->hasExplicitTemplateArgs()
5509 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005510}
5511
5512template<typename Derived>
5513Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005514TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005515 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005516}
5517
Mike Stump11289f42009-09-09 15:08:12 +00005518template<typename Derived>
5519Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005520TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00005521 TypeSourceInfo *EncodedTypeInfo
5522 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5523 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005524 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005525
Douglas Gregora16548e2009-08-11 05:31:07 +00005526 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00005527 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005528 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005529
5530 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00005531 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005532 E->getRParenLoc());
5533}
Mike Stump11289f42009-09-09 15:08:12 +00005534
Douglas Gregora16548e2009-08-11 05:31:07 +00005535template<typename Derived>
5536Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005537TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005538 // Transform arguments.
5539 bool ArgChanged = false;
5540 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5541 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5542 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5543 if (Arg.isInvalid())
5544 return SemaRef.ExprError();
5545
5546 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5547 Args.push_back(Arg.takeAs<Expr>());
5548 }
5549
5550 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5551 // Class message: transform the receiver type.
5552 TypeSourceInfo *ReceiverTypeInfo
5553 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5554 if (!ReceiverTypeInfo)
5555 return SemaRef.ExprError();
5556
5557 // If nothing changed, just retain the existing message send.
5558 if (!getDerived().AlwaysRebuild() &&
5559 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
5560 return SemaRef.Owned(E->Retain());
5561
5562 // Build a new class message send.
5563 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
5564 E->getSelector(),
5565 E->getMethodDecl(),
5566 E->getLeftLoc(),
5567 move_arg(Args),
5568 E->getRightLoc());
5569 }
5570
5571 // Instance message: transform the receiver
5572 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
5573 "Only class and instance messages may be instantiated");
5574 OwningExprResult Receiver
5575 = getDerived().TransformExpr(E->getInstanceReceiver());
5576 if (Receiver.isInvalid())
5577 return SemaRef.ExprError();
5578
5579 // If nothing changed, just retain the existing message send.
5580 if (!getDerived().AlwaysRebuild() &&
5581 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
5582 return SemaRef.Owned(E->Retain());
5583
5584 // Build a new instance message send.
5585 return getDerived().RebuildObjCMessageExpr(move(Receiver),
5586 E->getSelector(),
5587 E->getMethodDecl(),
5588 E->getLeftLoc(),
5589 move_arg(Args),
5590 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005591}
5592
Mike Stump11289f42009-09-09 15:08:12 +00005593template<typename Derived>
5594Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005595TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005596 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005597}
5598
Mike Stump11289f42009-09-09 15:08:12 +00005599template<typename Derived>
5600Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005601TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005602 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00005603 = cast_or_null<ObjCProtocolDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005604 getDerived().TransformDecl(E->getLocStart(),
5605 E->getProtocol()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005606 if (!Protocol)
5607 return SemaRef.ExprError();
5608
5609 if (!getDerived().AlwaysRebuild() &&
5610 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005611 return SemaRef.Owned(E->Retain());
5612
Douglas Gregora16548e2009-08-11 05:31:07 +00005613 return getDerived().RebuildObjCProtocolExpr(Protocol,
5614 E->getAtLoc(),
5615 /*FIXME:*/E->getAtLoc(),
5616 /*FIXME:*/E->getAtLoc(),
5617 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005618
Douglas Gregora16548e2009-08-11 05:31:07 +00005619}
5620
Mike Stump11289f42009-09-09 15:08:12 +00005621template<typename Derived>
5622Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005623TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005624 // FIXME: Implement this!
5625 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005626 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005627}
5628
Mike Stump11289f42009-09-09 15:08:12 +00005629template<typename Derived>
5630Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005631TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005632 // FIXME: Implement this!
5633 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005634 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005635}
5636
Mike Stump11289f42009-09-09 15:08:12 +00005637template<typename Derived>
5638Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005639TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005640 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005641 // FIXME: Implement this!
5642 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005643 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005644}
5645
Mike Stump11289f42009-09-09 15:08:12 +00005646template<typename Derived>
5647Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005648TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005649 // FIXME: Implement this!
5650 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005651 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005652}
5653
Mike Stump11289f42009-09-09 15:08:12 +00005654template<typename Derived>
5655Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005656TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005657 // FIXME: Implement this!
5658 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005659 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005660}
5661
Mike Stump11289f42009-09-09 15:08:12 +00005662template<typename Derived>
5663Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005664TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005665 bool ArgumentChanged = false;
5666 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5667 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5668 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5669 if (SubExpr.isInvalid())
5670 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005671
Douglas Gregora16548e2009-08-11 05:31:07 +00005672 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5673 SubExprs.push_back(SubExpr.takeAs<Expr>());
5674 }
Mike Stump11289f42009-09-09 15:08:12 +00005675
Douglas Gregora16548e2009-08-11 05:31:07 +00005676 if (!getDerived().AlwaysRebuild() &&
5677 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005678 return SemaRef.Owned(E->Retain());
5679
Douglas Gregora16548e2009-08-11 05:31:07 +00005680 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5681 move_arg(SubExprs),
5682 E->getRParenLoc());
5683}
5684
Mike Stump11289f42009-09-09 15:08:12 +00005685template<typename Derived>
5686Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005687TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005688 // FIXME: Implement this!
5689 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005690 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005691}
5692
Mike Stump11289f42009-09-09 15:08:12 +00005693template<typename Derived>
5694Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005695TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005696 // FIXME: Implement this!
5697 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005698 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005699}
Mike Stump11289f42009-09-09 15:08:12 +00005700
Douglas Gregora16548e2009-08-11 05:31:07 +00005701//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005702// Type reconstruction
5703//===----------------------------------------------------------------------===//
5704
Mike Stump11289f42009-09-09 15:08:12 +00005705template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005706QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5707 SourceLocation Star) {
5708 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005709 getDerived().getBaseEntity());
5710}
5711
Mike Stump11289f42009-09-09 15:08:12 +00005712template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005713QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5714 SourceLocation Star) {
5715 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005716 getDerived().getBaseEntity());
5717}
5718
Mike Stump11289f42009-09-09 15:08:12 +00005719template<typename Derived>
5720QualType
John McCall70dd5f62009-10-30 00:06:24 +00005721TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5722 bool WrittenAsLValue,
5723 SourceLocation Sigil) {
5724 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5725 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005726}
5727
5728template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005729QualType
John McCall70dd5f62009-10-30 00:06:24 +00005730TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5731 QualType ClassType,
5732 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005733 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005734 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005735}
5736
5737template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005738QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005739TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5740 ArrayType::ArraySizeModifier SizeMod,
5741 const llvm::APInt *Size,
5742 Expr *SizeExpr,
5743 unsigned IndexTypeQuals,
5744 SourceRange BracketsRange) {
5745 if (SizeExpr || !Size)
5746 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5747 IndexTypeQuals, BracketsRange,
5748 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005749
5750 QualType Types[] = {
5751 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5752 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5753 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005754 };
5755 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5756 QualType SizeType;
5757 for (unsigned I = 0; I != NumTypes; ++I)
5758 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5759 SizeType = Types[I];
5760 break;
5761 }
Mike Stump11289f42009-09-09 15:08:12 +00005762
Douglas Gregord6ff3322009-08-04 16:50:30 +00005763 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005764 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005765 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005766 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005767}
Mike Stump11289f42009-09-09 15:08:12 +00005768
Douglas Gregord6ff3322009-08-04 16:50:30 +00005769template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005770QualType
5771TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005772 ArrayType::ArraySizeModifier SizeMod,
5773 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005774 unsigned IndexTypeQuals,
5775 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005776 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005777 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005778}
5779
5780template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005781QualType
Mike Stump11289f42009-09-09 15:08:12 +00005782TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005783 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005784 unsigned IndexTypeQuals,
5785 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005786 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005787 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005788}
Mike Stump11289f42009-09-09 15:08:12 +00005789
Douglas Gregord6ff3322009-08-04 16:50:30 +00005790template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005791QualType
5792TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005793 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005794 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005795 unsigned IndexTypeQuals,
5796 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005797 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005798 SizeExpr.takeAs<Expr>(),
5799 IndexTypeQuals, BracketsRange);
5800}
5801
5802template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005803QualType
5804TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005805 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005806 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005807 unsigned IndexTypeQuals,
5808 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005809 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005810 SizeExpr.takeAs<Expr>(),
5811 IndexTypeQuals, BracketsRange);
5812}
5813
5814template<typename Derived>
5815QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00005816 unsigned NumElements,
5817 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005818 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00005819 return SemaRef.Context.getVectorType(ElementType, NumElements,
5820 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005821}
Mike Stump11289f42009-09-09 15:08:12 +00005822
Douglas Gregord6ff3322009-08-04 16:50:30 +00005823template<typename Derived>
5824QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5825 unsigned NumElements,
5826 SourceLocation AttributeLoc) {
5827 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5828 NumElements, true);
5829 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005830 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005831 AttributeLoc);
5832 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5833 AttributeLoc);
5834}
Mike Stump11289f42009-09-09 15:08:12 +00005835
Douglas Gregord6ff3322009-08-04 16:50:30 +00005836template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005837QualType
5838TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005839 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005840 SourceLocation AttributeLoc) {
5841 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5842}
Mike Stump11289f42009-09-09 15:08:12 +00005843
Douglas Gregord6ff3322009-08-04 16:50:30 +00005844template<typename Derived>
5845QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005846 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005847 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005848 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005849 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005850 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005851 Quals,
5852 getDerived().getBaseLocation(),
5853 getDerived().getBaseEntity());
5854}
Mike Stump11289f42009-09-09 15:08:12 +00005855
Douglas Gregord6ff3322009-08-04 16:50:30 +00005856template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005857QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5858 return SemaRef.Context.getFunctionNoProtoType(T);
5859}
5860
5861template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005862QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5863 assert(D && "no decl found");
5864 if (D->isInvalidDecl()) return QualType();
5865
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005866 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00005867 TypeDecl *Ty;
5868 if (isa<UsingDecl>(D)) {
5869 UsingDecl *Using = cast<UsingDecl>(D);
5870 assert(Using->isTypeName() &&
5871 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5872
5873 // A valid resolved using typename decl points to exactly one type decl.
5874 assert(++Using->shadow_begin() == Using->shadow_end());
5875 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5876
5877 } else {
5878 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5879 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5880 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5881 }
5882
5883 return SemaRef.Context.getTypeDeclType(Ty);
5884}
5885
5886template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005887QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005888 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5889}
5890
5891template<typename Derived>
5892QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5893 return SemaRef.Context.getTypeOfType(Underlying);
5894}
5895
5896template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005897QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005898 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5899}
5900
5901template<typename Derived>
5902QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005903 TemplateName Template,
5904 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005905 const TemplateArgumentListInfo &TemplateArgs) {
5906 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005907}
Mike Stump11289f42009-09-09 15:08:12 +00005908
Douglas Gregor1135c352009-08-06 05:28:30 +00005909template<typename Derived>
5910NestedNameSpecifier *
5911TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5912 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005913 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005914 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005915 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005916 CXXScopeSpec SS;
5917 // FIXME: The source location information is all wrong.
5918 SS.setRange(Range);
5919 SS.setScopeRep(Prefix);
5920 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005921 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005922 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005923 ObjectType,
5924 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005925 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005926}
5927
5928template<typename Derived>
5929NestedNameSpecifier *
5930TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5931 SourceRange Range,
5932 NamespaceDecl *NS) {
5933 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5934}
5935
5936template<typename Derived>
5937NestedNameSpecifier *
5938TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5939 SourceRange Range,
5940 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005941 QualType T) {
5942 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00005943 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005944 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005945 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5946 T.getTypePtr());
5947 }
Mike Stump11289f42009-09-09 15:08:12 +00005948
Douglas Gregor1135c352009-08-06 05:28:30 +00005949 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5950 return 0;
5951}
Mike Stump11289f42009-09-09 15:08:12 +00005952
Douglas Gregor71dc5092009-08-06 06:41:21 +00005953template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005954TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005955TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5956 bool TemplateKW,
5957 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005958 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005959 Template);
5960}
5961
5962template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005963TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005964TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005965 const IdentifierInfo &II,
5966 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005967 CXXScopeSpec SS;
5968 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005969 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005970 UnqualifiedId Name;
5971 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005972 return getSema().ActOnDependentTemplateName(
5973 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005974 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005975 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005976 ObjectType.getAsOpaquePtr(),
5977 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005978 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005979}
Mike Stump11289f42009-09-09 15:08:12 +00005980
Douglas Gregora16548e2009-08-11 05:31:07 +00005981template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005982TemplateName
5983TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5984 OverloadedOperatorKind Operator,
5985 QualType ObjectType) {
5986 CXXScopeSpec SS;
5987 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5988 SS.setScopeRep(Qualifier);
5989 UnqualifiedId Name;
5990 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5991 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5992 Operator, SymbolLocations);
5993 return getSema().ActOnDependentTemplateName(
5994 /*FIXME:*/getDerived().getBaseLocation(),
5995 SS,
5996 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005997 ObjectType.getAsOpaquePtr(),
5998 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005999 .template getAsVal<TemplateName>();
6000}
6001
6002template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006003Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006004TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6005 SourceLocation OpLoc,
6006 ExprArg Callee,
6007 ExprArg First,
6008 ExprArg Second) {
6009 Expr *FirstExpr = (Expr *)First.get();
6010 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006011 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006012 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006013
Douglas Gregora16548e2009-08-11 05:31:07 +00006014 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006015 if (Op == OO_Subscript) {
6016 if (!FirstExpr->getType()->isOverloadableType() &&
6017 !SecondExpr->getType()->isOverloadableType())
6018 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006019 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006020 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006021 } else if (Op == OO_Arrow) {
6022 // -> is never a builtin operation.
6023 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006024 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006025 if (!FirstExpr->getType()->isOverloadableType()) {
6026 // The argument is not of overloadable type, so try to create a
6027 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006028 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006029 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006030
Douglas Gregora16548e2009-08-11 05:31:07 +00006031 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6032 }
6033 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006034 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006035 !SecondExpr->getType()->isOverloadableType()) {
6036 // Neither of the arguments is an overloadable type, so try to
6037 // create a built-in binary operation.
6038 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006039 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006040 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6041 if (Result.isInvalid())
6042 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006043
Douglas Gregora16548e2009-08-11 05:31:07 +00006044 First.release();
6045 Second.release();
6046 return move(Result);
6047 }
6048 }
Mike Stump11289f42009-09-09 15:08:12 +00006049
6050 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006051 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006052 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006053
John McCalld14a8642009-11-21 08:51:07 +00006054 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6055 assert(ULE->requiresADL());
6056
6057 // FIXME: Do we have to check
6058 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006059 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006060 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006061 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006062 }
Mike Stump11289f42009-09-09 15:08:12 +00006063
Douglas Gregora16548e2009-08-11 05:31:07 +00006064 // Add any functions found via argument-dependent lookup.
6065 Expr *Args[2] = { FirstExpr, SecondExpr };
6066 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006067
Douglas Gregora16548e2009-08-11 05:31:07 +00006068 // Create the overloaded operator invocation for unary operators.
6069 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006070 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006071 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6072 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6073 }
Mike Stump11289f42009-09-09 15:08:12 +00006074
Sebastian Redladba46e2009-10-29 20:17:01 +00006075 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006076 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6077 OpLoc,
6078 move(First),
6079 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006080
Douglas Gregora16548e2009-08-11 05:31:07 +00006081 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006082 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006083 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006084 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006085 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6086 if (Result.isInvalid())
6087 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006088
Douglas Gregora16548e2009-08-11 05:31:07 +00006089 First.release();
6090 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006091 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006092}
Mike Stump11289f42009-09-09 15:08:12 +00006093
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006094template<typename Derived>
6095Sema::OwningExprResult
6096TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6097 SourceLocation OperatorLoc,
6098 bool isArrow,
6099 NestedNameSpecifier *Qualifier,
6100 SourceRange QualifierRange,
6101 TypeSourceInfo *ScopeType,
6102 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006103 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006104 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006105 CXXScopeSpec SS;
6106 if (Qualifier) {
6107 SS.setRange(QualifierRange);
6108 SS.setScopeRep(Qualifier);
6109 }
6110
6111 Expr *BaseE = (Expr *)Base.get();
6112 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006113 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006114 (!isArrow && !BaseType->getAs<RecordType>()) ||
6115 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006116 !BaseType->getAs<PointerType>()->getPointeeType()
6117 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006118 // This pseudo-destructor expression is still a pseudo-destructor.
6119 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6120 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006121 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006122 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006123 /*FIXME?*/true);
6124 }
6125
Douglas Gregor678f90d2010-02-25 01:56:36 +00006126 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006127 DeclarationName Name
6128 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6129 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
6130
6131 // FIXME: the ScopeType should be tacked onto SS.
6132
6133 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6134 OperatorLoc, isArrow,
6135 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006136 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006137 /*TemplateArgs*/ 0);
6138}
6139
Douglas Gregord6ff3322009-08-04 16:50:30 +00006140} // end namespace clang
6141
6142#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H