blob: 61091cdcc043d179ee3ce368b7fae3e60491146c [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);
Mike Stump11289f42009-09-09 15:08:12 +0000341
Douglas Gregorebe10102009-08-20 07:17:43 +0000342#define STMT(Node, Parent) \
343 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000344#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +0000345 OwningExprResult Transform##Node(Node *E);
Douglas Gregora16548e2009-08-11 05:31:07 +0000346#define ABSTRACT_EXPR(Node, Parent)
347#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000348
Douglas Gregord6ff3322009-08-04 16:50:30 +0000349 /// \brief Build a new pointer type given its pointee type.
350 ///
351 /// By default, performs semantic analysis when building the pointer type.
352 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000353 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000354
355 /// \brief Build a new block pointer type given its pointee type.
356 ///
Mike Stump11289f42009-09-09 15:08:12 +0000357 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000358 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000359 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000360
John McCall70dd5f62009-10-30 00:06:24 +0000361 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000362 ///
John McCall70dd5f62009-10-30 00:06:24 +0000363 /// By default, performs semantic analysis when building the
364 /// reference type. Subclasses may override this routine to provide
365 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000366 ///
John McCall70dd5f62009-10-30 00:06:24 +0000367 /// \param LValue whether the type was written with an lvalue sigil
368 /// or an rvalue sigil.
369 QualType RebuildReferenceType(QualType ReferentType,
370 bool LValue,
371 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000372
Douglas Gregord6ff3322009-08-04 16:50:30 +0000373 /// \brief Build a new member pointer type given the pointee type and the
374 /// class type it refers into.
375 ///
376 /// By default, performs semantic analysis when building the member pointer
377 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000378 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
379 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000380
John McCall550e0c22009-10-21 00:40:46 +0000381 /// \brief Build a new Objective C object pointer type.
John McCall70dd5f62009-10-30 00:06:24 +0000382 QualType RebuildObjCObjectPointerType(QualType PointeeType,
383 SourceLocation Sigil);
John McCall550e0c22009-10-21 00:40:46 +0000384
Douglas Gregord6ff3322009-08-04 16:50:30 +0000385 /// \brief Build a new array type given the element type, size
386 /// modifier, size of the array (if known), size expression, and index type
387 /// qualifiers.
388 ///
389 /// By default, performs semantic analysis when building the array type.
390 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000391 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000392 QualType RebuildArrayType(QualType ElementType,
393 ArrayType::ArraySizeModifier SizeMod,
394 const llvm::APInt *Size,
395 Expr *SizeExpr,
396 unsigned IndexTypeQuals,
397 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000398
Douglas Gregord6ff3322009-08-04 16:50:30 +0000399 /// \brief Build a new constant array type given the element type, size
400 /// modifier, (known) size of the array, and index type qualifiers.
401 ///
402 /// By default, performs semantic analysis when building the array type.
403 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000404 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000405 ArrayType::ArraySizeModifier SizeMod,
406 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000407 unsigned IndexTypeQuals,
408 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000409
Douglas Gregord6ff3322009-08-04 16:50:30 +0000410 /// \brief Build a new incomplete array type given the element type, size
411 /// modifier, and index type qualifiers.
412 ///
413 /// By default, performs semantic analysis when building the array type.
414 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000415 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000417 unsigned IndexTypeQuals,
418 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000419
Mike Stump11289f42009-09-09 15:08:12 +0000420 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000421 /// size modifier, size expression, and index type qualifiers.
422 ///
423 /// By default, performs semantic analysis when building the array type.
424 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000425 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000426 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000427 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000428 unsigned IndexTypeQuals,
429 SourceRange BracketsRange);
430
Mike Stump11289f42009-09-09 15:08:12 +0000431 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000432 /// size modifier, size expression, and index type qualifiers.
433 ///
434 /// By default, performs semantic analysis when building the array type.
435 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000436 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000437 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000438 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000439 unsigned IndexTypeQuals,
440 SourceRange BracketsRange);
441
442 /// \brief Build a new vector type given the element type and
443 /// number of elements.
444 ///
445 /// By default, performs semantic analysis when building the vector type.
446 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000447 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
448 bool IsAltiVec, bool IsPixel);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 /// \brief Build a new extended vector type given the element type and
451 /// number of elements.
452 ///
453 /// By default, performs semantic analysis when building the vector type.
454 /// Subclasses may override this routine to provide different behavior.
455 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
456 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000457
458 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000459 /// given the element type and number of elements.
460 ///
461 /// By default, performs semantic analysis when building the vector type.
462 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000463 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000464 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000465 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000466
Douglas Gregord6ff3322009-08-04 16:50:30 +0000467 /// \brief Build a new function type.
468 ///
469 /// By default, performs semantic analysis when building the function type.
470 /// Subclasses may override this routine to provide different behavior.
471 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000472 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000473 unsigned NumParamTypes,
474 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000475
John McCall550e0c22009-10-21 00:40:46 +0000476 /// \brief Build a new unprototyped function type.
477 QualType RebuildFunctionNoProtoType(QualType ResultType);
478
John McCallb96ec562009-12-04 22:46:56 +0000479 /// \brief Rebuild an unresolved typename type, given the decl that
480 /// the UnresolvedUsingTypenameDecl was transformed to.
481 QualType RebuildUnresolvedUsingType(Decl *D);
482
Douglas Gregord6ff3322009-08-04 16:50:30 +0000483 /// \brief Build a new typedef type.
484 QualType RebuildTypedefType(TypedefDecl *Typedef) {
485 return SemaRef.Context.getTypeDeclType(Typedef);
486 }
487
488 /// \brief Build a new class/struct/union type.
489 QualType RebuildRecordType(RecordDecl *Record) {
490 return SemaRef.Context.getTypeDeclType(Record);
491 }
492
493 /// \brief Build a new Enum type.
494 QualType RebuildEnumType(EnumDecl *Enum) {
495 return SemaRef.Context.getTypeDeclType(Enum);
496 }
John McCallfcc33b02009-09-05 00:15:47 +0000497
498 /// \brief Build a new elaborated type.
499 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
500 return SemaRef.Context.getElaboratedType(T, Tag);
501 }
Mike Stump11289f42009-09-09 15:08:12 +0000502
503 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000504 ///
505 /// By default, performs semantic analysis when building the typeof type.
506 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000507 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000508
Mike Stump11289f42009-09-09 15:08:12 +0000509 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000510 ///
511 /// By default, builds a new TypeOfType with the given underlying type.
512 QualType RebuildTypeOfType(QualType Underlying);
513
Mike Stump11289f42009-09-09 15:08:12 +0000514 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000515 ///
516 /// By default, performs semantic analysis when building the decltype type.
517 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000518 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000519
Douglas Gregord6ff3322009-08-04 16:50:30 +0000520 /// \brief Build a new template specialization type.
521 ///
522 /// By default, performs semantic analysis when building the template
523 /// specialization type. Subclasses may override this routine to provide
524 /// different behavior.
525 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000526 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000527 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000528
Douglas Gregord6ff3322009-08-04 16:50:30 +0000529 /// \brief Build a new qualified name type.
530 ///
Mike Stump11289f42009-09-09 15:08:12 +0000531 /// By default, builds a new QualifiedNameType type from the
532 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000533 /// this routine to provide different behavior.
534 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
535 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000536 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000537
538 /// \brief Build a new typename type that refers to a template-id.
539 ///
540 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000541 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000542 /// different behavior.
543 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
Douglas Gregor04922cb2010-02-13 06:05:33 +0000544 if (NNS->isDependent()) {
545 CXXScopeSpec SS;
546 SS.setScopeRep(NNS);
547 if (!SemaRef.computeDeclContext(SS))
548 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000549 cast<TemplateSpecializationType>(T));
Douglas Gregor04922cb2010-02-13 06:05:33 +0000550 }
Mike Stump11289f42009-09-09 15:08:12 +0000551
Douglas Gregord6ff3322009-08-04 16:50:30 +0000552 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000553 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000554
555 /// \brief Build a new typename type that refers to an identifier.
556 ///
557 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000558 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000559 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000560 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall0ad16662009-10-29 08:12:44 +0000561 const IdentifierInfo *Id,
562 SourceRange SR) {
563 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregor1135c352009-08-06 05:28:30 +0000564 }
Mike Stump11289f42009-09-09 15:08:12 +0000565
Douglas Gregor1135c352009-08-06 05:28:30 +0000566 /// \brief Build a new nested-name-specifier given the prefix and an
567 /// identifier that names the next step in the nested-name-specifier.
568 ///
569 /// By default, performs semantic analysis when building the new
570 /// nested-name-specifier. Subclasses may override this routine to provide
571 /// different behavior.
572 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
573 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000574 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000575 QualType ObjectType,
576 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000577
578 /// \brief Build a new nested-name-specifier given the prefix and the
579 /// namespace named in the next step in the nested-name-specifier.
580 ///
581 /// By default, performs semantic analysis when building the new
582 /// nested-name-specifier. Subclasses may override this routine to provide
583 /// different behavior.
584 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
585 SourceRange Range,
586 NamespaceDecl *NS);
587
588 /// \brief Build a new nested-name-specifier given the prefix and the
589 /// type named in the next step in the nested-name-specifier.
590 ///
591 /// By default, performs semantic analysis when building the new
592 /// nested-name-specifier. Subclasses may override this routine to provide
593 /// different behavior.
594 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
595 SourceRange Range,
596 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000597 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000598
599 /// \brief Build a new template name given a nested name specifier, a flag
600 /// indicating whether the "template" keyword was provided, and the template
601 /// that the template name refers to.
602 ///
603 /// By default, builds the new template name directly. Subclasses may override
604 /// this routine to provide different behavior.
605 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
606 bool TemplateKW,
607 TemplateDecl *Template);
608
Douglas Gregor71dc5092009-08-06 06:41:21 +0000609 /// \brief Build a new template name given a nested name specifier and the
610 /// name that is referred to as a template.
611 ///
612 /// By default, performs semantic analysis to determine whether the name can
613 /// be resolved to a specific template, then builds the appropriate kind of
614 /// template name. Subclasses may override this routine to provide different
615 /// behavior.
616 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000617 const IdentifierInfo &II,
618 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000619
Douglas Gregor71395fa2009-11-04 00:56:37 +0000620 /// \brief Build a new template name given a nested name specifier and the
621 /// overloaded operator name that is referred to as a template.
622 ///
623 /// By default, performs semantic analysis to determine whether the name can
624 /// be resolved to a specific template, then builds the appropriate kind of
625 /// template name. Subclasses may override this routine to provide different
626 /// behavior.
627 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
628 OverloadedOperatorKind Operator,
629 QualType ObjectType);
630
Douglas Gregorebe10102009-08-20 07:17:43 +0000631 /// \brief Build a new compound statement.
632 ///
633 /// By default, performs semantic analysis to build the new statement.
634 /// Subclasses may override this routine to provide different behavior.
635 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
636 MultiStmtArg Statements,
637 SourceLocation RBraceLoc,
638 bool IsStmtExpr) {
639 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
640 IsStmtExpr);
641 }
642
643 /// \brief Build a new case statement.
644 ///
645 /// By default, performs semantic analysis to build the new statement.
646 /// Subclasses may override this routine to provide different behavior.
647 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
648 ExprArg LHS,
649 SourceLocation EllipsisLoc,
650 ExprArg RHS,
651 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000652 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000653 ColonLoc);
654 }
Mike Stump11289f42009-09-09 15:08:12 +0000655
Douglas Gregorebe10102009-08-20 07:17:43 +0000656 /// \brief Attach the body to a new case statement.
657 ///
658 /// By default, performs semantic analysis to build the new statement.
659 /// Subclasses may override this routine to provide different behavior.
660 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
661 getSema().ActOnCaseStmtBody(S.get(), move(Body));
662 return move(S);
663 }
Mike Stump11289f42009-09-09 15:08:12 +0000664
Douglas Gregorebe10102009-08-20 07:17:43 +0000665 /// \brief Build a new default statement.
666 ///
667 /// By default, performs semantic analysis to build the new statement.
668 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000669 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000670 SourceLocation ColonLoc,
671 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000672 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000673 /*CurScope=*/0);
674 }
Mike Stump11289f42009-09-09 15:08:12 +0000675
Douglas Gregorebe10102009-08-20 07:17:43 +0000676 /// \brief Build a new label statement.
677 ///
678 /// By default, performs semantic analysis to build the new statement.
679 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000680 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000681 IdentifierInfo *Id,
682 SourceLocation ColonLoc,
683 StmtArg SubStmt) {
684 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
685 }
Mike Stump11289f42009-09-09 15:08:12 +0000686
Douglas Gregorebe10102009-08-20 07:17:43 +0000687 /// \brief Build a new "if" statement.
688 ///
689 /// By default, performs semantic analysis to build the new statement.
690 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000691 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000692 VarDecl *CondVar, StmtArg Then,
693 SourceLocation ElseLoc, StmtArg Else) {
694 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
695 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000696 }
Mike Stump11289f42009-09-09 15:08:12 +0000697
Douglas Gregorebe10102009-08-20 07:17:43 +0000698 /// \brief Start building a new switch statement.
699 ///
700 /// By default, performs semantic analysis to build the new statement.
701 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000702 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
703 VarDecl *CondVar) {
704 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000705 }
Mike Stump11289f42009-09-09 15:08:12 +0000706
Douglas Gregorebe10102009-08-20 07:17:43 +0000707 /// \brief Attach the body to the switch statement.
708 ///
709 /// By default, performs semantic analysis to build the new statement.
710 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000711 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000712 StmtArg Switch, StmtArg Body) {
713 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
714 move(Body));
715 }
716
717 /// \brief Build a new while statement.
718 ///
719 /// By default, performs semantic analysis to build the new statement.
720 /// Subclasses may override this routine to provide different behavior.
721 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
722 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000723 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000724 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000725 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
726 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000727 }
Mike Stump11289f42009-09-09 15:08:12 +0000728
Douglas Gregorebe10102009-08-20 07:17:43 +0000729 /// \brief Build a new do-while statement.
730 ///
731 /// By default, performs semantic analysis to build the new statement.
732 /// Subclasses may override this routine to provide different behavior.
733 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
734 SourceLocation WhileLoc,
735 SourceLocation LParenLoc,
736 ExprArg Cond,
737 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000738 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000739 move(Cond), RParenLoc);
740 }
741
742 /// \brief Build a new for statement.
743 ///
744 /// By default, performs semantic analysis to build the new statement.
745 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000746 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000747 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000748 StmtArg Init, Sema::FullExprArg Cond,
749 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000750 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000751 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
752 DeclPtrTy::make(CondVar),
753 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000754 }
Mike Stump11289f42009-09-09 15:08:12 +0000755
Douglas Gregorebe10102009-08-20 07:17:43 +0000756 /// \brief Build a new goto statement.
757 ///
758 /// By default, performs semantic analysis to build the new statement.
759 /// Subclasses may override this routine to provide different behavior.
760 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
761 SourceLocation LabelLoc,
762 LabelStmt *Label) {
763 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
764 }
765
766 /// \brief Build a new indirect goto statement.
767 ///
768 /// By default, performs semantic analysis to build the new statement.
769 /// Subclasses may override this routine to provide different behavior.
770 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
771 SourceLocation StarLoc,
772 ExprArg Target) {
773 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
774 }
Mike Stump11289f42009-09-09 15:08:12 +0000775
Douglas Gregorebe10102009-08-20 07:17:43 +0000776 /// \brief Build a new return statement.
777 ///
778 /// By default, performs semantic analysis to build the new statement.
779 /// Subclasses may override this routine to provide different behavior.
780 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
781 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000782
Douglas Gregorebe10102009-08-20 07:17:43 +0000783 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
784 }
Mike Stump11289f42009-09-09 15:08:12 +0000785
Douglas Gregorebe10102009-08-20 07:17:43 +0000786 /// \brief Build a new declaration statement.
787 ///
788 /// By default, performs semantic analysis to build the new statement.
789 /// Subclasses may override this routine to provide different behavior.
790 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000791 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000792 SourceLocation EndLoc) {
793 return getSema().Owned(
794 new (getSema().Context) DeclStmt(
795 DeclGroupRef::Create(getSema().Context,
796 Decls, NumDecls),
797 StartLoc, EndLoc));
798 }
Mike Stump11289f42009-09-09 15:08:12 +0000799
Anders Carlssonaaeef072010-01-24 05:50:09 +0000800 /// \brief Build a new inline asm 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 RebuildAsmStmt(SourceLocation AsmLoc,
805 bool IsSimple,
806 bool IsVolatile,
807 unsigned NumOutputs,
808 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000809 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000810 MultiExprArg Constraints,
811 MultiExprArg Exprs,
812 ExprArg AsmString,
813 MultiExprArg Clobbers,
814 SourceLocation RParenLoc,
815 bool MSAsm) {
816 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
817 NumInputs, Names, move(Constraints),
818 move(Exprs), move(AsmString), move(Clobbers),
819 RParenLoc, MSAsm);
820 }
821
Douglas Gregorebe10102009-08-20 07:17:43 +0000822 /// \brief Build a new C++ exception declaration.
823 ///
824 /// By default, performs semantic analysis to build the new decaration.
825 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000826 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000827 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000828 IdentifierInfo *Name,
829 SourceLocation Loc,
830 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000831 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000832 TypeRange);
833 }
834
835 /// \brief Build a new C++ catch statement.
836 ///
837 /// By default, performs semantic analysis to build the new statement.
838 /// Subclasses may override this routine to provide different behavior.
839 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
840 VarDecl *ExceptionDecl,
841 StmtArg Handler) {
842 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000843 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000844 Handler.takeAs<Stmt>()));
845 }
Mike Stump11289f42009-09-09 15:08:12 +0000846
Douglas Gregorebe10102009-08-20 07:17:43 +0000847 /// \brief Build a new C++ try 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 RebuildCXXTryStmt(SourceLocation TryLoc,
852 StmtArg TryBlock,
853 MultiStmtArg Handlers) {
854 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
855 }
Mike Stump11289f42009-09-09 15:08:12 +0000856
Douglas Gregora16548e2009-08-11 05:31:07 +0000857 /// \brief Build a new expression that references a declaration.
858 ///
859 /// By default, performs semantic analysis to build the new expression.
860 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +0000861 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
862 LookupResult &R,
863 bool RequiresADL) {
864 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
865 }
866
867
868 /// \brief Build a new expression that references a declaration.
869 ///
870 /// By default, performs semantic analysis to build the new expression.
871 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000872 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
873 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +0000874 ValueDecl *VD, SourceLocation Loc,
875 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000876 CXXScopeSpec SS;
877 SS.setScopeRep(Qualifier);
878 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +0000879
880 // FIXME: loses template args.
881
882 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +0000883 }
Mike Stump11289f42009-09-09 15:08:12 +0000884
Douglas Gregora16548e2009-08-11 05:31:07 +0000885 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000886 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000887 /// By default, performs semantic analysis to build the new expression.
888 /// Subclasses may override this routine to provide different behavior.
889 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
890 SourceLocation RParen) {
891 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
892 }
893
Douglas Gregorad8a3362009-09-04 17:36:40 +0000894 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000895 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000896 /// By default, performs semantic analysis to build the new expression.
897 /// Subclasses may override this routine to provide different behavior.
898 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
899 SourceLocation OperatorLoc,
900 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +0000901 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +0000902 SourceRange QualifierRange,
903 TypeSourceInfo *ScopeType,
904 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +0000905 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +0000906 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +0000907
Douglas Gregora16548e2009-08-11 05:31:07 +0000908 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000909 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000910 /// By default, performs semantic analysis to build the new expression.
911 /// Subclasses may override this routine to provide different behavior.
912 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
913 UnaryOperator::Opcode Opc,
914 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000915 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +0000916 }
Mike Stump11289f42009-09-09 15:08:12 +0000917
Douglas Gregora16548e2009-08-11 05:31:07 +0000918 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000919 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000920 /// By default, performs semantic analysis to build the new expression.
921 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +0000922 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +0000923 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000924 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +0000925 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +0000926 }
927
Mike Stump11289f42009-09-09 15:08:12 +0000928 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000929 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +0000930 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000931 /// By default, performs semantic analysis to build the new expression.
932 /// Subclasses may override this routine to provide different behavior.
933 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
934 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +0000935 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000936 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
937 OpLoc, isSizeOf, R);
938 if (Result.isInvalid())
939 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000940
Douglas Gregora16548e2009-08-11 05:31:07 +0000941 SubExpr.release();
942 return move(Result);
943 }
Mike Stump11289f42009-09-09 15:08:12 +0000944
Douglas Gregora16548e2009-08-11 05:31:07 +0000945 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +0000946 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000947 /// By default, performs semantic analysis to build the new expression.
948 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000949 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000950 SourceLocation LBracketLoc,
951 ExprArg RHS,
952 SourceLocation RBracketLoc) {
953 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000954 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000955 RBracketLoc);
956 }
957
958 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000959 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000960 /// By default, performs semantic analysis to build the new expression.
961 /// Subclasses may override this routine to provide different behavior.
962 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
963 MultiExprArg Args,
964 SourceLocation *CommaLocs,
965 SourceLocation RParenLoc) {
966 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
967 move(Args), CommaLocs, RParenLoc);
968 }
969
970 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000971 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000972 /// By default, performs semantic analysis to build the new expression.
973 /// Subclasses may override this routine to provide different behavior.
974 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000975 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000976 NestedNameSpecifier *Qualifier,
977 SourceRange QualifierRange,
978 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +0000979 ValueDecl *Member,
John McCall6b51f282009-11-23 01:53:49 +0000980 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000981 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +0000982 if (!Member->getDeclName()) {
983 // We have a reference to an unnamed field.
984 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +0000985
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000986 Expr *BaseExpr = Base.takeAs<Expr>();
Douglas Gregorcc3f3252010-03-03 23:55:11 +0000987 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000988 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +0000989
Mike Stump11289f42009-09-09 15:08:12 +0000990 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000991 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +0000992 Member, MemberLoc,
993 cast<FieldDecl>(Member)->getType());
994 return getSema().Owned(ME);
995 }
Mike Stump11289f42009-09-09 15:08:12 +0000996
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000997 CXXScopeSpec SS;
998 if (Qualifier) {
999 SS.setRange(QualifierRange);
1000 SS.setScopeRep(Qualifier);
1001 }
1002
John McCall2d74de92009-12-01 22:10:20 +00001003 QualType BaseType = ((Expr*) Base.get())->getType();
1004
John McCall38836f02010-01-15 08:34:02 +00001005 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1006 Sema::LookupMemberName);
1007 R.addDecl(Member);
1008 R.resolveKind();
1009
John McCall2d74de92009-12-01 22:10:20 +00001010 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1011 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001012 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001013 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001014 }
Mike Stump11289f42009-09-09 15:08:12 +00001015
Douglas Gregora16548e2009-08-11 05:31:07 +00001016 /// \brief Build a new binary operator 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.
1020 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1021 BinaryOperator::Opcode Opc,
1022 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001023 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1024 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001025 }
1026
1027 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001028 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001029 /// By default, performs semantic analysis to build the new expression.
1030 /// Subclasses may override this routine to provide different behavior.
1031 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1032 SourceLocation QuestionLoc,
1033 ExprArg LHS,
1034 SourceLocation ColonLoc,
1035 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001036 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001037 move(LHS), move(RHS));
1038 }
1039
Douglas Gregora16548e2009-08-11 05:31:07 +00001040 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001041 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001042 /// By default, performs semantic analysis to build the new expression.
1043 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001044 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1045 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001046 SourceLocation RParenLoc,
1047 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001048 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1049 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001050 }
Mike Stump11289f42009-09-09 15:08:12 +00001051
Douglas Gregora16548e2009-08-11 05:31:07 +00001052 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001053 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001054 /// By default, performs semantic analysis to build the new expression.
1055 /// Subclasses may override this routine to provide different behavior.
1056 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001057 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001058 SourceLocation RParenLoc,
1059 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001060 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1061 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001062 }
Mike Stump11289f42009-09-09 15:08:12 +00001063
Douglas Gregora16548e2009-08-11 05:31:07 +00001064 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001065 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001066 /// By default, performs semantic analysis to build the new expression.
1067 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001068 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001069 SourceLocation OpLoc,
1070 SourceLocation AccessorLoc,
1071 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001072
John McCall10eae182009-11-30 22:42:35 +00001073 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001074 QualType BaseType = ((Expr*) Base.get())->getType();
1075 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001076 OpLoc, /*IsArrow*/ false,
1077 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001078 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001079 AccessorLoc,
1080 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001081 }
Mike Stump11289f42009-09-09 15:08:12 +00001082
Douglas Gregora16548e2009-08-11 05:31:07 +00001083 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001084 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001085 /// By default, performs semantic analysis to build the new expression.
1086 /// Subclasses may override this routine to provide different behavior.
1087 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1088 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001089 SourceLocation RBraceLoc,
1090 QualType ResultTy) {
1091 OwningExprResult Result
1092 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1093 if (Result.isInvalid() || ResultTy->isDependentType())
1094 return move(Result);
1095
1096 // Patch in the result type we were given, which may have been computed
1097 // when the initial InitListExpr was built.
1098 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1099 ILE->setType(ResultTy);
1100 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001101 }
Mike Stump11289f42009-09-09 15:08:12 +00001102
Douglas Gregora16548e2009-08-11 05:31:07 +00001103 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001104 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001105 /// By default, performs semantic analysis to build the new expression.
1106 /// Subclasses may override this routine to provide different behavior.
1107 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1108 MultiExprArg ArrayExprs,
1109 SourceLocation EqualOrColonLoc,
1110 bool GNUSyntax,
1111 ExprArg Init) {
1112 OwningExprResult Result
1113 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1114 move(Init));
1115 if (Result.isInvalid())
1116 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001117
Douglas Gregora16548e2009-08-11 05:31:07 +00001118 ArrayExprs.release();
1119 return move(Result);
1120 }
Mike Stump11289f42009-09-09 15:08:12 +00001121
Douglas Gregora16548e2009-08-11 05:31:07 +00001122 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001123 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001124 /// By default, builds the implicit value initialization without performing
1125 /// any semantic analysis. Subclasses may override this routine to provide
1126 /// different behavior.
1127 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1128 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1129 }
Mike Stump11289f42009-09-09 15:08:12 +00001130
Douglas Gregora16548e2009-08-11 05:31:07 +00001131 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001132 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001133 /// By default, performs semantic analysis to build the new expression.
1134 /// Subclasses may override this routine to provide different behavior.
1135 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1136 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001137 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001138 RParenLoc);
1139 }
1140
1141 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001142 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001143 /// By default, performs semantic analysis to build the new expression.
1144 /// Subclasses may override this routine to provide different behavior.
1145 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1146 MultiExprArg SubExprs,
1147 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001148 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1149 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001150 }
Mike Stump11289f42009-09-09 15:08:12 +00001151
Douglas Gregora16548e2009-08-11 05:31:07 +00001152 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001153 ///
1154 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001155 /// rather than attempting to map the label statement itself.
1156 /// Subclasses may override this routine to provide different behavior.
1157 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1158 SourceLocation LabelLoc,
1159 LabelStmt *Label) {
1160 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1161 }
Mike Stump11289f42009-09-09 15:08:12 +00001162
Douglas Gregora16548e2009-08-11 05:31:07 +00001163 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001164 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001165 /// By default, performs semantic analysis to build the new expression.
1166 /// Subclasses may override this routine to provide different behavior.
1167 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1168 StmtArg SubStmt,
1169 SourceLocation RParenLoc) {
1170 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1171 }
Mike Stump11289f42009-09-09 15:08:12 +00001172
Douglas Gregora16548e2009-08-11 05:31:07 +00001173 /// \brief Build a new __builtin_types_compatible_p expression.
1174 ///
1175 /// By default, performs semantic analysis to build the new expression.
1176 /// Subclasses may override this routine to provide different behavior.
1177 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1178 QualType T1, QualType T2,
1179 SourceLocation RParenLoc) {
1180 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1181 T1.getAsOpaquePtr(),
1182 T2.getAsOpaquePtr(),
1183 RParenLoc);
1184 }
Mike Stump11289f42009-09-09 15:08:12 +00001185
Douglas Gregora16548e2009-08-11 05:31:07 +00001186 /// \brief Build a new __builtin_choose_expr expression.
1187 ///
1188 /// By default, performs semantic analysis to build the new expression.
1189 /// Subclasses may override this routine to provide different behavior.
1190 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1191 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1192 SourceLocation RParenLoc) {
1193 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1194 move(Cond), move(LHS), move(RHS),
1195 RParenLoc);
1196 }
Mike Stump11289f42009-09-09 15:08:12 +00001197
Douglas Gregora16548e2009-08-11 05:31:07 +00001198 /// \brief Build a new overloaded operator call expression.
1199 ///
1200 /// By default, performs semantic analysis to build the new expression.
1201 /// The semantic analysis provides the behavior of template instantiation,
1202 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001203 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001204 /// argument-dependent lookup, etc. Subclasses may override this routine to
1205 /// provide different behavior.
1206 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1207 SourceLocation OpLoc,
1208 ExprArg Callee,
1209 ExprArg First,
1210 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001211
1212 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001213 /// reinterpret_cast.
1214 ///
1215 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001216 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 /// Subclasses may override this routine to provide different behavior.
1218 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1219 Stmt::StmtClass Class,
1220 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001221 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001222 SourceLocation RAngleLoc,
1223 SourceLocation LParenLoc,
1224 ExprArg SubExpr,
1225 SourceLocation RParenLoc) {
1226 switch (Class) {
1227 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001228 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001229 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001230 move(SubExpr), RParenLoc);
1231
1232 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001233 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001234 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001235 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001236
Douglas Gregora16548e2009-08-11 05:31:07 +00001237 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001238 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001239 RAngleLoc, LParenLoc,
1240 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001241 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001242
Douglas Gregora16548e2009-08-11 05:31:07 +00001243 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001244 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001245 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001246 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001247
Douglas Gregora16548e2009-08-11 05:31:07 +00001248 default:
1249 assert(false && "Invalid C++ named cast");
1250 break;
1251 }
Mike Stump11289f42009-09-09 15:08:12 +00001252
Douglas Gregora16548e2009-08-11 05:31:07 +00001253 return getSema().ExprError();
1254 }
Mike Stump11289f42009-09-09 15:08:12 +00001255
Douglas Gregora16548e2009-08-11 05:31:07 +00001256 /// \brief Build a new C++ static_cast expression.
1257 ///
1258 /// By default, performs semantic analysis to build the new expression.
1259 /// Subclasses may override this routine to provide different behavior.
1260 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1261 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001262 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001263 SourceLocation RAngleLoc,
1264 SourceLocation LParenLoc,
1265 ExprArg SubExpr,
1266 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001267 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1268 TInfo, move(SubExpr),
1269 SourceRange(LAngleLoc, RAngleLoc),
1270 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001271 }
1272
1273 /// \brief Build a new C++ dynamic_cast expression.
1274 ///
1275 /// By default, performs semantic analysis to build the new expression.
1276 /// Subclasses may override this routine to provide different behavior.
1277 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1278 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001279 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 SourceLocation RAngleLoc,
1281 SourceLocation LParenLoc,
1282 ExprArg SubExpr,
1283 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001284 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1285 TInfo, move(SubExpr),
1286 SourceRange(LAngleLoc, RAngleLoc),
1287 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001288 }
1289
1290 /// \brief Build a new C++ reinterpret_cast expression.
1291 ///
1292 /// By default, performs semantic analysis to build the new expression.
1293 /// Subclasses may override this routine to provide different behavior.
1294 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
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) {
John McCalld377e042010-01-15 19:13:16 +00001301 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1302 TInfo, move(SubExpr),
1303 SourceRange(LAngleLoc, RAngleLoc),
1304 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001305 }
1306
1307 /// \brief Build a new C++ const_cast expression.
1308 ///
1309 /// By default, performs semantic analysis to build the new expression.
1310 /// Subclasses may override this routine to provide different behavior.
1311 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1312 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001313 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001314 SourceLocation RAngleLoc,
1315 SourceLocation LParenLoc,
1316 ExprArg SubExpr,
1317 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001318 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1319 TInfo, move(SubExpr),
1320 SourceRange(LAngleLoc, RAngleLoc),
1321 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 }
Mike Stump11289f42009-09-09 15:08:12 +00001323
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 /// \brief Build a new C++ functional-style cast expression.
1325 ///
1326 /// By default, performs semantic analysis to build the new expression.
1327 /// Subclasses may override this routine to provide different behavior.
1328 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001329 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 SourceLocation LParenLoc,
1331 ExprArg SubExpr,
1332 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001333 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001335 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001337 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001338 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001339 RParenLoc);
1340 }
Mike Stump11289f42009-09-09 15:08:12 +00001341
Douglas Gregora16548e2009-08-11 05:31:07 +00001342 /// \brief Build a new C++ typeid(type) expression.
1343 ///
1344 /// By default, performs semantic analysis to build the new expression.
1345 /// Subclasses may override this routine to provide different behavior.
1346 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1347 SourceLocation LParenLoc,
1348 QualType T,
1349 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001350 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 T.getAsOpaquePtr(), RParenLoc);
1352 }
Mike Stump11289f42009-09-09 15:08:12 +00001353
Douglas Gregora16548e2009-08-11 05:31:07 +00001354 /// \brief Build a new C++ typeid(expr) expression.
1355 ///
1356 /// By default, performs semantic analysis to build the new expression.
1357 /// Subclasses may override this routine to provide different behavior.
1358 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1359 SourceLocation LParenLoc,
1360 ExprArg Operand,
1361 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001362 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001363 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1364 RParenLoc);
1365 if (Result.isInvalid())
1366 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001367
Douglas Gregora16548e2009-08-11 05:31:07 +00001368 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1369 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001370 }
1371
Douglas Gregora16548e2009-08-11 05:31:07 +00001372 /// \brief Build a new C++ "this" expression.
1373 ///
1374 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001375 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001376 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001377 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001378 QualType ThisType,
1379 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001380 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001381 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1382 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001383 }
1384
1385 /// \brief Build a new C++ throw expression.
1386 ///
1387 /// By default, performs semantic analysis to build the new expression.
1388 /// Subclasses may override this routine to provide different behavior.
1389 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1390 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1391 }
1392
1393 /// \brief Build a new C++ default-argument expression.
1394 ///
1395 /// By default, builds a new default-argument expression, which does not
1396 /// require any semantic analysis. Subclasses may override this routine to
1397 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001398 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1399 ParmVarDecl *Param) {
1400 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1401 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001402 }
1403
1404 /// \brief Build a new C++ zero-initialization expression.
1405 ///
1406 /// By default, performs semantic analysis to build the new expression.
1407 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001408 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 SourceLocation LParenLoc,
1410 QualType T,
1411 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001412 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1413 T.getAsOpaquePtr(), LParenLoc,
1414 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 0, RParenLoc);
1416 }
Mike Stump11289f42009-09-09 15:08:12 +00001417
Douglas Gregora16548e2009-08-11 05:31:07 +00001418 /// \brief Build a new C++ "new" expression.
1419 ///
1420 /// By default, performs semantic analysis to build the new expression.
1421 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001422 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 bool UseGlobal,
1424 SourceLocation PlacementLParen,
1425 MultiExprArg PlacementArgs,
1426 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001427 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 QualType AllocType,
1429 SourceLocation TypeLoc,
1430 SourceRange TypeRange,
1431 ExprArg ArraySize,
1432 SourceLocation ConstructorLParen,
1433 MultiExprArg ConstructorArgs,
1434 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001435 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 PlacementLParen,
1437 move(PlacementArgs),
1438 PlacementRParen,
1439 ParenTypeId,
1440 AllocType,
1441 TypeLoc,
1442 TypeRange,
1443 move(ArraySize),
1444 ConstructorLParen,
1445 move(ConstructorArgs),
1446 ConstructorRParen);
1447 }
Mike Stump11289f42009-09-09 15:08:12 +00001448
Douglas Gregora16548e2009-08-11 05:31:07 +00001449 /// \brief Build a new C++ "delete" expression.
1450 ///
1451 /// By default, performs semantic analysis to build the new expression.
1452 /// Subclasses may override this routine to provide different behavior.
1453 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1454 bool IsGlobalDelete,
1455 bool IsArrayForm,
1456 ExprArg Operand) {
1457 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1458 move(Operand));
1459 }
Mike Stump11289f42009-09-09 15:08:12 +00001460
Douglas Gregora16548e2009-08-11 05:31:07 +00001461 /// \brief Build a new unary type trait expression.
1462 ///
1463 /// By default, performs semantic analysis to build the new expression.
1464 /// Subclasses may override this routine to provide different behavior.
1465 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1466 SourceLocation StartLoc,
1467 SourceLocation LParenLoc,
1468 QualType T,
1469 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001470 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001471 T.getAsOpaquePtr(), RParenLoc);
1472 }
1473
Mike Stump11289f42009-09-09 15:08:12 +00001474 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 /// expression.
1476 ///
1477 /// By default, performs semantic analysis to build the new expression.
1478 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001479 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001480 SourceRange QualifierRange,
1481 DeclarationName Name,
1482 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001483 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001484 CXXScopeSpec SS;
1485 SS.setRange(QualifierRange);
1486 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001487
1488 if (TemplateArgs)
1489 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1490 *TemplateArgs);
1491
1492 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001493 }
1494
1495 /// \brief Build a new template-id expression.
1496 ///
1497 /// By default, performs semantic analysis to build the new expression.
1498 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001499 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1500 LookupResult &R,
1501 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001502 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001503 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 }
1505
1506 /// \brief Build a new object-construction expression.
1507 ///
1508 /// By default, performs semantic analysis to build the new expression.
1509 /// Subclasses may override this routine to provide different behavior.
1510 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001511 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001512 CXXConstructorDecl *Constructor,
1513 bool IsElidable,
1514 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001515 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1516 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1517 ConvertedArgs))
1518 return getSema().ExprError();
1519
1520 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1521 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 }
1523
1524 /// \brief Build a new object-construction 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 RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1529 QualType T,
1530 SourceLocation LParenLoc,
1531 MultiExprArg Args,
1532 SourceLocation *Commas,
1533 SourceLocation RParenLoc) {
1534 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1535 T.getAsOpaquePtr(),
1536 LParenLoc,
1537 move(Args),
1538 Commas,
1539 RParenLoc);
1540 }
1541
1542 /// \brief Build a new object-construction expression.
1543 ///
1544 /// By default, performs semantic analysis to build the new expression.
1545 /// Subclasses may override this routine to provide different behavior.
1546 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1547 QualType T,
1548 SourceLocation LParenLoc,
1549 MultiExprArg Args,
1550 SourceLocation *Commas,
1551 SourceLocation RParenLoc) {
1552 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1553 /*FIXME*/LParenLoc),
1554 T.getAsOpaquePtr(),
1555 LParenLoc,
1556 move(Args),
1557 Commas,
1558 RParenLoc);
1559 }
Mike Stump11289f42009-09-09 15:08:12 +00001560
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 /// \brief Build a new member reference expression.
1562 ///
1563 /// By default, performs semantic analysis to build the new expression.
1564 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001565 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001566 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001567 bool IsArrow,
1568 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001569 NestedNameSpecifier *Qualifier,
1570 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001571 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001573 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001574 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001576 SS.setRange(QualifierRange);
1577 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001578
John McCall2d74de92009-12-01 22:10:20 +00001579 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1580 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001581 SS, FirstQualifierInScope,
1582 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 }
1584
John McCall10eae182009-11-30 22:42:35 +00001585 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001586 ///
1587 /// By default, performs semantic analysis to build the new expression.
1588 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001589 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001590 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001591 SourceLocation OperatorLoc,
1592 bool IsArrow,
1593 NestedNameSpecifier *Qualifier,
1594 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001595 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001596 LookupResult &R,
1597 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001598 CXXScopeSpec SS;
1599 SS.setRange(QualifierRange);
1600 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001601
John McCall2d74de92009-12-01 22:10:20 +00001602 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1603 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001604 SS, FirstQualifierInScope,
1605 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001606 }
Mike Stump11289f42009-09-09 15:08:12 +00001607
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 /// \brief Build a new Objective-C @encode expression.
1609 ///
1610 /// By default, performs semantic analysis to build the new expression.
1611 /// Subclasses may override this routine to provide different behavior.
1612 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1613 QualType T,
1614 SourceLocation RParenLoc) {
1615 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1616 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001617 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001618
1619 /// \brief Build a new Objective-C protocol expression.
1620 ///
1621 /// By default, performs semantic analysis to build the new expression.
1622 /// Subclasses may override this routine to provide different behavior.
1623 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1624 SourceLocation AtLoc,
1625 SourceLocation ProtoLoc,
1626 SourceLocation LParenLoc,
1627 SourceLocation RParenLoc) {
1628 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1629 Protocol->getIdentifier(),
1630 AtLoc,
1631 ProtoLoc,
1632 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001633 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 }
Mike Stump11289f42009-09-09 15:08:12 +00001635
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 /// \brief Build a new shuffle vector expression.
1637 ///
1638 /// By default, performs semantic analysis to build the new expression.
1639 /// Subclasses may override this routine to provide different behavior.
1640 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1641 MultiExprArg SubExprs,
1642 SourceLocation RParenLoc) {
1643 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001644 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1646 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1647 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1648 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001649
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 // Build a reference to the __builtin_shufflevector builtin
1651 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001652 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001653 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001654 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001655 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001656
1657 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 unsigned NumSubExprs = SubExprs.size();
1659 Expr **Subs = (Expr **)SubExprs.release();
1660 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1661 Subs, NumSubExprs,
1662 Builtin->getResultType(),
1663 RParenLoc);
1664 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001665
Douglas Gregora16548e2009-08-11 05:31:07 +00001666 // Type-check the __builtin_shufflevector expression.
1667 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1668 if (Result.isInvalid())
1669 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001670
Douglas Gregora16548e2009-08-11 05:31:07 +00001671 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001672 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001674};
Douglas Gregora16548e2009-08-11 05:31:07 +00001675
Douglas Gregorebe10102009-08-20 07:17:43 +00001676template<typename Derived>
1677Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1678 if (!S)
1679 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001680
Douglas Gregorebe10102009-08-20 07:17:43 +00001681 switch (S->getStmtClass()) {
1682 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001683
Douglas Gregorebe10102009-08-20 07:17:43 +00001684 // Transform individual statement nodes
1685#define STMT(Node, Parent) \
1686 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1687#define EXPR(Node, Parent)
1688#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001689
Douglas Gregorebe10102009-08-20 07:17:43 +00001690 // Transform expressions by calling TransformExpr.
1691#define STMT(Node, Parent)
John McCall2adddca2010-02-03 00:55:45 +00001692#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorebe10102009-08-20 07:17:43 +00001693#define EXPR(Node, Parent) case Stmt::Node##Class:
1694#include "clang/AST/StmtNodes.def"
1695 {
1696 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1697 if (E.isInvalid())
1698 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001699
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001700 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001701 }
Mike Stump11289f42009-09-09 15:08:12 +00001702 }
1703
Douglas Gregorebe10102009-08-20 07:17:43 +00001704 return SemaRef.Owned(S->Retain());
1705}
Mike Stump11289f42009-09-09 15:08:12 +00001706
1707
Douglas Gregore922c772009-08-04 22:27:00 +00001708template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001709Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 if (!E)
1711 return SemaRef.Owned(E);
1712
1713 switch (E->getStmtClass()) {
1714 case Stmt::NoStmtClass: break;
1715#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall2adddca2010-02-03 00:55:45 +00001716#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregora16548e2009-08-11 05:31:07 +00001717#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001718 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001719#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001720 }
1721
Douglas Gregora16548e2009-08-11 05:31:07 +00001722 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001723}
1724
1725template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001726NestedNameSpecifier *
1727TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001728 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001729 QualType ObjectType,
1730 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001731 if (!NNS)
1732 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001733
Douglas Gregorebe10102009-08-20 07:17:43 +00001734 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001735 NestedNameSpecifier *Prefix = NNS->getPrefix();
1736 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001737 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001738 ObjectType,
1739 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001740 if (!Prefix)
1741 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001742
1743 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001744 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001745 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001746 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001747 }
Mike Stump11289f42009-09-09 15:08:12 +00001748
Douglas Gregor1135c352009-08-06 05:28:30 +00001749 switch (NNS->getKind()) {
1750 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001751 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001752 "Identifier nested-name-specifier with no prefix or object type");
1753 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1754 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001755 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001756
1757 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001758 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001759 ObjectType,
1760 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001761
Douglas Gregor1135c352009-08-06 05:28:30 +00001762 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001763 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001764 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001765 getDerived().TransformDecl(Range.getBegin(),
1766 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001767 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001768 Prefix == NNS->getPrefix() &&
1769 NS == NNS->getAsNamespace())
1770 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001771
Douglas Gregor1135c352009-08-06 05:28:30 +00001772 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1773 }
Mike Stump11289f42009-09-09 15:08:12 +00001774
Douglas Gregor1135c352009-08-06 05:28:30 +00001775 case NestedNameSpecifier::Global:
1776 // There is no meaningful transformation that one could perform on the
1777 // global scope.
1778 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001779
Douglas Gregor1135c352009-08-06 05:28:30 +00001780 case NestedNameSpecifier::TypeSpecWithTemplate:
1781 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001782 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00001783 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
1784 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001785 if (T.isNull())
1786 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001787
Douglas Gregor1135c352009-08-06 05:28:30 +00001788 if (!getDerived().AlwaysRebuild() &&
1789 Prefix == NNS->getPrefix() &&
1790 T == QualType(NNS->getAsType(), 0))
1791 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001792
1793 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1794 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00001795 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001796 }
1797 }
Mike Stump11289f42009-09-09 15:08:12 +00001798
Douglas Gregor1135c352009-08-06 05:28:30 +00001799 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001800 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001801}
1802
1803template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001804DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001805TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001806 SourceLocation Loc,
1807 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001808 if (!Name)
1809 return Name;
1810
1811 switch (Name.getNameKind()) {
1812 case DeclarationName::Identifier:
1813 case DeclarationName::ObjCZeroArgSelector:
1814 case DeclarationName::ObjCOneArgSelector:
1815 case DeclarationName::ObjCMultiArgSelector:
1816 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001817 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001818 case DeclarationName::CXXUsingDirective:
1819 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001820
Douglas Gregorf816bd72009-09-03 22:13:48 +00001821 case DeclarationName::CXXConstructorName:
1822 case DeclarationName::CXXDestructorName:
1823 case DeclarationName::CXXConversionFunctionName: {
1824 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorfe17d252010-02-16 19:09:40 +00001825 QualType T = getDerived().TransformType(Name.getCXXNameType(),
1826 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00001827 if (T.isNull())
1828 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001829
Douglas Gregorf816bd72009-09-03 22:13:48 +00001830 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001831 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001832 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001833 }
Mike Stump11289f42009-09-09 15:08:12 +00001834 }
1835
Douglas Gregorf816bd72009-09-03 22:13:48 +00001836 return DeclarationName();
1837}
1838
1839template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001840TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001841TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1842 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001843 SourceLocation Loc = getDerived().getBaseLocation();
1844
Douglas Gregor71dc5092009-08-06 06:41:21 +00001845 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001846 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001847 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001848 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1849 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001850 if (!NNS)
1851 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001852
Douglas Gregor71dc5092009-08-06 06:41:21 +00001853 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001854 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001855 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001856 if (!TransTemplate)
1857 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001858
Douglas Gregor71dc5092009-08-06 06:41:21 +00001859 if (!getDerived().AlwaysRebuild() &&
1860 NNS == QTN->getQualifier() &&
1861 TransTemplate == Template)
1862 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001863
Douglas Gregor71dc5092009-08-06 06:41:21 +00001864 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1865 TransTemplate);
1866 }
Mike Stump11289f42009-09-09 15:08:12 +00001867
John McCalle66edc12009-11-24 19:00:30 +00001868 // These should be getting filtered out before they make it into the AST.
1869 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001870 }
Mike Stump11289f42009-09-09 15:08:12 +00001871
Douglas Gregor71dc5092009-08-06 06:41:21 +00001872 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001873 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001874 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001875 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1876 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00001877 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001878 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001879
Douglas Gregor71dc5092009-08-06 06:41:21 +00001880 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001881 NNS == DTN->getQualifier() &&
1882 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001883 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001884
Douglas Gregor71395fa2009-11-04 00:56:37 +00001885 if (DTN->isIdentifier())
1886 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1887 ObjectType);
1888
1889 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1890 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001891 }
Mike Stump11289f42009-09-09 15:08:12 +00001892
Douglas Gregor71dc5092009-08-06 06:41:21 +00001893 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001894 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001895 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001896 if (!TransTemplate)
1897 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001898
Douglas Gregor71dc5092009-08-06 06:41:21 +00001899 if (!getDerived().AlwaysRebuild() &&
1900 TransTemplate == Template)
1901 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001902
Douglas Gregor71dc5092009-08-06 06:41:21 +00001903 return TemplateName(TransTemplate);
1904 }
Mike Stump11289f42009-09-09 15:08:12 +00001905
John McCalle66edc12009-11-24 19:00:30 +00001906 // These should be getting filtered out before they reach the AST.
1907 assert(false && "overloaded function decl survived to here");
1908 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00001909}
1910
1911template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001912void TreeTransform<Derived>::InventTemplateArgumentLoc(
1913 const TemplateArgument &Arg,
1914 TemplateArgumentLoc &Output) {
1915 SourceLocation Loc = getDerived().getBaseLocation();
1916 switch (Arg.getKind()) {
1917 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00001918 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00001919 break;
1920
1921 case TemplateArgument::Type:
1922 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00001923 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00001924
1925 break;
1926
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001927 case TemplateArgument::Template:
1928 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1929 break;
1930
John McCall0ad16662009-10-29 08:12:44 +00001931 case TemplateArgument::Expression:
1932 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1933 break;
1934
1935 case TemplateArgument::Declaration:
1936 case TemplateArgument::Integral:
1937 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00001938 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00001939 break;
1940 }
1941}
1942
1943template<typename Derived>
1944bool TreeTransform<Derived>::TransformTemplateArgument(
1945 const TemplateArgumentLoc &Input,
1946 TemplateArgumentLoc &Output) {
1947 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00001948 switch (Arg.getKind()) {
1949 case TemplateArgument::Null:
1950 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001951 Output = Input;
1952 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001953
Douglas Gregore922c772009-08-04 22:27:00 +00001954 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00001955 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00001956 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00001957 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00001958
1959 DI = getDerived().TransformType(DI);
1960 if (!DI) return true;
1961
1962 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1963 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001964 }
Mike Stump11289f42009-09-09 15:08:12 +00001965
Douglas Gregore922c772009-08-04 22:27:00 +00001966 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001967 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001968 DeclarationName Name;
1969 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1970 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001971 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001972 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001973 if (!D) return true;
1974
John McCall0d07eb32009-10-29 18:45:58 +00001975 Expr *SourceExpr = Input.getSourceDeclExpression();
1976 if (SourceExpr) {
1977 EnterExpressionEvaluationContext Unevaluated(getSema(),
1978 Action::Unevaluated);
1979 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1980 if (E.isInvalid())
1981 SourceExpr = NULL;
1982 else {
1983 SourceExpr = E.takeAs<Expr>();
1984 SourceExpr->Retain();
1985 }
1986 }
1987
1988 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00001989 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001990 }
Mike Stump11289f42009-09-09 15:08:12 +00001991
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001992 case TemplateArgument::Template: {
1993 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1994 TemplateName Template
1995 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1996 if (Template.isNull())
1997 return true;
1998
1999 Output = TemplateArgumentLoc(TemplateArgument(Template),
2000 Input.getTemplateQualifierRange(),
2001 Input.getTemplateNameLoc());
2002 return false;
2003 }
2004
Douglas Gregore922c772009-08-04 22:27:00 +00002005 case TemplateArgument::Expression: {
2006 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002007 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002008 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002009
John McCall0ad16662009-10-29 08:12:44 +00002010 Expr *InputExpr = Input.getSourceExpression();
2011 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2012
2013 Sema::OwningExprResult E
2014 = getDerived().TransformExpr(InputExpr);
2015 if (E.isInvalid()) return true;
2016
2017 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002018 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002019 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2020 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002021 }
Mike Stump11289f42009-09-09 15:08:12 +00002022
Douglas Gregore922c772009-08-04 22:27:00 +00002023 case TemplateArgument::Pack: {
2024 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2025 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002026 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002027 AEnd = Arg.pack_end();
2028 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002029
John McCall0ad16662009-10-29 08:12:44 +00002030 // FIXME: preserve source information here when we start
2031 // caring about parameter packs.
2032
John McCall0d07eb32009-10-29 18:45:58 +00002033 TemplateArgumentLoc InputArg;
2034 TemplateArgumentLoc OutputArg;
2035 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2036 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002037 return true;
2038
John McCall0d07eb32009-10-29 18:45:58 +00002039 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002040 }
2041 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002042 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002043 true);
John McCall0d07eb32009-10-29 18:45:58 +00002044 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002045 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002046 }
2047 }
Mike Stump11289f42009-09-09 15:08:12 +00002048
Douglas Gregore922c772009-08-04 22:27:00 +00002049 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002050 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002051}
2052
Douglas Gregord6ff3322009-08-04 16:50:30 +00002053//===----------------------------------------------------------------------===//
2054// Type transformation
2055//===----------------------------------------------------------------------===//
2056
2057template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002058QualType TreeTransform<Derived>::TransformType(QualType T,
2059 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002060 if (getDerived().AlreadyTransformed(T))
2061 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002062
John McCall550e0c22009-10-21 00:40:46 +00002063 // Temporary workaround. All of these transformations should
2064 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002065 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002066 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002067
Douglas Gregorfe17d252010-02-16 19:09:40 +00002068 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002069
John McCall550e0c22009-10-21 00:40:46 +00002070 if (!NewDI)
2071 return QualType();
2072
2073 return NewDI->getType();
2074}
2075
2076template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002077TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2078 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002079 if (getDerived().AlreadyTransformed(DI->getType()))
2080 return DI;
2081
2082 TypeLocBuilder TLB;
2083
2084 TypeLoc TL = DI->getTypeLoc();
2085 TLB.reserve(TL.getFullDataSize());
2086
Douglas Gregorfe17d252010-02-16 19:09:40 +00002087 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002088 if (Result.isNull())
2089 return 0;
2090
John McCallbcd03502009-12-07 02:54:59 +00002091 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002092}
2093
2094template<typename Derived>
2095QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002096TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2097 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002098 switch (T.getTypeLocClass()) {
2099#define ABSTRACT_TYPELOC(CLASS, PARENT)
2100#define TYPELOC(CLASS, PARENT) \
2101 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002102 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2103 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002104#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002105 }
Mike Stump11289f42009-09-09 15:08:12 +00002106
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002107 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002108 return QualType();
2109}
2110
2111/// FIXME: By default, this routine adds type qualifiers only to types
2112/// that can have qualifiers, and silently suppresses those qualifiers
2113/// that are not permitted (e.g., qualifiers on reference or function
2114/// types). This is the right thing for template instantiation, but
2115/// probably not for other clients.
2116template<typename Derived>
2117QualType
2118TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002119 QualifiedTypeLoc T,
2120 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002121 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002122
Douglas Gregorfe17d252010-02-16 19:09:40 +00002123 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2124 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002125 if (Result.isNull())
2126 return QualType();
2127
2128 // Silently suppress qualifiers if the result type can't be qualified.
2129 // FIXME: this is the right thing for template instantiation, but
2130 // probably not for other clients.
2131 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002132 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002133
John McCall550e0c22009-10-21 00:40:46 +00002134 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2135
2136 TLB.push<QualifiedTypeLoc>(Result);
2137
2138 // No location information to preserve.
2139
2140 return Result;
2141}
2142
2143template <class TyLoc> static inline
2144QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2145 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2146 NewT.setNameLoc(T.getNameLoc());
2147 return T.getType();
2148}
2149
2150// Ugly metaprogramming macros because I couldn't be bothered to make
2151// the equivalent template version work.
2152#define TransformPointerLikeType(TypeClass) do { \
2153 QualType PointeeType \
2154 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2155 if (PointeeType.isNull()) \
2156 return QualType(); \
2157 \
2158 QualType Result = TL.getType(); \
2159 if (getDerived().AlwaysRebuild() || \
2160 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall70dd5f62009-10-30 00:06:24 +00002161 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2162 TL.getSigilLoc()); \
John McCall550e0c22009-10-21 00:40:46 +00002163 if (Result.isNull()) \
2164 return QualType(); \
2165 } \
2166 \
2167 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2168 NewT.setSigilLoc(TL.getSigilLoc()); \
2169 \
2170 return Result; \
2171} while(0)
2172
John McCall550e0c22009-10-21 00:40:46 +00002173template<typename Derived>
2174QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002175 BuiltinTypeLoc T,
2176 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002177 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2178 NewT.setBuiltinLoc(T.getBuiltinLoc());
2179 if (T.needsExtraLocalData())
2180 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2181 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002182}
Mike Stump11289f42009-09-09 15:08:12 +00002183
Douglas Gregord6ff3322009-08-04 16:50:30 +00002184template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002185QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002186 ComplexTypeLoc T,
2187 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002188 // FIXME: recurse?
2189 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002190}
Mike Stump11289f42009-09-09 15:08:12 +00002191
Douglas Gregord6ff3322009-08-04 16:50:30 +00002192template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002193QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002194 PointerTypeLoc TL,
2195 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002196 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002197}
Mike Stump11289f42009-09-09 15:08:12 +00002198
2199template<typename Derived>
2200QualType
John McCall550e0c22009-10-21 00:40:46 +00002201TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002202 BlockPointerTypeLoc TL,
2203 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002204 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002205}
2206
John McCall70dd5f62009-10-30 00:06:24 +00002207/// Transforms a reference type. Note that somewhat paradoxically we
2208/// don't care whether the type itself is an l-value type or an r-value
2209/// type; we only care if the type was *written* as an l-value type
2210/// or an r-value type.
2211template<typename Derived>
2212QualType
2213TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002214 ReferenceTypeLoc TL,
2215 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002216 const ReferenceType *T = TL.getTypePtr();
2217
2218 // Note that this works with the pointee-as-written.
2219 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2220 if (PointeeType.isNull())
2221 return QualType();
2222
2223 QualType Result = TL.getType();
2224 if (getDerived().AlwaysRebuild() ||
2225 PointeeType != T->getPointeeTypeAsWritten()) {
2226 Result = getDerived().RebuildReferenceType(PointeeType,
2227 T->isSpelledAsLValue(),
2228 TL.getSigilLoc());
2229 if (Result.isNull())
2230 return QualType();
2231 }
2232
2233 // r-value references can be rebuilt as l-value references.
2234 ReferenceTypeLoc NewTL;
2235 if (isa<LValueReferenceType>(Result))
2236 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2237 else
2238 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2239 NewTL.setSigilLoc(TL.getSigilLoc());
2240
2241 return Result;
2242}
2243
Mike Stump11289f42009-09-09 15:08:12 +00002244template<typename Derived>
2245QualType
John McCall550e0c22009-10-21 00:40:46 +00002246TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002247 LValueReferenceTypeLoc TL,
2248 QualType ObjectType) {
2249 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002250}
2251
Mike Stump11289f42009-09-09 15:08:12 +00002252template<typename Derived>
2253QualType
John McCall550e0c22009-10-21 00:40:46 +00002254TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002255 RValueReferenceTypeLoc TL,
2256 QualType ObjectType) {
2257 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002258}
Mike Stump11289f42009-09-09 15:08:12 +00002259
Douglas Gregord6ff3322009-08-04 16:50:30 +00002260template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002261QualType
John McCall550e0c22009-10-21 00:40:46 +00002262TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002263 MemberPointerTypeLoc TL,
2264 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002265 MemberPointerType *T = TL.getTypePtr();
2266
2267 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002268 if (PointeeType.isNull())
2269 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002270
John McCall550e0c22009-10-21 00:40:46 +00002271 // TODO: preserve source information for this.
2272 QualType ClassType
2273 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002274 if (ClassType.isNull())
2275 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002276
John McCall550e0c22009-10-21 00:40:46 +00002277 QualType Result = TL.getType();
2278 if (getDerived().AlwaysRebuild() ||
2279 PointeeType != T->getPointeeType() ||
2280 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002281 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2282 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002283 if (Result.isNull())
2284 return QualType();
2285 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002286
John McCall550e0c22009-10-21 00:40:46 +00002287 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2288 NewTL.setSigilLoc(TL.getSigilLoc());
2289
2290 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002291}
2292
Mike Stump11289f42009-09-09 15:08:12 +00002293template<typename Derived>
2294QualType
John McCall550e0c22009-10-21 00:40:46 +00002295TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002296 ConstantArrayTypeLoc TL,
2297 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002298 ConstantArrayType *T = TL.getTypePtr();
2299 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002300 if (ElementType.isNull())
2301 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002302
John McCall550e0c22009-10-21 00:40:46 +00002303 QualType Result = TL.getType();
2304 if (getDerived().AlwaysRebuild() ||
2305 ElementType != T->getElementType()) {
2306 Result = getDerived().RebuildConstantArrayType(ElementType,
2307 T->getSizeModifier(),
2308 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002309 T->getIndexTypeCVRQualifiers(),
2310 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002311 if (Result.isNull())
2312 return QualType();
2313 }
2314
2315 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2316 NewTL.setLBracketLoc(TL.getLBracketLoc());
2317 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002318
John McCall550e0c22009-10-21 00:40:46 +00002319 Expr *Size = TL.getSizeExpr();
2320 if (Size) {
2321 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2322 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2323 }
2324 NewTL.setSizeExpr(Size);
2325
2326 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002327}
Mike Stump11289f42009-09-09 15:08:12 +00002328
Douglas Gregord6ff3322009-08-04 16:50:30 +00002329template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002330QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002331 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002332 IncompleteArrayTypeLoc TL,
2333 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002334 IncompleteArrayType *T = TL.getTypePtr();
2335 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002336 if (ElementType.isNull())
2337 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002338
John McCall550e0c22009-10-21 00:40:46 +00002339 QualType Result = TL.getType();
2340 if (getDerived().AlwaysRebuild() ||
2341 ElementType != T->getElementType()) {
2342 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002343 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002344 T->getIndexTypeCVRQualifiers(),
2345 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002346 if (Result.isNull())
2347 return QualType();
2348 }
2349
2350 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2351 NewTL.setLBracketLoc(TL.getLBracketLoc());
2352 NewTL.setRBracketLoc(TL.getRBracketLoc());
2353 NewTL.setSizeExpr(0);
2354
2355 return Result;
2356}
2357
2358template<typename Derived>
2359QualType
2360TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002361 VariableArrayTypeLoc TL,
2362 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002363 VariableArrayType *T = TL.getTypePtr();
2364 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2365 if (ElementType.isNull())
2366 return QualType();
2367
2368 // Array bounds are not potentially evaluated contexts
2369 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2370
2371 Sema::OwningExprResult SizeResult
2372 = getDerived().TransformExpr(T->getSizeExpr());
2373 if (SizeResult.isInvalid())
2374 return QualType();
2375
2376 Expr *Size = static_cast<Expr*>(SizeResult.get());
2377
2378 QualType Result = TL.getType();
2379 if (getDerived().AlwaysRebuild() ||
2380 ElementType != T->getElementType() ||
2381 Size != T->getSizeExpr()) {
2382 Result = getDerived().RebuildVariableArrayType(ElementType,
2383 T->getSizeModifier(),
2384 move(SizeResult),
2385 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002386 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002387 if (Result.isNull())
2388 return QualType();
2389 }
2390 else SizeResult.take();
2391
2392 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2393 NewTL.setLBracketLoc(TL.getLBracketLoc());
2394 NewTL.setRBracketLoc(TL.getRBracketLoc());
2395 NewTL.setSizeExpr(Size);
2396
2397 return Result;
2398}
2399
2400template<typename Derived>
2401QualType
2402TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002403 DependentSizedArrayTypeLoc TL,
2404 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002405 DependentSizedArrayType *T = TL.getTypePtr();
2406 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2407 if (ElementType.isNull())
2408 return QualType();
2409
2410 // Array bounds are not potentially evaluated contexts
2411 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2412
2413 Sema::OwningExprResult SizeResult
2414 = getDerived().TransformExpr(T->getSizeExpr());
2415 if (SizeResult.isInvalid())
2416 return QualType();
2417
2418 Expr *Size = static_cast<Expr*>(SizeResult.get());
2419
2420 QualType Result = TL.getType();
2421 if (getDerived().AlwaysRebuild() ||
2422 ElementType != T->getElementType() ||
2423 Size != T->getSizeExpr()) {
2424 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2425 T->getSizeModifier(),
2426 move(SizeResult),
2427 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002428 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002429 if (Result.isNull())
2430 return QualType();
2431 }
2432 else SizeResult.take();
2433
2434 // We might have any sort of array type now, but fortunately they
2435 // all have the same location layout.
2436 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2437 NewTL.setLBracketLoc(TL.getLBracketLoc());
2438 NewTL.setRBracketLoc(TL.getRBracketLoc());
2439 NewTL.setSizeExpr(Size);
2440
2441 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002442}
Mike Stump11289f42009-09-09 15:08:12 +00002443
2444template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002445QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002446 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002447 DependentSizedExtVectorTypeLoc TL,
2448 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002449 DependentSizedExtVectorType *T = TL.getTypePtr();
2450
2451 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002452 QualType ElementType = getDerived().TransformType(T->getElementType());
2453 if (ElementType.isNull())
2454 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002455
Douglas Gregore922c772009-08-04 22:27:00 +00002456 // Vector sizes are not potentially evaluated contexts
2457 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2458
Douglas Gregord6ff3322009-08-04 16:50:30 +00002459 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2460 if (Size.isInvalid())
2461 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002462
John McCall550e0c22009-10-21 00:40:46 +00002463 QualType Result = TL.getType();
2464 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002465 ElementType != T->getElementType() ||
2466 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002467 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002468 move(Size),
2469 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002470 if (Result.isNull())
2471 return QualType();
2472 }
2473 else Size.take();
2474
2475 // Result might be dependent or not.
2476 if (isa<DependentSizedExtVectorType>(Result)) {
2477 DependentSizedExtVectorTypeLoc NewTL
2478 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2479 NewTL.setNameLoc(TL.getNameLoc());
2480 } else {
2481 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2482 NewTL.setNameLoc(TL.getNameLoc());
2483 }
2484
2485 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002486}
Mike Stump11289f42009-09-09 15:08:12 +00002487
2488template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002489QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002490 VectorTypeLoc TL,
2491 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002492 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002493 QualType ElementType = getDerived().TransformType(T->getElementType());
2494 if (ElementType.isNull())
2495 return QualType();
2496
John McCall550e0c22009-10-21 00:40:46 +00002497 QualType Result = TL.getType();
2498 if (getDerived().AlwaysRebuild() ||
2499 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002500 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2501 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002502 if (Result.isNull())
2503 return QualType();
2504 }
2505
2506 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2507 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002508
John McCall550e0c22009-10-21 00:40:46 +00002509 return Result;
2510}
2511
2512template<typename Derived>
2513QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002514 ExtVectorTypeLoc TL,
2515 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002516 VectorType *T = TL.getTypePtr();
2517 QualType ElementType = getDerived().TransformType(T->getElementType());
2518 if (ElementType.isNull())
2519 return QualType();
2520
2521 QualType Result = TL.getType();
2522 if (getDerived().AlwaysRebuild() ||
2523 ElementType != T->getElementType()) {
2524 Result = getDerived().RebuildExtVectorType(ElementType,
2525 T->getNumElements(),
2526 /*FIXME*/ SourceLocation());
2527 if (Result.isNull())
2528 return QualType();
2529 }
2530
2531 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2532 NewTL.setNameLoc(TL.getNameLoc());
2533
2534 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002535}
Mike Stump11289f42009-09-09 15:08:12 +00002536
2537template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002538ParmVarDecl *
2539TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2540 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2541 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2542 if (!NewDI)
2543 return 0;
2544
2545 if (NewDI == OldDI)
2546 return OldParm;
2547 else
2548 return ParmVarDecl::Create(SemaRef.Context,
2549 OldParm->getDeclContext(),
2550 OldParm->getLocation(),
2551 OldParm->getIdentifier(),
2552 NewDI->getType(),
2553 NewDI,
2554 OldParm->getStorageClass(),
2555 /* DefArg */ NULL);
2556}
2557
2558template<typename Derived>
2559bool TreeTransform<Derived>::
2560 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2561 llvm::SmallVectorImpl<QualType> &PTypes,
2562 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2563 FunctionProtoType *T = TL.getTypePtr();
2564
2565 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2566 ParmVarDecl *OldParm = TL.getArg(i);
2567
2568 QualType NewType;
2569 ParmVarDecl *NewParm;
2570
2571 if (OldParm) {
2572 assert(OldParm->getTypeSourceInfo()->getType() == T->getArgType(i));
2573
2574 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2575 if (!NewParm)
2576 return true;
2577 NewType = NewParm->getType();
2578
2579 // Deal with the possibility that we don't have a parameter
2580 // declaration for this parameter.
2581 } else {
2582 NewParm = 0;
2583
2584 QualType OldType = T->getArgType(i);
2585 NewType = getDerived().TransformType(OldType);
2586 if (NewType.isNull())
2587 return true;
2588 }
2589
2590 PTypes.push_back(NewType);
2591 PVars.push_back(NewParm);
2592 }
2593
2594 return false;
2595}
2596
2597template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002598QualType
John McCall550e0c22009-10-21 00:40:46 +00002599TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002600 FunctionProtoTypeLoc TL,
2601 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002602 FunctionProtoType *T = TL.getTypePtr();
2603 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002604 if (ResultType.isNull())
2605 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002606
John McCall550e0c22009-10-21 00:40:46 +00002607 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002608 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002609 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002610 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2611 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002612
John McCall550e0c22009-10-21 00:40:46 +00002613 QualType Result = TL.getType();
2614 if (getDerived().AlwaysRebuild() ||
2615 ResultType != T->getResultType() ||
2616 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2617 Result = getDerived().RebuildFunctionProtoType(ResultType,
2618 ParamTypes.data(),
2619 ParamTypes.size(),
2620 T->isVariadic(),
2621 T->getTypeQuals());
2622 if (Result.isNull())
2623 return QualType();
2624 }
Mike Stump11289f42009-09-09 15:08:12 +00002625
John McCall550e0c22009-10-21 00:40:46 +00002626 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2627 NewTL.setLParenLoc(TL.getLParenLoc());
2628 NewTL.setRParenLoc(TL.getRParenLoc());
2629 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2630 NewTL.setArg(i, ParamDecls[i]);
2631
2632 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002633}
Mike Stump11289f42009-09-09 15:08:12 +00002634
Douglas Gregord6ff3322009-08-04 16:50:30 +00002635template<typename Derived>
2636QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002637 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002638 FunctionNoProtoTypeLoc TL,
2639 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002640 FunctionNoProtoType *T = TL.getTypePtr();
2641 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2642 if (ResultType.isNull())
2643 return QualType();
2644
2645 QualType Result = TL.getType();
2646 if (getDerived().AlwaysRebuild() ||
2647 ResultType != T->getResultType())
2648 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2649
2650 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2651 NewTL.setLParenLoc(TL.getLParenLoc());
2652 NewTL.setRParenLoc(TL.getRParenLoc());
2653
2654 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002655}
Mike Stump11289f42009-09-09 15:08:12 +00002656
John McCallb96ec562009-12-04 22:46:56 +00002657template<typename Derived> QualType
2658TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002659 UnresolvedUsingTypeLoc TL,
2660 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002661 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002662 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002663 if (!D)
2664 return QualType();
2665
2666 QualType Result = TL.getType();
2667 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2668 Result = getDerived().RebuildUnresolvedUsingType(D);
2669 if (Result.isNull())
2670 return QualType();
2671 }
2672
2673 // We might get an arbitrary type spec type back. We should at
2674 // least always get a type spec type, though.
2675 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2676 NewTL.setNameLoc(TL.getNameLoc());
2677
2678 return Result;
2679}
2680
Douglas Gregord6ff3322009-08-04 16:50:30 +00002681template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002682QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002683 TypedefTypeLoc TL,
2684 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002685 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002686 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002687 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2688 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002689 if (!Typedef)
2690 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002691
John McCall550e0c22009-10-21 00:40:46 +00002692 QualType Result = TL.getType();
2693 if (getDerived().AlwaysRebuild() ||
2694 Typedef != T->getDecl()) {
2695 Result = getDerived().RebuildTypedefType(Typedef);
2696 if (Result.isNull())
2697 return QualType();
2698 }
Mike Stump11289f42009-09-09 15:08:12 +00002699
John McCall550e0c22009-10-21 00:40:46 +00002700 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2701 NewTL.setNameLoc(TL.getNameLoc());
2702
2703 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002704}
Mike Stump11289f42009-09-09 15:08:12 +00002705
Douglas Gregord6ff3322009-08-04 16:50:30 +00002706template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002707QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002708 TypeOfExprTypeLoc TL,
2709 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00002710 // typeof expressions are not potentially evaluated contexts
2711 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002712
John McCalle8595032010-01-13 20:03:27 +00002713 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002714 if (E.isInvalid())
2715 return QualType();
2716
John McCall550e0c22009-10-21 00:40:46 +00002717 QualType Result = TL.getType();
2718 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00002719 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002720 Result = getDerived().RebuildTypeOfExprType(move(E));
2721 if (Result.isNull())
2722 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002723 }
John McCall550e0c22009-10-21 00:40:46 +00002724 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002725
John McCall550e0c22009-10-21 00:40:46 +00002726 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002727 NewTL.setTypeofLoc(TL.getTypeofLoc());
2728 NewTL.setLParenLoc(TL.getLParenLoc());
2729 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00002730
2731 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002732}
Mike Stump11289f42009-09-09 15:08:12 +00002733
2734template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002735QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002736 TypeOfTypeLoc TL,
2737 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00002738 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2739 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2740 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00002741 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002742
John McCall550e0c22009-10-21 00:40:46 +00002743 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00002744 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2745 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00002746 if (Result.isNull())
2747 return QualType();
2748 }
Mike Stump11289f42009-09-09 15:08:12 +00002749
John McCall550e0c22009-10-21 00:40:46 +00002750 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002751 NewTL.setTypeofLoc(TL.getTypeofLoc());
2752 NewTL.setLParenLoc(TL.getLParenLoc());
2753 NewTL.setRParenLoc(TL.getRParenLoc());
2754 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00002755
2756 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002757}
Mike Stump11289f42009-09-09 15:08:12 +00002758
2759template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002760QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002761 DecltypeTypeLoc TL,
2762 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002763 DecltypeType *T = TL.getTypePtr();
2764
Douglas Gregore922c772009-08-04 22:27:00 +00002765 // decltype expressions are not potentially evaluated contexts
2766 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002767
Douglas Gregord6ff3322009-08-04 16:50:30 +00002768 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2769 if (E.isInvalid())
2770 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002771
John McCall550e0c22009-10-21 00:40:46 +00002772 QualType Result = TL.getType();
2773 if (getDerived().AlwaysRebuild() ||
2774 E.get() != T->getUnderlyingExpr()) {
2775 Result = getDerived().RebuildDecltypeType(move(E));
2776 if (Result.isNull())
2777 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002778 }
John McCall550e0c22009-10-21 00:40:46 +00002779 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002780
John McCall550e0c22009-10-21 00:40:46 +00002781 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2782 NewTL.setNameLoc(TL.getNameLoc());
2783
2784 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002785}
2786
2787template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002788QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002789 RecordTypeLoc TL,
2790 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002791 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002792 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002793 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2794 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002795 if (!Record)
2796 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002797
John McCall550e0c22009-10-21 00:40:46 +00002798 QualType Result = TL.getType();
2799 if (getDerived().AlwaysRebuild() ||
2800 Record != T->getDecl()) {
2801 Result = getDerived().RebuildRecordType(Record);
2802 if (Result.isNull())
2803 return QualType();
2804 }
Mike Stump11289f42009-09-09 15:08:12 +00002805
John McCall550e0c22009-10-21 00:40:46 +00002806 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2807 NewTL.setNameLoc(TL.getNameLoc());
2808
2809 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002810}
Mike Stump11289f42009-09-09 15:08:12 +00002811
2812template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002813QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002814 EnumTypeLoc TL,
2815 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002816 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002817 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002818 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2819 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002820 if (!Enum)
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 Enum != T->getDecl()) {
2826 Result = getDerived().RebuildEnumType(Enum);
2827 if (Result.isNull())
2828 return QualType();
2829 }
Mike Stump11289f42009-09-09 15:08:12 +00002830
John McCall550e0c22009-10-21 00:40:46 +00002831 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2832 NewTL.setNameLoc(TL.getNameLoc());
2833
2834 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002835}
John McCallfcc33b02009-09-05 00:15:47 +00002836
2837template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002838QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002839 ElaboratedTypeLoc TL,
2840 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002841 ElaboratedType *T = TL.getTypePtr();
2842
2843 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002844 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2845 if (Underlying.isNull())
2846 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002847
John McCall550e0c22009-10-21 00:40:46 +00002848 QualType Result = TL.getType();
2849 if (getDerived().AlwaysRebuild() ||
2850 Underlying != T->getUnderlyingType()) {
2851 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2852 if (Result.isNull())
2853 return QualType();
2854 }
Mike Stump11289f42009-09-09 15:08:12 +00002855
John McCall550e0c22009-10-21 00:40:46 +00002856 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2857 NewTL.setNameLoc(TL.getNameLoc());
2858
2859 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002860}
Mike Stump11289f42009-09-09 15:08:12 +00002861
John McCalle78aac42010-03-10 03:28:59 +00002862template<typename Derived>
2863QualType TreeTransform<Derived>::TransformInjectedClassNameType(
2864 TypeLocBuilder &TLB,
2865 InjectedClassNameTypeLoc TL,
2866 QualType ObjectType) {
2867 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
2868 TL.getTypePtr()->getDecl());
2869 if (!D) return QualType();
2870
2871 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
2872 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
2873 return T;
2874}
2875
Mike Stump11289f42009-09-09 15:08:12 +00002876
Douglas Gregord6ff3322009-08-04 16:50:30 +00002877template<typename Derived>
2878QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002879 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002880 TemplateTypeParmTypeLoc TL,
2881 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002882 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002883}
2884
Mike Stump11289f42009-09-09 15:08:12 +00002885template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002886QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002887 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002888 SubstTemplateTypeParmTypeLoc TL,
2889 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002890 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002891}
2892
2893template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002894QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2895 const TemplateSpecializationType *TST,
2896 QualType ObjectType) {
2897 // FIXME: this entire method is a temporary workaround; callers
2898 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00002899
John McCall0ad16662009-10-29 08:12:44 +00002900 // Fake up a TemplateSpecializationTypeLoc.
2901 TypeLocBuilder TLB;
2902 TemplateSpecializationTypeLoc TL
2903 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2904
John McCall0d07eb32009-10-29 18:45:58 +00002905 SourceLocation BaseLoc = getDerived().getBaseLocation();
2906
2907 TL.setTemplateNameLoc(BaseLoc);
2908 TL.setLAngleLoc(BaseLoc);
2909 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00002910 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2911 const TemplateArgument &TA = TST->getArg(i);
2912 TemplateArgumentLoc TAL;
2913 getDerived().InventTemplateArgumentLoc(TA, TAL);
2914 TL.setArgLocInfo(i, TAL.getLocInfo());
2915 }
2916
2917 TypeLocBuilder IgnoredTLB;
2918 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00002919}
2920
2921template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002922QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00002923 TypeLocBuilder &TLB,
2924 TemplateSpecializationTypeLoc TL,
2925 QualType ObjectType) {
2926 const TemplateSpecializationType *T = TL.getTypePtr();
2927
Mike Stump11289f42009-09-09 15:08:12 +00002928 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002929 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002930 if (Template.isNull())
2931 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002932
John McCall6b51f282009-11-23 01:53:49 +00002933 TemplateArgumentListInfo NewTemplateArgs;
2934 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2935 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2936
2937 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2938 TemplateArgumentLoc Loc;
2939 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00002940 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00002941 NewTemplateArgs.addArgument(Loc);
2942 }
Mike Stump11289f42009-09-09 15:08:12 +00002943
John McCall0ad16662009-10-29 08:12:44 +00002944 // FIXME: maybe don't rebuild if all the template arguments are the same.
2945
2946 QualType Result =
2947 getDerived().RebuildTemplateSpecializationType(Template,
2948 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00002949 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00002950
2951 if (!Result.isNull()) {
2952 TemplateSpecializationTypeLoc NewTL
2953 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2954 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2955 NewTL.setLAngleLoc(TL.getLAngleLoc());
2956 NewTL.setRAngleLoc(TL.getRAngleLoc());
2957 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2958 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002959 }
Mike Stump11289f42009-09-09 15:08:12 +00002960
John McCall0ad16662009-10-29 08:12:44 +00002961 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002962}
Mike Stump11289f42009-09-09 15:08:12 +00002963
2964template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002965QualType
2966TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002967 QualifiedNameTypeLoc TL,
2968 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002969 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002970 NestedNameSpecifier *NNS
2971 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002972 SourceRange(),
2973 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002974 if (!NNS)
2975 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002976
Douglas Gregord6ff3322009-08-04 16:50:30 +00002977 QualType Named = getDerived().TransformType(T->getNamedType());
2978 if (Named.isNull())
2979 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002980
John McCall550e0c22009-10-21 00:40:46 +00002981 QualType Result = TL.getType();
2982 if (getDerived().AlwaysRebuild() ||
2983 NNS != T->getQualifier() ||
2984 Named != T->getNamedType()) {
2985 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2986 if (Result.isNull())
2987 return QualType();
2988 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002989
John McCall550e0c22009-10-21 00:40:46 +00002990 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2991 NewTL.setNameLoc(TL.getNameLoc());
2992
2993 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002994}
Mike Stump11289f42009-09-09 15:08:12 +00002995
2996template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002997QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002998 TypenameTypeLoc TL,
2999 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003000 TypenameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003001
3002 /* FIXME: preserve source information better than this */
3003 SourceRange SR(TL.getNameLoc());
3004
Douglas Gregord6ff3322009-08-04 16:50:30 +00003005 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00003006 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003007 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003008 if (!NNS)
3009 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003010
John McCall550e0c22009-10-21 00:40:46 +00003011 QualType Result;
3012
Douglas Gregord6ff3322009-08-04 16:50:30 +00003013 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00003014 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00003015 = getDerived().TransformType(QualType(TemplateId, 0));
3016 if (NewTemplateId.isNull())
3017 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003018
Douglas Gregord6ff3322009-08-04 16:50:30 +00003019 if (!getDerived().AlwaysRebuild() &&
3020 NNS == T->getQualifier() &&
3021 NewTemplateId == QualType(TemplateId, 0))
3022 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00003023
John McCall550e0c22009-10-21 00:40:46 +00003024 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
3025 } else {
John McCall0ad16662009-10-29 08:12:44 +00003026 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003027 }
John McCall550e0c22009-10-21 00:40:46 +00003028 if (Result.isNull())
3029 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003030
John McCall550e0c22009-10-21 00:40:46 +00003031 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
3032 NewTL.setNameLoc(TL.getNameLoc());
3033
3034 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003035}
Mike Stump11289f42009-09-09 15:08:12 +00003036
Douglas Gregord6ff3322009-08-04 16:50:30 +00003037template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003038QualType
3039TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003040 ObjCInterfaceTypeLoc TL,
3041 QualType ObjectType) {
John McCallfc93cf92009-10-22 22:37:11 +00003042 assert(false && "TransformObjCInterfaceType unimplemented");
3043 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003044}
Mike Stump11289f42009-09-09 15:08:12 +00003045
3046template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003047QualType
3048TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003049 ObjCObjectPointerTypeLoc TL,
3050 QualType ObjectType) {
John McCallfc93cf92009-10-22 22:37:11 +00003051 assert(false && "TransformObjCObjectPointerType unimplemented");
3052 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003053}
3054
Douglas Gregord6ff3322009-08-04 16:50:30 +00003055//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003056// Statement transformation
3057//===----------------------------------------------------------------------===//
3058template<typename Derived>
3059Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003060TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3061 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003062}
3063
3064template<typename Derived>
3065Sema::OwningStmtResult
3066TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3067 return getDerived().TransformCompoundStmt(S, false);
3068}
3069
3070template<typename Derived>
3071Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003072TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003073 bool IsStmtExpr) {
3074 bool SubStmtChanged = false;
3075 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3076 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3077 B != BEnd; ++B) {
3078 OwningStmtResult Result = getDerived().TransformStmt(*B);
3079 if (Result.isInvalid())
3080 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003081
Douglas Gregorebe10102009-08-20 07:17:43 +00003082 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3083 Statements.push_back(Result.takeAs<Stmt>());
3084 }
Mike Stump11289f42009-09-09 15:08:12 +00003085
Douglas Gregorebe10102009-08-20 07:17:43 +00003086 if (!getDerived().AlwaysRebuild() &&
3087 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003088 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003089
3090 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3091 move_arg(Statements),
3092 S->getRBracLoc(),
3093 IsStmtExpr);
3094}
Mike Stump11289f42009-09-09 15:08:12 +00003095
Douglas Gregorebe10102009-08-20 07:17:43 +00003096template<typename Derived>
3097Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003098TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003099 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3100 {
3101 // The case value expressions are not potentially evaluated.
3102 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003103
Eli Friedman06577382009-11-19 03:14:00 +00003104 // Transform the left-hand case value.
3105 LHS = getDerived().TransformExpr(S->getLHS());
3106 if (LHS.isInvalid())
3107 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003108
Eli Friedman06577382009-11-19 03:14:00 +00003109 // Transform the right-hand case value (for the GNU case-range extension).
3110 RHS = getDerived().TransformExpr(S->getRHS());
3111 if (RHS.isInvalid())
3112 return SemaRef.StmtError();
3113 }
Mike Stump11289f42009-09-09 15:08:12 +00003114
Douglas Gregorebe10102009-08-20 07:17:43 +00003115 // Build the case statement.
3116 // Case statements are always rebuilt so that they will attached to their
3117 // transformed switch statement.
3118 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3119 move(LHS),
3120 S->getEllipsisLoc(),
3121 move(RHS),
3122 S->getColonLoc());
3123 if (Case.isInvalid())
3124 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003125
Douglas Gregorebe10102009-08-20 07:17:43 +00003126 // Transform the statement following the case
3127 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3128 if (SubStmt.isInvalid())
3129 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003130
Douglas Gregorebe10102009-08-20 07:17:43 +00003131 // Attach the body to the case statement
3132 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3133}
3134
3135template<typename Derived>
3136Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003137TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003138 // Transform the statement following the default case
3139 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3140 if (SubStmt.isInvalid())
3141 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003142
Douglas Gregorebe10102009-08-20 07:17:43 +00003143 // Default statements are always rebuilt
3144 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3145 move(SubStmt));
3146}
Mike Stump11289f42009-09-09 15:08:12 +00003147
Douglas Gregorebe10102009-08-20 07:17:43 +00003148template<typename Derived>
3149Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003150TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003151 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3152 if (SubStmt.isInvalid())
3153 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003154
Douglas Gregorebe10102009-08-20 07:17:43 +00003155 // FIXME: Pass the real colon location in.
3156 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3157 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3158 move(SubStmt));
3159}
Mike Stump11289f42009-09-09 15:08:12 +00003160
Douglas Gregorebe10102009-08-20 07:17:43 +00003161template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003162Sema::OwningStmtResult
3163TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003164 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003165 OwningExprResult Cond(SemaRef);
3166 VarDecl *ConditionVar = 0;
3167 if (S->getConditionVariable()) {
3168 ConditionVar
3169 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003170 getDerived().TransformDefinition(
3171 S->getConditionVariable()->getLocation(),
3172 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003173 if (!ConditionVar)
3174 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003175 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003176 Cond = getDerived().TransformExpr(S->getCond());
3177
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003178 if (Cond.isInvalid())
3179 return SemaRef.StmtError();
3180 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003181
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003182 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003183
Douglas Gregorebe10102009-08-20 07:17:43 +00003184 // Transform the "then" branch.
3185 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3186 if (Then.isInvalid())
3187 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003188
Douglas Gregorebe10102009-08-20 07:17:43 +00003189 // Transform the "else" branch.
3190 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3191 if (Else.isInvalid())
3192 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003193
Douglas Gregorebe10102009-08-20 07:17:43 +00003194 if (!getDerived().AlwaysRebuild() &&
3195 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003196 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003197 Then.get() == S->getThen() &&
3198 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003199 return SemaRef.Owned(S->Retain());
3200
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003201 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3202 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003203 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003204}
3205
3206template<typename Derived>
3207Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003208TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003209 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003210 OwningExprResult Cond(SemaRef);
3211 VarDecl *ConditionVar = 0;
3212 if (S->getConditionVariable()) {
3213 ConditionVar
3214 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003215 getDerived().TransformDefinition(
3216 S->getConditionVariable()->getLocation(),
3217 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003218 if (!ConditionVar)
3219 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003220 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003221 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003222
3223 if (Cond.isInvalid())
3224 return SemaRef.StmtError();
3225 }
Mike Stump11289f42009-09-09 15:08:12 +00003226
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003227 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003228
Douglas Gregorebe10102009-08-20 07:17:43 +00003229 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003230 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3231 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003232 if (Switch.isInvalid())
3233 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003234
Douglas Gregorebe10102009-08-20 07:17:43 +00003235 // Transform the body of the switch statement.
3236 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3237 if (Body.isInvalid())
3238 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003239
Douglas Gregorebe10102009-08-20 07:17:43 +00003240 // Complete the switch statement.
3241 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3242 move(Body));
3243}
Mike Stump11289f42009-09-09 15:08:12 +00003244
Douglas Gregorebe10102009-08-20 07:17:43 +00003245template<typename Derived>
3246Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003247TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003248 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003249 OwningExprResult Cond(SemaRef);
3250 VarDecl *ConditionVar = 0;
3251 if (S->getConditionVariable()) {
3252 ConditionVar
3253 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003254 getDerived().TransformDefinition(
3255 S->getConditionVariable()->getLocation(),
3256 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003257 if (!ConditionVar)
3258 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003259 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003260 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003261
3262 if (Cond.isInvalid())
3263 return SemaRef.StmtError();
3264 }
Mike Stump11289f42009-09-09 15:08:12 +00003265
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003266 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003267
Douglas Gregorebe10102009-08-20 07:17:43 +00003268 // Transform the body
3269 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3270 if (Body.isInvalid())
3271 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003272
Douglas Gregorebe10102009-08-20 07:17:43 +00003273 if (!getDerived().AlwaysRebuild() &&
3274 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003275 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003276 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003277 return SemaRef.Owned(S->Retain());
3278
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003279 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3280 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003281}
Mike Stump11289f42009-09-09 15:08:12 +00003282
Douglas Gregorebe10102009-08-20 07:17:43 +00003283template<typename Derived>
3284Sema::OwningStmtResult
3285TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3286 // Transform the condition
3287 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3288 if (Cond.isInvalid())
3289 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003290
Douglas Gregorebe10102009-08-20 07:17:43 +00003291 // Transform the body
3292 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3293 if (Body.isInvalid())
3294 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003295
Douglas Gregorebe10102009-08-20 07:17:43 +00003296 if (!getDerived().AlwaysRebuild() &&
3297 Cond.get() == S->getCond() &&
3298 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003299 return SemaRef.Owned(S->Retain());
3300
Douglas Gregorebe10102009-08-20 07:17:43 +00003301 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3302 /*FIXME:*/S->getWhileLoc(), move(Cond),
3303 S->getRParenLoc());
3304}
Mike Stump11289f42009-09-09 15:08:12 +00003305
Douglas Gregorebe10102009-08-20 07:17:43 +00003306template<typename Derived>
3307Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003308TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003309 // Transform the initialization statement
3310 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3311 if (Init.isInvalid())
3312 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003313
Douglas Gregorebe10102009-08-20 07:17:43 +00003314 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003315 OwningExprResult Cond(SemaRef);
3316 VarDecl *ConditionVar = 0;
3317 if (S->getConditionVariable()) {
3318 ConditionVar
3319 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003320 getDerived().TransformDefinition(
3321 S->getConditionVariable()->getLocation(),
3322 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003323 if (!ConditionVar)
3324 return SemaRef.StmtError();
3325 } else {
3326 Cond = getDerived().TransformExpr(S->getCond());
3327
3328 if (Cond.isInvalid())
3329 return SemaRef.StmtError();
3330 }
Mike Stump11289f42009-09-09 15:08:12 +00003331
Douglas Gregorebe10102009-08-20 07:17:43 +00003332 // Transform the increment
3333 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3334 if (Inc.isInvalid())
3335 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003336
Douglas Gregorebe10102009-08-20 07:17:43 +00003337 // Transform the body
3338 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3339 if (Body.isInvalid())
3340 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003341
Douglas Gregorebe10102009-08-20 07:17:43 +00003342 if (!getDerived().AlwaysRebuild() &&
3343 Init.get() == S->getInit() &&
3344 Cond.get() == S->getCond() &&
3345 Inc.get() == S->getInc() &&
3346 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003347 return SemaRef.Owned(S->Retain());
3348
Douglas Gregorebe10102009-08-20 07:17:43 +00003349 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003350 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003351 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003352 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003353 S->getRParenLoc(), move(Body));
3354}
3355
3356template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003357Sema::OwningStmtResult
3358TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003359 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003360 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003361 S->getLabel());
3362}
3363
3364template<typename Derived>
3365Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003366TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003367 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3368 if (Target.isInvalid())
3369 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003370
Douglas Gregorebe10102009-08-20 07:17:43 +00003371 if (!getDerived().AlwaysRebuild() &&
3372 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003373 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003374
3375 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3376 move(Target));
3377}
3378
3379template<typename Derived>
3380Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003381TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3382 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003383}
Mike Stump11289f42009-09-09 15:08:12 +00003384
Douglas Gregorebe10102009-08-20 07:17:43 +00003385template<typename Derived>
3386Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003387TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3388 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003389}
Mike Stump11289f42009-09-09 15:08:12 +00003390
Douglas Gregorebe10102009-08-20 07:17:43 +00003391template<typename Derived>
3392Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003393TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003394 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3395 if (Result.isInvalid())
3396 return SemaRef.StmtError();
3397
Mike Stump11289f42009-09-09 15:08:12 +00003398 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003399 // to tell whether the return type of the function has changed.
3400 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3401}
Mike Stump11289f42009-09-09 15:08:12 +00003402
Douglas Gregorebe10102009-08-20 07:17:43 +00003403template<typename Derived>
3404Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003405TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003406 bool DeclChanged = false;
3407 llvm::SmallVector<Decl *, 4> Decls;
3408 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3409 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003410 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3411 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003412 if (!Transformed)
3413 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003414
Douglas Gregorebe10102009-08-20 07:17:43 +00003415 if (Transformed != *D)
3416 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003417
Douglas Gregorebe10102009-08-20 07:17:43 +00003418 Decls.push_back(Transformed);
3419 }
Mike Stump11289f42009-09-09 15:08:12 +00003420
Douglas Gregorebe10102009-08-20 07:17:43 +00003421 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003422 return SemaRef.Owned(S->Retain());
3423
3424 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003425 S->getStartLoc(), S->getEndLoc());
3426}
Mike Stump11289f42009-09-09 15:08:12 +00003427
Douglas Gregorebe10102009-08-20 07:17:43 +00003428template<typename Derived>
3429Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003430TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003431 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003432 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003433}
3434
3435template<typename Derived>
3436Sema::OwningStmtResult
3437TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003438
3439 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3440 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003441 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003442
Anders Carlssonaaeef072010-01-24 05:50:09 +00003443 OwningExprResult AsmString(SemaRef);
3444 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3445
3446 bool ExprsChanged = false;
3447
3448 // Go through the outputs.
3449 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003450 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003451
Anders Carlssonaaeef072010-01-24 05:50:09 +00003452 // No need to transform the constraint literal.
3453 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3454
3455 // Transform the output expr.
3456 Expr *OutputExpr = S->getOutputExpr(I);
3457 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3458 if (Result.isInvalid())
3459 return SemaRef.StmtError();
3460
3461 ExprsChanged |= Result.get() != OutputExpr;
3462
3463 Exprs.push_back(Result.takeAs<Expr>());
3464 }
3465
3466 // Go through the inputs.
3467 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003468 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003469
Anders Carlssonaaeef072010-01-24 05:50:09 +00003470 // No need to transform the constraint literal.
3471 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3472
3473 // Transform the input expr.
3474 Expr *InputExpr = S->getInputExpr(I);
3475 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3476 if (Result.isInvalid())
3477 return SemaRef.StmtError();
3478
3479 ExprsChanged |= Result.get() != InputExpr;
3480
3481 Exprs.push_back(Result.takeAs<Expr>());
3482 }
3483
3484 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3485 return SemaRef.Owned(S->Retain());
3486
3487 // Go through the clobbers.
3488 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3489 Clobbers.push_back(S->getClobber(I)->Retain());
3490
3491 // No need to transform the asm string literal.
3492 AsmString = SemaRef.Owned(S->getAsmString());
3493
3494 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3495 S->isSimple(),
3496 S->isVolatile(),
3497 S->getNumOutputs(),
3498 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003499 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003500 move_arg(Constraints),
3501 move_arg(Exprs),
3502 move(AsmString),
3503 move_arg(Clobbers),
3504 S->getRParenLoc(),
3505 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003506}
3507
3508
3509template<typename Derived>
3510Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003511TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003512 // FIXME: Implement this
3513 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003514 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003515}
Mike Stump11289f42009-09-09 15:08:12 +00003516
Douglas Gregorebe10102009-08-20 07:17:43 +00003517template<typename Derived>
3518Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003519TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003520 // FIXME: Implement this
3521 assert(false && "Cannot transform an Objective-C @catch statement");
3522 return SemaRef.Owned(S->Retain());
3523}
Mike Stump11289f42009-09-09 15:08:12 +00003524
Douglas Gregorebe10102009-08-20 07:17:43 +00003525template<typename Derived>
3526Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003527TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003528 // FIXME: Implement this
3529 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003530 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003531}
Mike Stump11289f42009-09-09 15:08:12 +00003532
Douglas Gregorebe10102009-08-20 07:17:43 +00003533template<typename Derived>
3534Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003535TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003536 // FIXME: Implement this
3537 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003538 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003539}
Mike Stump11289f42009-09-09 15:08:12 +00003540
Douglas Gregorebe10102009-08-20 07:17:43 +00003541template<typename Derived>
3542Sema::OwningStmtResult
3543TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003544 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003545 // FIXME: Implement this
3546 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003547 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003548}
3549
3550template<typename Derived>
3551Sema::OwningStmtResult
3552TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003553 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003554 // FIXME: Implement this
3555 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003556 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003557}
3558
3559
3560template<typename Derived>
3561Sema::OwningStmtResult
3562TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3563 // Transform the exception declaration, if any.
3564 VarDecl *Var = 0;
3565 if (S->getExceptionDecl()) {
3566 VarDecl *ExceptionDecl = S->getExceptionDecl();
3567 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3568 ExceptionDecl->getDeclName());
3569
3570 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3571 if (T.isNull())
3572 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003573
Douglas Gregorebe10102009-08-20 07:17:43 +00003574 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3575 T,
John McCallbcd03502009-12-07 02:54:59 +00003576 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003577 ExceptionDecl->getIdentifier(),
3578 ExceptionDecl->getLocation(),
3579 /*FIXME: Inaccurate*/
3580 SourceRange(ExceptionDecl->getLocation()));
3581 if (!Var || Var->isInvalidDecl()) {
3582 if (Var)
3583 Var->Destroy(SemaRef.Context);
3584 return SemaRef.StmtError();
3585 }
3586 }
Mike Stump11289f42009-09-09 15:08:12 +00003587
Douglas Gregorebe10102009-08-20 07:17:43 +00003588 // Transform the actual exception handler.
3589 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3590 if (Handler.isInvalid()) {
3591 if (Var)
3592 Var->Destroy(SemaRef.Context);
3593 return SemaRef.StmtError();
3594 }
Mike Stump11289f42009-09-09 15:08:12 +00003595
Douglas Gregorebe10102009-08-20 07:17:43 +00003596 if (!getDerived().AlwaysRebuild() &&
3597 !Var &&
3598 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003599 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003600
3601 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3602 Var,
3603 move(Handler));
3604}
Mike Stump11289f42009-09-09 15:08:12 +00003605
Douglas Gregorebe10102009-08-20 07:17:43 +00003606template<typename Derived>
3607Sema::OwningStmtResult
3608TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3609 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003610 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003611 = getDerived().TransformCompoundStmt(S->getTryBlock());
3612 if (TryBlock.isInvalid())
3613 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003614
Douglas Gregorebe10102009-08-20 07:17:43 +00003615 // Transform the handlers.
3616 bool HandlerChanged = false;
3617 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3618 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003619 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003620 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3621 if (Handler.isInvalid())
3622 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003623
Douglas Gregorebe10102009-08-20 07:17:43 +00003624 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3625 Handlers.push_back(Handler.takeAs<Stmt>());
3626 }
Mike Stump11289f42009-09-09 15:08:12 +00003627
Douglas Gregorebe10102009-08-20 07:17:43 +00003628 if (!getDerived().AlwaysRebuild() &&
3629 TryBlock.get() == S->getTryBlock() &&
3630 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003631 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003632
3633 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003634 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003635}
Mike Stump11289f42009-09-09 15:08:12 +00003636
Douglas Gregorebe10102009-08-20 07:17:43 +00003637//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003638// Expression transformation
3639//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003640template<typename Derived>
3641Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003642TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003643 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003644}
Mike Stump11289f42009-09-09 15:08:12 +00003645
3646template<typename Derived>
3647Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003648TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003649 NestedNameSpecifier *Qualifier = 0;
3650 if (E->getQualifier()) {
3651 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003652 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003653 if (!Qualifier)
3654 return SemaRef.ExprError();
3655 }
John McCallce546572009-12-08 09:08:17 +00003656
3657 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003658 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
3659 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003660 if (!ND)
3661 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003662
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003663 if (!getDerived().AlwaysRebuild() &&
3664 Qualifier == E->getQualifier() &&
3665 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003666 !E->hasExplicitTemplateArgumentList()) {
3667
3668 // Mark it referenced in the new context regardless.
3669 // FIXME: this is a bit instantiation-specific.
3670 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3671
Mike Stump11289f42009-09-09 15:08:12 +00003672 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003673 }
John McCallce546572009-12-08 09:08:17 +00003674
3675 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3676 if (E->hasExplicitTemplateArgumentList()) {
3677 TemplateArgs = &TransArgs;
3678 TransArgs.setLAngleLoc(E->getLAngleLoc());
3679 TransArgs.setRAngleLoc(E->getRAngleLoc());
3680 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3681 TemplateArgumentLoc Loc;
3682 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3683 return SemaRef.ExprError();
3684 TransArgs.addArgument(Loc);
3685 }
3686 }
3687
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003688 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003689 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003690}
Mike Stump11289f42009-09-09 15:08:12 +00003691
Douglas Gregora16548e2009-08-11 05:31:07 +00003692template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003693Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003694TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003695 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003696}
Mike Stump11289f42009-09-09 15:08:12 +00003697
Douglas Gregora16548e2009-08-11 05:31:07 +00003698template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003699Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003700TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003701 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003702}
Mike Stump11289f42009-09-09 15:08:12 +00003703
Douglas Gregora16548e2009-08-11 05:31:07 +00003704template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003705Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003706TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003707 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003708}
Mike Stump11289f42009-09-09 15:08:12 +00003709
Douglas Gregora16548e2009-08-11 05:31:07 +00003710template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003711Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003712TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003713 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003714}
Mike Stump11289f42009-09-09 15:08:12 +00003715
Douglas Gregora16548e2009-08-11 05:31:07 +00003716template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003717Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003718TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003719 return SemaRef.Owned(E->Retain());
3720}
3721
3722template<typename Derived>
3723Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003724TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003725 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3726 if (SubExpr.isInvalid())
3727 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003728
Douglas Gregora16548e2009-08-11 05:31:07 +00003729 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003730 return SemaRef.Owned(E->Retain());
3731
3732 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003733 E->getRParen());
3734}
3735
Mike Stump11289f42009-09-09 15:08:12 +00003736template<typename Derived>
3737Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003738TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3739 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003740 if (SubExpr.isInvalid())
3741 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003742
Douglas Gregora16548e2009-08-11 05:31:07 +00003743 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003744 return SemaRef.Owned(E->Retain());
3745
Douglas Gregora16548e2009-08-11 05:31:07 +00003746 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3747 E->getOpcode(),
3748 move(SubExpr));
3749}
Mike Stump11289f42009-09-09 15:08:12 +00003750
Douglas Gregora16548e2009-08-11 05:31:07 +00003751template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003752Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003753TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003754 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003755 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003756
John McCallbcd03502009-12-07 02:54:59 +00003757 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003758 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003759 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003760
John McCall4c98fd82009-11-04 07:28:41 +00003761 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003762 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003763
John McCall4c98fd82009-11-04 07:28:41 +00003764 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003765 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003766 E->getSourceRange());
3767 }
Mike Stump11289f42009-09-09 15:08:12 +00003768
Douglas Gregora16548e2009-08-11 05:31:07 +00003769 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003770 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003771 // C++0x [expr.sizeof]p1:
3772 // The operand is either an expression, which is an unevaluated operand
3773 // [...]
3774 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003775
Douglas Gregora16548e2009-08-11 05:31:07 +00003776 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3777 if (SubExpr.isInvalid())
3778 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003779
Douglas Gregora16548e2009-08-11 05:31:07 +00003780 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3781 return SemaRef.Owned(E->Retain());
3782 }
Mike Stump11289f42009-09-09 15:08:12 +00003783
Douglas Gregora16548e2009-08-11 05:31:07 +00003784 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3785 E->isSizeOf(),
3786 E->getSourceRange());
3787}
Mike Stump11289f42009-09-09 15:08:12 +00003788
Douglas Gregora16548e2009-08-11 05:31:07 +00003789template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003790Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003791TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003792 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3793 if (LHS.isInvalid())
3794 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003795
Douglas Gregora16548e2009-08-11 05:31:07 +00003796 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3797 if (RHS.isInvalid())
3798 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003799
3800
Douglas Gregora16548e2009-08-11 05:31:07 +00003801 if (!getDerived().AlwaysRebuild() &&
3802 LHS.get() == E->getLHS() &&
3803 RHS.get() == E->getRHS())
3804 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003805
Douglas Gregora16548e2009-08-11 05:31:07 +00003806 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3807 /*FIXME:*/E->getLHS()->getLocStart(),
3808 move(RHS),
3809 E->getRBracketLoc());
3810}
Mike Stump11289f42009-09-09 15:08:12 +00003811
3812template<typename Derived>
3813Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003814TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003815 // Transform the callee.
3816 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3817 if (Callee.isInvalid())
3818 return SemaRef.ExprError();
3819
3820 // Transform arguments.
3821 bool ArgChanged = false;
3822 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3823 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3824 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3825 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3826 if (Arg.isInvalid())
3827 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003828
Douglas Gregora16548e2009-08-11 05:31:07 +00003829 // FIXME: Wrong source location information for the ','.
3830 FakeCommaLocs.push_back(
3831 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003832
3833 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003834 Args.push_back(Arg.takeAs<Expr>());
3835 }
Mike Stump11289f42009-09-09 15:08:12 +00003836
Douglas Gregora16548e2009-08-11 05:31:07 +00003837 if (!getDerived().AlwaysRebuild() &&
3838 Callee.get() == E->getCallee() &&
3839 !ArgChanged)
3840 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003841
Douglas Gregora16548e2009-08-11 05:31:07 +00003842 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003843 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003844 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3845 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3846 move_arg(Args),
3847 FakeCommaLocs.data(),
3848 E->getRParenLoc());
3849}
Mike Stump11289f42009-09-09 15:08:12 +00003850
3851template<typename Derived>
3852Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003853TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003854 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3855 if (Base.isInvalid())
3856 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003857
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003858 NestedNameSpecifier *Qualifier = 0;
3859 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003860 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003861 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003862 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003863 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003864 return SemaRef.ExprError();
3865 }
Mike Stump11289f42009-09-09 15:08:12 +00003866
Eli Friedman2cfcef62009-12-04 06:40:45 +00003867 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003868 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
3869 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003870 if (!Member)
3871 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003872
Douglas Gregora16548e2009-08-11 05:31:07 +00003873 if (!getDerived().AlwaysRebuild() &&
3874 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003875 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003876 Member == E->getMemberDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003877 !E->hasExplicitTemplateArgumentList()) {
3878
3879 // Mark it referenced in the new context regardless.
3880 // FIXME: this is a bit instantiation-specific.
3881 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00003882 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003883 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003884
John McCall6b51f282009-11-23 01:53:49 +00003885 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003886 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003887 TransArgs.setLAngleLoc(E->getLAngleLoc());
3888 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003889 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003890 TemplateArgumentLoc Loc;
3891 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003892 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003893 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003894 }
3895 }
3896
Douglas Gregora16548e2009-08-11 05:31:07 +00003897 // FIXME: Bogus source location for the operator
3898 SourceLocation FakeOperatorLoc
3899 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3900
John McCall38836f02010-01-15 08:34:02 +00003901 // FIXME: to do this check properly, we will need to preserve the
3902 // first-qualifier-in-scope here, just in case we had a dependent
3903 // base (and therefore couldn't do the check) and a
3904 // nested-name-qualifier (and therefore could do the lookup).
3905 NamedDecl *FirstQualifierInScope = 0;
3906
Douglas Gregora16548e2009-08-11 05:31:07 +00003907 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3908 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003909 Qualifier,
3910 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003911 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003912 Member,
John McCall6b51f282009-11-23 01:53:49 +00003913 (E->hasExplicitTemplateArgumentList()
3914 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00003915 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00003916}
Mike Stump11289f42009-09-09 15:08:12 +00003917
Douglas Gregora16548e2009-08-11 05:31:07 +00003918template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003919Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003920TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003921 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3922 if (LHS.isInvalid())
3923 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003924
Douglas Gregora16548e2009-08-11 05:31:07 +00003925 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3926 if (RHS.isInvalid())
3927 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003928
Douglas Gregora16548e2009-08-11 05:31:07 +00003929 if (!getDerived().AlwaysRebuild() &&
3930 LHS.get() == E->getLHS() &&
3931 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003932 return SemaRef.Owned(E->Retain());
3933
Douglas Gregora16548e2009-08-11 05:31:07 +00003934 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3935 move(LHS), move(RHS));
3936}
3937
Mike Stump11289f42009-09-09 15:08:12 +00003938template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003939Sema::OwningExprResult
3940TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00003941 CompoundAssignOperator *E) {
3942 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00003943}
Mike Stump11289f42009-09-09 15:08:12 +00003944
Douglas Gregora16548e2009-08-11 05:31:07 +00003945template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003946Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003947TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003948 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3949 if (Cond.isInvalid())
3950 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003951
Douglas Gregora16548e2009-08-11 05:31:07 +00003952 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3953 if (LHS.isInvalid())
3954 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003955
Douglas Gregora16548e2009-08-11 05:31:07 +00003956 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3957 if (RHS.isInvalid())
3958 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003959
Douglas Gregora16548e2009-08-11 05:31:07 +00003960 if (!getDerived().AlwaysRebuild() &&
3961 Cond.get() == E->getCond() &&
3962 LHS.get() == E->getLHS() &&
3963 RHS.get() == E->getRHS())
3964 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003965
3966 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003967 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003968 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003969 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003970 move(RHS));
3971}
Mike Stump11289f42009-09-09 15:08:12 +00003972
3973template<typename Derived>
3974Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003975TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00003976 // Implicit casts are eliminated during transformation, since they
3977 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00003978 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003979}
Mike Stump11289f42009-09-09 15:08:12 +00003980
Douglas Gregora16548e2009-08-11 05:31:07 +00003981template<typename Derived>
3982Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003983TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00003984 TypeSourceInfo *OldT;
3985 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00003986 {
3987 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003988 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003989 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3990 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003991
John McCall97513962010-01-15 18:39:57 +00003992 OldT = E->getTypeInfoAsWritten();
3993 NewT = getDerived().TransformType(OldT);
3994 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003995 return SemaRef.ExprError();
3996 }
Mike Stump11289f42009-09-09 15:08:12 +00003997
Douglas Gregor6131b442009-12-12 18:16:41 +00003998 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00003999 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004000 if (SubExpr.isInvalid())
4001 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004002
Douglas Gregora16548e2009-08-11 05:31:07 +00004003 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004004 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004005 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004006 return SemaRef.Owned(E->Retain());
4007
John McCall97513962010-01-15 18:39:57 +00004008 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4009 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004010 E->getRParenLoc(),
4011 move(SubExpr));
4012}
Mike Stump11289f42009-09-09 15:08:12 +00004013
Douglas Gregora16548e2009-08-11 05:31:07 +00004014template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004015Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004016TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004017 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4018 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4019 if (!NewT)
4020 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004021
Douglas Gregora16548e2009-08-11 05:31:07 +00004022 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4023 if (Init.isInvalid())
4024 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004025
Douglas Gregora16548e2009-08-11 05:31:07 +00004026 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004027 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004028 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004029 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004030
John McCall5d7aa7f2010-01-19 22:33:45 +00004031 // Note: the expression type doesn't necessarily match the
4032 // type-as-written, but that's okay, because it should always be
4033 // derivable from the initializer.
4034
John McCalle15bbff2010-01-18 19:35:47 +00004035 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004036 /*FIXME:*/E->getInitializer()->getLocEnd(),
4037 move(Init));
4038}
Mike Stump11289f42009-09-09 15:08:12 +00004039
Douglas Gregora16548e2009-08-11 05:31:07 +00004040template<typename Derived>
4041Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004042TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004043 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4044 if (Base.isInvalid())
4045 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004046
Douglas Gregora16548e2009-08-11 05:31:07 +00004047 if (!getDerived().AlwaysRebuild() &&
4048 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004049 return SemaRef.Owned(E->Retain());
4050
Douglas Gregora16548e2009-08-11 05:31:07 +00004051 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004052 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004053 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4054 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4055 E->getAccessorLoc(),
4056 E->getAccessor());
4057}
Mike Stump11289f42009-09-09 15:08:12 +00004058
Douglas Gregora16548e2009-08-11 05:31:07 +00004059template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004060Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004061TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004062 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004063
Douglas Gregora16548e2009-08-11 05:31:07 +00004064 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4065 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4066 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4067 if (Init.isInvalid())
4068 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004069
Douglas Gregora16548e2009-08-11 05:31:07 +00004070 InitChanged = InitChanged || Init.get() != E->getInit(I);
4071 Inits.push_back(Init.takeAs<Expr>());
4072 }
Mike Stump11289f42009-09-09 15:08:12 +00004073
Douglas Gregora16548e2009-08-11 05:31:07 +00004074 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004075 return SemaRef.Owned(E->Retain());
4076
Douglas Gregora16548e2009-08-11 05:31:07 +00004077 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004078 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004079}
Mike Stump11289f42009-09-09 15:08:12 +00004080
Douglas Gregora16548e2009-08-11 05:31:07 +00004081template<typename Derived>
4082Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004083TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004084 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004085
Douglas Gregorebe10102009-08-20 07:17:43 +00004086 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004087 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4088 if (Init.isInvalid())
4089 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004090
Douglas Gregorebe10102009-08-20 07:17:43 +00004091 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004092 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4093 bool ExprChanged = false;
4094 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4095 DEnd = E->designators_end();
4096 D != DEnd; ++D) {
4097 if (D->isFieldDesignator()) {
4098 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4099 D->getDotLoc(),
4100 D->getFieldLoc()));
4101 continue;
4102 }
Mike Stump11289f42009-09-09 15:08:12 +00004103
Douglas Gregora16548e2009-08-11 05:31:07 +00004104 if (D->isArrayDesignator()) {
4105 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4106 if (Index.isInvalid())
4107 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004108
4109 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004110 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004111
Douglas Gregora16548e2009-08-11 05:31:07 +00004112 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4113 ArrayExprs.push_back(Index.release());
4114 continue;
4115 }
Mike Stump11289f42009-09-09 15:08:12 +00004116
Douglas Gregora16548e2009-08-11 05:31:07 +00004117 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004118 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004119 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4120 if (Start.isInvalid())
4121 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004122
Douglas Gregora16548e2009-08-11 05:31:07 +00004123 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4124 if (End.isInvalid())
4125 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004126
4127 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004128 End.get(),
4129 D->getLBracketLoc(),
4130 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004131
Douglas Gregora16548e2009-08-11 05:31:07 +00004132 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4133 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004134
Douglas Gregora16548e2009-08-11 05:31:07 +00004135 ArrayExprs.push_back(Start.release());
4136 ArrayExprs.push_back(End.release());
4137 }
Mike Stump11289f42009-09-09 15:08:12 +00004138
Douglas Gregora16548e2009-08-11 05:31:07 +00004139 if (!getDerived().AlwaysRebuild() &&
4140 Init.get() == E->getInit() &&
4141 !ExprChanged)
4142 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004143
Douglas Gregora16548e2009-08-11 05:31:07 +00004144 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4145 E->getEqualOrColonLoc(),
4146 E->usesGNUSyntax(), move(Init));
4147}
Mike Stump11289f42009-09-09 15:08:12 +00004148
Douglas Gregora16548e2009-08-11 05:31:07 +00004149template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004150Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004151TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004152 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004153 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4154
4155 // FIXME: Will we ever have proper type location here? Will we actually
4156 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004157 QualType T = getDerived().TransformType(E->getType());
4158 if (T.isNull())
4159 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004160
Douglas Gregora16548e2009-08-11 05:31:07 +00004161 if (!getDerived().AlwaysRebuild() &&
4162 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004163 return SemaRef.Owned(E->Retain());
4164
Douglas Gregora16548e2009-08-11 05:31:07 +00004165 return getDerived().RebuildImplicitValueInitExpr(T);
4166}
Mike Stump11289f42009-09-09 15:08:12 +00004167
Douglas Gregora16548e2009-08-11 05:31:07 +00004168template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004169Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004170TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004171 // FIXME: Do we want the type as written?
4172 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004173
Douglas Gregora16548e2009-08-11 05:31:07 +00004174 {
4175 // FIXME: Source location isn't quite accurate.
4176 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4177 T = getDerived().TransformType(E->getType());
4178 if (T.isNull())
4179 return SemaRef.ExprError();
4180 }
Mike Stump11289f42009-09-09 15:08:12 +00004181
Douglas Gregora16548e2009-08-11 05:31:07 +00004182 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4183 if (SubExpr.isInvalid())
4184 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004185
Douglas Gregora16548e2009-08-11 05:31:07 +00004186 if (!getDerived().AlwaysRebuild() &&
4187 T == E->getType() &&
4188 SubExpr.get() == E->getSubExpr())
4189 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004190
Douglas Gregora16548e2009-08-11 05:31:07 +00004191 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4192 T, E->getRParenLoc());
4193}
4194
4195template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004196Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004197TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004198 bool ArgumentChanged = false;
4199 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4200 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4201 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4202 if (Init.isInvalid())
4203 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004204
Douglas Gregora16548e2009-08-11 05:31:07 +00004205 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4206 Inits.push_back(Init.takeAs<Expr>());
4207 }
Mike Stump11289f42009-09-09 15:08:12 +00004208
Douglas Gregora16548e2009-08-11 05:31:07 +00004209 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4210 move_arg(Inits),
4211 E->getRParenLoc());
4212}
Mike Stump11289f42009-09-09 15:08:12 +00004213
Douglas Gregora16548e2009-08-11 05:31:07 +00004214/// \brief Transform an address-of-label expression.
4215///
4216/// By default, the transformation of an address-of-label expression always
4217/// rebuilds the expression, so that the label identifier can be resolved to
4218/// the corresponding label statement by semantic analysis.
4219template<typename Derived>
4220Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004221TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004222 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4223 E->getLabel());
4224}
Mike Stump11289f42009-09-09 15:08:12 +00004225
4226template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004227Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004228TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004229 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004230 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4231 if (SubStmt.isInvalid())
4232 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004233
Douglas Gregora16548e2009-08-11 05:31:07 +00004234 if (!getDerived().AlwaysRebuild() &&
4235 SubStmt.get() == E->getSubStmt())
4236 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004237
4238 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004239 move(SubStmt),
4240 E->getRParenLoc());
4241}
Mike Stump11289f42009-09-09 15:08:12 +00004242
Douglas Gregora16548e2009-08-11 05:31:07 +00004243template<typename Derived>
4244Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004245TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004246 QualType T1, T2;
4247 {
4248 // FIXME: Source location isn't quite accurate.
4249 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004250
Douglas Gregora16548e2009-08-11 05:31:07 +00004251 T1 = getDerived().TransformType(E->getArgType1());
4252 if (T1.isNull())
4253 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004254
Douglas Gregora16548e2009-08-11 05:31:07 +00004255 T2 = getDerived().TransformType(E->getArgType2());
4256 if (T2.isNull())
4257 return SemaRef.ExprError();
4258 }
4259
4260 if (!getDerived().AlwaysRebuild() &&
4261 T1 == E->getArgType1() &&
4262 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004263 return SemaRef.Owned(E->Retain());
4264
Douglas Gregora16548e2009-08-11 05:31:07 +00004265 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4266 T1, T2, E->getRParenLoc());
4267}
Mike Stump11289f42009-09-09 15:08:12 +00004268
Douglas Gregora16548e2009-08-11 05:31:07 +00004269template<typename Derived>
4270Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004271TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004272 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4273 if (Cond.isInvalid())
4274 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004275
Douglas Gregora16548e2009-08-11 05:31:07 +00004276 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4277 if (LHS.isInvalid())
4278 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004279
Douglas Gregora16548e2009-08-11 05:31:07 +00004280 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4281 if (RHS.isInvalid())
4282 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004283
Douglas Gregora16548e2009-08-11 05:31:07 +00004284 if (!getDerived().AlwaysRebuild() &&
4285 Cond.get() == E->getCond() &&
4286 LHS.get() == E->getLHS() &&
4287 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004288 return SemaRef.Owned(E->Retain());
4289
Douglas Gregora16548e2009-08-11 05:31:07 +00004290 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4291 move(Cond), move(LHS), move(RHS),
4292 E->getRParenLoc());
4293}
Mike Stump11289f42009-09-09 15:08:12 +00004294
Douglas Gregora16548e2009-08-11 05:31:07 +00004295template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004296Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004297TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004298 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004299}
4300
4301template<typename Derived>
4302Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004303TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004304 switch (E->getOperator()) {
4305 case OO_New:
4306 case OO_Delete:
4307 case OO_Array_New:
4308 case OO_Array_Delete:
4309 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4310 return SemaRef.ExprError();
4311
4312 case OO_Call: {
4313 // This is a call to an object's operator().
4314 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4315
4316 // Transform the object itself.
4317 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4318 if (Object.isInvalid())
4319 return SemaRef.ExprError();
4320
4321 // FIXME: Poor location information
4322 SourceLocation FakeLParenLoc
4323 = SemaRef.PP.getLocForEndOfToken(
4324 static_cast<Expr *>(Object.get())->getLocEnd());
4325
4326 // Transform the call arguments.
4327 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4328 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4329 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004330 if (getDerived().DropCallArgument(E->getArg(I)))
4331 break;
4332
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004333 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4334 if (Arg.isInvalid())
4335 return SemaRef.ExprError();
4336
4337 // FIXME: Poor source location information.
4338 SourceLocation FakeCommaLoc
4339 = SemaRef.PP.getLocForEndOfToken(
4340 static_cast<Expr *>(Arg.get())->getLocEnd());
4341 FakeCommaLocs.push_back(FakeCommaLoc);
4342 Args.push_back(Arg.release());
4343 }
4344
4345 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4346 move_arg(Args),
4347 FakeCommaLocs.data(),
4348 E->getLocEnd());
4349 }
4350
4351#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4352 case OO_##Name:
4353#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4354#include "clang/Basic/OperatorKinds.def"
4355 case OO_Subscript:
4356 // Handled below.
4357 break;
4358
4359 case OO_Conditional:
4360 llvm_unreachable("conditional operator is not actually overloadable");
4361 return SemaRef.ExprError();
4362
4363 case OO_None:
4364 case NUM_OVERLOADED_OPERATORS:
4365 llvm_unreachable("not an overloaded operator?");
4366 return SemaRef.ExprError();
4367 }
4368
Douglas Gregora16548e2009-08-11 05:31:07 +00004369 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4370 if (Callee.isInvalid())
4371 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004372
John McCall47f29ea2009-12-08 09:21:05 +00004373 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004374 if (First.isInvalid())
4375 return SemaRef.ExprError();
4376
4377 OwningExprResult Second(SemaRef);
4378 if (E->getNumArgs() == 2) {
4379 Second = getDerived().TransformExpr(E->getArg(1));
4380 if (Second.isInvalid())
4381 return SemaRef.ExprError();
4382 }
Mike Stump11289f42009-09-09 15:08:12 +00004383
Douglas Gregora16548e2009-08-11 05:31:07 +00004384 if (!getDerived().AlwaysRebuild() &&
4385 Callee.get() == E->getCallee() &&
4386 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004387 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4388 return SemaRef.Owned(E->Retain());
4389
Douglas Gregora16548e2009-08-11 05:31:07 +00004390 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4391 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004392 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004393 move(First),
4394 move(Second));
4395}
Mike Stump11289f42009-09-09 15:08:12 +00004396
Douglas Gregora16548e2009-08-11 05:31:07 +00004397template<typename Derived>
4398Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004399TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4400 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004401}
Mike Stump11289f42009-09-09 15:08:12 +00004402
Douglas Gregora16548e2009-08-11 05:31:07 +00004403template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004404Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004405TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004406 TypeSourceInfo *OldT;
4407 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004408 {
4409 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004410 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004411 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4412 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004413
John McCall97513962010-01-15 18:39:57 +00004414 OldT = E->getTypeInfoAsWritten();
4415 NewT = getDerived().TransformType(OldT);
4416 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004417 return SemaRef.ExprError();
4418 }
Mike Stump11289f42009-09-09 15:08:12 +00004419
Douglas Gregor6131b442009-12-12 18:16:41 +00004420 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004421 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004422 if (SubExpr.isInvalid())
4423 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004424
Douglas Gregora16548e2009-08-11 05:31:07 +00004425 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004426 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004427 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004428 return SemaRef.Owned(E->Retain());
4429
Douglas Gregora16548e2009-08-11 05:31:07 +00004430 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004431 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004432 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4433 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4434 SourceLocation FakeRParenLoc
4435 = SemaRef.PP.getLocForEndOfToken(
4436 E->getSubExpr()->getSourceRange().getEnd());
4437 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004438 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004439 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004440 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004441 FakeRAngleLoc,
4442 FakeRAngleLoc,
4443 move(SubExpr),
4444 FakeRParenLoc);
4445}
Mike Stump11289f42009-09-09 15:08:12 +00004446
Douglas Gregora16548e2009-08-11 05:31:07 +00004447template<typename Derived>
4448Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004449TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4450 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004451}
Mike Stump11289f42009-09-09 15:08:12 +00004452
4453template<typename Derived>
4454Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004455TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4456 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004457}
4458
Douglas Gregora16548e2009-08-11 05:31:07 +00004459template<typename Derived>
4460Sema::OwningExprResult
4461TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004462 CXXReinterpretCastExpr *E) {
4463 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004464}
Mike Stump11289f42009-09-09 15:08:12 +00004465
Douglas Gregora16548e2009-08-11 05:31:07 +00004466template<typename Derived>
4467Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004468TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4469 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004470}
Mike Stump11289f42009-09-09 15:08:12 +00004471
Douglas Gregora16548e2009-08-11 05:31:07 +00004472template<typename Derived>
4473Sema::OwningExprResult
4474TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004475 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004476 TypeSourceInfo *OldT;
4477 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004478 {
4479 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004480
John McCall97513962010-01-15 18:39:57 +00004481 OldT = E->getTypeInfoAsWritten();
4482 NewT = getDerived().TransformType(OldT);
4483 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004484 return SemaRef.ExprError();
4485 }
Mike Stump11289f42009-09-09 15:08:12 +00004486
Douglas Gregor6131b442009-12-12 18:16:41 +00004487 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004488 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004489 if (SubExpr.isInvalid())
4490 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004491
Douglas Gregora16548e2009-08-11 05:31:07 +00004492 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004493 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004494 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004495 return SemaRef.Owned(E->Retain());
4496
Douglas Gregora16548e2009-08-11 05:31:07 +00004497 // FIXME: The end of the type's source range is wrong
4498 return getDerived().RebuildCXXFunctionalCastExpr(
4499 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004500 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004501 /*FIXME:*/E->getSubExpr()->getLocStart(),
4502 move(SubExpr),
4503 E->getRParenLoc());
4504}
Mike Stump11289f42009-09-09 15:08:12 +00004505
Douglas Gregora16548e2009-08-11 05:31:07 +00004506template<typename Derived>
4507Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004508TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004509 if (E->isTypeOperand()) {
4510 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004511
Douglas Gregora16548e2009-08-11 05:31:07 +00004512 QualType T = getDerived().TransformType(E->getTypeOperand());
4513 if (T.isNull())
4514 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004515
Douglas Gregora16548e2009-08-11 05:31:07 +00004516 if (!getDerived().AlwaysRebuild() &&
4517 T == E->getTypeOperand())
4518 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004519
Douglas Gregora16548e2009-08-11 05:31:07 +00004520 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4521 /*FIXME:*/E->getLocStart(),
4522 T,
4523 E->getLocEnd());
4524 }
Mike Stump11289f42009-09-09 15:08:12 +00004525
Douglas Gregora16548e2009-08-11 05:31:07 +00004526 // We don't know whether the expression is potentially evaluated until
4527 // after we perform semantic analysis, so the expression is potentially
4528 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004529 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004530 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004531
Douglas Gregora16548e2009-08-11 05:31:07 +00004532 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4533 if (SubExpr.isInvalid())
4534 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004535
Douglas Gregora16548e2009-08-11 05:31:07 +00004536 if (!getDerived().AlwaysRebuild() &&
4537 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004538 return SemaRef.Owned(E->Retain());
4539
Douglas Gregora16548e2009-08-11 05:31:07 +00004540 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4541 /*FIXME:*/E->getLocStart(),
4542 move(SubExpr),
4543 E->getLocEnd());
4544}
4545
4546template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004547Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004548TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004549 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004550}
Mike Stump11289f42009-09-09 15:08:12 +00004551
Douglas Gregora16548e2009-08-11 05:31:07 +00004552template<typename Derived>
4553Sema::OwningExprResult
4554TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004555 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004556 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004557}
Mike Stump11289f42009-09-09 15:08:12 +00004558
Douglas Gregora16548e2009-08-11 05:31:07 +00004559template<typename Derived>
4560Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004561TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004562 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004563
Douglas Gregora16548e2009-08-11 05:31:07 +00004564 QualType T = getDerived().TransformType(E->getType());
4565 if (T.isNull())
4566 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004567
Douglas Gregora16548e2009-08-11 05:31:07 +00004568 if (!getDerived().AlwaysRebuild() &&
4569 T == E->getType())
4570 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004571
Douglas Gregorb15af892010-01-07 23:12:05 +00004572 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004573}
Mike Stump11289f42009-09-09 15:08:12 +00004574
Douglas Gregora16548e2009-08-11 05:31:07 +00004575template<typename Derived>
4576Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004577TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004578 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4579 if (SubExpr.isInvalid())
4580 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004581
Douglas Gregora16548e2009-08-11 05:31:07 +00004582 if (!getDerived().AlwaysRebuild() &&
4583 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004584 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004585
4586 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4587}
Mike Stump11289f42009-09-09 15:08:12 +00004588
Douglas Gregora16548e2009-08-11 05:31:07 +00004589template<typename Derived>
4590Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004591TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004592 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004593 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
4594 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004595 if (!Param)
4596 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004597
Chandler Carruth794da4c2010-02-08 06:42:49 +00004598 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004599 Param == E->getParam())
4600 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004601
Douglas Gregor033f6752009-12-23 23:03:06 +00004602 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00004603}
Mike Stump11289f42009-09-09 15:08:12 +00004604
Douglas Gregora16548e2009-08-11 05:31:07 +00004605template<typename Derived>
4606Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004607TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004608 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4609
4610 QualType T = getDerived().TransformType(E->getType());
4611 if (T.isNull())
4612 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004613
Douglas Gregora16548e2009-08-11 05:31:07 +00004614 if (!getDerived().AlwaysRebuild() &&
4615 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004616 return SemaRef.Owned(E->Retain());
4617
4618 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004619 /*FIXME:*/E->getTypeBeginLoc(),
4620 T,
4621 E->getRParenLoc());
4622}
Mike Stump11289f42009-09-09 15:08:12 +00004623
Douglas Gregora16548e2009-08-11 05:31:07 +00004624template<typename Derived>
4625Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004626TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004627 // Transform the type that we're allocating
4628 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4629 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4630 if (AllocType.isNull())
4631 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004632
Douglas Gregora16548e2009-08-11 05:31:07 +00004633 // Transform the size of the array we're allocating (if any).
4634 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4635 if (ArraySize.isInvalid())
4636 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004637
Douglas Gregora16548e2009-08-11 05:31:07 +00004638 // Transform the placement arguments (if any).
4639 bool ArgumentChanged = false;
4640 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4641 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4642 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4643 if (Arg.isInvalid())
4644 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004645
Douglas Gregora16548e2009-08-11 05:31:07 +00004646 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4647 PlacementArgs.push_back(Arg.take());
4648 }
Mike Stump11289f42009-09-09 15:08:12 +00004649
Douglas Gregorebe10102009-08-20 07:17:43 +00004650 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004651 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4652 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4653 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4654 if (Arg.isInvalid())
4655 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004656
Douglas Gregora16548e2009-08-11 05:31:07 +00004657 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4658 ConstructorArgs.push_back(Arg.take());
4659 }
Mike Stump11289f42009-09-09 15:08:12 +00004660
Douglas Gregord2d9da02010-02-26 00:38:10 +00004661 // Transform constructor, new operator, and delete operator.
4662 CXXConstructorDecl *Constructor = 0;
4663 if (E->getConstructor()) {
4664 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004665 getDerived().TransformDecl(E->getLocStart(),
4666 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004667 if (!Constructor)
4668 return SemaRef.ExprError();
4669 }
4670
4671 FunctionDecl *OperatorNew = 0;
4672 if (E->getOperatorNew()) {
4673 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004674 getDerived().TransformDecl(E->getLocStart(),
4675 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004676 if (!OperatorNew)
4677 return SemaRef.ExprError();
4678 }
4679
4680 FunctionDecl *OperatorDelete = 0;
4681 if (E->getOperatorDelete()) {
4682 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004683 getDerived().TransformDecl(E->getLocStart(),
4684 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004685 if (!OperatorDelete)
4686 return SemaRef.ExprError();
4687 }
4688
Douglas Gregora16548e2009-08-11 05:31:07 +00004689 if (!getDerived().AlwaysRebuild() &&
4690 AllocType == E->getAllocatedType() &&
4691 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004692 Constructor == E->getConstructor() &&
4693 OperatorNew == E->getOperatorNew() &&
4694 OperatorDelete == E->getOperatorDelete() &&
4695 !ArgumentChanged) {
4696 // Mark any declarations we need as referenced.
4697 // FIXME: instantiation-specific.
4698 if (Constructor)
4699 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
4700 if (OperatorNew)
4701 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
4702 if (OperatorDelete)
4703 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004704 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004705 }
Mike Stump11289f42009-09-09 15:08:12 +00004706
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004707 if (!ArraySize.get()) {
4708 // If no array size was specified, but the new expression was
4709 // instantiated with an array type (e.g., "new T" where T is
4710 // instantiated with "int[4]"), extract the outer bound from the
4711 // array type as our array size. We do this with constant and
4712 // dependently-sized array types.
4713 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4714 if (!ArrayT) {
4715 // Do nothing
4716 } else if (const ConstantArrayType *ConsArrayT
4717 = dyn_cast<ConstantArrayType>(ArrayT)) {
4718 ArraySize
4719 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4720 ConsArrayT->getSize(),
4721 SemaRef.Context.getSizeType(),
4722 /*FIXME:*/E->getLocStart()));
4723 AllocType = ConsArrayT->getElementType();
4724 } else if (const DependentSizedArrayType *DepArrayT
4725 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4726 if (DepArrayT->getSizeExpr()) {
4727 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4728 AllocType = DepArrayT->getElementType();
4729 }
4730 }
4731 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004732 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4733 E->isGlobalNew(),
4734 /*FIXME:*/E->getLocStart(),
4735 move_arg(PlacementArgs),
4736 /*FIXME:*/E->getLocStart(),
4737 E->isParenTypeId(),
4738 AllocType,
4739 /*FIXME:*/E->getLocStart(),
4740 /*FIXME:*/SourceRange(),
4741 move(ArraySize),
4742 /*FIXME:*/E->getLocStart(),
4743 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004744 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004745}
Mike Stump11289f42009-09-09 15:08:12 +00004746
Douglas Gregora16548e2009-08-11 05:31:07 +00004747template<typename Derived>
4748Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004749TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004750 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4751 if (Operand.isInvalid())
4752 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004753
Douglas Gregord2d9da02010-02-26 00:38:10 +00004754 // Transform the delete operator, if known.
4755 FunctionDecl *OperatorDelete = 0;
4756 if (E->getOperatorDelete()) {
4757 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004758 getDerived().TransformDecl(E->getLocStart(),
4759 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004760 if (!OperatorDelete)
4761 return SemaRef.ExprError();
4762 }
4763
Douglas Gregora16548e2009-08-11 05:31:07 +00004764 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004765 Operand.get() == E->getArgument() &&
4766 OperatorDelete == E->getOperatorDelete()) {
4767 // Mark any declarations we need as referenced.
4768 // FIXME: instantiation-specific.
4769 if (OperatorDelete)
4770 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004771 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004772 }
Mike Stump11289f42009-09-09 15:08:12 +00004773
Douglas Gregora16548e2009-08-11 05:31:07 +00004774 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4775 E->isGlobalDelete(),
4776 E->isArrayForm(),
4777 move(Operand));
4778}
Mike Stump11289f42009-09-09 15:08:12 +00004779
Douglas Gregora16548e2009-08-11 05:31:07 +00004780template<typename Derived>
4781Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004782TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004783 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004784 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4785 if (Base.isInvalid())
4786 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004787
Douglas Gregor678f90d2010-02-25 01:56:36 +00004788 Sema::TypeTy *ObjectTypePtr = 0;
4789 bool MayBePseudoDestructor = false;
4790 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4791 E->getOperatorLoc(),
4792 E->isArrow()? tok::arrow : tok::period,
4793 ObjectTypePtr,
4794 MayBePseudoDestructor);
4795 if (Base.isInvalid())
4796 return SemaRef.ExprError();
4797
4798 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004799 NestedNameSpecifier *Qualifier
4800 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00004801 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00004802 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004803 if (E->getQualifier() && !Qualifier)
4804 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004805
Douglas Gregor678f90d2010-02-25 01:56:36 +00004806 PseudoDestructorTypeStorage Destroyed;
4807 if (E->getDestroyedTypeInfo()) {
4808 TypeSourceInfo *DestroyedTypeInfo
4809 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
4810 if (!DestroyedTypeInfo)
4811 return SemaRef.ExprError();
4812 Destroyed = DestroyedTypeInfo;
4813 } else if (ObjectType->isDependentType()) {
4814 // We aren't likely to be able to resolve the identifier down to a type
4815 // now anyway, so just retain the identifier.
4816 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
4817 E->getDestroyedTypeLoc());
4818 } else {
4819 // Look for a destructor known with the given name.
4820 CXXScopeSpec SS;
4821 if (Qualifier) {
4822 SS.setScopeRep(Qualifier);
4823 SS.setRange(E->getQualifierRange());
4824 }
4825
4826 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
4827 *E->getDestroyedTypeIdentifier(),
4828 E->getDestroyedTypeLoc(),
4829 /*Scope=*/0,
4830 SS, ObjectTypePtr,
4831 false);
4832 if (!T)
4833 return SemaRef.ExprError();
4834
4835 Destroyed
4836 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
4837 E->getDestroyedTypeLoc());
4838 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004839
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004840 TypeSourceInfo *ScopeTypeInfo = 0;
4841 if (E->getScopeTypeInfo()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00004842 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
4843 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004844 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00004845 return SemaRef.ExprError();
4846 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004847
Douglas Gregorad8a3362009-09-04 17:36:40 +00004848 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4849 E->getOperatorLoc(),
4850 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00004851 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004852 E->getQualifierRange(),
4853 ScopeTypeInfo,
4854 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00004855 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00004856 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004857}
Mike Stump11289f42009-09-09 15:08:12 +00004858
Douglas Gregorad8a3362009-09-04 17:36:40 +00004859template<typename Derived>
4860Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004861TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004862 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00004863 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4864
4865 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4866 Sema::LookupOrdinaryName);
4867
4868 // Transform all the decls.
4869 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4870 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004871 NamedDecl *InstD = static_cast<NamedDecl*>(
4872 getDerived().TransformDecl(Old->getNameLoc(),
4873 *I));
John McCall84d87672009-12-10 09:41:52 +00004874 if (!InstD) {
4875 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4876 // This can happen because of dependent hiding.
4877 if (isa<UsingShadowDecl>(*I))
4878 continue;
4879 else
4880 return SemaRef.ExprError();
4881 }
John McCalle66edc12009-11-24 19:00:30 +00004882
4883 // Expand using declarations.
4884 if (isa<UsingDecl>(InstD)) {
4885 UsingDecl *UD = cast<UsingDecl>(InstD);
4886 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4887 E = UD->shadow_end(); I != E; ++I)
4888 R.addDecl(*I);
4889 continue;
4890 }
4891
4892 R.addDecl(InstD);
4893 }
4894
4895 // Resolve a kind, but don't do any further analysis. If it's
4896 // ambiguous, the callee needs to deal with it.
4897 R.resolveKind();
4898
4899 // Rebuild the nested-name qualifier, if present.
4900 CXXScopeSpec SS;
4901 NestedNameSpecifier *Qualifier = 0;
4902 if (Old->getQualifier()) {
4903 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004904 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00004905 if (!Qualifier)
4906 return SemaRef.ExprError();
4907
4908 SS.setScopeRep(Qualifier);
4909 SS.setRange(Old->getQualifierRange());
4910 }
4911
4912 // If we have no template arguments, it's a normal declaration name.
4913 if (!Old->hasExplicitTemplateArgs())
4914 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4915
4916 // If we have template arguments, rebuild them, then rebuild the
4917 // templateid expression.
4918 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4919 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4920 TemplateArgumentLoc Loc;
4921 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4922 return SemaRef.ExprError();
4923 TransArgs.addArgument(Loc);
4924 }
4925
4926 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4927 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004928}
Mike Stump11289f42009-09-09 15:08:12 +00004929
Douglas Gregora16548e2009-08-11 05:31:07 +00004930template<typename Derived>
4931Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004932TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004933 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004934
Douglas Gregora16548e2009-08-11 05:31:07 +00004935 QualType T = getDerived().TransformType(E->getQueriedType());
4936 if (T.isNull())
4937 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004938
Douglas Gregora16548e2009-08-11 05:31:07 +00004939 if (!getDerived().AlwaysRebuild() &&
4940 T == E->getQueriedType())
4941 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004942
Douglas Gregora16548e2009-08-11 05:31:07 +00004943 // FIXME: Bad location information
4944 SourceLocation FakeLParenLoc
4945 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004946
4947 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004948 E->getLocStart(),
4949 /*FIXME:*/FakeLParenLoc,
4950 T,
4951 E->getLocEnd());
4952}
Mike Stump11289f42009-09-09 15:08:12 +00004953
Douglas Gregora16548e2009-08-11 05:31:07 +00004954template<typename Derived>
4955Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004956TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004957 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004958 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004959 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004960 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004961 if (!NNS)
4962 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004963
4964 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004965 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4966 if (!Name)
4967 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004968
John McCalle66edc12009-11-24 19:00:30 +00004969 if (!E->hasExplicitTemplateArgs()) {
4970 if (!getDerived().AlwaysRebuild() &&
4971 NNS == E->getQualifier() &&
4972 Name == E->getDeclName())
4973 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004974
John McCalle66edc12009-11-24 19:00:30 +00004975 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4976 E->getQualifierRange(),
4977 Name, E->getLocation(),
4978 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004979 }
John McCall6b51f282009-11-23 01:53:49 +00004980
4981 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004982 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004983 TemplateArgumentLoc Loc;
4984 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004985 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004986 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004987 }
4988
John McCalle66edc12009-11-24 19:00:30 +00004989 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4990 E->getQualifierRange(),
4991 Name, E->getLocation(),
4992 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004993}
4994
4995template<typename Derived>
4996Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004997TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00004998 // CXXConstructExprs are always implicit, so when we have a
4999 // 1-argument construction we just transform that argument.
5000 if (E->getNumArgs() == 1 ||
5001 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5002 return getDerived().TransformExpr(E->getArg(0));
5003
Douglas Gregora16548e2009-08-11 05:31:07 +00005004 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5005
5006 QualType T = getDerived().TransformType(E->getType());
5007 if (T.isNull())
5008 return SemaRef.ExprError();
5009
5010 CXXConstructorDecl *Constructor
5011 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005012 getDerived().TransformDecl(E->getLocStart(),
5013 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005014 if (!Constructor)
5015 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005016
Douglas Gregora16548e2009-08-11 05:31:07 +00005017 bool ArgumentChanged = false;
5018 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005019 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005020 ArgEnd = E->arg_end();
5021 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005022 if (getDerived().DropCallArgument(*Arg)) {
5023 ArgumentChanged = true;
5024 break;
5025 }
5026
Douglas Gregora16548e2009-08-11 05:31:07 +00005027 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5028 if (TransArg.isInvalid())
5029 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005030
Douglas Gregora16548e2009-08-11 05:31:07 +00005031 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5032 Args.push_back(TransArg.takeAs<Expr>());
5033 }
5034
5035 if (!getDerived().AlwaysRebuild() &&
5036 T == E->getType() &&
5037 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005038 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005039 // Mark the constructor as referenced.
5040 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005041 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005042 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005043 }
Mike Stump11289f42009-09-09 15:08:12 +00005044
Douglas Gregordb121ba2009-12-14 16:27:04 +00005045 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5046 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005047 move_arg(Args));
5048}
Mike Stump11289f42009-09-09 15:08:12 +00005049
Douglas Gregora16548e2009-08-11 05:31:07 +00005050/// \brief Transform a C++ temporary-binding expression.
5051///
Douglas Gregor363b1512009-12-24 18:51:59 +00005052/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5053/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005054template<typename Derived>
5055Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005056TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005057 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005058}
Mike Stump11289f42009-09-09 15:08:12 +00005059
Anders Carlssonba6c4372010-01-29 02:39:32 +00005060/// \brief Transform a C++ reference-binding expression.
5061///
5062/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5063/// transform the subexpression and return that.
5064template<typename Derived>
5065Sema::OwningExprResult
5066TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5067 return getDerived().TransformExpr(E->getSubExpr());
5068}
5069
Mike Stump11289f42009-09-09 15:08:12 +00005070/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005071/// be destroyed after the expression is evaluated.
5072///
Douglas Gregor363b1512009-12-24 18:51:59 +00005073/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5074/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005075template<typename Derived>
5076Sema::OwningExprResult
5077TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005078 CXXExprWithTemporaries *E) {
5079 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005080}
Mike Stump11289f42009-09-09 15:08:12 +00005081
Douglas Gregora16548e2009-08-11 05:31:07 +00005082template<typename Derived>
5083Sema::OwningExprResult
5084TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005085 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005086 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5087 QualType T = getDerived().TransformType(E->getType());
5088 if (T.isNull())
5089 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005090
Douglas Gregora16548e2009-08-11 05:31:07 +00005091 CXXConstructorDecl *Constructor
5092 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005093 getDerived().TransformDecl(E->getLocStart(),
5094 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005095 if (!Constructor)
5096 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005097
Douglas Gregora16548e2009-08-11 05:31:07 +00005098 bool ArgumentChanged = false;
5099 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5100 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005101 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005102 ArgEnd = E->arg_end();
5103 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005104 if (getDerived().DropCallArgument(*Arg)) {
5105 ArgumentChanged = true;
5106 break;
5107 }
5108
Douglas Gregora16548e2009-08-11 05:31:07 +00005109 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5110 if (TransArg.isInvalid())
5111 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005112
Douglas Gregora16548e2009-08-11 05:31:07 +00005113 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5114 Args.push_back((Expr *)TransArg.release());
5115 }
Mike Stump11289f42009-09-09 15:08:12 +00005116
Douglas Gregora16548e2009-08-11 05:31:07 +00005117 if (!getDerived().AlwaysRebuild() &&
5118 T == E->getType() &&
5119 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005120 !ArgumentChanged) {
5121 // FIXME: Instantiation-specific
5122 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005123 return SemaRef.Owned(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005124 }
Mike Stump11289f42009-09-09 15:08:12 +00005125
Douglas Gregora16548e2009-08-11 05:31:07 +00005126 // FIXME: Bogus location information
5127 SourceLocation CommaLoc;
5128 if (Args.size() > 1) {
5129 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005130 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005131 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5132 }
5133 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5134 T,
5135 /*FIXME:*/E->getTypeBeginLoc(),
5136 move_arg(Args),
5137 &CommaLoc,
5138 E->getLocEnd());
5139}
Mike Stump11289f42009-09-09 15:08:12 +00005140
Douglas Gregora16548e2009-08-11 05:31:07 +00005141template<typename Derived>
5142Sema::OwningExprResult
5143TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005144 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005145 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5146 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5147 if (T.isNull())
5148 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005149
Douglas Gregora16548e2009-08-11 05:31:07 +00005150 bool ArgumentChanged = false;
5151 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5152 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5153 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5154 ArgEnd = E->arg_end();
5155 Arg != ArgEnd; ++Arg) {
5156 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5157 if (TransArg.isInvalid())
5158 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005159
Douglas Gregora16548e2009-08-11 05:31:07 +00005160 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5161 FakeCommaLocs.push_back(
5162 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5163 Args.push_back(TransArg.takeAs<Expr>());
5164 }
Mike Stump11289f42009-09-09 15:08:12 +00005165
Douglas Gregora16548e2009-08-11 05:31:07 +00005166 if (!getDerived().AlwaysRebuild() &&
5167 T == E->getTypeAsWritten() &&
5168 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005169 return SemaRef.Owned(E->Retain());
5170
Douglas Gregora16548e2009-08-11 05:31:07 +00005171 // FIXME: we're faking the locations of the commas
5172 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5173 T,
5174 E->getLParenLoc(),
5175 move_arg(Args),
5176 FakeCommaLocs.data(),
5177 E->getRParenLoc());
5178}
Mike Stump11289f42009-09-09 15:08:12 +00005179
Douglas Gregora16548e2009-08-11 05:31:07 +00005180template<typename Derived>
5181Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005182TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005183 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005184 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005185 OwningExprResult Base(SemaRef, (Expr*) 0);
5186 Expr *OldBase;
5187 QualType BaseType;
5188 QualType ObjectType;
5189 if (!E->isImplicitAccess()) {
5190 OldBase = E->getBase();
5191 Base = getDerived().TransformExpr(OldBase);
5192 if (Base.isInvalid())
5193 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005194
John McCall2d74de92009-12-01 22:10:20 +00005195 // Start the member reference and compute the object's type.
5196 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005197 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005198 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5199 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005200 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005201 ObjectTy,
5202 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005203 if (Base.isInvalid())
5204 return SemaRef.ExprError();
5205
5206 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5207 BaseType = ((Expr*) Base.get())->getType();
5208 } else {
5209 OldBase = 0;
5210 BaseType = getDerived().TransformType(E->getBaseType());
5211 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5212 }
Mike Stump11289f42009-09-09 15:08:12 +00005213
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005214 // Transform the first part of the nested-name-specifier that qualifies
5215 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005216 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005217 = getDerived().TransformFirstQualifierInScope(
5218 E->getFirstQualifierFoundInScope(),
5219 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005220
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005221 NestedNameSpecifier *Qualifier = 0;
5222 if (E->getQualifier()) {
5223 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5224 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005225 ObjectType,
5226 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005227 if (!Qualifier)
5228 return SemaRef.ExprError();
5229 }
Mike Stump11289f42009-09-09 15:08:12 +00005230
5231 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005232 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005233 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005234 if (!Name)
5235 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005236
John McCall2d74de92009-12-01 22:10:20 +00005237 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005238 // This is a reference to a member without an explicitly-specified
5239 // template argument list. Optimize for this common case.
5240 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005241 Base.get() == OldBase &&
5242 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005243 Qualifier == E->getQualifier() &&
5244 Name == E->getMember() &&
5245 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005246 return SemaRef.Owned(E->Retain());
5247
John McCall8cd78132009-11-19 22:55:06 +00005248 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005249 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005250 E->isArrow(),
5251 E->getOperatorLoc(),
5252 Qualifier,
5253 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005254 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005255 Name,
5256 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005257 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005258 }
5259
John McCall6b51f282009-11-23 01:53:49 +00005260 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005261 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005262 TemplateArgumentLoc Loc;
5263 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005264 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005265 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005266 }
Mike Stump11289f42009-09-09 15:08:12 +00005267
John McCall8cd78132009-11-19 22:55:06 +00005268 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005269 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005270 E->isArrow(),
5271 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005272 Qualifier,
5273 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005274 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005275 Name,
5276 E->getMemberLoc(),
5277 &TransArgs);
5278}
5279
5280template<typename Derived>
5281Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005282TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005283 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005284 OwningExprResult Base(SemaRef, (Expr*) 0);
5285 QualType BaseType;
5286 if (!Old->isImplicitAccess()) {
5287 Base = getDerived().TransformExpr(Old->getBase());
5288 if (Base.isInvalid())
5289 return SemaRef.ExprError();
5290 BaseType = ((Expr*) Base.get())->getType();
5291 } else {
5292 BaseType = getDerived().TransformType(Old->getBaseType());
5293 }
John McCall10eae182009-11-30 22:42:35 +00005294
5295 NestedNameSpecifier *Qualifier = 0;
5296 if (Old->getQualifier()) {
5297 Qualifier
5298 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005299 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005300 if (Qualifier == 0)
5301 return SemaRef.ExprError();
5302 }
5303
5304 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5305 Sema::LookupOrdinaryName);
5306
5307 // Transform all the decls.
5308 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5309 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005310 NamedDecl *InstD = static_cast<NamedDecl*>(
5311 getDerived().TransformDecl(Old->getMemberLoc(),
5312 *I));
John McCall84d87672009-12-10 09:41:52 +00005313 if (!InstD) {
5314 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5315 // This can happen because of dependent hiding.
5316 if (isa<UsingShadowDecl>(*I))
5317 continue;
5318 else
5319 return SemaRef.ExprError();
5320 }
John McCall10eae182009-11-30 22:42:35 +00005321
5322 // Expand using declarations.
5323 if (isa<UsingDecl>(InstD)) {
5324 UsingDecl *UD = cast<UsingDecl>(InstD);
5325 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5326 E = UD->shadow_end(); I != E; ++I)
5327 R.addDecl(*I);
5328 continue;
5329 }
5330
5331 R.addDecl(InstD);
5332 }
5333
5334 R.resolveKind();
5335
5336 TemplateArgumentListInfo TransArgs;
5337 if (Old->hasExplicitTemplateArgs()) {
5338 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5339 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5340 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5341 TemplateArgumentLoc Loc;
5342 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5343 Loc))
5344 return SemaRef.ExprError();
5345 TransArgs.addArgument(Loc);
5346 }
5347 }
John McCall38836f02010-01-15 08:34:02 +00005348
5349 // FIXME: to do this check properly, we will need to preserve the
5350 // first-qualifier-in-scope here, just in case we had a dependent
5351 // base (and therefore couldn't do the check) and a
5352 // nested-name-qualifier (and therefore could do the lookup).
5353 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005354
5355 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005356 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005357 Old->getOperatorLoc(),
5358 Old->isArrow(),
5359 Qualifier,
5360 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005361 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005362 R,
5363 (Old->hasExplicitTemplateArgs()
5364 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005365}
5366
5367template<typename Derived>
5368Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005369TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005370 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005371}
5372
Mike Stump11289f42009-09-09 15:08:12 +00005373template<typename Derived>
5374Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005375TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005376 // FIXME: poor source location
5377 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5378 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5379 if (EncodedType.isNull())
5380 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005381
Douglas Gregora16548e2009-08-11 05:31:07 +00005382 if (!getDerived().AlwaysRebuild() &&
5383 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00005384 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005385
5386 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5387 EncodedType,
5388 E->getRParenLoc());
5389}
Mike Stump11289f42009-09-09 15:08:12 +00005390
Douglas Gregora16548e2009-08-11 05:31:07 +00005391template<typename Derived>
5392Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005393TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005394 // FIXME: Implement this!
5395 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005396 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005397}
5398
Mike Stump11289f42009-09-09 15:08:12 +00005399template<typename Derived>
5400Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005401TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005402 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005403}
5404
Mike Stump11289f42009-09-09 15:08:12 +00005405template<typename Derived>
5406Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005407TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005408 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00005409 = cast_or_null<ObjCProtocolDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005410 getDerived().TransformDecl(E->getLocStart(),
5411 E->getProtocol()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005412 if (!Protocol)
5413 return SemaRef.ExprError();
5414
5415 if (!getDerived().AlwaysRebuild() &&
5416 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005417 return SemaRef.Owned(E->Retain());
5418
Douglas Gregora16548e2009-08-11 05:31:07 +00005419 return getDerived().RebuildObjCProtocolExpr(Protocol,
5420 E->getAtLoc(),
5421 /*FIXME:*/E->getAtLoc(),
5422 /*FIXME:*/E->getAtLoc(),
5423 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005424
Douglas Gregora16548e2009-08-11 05:31:07 +00005425}
5426
Mike Stump11289f42009-09-09 15:08:12 +00005427template<typename Derived>
5428Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005429TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005430 // FIXME: Implement this!
5431 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005432 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005433}
5434
Mike Stump11289f42009-09-09 15:08:12 +00005435template<typename Derived>
5436Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005437TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005438 // FIXME: Implement this!
5439 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005440 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005441}
5442
Mike Stump11289f42009-09-09 15:08:12 +00005443template<typename Derived>
5444Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005445TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005446 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005447 // FIXME: Implement this!
5448 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005449 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005450}
5451
Mike Stump11289f42009-09-09 15:08:12 +00005452template<typename Derived>
5453Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005454TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005455 // FIXME: Implement this!
5456 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005457 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005458}
5459
Mike Stump11289f42009-09-09 15:08:12 +00005460template<typename Derived>
5461Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005462TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005463 // FIXME: Implement this!
5464 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005465 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005466}
5467
Mike Stump11289f42009-09-09 15:08:12 +00005468template<typename Derived>
5469Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005470TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005471 bool ArgumentChanged = false;
5472 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5473 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5474 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5475 if (SubExpr.isInvalid())
5476 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005477
Douglas Gregora16548e2009-08-11 05:31:07 +00005478 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5479 SubExprs.push_back(SubExpr.takeAs<Expr>());
5480 }
Mike Stump11289f42009-09-09 15:08:12 +00005481
Douglas Gregora16548e2009-08-11 05:31:07 +00005482 if (!getDerived().AlwaysRebuild() &&
5483 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005484 return SemaRef.Owned(E->Retain());
5485
Douglas Gregora16548e2009-08-11 05:31:07 +00005486 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5487 move_arg(SubExprs),
5488 E->getRParenLoc());
5489}
5490
Mike Stump11289f42009-09-09 15:08:12 +00005491template<typename Derived>
5492Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005493TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005494 // FIXME: Implement this!
5495 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005496 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005497}
5498
Mike Stump11289f42009-09-09 15:08:12 +00005499template<typename Derived>
5500Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005501TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005502 // FIXME: Implement this!
5503 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005504 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005505}
Mike Stump11289f42009-09-09 15:08:12 +00005506
Douglas Gregora16548e2009-08-11 05:31:07 +00005507//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005508// Type reconstruction
5509//===----------------------------------------------------------------------===//
5510
Mike Stump11289f42009-09-09 15:08:12 +00005511template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005512QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5513 SourceLocation Star) {
5514 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005515 getDerived().getBaseEntity());
5516}
5517
Mike Stump11289f42009-09-09 15:08:12 +00005518template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005519QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5520 SourceLocation Star) {
5521 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005522 getDerived().getBaseEntity());
5523}
5524
Mike Stump11289f42009-09-09 15:08:12 +00005525template<typename Derived>
5526QualType
John McCall70dd5f62009-10-30 00:06:24 +00005527TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5528 bool WrittenAsLValue,
5529 SourceLocation Sigil) {
5530 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5531 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005532}
5533
5534template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005535QualType
John McCall70dd5f62009-10-30 00:06:24 +00005536TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5537 QualType ClassType,
5538 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005539 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005540 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005541}
5542
5543template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005544QualType
John McCall70dd5f62009-10-30 00:06:24 +00005545TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5546 SourceLocation Sigil) {
5547 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005548 getDerived().getBaseEntity());
5549}
5550
5551template<typename Derived>
5552QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005553TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5554 ArrayType::ArraySizeModifier SizeMod,
5555 const llvm::APInt *Size,
5556 Expr *SizeExpr,
5557 unsigned IndexTypeQuals,
5558 SourceRange BracketsRange) {
5559 if (SizeExpr || !Size)
5560 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5561 IndexTypeQuals, BracketsRange,
5562 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005563
5564 QualType Types[] = {
5565 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5566 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5567 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005568 };
5569 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5570 QualType SizeType;
5571 for (unsigned I = 0; I != NumTypes; ++I)
5572 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5573 SizeType = Types[I];
5574 break;
5575 }
Mike Stump11289f42009-09-09 15:08:12 +00005576
Douglas Gregord6ff3322009-08-04 16:50:30 +00005577 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005578 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005579 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005580 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005581}
Mike Stump11289f42009-09-09 15:08:12 +00005582
Douglas Gregord6ff3322009-08-04 16:50:30 +00005583template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005584QualType
5585TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005586 ArrayType::ArraySizeModifier SizeMod,
5587 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005588 unsigned IndexTypeQuals,
5589 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005590 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005591 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005592}
5593
5594template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005595QualType
Mike Stump11289f42009-09-09 15:08:12 +00005596TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005597 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005598 unsigned IndexTypeQuals,
5599 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005600 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005601 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005602}
Mike Stump11289f42009-09-09 15:08:12 +00005603
Douglas Gregord6ff3322009-08-04 16:50:30 +00005604template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005605QualType
5606TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005607 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005608 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005609 unsigned IndexTypeQuals,
5610 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005611 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005612 SizeExpr.takeAs<Expr>(),
5613 IndexTypeQuals, BracketsRange);
5614}
5615
5616template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005617QualType
5618TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005619 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005620 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005621 unsigned IndexTypeQuals,
5622 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005623 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005624 SizeExpr.takeAs<Expr>(),
5625 IndexTypeQuals, BracketsRange);
5626}
5627
5628template<typename Derived>
5629QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00005630 unsigned NumElements,
5631 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005632 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00005633 return SemaRef.Context.getVectorType(ElementType, NumElements,
5634 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005635}
Mike Stump11289f42009-09-09 15:08:12 +00005636
Douglas Gregord6ff3322009-08-04 16:50:30 +00005637template<typename Derived>
5638QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5639 unsigned NumElements,
5640 SourceLocation AttributeLoc) {
5641 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5642 NumElements, true);
5643 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005644 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005645 AttributeLoc);
5646 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5647 AttributeLoc);
5648}
Mike Stump11289f42009-09-09 15:08:12 +00005649
Douglas Gregord6ff3322009-08-04 16:50:30 +00005650template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005651QualType
5652TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005653 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005654 SourceLocation AttributeLoc) {
5655 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5656}
Mike Stump11289f42009-09-09 15:08:12 +00005657
Douglas Gregord6ff3322009-08-04 16:50:30 +00005658template<typename Derived>
5659QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005660 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005661 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005662 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005663 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005664 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005665 Quals,
5666 getDerived().getBaseLocation(),
5667 getDerived().getBaseEntity());
5668}
Mike Stump11289f42009-09-09 15:08:12 +00005669
Douglas Gregord6ff3322009-08-04 16:50:30 +00005670template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005671QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5672 return SemaRef.Context.getFunctionNoProtoType(T);
5673}
5674
5675template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005676QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5677 assert(D && "no decl found");
5678 if (D->isInvalidDecl()) return QualType();
5679
5680 TypeDecl *Ty;
5681 if (isa<UsingDecl>(D)) {
5682 UsingDecl *Using = cast<UsingDecl>(D);
5683 assert(Using->isTypeName() &&
5684 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5685
5686 // A valid resolved using typename decl points to exactly one type decl.
5687 assert(++Using->shadow_begin() == Using->shadow_end());
5688 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5689
5690 } else {
5691 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5692 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5693 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5694 }
5695
5696 return SemaRef.Context.getTypeDeclType(Ty);
5697}
5698
5699template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005700QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005701 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5702}
5703
5704template<typename Derived>
5705QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5706 return SemaRef.Context.getTypeOfType(Underlying);
5707}
5708
5709template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005710QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005711 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5712}
5713
5714template<typename Derived>
5715QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005716 TemplateName Template,
5717 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005718 const TemplateArgumentListInfo &TemplateArgs) {
5719 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005720}
Mike Stump11289f42009-09-09 15:08:12 +00005721
Douglas Gregor1135c352009-08-06 05:28:30 +00005722template<typename Derived>
5723NestedNameSpecifier *
5724TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5725 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005726 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005727 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005728 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005729 CXXScopeSpec SS;
5730 // FIXME: The source location information is all wrong.
5731 SS.setRange(Range);
5732 SS.setScopeRep(Prefix);
5733 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005734 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005735 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005736 ObjectType,
5737 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005738 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005739}
5740
5741template<typename Derived>
5742NestedNameSpecifier *
5743TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5744 SourceRange Range,
5745 NamespaceDecl *NS) {
5746 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5747}
5748
5749template<typename Derived>
5750NestedNameSpecifier *
5751TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5752 SourceRange Range,
5753 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005754 QualType T) {
5755 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00005756 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005757 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005758 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5759 T.getTypePtr());
5760 }
Mike Stump11289f42009-09-09 15:08:12 +00005761
Douglas Gregor1135c352009-08-06 05:28:30 +00005762 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5763 return 0;
5764}
Mike Stump11289f42009-09-09 15:08:12 +00005765
Douglas Gregor71dc5092009-08-06 06:41:21 +00005766template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005767TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005768TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5769 bool TemplateKW,
5770 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005771 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005772 Template);
5773}
5774
5775template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005776TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005777TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005778 const IdentifierInfo &II,
5779 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005780 CXXScopeSpec SS;
5781 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005782 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005783 UnqualifiedId Name;
5784 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005785 return getSema().ActOnDependentTemplateName(
5786 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005787 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005788 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005789 ObjectType.getAsOpaquePtr(),
5790 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005791 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005792}
Mike Stump11289f42009-09-09 15:08:12 +00005793
Douglas Gregora16548e2009-08-11 05:31:07 +00005794template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005795TemplateName
5796TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5797 OverloadedOperatorKind Operator,
5798 QualType ObjectType) {
5799 CXXScopeSpec SS;
5800 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5801 SS.setScopeRep(Qualifier);
5802 UnqualifiedId Name;
5803 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5804 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5805 Operator, SymbolLocations);
5806 return getSema().ActOnDependentTemplateName(
5807 /*FIXME:*/getDerived().getBaseLocation(),
5808 SS,
5809 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005810 ObjectType.getAsOpaquePtr(),
5811 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005812 .template getAsVal<TemplateName>();
5813}
5814
5815template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005816Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005817TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5818 SourceLocation OpLoc,
5819 ExprArg Callee,
5820 ExprArg First,
5821 ExprArg Second) {
5822 Expr *FirstExpr = (Expr *)First.get();
5823 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005824 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005825 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005826
Douglas Gregora16548e2009-08-11 05:31:07 +00005827 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005828 if (Op == OO_Subscript) {
5829 if (!FirstExpr->getType()->isOverloadableType() &&
5830 !SecondExpr->getType()->isOverloadableType())
5831 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005832 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005833 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005834 } else if (Op == OO_Arrow) {
5835 // -> is never a builtin operation.
5836 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005837 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005838 if (!FirstExpr->getType()->isOverloadableType()) {
5839 // The argument is not of overloadable type, so try to create a
5840 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005841 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005842 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005843
Douglas Gregora16548e2009-08-11 05:31:07 +00005844 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5845 }
5846 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005847 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005848 !SecondExpr->getType()->isOverloadableType()) {
5849 // Neither of the arguments is an overloadable type, so try to
5850 // create a built-in binary operation.
5851 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005852 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005853 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5854 if (Result.isInvalid())
5855 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005856
Douglas Gregora16548e2009-08-11 05:31:07 +00005857 First.release();
5858 Second.release();
5859 return move(Result);
5860 }
5861 }
Mike Stump11289f42009-09-09 15:08:12 +00005862
5863 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005864 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00005865 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005866
John McCalld14a8642009-11-21 08:51:07 +00005867 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5868 assert(ULE->requiresADL());
5869
5870 // FIXME: Do we have to check
5871 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00005872 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00005873 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00005874 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00005875 }
Mike Stump11289f42009-09-09 15:08:12 +00005876
Douglas Gregora16548e2009-08-11 05:31:07 +00005877 // Add any functions found via argument-dependent lookup.
5878 Expr *Args[2] = { FirstExpr, SecondExpr };
5879 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005880
Douglas Gregora16548e2009-08-11 05:31:07 +00005881 // Create the overloaded operator invocation for unary operators.
5882 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005883 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005884 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5885 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5886 }
Mike Stump11289f42009-09-09 15:08:12 +00005887
Sebastian Redladba46e2009-10-29 20:17:01 +00005888 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005889 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5890 OpLoc,
5891 move(First),
5892 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005893
Douglas Gregora16548e2009-08-11 05:31:07 +00005894 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005895 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005896 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005897 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005898 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5899 if (Result.isInvalid())
5900 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005901
Douglas Gregora16548e2009-08-11 05:31:07 +00005902 First.release();
5903 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005904 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005905}
Mike Stump11289f42009-09-09 15:08:12 +00005906
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005907template<typename Derived>
5908Sema::OwningExprResult
5909TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
5910 SourceLocation OperatorLoc,
5911 bool isArrow,
5912 NestedNameSpecifier *Qualifier,
5913 SourceRange QualifierRange,
5914 TypeSourceInfo *ScopeType,
5915 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005916 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00005917 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005918 CXXScopeSpec SS;
5919 if (Qualifier) {
5920 SS.setRange(QualifierRange);
5921 SS.setScopeRep(Qualifier);
5922 }
5923
5924 Expr *BaseE = (Expr *)Base.get();
5925 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005926 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005927 (!isArrow && !BaseType->getAs<RecordType>()) ||
5928 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00005929 !BaseType->getAs<PointerType>()->getPointeeType()
5930 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005931 // This pseudo-destructor expression is still a pseudo-destructor.
5932 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
5933 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005934 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00005935 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005936 /*FIXME?*/true);
5937 }
5938
Douglas Gregor678f90d2010-02-25 01:56:36 +00005939 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005940 DeclarationName Name
5941 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
5942 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
5943
5944 // FIXME: the ScopeType should be tacked onto SS.
5945
5946 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
5947 OperatorLoc, isArrow,
5948 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00005949 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005950 /*TemplateArgs*/ 0);
5951}
5952
Douglas Gregord6ff3322009-08-04 16:50:30 +00005953} // end namespace clang
5954
5955#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H