blob: bd939f0aeb58e0f49c21b78aba9e7abc6373f1f6 [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.
240 Decl *TransformDecl(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.
246 Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); }
Mike Stump11289f42009-09-09 15:08:12 +0000247
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000248 /// \brief Transform the given declaration, which was the first part of a
249 /// nested-name-specifier in a member access expression.
250 ///
251 /// This specific declaration transformation only applies to the first
252 /// identifier in a nested-name-specifier of a member access expression, e.g.,
253 /// the \c T in \c x->T::member
254 ///
255 /// By default, invokes TransformDecl() to transform the declaration.
256 /// Subclasses may override this function to provide alternate behavior.
257 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
258 return cast_or_null<NamedDecl>(getDerived().TransformDecl(D));
259 }
260
Douglas Gregord6ff3322009-08-04 16:50:30 +0000261 /// \brief Transform the given nested-name-specifier.
262 ///
Mike Stump11289f42009-09-09 15:08:12 +0000263 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000264 /// nested-name-specifier. Subclasses may override this function to provide
265 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000266 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000267 SourceRange Range,
Douglas Gregor90d554e2010-02-21 18:36:56 +0000268 bool MayBePseudoDestructor,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000269 QualType ObjectType = QualType(),
270 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000271
Douglas Gregorf816bd72009-09-03 22:13:48 +0000272 /// \brief Transform the given declaration name.
273 ///
274 /// By default, transforms the types of conversion function, constructor,
275 /// and destructor names and then (if needed) rebuilds the declaration name.
276 /// Identifiers and selectors are returned unmodified. Sublcasses may
277 /// override this function to provide alternate behavior.
278 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +0000279 SourceLocation Loc,
280 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000283 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000284 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000285 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000286 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000287 TemplateName TransformTemplateName(TemplateName Name,
288 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000289
Douglas Gregord6ff3322009-08-04 16:50:30 +0000290 /// \brief Transform the given template argument.
291 ///
Mike Stump11289f42009-09-09 15:08:12 +0000292 /// By default, this operation transforms the type, expression, or
293 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000294 /// new template argument from the transformed result. Subclasses may
295 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000296 ///
297 /// Returns true if there was an error.
298 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
299 TemplateArgumentLoc &Output);
300
301 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
302 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
303 TemplateArgumentLoc &ArgLoc);
304
John McCallbcd03502009-12-07 02:54:59 +0000305 /// \brief Fakes up a TypeSourceInfo for a type.
306 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
307 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000308 getDerived().getBaseLocation());
309 }
Mike Stump11289f42009-09-09 15:08:12 +0000310
John McCall550e0c22009-10-21 00:40:46 +0000311#define ABSTRACT_TYPELOC(CLASS, PARENT)
312#define TYPELOC(CLASS, PARENT) \
Douglas Gregorfe17d252010-02-16 19:09:40 +0000313 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
314 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000315#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000316
Douglas Gregorfe17d252010-02-16 19:09:40 +0000317 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
318 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000319
Douglas Gregorc59e5612009-10-19 22:04:39 +0000320 QualType
321 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
322 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000323
Douglas Gregorebe10102009-08-20 07:17:43 +0000324 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Mike Stump11289f42009-09-09 15:08:12 +0000325
Douglas Gregorebe10102009-08-20 07:17:43 +0000326#define STMT(Node, Parent) \
327 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000328#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +0000329 OwningExprResult Transform##Node(Node *E);
Douglas Gregora16548e2009-08-11 05:31:07 +0000330#define ABSTRACT_EXPR(Node, Parent)
331#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000332
Douglas Gregord6ff3322009-08-04 16:50:30 +0000333 /// \brief Build a new pointer type given its pointee type.
334 ///
335 /// By default, performs semantic analysis when building the pointer type.
336 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000337 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000338
339 /// \brief Build a new block pointer type given its pointee type.
340 ///
Mike Stump11289f42009-09-09 15:08:12 +0000341 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000342 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000343 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000344
John McCall70dd5f62009-10-30 00:06:24 +0000345 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000346 ///
John McCall70dd5f62009-10-30 00:06:24 +0000347 /// By default, performs semantic analysis when building the
348 /// reference type. Subclasses may override this routine to provide
349 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 ///
John McCall70dd5f62009-10-30 00:06:24 +0000351 /// \param LValue whether the type was written with an lvalue sigil
352 /// or an rvalue sigil.
353 QualType RebuildReferenceType(QualType ReferentType,
354 bool LValue,
355 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000356
Douglas Gregord6ff3322009-08-04 16:50:30 +0000357 /// \brief Build a new member pointer type given the pointee type and the
358 /// class type it refers into.
359 ///
360 /// By default, performs semantic analysis when building the member pointer
361 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000362 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
363 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000364
John McCall550e0c22009-10-21 00:40:46 +0000365 /// \brief Build a new Objective C object pointer type.
John McCall70dd5f62009-10-30 00:06:24 +0000366 QualType RebuildObjCObjectPointerType(QualType PointeeType,
367 SourceLocation Sigil);
John McCall550e0c22009-10-21 00:40:46 +0000368
Douglas Gregord6ff3322009-08-04 16:50:30 +0000369 /// \brief Build a new array type given the element type, size
370 /// modifier, size of the array (if known), size expression, and index type
371 /// qualifiers.
372 ///
373 /// By default, performs semantic analysis when building the array type.
374 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000375 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000376 QualType RebuildArrayType(QualType ElementType,
377 ArrayType::ArraySizeModifier SizeMod,
378 const llvm::APInt *Size,
379 Expr *SizeExpr,
380 unsigned IndexTypeQuals,
381 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000382
Douglas Gregord6ff3322009-08-04 16:50:30 +0000383 /// \brief Build a new constant array type given the element type, size
384 /// modifier, (known) size of the array, and index type qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000388 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000389 ArrayType::ArraySizeModifier SizeMod,
390 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000391 unsigned IndexTypeQuals,
392 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000393
Douglas Gregord6ff3322009-08-04 16:50:30 +0000394 /// \brief Build a new incomplete array type given the element type, size
395 /// modifier, and index type qualifiers.
396 ///
397 /// By default, performs semantic analysis when building the array type.
398 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000399 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000400 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000401 unsigned IndexTypeQuals,
402 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000403
Mike Stump11289f42009-09-09 15:08:12 +0000404 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000405 /// size modifier, size expression, and index type qualifiers.
406 ///
407 /// By default, performs semantic analysis when building the array type.
408 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000409 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000410 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000411 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000412 unsigned IndexTypeQuals,
413 SourceRange BracketsRange);
414
Mike Stump11289f42009-09-09 15:08:12 +0000415 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416 /// size modifier, size expression, and index type qualifiers.
417 ///
418 /// By default, performs semantic analysis when building the array type.
419 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000420 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000421 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000422 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 unsigned IndexTypeQuals,
424 SourceRange BracketsRange);
425
426 /// \brief Build a new vector type given the element type and
427 /// number of elements.
428 ///
429 /// By default, performs semantic analysis when building the vector type.
430 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000431 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
432 bool IsAltiVec, bool IsPixel);
Mike Stump11289f42009-09-09 15:08:12 +0000433
Douglas Gregord6ff3322009-08-04 16:50:30 +0000434 /// \brief Build a new extended vector type given the element type and
435 /// number of elements.
436 ///
437 /// By default, performs semantic analysis when building the vector type.
438 /// Subclasses may override this routine to provide different behavior.
439 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
440 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000441
442 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000443 /// given the element type and 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.
Mike Stump11289f42009-09-09 15:08:12 +0000447 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000448 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000449 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000450
Douglas Gregord6ff3322009-08-04 16:50:30 +0000451 /// \brief Build a new function type.
452 ///
453 /// By default, performs semantic analysis when building the function type.
454 /// Subclasses may override this routine to provide different behavior.
455 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000456 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000457 unsigned NumParamTypes,
458 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000459
John McCall550e0c22009-10-21 00:40:46 +0000460 /// \brief Build a new unprototyped function type.
461 QualType RebuildFunctionNoProtoType(QualType ResultType);
462
John McCallb96ec562009-12-04 22:46:56 +0000463 /// \brief Rebuild an unresolved typename type, given the decl that
464 /// the UnresolvedUsingTypenameDecl was transformed to.
465 QualType RebuildUnresolvedUsingType(Decl *D);
466
Douglas Gregord6ff3322009-08-04 16:50:30 +0000467 /// \brief Build a new typedef type.
468 QualType RebuildTypedefType(TypedefDecl *Typedef) {
469 return SemaRef.Context.getTypeDeclType(Typedef);
470 }
471
472 /// \brief Build a new class/struct/union type.
473 QualType RebuildRecordType(RecordDecl *Record) {
474 return SemaRef.Context.getTypeDeclType(Record);
475 }
476
477 /// \brief Build a new Enum type.
478 QualType RebuildEnumType(EnumDecl *Enum) {
479 return SemaRef.Context.getTypeDeclType(Enum);
480 }
John McCallfcc33b02009-09-05 00:15:47 +0000481
482 /// \brief Build a new elaborated type.
483 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
484 return SemaRef.Context.getElaboratedType(T, Tag);
485 }
Mike Stump11289f42009-09-09 15:08:12 +0000486
487 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000488 ///
489 /// By default, performs semantic analysis when building the typeof type.
490 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000491 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000492
Mike Stump11289f42009-09-09 15:08:12 +0000493 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000494 ///
495 /// By default, builds a new TypeOfType with the given underlying type.
496 QualType RebuildTypeOfType(QualType Underlying);
497
Mike Stump11289f42009-09-09 15:08:12 +0000498 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000499 ///
500 /// By default, performs semantic analysis when building the decltype type.
501 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000502 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000503
Douglas Gregord6ff3322009-08-04 16:50:30 +0000504 /// \brief Build a new template specialization type.
505 ///
506 /// By default, performs semantic analysis when building the template
507 /// specialization type. Subclasses may override this routine to provide
508 /// different behavior.
509 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000510 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000511 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000512
Douglas Gregord6ff3322009-08-04 16:50:30 +0000513 /// \brief Build a new qualified name type.
514 ///
Mike Stump11289f42009-09-09 15:08:12 +0000515 /// By default, builds a new QualifiedNameType type from the
516 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000517 /// this routine to provide different behavior.
518 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
519 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000520 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000521
522 /// \brief Build a new typename type that refers to a template-id.
523 ///
524 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000525 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000526 /// different behavior.
527 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
Douglas Gregor04922cb2010-02-13 06:05:33 +0000528 if (NNS->isDependent()) {
529 CXXScopeSpec SS;
530 SS.setScopeRep(NNS);
531 if (!SemaRef.computeDeclContext(SS))
532 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000533 cast<TemplateSpecializationType>(T));
Douglas Gregor04922cb2010-02-13 06:05:33 +0000534 }
Mike Stump11289f42009-09-09 15:08:12 +0000535
Douglas Gregord6ff3322009-08-04 16:50:30 +0000536 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000537 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000538
539 /// \brief Build a new typename type that refers to an identifier.
540 ///
541 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000542 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000543 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000544 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall0ad16662009-10-29 08:12:44 +0000545 const IdentifierInfo *Id,
546 SourceRange SR) {
547 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregor1135c352009-08-06 05:28:30 +0000548 }
Mike Stump11289f42009-09-09 15:08:12 +0000549
Douglas Gregor1135c352009-08-06 05:28:30 +0000550 /// \brief Build a new nested-name-specifier given the prefix and an
551 /// identifier that names the next step in the nested-name-specifier.
552 ///
553 /// By default, performs semantic analysis when building the new
554 /// nested-name-specifier. Subclasses may override this routine to provide
555 /// different behavior.
556 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
557 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000558 IdentifierInfo &II,
Douglas Gregor90d554e2010-02-21 18:36:56 +0000559 bool MayBePseudoDestructor,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000560 QualType ObjectType,
561 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000562
563 /// \brief Build a new nested-name-specifier given the prefix and the
564 /// namespace named in the next step in the nested-name-specifier.
565 ///
566 /// By default, performs semantic analysis when building the new
567 /// nested-name-specifier. Subclasses may override this routine to provide
568 /// different behavior.
569 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
570 SourceRange Range,
571 NamespaceDecl *NS);
572
573 /// \brief Build a new nested-name-specifier given the prefix and the
574 /// type named in the next step in the nested-name-specifier.
575 ///
576 /// By default, performs semantic analysis when building the new
577 /// nested-name-specifier. Subclasses may override this routine to provide
578 /// different behavior.
579 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
580 SourceRange Range,
581 bool TemplateKW,
Douglas Gregor90d554e2010-02-21 18:36:56 +0000582 QualType T,
583 bool MayBePseudoDestructor);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000584
585 /// \brief Build a new template name given a nested name specifier, a flag
586 /// indicating whether the "template" keyword was provided, and the template
587 /// that the template name refers to.
588 ///
589 /// By default, builds the new template name directly. Subclasses may override
590 /// this routine to provide different behavior.
591 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
592 bool TemplateKW,
593 TemplateDecl *Template);
594
Douglas Gregor71dc5092009-08-06 06:41:21 +0000595 /// \brief Build a new template name given a nested name specifier and the
596 /// name that is referred to as a template.
597 ///
598 /// By default, performs semantic analysis to determine whether the name can
599 /// be resolved to a specific template, then builds the appropriate kind of
600 /// template name. Subclasses may override this routine to provide different
601 /// behavior.
602 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000603 const IdentifierInfo &II,
604 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000605
Douglas Gregor71395fa2009-11-04 00:56:37 +0000606 /// \brief Build a new template name given a nested name specifier and the
607 /// overloaded operator name that is referred to as a template.
608 ///
609 /// By default, performs semantic analysis to determine whether the name can
610 /// be resolved to a specific template, then builds the appropriate kind of
611 /// template name. Subclasses may override this routine to provide different
612 /// behavior.
613 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
614 OverloadedOperatorKind Operator,
615 QualType ObjectType);
616
Douglas Gregorebe10102009-08-20 07:17:43 +0000617 /// \brief Build a new compound statement.
618 ///
619 /// By default, performs semantic analysis to build the new statement.
620 /// Subclasses may override this routine to provide different behavior.
621 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
622 MultiStmtArg Statements,
623 SourceLocation RBraceLoc,
624 bool IsStmtExpr) {
625 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
626 IsStmtExpr);
627 }
628
629 /// \brief Build a new case statement.
630 ///
631 /// By default, performs semantic analysis to build the new statement.
632 /// Subclasses may override this routine to provide different behavior.
633 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
634 ExprArg LHS,
635 SourceLocation EllipsisLoc,
636 ExprArg RHS,
637 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000638 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000639 ColonLoc);
640 }
Mike Stump11289f42009-09-09 15:08:12 +0000641
Douglas Gregorebe10102009-08-20 07:17:43 +0000642 /// \brief Attach the body to a new case statement.
643 ///
644 /// By default, performs semantic analysis to build the new statement.
645 /// Subclasses may override this routine to provide different behavior.
646 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
647 getSema().ActOnCaseStmtBody(S.get(), move(Body));
648 return move(S);
649 }
Mike Stump11289f42009-09-09 15:08:12 +0000650
Douglas Gregorebe10102009-08-20 07:17:43 +0000651 /// \brief Build a new default statement.
652 ///
653 /// By default, performs semantic analysis to build the new statement.
654 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000655 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000656 SourceLocation ColonLoc,
657 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000658 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000659 /*CurScope=*/0);
660 }
Mike Stump11289f42009-09-09 15:08:12 +0000661
Douglas Gregorebe10102009-08-20 07:17:43 +0000662 /// \brief Build a new label statement.
663 ///
664 /// By default, performs semantic analysis to build the new statement.
665 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000666 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000667 IdentifierInfo *Id,
668 SourceLocation ColonLoc,
669 StmtArg SubStmt) {
670 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
671 }
Mike Stump11289f42009-09-09 15:08:12 +0000672
Douglas Gregorebe10102009-08-20 07:17:43 +0000673 /// \brief Build a new "if" statement.
674 ///
675 /// By default, performs semantic analysis to build the new statement.
676 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000677 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000678 VarDecl *CondVar, StmtArg Then,
679 SourceLocation ElseLoc, StmtArg Else) {
680 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
681 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000682 }
Mike Stump11289f42009-09-09 15:08:12 +0000683
Douglas Gregorebe10102009-08-20 07:17:43 +0000684 /// \brief Start building a new switch statement.
685 ///
686 /// By default, performs semantic analysis to build the new statement.
687 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000688 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
689 VarDecl *CondVar) {
690 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000691 }
Mike Stump11289f42009-09-09 15:08:12 +0000692
Douglas Gregorebe10102009-08-20 07:17:43 +0000693 /// \brief Attach the body to the switch statement.
694 ///
695 /// By default, performs semantic analysis to build the new statement.
696 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000697 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000698 StmtArg Switch, StmtArg Body) {
699 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
700 move(Body));
701 }
702
703 /// \brief Build a new while statement.
704 ///
705 /// By default, performs semantic analysis to build the new statement.
706 /// Subclasses may override this routine to provide different behavior.
707 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
708 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000709 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000710 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000711 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
712 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000713 }
Mike Stump11289f42009-09-09 15:08:12 +0000714
Douglas Gregorebe10102009-08-20 07:17:43 +0000715 /// \brief Build a new do-while statement.
716 ///
717 /// By default, performs semantic analysis to build the new statement.
718 /// Subclasses may override this routine to provide different behavior.
719 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
720 SourceLocation WhileLoc,
721 SourceLocation LParenLoc,
722 ExprArg Cond,
723 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000724 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000725 move(Cond), RParenLoc);
726 }
727
728 /// \brief Build a new for statement.
729 ///
730 /// By default, performs semantic analysis to build the new statement.
731 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000732 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000733 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000734 StmtArg Init, Sema::FullExprArg Cond,
735 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000736 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000737 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
738 DeclPtrTy::make(CondVar),
739 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000740 }
Mike Stump11289f42009-09-09 15:08:12 +0000741
Douglas Gregorebe10102009-08-20 07:17:43 +0000742 /// \brief Build a new goto statement.
743 ///
744 /// By default, performs semantic analysis to build the new statement.
745 /// Subclasses may override this routine to provide different behavior.
746 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
747 SourceLocation LabelLoc,
748 LabelStmt *Label) {
749 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
750 }
751
752 /// \brief Build a new indirect goto statement.
753 ///
754 /// By default, performs semantic analysis to build the new statement.
755 /// Subclasses may override this routine to provide different behavior.
756 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
757 SourceLocation StarLoc,
758 ExprArg Target) {
759 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
760 }
Mike Stump11289f42009-09-09 15:08:12 +0000761
Douglas Gregorebe10102009-08-20 07:17:43 +0000762 /// \brief Build a new return statement.
763 ///
764 /// By default, performs semantic analysis to build the new statement.
765 /// Subclasses may override this routine to provide different behavior.
766 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
767 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000768
Douglas Gregorebe10102009-08-20 07:17:43 +0000769 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
770 }
Mike Stump11289f42009-09-09 15:08:12 +0000771
Douglas Gregorebe10102009-08-20 07:17:43 +0000772 /// \brief Build a new declaration statement.
773 ///
774 /// By default, performs semantic analysis to build the new statement.
775 /// Subclasses may override this routine to provide different behavior.
776 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000777 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000778 SourceLocation EndLoc) {
779 return getSema().Owned(
780 new (getSema().Context) DeclStmt(
781 DeclGroupRef::Create(getSema().Context,
782 Decls, NumDecls),
783 StartLoc, EndLoc));
784 }
Mike Stump11289f42009-09-09 15:08:12 +0000785
Anders Carlssonaaeef072010-01-24 05:50:09 +0000786 /// \brief Build a new inline asm 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 RebuildAsmStmt(SourceLocation AsmLoc,
791 bool IsSimple,
792 bool IsVolatile,
793 unsigned NumOutputs,
794 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000795 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000796 MultiExprArg Constraints,
797 MultiExprArg Exprs,
798 ExprArg AsmString,
799 MultiExprArg Clobbers,
800 SourceLocation RParenLoc,
801 bool MSAsm) {
802 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
803 NumInputs, Names, move(Constraints),
804 move(Exprs), move(AsmString), move(Clobbers),
805 RParenLoc, MSAsm);
806 }
807
Douglas Gregorebe10102009-08-20 07:17:43 +0000808 /// \brief Build a new C++ exception declaration.
809 ///
810 /// By default, performs semantic analysis to build the new decaration.
811 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000812 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000813 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000814 IdentifierInfo *Name,
815 SourceLocation Loc,
816 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000817 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000818 TypeRange);
819 }
820
821 /// \brief Build a new C++ catch statement.
822 ///
823 /// By default, performs semantic analysis to build the new statement.
824 /// Subclasses may override this routine to provide different behavior.
825 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
826 VarDecl *ExceptionDecl,
827 StmtArg Handler) {
828 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000829 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000830 Handler.takeAs<Stmt>()));
831 }
Mike Stump11289f42009-09-09 15:08:12 +0000832
Douglas Gregorebe10102009-08-20 07:17:43 +0000833 /// \brief Build a new C++ try statement.
834 ///
835 /// By default, performs semantic analysis to build the new statement.
836 /// Subclasses may override this routine to provide different behavior.
837 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
838 StmtArg TryBlock,
839 MultiStmtArg Handlers) {
840 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
841 }
Mike Stump11289f42009-09-09 15:08:12 +0000842
Douglas Gregora16548e2009-08-11 05:31:07 +0000843 /// \brief Build a new expression that references a declaration.
844 ///
845 /// By default, performs semantic analysis to build the new expression.
846 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +0000847 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
848 LookupResult &R,
849 bool RequiresADL) {
850 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
851 }
852
853
854 /// \brief Build a new expression that references a declaration.
855 ///
856 /// By default, performs semantic analysis to build the new expression.
857 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000858 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
859 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +0000860 ValueDecl *VD, SourceLocation Loc,
861 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000862 CXXScopeSpec SS;
863 SS.setScopeRep(Qualifier);
864 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +0000865
866 // FIXME: loses template args.
867
868 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +0000869 }
Mike Stump11289f42009-09-09 15:08:12 +0000870
Douglas Gregora16548e2009-08-11 05:31:07 +0000871 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000872 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000873 /// By default, performs semantic analysis to build the new expression.
874 /// Subclasses may override this routine to provide different behavior.
875 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
876 SourceLocation RParen) {
877 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
878 }
879
Douglas Gregorad8a3362009-09-04 17:36:40 +0000880 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000881 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000882 /// By default, performs semantic analysis to build the new expression.
883 /// Subclasses may override this routine to provide different behavior.
884 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
885 SourceLocation OperatorLoc,
886 bool isArrow,
Douglas Gregor651fe5e2010-02-24 23:40:28 +0000887 NestedNameSpecifier *Qualifier,
888 SourceRange QualifierRange,
889 TypeSourceInfo *ScopeType,
890 SourceLocation CCLoc,
891 TypeSourceInfo *DestroyedType);
Mike Stump11289f42009-09-09 15:08:12 +0000892
Douglas Gregora16548e2009-08-11 05:31:07 +0000893 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000894 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000895 /// By default, performs semantic analysis to build the new expression.
896 /// Subclasses may override this routine to provide different behavior.
897 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
898 UnaryOperator::Opcode Opc,
899 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000900 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +0000901 }
Mike Stump11289f42009-09-09 15:08:12 +0000902
Douglas Gregora16548e2009-08-11 05:31:07 +0000903 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000904 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000905 /// By default, performs semantic analysis to build the new expression.
906 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +0000907 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +0000908 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000909 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +0000910 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +0000911 }
912
Mike Stump11289f42009-09-09 15:08:12 +0000913 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000914 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +0000915 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000916 /// By default, performs semantic analysis to build the new expression.
917 /// Subclasses may override this routine to provide different behavior.
918 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
919 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +0000920 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000921 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
922 OpLoc, isSizeOf, R);
923 if (Result.isInvalid())
924 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000925
Douglas Gregora16548e2009-08-11 05:31:07 +0000926 SubExpr.release();
927 return move(Result);
928 }
Mike Stump11289f42009-09-09 15:08:12 +0000929
Douglas Gregora16548e2009-08-11 05:31:07 +0000930 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +0000931 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000932 /// By default, performs semantic analysis to build the new expression.
933 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000934 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000935 SourceLocation LBracketLoc,
936 ExprArg RHS,
937 SourceLocation RBracketLoc) {
938 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000939 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000940 RBracketLoc);
941 }
942
943 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000944 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000945 /// By default, performs semantic analysis to build the new expression.
946 /// Subclasses may override this routine to provide different behavior.
947 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
948 MultiExprArg Args,
949 SourceLocation *CommaLocs,
950 SourceLocation RParenLoc) {
951 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
952 move(Args), CommaLocs, RParenLoc);
953 }
954
955 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000956 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000957 /// By default, performs semantic analysis to build the new expression.
958 /// Subclasses may override this routine to provide different behavior.
959 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000960 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000961 NestedNameSpecifier *Qualifier,
962 SourceRange QualifierRange,
963 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +0000964 ValueDecl *Member,
John McCall6b51f282009-11-23 01:53:49 +0000965 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000966 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +0000967 if (!Member->getDeclName()) {
968 // We have a reference to an unnamed field.
969 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +0000970
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000971 Expr *BaseExpr = Base.takeAs<Expr>();
972 if (getSema().PerformObjectMemberConversion(BaseExpr, Member))
973 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +0000974
Mike Stump11289f42009-09-09 15:08:12 +0000975 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000976 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +0000977 Member, MemberLoc,
978 cast<FieldDecl>(Member)->getType());
979 return getSema().Owned(ME);
980 }
Mike Stump11289f42009-09-09 15:08:12 +0000981
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000982 CXXScopeSpec SS;
983 if (Qualifier) {
984 SS.setRange(QualifierRange);
985 SS.setScopeRep(Qualifier);
986 }
987
John McCall2d74de92009-12-01 22:10:20 +0000988 QualType BaseType = ((Expr*) Base.get())->getType();
989
John McCall38836f02010-01-15 08:34:02 +0000990 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
991 Sema::LookupMemberName);
992 R.addDecl(Member);
993 R.resolveKind();
994
John McCall2d74de92009-12-01 22:10:20 +0000995 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
996 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +0000997 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +0000998 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +0000999 }
Mike Stump11289f42009-09-09 15:08:12 +00001000
Douglas Gregora16548e2009-08-11 05:31:07 +00001001 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001002 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001003 /// By default, performs semantic analysis to build the new expression.
1004 /// Subclasses may override this routine to provide different behavior.
1005 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1006 BinaryOperator::Opcode Opc,
1007 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001008 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1009 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001010 }
1011
1012 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001013 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001014 /// By default, performs semantic analysis to build the new expression.
1015 /// Subclasses may override this routine to provide different behavior.
1016 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1017 SourceLocation QuestionLoc,
1018 ExprArg LHS,
1019 SourceLocation ColonLoc,
1020 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001021 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001022 move(LHS), move(RHS));
1023 }
1024
Douglas Gregora16548e2009-08-11 05:31:07 +00001025 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001026 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001027 /// By default, performs semantic analysis to build the new expression.
1028 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001029 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1030 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001031 SourceLocation RParenLoc,
1032 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001033 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1034 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001035 }
Mike Stump11289f42009-09-09 15:08:12 +00001036
Douglas Gregora16548e2009-08-11 05:31:07 +00001037 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001038 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001039 /// By default, performs semantic analysis to build the new expression.
1040 /// Subclasses may override this routine to provide different behavior.
1041 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001042 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001043 SourceLocation RParenLoc,
1044 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001045 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1046 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001047 }
Mike Stump11289f42009-09-09 15:08:12 +00001048
Douglas Gregora16548e2009-08-11 05:31:07 +00001049 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001050 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001051 /// By default, performs semantic analysis to build the new expression.
1052 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001053 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001054 SourceLocation OpLoc,
1055 SourceLocation AccessorLoc,
1056 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001057
John McCall10eae182009-11-30 22:42:35 +00001058 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001059 QualType BaseType = ((Expr*) Base.get())->getType();
1060 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001061 OpLoc, /*IsArrow*/ false,
1062 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001063 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001064 AccessorLoc,
1065 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001066 }
Mike Stump11289f42009-09-09 15:08:12 +00001067
Douglas Gregora16548e2009-08-11 05:31:07 +00001068 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001069 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001070 /// By default, performs semantic analysis to build the new expression.
1071 /// Subclasses may override this routine to provide different behavior.
1072 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1073 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001074 SourceLocation RBraceLoc,
1075 QualType ResultTy) {
1076 OwningExprResult Result
1077 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1078 if (Result.isInvalid() || ResultTy->isDependentType())
1079 return move(Result);
1080
1081 // Patch in the result type we were given, which may have been computed
1082 // when the initial InitListExpr was built.
1083 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1084 ILE->setType(ResultTy);
1085 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001086 }
Mike Stump11289f42009-09-09 15:08:12 +00001087
Douglas Gregora16548e2009-08-11 05:31:07 +00001088 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001089 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001090 /// By default, performs semantic analysis to build the new expression.
1091 /// Subclasses may override this routine to provide different behavior.
1092 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1093 MultiExprArg ArrayExprs,
1094 SourceLocation EqualOrColonLoc,
1095 bool GNUSyntax,
1096 ExprArg Init) {
1097 OwningExprResult Result
1098 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1099 move(Init));
1100 if (Result.isInvalid())
1101 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001102
Douglas Gregora16548e2009-08-11 05:31:07 +00001103 ArrayExprs.release();
1104 return move(Result);
1105 }
Mike Stump11289f42009-09-09 15:08:12 +00001106
Douglas Gregora16548e2009-08-11 05:31:07 +00001107 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001108 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001109 /// By default, builds the implicit value initialization without performing
1110 /// any semantic analysis. Subclasses may override this routine to provide
1111 /// different behavior.
1112 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1113 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1114 }
Mike Stump11289f42009-09-09 15:08:12 +00001115
Douglas Gregora16548e2009-08-11 05:31:07 +00001116 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001117 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001118 /// By default, performs semantic analysis to build the new expression.
1119 /// Subclasses may override this routine to provide different behavior.
1120 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1121 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001122 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001123 RParenLoc);
1124 }
1125
1126 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001127 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001128 /// By default, performs semantic analysis to build the new expression.
1129 /// Subclasses may override this routine to provide different behavior.
1130 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1131 MultiExprArg SubExprs,
1132 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001133 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1134 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001135 }
Mike Stump11289f42009-09-09 15:08:12 +00001136
Douglas Gregora16548e2009-08-11 05:31:07 +00001137 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001138 ///
1139 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001140 /// rather than attempting to map the label statement itself.
1141 /// Subclasses may override this routine to provide different behavior.
1142 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1143 SourceLocation LabelLoc,
1144 LabelStmt *Label) {
1145 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1146 }
Mike Stump11289f42009-09-09 15:08:12 +00001147
Douglas Gregora16548e2009-08-11 05:31:07 +00001148 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001149 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001150 /// By default, performs semantic analysis to build the new expression.
1151 /// Subclasses may override this routine to provide different behavior.
1152 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1153 StmtArg SubStmt,
1154 SourceLocation RParenLoc) {
1155 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1156 }
Mike Stump11289f42009-09-09 15:08:12 +00001157
Douglas Gregora16548e2009-08-11 05:31:07 +00001158 /// \brief Build a new __builtin_types_compatible_p expression.
1159 ///
1160 /// By default, performs semantic analysis to build the new expression.
1161 /// Subclasses may override this routine to provide different behavior.
1162 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1163 QualType T1, QualType T2,
1164 SourceLocation RParenLoc) {
1165 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1166 T1.getAsOpaquePtr(),
1167 T2.getAsOpaquePtr(),
1168 RParenLoc);
1169 }
Mike Stump11289f42009-09-09 15:08:12 +00001170
Douglas Gregora16548e2009-08-11 05:31:07 +00001171 /// \brief Build a new __builtin_choose_expr expression.
1172 ///
1173 /// By default, performs semantic analysis to build the new expression.
1174 /// Subclasses may override this routine to provide different behavior.
1175 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1176 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1177 SourceLocation RParenLoc) {
1178 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1179 move(Cond), move(LHS), move(RHS),
1180 RParenLoc);
1181 }
Mike Stump11289f42009-09-09 15:08:12 +00001182
Douglas Gregora16548e2009-08-11 05:31:07 +00001183 /// \brief Build a new overloaded operator call expression.
1184 ///
1185 /// By default, performs semantic analysis to build the new expression.
1186 /// The semantic analysis provides the behavior of template instantiation,
1187 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001188 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001189 /// argument-dependent lookup, etc. Subclasses may override this routine to
1190 /// provide different behavior.
1191 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1192 SourceLocation OpLoc,
1193 ExprArg Callee,
1194 ExprArg First,
1195 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001196
1197 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001198 /// reinterpret_cast.
1199 ///
1200 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001201 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001202 /// Subclasses may override this routine to provide different behavior.
1203 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1204 Stmt::StmtClass Class,
1205 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001206 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001207 SourceLocation RAngleLoc,
1208 SourceLocation LParenLoc,
1209 ExprArg SubExpr,
1210 SourceLocation RParenLoc) {
1211 switch (Class) {
1212 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001213 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001214 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 move(SubExpr), RParenLoc);
1216
1217 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001218 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001219 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001221
Douglas Gregora16548e2009-08-11 05:31:07 +00001222 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001223 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001224 RAngleLoc, LParenLoc,
1225 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001226 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001227
Douglas Gregora16548e2009-08-11 05:31:07 +00001228 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001229 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001230 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001231 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001232
Douglas Gregora16548e2009-08-11 05:31:07 +00001233 default:
1234 assert(false && "Invalid C++ named cast");
1235 break;
1236 }
Mike Stump11289f42009-09-09 15:08:12 +00001237
Douglas Gregora16548e2009-08-11 05:31:07 +00001238 return getSema().ExprError();
1239 }
Mike Stump11289f42009-09-09 15:08:12 +00001240
Douglas Gregora16548e2009-08-11 05:31:07 +00001241 /// \brief Build a new C++ static_cast expression.
1242 ///
1243 /// By default, performs semantic analysis to build the new expression.
1244 /// Subclasses may override this routine to provide different behavior.
1245 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1246 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001247 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001248 SourceLocation RAngleLoc,
1249 SourceLocation LParenLoc,
1250 ExprArg SubExpr,
1251 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001252 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1253 TInfo, move(SubExpr),
1254 SourceRange(LAngleLoc, RAngleLoc),
1255 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001256 }
1257
1258 /// \brief Build a new C++ dynamic_cast expression.
1259 ///
1260 /// By default, performs semantic analysis to build the new expression.
1261 /// Subclasses may override this routine to provide different behavior.
1262 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1263 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001264 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001265 SourceLocation RAngleLoc,
1266 SourceLocation LParenLoc,
1267 ExprArg SubExpr,
1268 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001269 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1270 TInfo, move(SubExpr),
1271 SourceRange(LAngleLoc, RAngleLoc),
1272 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001273 }
1274
1275 /// \brief Build a new C++ reinterpret_cast expression.
1276 ///
1277 /// By default, performs semantic analysis to build the new expression.
1278 /// Subclasses may override this routine to provide different behavior.
1279 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1280 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001281 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001282 SourceLocation RAngleLoc,
1283 SourceLocation LParenLoc,
1284 ExprArg SubExpr,
1285 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001286 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1287 TInfo, move(SubExpr),
1288 SourceRange(LAngleLoc, RAngleLoc),
1289 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001290 }
1291
1292 /// \brief Build a new C++ const_cast expression.
1293 ///
1294 /// By default, performs semantic analysis to build the new expression.
1295 /// Subclasses may override this routine to provide different behavior.
1296 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1297 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001298 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001299 SourceLocation RAngleLoc,
1300 SourceLocation LParenLoc,
1301 ExprArg SubExpr,
1302 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001303 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1304 TInfo, move(SubExpr),
1305 SourceRange(LAngleLoc, RAngleLoc),
1306 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 }
Mike Stump11289f42009-09-09 15:08:12 +00001308
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 /// \brief Build a new C++ functional-style cast expression.
1310 ///
1311 /// By default, performs semantic analysis to build the new expression.
1312 /// Subclasses may override this routine to provide different behavior.
1313 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001314 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001315 SourceLocation LParenLoc,
1316 ExprArg SubExpr,
1317 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001318 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001320 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001322 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001323 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 RParenLoc);
1325 }
Mike Stump11289f42009-09-09 15:08:12 +00001326
Douglas Gregora16548e2009-08-11 05:31:07 +00001327 /// \brief Build a new C++ typeid(type) expression.
1328 ///
1329 /// By default, performs semantic analysis to build the new expression.
1330 /// Subclasses may override this routine to provide different behavior.
1331 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1332 SourceLocation LParenLoc,
1333 QualType T,
1334 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001335 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 T.getAsOpaquePtr(), RParenLoc);
1337 }
Mike Stump11289f42009-09-09 15:08:12 +00001338
Douglas Gregora16548e2009-08-11 05:31:07 +00001339 /// \brief Build a new C++ typeid(expr) expression.
1340 ///
1341 /// By default, performs semantic analysis to build the new expression.
1342 /// Subclasses may override this routine to provide different behavior.
1343 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1344 SourceLocation LParenLoc,
1345 ExprArg Operand,
1346 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001347 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001348 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1349 RParenLoc);
1350 if (Result.isInvalid())
1351 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001352
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1354 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001355 }
1356
Douglas Gregora16548e2009-08-11 05:31:07 +00001357 /// \brief Build a new C++ "this" expression.
1358 ///
1359 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001360 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001361 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001362 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001363 QualType ThisType,
1364 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001366 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1367 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001368 }
1369
1370 /// \brief Build a new C++ throw expression.
1371 ///
1372 /// By default, performs semantic analysis to build the new expression.
1373 /// Subclasses may override this routine to provide different behavior.
1374 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1375 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1376 }
1377
1378 /// \brief Build a new C++ default-argument expression.
1379 ///
1380 /// By default, builds a new default-argument expression, which does not
1381 /// require any semantic analysis. Subclasses may override this routine to
1382 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001383 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1384 ParmVarDecl *Param) {
1385 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1386 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001387 }
1388
1389 /// \brief Build a new C++ zero-initialization expression.
1390 ///
1391 /// By default, performs semantic analysis to build the new expression.
1392 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001393 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001394 SourceLocation LParenLoc,
1395 QualType T,
1396 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001397 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1398 T.getAsOpaquePtr(), LParenLoc,
1399 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001400 0, RParenLoc);
1401 }
Mike Stump11289f42009-09-09 15:08:12 +00001402
Douglas Gregora16548e2009-08-11 05:31:07 +00001403 /// \brief Build a new C++ "new" expression.
1404 ///
1405 /// By default, performs semantic analysis to build the new expression.
1406 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001407 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 bool UseGlobal,
1409 SourceLocation PlacementLParen,
1410 MultiExprArg PlacementArgs,
1411 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001412 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001413 QualType AllocType,
1414 SourceLocation TypeLoc,
1415 SourceRange TypeRange,
1416 ExprArg ArraySize,
1417 SourceLocation ConstructorLParen,
1418 MultiExprArg ConstructorArgs,
1419 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001420 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 PlacementLParen,
1422 move(PlacementArgs),
1423 PlacementRParen,
1424 ParenTypeId,
1425 AllocType,
1426 TypeLoc,
1427 TypeRange,
1428 move(ArraySize),
1429 ConstructorLParen,
1430 move(ConstructorArgs),
1431 ConstructorRParen);
1432 }
Mike Stump11289f42009-09-09 15:08:12 +00001433
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 /// \brief Build a new C++ "delete" expression.
1435 ///
1436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
1438 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1439 bool IsGlobalDelete,
1440 bool IsArrayForm,
1441 ExprArg Operand) {
1442 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1443 move(Operand));
1444 }
Mike Stump11289f42009-09-09 15:08:12 +00001445
Douglas Gregora16548e2009-08-11 05:31:07 +00001446 /// \brief Build a new unary type trait expression.
1447 ///
1448 /// By default, performs semantic analysis to build the new expression.
1449 /// Subclasses may override this routine to provide different behavior.
1450 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1451 SourceLocation StartLoc,
1452 SourceLocation LParenLoc,
1453 QualType T,
1454 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001455 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 T.getAsOpaquePtr(), RParenLoc);
1457 }
1458
Mike Stump11289f42009-09-09 15:08:12 +00001459 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001460 /// expression.
1461 ///
1462 /// By default, performs semantic analysis to build the new expression.
1463 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001464 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001465 SourceRange QualifierRange,
1466 DeclarationName Name,
1467 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001468 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001469 CXXScopeSpec SS;
1470 SS.setRange(QualifierRange);
1471 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001472
1473 if (TemplateArgs)
1474 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1475 *TemplateArgs);
1476
1477 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001478 }
1479
1480 /// \brief Build a new template-id expression.
1481 ///
1482 /// By default, performs semantic analysis to build the new expression.
1483 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001484 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1485 LookupResult &R,
1486 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001487 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001488 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 }
1490
1491 /// \brief Build a new object-construction expression.
1492 ///
1493 /// By default, performs semantic analysis to build the new expression.
1494 /// Subclasses may override this routine to provide different behavior.
1495 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001496 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001497 CXXConstructorDecl *Constructor,
1498 bool IsElidable,
1499 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001500 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1501 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1502 ConvertedArgs))
1503 return getSema().ExprError();
1504
1505 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1506 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 }
1508
1509 /// \brief Build a new object-construction expression.
1510 ///
1511 /// By default, performs semantic analysis to build the new expression.
1512 /// Subclasses may override this routine to provide different behavior.
1513 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1514 QualType T,
1515 SourceLocation LParenLoc,
1516 MultiExprArg Args,
1517 SourceLocation *Commas,
1518 SourceLocation RParenLoc) {
1519 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1520 T.getAsOpaquePtr(),
1521 LParenLoc,
1522 move(Args),
1523 Commas,
1524 RParenLoc);
1525 }
1526
1527 /// \brief Build a new object-construction expression.
1528 ///
1529 /// By default, performs semantic analysis to build the new expression.
1530 /// Subclasses may override this routine to provide different behavior.
1531 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1532 QualType T,
1533 SourceLocation LParenLoc,
1534 MultiExprArg Args,
1535 SourceLocation *Commas,
1536 SourceLocation RParenLoc) {
1537 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1538 /*FIXME*/LParenLoc),
1539 T.getAsOpaquePtr(),
1540 LParenLoc,
1541 move(Args),
1542 Commas,
1543 RParenLoc);
1544 }
Mike Stump11289f42009-09-09 15:08:12 +00001545
Douglas Gregora16548e2009-08-11 05:31:07 +00001546 /// \brief Build a new member reference expression.
1547 ///
1548 /// By default, performs semantic analysis to build the new expression.
1549 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001550 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001551 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 bool IsArrow,
1553 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001554 NestedNameSpecifier *Qualifier,
1555 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001556 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001557 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001558 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001559 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001560 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001561 SS.setRange(QualifierRange);
1562 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001563
John McCall2d74de92009-12-01 22:10:20 +00001564 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1565 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001566 SS, FirstQualifierInScope,
1567 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 }
1569
John McCall10eae182009-11-30 22:42:35 +00001570 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001571 ///
1572 /// By default, performs semantic analysis to build the new expression.
1573 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001574 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001575 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001576 SourceLocation OperatorLoc,
1577 bool IsArrow,
1578 NestedNameSpecifier *Qualifier,
1579 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001580 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001581 LookupResult &R,
1582 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001583 CXXScopeSpec SS;
1584 SS.setRange(QualifierRange);
1585 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001586
John McCall2d74de92009-12-01 22:10:20 +00001587 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1588 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001589 SS, FirstQualifierInScope,
1590 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001591 }
Mike Stump11289f42009-09-09 15:08:12 +00001592
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 /// \brief Build a new Objective-C @encode expression.
1594 ///
1595 /// By default, performs semantic analysis to build the new expression.
1596 /// Subclasses may override this routine to provide different behavior.
1597 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1598 QualType T,
1599 SourceLocation RParenLoc) {
1600 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1601 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001602 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001603
1604 /// \brief Build a new Objective-C protocol expression.
1605 ///
1606 /// By default, performs semantic analysis to build the new expression.
1607 /// Subclasses may override this routine to provide different behavior.
1608 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1609 SourceLocation AtLoc,
1610 SourceLocation ProtoLoc,
1611 SourceLocation LParenLoc,
1612 SourceLocation RParenLoc) {
1613 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1614 Protocol->getIdentifier(),
1615 AtLoc,
1616 ProtoLoc,
1617 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001618 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 }
Mike Stump11289f42009-09-09 15:08:12 +00001620
Douglas Gregora16548e2009-08-11 05:31:07 +00001621 /// \brief Build a new shuffle vector expression.
1622 ///
1623 /// By default, performs semantic analysis to build the new expression.
1624 /// Subclasses may override this routine to provide different behavior.
1625 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1626 MultiExprArg SubExprs,
1627 SourceLocation RParenLoc) {
1628 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001629 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001630 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1631 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1632 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1633 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001634
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 // Build a reference to the __builtin_shufflevector builtin
1636 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001637 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001639 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001641
1642 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 unsigned NumSubExprs = SubExprs.size();
1644 Expr **Subs = (Expr **)SubExprs.release();
1645 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1646 Subs, NumSubExprs,
1647 Builtin->getResultType(),
1648 RParenLoc);
1649 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001650
Douglas Gregora16548e2009-08-11 05:31:07 +00001651 // Type-check the __builtin_shufflevector expression.
1652 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1653 if (Result.isInvalid())
1654 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001655
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001657 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001659};
Douglas Gregora16548e2009-08-11 05:31:07 +00001660
Douglas Gregorebe10102009-08-20 07:17:43 +00001661template<typename Derived>
1662Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1663 if (!S)
1664 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001665
Douglas Gregorebe10102009-08-20 07:17:43 +00001666 switch (S->getStmtClass()) {
1667 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001668
Douglas Gregorebe10102009-08-20 07:17:43 +00001669 // Transform individual statement nodes
1670#define STMT(Node, Parent) \
1671 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1672#define EXPR(Node, Parent)
1673#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001674
Douglas Gregorebe10102009-08-20 07:17:43 +00001675 // Transform expressions by calling TransformExpr.
1676#define STMT(Node, Parent)
John McCall2adddca2010-02-03 00:55:45 +00001677#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorebe10102009-08-20 07:17:43 +00001678#define EXPR(Node, Parent) case Stmt::Node##Class:
1679#include "clang/AST/StmtNodes.def"
1680 {
1681 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1682 if (E.isInvalid())
1683 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001684
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001685 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001686 }
Mike Stump11289f42009-09-09 15:08:12 +00001687 }
1688
Douglas Gregorebe10102009-08-20 07:17:43 +00001689 return SemaRef.Owned(S->Retain());
1690}
Mike Stump11289f42009-09-09 15:08:12 +00001691
1692
Douglas Gregore922c772009-08-04 22:27:00 +00001693template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001694Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001695 if (!E)
1696 return SemaRef.Owned(E);
1697
1698 switch (E->getStmtClass()) {
1699 case Stmt::NoStmtClass: break;
1700#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall2adddca2010-02-03 00:55:45 +00001701#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregora16548e2009-08-11 05:31:07 +00001702#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001703 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001704#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001705 }
1706
Douglas Gregora16548e2009-08-11 05:31:07 +00001707 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001708}
1709
1710template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001711NestedNameSpecifier *
1712TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001713 SourceRange Range,
Douglas Gregor90d554e2010-02-21 18:36:56 +00001714 bool MayBePseudoDestructor,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001715 QualType ObjectType,
1716 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001717 if (!NNS)
1718 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001719
Douglas Gregorebe10102009-08-20 07:17:43 +00001720 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001721 NestedNameSpecifier *Prefix = NNS->getPrefix();
1722 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001723 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor90d554e2010-02-21 18:36:56 +00001724 false,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001725 ObjectType,
1726 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001727 if (!Prefix)
1728 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001729
1730 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001731 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001732 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001733 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001734 }
Mike Stump11289f42009-09-09 15:08:12 +00001735
Douglas Gregor1135c352009-08-06 05:28:30 +00001736 switch (NNS->getKind()) {
1737 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001738 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001739 "Identifier nested-name-specifier with no prefix or object type");
1740 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1741 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001742 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001743
1744 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001745 *NNS->getAsIdentifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00001746 MayBePseudoDestructor,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001747 ObjectType,
1748 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001749
Douglas Gregor1135c352009-08-06 05:28:30 +00001750 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001751 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001752 = cast_or_null<NamespaceDecl>(
1753 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001754 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001755 Prefix == NNS->getPrefix() &&
1756 NS == NNS->getAsNamespace())
1757 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001758
Douglas Gregor1135c352009-08-06 05:28:30 +00001759 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1760 }
Mike Stump11289f42009-09-09 15:08:12 +00001761
Douglas Gregor1135c352009-08-06 05:28:30 +00001762 case NestedNameSpecifier::Global:
1763 // There is no meaningful transformation that one could perform on the
1764 // global scope.
1765 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001766
Douglas Gregor1135c352009-08-06 05:28:30 +00001767 case NestedNameSpecifier::TypeSpecWithTemplate:
1768 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001769 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00001770 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
1771 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001772 if (T.isNull())
1773 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001774
Douglas Gregor1135c352009-08-06 05:28:30 +00001775 if (!getDerived().AlwaysRebuild() &&
1776 Prefix == NNS->getPrefix() &&
1777 T == QualType(NNS->getAsType(), 0))
1778 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001779
1780 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1781 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregor90d554e2010-02-21 18:36:56 +00001782 T,
1783 MayBePseudoDestructor);
Douglas Gregor1135c352009-08-06 05:28:30 +00001784 }
1785 }
Mike Stump11289f42009-09-09 15:08:12 +00001786
Douglas Gregor1135c352009-08-06 05:28:30 +00001787 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001788 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001789}
1790
1791template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001792DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001793TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001794 SourceLocation Loc,
1795 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001796 if (!Name)
1797 return Name;
1798
1799 switch (Name.getNameKind()) {
1800 case DeclarationName::Identifier:
1801 case DeclarationName::ObjCZeroArgSelector:
1802 case DeclarationName::ObjCOneArgSelector:
1803 case DeclarationName::ObjCMultiArgSelector:
1804 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001805 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001806 case DeclarationName::CXXUsingDirective:
1807 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001808
Douglas Gregorf816bd72009-09-03 22:13:48 +00001809 case DeclarationName::CXXConstructorName:
1810 case DeclarationName::CXXDestructorName:
1811 case DeclarationName::CXXConversionFunctionName: {
1812 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorfe17d252010-02-16 19:09:40 +00001813 QualType T = getDerived().TransformType(Name.getCXXNameType(),
1814 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00001815 if (T.isNull())
1816 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001817
Douglas Gregorf816bd72009-09-03 22:13:48 +00001818 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001819 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001820 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001821 }
Mike Stump11289f42009-09-09 15:08:12 +00001822 }
1823
Douglas Gregorf816bd72009-09-03 22:13:48 +00001824 return DeclarationName();
1825}
1826
1827template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001828TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001829TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1830 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00001831 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001832 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001833 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001834 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
Douglas Gregor90d554e2010-02-21 18:36:56 +00001835 false,
Douglas Gregorfe17d252010-02-16 19:09:40 +00001836 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001837 if (!NNS)
1838 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001839
Douglas Gregor71dc5092009-08-06 06:41:21 +00001840 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001841 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001842 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1843 if (!TransTemplate)
1844 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001845
Douglas Gregor71dc5092009-08-06 06:41:21 +00001846 if (!getDerived().AlwaysRebuild() &&
1847 NNS == QTN->getQualifier() &&
1848 TransTemplate == Template)
1849 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001850
Douglas Gregor71dc5092009-08-06 06:41:21 +00001851 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1852 TransTemplate);
1853 }
Mike Stump11289f42009-09-09 15:08:12 +00001854
John McCalle66edc12009-11-24 19:00:30 +00001855 // These should be getting filtered out before they make it into the AST.
1856 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001857 }
Mike Stump11289f42009-09-09 15:08:12 +00001858
Douglas Gregor71dc5092009-08-06 06:41:21 +00001859 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001860 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001861 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001862 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
Douglas Gregor90d554e2010-02-21 18:36:56 +00001863 false,
Douglas Gregorfe17d252010-02-16 19:09:40 +00001864 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00001865 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001866 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001867
Douglas Gregor71dc5092009-08-06 06:41:21 +00001868 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001869 NNS == DTN->getQualifier() &&
1870 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001871 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001872
Douglas Gregor71395fa2009-11-04 00:56:37 +00001873 if (DTN->isIdentifier())
1874 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1875 ObjectType);
1876
1877 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1878 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001879 }
Mike Stump11289f42009-09-09 15:08:12 +00001880
Douglas Gregor71dc5092009-08-06 06:41:21 +00001881 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001882 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001883 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1884 if (!TransTemplate)
1885 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001886
Douglas Gregor71dc5092009-08-06 06:41:21 +00001887 if (!getDerived().AlwaysRebuild() &&
1888 TransTemplate == Template)
1889 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001890
Douglas Gregor71dc5092009-08-06 06:41:21 +00001891 return TemplateName(TransTemplate);
1892 }
Mike Stump11289f42009-09-09 15:08:12 +00001893
John McCalle66edc12009-11-24 19:00:30 +00001894 // These should be getting filtered out before they reach the AST.
1895 assert(false && "overloaded function decl survived to here");
1896 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00001897}
1898
1899template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001900void TreeTransform<Derived>::InventTemplateArgumentLoc(
1901 const TemplateArgument &Arg,
1902 TemplateArgumentLoc &Output) {
1903 SourceLocation Loc = getDerived().getBaseLocation();
1904 switch (Arg.getKind()) {
1905 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00001906 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00001907 break;
1908
1909 case TemplateArgument::Type:
1910 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00001911 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00001912
1913 break;
1914
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001915 case TemplateArgument::Template:
1916 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1917 break;
1918
John McCall0ad16662009-10-29 08:12:44 +00001919 case TemplateArgument::Expression:
1920 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1921 break;
1922
1923 case TemplateArgument::Declaration:
1924 case TemplateArgument::Integral:
1925 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00001926 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00001927 break;
1928 }
1929}
1930
1931template<typename Derived>
1932bool TreeTransform<Derived>::TransformTemplateArgument(
1933 const TemplateArgumentLoc &Input,
1934 TemplateArgumentLoc &Output) {
1935 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00001936 switch (Arg.getKind()) {
1937 case TemplateArgument::Null:
1938 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001939 Output = Input;
1940 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001941
Douglas Gregore922c772009-08-04 22:27:00 +00001942 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00001943 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00001944 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00001945 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00001946
1947 DI = getDerived().TransformType(DI);
1948 if (!DI) return true;
1949
1950 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1951 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001952 }
Mike Stump11289f42009-09-09 15:08:12 +00001953
Douglas Gregore922c772009-08-04 22:27:00 +00001954 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001955 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001956 DeclarationName Name;
1957 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1958 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001959 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregore922c772009-08-04 22:27:00 +00001960 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001961 if (!D) return true;
1962
John McCall0d07eb32009-10-29 18:45:58 +00001963 Expr *SourceExpr = Input.getSourceDeclExpression();
1964 if (SourceExpr) {
1965 EnterExpressionEvaluationContext Unevaluated(getSema(),
1966 Action::Unevaluated);
1967 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1968 if (E.isInvalid())
1969 SourceExpr = NULL;
1970 else {
1971 SourceExpr = E.takeAs<Expr>();
1972 SourceExpr->Retain();
1973 }
1974 }
1975
1976 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00001977 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001978 }
Mike Stump11289f42009-09-09 15:08:12 +00001979
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001980 case TemplateArgument::Template: {
1981 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1982 TemplateName Template
1983 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1984 if (Template.isNull())
1985 return true;
1986
1987 Output = TemplateArgumentLoc(TemplateArgument(Template),
1988 Input.getTemplateQualifierRange(),
1989 Input.getTemplateNameLoc());
1990 return false;
1991 }
1992
Douglas Gregore922c772009-08-04 22:27:00 +00001993 case TemplateArgument::Expression: {
1994 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00001995 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00001996 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00001997
John McCall0ad16662009-10-29 08:12:44 +00001998 Expr *InputExpr = Input.getSourceExpression();
1999 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2000
2001 Sema::OwningExprResult E
2002 = getDerived().TransformExpr(InputExpr);
2003 if (E.isInvalid()) return true;
2004
2005 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002006 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002007 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2008 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002009 }
Mike Stump11289f42009-09-09 15:08:12 +00002010
Douglas Gregore922c772009-08-04 22:27:00 +00002011 case TemplateArgument::Pack: {
2012 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2013 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002014 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002015 AEnd = Arg.pack_end();
2016 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002017
John McCall0ad16662009-10-29 08:12:44 +00002018 // FIXME: preserve source information here when we start
2019 // caring about parameter packs.
2020
John McCall0d07eb32009-10-29 18:45:58 +00002021 TemplateArgumentLoc InputArg;
2022 TemplateArgumentLoc OutputArg;
2023 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2024 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002025 return true;
2026
John McCall0d07eb32009-10-29 18:45:58 +00002027 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002028 }
2029 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002030 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002031 true);
John McCall0d07eb32009-10-29 18:45:58 +00002032 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002033 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002034 }
2035 }
Mike Stump11289f42009-09-09 15:08:12 +00002036
Douglas Gregore922c772009-08-04 22:27:00 +00002037 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002038 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002039}
2040
Douglas Gregord6ff3322009-08-04 16:50:30 +00002041//===----------------------------------------------------------------------===//
2042// Type transformation
2043//===----------------------------------------------------------------------===//
2044
2045template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002046QualType TreeTransform<Derived>::TransformType(QualType T,
2047 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002048 if (getDerived().AlreadyTransformed(T))
2049 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002050
John McCall550e0c22009-10-21 00:40:46 +00002051 // Temporary workaround. All of these transformations should
2052 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002053 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002054 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002055
Douglas Gregorfe17d252010-02-16 19:09:40 +00002056 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002057
John McCall550e0c22009-10-21 00:40:46 +00002058 if (!NewDI)
2059 return QualType();
2060
2061 return NewDI->getType();
2062}
2063
2064template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002065TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2066 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002067 if (getDerived().AlreadyTransformed(DI->getType()))
2068 return DI;
2069
2070 TypeLocBuilder TLB;
2071
2072 TypeLoc TL = DI->getTypeLoc();
2073 TLB.reserve(TL.getFullDataSize());
2074
Douglas Gregorfe17d252010-02-16 19:09:40 +00002075 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002076 if (Result.isNull())
2077 return 0;
2078
John McCallbcd03502009-12-07 02:54:59 +00002079 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002080}
2081
2082template<typename Derived>
2083QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002084TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2085 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002086 switch (T.getTypeLocClass()) {
2087#define ABSTRACT_TYPELOC(CLASS, PARENT)
2088#define TYPELOC(CLASS, PARENT) \
2089 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002090 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2091 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002092#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002093 }
Mike Stump11289f42009-09-09 15:08:12 +00002094
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002095 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002096 return QualType();
2097}
2098
2099/// FIXME: By default, this routine adds type qualifiers only to types
2100/// that can have qualifiers, and silently suppresses those qualifiers
2101/// that are not permitted (e.g., qualifiers on reference or function
2102/// types). This is the right thing for template instantiation, but
2103/// probably not for other clients.
2104template<typename Derived>
2105QualType
2106TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002107 QualifiedTypeLoc T,
2108 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002109 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002110
Douglas Gregorfe17d252010-02-16 19:09:40 +00002111 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2112 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002113 if (Result.isNull())
2114 return QualType();
2115
2116 // Silently suppress qualifiers if the result type can't be qualified.
2117 // FIXME: this is the right thing for template instantiation, but
2118 // probably not for other clients.
2119 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002120 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002121
John McCall550e0c22009-10-21 00:40:46 +00002122 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2123
2124 TLB.push<QualifiedTypeLoc>(Result);
2125
2126 // No location information to preserve.
2127
2128 return Result;
2129}
2130
2131template <class TyLoc> static inline
2132QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2133 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2134 NewT.setNameLoc(T.getNameLoc());
2135 return T.getType();
2136}
2137
2138// Ugly metaprogramming macros because I couldn't be bothered to make
2139// the equivalent template version work.
2140#define TransformPointerLikeType(TypeClass) do { \
2141 QualType PointeeType \
2142 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2143 if (PointeeType.isNull()) \
2144 return QualType(); \
2145 \
2146 QualType Result = TL.getType(); \
2147 if (getDerived().AlwaysRebuild() || \
2148 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall70dd5f62009-10-30 00:06:24 +00002149 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2150 TL.getSigilLoc()); \
John McCall550e0c22009-10-21 00:40:46 +00002151 if (Result.isNull()) \
2152 return QualType(); \
2153 } \
2154 \
2155 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2156 NewT.setSigilLoc(TL.getSigilLoc()); \
2157 \
2158 return Result; \
2159} while(0)
2160
John McCall550e0c22009-10-21 00:40:46 +00002161template<typename Derived>
2162QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002163 BuiltinTypeLoc T,
2164 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002165 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2166 NewT.setBuiltinLoc(T.getBuiltinLoc());
2167 if (T.needsExtraLocalData())
2168 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2169 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002170}
Mike Stump11289f42009-09-09 15:08:12 +00002171
Douglas Gregord6ff3322009-08-04 16:50:30 +00002172template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002173QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002174 ComplexTypeLoc T,
2175 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002176 // FIXME: recurse?
2177 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002178}
Mike Stump11289f42009-09-09 15:08:12 +00002179
Douglas Gregord6ff3322009-08-04 16:50:30 +00002180template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002181QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002182 PointerTypeLoc TL,
2183 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002184 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002185}
Mike Stump11289f42009-09-09 15:08:12 +00002186
2187template<typename Derived>
2188QualType
John McCall550e0c22009-10-21 00:40:46 +00002189TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002190 BlockPointerTypeLoc TL,
2191 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002192 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002193}
2194
John McCall70dd5f62009-10-30 00:06:24 +00002195/// Transforms a reference type. Note that somewhat paradoxically we
2196/// don't care whether the type itself is an l-value type or an r-value
2197/// type; we only care if the type was *written* as an l-value type
2198/// or an r-value type.
2199template<typename Derived>
2200QualType
2201TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002202 ReferenceTypeLoc TL,
2203 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002204 const ReferenceType *T = TL.getTypePtr();
2205
2206 // Note that this works with the pointee-as-written.
2207 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2208 if (PointeeType.isNull())
2209 return QualType();
2210
2211 QualType Result = TL.getType();
2212 if (getDerived().AlwaysRebuild() ||
2213 PointeeType != T->getPointeeTypeAsWritten()) {
2214 Result = getDerived().RebuildReferenceType(PointeeType,
2215 T->isSpelledAsLValue(),
2216 TL.getSigilLoc());
2217 if (Result.isNull())
2218 return QualType();
2219 }
2220
2221 // r-value references can be rebuilt as l-value references.
2222 ReferenceTypeLoc NewTL;
2223 if (isa<LValueReferenceType>(Result))
2224 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2225 else
2226 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2227 NewTL.setSigilLoc(TL.getSigilLoc());
2228
2229 return Result;
2230}
2231
Mike Stump11289f42009-09-09 15:08:12 +00002232template<typename Derived>
2233QualType
John McCall550e0c22009-10-21 00:40:46 +00002234TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002235 LValueReferenceTypeLoc TL,
2236 QualType ObjectType) {
2237 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002238}
2239
Mike Stump11289f42009-09-09 15:08:12 +00002240template<typename Derived>
2241QualType
John McCall550e0c22009-10-21 00:40:46 +00002242TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002243 RValueReferenceTypeLoc TL,
2244 QualType ObjectType) {
2245 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002246}
Mike Stump11289f42009-09-09 15:08:12 +00002247
Douglas Gregord6ff3322009-08-04 16:50:30 +00002248template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002249QualType
John McCall550e0c22009-10-21 00:40:46 +00002250TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002251 MemberPointerTypeLoc TL,
2252 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002253 MemberPointerType *T = TL.getTypePtr();
2254
2255 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002256 if (PointeeType.isNull())
2257 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002258
John McCall550e0c22009-10-21 00:40:46 +00002259 // TODO: preserve source information for this.
2260 QualType ClassType
2261 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002262 if (ClassType.isNull())
2263 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002264
John McCall550e0c22009-10-21 00:40:46 +00002265 QualType Result = TL.getType();
2266 if (getDerived().AlwaysRebuild() ||
2267 PointeeType != T->getPointeeType() ||
2268 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002269 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2270 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002271 if (Result.isNull())
2272 return QualType();
2273 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002274
John McCall550e0c22009-10-21 00:40:46 +00002275 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2276 NewTL.setSigilLoc(TL.getSigilLoc());
2277
2278 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002279}
2280
Mike Stump11289f42009-09-09 15:08:12 +00002281template<typename Derived>
2282QualType
John McCall550e0c22009-10-21 00:40:46 +00002283TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002284 ConstantArrayTypeLoc TL,
2285 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002286 ConstantArrayType *T = TL.getTypePtr();
2287 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002288 if (ElementType.isNull())
2289 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002290
John McCall550e0c22009-10-21 00:40:46 +00002291 QualType Result = TL.getType();
2292 if (getDerived().AlwaysRebuild() ||
2293 ElementType != T->getElementType()) {
2294 Result = getDerived().RebuildConstantArrayType(ElementType,
2295 T->getSizeModifier(),
2296 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002297 T->getIndexTypeCVRQualifiers(),
2298 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002299 if (Result.isNull())
2300 return QualType();
2301 }
2302
2303 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2304 NewTL.setLBracketLoc(TL.getLBracketLoc());
2305 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002306
John McCall550e0c22009-10-21 00:40:46 +00002307 Expr *Size = TL.getSizeExpr();
2308 if (Size) {
2309 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2310 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2311 }
2312 NewTL.setSizeExpr(Size);
2313
2314 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002315}
Mike Stump11289f42009-09-09 15:08:12 +00002316
Douglas Gregord6ff3322009-08-04 16:50:30 +00002317template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002318QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002319 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002320 IncompleteArrayTypeLoc TL,
2321 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002322 IncompleteArrayType *T = TL.getTypePtr();
2323 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002324 if (ElementType.isNull())
2325 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002326
John McCall550e0c22009-10-21 00:40:46 +00002327 QualType Result = TL.getType();
2328 if (getDerived().AlwaysRebuild() ||
2329 ElementType != T->getElementType()) {
2330 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002331 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002332 T->getIndexTypeCVRQualifiers(),
2333 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002334 if (Result.isNull())
2335 return QualType();
2336 }
2337
2338 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2339 NewTL.setLBracketLoc(TL.getLBracketLoc());
2340 NewTL.setRBracketLoc(TL.getRBracketLoc());
2341 NewTL.setSizeExpr(0);
2342
2343 return Result;
2344}
2345
2346template<typename Derived>
2347QualType
2348TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002349 VariableArrayTypeLoc TL,
2350 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002351 VariableArrayType *T = TL.getTypePtr();
2352 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2353 if (ElementType.isNull())
2354 return QualType();
2355
2356 // Array bounds are not potentially evaluated contexts
2357 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2358
2359 Sema::OwningExprResult SizeResult
2360 = getDerived().TransformExpr(T->getSizeExpr());
2361 if (SizeResult.isInvalid())
2362 return QualType();
2363
2364 Expr *Size = static_cast<Expr*>(SizeResult.get());
2365
2366 QualType Result = TL.getType();
2367 if (getDerived().AlwaysRebuild() ||
2368 ElementType != T->getElementType() ||
2369 Size != T->getSizeExpr()) {
2370 Result = getDerived().RebuildVariableArrayType(ElementType,
2371 T->getSizeModifier(),
2372 move(SizeResult),
2373 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002374 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002375 if (Result.isNull())
2376 return QualType();
2377 }
2378 else SizeResult.take();
2379
2380 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2381 NewTL.setLBracketLoc(TL.getLBracketLoc());
2382 NewTL.setRBracketLoc(TL.getRBracketLoc());
2383 NewTL.setSizeExpr(Size);
2384
2385 return Result;
2386}
2387
2388template<typename Derived>
2389QualType
2390TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002391 DependentSizedArrayTypeLoc TL,
2392 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002393 DependentSizedArrayType *T = TL.getTypePtr();
2394 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2395 if (ElementType.isNull())
2396 return QualType();
2397
2398 // Array bounds are not potentially evaluated contexts
2399 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2400
2401 Sema::OwningExprResult SizeResult
2402 = getDerived().TransformExpr(T->getSizeExpr());
2403 if (SizeResult.isInvalid())
2404 return QualType();
2405
2406 Expr *Size = static_cast<Expr*>(SizeResult.get());
2407
2408 QualType Result = TL.getType();
2409 if (getDerived().AlwaysRebuild() ||
2410 ElementType != T->getElementType() ||
2411 Size != T->getSizeExpr()) {
2412 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2413 T->getSizeModifier(),
2414 move(SizeResult),
2415 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002416 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002417 if (Result.isNull())
2418 return QualType();
2419 }
2420 else SizeResult.take();
2421
2422 // We might have any sort of array type now, but fortunately they
2423 // all have the same location layout.
2424 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2425 NewTL.setLBracketLoc(TL.getLBracketLoc());
2426 NewTL.setRBracketLoc(TL.getRBracketLoc());
2427 NewTL.setSizeExpr(Size);
2428
2429 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002430}
Mike Stump11289f42009-09-09 15:08:12 +00002431
2432template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002433QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002434 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002435 DependentSizedExtVectorTypeLoc TL,
2436 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002437 DependentSizedExtVectorType *T = TL.getTypePtr();
2438
2439 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002440 QualType ElementType = getDerived().TransformType(T->getElementType());
2441 if (ElementType.isNull())
2442 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002443
Douglas Gregore922c772009-08-04 22:27:00 +00002444 // Vector sizes are not potentially evaluated contexts
2445 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2446
Douglas Gregord6ff3322009-08-04 16:50:30 +00002447 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2448 if (Size.isInvalid())
2449 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002450
John McCall550e0c22009-10-21 00:40:46 +00002451 QualType Result = TL.getType();
2452 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002453 ElementType != T->getElementType() ||
2454 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002455 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002456 move(Size),
2457 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002458 if (Result.isNull())
2459 return QualType();
2460 }
2461 else Size.take();
2462
2463 // Result might be dependent or not.
2464 if (isa<DependentSizedExtVectorType>(Result)) {
2465 DependentSizedExtVectorTypeLoc NewTL
2466 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2467 NewTL.setNameLoc(TL.getNameLoc());
2468 } else {
2469 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2470 NewTL.setNameLoc(TL.getNameLoc());
2471 }
2472
2473 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002474}
Mike Stump11289f42009-09-09 15:08:12 +00002475
2476template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002477QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002478 VectorTypeLoc TL,
2479 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002480 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002481 QualType ElementType = getDerived().TransformType(T->getElementType());
2482 if (ElementType.isNull())
2483 return QualType();
2484
John McCall550e0c22009-10-21 00:40:46 +00002485 QualType Result = TL.getType();
2486 if (getDerived().AlwaysRebuild() ||
2487 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002488 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2489 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002490 if (Result.isNull())
2491 return QualType();
2492 }
2493
2494 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2495 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002496
John McCall550e0c22009-10-21 00:40:46 +00002497 return Result;
2498}
2499
2500template<typename Derived>
2501QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002502 ExtVectorTypeLoc TL,
2503 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002504 VectorType *T = TL.getTypePtr();
2505 QualType ElementType = getDerived().TransformType(T->getElementType());
2506 if (ElementType.isNull())
2507 return QualType();
2508
2509 QualType Result = TL.getType();
2510 if (getDerived().AlwaysRebuild() ||
2511 ElementType != T->getElementType()) {
2512 Result = getDerived().RebuildExtVectorType(ElementType,
2513 T->getNumElements(),
2514 /*FIXME*/ SourceLocation());
2515 if (Result.isNull())
2516 return QualType();
2517 }
2518
2519 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2520 NewTL.setNameLoc(TL.getNameLoc());
2521
2522 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002523}
Mike Stump11289f42009-09-09 15:08:12 +00002524
2525template<typename Derived>
2526QualType
John McCall550e0c22009-10-21 00:40:46 +00002527TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002528 FunctionProtoTypeLoc TL,
2529 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002530 FunctionProtoType *T = TL.getTypePtr();
2531 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002532 if (ResultType.isNull())
2533 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002534
John McCall550e0c22009-10-21 00:40:46 +00002535 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002536 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002537 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2538 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2539 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump11289f42009-09-09 15:08:12 +00002540
John McCall550e0c22009-10-21 00:40:46 +00002541 QualType NewType;
2542 ParmVarDecl *NewParm;
2543
2544 if (OldParm) {
John McCallbcd03502009-12-07 02:54:59 +00002545 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCall550e0c22009-10-21 00:40:46 +00002546 assert(OldDI->getType() == T->getArgType(i));
2547
John McCallbcd03502009-12-07 02:54:59 +00002548 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCall550e0c22009-10-21 00:40:46 +00002549 if (!NewDI)
2550 return QualType();
2551
2552 if (NewDI == OldDI)
2553 NewParm = OldParm;
2554 else
2555 NewParm = ParmVarDecl::Create(SemaRef.Context,
2556 OldParm->getDeclContext(),
2557 OldParm->getLocation(),
2558 OldParm->getIdentifier(),
2559 NewDI->getType(),
2560 NewDI,
2561 OldParm->getStorageClass(),
2562 /* DefArg */ NULL);
2563 NewType = NewParm->getType();
2564
2565 // Deal with the possibility that we don't have a parameter
2566 // declaration for this parameter.
2567 } else {
2568 NewParm = 0;
2569
2570 QualType OldType = T->getArgType(i);
2571 NewType = getDerived().TransformType(OldType);
2572 if (NewType.isNull())
2573 return QualType();
2574 }
2575
2576 ParamTypes.push_back(NewType);
2577 ParamDecls.push_back(NewParm);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002578 }
Mike Stump11289f42009-09-09 15:08:12 +00002579
John McCall550e0c22009-10-21 00:40:46 +00002580 QualType Result = TL.getType();
2581 if (getDerived().AlwaysRebuild() ||
2582 ResultType != T->getResultType() ||
2583 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2584 Result = getDerived().RebuildFunctionProtoType(ResultType,
2585 ParamTypes.data(),
2586 ParamTypes.size(),
2587 T->isVariadic(),
2588 T->getTypeQuals());
2589 if (Result.isNull())
2590 return QualType();
2591 }
Mike Stump11289f42009-09-09 15:08:12 +00002592
John McCall550e0c22009-10-21 00:40:46 +00002593 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2594 NewTL.setLParenLoc(TL.getLParenLoc());
2595 NewTL.setRParenLoc(TL.getRParenLoc());
2596 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2597 NewTL.setArg(i, ParamDecls[i]);
2598
2599 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002600}
Mike Stump11289f42009-09-09 15:08:12 +00002601
Douglas Gregord6ff3322009-08-04 16:50:30 +00002602template<typename Derived>
2603QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002604 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002605 FunctionNoProtoTypeLoc TL,
2606 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002607 FunctionNoProtoType *T = TL.getTypePtr();
2608 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2609 if (ResultType.isNull())
2610 return QualType();
2611
2612 QualType Result = TL.getType();
2613 if (getDerived().AlwaysRebuild() ||
2614 ResultType != T->getResultType())
2615 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2616
2617 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2618 NewTL.setLParenLoc(TL.getLParenLoc());
2619 NewTL.setRParenLoc(TL.getRParenLoc());
2620
2621 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002622}
Mike Stump11289f42009-09-09 15:08:12 +00002623
John McCallb96ec562009-12-04 22:46:56 +00002624template<typename Derived> QualType
2625TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002626 UnresolvedUsingTypeLoc TL,
2627 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002628 UnresolvedUsingType *T = TL.getTypePtr();
2629 Decl *D = getDerived().TransformDecl(T->getDecl());
2630 if (!D)
2631 return QualType();
2632
2633 QualType Result = TL.getType();
2634 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2635 Result = getDerived().RebuildUnresolvedUsingType(D);
2636 if (Result.isNull())
2637 return QualType();
2638 }
2639
2640 // We might get an arbitrary type spec type back. We should at
2641 // least always get a type spec type, though.
2642 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2643 NewTL.setNameLoc(TL.getNameLoc());
2644
2645 return Result;
2646}
2647
Douglas Gregord6ff3322009-08-04 16:50:30 +00002648template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002649QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002650 TypedefTypeLoc TL,
2651 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002652 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002653 TypedefDecl *Typedef
2654 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2655 if (!Typedef)
2656 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002657
John McCall550e0c22009-10-21 00:40:46 +00002658 QualType Result = TL.getType();
2659 if (getDerived().AlwaysRebuild() ||
2660 Typedef != T->getDecl()) {
2661 Result = getDerived().RebuildTypedefType(Typedef);
2662 if (Result.isNull())
2663 return QualType();
2664 }
Mike Stump11289f42009-09-09 15:08:12 +00002665
John McCall550e0c22009-10-21 00:40:46 +00002666 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2667 NewTL.setNameLoc(TL.getNameLoc());
2668
2669 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002670}
Mike Stump11289f42009-09-09 15:08:12 +00002671
Douglas Gregord6ff3322009-08-04 16:50:30 +00002672template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002673QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002674 TypeOfExprTypeLoc TL,
2675 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00002676 // typeof expressions are not potentially evaluated contexts
2677 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002678
John McCalle8595032010-01-13 20:03:27 +00002679 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002680 if (E.isInvalid())
2681 return QualType();
2682
John McCall550e0c22009-10-21 00:40:46 +00002683 QualType Result = TL.getType();
2684 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00002685 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002686 Result = getDerived().RebuildTypeOfExprType(move(E));
2687 if (Result.isNull())
2688 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002689 }
John McCall550e0c22009-10-21 00:40:46 +00002690 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002691
John McCall550e0c22009-10-21 00:40:46 +00002692 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002693 NewTL.setTypeofLoc(TL.getTypeofLoc());
2694 NewTL.setLParenLoc(TL.getLParenLoc());
2695 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00002696
2697 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002698}
Mike Stump11289f42009-09-09 15:08:12 +00002699
2700template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002701QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002702 TypeOfTypeLoc TL,
2703 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00002704 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2705 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2706 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00002707 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002708
John McCall550e0c22009-10-21 00:40:46 +00002709 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00002710 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2711 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00002712 if (Result.isNull())
2713 return QualType();
2714 }
Mike Stump11289f42009-09-09 15:08:12 +00002715
John McCall550e0c22009-10-21 00:40:46 +00002716 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002717 NewTL.setTypeofLoc(TL.getTypeofLoc());
2718 NewTL.setLParenLoc(TL.getLParenLoc());
2719 NewTL.setRParenLoc(TL.getRParenLoc());
2720 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00002721
2722 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002723}
Mike Stump11289f42009-09-09 15:08:12 +00002724
2725template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002726QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002727 DecltypeTypeLoc TL,
2728 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002729 DecltypeType *T = TL.getTypePtr();
2730
Douglas Gregore922c772009-08-04 22:27:00 +00002731 // decltype expressions are not potentially evaluated contexts
2732 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002733
Douglas Gregord6ff3322009-08-04 16:50:30 +00002734 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2735 if (E.isInvalid())
2736 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002737
John McCall550e0c22009-10-21 00:40:46 +00002738 QualType Result = TL.getType();
2739 if (getDerived().AlwaysRebuild() ||
2740 E.get() != T->getUnderlyingExpr()) {
2741 Result = getDerived().RebuildDecltypeType(move(E));
2742 if (Result.isNull())
2743 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002744 }
John McCall550e0c22009-10-21 00:40:46 +00002745 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002746
John McCall550e0c22009-10-21 00:40:46 +00002747 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2748 NewTL.setNameLoc(TL.getNameLoc());
2749
2750 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002751}
2752
2753template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002754QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002755 RecordTypeLoc TL,
2756 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002757 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002758 RecordDecl *Record
John McCall550e0c22009-10-21 00:40:46 +00002759 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002760 if (!Record)
2761 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002762
John McCall550e0c22009-10-21 00:40:46 +00002763 QualType Result = TL.getType();
2764 if (getDerived().AlwaysRebuild() ||
2765 Record != T->getDecl()) {
2766 Result = getDerived().RebuildRecordType(Record);
2767 if (Result.isNull())
2768 return QualType();
2769 }
Mike Stump11289f42009-09-09 15:08:12 +00002770
John McCall550e0c22009-10-21 00:40:46 +00002771 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2772 NewTL.setNameLoc(TL.getNameLoc());
2773
2774 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002775}
Mike Stump11289f42009-09-09 15:08:12 +00002776
2777template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002778QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002779 EnumTypeLoc TL,
2780 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002781 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002782 EnumDecl *Enum
John McCall550e0c22009-10-21 00:40:46 +00002783 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002784 if (!Enum)
2785 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002786
John McCall550e0c22009-10-21 00:40:46 +00002787 QualType Result = TL.getType();
2788 if (getDerived().AlwaysRebuild() ||
2789 Enum != T->getDecl()) {
2790 Result = getDerived().RebuildEnumType(Enum);
2791 if (Result.isNull())
2792 return QualType();
2793 }
Mike Stump11289f42009-09-09 15:08:12 +00002794
John McCall550e0c22009-10-21 00:40:46 +00002795 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2796 NewTL.setNameLoc(TL.getNameLoc());
2797
2798 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002799}
John McCallfcc33b02009-09-05 00:15:47 +00002800
2801template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002802QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002803 ElaboratedTypeLoc TL,
2804 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002805 ElaboratedType *T = TL.getTypePtr();
2806
2807 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002808 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2809 if (Underlying.isNull())
2810 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002811
John McCall550e0c22009-10-21 00:40:46 +00002812 QualType Result = TL.getType();
2813 if (getDerived().AlwaysRebuild() ||
2814 Underlying != T->getUnderlyingType()) {
2815 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2816 if (Result.isNull())
2817 return QualType();
2818 }
Mike Stump11289f42009-09-09 15:08:12 +00002819
John McCall550e0c22009-10-21 00:40:46 +00002820 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2821 NewTL.setNameLoc(TL.getNameLoc());
2822
2823 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002824}
Mike Stump11289f42009-09-09 15:08:12 +00002825
2826
Douglas Gregord6ff3322009-08-04 16:50:30 +00002827template<typename Derived>
2828QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002829 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002830 TemplateTypeParmTypeLoc TL,
2831 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002832 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002833}
2834
Mike Stump11289f42009-09-09 15:08:12 +00002835template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002836QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002837 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002838 SubstTemplateTypeParmTypeLoc TL,
2839 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002840 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002841}
2842
2843template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002844QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2845 const TemplateSpecializationType *TST,
2846 QualType ObjectType) {
2847 // FIXME: this entire method is a temporary workaround; callers
2848 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00002849
John McCall0ad16662009-10-29 08:12:44 +00002850 // Fake up a TemplateSpecializationTypeLoc.
2851 TypeLocBuilder TLB;
2852 TemplateSpecializationTypeLoc TL
2853 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2854
John McCall0d07eb32009-10-29 18:45:58 +00002855 SourceLocation BaseLoc = getDerived().getBaseLocation();
2856
2857 TL.setTemplateNameLoc(BaseLoc);
2858 TL.setLAngleLoc(BaseLoc);
2859 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00002860 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2861 const TemplateArgument &TA = TST->getArg(i);
2862 TemplateArgumentLoc TAL;
2863 getDerived().InventTemplateArgumentLoc(TA, TAL);
2864 TL.setArgLocInfo(i, TAL.getLocInfo());
2865 }
2866
2867 TypeLocBuilder IgnoredTLB;
2868 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00002869}
2870
2871template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002872QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00002873 TypeLocBuilder &TLB,
2874 TemplateSpecializationTypeLoc TL,
2875 QualType ObjectType) {
2876 const TemplateSpecializationType *T = TL.getTypePtr();
2877
Mike Stump11289f42009-09-09 15:08:12 +00002878 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002879 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002880 if (Template.isNull())
2881 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002882
John McCall6b51f282009-11-23 01:53:49 +00002883 TemplateArgumentListInfo NewTemplateArgs;
2884 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2885 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2886
2887 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2888 TemplateArgumentLoc Loc;
2889 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00002890 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00002891 NewTemplateArgs.addArgument(Loc);
2892 }
Mike Stump11289f42009-09-09 15:08:12 +00002893
John McCall0ad16662009-10-29 08:12:44 +00002894 // FIXME: maybe don't rebuild if all the template arguments are the same.
2895
2896 QualType Result =
2897 getDerived().RebuildTemplateSpecializationType(Template,
2898 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00002899 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00002900
2901 if (!Result.isNull()) {
2902 TemplateSpecializationTypeLoc NewTL
2903 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2904 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2905 NewTL.setLAngleLoc(TL.getLAngleLoc());
2906 NewTL.setRAngleLoc(TL.getRAngleLoc());
2907 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2908 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002909 }
Mike Stump11289f42009-09-09 15:08:12 +00002910
John McCall0ad16662009-10-29 08:12:44 +00002911 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002912}
Mike Stump11289f42009-09-09 15:08:12 +00002913
2914template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002915QualType
2916TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002917 QualifiedNameTypeLoc TL,
2918 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002919 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002920 NestedNameSpecifier *NNS
2921 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002922 SourceRange(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00002923 false,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002924 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002925 if (!NNS)
2926 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002927
Douglas Gregord6ff3322009-08-04 16:50:30 +00002928 QualType Named = getDerived().TransformType(T->getNamedType());
2929 if (Named.isNull())
2930 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002931
John McCall550e0c22009-10-21 00:40:46 +00002932 QualType Result = TL.getType();
2933 if (getDerived().AlwaysRebuild() ||
2934 NNS != T->getQualifier() ||
2935 Named != T->getNamedType()) {
2936 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2937 if (Result.isNull())
2938 return QualType();
2939 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002940
John McCall550e0c22009-10-21 00:40:46 +00002941 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2942 NewTL.setNameLoc(TL.getNameLoc());
2943
2944 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002945}
Mike Stump11289f42009-09-09 15:08:12 +00002946
2947template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002948QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002949 TypenameTypeLoc TL,
2950 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002951 TypenameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00002952
2953 /* FIXME: preserve source information better than this */
2954 SourceRange SR(TL.getNameLoc());
2955
Douglas Gregord6ff3322009-08-04 16:50:30 +00002956 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00002957 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregor90d554e2010-02-21 18:36:56 +00002958 false, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002959 if (!NNS)
2960 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002961
John McCall550e0c22009-10-21 00:40:46 +00002962 QualType Result;
2963
Douglas Gregord6ff3322009-08-04 16:50:30 +00002964 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002965 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002966 = getDerived().TransformType(QualType(TemplateId, 0));
2967 if (NewTemplateId.isNull())
2968 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002969
Douglas Gregord6ff3322009-08-04 16:50:30 +00002970 if (!getDerived().AlwaysRebuild() &&
2971 NNS == T->getQualifier() &&
2972 NewTemplateId == QualType(TemplateId, 0))
2973 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002974
John McCall550e0c22009-10-21 00:40:46 +00002975 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2976 } else {
John McCall0ad16662009-10-29 08:12:44 +00002977 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002978 }
John McCall550e0c22009-10-21 00:40:46 +00002979 if (Result.isNull())
2980 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002981
John McCall550e0c22009-10-21 00:40:46 +00002982 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2983 NewTL.setNameLoc(TL.getNameLoc());
2984
2985 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002986}
Mike Stump11289f42009-09-09 15:08:12 +00002987
Douglas Gregord6ff3322009-08-04 16:50:30 +00002988template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002989QualType
2990TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002991 ObjCInterfaceTypeLoc TL,
2992 QualType ObjectType) {
John McCallfc93cf92009-10-22 22:37:11 +00002993 assert(false && "TransformObjCInterfaceType unimplemented");
2994 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002995}
Mike Stump11289f42009-09-09 15:08:12 +00002996
2997template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002998QualType
2999TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003000 ObjCObjectPointerTypeLoc TL,
3001 QualType ObjectType) {
John McCallfc93cf92009-10-22 22:37:11 +00003002 assert(false && "TransformObjCObjectPointerType unimplemented");
3003 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003004}
3005
Douglas Gregord6ff3322009-08-04 16:50:30 +00003006//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003007// Statement transformation
3008//===----------------------------------------------------------------------===//
3009template<typename Derived>
3010Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003011TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3012 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003013}
3014
3015template<typename Derived>
3016Sema::OwningStmtResult
3017TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3018 return getDerived().TransformCompoundStmt(S, false);
3019}
3020
3021template<typename Derived>
3022Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003023TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003024 bool IsStmtExpr) {
3025 bool SubStmtChanged = false;
3026 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3027 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3028 B != BEnd; ++B) {
3029 OwningStmtResult Result = getDerived().TransformStmt(*B);
3030 if (Result.isInvalid())
3031 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003032
Douglas Gregorebe10102009-08-20 07:17:43 +00003033 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3034 Statements.push_back(Result.takeAs<Stmt>());
3035 }
Mike Stump11289f42009-09-09 15:08:12 +00003036
Douglas Gregorebe10102009-08-20 07:17:43 +00003037 if (!getDerived().AlwaysRebuild() &&
3038 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003039 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003040
3041 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3042 move_arg(Statements),
3043 S->getRBracLoc(),
3044 IsStmtExpr);
3045}
Mike Stump11289f42009-09-09 15:08:12 +00003046
Douglas Gregorebe10102009-08-20 07:17:43 +00003047template<typename Derived>
3048Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003049TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003050 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3051 {
3052 // The case value expressions are not potentially evaluated.
3053 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003054
Eli Friedman06577382009-11-19 03:14:00 +00003055 // Transform the left-hand case value.
3056 LHS = getDerived().TransformExpr(S->getLHS());
3057 if (LHS.isInvalid())
3058 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003059
Eli Friedman06577382009-11-19 03:14:00 +00003060 // Transform the right-hand case value (for the GNU case-range extension).
3061 RHS = getDerived().TransformExpr(S->getRHS());
3062 if (RHS.isInvalid())
3063 return SemaRef.StmtError();
3064 }
Mike Stump11289f42009-09-09 15:08:12 +00003065
Douglas Gregorebe10102009-08-20 07:17:43 +00003066 // Build the case statement.
3067 // Case statements are always rebuilt so that they will attached to their
3068 // transformed switch statement.
3069 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3070 move(LHS),
3071 S->getEllipsisLoc(),
3072 move(RHS),
3073 S->getColonLoc());
3074 if (Case.isInvalid())
3075 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003076
Douglas Gregorebe10102009-08-20 07:17:43 +00003077 // Transform the statement following the case
3078 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3079 if (SubStmt.isInvalid())
3080 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003081
Douglas Gregorebe10102009-08-20 07:17:43 +00003082 // Attach the body to the case statement
3083 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3084}
3085
3086template<typename Derived>
3087Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003088TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003089 // Transform the statement following the default case
3090 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3091 if (SubStmt.isInvalid())
3092 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003093
Douglas Gregorebe10102009-08-20 07:17:43 +00003094 // Default statements are always rebuilt
3095 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3096 move(SubStmt));
3097}
Mike Stump11289f42009-09-09 15:08:12 +00003098
Douglas Gregorebe10102009-08-20 07:17:43 +00003099template<typename Derived>
3100Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003101TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003102 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3103 if (SubStmt.isInvalid())
3104 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003105
Douglas Gregorebe10102009-08-20 07:17:43 +00003106 // FIXME: Pass the real colon location in.
3107 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3108 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3109 move(SubStmt));
3110}
Mike Stump11289f42009-09-09 15:08:12 +00003111
Douglas Gregorebe10102009-08-20 07:17:43 +00003112template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003113Sema::OwningStmtResult
3114TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003115 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003116 OwningExprResult Cond(SemaRef);
3117 VarDecl *ConditionVar = 0;
3118 if (S->getConditionVariable()) {
3119 ConditionVar
3120 = cast_or_null<VarDecl>(
3121 getDerived().TransformDefinition(S->getConditionVariable()));
3122 if (!ConditionVar)
3123 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003124 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003125 Cond = getDerived().TransformExpr(S->getCond());
3126
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003127 if (Cond.isInvalid())
3128 return SemaRef.StmtError();
3129 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003130
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003131 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003132
Douglas Gregorebe10102009-08-20 07:17:43 +00003133 // Transform the "then" branch.
3134 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3135 if (Then.isInvalid())
3136 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003137
Douglas Gregorebe10102009-08-20 07:17:43 +00003138 // Transform the "else" branch.
3139 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3140 if (Else.isInvalid())
3141 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003142
Douglas Gregorebe10102009-08-20 07:17:43 +00003143 if (!getDerived().AlwaysRebuild() &&
3144 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003145 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003146 Then.get() == S->getThen() &&
3147 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003148 return SemaRef.Owned(S->Retain());
3149
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003150 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3151 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003152 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003153}
3154
3155template<typename Derived>
3156Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003157TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003158 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003159 OwningExprResult Cond(SemaRef);
3160 VarDecl *ConditionVar = 0;
3161 if (S->getConditionVariable()) {
3162 ConditionVar
3163 = cast_or_null<VarDecl>(
3164 getDerived().TransformDefinition(S->getConditionVariable()));
3165 if (!ConditionVar)
3166 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003167 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003168 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003169
3170 if (Cond.isInvalid())
3171 return SemaRef.StmtError();
3172 }
Mike Stump11289f42009-09-09 15:08:12 +00003173
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003174 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003175
Douglas Gregorebe10102009-08-20 07:17:43 +00003176 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003177 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3178 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003179 if (Switch.isInvalid())
3180 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003181
Douglas Gregorebe10102009-08-20 07:17:43 +00003182 // Transform the body of the switch statement.
3183 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3184 if (Body.isInvalid())
3185 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003186
Douglas Gregorebe10102009-08-20 07:17:43 +00003187 // Complete the switch statement.
3188 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3189 move(Body));
3190}
Mike Stump11289f42009-09-09 15:08:12 +00003191
Douglas Gregorebe10102009-08-20 07:17:43 +00003192template<typename Derived>
3193Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003194TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003195 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003196 OwningExprResult Cond(SemaRef);
3197 VarDecl *ConditionVar = 0;
3198 if (S->getConditionVariable()) {
3199 ConditionVar
3200 = cast_or_null<VarDecl>(
3201 getDerived().TransformDefinition(S->getConditionVariable()));
3202 if (!ConditionVar)
3203 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003204 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003205 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003206
3207 if (Cond.isInvalid())
3208 return SemaRef.StmtError();
3209 }
Mike Stump11289f42009-09-09 15:08:12 +00003210
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003211 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003212
Douglas Gregorebe10102009-08-20 07:17:43 +00003213 // Transform the body
3214 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3215 if (Body.isInvalid())
3216 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003217
Douglas Gregorebe10102009-08-20 07:17:43 +00003218 if (!getDerived().AlwaysRebuild() &&
3219 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003220 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003221 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003222 return SemaRef.Owned(S->Retain());
3223
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003224 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3225 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003226}
Mike Stump11289f42009-09-09 15:08:12 +00003227
Douglas Gregorebe10102009-08-20 07:17:43 +00003228template<typename Derived>
3229Sema::OwningStmtResult
3230TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3231 // Transform the condition
3232 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3233 if (Cond.isInvalid())
3234 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003235
Douglas Gregorebe10102009-08-20 07:17:43 +00003236 // Transform the body
3237 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3238 if (Body.isInvalid())
3239 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003240
Douglas Gregorebe10102009-08-20 07:17:43 +00003241 if (!getDerived().AlwaysRebuild() &&
3242 Cond.get() == S->getCond() &&
3243 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003244 return SemaRef.Owned(S->Retain());
3245
Douglas Gregorebe10102009-08-20 07:17:43 +00003246 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3247 /*FIXME:*/S->getWhileLoc(), move(Cond),
3248 S->getRParenLoc());
3249}
Mike Stump11289f42009-09-09 15:08:12 +00003250
Douglas Gregorebe10102009-08-20 07:17:43 +00003251template<typename Derived>
3252Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003253TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003254 // Transform the initialization statement
3255 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3256 if (Init.isInvalid())
3257 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003258
Douglas Gregorebe10102009-08-20 07:17:43 +00003259 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003260 OwningExprResult Cond(SemaRef);
3261 VarDecl *ConditionVar = 0;
3262 if (S->getConditionVariable()) {
3263 ConditionVar
3264 = cast_or_null<VarDecl>(
3265 getDerived().TransformDefinition(S->getConditionVariable()));
3266 if (!ConditionVar)
3267 return SemaRef.StmtError();
3268 } else {
3269 Cond = getDerived().TransformExpr(S->getCond());
3270
3271 if (Cond.isInvalid())
3272 return SemaRef.StmtError();
3273 }
Mike Stump11289f42009-09-09 15:08:12 +00003274
Douglas Gregorebe10102009-08-20 07:17:43 +00003275 // Transform the increment
3276 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3277 if (Inc.isInvalid())
3278 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003279
Douglas Gregorebe10102009-08-20 07:17:43 +00003280 // Transform the body
3281 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3282 if (Body.isInvalid())
3283 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003284
Douglas Gregorebe10102009-08-20 07:17:43 +00003285 if (!getDerived().AlwaysRebuild() &&
3286 Init.get() == S->getInit() &&
3287 Cond.get() == S->getCond() &&
3288 Inc.get() == S->getInc() &&
3289 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003290 return SemaRef.Owned(S->Retain());
3291
Douglas Gregorebe10102009-08-20 07:17:43 +00003292 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003293 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003294 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003295 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003296 S->getRParenLoc(), move(Body));
3297}
3298
3299template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003300Sema::OwningStmtResult
3301TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003302 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003303 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003304 S->getLabel());
3305}
3306
3307template<typename Derived>
3308Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003309TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003310 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3311 if (Target.isInvalid())
3312 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003313
Douglas Gregorebe10102009-08-20 07:17:43 +00003314 if (!getDerived().AlwaysRebuild() &&
3315 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003316 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003317
3318 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3319 move(Target));
3320}
3321
3322template<typename Derived>
3323Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003324TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3325 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003326}
Mike Stump11289f42009-09-09 15:08:12 +00003327
Douglas Gregorebe10102009-08-20 07:17:43 +00003328template<typename Derived>
3329Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003330TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3331 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003332}
Mike Stump11289f42009-09-09 15:08:12 +00003333
Douglas Gregorebe10102009-08-20 07:17:43 +00003334template<typename Derived>
3335Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003336TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003337 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3338 if (Result.isInvalid())
3339 return SemaRef.StmtError();
3340
Mike Stump11289f42009-09-09 15:08:12 +00003341 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003342 // to tell whether the return type of the function has changed.
3343 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3344}
Mike Stump11289f42009-09-09 15:08:12 +00003345
Douglas Gregorebe10102009-08-20 07:17:43 +00003346template<typename Derived>
3347Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003348TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003349 bool DeclChanged = false;
3350 llvm::SmallVector<Decl *, 4> Decls;
3351 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3352 D != DEnd; ++D) {
3353 Decl *Transformed = getDerived().TransformDefinition(*D);
3354 if (!Transformed)
3355 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003356
Douglas Gregorebe10102009-08-20 07:17:43 +00003357 if (Transformed != *D)
3358 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003359
Douglas Gregorebe10102009-08-20 07:17:43 +00003360 Decls.push_back(Transformed);
3361 }
Mike Stump11289f42009-09-09 15:08:12 +00003362
Douglas Gregorebe10102009-08-20 07:17:43 +00003363 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003364 return SemaRef.Owned(S->Retain());
3365
3366 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003367 S->getStartLoc(), S->getEndLoc());
3368}
Mike Stump11289f42009-09-09 15:08:12 +00003369
Douglas Gregorebe10102009-08-20 07:17:43 +00003370template<typename Derived>
3371Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003372TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003373 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003374 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003375}
3376
3377template<typename Derived>
3378Sema::OwningStmtResult
3379TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003380
3381 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3382 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003383 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003384
Anders Carlssonaaeef072010-01-24 05:50:09 +00003385 OwningExprResult AsmString(SemaRef);
3386 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3387
3388 bool ExprsChanged = false;
3389
3390 // Go through the outputs.
3391 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003392 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003393
Anders Carlssonaaeef072010-01-24 05:50:09 +00003394 // No need to transform the constraint literal.
3395 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3396
3397 // Transform the output expr.
3398 Expr *OutputExpr = S->getOutputExpr(I);
3399 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3400 if (Result.isInvalid())
3401 return SemaRef.StmtError();
3402
3403 ExprsChanged |= Result.get() != OutputExpr;
3404
3405 Exprs.push_back(Result.takeAs<Expr>());
3406 }
3407
3408 // Go through the inputs.
3409 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003410 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003411
Anders Carlssonaaeef072010-01-24 05:50:09 +00003412 // No need to transform the constraint literal.
3413 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3414
3415 // Transform the input expr.
3416 Expr *InputExpr = S->getInputExpr(I);
3417 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3418 if (Result.isInvalid())
3419 return SemaRef.StmtError();
3420
3421 ExprsChanged |= Result.get() != InputExpr;
3422
3423 Exprs.push_back(Result.takeAs<Expr>());
3424 }
3425
3426 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3427 return SemaRef.Owned(S->Retain());
3428
3429 // Go through the clobbers.
3430 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3431 Clobbers.push_back(S->getClobber(I)->Retain());
3432
3433 // No need to transform the asm string literal.
3434 AsmString = SemaRef.Owned(S->getAsmString());
3435
3436 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3437 S->isSimple(),
3438 S->isVolatile(),
3439 S->getNumOutputs(),
3440 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003441 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003442 move_arg(Constraints),
3443 move_arg(Exprs),
3444 move(AsmString),
3445 move_arg(Clobbers),
3446 S->getRParenLoc(),
3447 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003448}
3449
3450
3451template<typename Derived>
3452Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003453TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003454 // FIXME: Implement this
3455 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003456 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003457}
Mike Stump11289f42009-09-09 15:08:12 +00003458
Douglas Gregorebe10102009-08-20 07:17:43 +00003459template<typename Derived>
3460Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003461TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003462 // FIXME: Implement this
3463 assert(false && "Cannot transform an Objective-C @catch statement");
3464 return SemaRef.Owned(S->Retain());
3465}
Mike Stump11289f42009-09-09 15:08:12 +00003466
Douglas Gregorebe10102009-08-20 07:17:43 +00003467template<typename Derived>
3468Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003469TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003470 // FIXME: Implement this
3471 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003472 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003473}
Mike Stump11289f42009-09-09 15:08:12 +00003474
Douglas Gregorebe10102009-08-20 07:17:43 +00003475template<typename Derived>
3476Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003477TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003478 // FIXME: Implement this
3479 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003480 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003481}
Mike Stump11289f42009-09-09 15:08:12 +00003482
Douglas Gregorebe10102009-08-20 07:17:43 +00003483template<typename Derived>
3484Sema::OwningStmtResult
3485TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003486 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003487 // FIXME: Implement this
3488 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003489 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003490}
3491
3492template<typename Derived>
3493Sema::OwningStmtResult
3494TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003495 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003496 // FIXME: Implement this
3497 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003498 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003499}
3500
3501
3502template<typename Derived>
3503Sema::OwningStmtResult
3504TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3505 // Transform the exception declaration, if any.
3506 VarDecl *Var = 0;
3507 if (S->getExceptionDecl()) {
3508 VarDecl *ExceptionDecl = S->getExceptionDecl();
3509 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3510 ExceptionDecl->getDeclName());
3511
3512 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3513 if (T.isNull())
3514 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003515
Douglas Gregorebe10102009-08-20 07:17:43 +00003516 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3517 T,
John McCallbcd03502009-12-07 02:54:59 +00003518 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003519 ExceptionDecl->getIdentifier(),
3520 ExceptionDecl->getLocation(),
3521 /*FIXME: Inaccurate*/
3522 SourceRange(ExceptionDecl->getLocation()));
3523 if (!Var || Var->isInvalidDecl()) {
3524 if (Var)
3525 Var->Destroy(SemaRef.Context);
3526 return SemaRef.StmtError();
3527 }
3528 }
Mike Stump11289f42009-09-09 15:08:12 +00003529
Douglas Gregorebe10102009-08-20 07:17:43 +00003530 // Transform the actual exception handler.
3531 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3532 if (Handler.isInvalid()) {
3533 if (Var)
3534 Var->Destroy(SemaRef.Context);
3535 return SemaRef.StmtError();
3536 }
Mike Stump11289f42009-09-09 15:08:12 +00003537
Douglas Gregorebe10102009-08-20 07:17:43 +00003538 if (!getDerived().AlwaysRebuild() &&
3539 !Var &&
3540 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003541 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003542
3543 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3544 Var,
3545 move(Handler));
3546}
Mike Stump11289f42009-09-09 15:08:12 +00003547
Douglas Gregorebe10102009-08-20 07:17:43 +00003548template<typename Derived>
3549Sema::OwningStmtResult
3550TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3551 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003552 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003553 = getDerived().TransformCompoundStmt(S->getTryBlock());
3554 if (TryBlock.isInvalid())
3555 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003556
Douglas Gregorebe10102009-08-20 07:17:43 +00003557 // Transform the handlers.
3558 bool HandlerChanged = false;
3559 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3560 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003561 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003562 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3563 if (Handler.isInvalid())
3564 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003565
Douglas Gregorebe10102009-08-20 07:17:43 +00003566 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3567 Handlers.push_back(Handler.takeAs<Stmt>());
3568 }
Mike Stump11289f42009-09-09 15:08:12 +00003569
Douglas Gregorebe10102009-08-20 07:17:43 +00003570 if (!getDerived().AlwaysRebuild() &&
3571 TryBlock.get() == S->getTryBlock() &&
3572 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003573 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003574
3575 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003576 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003577}
Mike Stump11289f42009-09-09 15:08:12 +00003578
Douglas Gregorebe10102009-08-20 07:17:43 +00003579//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003580// Expression transformation
3581//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003582template<typename Derived>
3583Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003584TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003585 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003586}
Mike Stump11289f42009-09-09 15:08:12 +00003587
3588template<typename Derived>
3589Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003590TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003591 NestedNameSpecifier *Qualifier = 0;
3592 if (E->getQualifier()) {
3593 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00003594 E->getQualifierRange(),
3595 false);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003596 if (!Qualifier)
3597 return SemaRef.ExprError();
3598 }
John McCallce546572009-12-08 09:08:17 +00003599
3600 ValueDecl *ND
3601 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003602 if (!ND)
3603 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003604
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003605 if (!getDerived().AlwaysRebuild() &&
3606 Qualifier == E->getQualifier() &&
3607 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003608 !E->hasExplicitTemplateArgumentList()) {
3609
3610 // Mark it referenced in the new context regardless.
3611 // FIXME: this is a bit instantiation-specific.
3612 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3613
Mike Stump11289f42009-09-09 15:08:12 +00003614 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003615 }
John McCallce546572009-12-08 09:08:17 +00003616
3617 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3618 if (E->hasExplicitTemplateArgumentList()) {
3619 TemplateArgs = &TransArgs;
3620 TransArgs.setLAngleLoc(E->getLAngleLoc());
3621 TransArgs.setRAngleLoc(E->getRAngleLoc());
3622 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3623 TemplateArgumentLoc Loc;
3624 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3625 return SemaRef.ExprError();
3626 TransArgs.addArgument(Loc);
3627 }
3628 }
3629
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003630 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003631 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003632}
Mike Stump11289f42009-09-09 15:08:12 +00003633
Douglas Gregora16548e2009-08-11 05:31:07 +00003634template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003635Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003636TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003637 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003638}
Mike Stump11289f42009-09-09 15:08:12 +00003639
Douglas Gregora16548e2009-08-11 05:31:07 +00003640template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003641Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003642TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *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
Douglas Gregora16548e2009-08-11 05:31:07 +00003646template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003647Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003648TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003649 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003650}
Mike Stump11289f42009-09-09 15:08:12 +00003651
Douglas Gregora16548e2009-08-11 05:31:07 +00003652template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003653Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003654TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003655 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003656}
Mike Stump11289f42009-09-09 15:08:12 +00003657
Douglas Gregora16548e2009-08-11 05:31:07 +00003658template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003659Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003660TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003661 return SemaRef.Owned(E->Retain());
3662}
3663
3664template<typename Derived>
3665Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003666TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003667 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3668 if (SubExpr.isInvalid())
3669 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003670
Douglas Gregora16548e2009-08-11 05:31:07 +00003671 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003672 return SemaRef.Owned(E->Retain());
3673
3674 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003675 E->getRParen());
3676}
3677
Mike Stump11289f42009-09-09 15:08:12 +00003678template<typename Derived>
3679Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003680TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3681 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003682 if (SubExpr.isInvalid())
3683 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003684
Douglas Gregora16548e2009-08-11 05:31:07 +00003685 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003686 return SemaRef.Owned(E->Retain());
3687
Douglas Gregora16548e2009-08-11 05:31:07 +00003688 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3689 E->getOpcode(),
3690 move(SubExpr));
3691}
Mike Stump11289f42009-09-09 15:08:12 +00003692
Douglas Gregora16548e2009-08-11 05:31:07 +00003693template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003694Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003695TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003696 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003697 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003698
John McCallbcd03502009-12-07 02:54:59 +00003699 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003700 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003701 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003702
John McCall4c98fd82009-11-04 07:28:41 +00003703 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003704 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003705
John McCall4c98fd82009-11-04 07:28:41 +00003706 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003707 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003708 E->getSourceRange());
3709 }
Mike Stump11289f42009-09-09 15:08:12 +00003710
Douglas Gregora16548e2009-08-11 05:31:07 +00003711 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003712 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003713 // C++0x [expr.sizeof]p1:
3714 // The operand is either an expression, which is an unevaluated operand
3715 // [...]
3716 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003717
Douglas Gregora16548e2009-08-11 05:31:07 +00003718 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3719 if (SubExpr.isInvalid())
3720 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003721
Douglas Gregora16548e2009-08-11 05:31:07 +00003722 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3723 return SemaRef.Owned(E->Retain());
3724 }
Mike Stump11289f42009-09-09 15:08:12 +00003725
Douglas Gregora16548e2009-08-11 05:31:07 +00003726 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3727 E->isSizeOf(),
3728 E->getSourceRange());
3729}
Mike Stump11289f42009-09-09 15:08:12 +00003730
Douglas Gregora16548e2009-08-11 05:31:07 +00003731template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003732Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003733TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003734 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3735 if (LHS.isInvalid())
3736 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003737
Douglas Gregora16548e2009-08-11 05:31:07 +00003738 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3739 if (RHS.isInvalid())
3740 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003741
3742
Douglas Gregora16548e2009-08-11 05:31:07 +00003743 if (!getDerived().AlwaysRebuild() &&
3744 LHS.get() == E->getLHS() &&
3745 RHS.get() == E->getRHS())
3746 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003747
Douglas Gregora16548e2009-08-11 05:31:07 +00003748 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3749 /*FIXME:*/E->getLHS()->getLocStart(),
3750 move(RHS),
3751 E->getRBracketLoc());
3752}
Mike Stump11289f42009-09-09 15:08:12 +00003753
3754template<typename Derived>
3755Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003756TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003757 // Transform the callee.
3758 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3759 if (Callee.isInvalid())
3760 return SemaRef.ExprError();
3761
3762 // Transform arguments.
3763 bool ArgChanged = false;
3764 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3765 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3766 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3767 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3768 if (Arg.isInvalid())
3769 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003770
Douglas Gregora16548e2009-08-11 05:31:07 +00003771 // FIXME: Wrong source location information for the ','.
3772 FakeCommaLocs.push_back(
3773 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003774
3775 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003776 Args.push_back(Arg.takeAs<Expr>());
3777 }
Mike Stump11289f42009-09-09 15:08:12 +00003778
Douglas Gregora16548e2009-08-11 05:31:07 +00003779 if (!getDerived().AlwaysRebuild() &&
3780 Callee.get() == E->getCallee() &&
3781 !ArgChanged)
3782 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003783
Douglas Gregora16548e2009-08-11 05:31:07 +00003784 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003785 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003786 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3787 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3788 move_arg(Args),
3789 FakeCommaLocs.data(),
3790 E->getRParenLoc());
3791}
Mike Stump11289f42009-09-09 15:08:12 +00003792
3793template<typename Derived>
3794Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003795TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003796 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3797 if (Base.isInvalid())
3798 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003799
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003800 NestedNameSpecifier *Qualifier = 0;
3801 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003802 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003803 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00003804 E->getQualifierRange(),
3805 false);
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003806 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003807 return SemaRef.ExprError();
3808 }
Mike Stump11289f42009-09-09 15:08:12 +00003809
Eli Friedman2cfcef62009-12-04 06:40:45 +00003810 ValueDecl *Member
3811 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003812 if (!Member)
3813 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003814
Douglas Gregora16548e2009-08-11 05:31:07 +00003815 if (!getDerived().AlwaysRebuild() &&
3816 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003817 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003818 Member == E->getMemberDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003819 !E->hasExplicitTemplateArgumentList()) {
3820
3821 // Mark it referenced in the new context regardless.
3822 // FIXME: this is a bit instantiation-specific.
3823 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00003824 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003825 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003826
John McCall6b51f282009-11-23 01:53:49 +00003827 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003828 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003829 TransArgs.setLAngleLoc(E->getLAngleLoc());
3830 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003831 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003832 TemplateArgumentLoc Loc;
3833 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003834 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003835 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003836 }
3837 }
3838
Douglas Gregora16548e2009-08-11 05:31:07 +00003839 // FIXME: Bogus source location for the operator
3840 SourceLocation FakeOperatorLoc
3841 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3842
John McCall38836f02010-01-15 08:34:02 +00003843 // FIXME: to do this check properly, we will need to preserve the
3844 // first-qualifier-in-scope here, just in case we had a dependent
3845 // base (and therefore couldn't do the check) and a
3846 // nested-name-qualifier (and therefore could do the lookup).
3847 NamedDecl *FirstQualifierInScope = 0;
3848
Douglas Gregora16548e2009-08-11 05:31:07 +00003849 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3850 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003851 Qualifier,
3852 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003853 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003854 Member,
John McCall6b51f282009-11-23 01:53:49 +00003855 (E->hasExplicitTemplateArgumentList()
3856 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00003857 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00003858}
Mike Stump11289f42009-09-09 15:08:12 +00003859
Douglas Gregora16548e2009-08-11 05:31:07 +00003860template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003861Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003862TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003863 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3864 if (LHS.isInvalid())
3865 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003866
Douglas Gregora16548e2009-08-11 05:31:07 +00003867 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3868 if (RHS.isInvalid())
3869 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003870
Douglas Gregora16548e2009-08-11 05:31:07 +00003871 if (!getDerived().AlwaysRebuild() &&
3872 LHS.get() == E->getLHS() &&
3873 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003874 return SemaRef.Owned(E->Retain());
3875
Douglas Gregora16548e2009-08-11 05:31:07 +00003876 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3877 move(LHS), move(RHS));
3878}
3879
Mike Stump11289f42009-09-09 15:08:12 +00003880template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003881Sema::OwningExprResult
3882TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00003883 CompoundAssignOperator *E) {
3884 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00003885}
Mike Stump11289f42009-09-09 15:08:12 +00003886
Douglas Gregora16548e2009-08-11 05:31:07 +00003887template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003888Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003889TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003890 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3891 if (Cond.isInvalid())
3892 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003893
Douglas Gregora16548e2009-08-11 05:31:07 +00003894 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3895 if (LHS.isInvalid())
3896 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003897
Douglas Gregora16548e2009-08-11 05:31:07 +00003898 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3899 if (RHS.isInvalid())
3900 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003901
Douglas Gregora16548e2009-08-11 05:31:07 +00003902 if (!getDerived().AlwaysRebuild() &&
3903 Cond.get() == E->getCond() &&
3904 LHS.get() == E->getLHS() &&
3905 RHS.get() == E->getRHS())
3906 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003907
3908 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003909 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003910 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003911 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003912 move(RHS));
3913}
Mike Stump11289f42009-09-09 15:08:12 +00003914
3915template<typename Derived>
3916Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003917TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00003918 // Implicit casts are eliminated during transformation, since they
3919 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00003920 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003921}
Mike Stump11289f42009-09-09 15:08:12 +00003922
Douglas Gregora16548e2009-08-11 05:31:07 +00003923template<typename Derived>
3924Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003925TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00003926 TypeSourceInfo *OldT;
3927 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00003928 {
3929 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003930 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003931 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3932 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003933
John McCall97513962010-01-15 18:39:57 +00003934 OldT = E->getTypeInfoAsWritten();
3935 NewT = getDerived().TransformType(OldT);
3936 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003937 return SemaRef.ExprError();
3938 }
Mike Stump11289f42009-09-09 15:08:12 +00003939
Douglas Gregor6131b442009-12-12 18:16:41 +00003940 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00003941 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003942 if (SubExpr.isInvalid())
3943 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003944
Douglas Gregora16548e2009-08-11 05:31:07 +00003945 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00003946 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003947 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003948 return SemaRef.Owned(E->Retain());
3949
John McCall97513962010-01-15 18:39:57 +00003950 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
3951 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00003952 E->getRParenLoc(),
3953 move(SubExpr));
3954}
Mike Stump11289f42009-09-09 15:08:12 +00003955
Douglas Gregora16548e2009-08-11 05:31:07 +00003956template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003957Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003958TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00003959 TypeSourceInfo *OldT = E->getTypeSourceInfo();
3960 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
3961 if (!NewT)
3962 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003963
Douglas Gregora16548e2009-08-11 05:31:07 +00003964 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3965 if (Init.isInvalid())
3966 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003967
Douglas Gregora16548e2009-08-11 05:31:07 +00003968 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00003969 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003970 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003971 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003972
John McCall5d7aa7f2010-01-19 22:33:45 +00003973 // Note: the expression type doesn't necessarily match the
3974 // type-as-written, but that's okay, because it should always be
3975 // derivable from the initializer.
3976
John McCalle15bbff2010-01-18 19:35:47 +00003977 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00003978 /*FIXME:*/E->getInitializer()->getLocEnd(),
3979 move(Init));
3980}
Mike Stump11289f42009-09-09 15:08:12 +00003981
Douglas Gregora16548e2009-08-11 05:31:07 +00003982template<typename Derived>
3983Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003984TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003985 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3986 if (Base.isInvalid())
3987 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003988
Douglas Gregora16548e2009-08-11 05:31:07 +00003989 if (!getDerived().AlwaysRebuild() &&
3990 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003991 return SemaRef.Owned(E->Retain());
3992
Douglas Gregora16548e2009-08-11 05:31:07 +00003993 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003994 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003995 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3996 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3997 E->getAccessorLoc(),
3998 E->getAccessor());
3999}
Mike Stump11289f42009-09-09 15:08:12 +00004000
Douglas Gregora16548e2009-08-11 05:31:07 +00004001template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004002Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004003TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004004 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004005
Douglas Gregora16548e2009-08-11 05:31:07 +00004006 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4007 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4008 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4009 if (Init.isInvalid())
4010 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004011
Douglas Gregora16548e2009-08-11 05:31:07 +00004012 InitChanged = InitChanged || Init.get() != E->getInit(I);
4013 Inits.push_back(Init.takeAs<Expr>());
4014 }
Mike Stump11289f42009-09-09 15:08:12 +00004015
Douglas Gregora16548e2009-08-11 05:31:07 +00004016 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004017 return SemaRef.Owned(E->Retain());
4018
Douglas Gregora16548e2009-08-11 05:31:07 +00004019 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004020 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004021}
Mike Stump11289f42009-09-09 15:08:12 +00004022
Douglas Gregora16548e2009-08-11 05:31:07 +00004023template<typename Derived>
4024Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004025TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004026 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004027
Douglas Gregorebe10102009-08-20 07:17:43 +00004028 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004029 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4030 if (Init.isInvalid())
4031 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004032
Douglas Gregorebe10102009-08-20 07:17:43 +00004033 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004034 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4035 bool ExprChanged = false;
4036 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4037 DEnd = E->designators_end();
4038 D != DEnd; ++D) {
4039 if (D->isFieldDesignator()) {
4040 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4041 D->getDotLoc(),
4042 D->getFieldLoc()));
4043 continue;
4044 }
Mike Stump11289f42009-09-09 15:08:12 +00004045
Douglas Gregora16548e2009-08-11 05:31:07 +00004046 if (D->isArrayDesignator()) {
4047 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4048 if (Index.isInvalid())
4049 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004050
4051 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004052 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004053
Douglas Gregora16548e2009-08-11 05:31:07 +00004054 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4055 ArrayExprs.push_back(Index.release());
4056 continue;
4057 }
Mike Stump11289f42009-09-09 15:08:12 +00004058
Douglas Gregora16548e2009-08-11 05:31:07 +00004059 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004060 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004061 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4062 if (Start.isInvalid())
4063 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004064
Douglas Gregora16548e2009-08-11 05:31:07 +00004065 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4066 if (End.isInvalid())
4067 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004068
4069 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004070 End.get(),
4071 D->getLBracketLoc(),
4072 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004073
Douglas Gregora16548e2009-08-11 05:31:07 +00004074 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4075 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004076
Douglas Gregora16548e2009-08-11 05:31:07 +00004077 ArrayExprs.push_back(Start.release());
4078 ArrayExprs.push_back(End.release());
4079 }
Mike Stump11289f42009-09-09 15:08:12 +00004080
Douglas Gregora16548e2009-08-11 05:31:07 +00004081 if (!getDerived().AlwaysRebuild() &&
4082 Init.get() == E->getInit() &&
4083 !ExprChanged)
4084 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004085
Douglas Gregora16548e2009-08-11 05:31:07 +00004086 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4087 E->getEqualOrColonLoc(),
4088 E->usesGNUSyntax(), move(Init));
4089}
Mike Stump11289f42009-09-09 15:08:12 +00004090
Douglas Gregora16548e2009-08-11 05:31:07 +00004091template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004092Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004093TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004094 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004095 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4096
4097 // FIXME: Will we ever have proper type location here? Will we actually
4098 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004099 QualType T = getDerived().TransformType(E->getType());
4100 if (T.isNull())
4101 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004102
Douglas Gregora16548e2009-08-11 05:31:07 +00004103 if (!getDerived().AlwaysRebuild() &&
4104 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004105 return SemaRef.Owned(E->Retain());
4106
Douglas Gregora16548e2009-08-11 05:31:07 +00004107 return getDerived().RebuildImplicitValueInitExpr(T);
4108}
Mike Stump11289f42009-09-09 15:08:12 +00004109
Douglas Gregora16548e2009-08-11 05:31:07 +00004110template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004111Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004112TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004113 // FIXME: Do we want the type as written?
4114 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004115
Douglas Gregora16548e2009-08-11 05:31:07 +00004116 {
4117 // FIXME: Source location isn't quite accurate.
4118 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4119 T = getDerived().TransformType(E->getType());
4120 if (T.isNull())
4121 return SemaRef.ExprError();
4122 }
Mike Stump11289f42009-09-09 15:08:12 +00004123
Douglas Gregora16548e2009-08-11 05:31:07 +00004124 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4125 if (SubExpr.isInvalid())
4126 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004127
Douglas Gregora16548e2009-08-11 05:31:07 +00004128 if (!getDerived().AlwaysRebuild() &&
4129 T == E->getType() &&
4130 SubExpr.get() == E->getSubExpr())
4131 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004132
Douglas Gregora16548e2009-08-11 05:31:07 +00004133 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4134 T, E->getRParenLoc());
4135}
4136
4137template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004138Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004139TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004140 bool ArgumentChanged = false;
4141 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4142 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4143 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4144 if (Init.isInvalid())
4145 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004146
Douglas Gregora16548e2009-08-11 05:31:07 +00004147 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4148 Inits.push_back(Init.takeAs<Expr>());
4149 }
Mike Stump11289f42009-09-09 15:08:12 +00004150
Douglas Gregora16548e2009-08-11 05:31:07 +00004151 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4152 move_arg(Inits),
4153 E->getRParenLoc());
4154}
Mike Stump11289f42009-09-09 15:08:12 +00004155
Douglas Gregora16548e2009-08-11 05:31:07 +00004156/// \brief Transform an address-of-label expression.
4157///
4158/// By default, the transformation of an address-of-label expression always
4159/// rebuilds the expression, so that the label identifier can be resolved to
4160/// the corresponding label statement by semantic analysis.
4161template<typename Derived>
4162Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004163TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004164 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4165 E->getLabel());
4166}
Mike Stump11289f42009-09-09 15:08:12 +00004167
4168template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004169Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004170TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004171 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004172 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4173 if (SubStmt.isInvalid())
4174 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004175
Douglas Gregora16548e2009-08-11 05:31:07 +00004176 if (!getDerived().AlwaysRebuild() &&
4177 SubStmt.get() == E->getSubStmt())
4178 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004179
4180 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004181 move(SubStmt),
4182 E->getRParenLoc());
4183}
Mike Stump11289f42009-09-09 15:08:12 +00004184
Douglas Gregora16548e2009-08-11 05:31:07 +00004185template<typename Derived>
4186Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004187TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004188 QualType T1, T2;
4189 {
4190 // FIXME: Source location isn't quite accurate.
4191 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004192
Douglas Gregora16548e2009-08-11 05:31:07 +00004193 T1 = getDerived().TransformType(E->getArgType1());
4194 if (T1.isNull())
4195 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004196
Douglas Gregora16548e2009-08-11 05:31:07 +00004197 T2 = getDerived().TransformType(E->getArgType2());
4198 if (T2.isNull())
4199 return SemaRef.ExprError();
4200 }
4201
4202 if (!getDerived().AlwaysRebuild() &&
4203 T1 == E->getArgType1() &&
4204 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004205 return SemaRef.Owned(E->Retain());
4206
Douglas Gregora16548e2009-08-11 05:31:07 +00004207 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4208 T1, T2, E->getRParenLoc());
4209}
Mike Stump11289f42009-09-09 15:08:12 +00004210
Douglas Gregora16548e2009-08-11 05:31:07 +00004211template<typename Derived>
4212Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004213TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004214 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4215 if (Cond.isInvalid())
4216 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004217
Douglas Gregora16548e2009-08-11 05:31:07 +00004218 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4219 if (LHS.isInvalid())
4220 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004221
Douglas Gregora16548e2009-08-11 05:31:07 +00004222 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4223 if (RHS.isInvalid())
4224 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004225
Douglas Gregora16548e2009-08-11 05:31:07 +00004226 if (!getDerived().AlwaysRebuild() &&
4227 Cond.get() == E->getCond() &&
4228 LHS.get() == E->getLHS() &&
4229 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004230 return SemaRef.Owned(E->Retain());
4231
Douglas Gregora16548e2009-08-11 05:31:07 +00004232 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4233 move(Cond), move(LHS), move(RHS),
4234 E->getRParenLoc());
4235}
Mike Stump11289f42009-09-09 15:08:12 +00004236
Douglas Gregora16548e2009-08-11 05:31:07 +00004237template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004238Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004239TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004240 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004241}
4242
4243template<typename Derived>
4244Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004245TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004246 switch (E->getOperator()) {
4247 case OO_New:
4248 case OO_Delete:
4249 case OO_Array_New:
4250 case OO_Array_Delete:
4251 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4252 return SemaRef.ExprError();
4253
4254 case OO_Call: {
4255 // This is a call to an object's operator().
4256 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4257
4258 // Transform the object itself.
4259 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4260 if (Object.isInvalid())
4261 return SemaRef.ExprError();
4262
4263 // FIXME: Poor location information
4264 SourceLocation FakeLParenLoc
4265 = SemaRef.PP.getLocForEndOfToken(
4266 static_cast<Expr *>(Object.get())->getLocEnd());
4267
4268 // Transform the call arguments.
4269 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4270 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4271 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004272 if (getDerived().DropCallArgument(E->getArg(I)))
4273 break;
4274
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004275 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4276 if (Arg.isInvalid())
4277 return SemaRef.ExprError();
4278
4279 // FIXME: Poor source location information.
4280 SourceLocation FakeCommaLoc
4281 = SemaRef.PP.getLocForEndOfToken(
4282 static_cast<Expr *>(Arg.get())->getLocEnd());
4283 FakeCommaLocs.push_back(FakeCommaLoc);
4284 Args.push_back(Arg.release());
4285 }
4286
4287 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4288 move_arg(Args),
4289 FakeCommaLocs.data(),
4290 E->getLocEnd());
4291 }
4292
4293#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4294 case OO_##Name:
4295#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4296#include "clang/Basic/OperatorKinds.def"
4297 case OO_Subscript:
4298 // Handled below.
4299 break;
4300
4301 case OO_Conditional:
4302 llvm_unreachable("conditional operator is not actually overloadable");
4303 return SemaRef.ExprError();
4304
4305 case OO_None:
4306 case NUM_OVERLOADED_OPERATORS:
4307 llvm_unreachable("not an overloaded operator?");
4308 return SemaRef.ExprError();
4309 }
4310
Douglas Gregora16548e2009-08-11 05:31:07 +00004311 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4312 if (Callee.isInvalid())
4313 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004314
John McCall47f29ea2009-12-08 09:21:05 +00004315 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004316 if (First.isInvalid())
4317 return SemaRef.ExprError();
4318
4319 OwningExprResult Second(SemaRef);
4320 if (E->getNumArgs() == 2) {
4321 Second = getDerived().TransformExpr(E->getArg(1));
4322 if (Second.isInvalid())
4323 return SemaRef.ExprError();
4324 }
Mike Stump11289f42009-09-09 15:08:12 +00004325
Douglas Gregora16548e2009-08-11 05:31:07 +00004326 if (!getDerived().AlwaysRebuild() &&
4327 Callee.get() == E->getCallee() &&
4328 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004329 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4330 return SemaRef.Owned(E->Retain());
4331
Douglas Gregora16548e2009-08-11 05:31:07 +00004332 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4333 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004334 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004335 move(First),
4336 move(Second));
4337}
Mike Stump11289f42009-09-09 15:08:12 +00004338
Douglas Gregora16548e2009-08-11 05:31:07 +00004339template<typename Derived>
4340Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004341TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4342 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004343}
Mike Stump11289f42009-09-09 15:08:12 +00004344
Douglas Gregora16548e2009-08-11 05:31:07 +00004345template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004346Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004347TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004348 TypeSourceInfo *OldT;
4349 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004350 {
4351 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004352 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004353 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4354 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004355
John McCall97513962010-01-15 18:39:57 +00004356 OldT = E->getTypeInfoAsWritten();
4357 NewT = getDerived().TransformType(OldT);
4358 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004359 return SemaRef.ExprError();
4360 }
Mike Stump11289f42009-09-09 15:08:12 +00004361
Douglas Gregor6131b442009-12-12 18:16:41 +00004362 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004363 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004364 if (SubExpr.isInvalid())
4365 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004366
Douglas Gregora16548e2009-08-11 05:31:07 +00004367 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004368 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004369 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004370 return SemaRef.Owned(E->Retain());
4371
Douglas Gregora16548e2009-08-11 05:31:07 +00004372 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004373 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004374 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4375 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4376 SourceLocation FakeRParenLoc
4377 = SemaRef.PP.getLocForEndOfToken(
4378 E->getSubExpr()->getSourceRange().getEnd());
4379 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004380 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004381 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004382 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004383 FakeRAngleLoc,
4384 FakeRAngleLoc,
4385 move(SubExpr),
4386 FakeRParenLoc);
4387}
Mike Stump11289f42009-09-09 15:08:12 +00004388
Douglas Gregora16548e2009-08-11 05:31:07 +00004389template<typename Derived>
4390Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004391TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4392 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004393}
Mike Stump11289f42009-09-09 15:08:12 +00004394
4395template<typename Derived>
4396Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004397TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4398 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004399}
4400
Douglas Gregora16548e2009-08-11 05:31:07 +00004401template<typename Derived>
4402Sema::OwningExprResult
4403TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004404 CXXReinterpretCastExpr *E) {
4405 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004406}
Mike Stump11289f42009-09-09 15:08:12 +00004407
Douglas Gregora16548e2009-08-11 05:31:07 +00004408template<typename Derived>
4409Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004410TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4411 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004412}
Mike Stump11289f42009-09-09 15:08:12 +00004413
Douglas Gregora16548e2009-08-11 05:31:07 +00004414template<typename Derived>
4415Sema::OwningExprResult
4416TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004417 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004418 TypeSourceInfo *OldT;
4419 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004420 {
4421 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004422
John McCall97513962010-01-15 18:39:57 +00004423 OldT = E->getTypeInfoAsWritten();
4424 NewT = getDerived().TransformType(OldT);
4425 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004426 return SemaRef.ExprError();
4427 }
Mike Stump11289f42009-09-09 15:08:12 +00004428
Douglas Gregor6131b442009-12-12 18:16:41 +00004429 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004430 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004431 if (SubExpr.isInvalid())
4432 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004433
Douglas Gregora16548e2009-08-11 05:31:07 +00004434 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004435 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004436 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004437 return SemaRef.Owned(E->Retain());
4438
Douglas Gregora16548e2009-08-11 05:31:07 +00004439 // FIXME: The end of the type's source range is wrong
4440 return getDerived().RebuildCXXFunctionalCastExpr(
4441 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004442 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004443 /*FIXME:*/E->getSubExpr()->getLocStart(),
4444 move(SubExpr),
4445 E->getRParenLoc());
4446}
Mike Stump11289f42009-09-09 15:08:12 +00004447
Douglas Gregora16548e2009-08-11 05:31:07 +00004448template<typename Derived>
4449Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004450TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004451 if (E->isTypeOperand()) {
4452 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004453
Douglas Gregora16548e2009-08-11 05:31:07 +00004454 QualType T = getDerived().TransformType(E->getTypeOperand());
4455 if (T.isNull())
4456 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004457
Douglas Gregora16548e2009-08-11 05:31:07 +00004458 if (!getDerived().AlwaysRebuild() &&
4459 T == E->getTypeOperand())
4460 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004461
Douglas Gregora16548e2009-08-11 05:31:07 +00004462 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4463 /*FIXME:*/E->getLocStart(),
4464 T,
4465 E->getLocEnd());
4466 }
Mike Stump11289f42009-09-09 15:08:12 +00004467
Douglas Gregora16548e2009-08-11 05:31:07 +00004468 // We don't know whether the expression is potentially evaluated until
4469 // after we perform semantic analysis, so the expression is potentially
4470 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004471 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004472 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004473
Douglas Gregora16548e2009-08-11 05:31:07 +00004474 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4475 if (SubExpr.isInvalid())
4476 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004477
Douglas Gregora16548e2009-08-11 05:31:07 +00004478 if (!getDerived().AlwaysRebuild() &&
4479 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004480 return SemaRef.Owned(E->Retain());
4481
Douglas Gregora16548e2009-08-11 05:31:07 +00004482 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4483 /*FIXME:*/E->getLocStart(),
4484 move(SubExpr),
4485 E->getLocEnd());
4486}
4487
4488template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004489Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004490TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004491 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004492}
Mike Stump11289f42009-09-09 15:08:12 +00004493
Douglas Gregora16548e2009-08-11 05:31:07 +00004494template<typename Derived>
4495Sema::OwningExprResult
4496TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004497 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004498 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004499}
Mike Stump11289f42009-09-09 15:08:12 +00004500
Douglas Gregora16548e2009-08-11 05:31:07 +00004501template<typename Derived>
4502Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004503TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004504 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004505
Douglas Gregora16548e2009-08-11 05:31:07 +00004506 QualType T = getDerived().TransformType(E->getType());
4507 if (T.isNull())
4508 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004509
Douglas Gregora16548e2009-08-11 05:31:07 +00004510 if (!getDerived().AlwaysRebuild() &&
4511 T == E->getType())
4512 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004513
Douglas Gregorb15af892010-01-07 23:12:05 +00004514 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004515}
Mike Stump11289f42009-09-09 15:08:12 +00004516
Douglas Gregora16548e2009-08-11 05:31:07 +00004517template<typename Derived>
4518Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004519TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004520 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4521 if (SubExpr.isInvalid())
4522 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004523
Douglas Gregora16548e2009-08-11 05:31:07 +00004524 if (!getDerived().AlwaysRebuild() &&
4525 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004526 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004527
4528 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4529}
Mike Stump11289f42009-09-09 15:08:12 +00004530
Douglas Gregora16548e2009-08-11 05:31:07 +00004531template<typename Derived>
4532Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004533TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004534 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004535 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4536 if (!Param)
4537 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004538
Chandler Carruth794da4c2010-02-08 06:42:49 +00004539 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004540 Param == E->getParam())
4541 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004542
Douglas Gregor033f6752009-12-23 23:03:06 +00004543 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00004544}
Mike Stump11289f42009-09-09 15:08:12 +00004545
Douglas Gregora16548e2009-08-11 05:31:07 +00004546template<typename Derived>
4547Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004548TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004549 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4550
4551 QualType T = getDerived().TransformType(E->getType());
4552 if (T.isNull())
4553 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004554
Douglas Gregora16548e2009-08-11 05:31:07 +00004555 if (!getDerived().AlwaysRebuild() &&
4556 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004557 return SemaRef.Owned(E->Retain());
4558
4559 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004560 /*FIXME:*/E->getTypeBeginLoc(),
4561 T,
4562 E->getRParenLoc());
4563}
Mike Stump11289f42009-09-09 15:08:12 +00004564
Douglas Gregora16548e2009-08-11 05:31:07 +00004565template<typename Derived>
4566Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004567TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004568 // Transform the type that we're allocating
4569 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4570 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4571 if (AllocType.isNull())
4572 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004573
Douglas Gregora16548e2009-08-11 05:31:07 +00004574 // Transform the size of the array we're allocating (if any).
4575 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4576 if (ArraySize.isInvalid())
4577 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004578
Douglas Gregora16548e2009-08-11 05:31:07 +00004579 // Transform the placement arguments (if any).
4580 bool ArgumentChanged = false;
4581 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4582 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4583 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4584 if (Arg.isInvalid())
4585 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004586
Douglas Gregora16548e2009-08-11 05:31:07 +00004587 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4588 PlacementArgs.push_back(Arg.take());
4589 }
Mike Stump11289f42009-09-09 15:08:12 +00004590
Douglas Gregorebe10102009-08-20 07:17:43 +00004591 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004592 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4593 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4594 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4595 if (Arg.isInvalid())
4596 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004597
Douglas Gregora16548e2009-08-11 05:31:07 +00004598 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4599 ConstructorArgs.push_back(Arg.take());
4600 }
Mike Stump11289f42009-09-09 15:08:12 +00004601
Douglas Gregora16548e2009-08-11 05:31:07 +00004602 if (!getDerived().AlwaysRebuild() &&
4603 AllocType == E->getAllocatedType() &&
4604 ArraySize.get() == E->getArraySize() &&
4605 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004606 return SemaRef.Owned(E->Retain());
4607
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004608 if (!ArraySize.get()) {
4609 // If no array size was specified, but the new expression was
4610 // instantiated with an array type (e.g., "new T" where T is
4611 // instantiated with "int[4]"), extract the outer bound from the
4612 // array type as our array size. We do this with constant and
4613 // dependently-sized array types.
4614 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4615 if (!ArrayT) {
4616 // Do nothing
4617 } else if (const ConstantArrayType *ConsArrayT
4618 = dyn_cast<ConstantArrayType>(ArrayT)) {
4619 ArraySize
4620 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4621 ConsArrayT->getSize(),
4622 SemaRef.Context.getSizeType(),
4623 /*FIXME:*/E->getLocStart()));
4624 AllocType = ConsArrayT->getElementType();
4625 } else if (const DependentSizedArrayType *DepArrayT
4626 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4627 if (DepArrayT->getSizeExpr()) {
4628 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4629 AllocType = DepArrayT->getElementType();
4630 }
4631 }
4632 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004633 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4634 E->isGlobalNew(),
4635 /*FIXME:*/E->getLocStart(),
4636 move_arg(PlacementArgs),
4637 /*FIXME:*/E->getLocStart(),
4638 E->isParenTypeId(),
4639 AllocType,
4640 /*FIXME:*/E->getLocStart(),
4641 /*FIXME:*/SourceRange(),
4642 move(ArraySize),
4643 /*FIXME:*/E->getLocStart(),
4644 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004645 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004646}
Mike Stump11289f42009-09-09 15:08:12 +00004647
Douglas Gregora16548e2009-08-11 05:31:07 +00004648template<typename Derived>
4649Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004650TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004651 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4652 if (Operand.isInvalid())
4653 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004654
Douglas Gregora16548e2009-08-11 05:31:07 +00004655 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004656 Operand.get() == E->getArgument())
4657 return SemaRef.Owned(E->Retain());
4658
Douglas Gregora16548e2009-08-11 05:31:07 +00004659 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4660 E->isGlobalDelete(),
4661 E->isArrayForm(),
4662 move(Operand));
4663}
Mike Stump11289f42009-09-09 15:08:12 +00004664
Douglas Gregora16548e2009-08-11 05:31:07 +00004665template<typename Derived>
4666Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004667TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004668 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004669 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4670 if (Base.isInvalid())
4671 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004672
Douglas Gregorad8a3362009-09-04 17:36:40 +00004673 NestedNameSpecifier *Qualifier
4674 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00004675 E->getQualifierRange(),
4676 true);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004677 if (E->getQualifier() && !Qualifier)
4678 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004679
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004680 // FIXME: Object type!
4681 TypeSourceInfo *DestroyedTypeInfo
4682 = getDerived().TransformType(E->getDestroyedTypeInfo());
4683 if (!DestroyedTypeInfo)
4684 return SemaRef.ExprError();
4685
4686 // FIXME: Object type!
4687 TypeSourceInfo *ScopeTypeInfo = 0;
4688 if (E->getScopeTypeInfo()) {
4689 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
4690 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00004691 return SemaRef.ExprError();
4692 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004693
Douglas Gregorad8a3362009-09-04 17:36:40 +00004694 if (!getDerived().AlwaysRebuild() &&
4695 Base.get() == E->getBase() &&
4696 Qualifier == E->getQualifier() &&
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004697 ScopeTypeInfo == E->getScopeTypeInfo() &&
4698 DestroyedTypeInfo == E->getDestroyedTypeInfo())
Douglas Gregorad8a3362009-09-04 17:36:40 +00004699 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004700
Douglas Gregorad8a3362009-09-04 17:36:40 +00004701 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4702 E->getOperatorLoc(),
4703 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00004704 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004705 E->getQualifierRange(),
4706 ScopeTypeInfo,
4707 E->getColonColonLoc(),
4708 DestroyedTypeInfo);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004709}
Mike Stump11289f42009-09-09 15:08:12 +00004710
Douglas Gregorad8a3362009-09-04 17:36:40 +00004711template<typename Derived>
4712Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004713TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004714 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00004715 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4716
4717 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4718 Sema::LookupOrdinaryName);
4719
4720 // Transform all the decls.
4721 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4722 E = Old->decls_end(); I != E; ++I) {
4723 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00004724 if (!InstD) {
4725 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4726 // This can happen because of dependent hiding.
4727 if (isa<UsingShadowDecl>(*I))
4728 continue;
4729 else
4730 return SemaRef.ExprError();
4731 }
John McCalle66edc12009-11-24 19:00:30 +00004732
4733 // Expand using declarations.
4734 if (isa<UsingDecl>(InstD)) {
4735 UsingDecl *UD = cast<UsingDecl>(InstD);
4736 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4737 E = UD->shadow_end(); I != E; ++I)
4738 R.addDecl(*I);
4739 continue;
4740 }
4741
4742 R.addDecl(InstD);
4743 }
4744
4745 // Resolve a kind, but don't do any further analysis. If it's
4746 // ambiguous, the callee needs to deal with it.
4747 R.resolveKind();
4748
4749 // Rebuild the nested-name qualifier, if present.
4750 CXXScopeSpec SS;
4751 NestedNameSpecifier *Qualifier = 0;
4752 if (Old->getQualifier()) {
4753 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00004754 Old->getQualifierRange(),
4755 false);
John McCalle66edc12009-11-24 19:00:30 +00004756 if (!Qualifier)
4757 return SemaRef.ExprError();
4758
4759 SS.setScopeRep(Qualifier);
4760 SS.setRange(Old->getQualifierRange());
4761 }
4762
4763 // If we have no template arguments, it's a normal declaration name.
4764 if (!Old->hasExplicitTemplateArgs())
4765 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4766
4767 // If we have template arguments, rebuild them, then rebuild the
4768 // templateid expression.
4769 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4770 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4771 TemplateArgumentLoc Loc;
4772 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4773 return SemaRef.ExprError();
4774 TransArgs.addArgument(Loc);
4775 }
4776
4777 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4778 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004779}
Mike Stump11289f42009-09-09 15:08:12 +00004780
Douglas Gregora16548e2009-08-11 05:31:07 +00004781template<typename Derived>
4782Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004783TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004784 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004785
Douglas Gregora16548e2009-08-11 05:31:07 +00004786 QualType T = getDerived().TransformType(E->getQueriedType());
4787 if (T.isNull())
4788 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004789
Douglas Gregora16548e2009-08-11 05:31:07 +00004790 if (!getDerived().AlwaysRebuild() &&
4791 T == E->getQueriedType())
4792 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004793
Douglas Gregora16548e2009-08-11 05:31:07 +00004794 // FIXME: Bad location information
4795 SourceLocation FakeLParenLoc
4796 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004797
4798 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004799 E->getLocStart(),
4800 /*FIXME:*/FakeLParenLoc,
4801 T,
4802 E->getLocEnd());
4803}
Mike Stump11289f42009-09-09 15:08:12 +00004804
Douglas Gregora16548e2009-08-11 05:31:07 +00004805template<typename Derived>
4806Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004807TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004808 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004809 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004810 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00004811 E->getQualifierRange(),
4812 false);
Douglas Gregora16548e2009-08-11 05:31:07 +00004813 if (!NNS)
4814 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004815
4816 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004817 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4818 if (!Name)
4819 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004820
John McCalle66edc12009-11-24 19:00:30 +00004821 if (!E->hasExplicitTemplateArgs()) {
4822 if (!getDerived().AlwaysRebuild() &&
4823 NNS == E->getQualifier() &&
4824 Name == E->getDeclName())
4825 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004826
John McCalle66edc12009-11-24 19:00:30 +00004827 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4828 E->getQualifierRange(),
4829 Name, E->getLocation(),
4830 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004831 }
John McCall6b51f282009-11-23 01:53:49 +00004832
4833 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004834 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004835 TemplateArgumentLoc Loc;
4836 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004837 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004838 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004839 }
4840
John McCalle66edc12009-11-24 19:00:30 +00004841 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4842 E->getQualifierRange(),
4843 Name, E->getLocation(),
4844 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004845}
4846
4847template<typename Derived>
4848Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004849TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00004850 // CXXConstructExprs are always implicit, so when we have a
4851 // 1-argument construction we just transform that argument.
4852 if (E->getNumArgs() == 1 ||
4853 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
4854 return getDerived().TransformExpr(E->getArg(0));
4855
Douglas Gregora16548e2009-08-11 05:31:07 +00004856 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4857
4858 QualType T = getDerived().TransformType(E->getType());
4859 if (T.isNull())
4860 return SemaRef.ExprError();
4861
4862 CXXConstructorDecl *Constructor
4863 = cast_or_null<CXXConstructorDecl>(
4864 getDerived().TransformDecl(E->getConstructor()));
4865 if (!Constructor)
4866 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004867
Douglas Gregora16548e2009-08-11 05:31:07 +00004868 bool ArgumentChanged = false;
4869 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004870 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004871 ArgEnd = E->arg_end();
4872 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00004873 if (getDerived().DropCallArgument(*Arg)) {
4874 ArgumentChanged = true;
4875 break;
4876 }
4877
Douglas Gregora16548e2009-08-11 05:31:07 +00004878 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4879 if (TransArg.isInvalid())
4880 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004881
Douglas Gregora16548e2009-08-11 05:31:07 +00004882 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4883 Args.push_back(TransArg.takeAs<Expr>());
4884 }
4885
4886 if (!getDerived().AlwaysRebuild() &&
4887 T == E->getType() &&
4888 Constructor == E->getConstructor() &&
4889 !ArgumentChanged)
4890 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004891
Douglas Gregordb121ba2009-12-14 16:27:04 +00004892 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
4893 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004894 move_arg(Args));
4895}
Mike Stump11289f42009-09-09 15:08:12 +00004896
Douglas Gregora16548e2009-08-11 05:31:07 +00004897/// \brief Transform a C++ temporary-binding expression.
4898///
Douglas Gregor363b1512009-12-24 18:51:59 +00004899/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
4900/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00004901template<typename Derived>
4902Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004903TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00004904 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004905}
Mike Stump11289f42009-09-09 15:08:12 +00004906
Anders Carlssonba6c4372010-01-29 02:39:32 +00004907/// \brief Transform a C++ reference-binding expression.
4908///
4909/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
4910/// transform the subexpression and return that.
4911template<typename Derived>
4912Sema::OwningExprResult
4913TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
4914 return getDerived().TransformExpr(E->getSubExpr());
4915}
4916
Mike Stump11289f42009-09-09 15:08:12 +00004917/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004918/// be destroyed after the expression is evaluated.
4919///
Douglas Gregor363b1512009-12-24 18:51:59 +00004920/// Since CXXExprWithTemporaries nodes are implicitly generated, we
4921/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00004922template<typename Derived>
4923Sema::OwningExprResult
4924TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00004925 CXXExprWithTemporaries *E) {
4926 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004927}
Mike Stump11289f42009-09-09 15:08:12 +00004928
Douglas Gregora16548e2009-08-11 05:31:07 +00004929template<typename Derived>
4930Sema::OwningExprResult
4931TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004932 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004933 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4934 QualType T = getDerived().TransformType(E->getType());
4935 if (T.isNull())
4936 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004937
Douglas Gregora16548e2009-08-11 05:31:07 +00004938 CXXConstructorDecl *Constructor
4939 = cast_or_null<CXXConstructorDecl>(
4940 getDerived().TransformDecl(E->getConstructor()));
4941 if (!Constructor)
4942 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004943
Douglas Gregora16548e2009-08-11 05:31:07 +00004944 bool ArgumentChanged = false;
4945 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4946 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004947 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004948 ArgEnd = E->arg_end();
4949 Arg != ArgEnd; ++Arg) {
4950 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4951 if (TransArg.isInvalid())
4952 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004953
Douglas Gregora16548e2009-08-11 05:31:07 +00004954 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4955 Args.push_back((Expr *)TransArg.release());
4956 }
Mike Stump11289f42009-09-09 15:08:12 +00004957
Douglas Gregora16548e2009-08-11 05:31:07 +00004958 if (!getDerived().AlwaysRebuild() &&
4959 T == E->getType() &&
4960 Constructor == E->getConstructor() &&
4961 !ArgumentChanged)
4962 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004963
Douglas Gregora16548e2009-08-11 05:31:07 +00004964 // FIXME: Bogus location information
4965 SourceLocation CommaLoc;
4966 if (Args.size() > 1) {
4967 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004968 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004969 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4970 }
4971 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4972 T,
4973 /*FIXME:*/E->getTypeBeginLoc(),
4974 move_arg(Args),
4975 &CommaLoc,
4976 E->getLocEnd());
4977}
Mike Stump11289f42009-09-09 15:08:12 +00004978
Douglas Gregora16548e2009-08-11 05:31:07 +00004979template<typename Derived>
4980Sema::OwningExprResult
4981TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004982 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004983 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4984 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4985 if (T.isNull())
4986 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004987
Douglas Gregora16548e2009-08-11 05:31:07 +00004988 bool ArgumentChanged = false;
4989 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4990 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4991 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4992 ArgEnd = E->arg_end();
4993 Arg != ArgEnd; ++Arg) {
4994 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4995 if (TransArg.isInvalid())
4996 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004997
Douglas Gregora16548e2009-08-11 05:31:07 +00004998 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4999 FakeCommaLocs.push_back(
5000 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5001 Args.push_back(TransArg.takeAs<Expr>());
5002 }
Mike Stump11289f42009-09-09 15:08:12 +00005003
Douglas Gregora16548e2009-08-11 05:31:07 +00005004 if (!getDerived().AlwaysRebuild() &&
5005 T == E->getTypeAsWritten() &&
5006 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005007 return SemaRef.Owned(E->Retain());
5008
Douglas Gregora16548e2009-08-11 05:31:07 +00005009 // FIXME: we're faking the locations of the commas
5010 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5011 T,
5012 E->getLParenLoc(),
5013 move_arg(Args),
5014 FakeCommaLocs.data(),
5015 E->getRParenLoc());
5016}
Mike Stump11289f42009-09-09 15:08:12 +00005017
Douglas Gregora16548e2009-08-11 05:31:07 +00005018template<typename Derived>
5019Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005020TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005021 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005022 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005023 OwningExprResult Base(SemaRef, (Expr*) 0);
5024 Expr *OldBase;
5025 QualType BaseType;
5026 QualType ObjectType;
5027 if (!E->isImplicitAccess()) {
5028 OldBase = E->getBase();
5029 Base = getDerived().TransformExpr(OldBase);
5030 if (Base.isInvalid())
5031 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005032
John McCall2d74de92009-12-01 22:10:20 +00005033 // Start the member reference and compute the object's type.
5034 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005035 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005036 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5037 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005038 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005039 ObjectTy,
5040 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005041 if (Base.isInvalid())
5042 return SemaRef.ExprError();
5043
5044 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5045 BaseType = ((Expr*) Base.get())->getType();
5046 } else {
5047 OldBase = 0;
5048 BaseType = getDerived().TransformType(E->getBaseType());
5049 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5050 }
Mike Stump11289f42009-09-09 15:08:12 +00005051
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005052 // Transform the first part of the nested-name-specifier that qualifies
5053 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005054 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005055 = getDerived().TransformFirstQualifierInScope(
5056 E->getFirstQualifierFoundInScope(),
5057 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005058
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005059 NestedNameSpecifier *Qualifier = 0;
5060 if (E->getQualifier()) {
Douglas Gregor90d554e2010-02-21 18:36:56 +00005061 bool MayBePseudoDestructor
5062 = E->getMember().getNameKind() == DeclarationName::CXXDestructorName;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005063 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5064 E->getQualifierRange(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005065 MayBePseudoDestructor,
John McCall2d74de92009-12-01 22:10:20 +00005066 ObjectType,
5067 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005068 if (!Qualifier)
5069 return SemaRef.ExprError();
5070 }
Mike Stump11289f42009-09-09 15:08:12 +00005071
5072 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005073 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005074 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005075 if (!Name)
5076 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005077
John McCall2d74de92009-12-01 22:10:20 +00005078 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005079 // This is a reference to a member without an explicitly-specified
5080 // template argument list. Optimize for this common case.
5081 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005082 Base.get() == OldBase &&
5083 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005084 Qualifier == E->getQualifier() &&
5085 Name == E->getMember() &&
5086 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005087 return SemaRef.Owned(E->Retain());
5088
John McCall8cd78132009-11-19 22:55:06 +00005089 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005090 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005091 E->isArrow(),
5092 E->getOperatorLoc(),
5093 Qualifier,
5094 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005095 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005096 Name,
5097 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005098 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005099 }
5100
John McCall6b51f282009-11-23 01:53:49 +00005101 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005102 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005103 TemplateArgumentLoc Loc;
5104 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005105 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005106 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005107 }
Mike Stump11289f42009-09-09 15:08:12 +00005108
John McCall8cd78132009-11-19 22:55:06 +00005109 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005110 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005111 E->isArrow(),
5112 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005113 Qualifier,
5114 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005115 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005116 Name,
5117 E->getMemberLoc(),
5118 &TransArgs);
5119}
5120
5121template<typename Derived>
5122Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005123TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005124 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005125 OwningExprResult Base(SemaRef, (Expr*) 0);
5126 QualType BaseType;
5127 if (!Old->isImplicitAccess()) {
5128 Base = getDerived().TransformExpr(Old->getBase());
5129 if (Base.isInvalid())
5130 return SemaRef.ExprError();
5131 BaseType = ((Expr*) Base.get())->getType();
5132 } else {
5133 BaseType = getDerived().TransformType(Old->getBaseType());
5134 }
John McCall10eae182009-11-30 22:42:35 +00005135
5136 NestedNameSpecifier *Qualifier = 0;
5137 if (Old->getQualifier()) {
5138 Qualifier
5139 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005140 Old->getQualifierRange(),
5141 false);
John McCall10eae182009-11-30 22:42:35 +00005142 if (Qualifier == 0)
5143 return SemaRef.ExprError();
5144 }
5145
5146 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5147 Sema::LookupOrdinaryName);
5148
5149 // Transform all the decls.
5150 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5151 E = Old->decls_end(); I != E; ++I) {
5152 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00005153 if (!InstD) {
5154 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5155 // This can happen because of dependent hiding.
5156 if (isa<UsingShadowDecl>(*I))
5157 continue;
5158 else
5159 return SemaRef.ExprError();
5160 }
John McCall10eae182009-11-30 22:42:35 +00005161
5162 // Expand using declarations.
5163 if (isa<UsingDecl>(InstD)) {
5164 UsingDecl *UD = cast<UsingDecl>(InstD);
5165 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5166 E = UD->shadow_end(); I != E; ++I)
5167 R.addDecl(*I);
5168 continue;
5169 }
5170
5171 R.addDecl(InstD);
5172 }
5173
5174 R.resolveKind();
5175
5176 TemplateArgumentListInfo TransArgs;
5177 if (Old->hasExplicitTemplateArgs()) {
5178 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5179 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5180 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5181 TemplateArgumentLoc Loc;
5182 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5183 Loc))
5184 return SemaRef.ExprError();
5185 TransArgs.addArgument(Loc);
5186 }
5187 }
John McCall38836f02010-01-15 08:34:02 +00005188
5189 // FIXME: to do this check properly, we will need to preserve the
5190 // first-qualifier-in-scope here, just in case we had a dependent
5191 // base (and therefore couldn't do the check) and a
5192 // nested-name-qualifier (and therefore could do the lookup).
5193 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005194
5195 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005196 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005197 Old->getOperatorLoc(),
5198 Old->isArrow(),
5199 Qualifier,
5200 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005201 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005202 R,
5203 (Old->hasExplicitTemplateArgs()
5204 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005205}
5206
5207template<typename Derived>
5208Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005209TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005210 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005211}
5212
Mike Stump11289f42009-09-09 15:08:12 +00005213template<typename Derived>
5214Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005215TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005216 // FIXME: poor source location
5217 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5218 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5219 if (EncodedType.isNull())
5220 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005221
Douglas Gregora16548e2009-08-11 05:31:07 +00005222 if (!getDerived().AlwaysRebuild() &&
5223 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00005224 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005225
5226 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5227 EncodedType,
5228 E->getRParenLoc());
5229}
Mike Stump11289f42009-09-09 15:08:12 +00005230
Douglas Gregora16548e2009-08-11 05:31:07 +00005231template<typename Derived>
5232Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005233TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005234 // FIXME: Implement this!
5235 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005236 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005237}
5238
Mike Stump11289f42009-09-09 15:08:12 +00005239template<typename Derived>
5240Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005241TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005242 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005243}
5244
Mike Stump11289f42009-09-09 15:08:12 +00005245template<typename Derived>
5246Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005247TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005248 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00005249 = cast_or_null<ObjCProtocolDecl>(
5250 getDerived().TransformDecl(E->getProtocol()));
5251 if (!Protocol)
5252 return SemaRef.ExprError();
5253
5254 if (!getDerived().AlwaysRebuild() &&
5255 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005256 return SemaRef.Owned(E->Retain());
5257
Douglas Gregora16548e2009-08-11 05:31:07 +00005258 return getDerived().RebuildObjCProtocolExpr(Protocol,
5259 E->getAtLoc(),
5260 /*FIXME:*/E->getAtLoc(),
5261 /*FIXME:*/E->getAtLoc(),
5262 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005263
Douglas Gregora16548e2009-08-11 05:31:07 +00005264}
5265
Mike Stump11289f42009-09-09 15:08:12 +00005266template<typename Derived>
5267Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005268TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005269 // FIXME: Implement this!
5270 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005271 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005272}
5273
Mike Stump11289f42009-09-09 15:08:12 +00005274template<typename Derived>
5275Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005276TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005277 // FIXME: Implement this!
5278 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005279 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005280}
5281
Mike Stump11289f42009-09-09 15:08:12 +00005282template<typename Derived>
5283Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005284TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005285 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005286 // FIXME: Implement this!
5287 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005288 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005289}
5290
Mike Stump11289f42009-09-09 15:08:12 +00005291template<typename Derived>
5292Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005293TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005294 // FIXME: Implement this!
5295 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005296 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005297}
5298
Mike Stump11289f42009-09-09 15:08:12 +00005299template<typename Derived>
5300Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005301TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005302 // FIXME: Implement this!
5303 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005304 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005305}
5306
Mike Stump11289f42009-09-09 15:08:12 +00005307template<typename Derived>
5308Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005309TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005310 bool ArgumentChanged = false;
5311 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5312 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5313 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5314 if (SubExpr.isInvalid())
5315 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005316
Douglas Gregora16548e2009-08-11 05:31:07 +00005317 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5318 SubExprs.push_back(SubExpr.takeAs<Expr>());
5319 }
Mike Stump11289f42009-09-09 15:08:12 +00005320
Douglas Gregora16548e2009-08-11 05:31:07 +00005321 if (!getDerived().AlwaysRebuild() &&
5322 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005323 return SemaRef.Owned(E->Retain());
5324
Douglas Gregora16548e2009-08-11 05:31:07 +00005325 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5326 move_arg(SubExprs),
5327 E->getRParenLoc());
5328}
5329
Mike Stump11289f42009-09-09 15:08:12 +00005330template<typename Derived>
5331Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005332TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005333 // FIXME: Implement this!
5334 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005335 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005336}
5337
Mike Stump11289f42009-09-09 15:08:12 +00005338template<typename Derived>
5339Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005340TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005341 // FIXME: Implement this!
5342 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005343 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005344}
Mike Stump11289f42009-09-09 15:08:12 +00005345
Douglas Gregora16548e2009-08-11 05:31:07 +00005346//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005347// Type reconstruction
5348//===----------------------------------------------------------------------===//
5349
Mike Stump11289f42009-09-09 15:08:12 +00005350template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005351QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5352 SourceLocation Star) {
5353 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005354 getDerived().getBaseEntity());
5355}
5356
Mike Stump11289f42009-09-09 15:08:12 +00005357template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005358QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5359 SourceLocation Star) {
5360 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005361 getDerived().getBaseEntity());
5362}
5363
Mike Stump11289f42009-09-09 15:08:12 +00005364template<typename Derived>
5365QualType
John McCall70dd5f62009-10-30 00:06:24 +00005366TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5367 bool WrittenAsLValue,
5368 SourceLocation Sigil) {
5369 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5370 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005371}
5372
5373template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005374QualType
John McCall70dd5f62009-10-30 00:06:24 +00005375TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5376 QualType ClassType,
5377 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005378 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005379 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005380}
5381
5382template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005383QualType
John McCall70dd5f62009-10-30 00:06:24 +00005384TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5385 SourceLocation Sigil) {
5386 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005387 getDerived().getBaseEntity());
5388}
5389
5390template<typename Derived>
5391QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005392TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5393 ArrayType::ArraySizeModifier SizeMod,
5394 const llvm::APInt *Size,
5395 Expr *SizeExpr,
5396 unsigned IndexTypeQuals,
5397 SourceRange BracketsRange) {
5398 if (SizeExpr || !Size)
5399 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5400 IndexTypeQuals, BracketsRange,
5401 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005402
5403 QualType Types[] = {
5404 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5405 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5406 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005407 };
5408 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5409 QualType SizeType;
5410 for (unsigned I = 0; I != NumTypes; ++I)
5411 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5412 SizeType = Types[I];
5413 break;
5414 }
Mike Stump11289f42009-09-09 15:08:12 +00005415
Douglas Gregord6ff3322009-08-04 16:50:30 +00005416 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005417 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005418 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005419 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005420}
Mike Stump11289f42009-09-09 15:08:12 +00005421
Douglas Gregord6ff3322009-08-04 16:50:30 +00005422template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005423QualType
5424TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005425 ArrayType::ArraySizeModifier SizeMod,
5426 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005427 unsigned IndexTypeQuals,
5428 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005429 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005430 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005431}
5432
5433template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005434QualType
Mike Stump11289f42009-09-09 15:08:12 +00005435TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005436 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005437 unsigned IndexTypeQuals,
5438 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005439 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005440 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005441}
Mike Stump11289f42009-09-09 15:08:12 +00005442
Douglas Gregord6ff3322009-08-04 16:50:30 +00005443template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005444QualType
5445TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005446 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005447 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005448 unsigned IndexTypeQuals,
5449 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005450 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005451 SizeExpr.takeAs<Expr>(),
5452 IndexTypeQuals, BracketsRange);
5453}
5454
5455template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005456QualType
5457TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005458 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005459 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005460 unsigned IndexTypeQuals,
5461 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005462 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005463 SizeExpr.takeAs<Expr>(),
5464 IndexTypeQuals, BracketsRange);
5465}
5466
5467template<typename Derived>
5468QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00005469 unsigned NumElements,
5470 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005471 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00005472 return SemaRef.Context.getVectorType(ElementType, NumElements,
5473 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005474}
Mike Stump11289f42009-09-09 15:08:12 +00005475
Douglas Gregord6ff3322009-08-04 16:50:30 +00005476template<typename Derived>
5477QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5478 unsigned NumElements,
5479 SourceLocation AttributeLoc) {
5480 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5481 NumElements, true);
5482 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005483 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005484 AttributeLoc);
5485 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5486 AttributeLoc);
5487}
Mike Stump11289f42009-09-09 15:08:12 +00005488
Douglas Gregord6ff3322009-08-04 16:50:30 +00005489template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005490QualType
5491TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005492 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005493 SourceLocation AttributeLoc) {
5494 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5495}
Mike Stump11289f42009-09-09 15:08:12 +00005496
Douglas Gregord6ff3322009-08-04 16:50:30 +00005497template<typename Derived>
5498QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005499 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005500 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005501 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005502 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005503 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005504 Quals,
5505 getDerived().getBaseLocation(),
5506 getDerived().getBaseEntity());
5507}
Mike Stump11289f42009-09-09 15:08:12 +00005508
Douglas Gregord6ff3322009-08-04 16:50:30 +00005509template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005510QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5511 return SemaRef.Context.getFunctionNoProtoType(T);
5512}
5513
5514template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005515QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5516 assert(D && "no decl found");
5517 if (D->isInvalidDecl()) return QualType();
5518
5519 TypeDecl *Ty;
5520 if (isa<UsingDecl>(D)) {
5521 UsingDecl *Using = cast<UsingDecl>(D);
5522 assert(Using->isTypeName() &&
5523 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5524
5525 // A valid resolved using typename decl points to exactly one type decl.
5526 assert(++Using->shadow_begin() == Using->shadow_end());
5527 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5528
5529 } else {
5530 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5531 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5532 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5533 }
5534
5535 return SemaRef.Context.getTypeDeclType(Ty);
5536}
5537
5538template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005539QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005540 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5541}
5542
5543template<typename Derived>
5544QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5545 return SemaRef.Context.getTypeOfType(Underlying);
5546}
5547
5548template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005549QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005550 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5551}
5552
5553template<typename Derived>
5554QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005555 TemplateName Template,
5556 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005557 const TemplateArgumentListInfo &TemplateArgs) {
5558 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005559}
Mike Stump11289f42009-09-09 15:08:12 +00005560
Douglas Gregor1135c352009-08-06 05:28:30 +00005561template<typename Derived>
5562NestedNameSpecifier *
5563TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5564 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005565 IdentifierInfo &II,
Douglas Gregor90d554e2010-02-21 18:36:56 +00005566 bool MayBePseudoDestructor,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005567 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005568 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005569 CXXScopeSpec SS;
5570 // FIXME: The source location information is all wrong.
5571 SS.setRange(Range);
5572 SS.setScopeRep(Prefix);
5573 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005574 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005575 Range.getEnd(), II,
Douglas Gregor90d554e2010-02-21 18:36:56 +00005576 MayBePseudoDestructor,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005577 ObjectType,
5578 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005579 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005580}
5581
5582template<typename Derived>
5583NestedNameSpecifier *
5584TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5585 SourceRange Range,
5586 NamespaceDecl *NS) {
5587 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5588}
5589
5590template<typename Derived>
5591NestedNameSpecifier *
5592TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5593 SourceRange Range,
5594 bool TemplateKW,
Douglas Gregor90d554e2010-02-21 18:36:56 +00005595 QualType T,
5596 bool MayBePseudoDestructor) {
5597 if (MayBePseudoDestructor || T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00005598 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005599 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005600 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5601 T.getTypePtr());
5602 }
Mike Stump11289f42009-09-09 15:08:12 +00005603
Douglas Gregor1135c352009-08-06 05:28:30 +00005604 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5605 return 0;
5606}
Mike Stump11289f42009-09-09 15:08:12 +00005607
Douglas Gregor71dc5092009-08-06 06:41:21 +00005608template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005609TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005610TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5611 bool TemplateKW,
5612 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005613 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005614 Template);
5615}
5616
5617template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005618TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005619TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005620 const IdentifierInfo &II,
5621 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005622 CXXScopeSpec SS;
5623 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005624 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005625 UnqualifiedId Name;
5626 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005627 return getSema().ActOnDependentTemplateName(
5628 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005629 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005630 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005631 ObjectType.getAsOpaquePtr(),
5632 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005633 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005634}
Mike Stump11289f42009-09-09 15:08:12 +00005635
Douglas Gregora16548e2009-08-11 05:31:07 +00005636template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005637TemplateName
5638TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5639 OverloadedOperatorKind Operator,
5640 QualType ObjectType) {
5641 CXXScopeSpec SS;
5642 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5643 SS.setScopeRep(Qualifier);
5644 UnqualifiedId Name;
5645 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5646 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5647 Operator, SymbolLocations);
5648 return getSema().ActOnDependentTemplateName(
5649 /*FIXME:*/getDerived().getBaseLocation(),
5650 SS,
5651 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005652 ObjectType.getAsOpaquePtr(),
5653 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005654 .template getAsVal<TemplateName>();
5655}
5656
5657template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005658Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005659TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5660 SourceLocation OpLoc,
5661 ExprArg Callee,
5662 ExprArg First,
5663 ExprArg Second) {
5664 Expr *FirstExpr = (Expr *)First.get();
5665 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005666 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005667 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005668
Douglas Gregora16548e2009-08-11 05:31:07 +00005669 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005670 if (Op == OO_Subscript) {
5671 if (!FirstExpr->getType()->isOverloadableType() &&
5672 !SecondExpr->getType()->isOverloadableType())
5673 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005674 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005675 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005676 } else if (Op == OO_Arrow) {
5677 // -> is never a builtin operation.
5678 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005679 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005680 if (!FirstExpr->getType()->isOverloadableType()) {
5681 // The argument is not of overloadable type, so try to create a
5682 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005683 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005684 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005685
Douglas Gregora16548e2009-08-11 05:31:07 +00005686 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5687 }
5688 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005689 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005690 !SecondExpr->getType()->isOverloadableType()) {
5691 // Neither of the arguments is an overloadable type, so try to
5692 // create a built-in binary operation.
5693 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005694 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005695 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5696 if (Result.isInvalid())
5697 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005698
Douglas Gregora16548e2009-08-11 05:31:07 +00005699 First.release();
5700 Second.release();
5701 return move(Result);
5702 }
5703 }
Mike Stump11289f42009-09-09 15:08:12 +00005704
5705 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005706 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00005707 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005708
John McCalld14a8642009-11-21 08:51:07 +00005709 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5710 assert(ULE->requiresADL());
5711
5712 // FIXME: Do we have to check
5713 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00005714 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00005715 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00005716 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00005717 }
Mike Stump11289f42009-09-09 15:08:12 +00005718
Douglas Gregora16548e2009-08-11 05:31:07 +00005719 // Add any functions found via argument-dependent lookup.
5720 Expr *Args[2] = { FirstExpr, SecondExpr };
5721 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005722
Douglas Gregora16548e2009-08-11 05:31:07 +00005723 // Create the overloaded operator invocation for unary operators.
5724 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005725 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005726 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5727 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5728 }
Mike Stump11289f42009-09-09 15:08:12 +00005729
Sebastian Redladba46e2009-10-29 20:17:01 +00005730 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005731 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5732 OpLoc,
5733 move(First),
5734 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005735
Douglas Gregora16548e2009-08-11 05:31:07 +00005736 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005737 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005738 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005739 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005740 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5741 if (Result.isInvalid())
5742 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005743
Douglas Gregora16548e2009-08-11 05:31:07 +00005744 First.release();
5745 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005746 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005747}
Mike Stump11289f42009-09-09 15:08:12 +00005748
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005749template<typename Derived>
5750Sema::OwningExprResult
5751TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
5752 SourceLocation OperatorLoc,
5753 bool isArrow,
5754 NestedNameSpecifier *Qualifier,
5755 SourceRange QualifierRange,
5756 TypeSourceInfo *ScopeType,
5757 SourceLocation CCLoc,
5758 TypeSourceInfo *DestroyedType) {
5759 CXXScopeSpec SS;
5760 if (Qualifier) {
5761 SS.setRange(QualifierRange);
5762 SS.setScopeRep(Qualifier);
5763 }
5764
5765 Expr *BaseE = (Expr *)Base.get();
5766 QualType BaseType = BaseE->getType();
5767 if (BaseE->isTypeDependent() ||
5768 (!isArrow && !BaseType->getAs<RecordType>()) ||
5769 (isArrow && BaseType->getAs<PointerType>() &&
5770 !BaseType->getAs<PointerType>()->getAs<RecordType>())) {
5771 // This pseudo-destructor expression is still a pseudo-destructor.
5772 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
5773 isArrow? tok::arrow : tok::period,
5774 SS, ScopeType, CCLoc,
5775 DestroyedType,
5776 /*FIXME?*/true);
5777 }
5778
5779 DeclarationName Name
5780 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
5781 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
5782
5783 // FIXME: the ScopeType should be tacked onto SS.
5784
5785 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
5786 OperatorLoc, isArrow,
5787 SS, /*FIXME: FirstQualifier*/ 0,
5788 Name,
5789 DestroyedType->getTypeLoc().getSourceRange().getBegin(),
5790 /*TemplateArgs*/ 0);
5791}
5792
Douglas Gregord6ff3322009-08-04 16:50:30 +00005793} // end namespace clang
5794
5795#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H