blob: e062a37f8ef2f9386d206695130ad20e8d54cc85 [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.
194 QualType TransformType(QualType T);
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.
John McCallbcd03502009-12-07 02:54:59 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000205
206 /// \brief Transform the given type-with-location into a new
207 /// type, collecting location information in the given builder
208 /// as necessary.
209 ///
210 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000211
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000212 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000213 ///
Mike Stump11289f42009-09-09 15:08:12 +0000214 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000215 /// appropriate TransformXXXStmt function to transform a specific kind of
216 /// statement or the TransformExpr() function to transform an expression.
217 /// Subclasses may override this function to transform statements using some
218 /// other mechanism.
219 ///
220 /// \returns the transformed statement.
Douglas Gregora16548e2009-08-11 05:31:07 +0000221 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000222
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000223 /// \brief Transform the given expression.
224 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000225 /// By default, this routine transforms an expression by delegating to the
226 /// appropriate TransformXXXExpr function to build a new expression.
227 /// Subclasses may override this function to transform expressions using some
228 /// other mechanism.
229 ///
230 /// \returns the transformed expression.
John McCall47f29ea2009-12-08 09:21:05 +0000231 OwningExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000232
Douglas Gregord6ff3322009-08-04 16:50:30 +0000233 /// \brief Transform the given declaration, which is referenced from a type
234 /// or expression.
235 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000236 /// By default, acts as the identity function on declarations. Subclasses
237 /// may override this function to provide alternate behavior.
238 Decl *TransformDecl(Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000239
240 /// \brief Transform the definition of the given declaration.
241 ///
Mike Stump11289f42009-09-09 15:08:12 +0000242 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000243 /// Subclasses may override this function to provide alternate behavior.
244 Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); }
Mike Stump11289f42009-09-09 15:08:12 +0000245
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000246 /// \brief Transform the given declaration, which was the first part of a
247 /// nested-name-specifier in a member access expression.
248 ///
249 /// This specific declaration transformation only applies to the first
250 /// identifier in a nested-name-specifier of a member access expression, e.g.,
251 /// the \c T in \c x->T::member
252 ///
253 /// By default, invokes TransformDecl() to transform the declaration.
254 /// Subclasses may override this function to provide alternate behavior.
255 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
256 return cast_or_null<NamedDecl>(getDerived().TransformDecl(D));
257 }
258
Douglas Gregord6ff3322009-08-04 16:50:30 +0000259 /// \brief Transform the given nested-name-specifier.
260 ///
Mike Stump11289f42009-09-09 15:08:12 +0000261 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000262 /// nested-name-specifier. Subclasses may override this function to provide
263 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000264 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000265 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000266 QualType ObjectType = QualType(),
267 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000268
Douglas Gregorf816bd72009-09-03 22:13:48 +0000269 /// \brief Transform the given declaration name.
270 ///
271 /// By default, transforms the types of conversion function, constructor,
272 /// and destructor names and then (if needed) rebuilds the declaration name.
273 /// Identifiers and selectors are returned unmodified. Sublcasses may
274 /// override this function to provide alternate behavior.
275 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +0000276 SourceLocation Loc,
277 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000278
Douglas Gregord6ff3322009-08-04 16:50:30 +0000279 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000280 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000281 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000282 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000283 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000284 TemplateName TransformTemplateName(TemplateName Name,
285 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000286
Douglas Gregord6ff3322009-08-04 16:50:30 +0000287 /// \brief Transform the given template argument.
288 ///
Mike Stump11289f42009-09-09 15:08:12 +0000289 /// By default, this operation transforms the type, expression, or
290 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000291 /// new template argument from the transformed result. Subclasses may
292 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000293 ///
294 /// Returns true if there was an error.
295 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
296 TemplateArgumentLoc &Output);
297
298 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
299 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
300 TemplateArgumentLoc &ArgLoc);
301
John McCallbcd03502009-12-07 02:54:59 +0000302 /// \brief Fakes up a TypeSourceInfo for a type.
303 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
304 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000305 getDerived().getBaseLocation());
306 }
Mike Stump11289f42009-09-09 15:08:12 +0000307
John McCall550e0c22009-10-21 00:40:46 +0000308#define ABSTRACT_TYPELOC(CLASS, PARENT)
309#define TYPELOC(CLASS, PARENT) \
310 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
311#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000312
John McCall70dd5f62009-10-30 00:06:24 +0000313 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
314
Douglas Gregorc59e5612009-10-19 22:04:39 +0000315 QualType
316 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
317 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000318
319 QualType
320 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
321 TemplateSpecializationTypeLoc TL,
322 QualType ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +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.
431 QualType RebuildVectorType(QualType ElementType, unsigned NumElements);
Mike Stump11289f42009-09-09 15:08:12 +0000432
Douglas Gregord6ff3322009-08-04 16:50:30 +0000433 /// \brief Build a new extended vector type given the element type and
434 /// number of elements.
435 ///
436 /// By default, performs semantic analysis when building the vector type.
437 /// Subclasses may override this routine to provide different behavior.
438 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
439 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000440
441 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000442 /// given the element type and number of elements.
443 ///
444 /// By default, performs semantic analysis when building the vector type.
445 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000446 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000447 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000448 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 /// \brief Build a new function type.
451 ///
452 /// By default, performs semantic analysis when building the function type.
453 /// Subclasses may override this routine to provide different behavior.
454 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000455 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000456 unsigned NumParamTypes,
457 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000458
John McCall550e0c22009-10-21 00:40:46 +0000459 /// \brief Build a new unprototyped function type.
460 QualType RebuildFunctionNoProtoType(QualType ResultType);
461
John McCallb96ec562009-12-04 22:46:56 +0000462 /// \brief Rebuild an unresolved typename type, given the decl that
463 /// the UnresolvedUsingTypenameDecl was transformed to.
464 QualType RebuildUnresolvedUsingType(Decl *D);
465
Douglas Gregord6ff3322009-08-04 16:50:30 +0000466 /// \brief Build a new typedef type.
467 QualType RebuildTypedefType(TypedefDecl *Typedef) {
468 return SemaRef.Context.getTypeDeclType(Typedef);
469 }
470
471 /// \brief Build a new class/struct/union type.
472 QualType RebuildRecordType(RecordDecl *Record) {
473 return SemaRef.Context.getTypeDeclType(Record);
474 }
475
476 /// \brief Build a new Enum type.
477 QualType RebuildEnumType(EnumDecl *Enum) {
478 return SemaRef.Context.getTypeDeclType(Enum);
479 }
John McCallfcc33b02009-09-05 00:15:47 +0000480
481 /// \brief Build a new elaborated type.
482 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
483 return SemaRef.Context.getElaboratedType(T, Tag);
484 }
Mike Stump11289f42009-09-09 15:08:12 +0000485
486 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000487 ///
488 /// By default, performs semantic analysis when building the typeof type.
489 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000490 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000491
Mike Stump11289f42009-09-09 15:08:12 +0000492 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000493 ///
494 /// By default, builds a new TypeOfType with the given underlying type.
495 QualType RebuildTypeOfType(QualType Underlying);
496
Mike Stump11289f42009-09-09 15:08:12 +0000497 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000498 ///
499 /// By default, performs semantic analysis when building the decltype type.
500 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000501 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000502
Douglas Gregord6ff3322009-08-04 16:50:30 +0000503 /// \brief Build a new template specialization type.
504 ///
505 /// By default, performs semantic analysis when building the template
506 /// specialization type. Subclasses may override this routine to provide
507 /// different behavior.
508 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000509 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000510 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000511
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 /// \brief Build a new qualified name type.
513 ///
Mike Stump11289f42009-09-09 15:08:12 +0000514 /// By default, builds a new QualifiedNameType type from the
515 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000516 /// this routine to provide different behavior.
517 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
518 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000519 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000520
521 /// \brief Build a new typename type that refers to a template-id.
522 ///
523 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000524 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000525 /// different behavior.
526 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
527 if (NNS->isDependent())
Mike Stump11289f42009-09-09 15:08:12 +0000528 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000529 cast<TemplateSpecializationType>(T));
Mike Stump11289f42009-09-09 15:08:12 +0000530
Douglas Gregord6ff3322009-08-04 16:50:30 +0000531 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000532 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000533
534 /// \brief Build a new typename type that refers to an identifier.
535 ///
536 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000537 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000538 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000539 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall0ad16662009-10-29 08:12:44 +0000540 const IdentifierInfo *Id,
541 SourceRange SR) {
542 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregor1135c352009-08-06 05:28:30 +0000543 }
Mike Stump11289f42009-09-09 15:08:12 +0000544
Douglas Gregor1135c352009-08-06 05:28:30 +0000545 /// \brief Build a new nested-name-specifier given the prefix and an
546 /// identifier that names the next step in the nested-name-specifier.
547 ///
548 /// By default, performs semantic analysis when building the new
549 /// nested-name-specifier. Subclasses may override this routine to provide
550 /// different behavior.
551 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
552 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000553 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000554 QualType ObjectType,
555 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000556
557 /// \brief Build a new nested-name-specifier given the prefix and the
558 /// namespace named in the next step in the nested-name-specifier.
559 ///
560 /// By default, performs semantic analysis when building the new
561 /// nested-name-specifier. Subclasses may override this routine to provide
562 /// different behavior.
563 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
564 SourceRange Range,
565 NamespaceDecl *NS);
566
567 /// \brief Build a new nested-name-specifier given the prefix and the
568 /// type named in the next step in the nested-name-specifier.
569 ///
570 /// By default, performs semantic analysis when building the new
571 /// nested-name-specifier. Subclasses may override this routine to provide
572 /// different behavior.
573 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
574 SourceRange Range,
575 bool TemplateKW,
576 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000577
578 /// \brief Build a new template name given a nested name specifier, a flag
579 /// indicating whether the "template" keyword was provided, and the template
580 /// that the template name refers to.
581 ///
582 /// By default, builds the new template name directly. Subclasses may override
583 /// this routine to provide different behavior.
584 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
585 bool TemplateKW,
586 TemplateDecl *Template);
587
Douglas Gregor71dc5092009-08-06 06:41:21 +0000588 /// \brief Build a new template name given a nested name specifier and the
589 /// name that is referred to as a template.
590 ///
591 /// By default, performs semantic analysis to determine whether the name can
592 /// be resolved to a specific template, then builds the appropriate kind of
593 /// template name. Subclasses may override this routine to provide different
594 /// behavior.
595 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000596 const IdentifierInfo &II,
597 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000598
Douglas Gregor71395fa2009-11-04 00:56:37 +0000599 /// \brief Build a new template name given a nested name specifier and the
600 /// overloaded operator name that is referred to as a template.
601 ///
602 /// By default, performs semantic analysis to determine whether the name can
603 /// be resolved to a specific template, then builds the appropriate kind of
604 /// template name. Subclasses may override this routine to provide different
605 /// behavior.
606 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
607 OverloadedOperatorKind Operator,
608 QualType ObjectType);
609
Douglas Gregorebe10102009-08-20 07:17:43 +0000610 /// \brief Build a new compound statement.
611 ///
612 /// By default, performs semantic analysis to build the new statement.
613 /// Subclasses may override this routine to provide different behavior.
614 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
615 MultiStmtArg Statements,
616 SourceLocation RBraceLoc,
617 bool IsStmtExpr) {
618 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
619 IsStmtExpr);
620 }
621
622 /// \brief Build a new case statement.
623 ///
624 /// By default, performs semantic analysis to build the new statement.
625 /// Subclasses may override this routine to provide different behavior.
626 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
627 ExprArg LHS,
628 SourceLocation EllipsisLoc,
629 ExprArg RHS,
630 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000631 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000632 ColonLoc);
633 }
Mike Stump11289f42009-09-09 15:08:12 +0000634
Douglas Gregorebe10102009-08-20 07:17:43 +0000635 /// \brief Attach the body to a new case statement.
636 ///
637 /// By default, performs semantic analysis to build the new statement.
638 /// Subclasses may override this routine to provide different behavior.
639 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
640 getSema().ActOnCaseStmtBody(S.get(), move(Body));
641 return move(S);
642 }
Mike Stump11289f42009-09-09 15:08:12 +0000643
Douglas Gregorebe10102009-08-20 07:17:43 +0000644 /// \brief Build a new default statement.
645 ///
646 /// By default, performs semantic analysis to build the new statement.
647 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000648 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000649 SourceLocation ColonLoc,
650 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000651 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000652 /*CurScope=*/0);
653 }
Mike Stump11289f42009-09-09 15:08:12 +0000654
Douglas Gregorebe10102009-08-20 07:17:43 +0000655 /// \brief Build a new label statement.
656 ///
657 /// By default, performs semantic analysis to build the new statement.
658 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000659 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000660 IdentifierInfo *Id,
661 SourceLocation ColonLoc,
662 StmtArg SubStmt) {
663 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
664 }
Mike Stump11289f42009-09-09 15:08:12 +0000665
Douglas Gregorebe10102009-08-20 07:17:43 +0000666 /// \brief Build a new "if" statement.
667 ///
668 /// By default, performs semantic analysis to build the new statement.
669 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000670 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000671 VarDecl *CondVar, StmtArg Then,
672 SourceLocation ElseLoc, StmtArg Else) {
673 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
674 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000675 }
Mike Stump11289f42009-09-09 15:08:12 +0000676
Douglas Gregorebe10102009-08-20 07:17:43 +0000677 /// \brief Start building a new switch statement.
678 ///
679 /// By default, performs semantic analysis to build the new statement.
680 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000681 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
682 VarDecl *CondVar) {
683 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000684 }
Mike Stump11289f42009-09-09 15:08:12 +0000685
Douglas Gregorebe10102009-08-20 07:17:43 +0000686 /// \brief Attach the body to the switch statement.
687 ///
688 /// By default, performs semantic analysis to build the new statement.
689 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000690 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000691 StmtArg Switch, StmtArg Body) {
692 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
693 move(Body));
694 }
695
696 /// \brief Build a new while statement.
697 ///
698 /// By default, performs semantic analysis to build the new statement.
699 /// Subclasses may override this routine to provide different behavior.
700 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
701 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000702 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000703 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000704 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
705 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000706 }
Mike Stump11289f42009-09-09 15:08:12 +0000707
Douglas Gregorebe10102009-08-20 07:17:43 +0000708 /// \brief Build a new do-while statement.
709 ///
710 /// By default, performs semantic analysis to build the new statement.
711 /// Subclasses may override this routine to provide different behavior.
712 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
713 SourceLocation WhileLoc,
714 SourceLocation LParenLoc,
715 ExprArg Cond,
716 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000717 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000718 move(Cond), RParenLoc);
719 }
720
721 /// \brief Build a new for statement.
722 ///
723 /// By default, performs semantic analysis to build the new statement.
724 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000725 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000726 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000727 StmtArg Init, Sema::FullExprArg Cond,
728 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000729 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000730 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
731 DeclPtrTy::make(CondVar),
732 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000733 }
Mike Stump11289f42009-09-09 15:08:12 +0000734
Douglas Gregorebe10102009-08-20 07:17:43 +0000735 /// \brief Build a new goto statement.
736 ///
737 /// By default, performs semantic analysis to build the new statement.
738 /// Subclasses may override this routine to provide different behavior.
739 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
740 SourceLocation LabelLoc,
741 LabelStmt *Label) {
742 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
743 }
744
745 /// \brief Build a new indirect goto statement.
746 ///
747 /// By default, performs semantic analysis to build the new statement.
748 /// Subclasses may override this routine to provide different behavior.
749 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
750 SourceLocation StarLoc,
751 ExprArg Target) {
752 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
753 }
Mike Stump11289f42009-09-09 15:08:12 +0000754
Douglas Gregorebe10102009-08-20 07:17:43 +0000755 /// \brief Build a new return statement.
756 ///
757 /// By default, performs semantic analysis to build the new statement.
758 /// Subclasses may override this routine to provide different behavior.
759 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
760 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000761
Douglas Gregorebe10102009-08-20 07:17:43 +0000762 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
763 }
Mike Stump11289f42009-09-09 15:08:12 +0000764
Douglas Gregorebe10102009-08-20 07:17:43 +0000765 /// \brief Build a new declaration statement.
766 ///
767 /// By default, performs semantic analysis to build the new statement.
768 /// Subclasses may override this routine to provide different behavior.
769 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000770 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000771 SourceLocation EndLoc) {
772 return getSema().Owned(
773 new (getSema().Context) DeclStmt(
774 DeclGroupRef::Create(getSema().Context,
775 Decls, NumDecls),
776 StartLoc, EndLoc));
777 }
Mike Stump11289f42009-09-09 15:08:12 +0000778
Douglas Gregorebe10102009-08-20 07:17:43 +0000779 /// \brief Build a new C++ exception declaration.
780 ///
781 /// By default, performs semantic analysis to build the new decaration.
782 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000783 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000784 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000785 IdentifierInfo *Name,
786 SourceLocation Loc,
787 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000788 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000789 TypeRange);
790 }
791
792 /// \brief Build a new C++ catch statement.
793 ///
794 /// By default, performs semantic analysis to build the new statement.
795 /// Subclasses may override this routine to provide different behavior.
796 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
797 VarDecl *ExceptionDecl,
798 StmtArg Handler) {
799 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000800 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000801 Handler.takeAs<Stmt>()));
802 }
Mike Stump11289f42009-09-09 15:08:12 +0000803
Douglas Gregorebe10102009-08-20 07:17:43 +0000804 /// \brief Build a new C++ try statement.
805 ///
806 /// By default, performs semantic analysis to build the new statement.
807 /// Subclasses may override this routine to provide different behavior.
808 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
809 StmtArg TryBlock,
810 MultiStmtArg Handlers) {
811 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
812 }
Mike Stump11289f42009-09-09 15:08:12 +0000813
Douglas Gregora16548e2009-08-11 05:31:07 +0000814 /// \brief Build a new expression that references a declaration.
815 ///
816 /// By default, performs semantic analysis to build the new expression.
817 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +0000818 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
819 LookupResult &R,
820 bool RequiresADL) {
821 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
822 }
823
824
825 /// \brief Build a new expression that references a declaration.
826 ///
827 /// By default, performs semantic analysis to build the new expression.
828 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000829 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
830 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +0000831 ValueDecl *VD, SourceLocation Loc,
832 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000833 CXXScopeSpec SS;
834 SS.setScopeRep(Qualifier);
835 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +0000836
837 // FIXME: loses template args.
838
839 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +0000840 }
Mike Stump11289f42009-09-09 15:08:12 +0000841
Douglas Gregora16548e2009-08-11 05:31:07 +0000842 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000843 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000844 /// By default, performs semantic analysis to build the new expression.
845 /// Subclasses may override this routine to provide different behavior.
846 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
847 SourceLocation RParen) {
848 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
849 }
850
Douglas Gregorad8a3362009-09-04 17:36:40 +0000851 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000852 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000853 /// By default, performs semantic analysis to build the new expression.
854 /// Subclasses may override this routine to provide different behavior.
855 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
856 SourceLocation OperatorLoc,
857 bool isArrow,
858 SourceLocation DestroyedTypeLoc,
859 QualType DestroyedType,
860 NestedNameSpecifier *Qualifier,
861 SourceRange QualifierRange) {
862 CXXScopeSpec SS;
863 if (Qualifier) {
864 SS.setRange(QualifierRange);
865 SS.setScopeRep(Qualifier);
866 }
867
John McCall2d74de92009-12-01 22:10:20 +0000868 QualType BaseType = ((Expr*) Base.get())->getType();
869
Mike Stump11289f42009-09-09 15:08:12 +0000870 DeclarationName Name
Douglas Gregorad8a3362009-09-04 17:36:40 +0000871 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
872 SemaRef.Context.getCanonicalType(DestroyedType));
Mike Stump11289f42009-09-09 15:08:12 +0000873
John McCall2d74de92009-12-01 22:10:20 +0000874 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
875 OperatorLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +0000876 SS, /*FIXME: FirstQualifier*/ 0,
877 Name, DestroyedTypeLoc,
878 /*TemplateArgs*/ 0);
Mike Stump11289f42009-09-09 15:08:12 +0000879 }
880
Douglas Gregora16548e2009-08-11 05:31:07 +0000881 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000882 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000883 /// By default, performs semantic analysis to build the new expression.
884 /// Subclasses may override this routine to provide different behavior.
885 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
886 UnaryOperator::Opcode Opc,
887 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000888 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +0000889 }
Mike Stump11289f42009-09-09 15:08:12 +0000890
Douglas Gregora16548e2009-08-11 05:31:07 +0000891 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000892 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000893 /// By default, performs semantic analysis to build the new expression.
894 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +0000895 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +0000896 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000897 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +0000898 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +0000899 }
900
Mike Stump11289f42009-09-09 15:08:12 +0000901 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000902 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +0000903 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000904 /// By default, performs semantic analysis to build the new expression.
905 /// Subclasses may override this routine to provide different behavior.
906 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
907 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +0000908 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000909 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
910 OpLoc, isSizeOf, R);
911 if (Result.isInvalid())
912 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000913
Douglas Gregora16548e2009-08-11 05:31:07 +0000914 SubExpr.release();
915 return move(Result);
916 }
Mike Stump11289f42009-09-09 15:08:12 +0000917
Douglas Gregora16548e2009-08-11 05:31:07 +0000918 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +0000919 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000920 /// By default, performs semantic analysis to build the new expression.
921 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000922 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000923 SourceLocation LBracketLoc,
924 ExprArg RHS,
925 SourceLocation RBracketLoc) {
926 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000927 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000928 RBracketLoc);
929 }
930
931 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000932 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000933 /// By default, performs semantic analysis to build the new expression.
934 /// Subclasses may override this routine to provide different behavior.
935 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
936 MultiExprArg Args,
937 SourceLocation *CommaLocs,
938 SourceLocation RParenLoc) {
939 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
940 move(Args), CommaLocs, RParenLoc);
941 }
942
943 /// \brief Build a new member access 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 RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000948 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000949 NestedNameSpecifier *Qualifier,
950 SourceRange QualifierRange,
951 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +0000952 ValueDecl *Member,
John McCall6b51f282009-11-23 01:53:49 +0000953 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000954 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +0000955 if (!Member->getDeclName()) {
956 // We have a reference to an unnamed field.
957 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +0000958
959 MemberExpr *ME =
Anders Carlsson5da84842009-09-01 04:26:58 +0000960 new (getSema().Context) MemberExpr(Base.takeAs<Expr>(), isArrow,
961 Member, MemberLoc,
962 cast<FieldDecl>(Member)->getType());
963 return getSema().Owned(ME);
964 }
Mike Stump11289f42009-09-09 15:08:12 +0000965
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000966 CXXScopeSpec SS;
967 if (Qualifier) {
968 SS.setRange(QualifierRange);
969 SS.setScopeRep(Qualifier);
970 }
971
John McCall2d74de92009-12-01 22:10:20 +0000972 QualType BaseType = ((Expr*) Base.get())->getType();
973
974 // FIXME: wait, this is re-performing lookup?
975 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
976 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +0000977 SS, FirstQualifierInScope,
978 Member->getDeclName(), MemberLoc,
979 ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +0000980 }
Mike Stump11289f42009-09-09 15:08:12 +0000981
Douglas Gregora16548e2009-08-11 05:31:07 +0000982 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000983 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000984 /// By default, performs semantic analysis to build the new expression.
985 /// Subclasses may override this routine to provide different behavior.
986 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
987 BinaryOperator::Opcode Opc,
988 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000989 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
990 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +0000991 }
992
993 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000994 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000995 /// By default, performs semantic analysis to build the new expression.
996 /// Subclasses may override this routine to provide different behavior.
997 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
998 SourceLocation QuestionLoc,
999 ExprArg LHS,
1000 SourceLocation ColonLoc,
1001 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001002 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001003 move(LHS), move(RHS));
1004 }
1005
Douglas Gregora16548e2009-08-11 05:31:07 +00001006 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001007 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001008 /// By default, performs semantic analysis to build the new expression.
1009 /// Subclasses may override this routine to provide different behavior.
1010 OwningExprResult RebuildCStyleCaseExpr(SourceLocation LParenLoc,
1011 QualType ExplicitTy,
1012 SourceLocation RParenLoc,
1013 ExprArg SubExpr) {
1014 return getSema().ActOnCastExpr(/*Scope=*/0,
1015 LParenLoc,
1016 ExplicitTy.getAsOpaquePtr(),
1017 RParenLoc,
1018 move(SubExpr));
1019 }
Mike Stump11289f42009-09-09 15:08:12 +00001020
Douglas Gregora16548e2009-08-11 05:31:07 +00001021 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001022 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001023 /// By default, performs semantic analysis to build the new expression.
1024 /// Subclasses may override this routine to provide different behavior.
1025 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
1026 QualType T,
1027 SourceLocation RParenLoc,
1028 ExprArg Init) {
1029 return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(),
1030 RParenLoc, move(Init));
1031 }
Mike Stump11289f42009-09-09 15:08:12 +00001032
Douglas Gregora16548e2009-08-11 05:31:07 +00001033 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001034 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001035 /// By default, performs semantic analysis to build the new expression.
1036 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001037 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001038 SourceLocation OpLoc,
1039 SourceLocation AccessorLoc,
1040 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001041
John McCall10eae182009-11-30 22:42:35 +00001042 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001043 QualType BaseType = ((Expr*) Base.get())->getType();
1044 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001045 OpLoc, /*IsArrow*/ false,
1046 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001047 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001048 AccessorLoc,
1049 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001050 }
Mike Stump11289f42009-09-09 15:08:12 +00001051
Douglas Gregora16548e2009-08-11 05:31:07 +00001052 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001053 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001054 /// By default, performs semantic analysis to build the new expression.
1055 /// Subclasses may override this routine to provide different behavior.
1056 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1057 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001058 SourceLocation RBraceLoc,
1059 QualType ResultTy) {
1060 OwningExprResult Result
1061 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1062 if (Result.isInvalid() || ResultTy->isDependentType())
1063 return move(Result);
1064
1065 // Patch in the result type we were given, which may have been computed
1066 // when the initial InitListExpr was built.
1067 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1068 ILE->setType(ResultTy);
1069 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001070 }
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregora16548e2009-08-11 05:31:07 +00001072 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001073 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001074 /// By default, performs semantic analysis to build the new expression.
1075 /// Subclasses may override this routine to provide different behavior.
1076 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1077 MultiExprArg ArrayExprs,
1078 SourceLocation EqualOrColonLoc,
1079 bool GNUSyntax,
1080 ExprArg Init) {
1081 OwningExprResult Result
1082 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1083 move(Init));
1084 if (Result.isInvalid())
1085 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001086
Douglas Gregora16548e2009-08-11 05:31:07 +00001087 ArrayExprs.release();
1088 return move(Result);
1089 }
Mike Stump11289f42009-09-09 15:08:12 +00001090
Douglas Gregora16548e2009-08-11 05:31:07 +00001091 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001092 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001093 /// By default, builds the implicit value initialization without performing
1094 /// any semantic analysis. Subclasses may override this routine to provide
1095 /// different behavior.
1096 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1097 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1098 }
Mike Stump11289f42009-09-09 15:08:12 +00001099
Douglas Gregora16548e2009-08-11 05:31:07 +00001100 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001101 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001102 /// By default, performs semantic analysis to build the new expression.
1103 /// Subclasses may override this routine to provide different behavior.
1104 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1105 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001106 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001107 RParenLoc);
1108 }
1109
1110 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001111 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001112 /// By default, performs semantic analysis to build the new expression.
1113 /// Subclasses may override this routine to provide different behavior.
1114 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1115 MultiExprArg SubExprs,
1116 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001117 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1118 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001119 }
Mike Stump11289f42009-09-09 15:08:12 +00001120
Douglas Gregora16548e2009-08-11 05:31:07 +00001121 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001122 ///
1123 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001124 /// rather than attempting to map the label statement itself.
1125 /// Subclasses may override this routine to provide different behavior.
1126 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1127 SourceLocation LabelLoc,
1128 LabelStmt *Label) {
1129 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1130 }
Mike Stump11289f42009-09-09 15:08:12 +00001131
Douglas Gregora16548e2009-08-11 05:31:07 +00001132 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001133 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001134 /// By default, performs semantic analysis to build the new expression.
1135 /// Subclasses may override this routine to provide different behavior.
1136 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1137 StmtArg SubStmt,
1138 SourceLocation RParenLoc) {
1139 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1140 }
Mike Stump11289f42009-09-09 15:08:12 +00001141
Douglas Gregora16548e2009-08-11 05:31:07 +00001142 /// \brief Build a new __builtin_types_compatible_p expression.
1143 ///
1144 /// By default, performs semantic analysis to build the new expression.
1145 /// Subclasses may override this routine to provide different behavior.
1146 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1147 QualType T1, QualType T2,
1148 SourceLocation RParenLoc) {
1149 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1150 T1.getAsOpaquePtr(),
1151 T2.getAsOpaquePtr(),
1152 RParenLoc);
1153 }
Mike Stump11289f42009-09-09 15:08:12 +00001154
Douglas Gregora16548e2009-08-11 05:31:07 +00001155 /// \brief Build a new __builtin_choose_expr expression.
1156 ///
1157 /// By default, performs semantic analysis to build the new expression.
1158 /// Subclasses may override this routine to provide different behavior.
1159 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1160 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1161 SourceLocation RParenLoc) {
1162 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1163 move(Cond), move(LHS), move(RHS),
1164 RParenLoc);
1165 }
Mike Stump11289f42009-09-09 15:08:12 +00001166
Douglas Gregora16548e2009-08-11 05:31:07 +00001167 /// \brief Build a new overloaded operator call expression.
1168 ///
1169 /// By default, performs semantic analysis to build the new expression.
1170 /// The semantic analysis provides the behavior of template instantiation,
1171 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001172 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001173 /// argument-dependent lookup, etc. Subclasses may override this routine to
1174 /// provide different behavior.
1175 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1176 SourceLocation OpLoc,
1177 ExprArg Callee,
1178 ExprArg First,
1179 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001180
1181 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001182 /// reinterpret_cast.
1183 ///
1184 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001185 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001186 /// Subclasses may override this routine to provide different behavior.
1187 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1188 Stmt::StmtClass Class,
1189 SourceLocation LAngleLoc,
1190 QualType T,
1191 SourceLocation RAngleLoc,
1192 SourceLocation LParenLoc,
1193 ExprArg SubExpr,
1194 SourceLocation RParenLoc) {
1195 switch (Class) {
1196 case Stmt::CXXStaticCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001197 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T,
1198 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001199 move(SubExpr), RParenLoc);
1200
1201 case Stmt::CXXDynamicCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001202 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T,
1203 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001204 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001205
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 case Stmt::CXXReinterpretCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001207 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T,
1208 RAngleLoc, LParenLoc,
1209 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001210 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001211
Douglas Gregora16548e2009-08-11 05:31:07 +00001212 case Stmt::CXXConstCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001213 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T,
1214 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001216
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 default:
1218 assert(false && "Invalid C++ named cast");
1219 break;
1220 }
Mike Stump11289f42009-09-09 15:08:12 +00001221
Douglas Gregora16548e2009-08-11 05:31:07 +00001222 return getSema().ExprError();
1223 }
Mike Stump11289f42009-09-09 15:08:12 +00001224
Douglas Gregora16548e2009-08-11 05:31:07 +00001225 /// \brief Build a new C++ static_cast expression.
1226 ///
1227 /// By default, performs semantic analysis to build the new expression.
1228 /// Subclasses may override this routine to provide different behavior.
1229 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1230 SourceLocation LAngleLoc,
1231 QualType T,
1232 SourceLocation RAngleLoc,
1233 SourceLocation LParenLoc,
1234 ExprArg SubExpr,
1235 SourceLocation RParenLoc) {
1236 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001237 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001238 LParenLoc, move(SubExpr), RParenLoc);
1239 }
1240
1241 /// \brief Build a new C++ dynamic_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 RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1246 SourceLocation LAngleLoc,
1247 QualType T,
1248 SourceLocation RAngleLoc,
1249 SourceLocation LParenLoc,
1250 ExprArg SubExpr,
1251 SourceLocation RParenLoc) {
1252 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001253 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001254 LParenLoc, move(SubExpr), RParenLoc);
1255 }
1256
1257 /// \brief Build a new C++ reinterpret_cast expression.
1258 ///
1259 /// By default, performs semantic analysis to build the new expression.
1260 /// Subclasses may override this routine to provide different behavior.
1261 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1262 SourceLocation LAngleLoc,
1263 QualType T,
1264 SourceLocation RAngleLoc,
1265 SourceLocation LParenLoc,
1266 ExprArg SubExpr,
1267 SourceLocation RParenLoc) {
1268 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1269 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
1270 LParenLoc, move(SubExpr), RParenLoc);
1271 }
1272
1273 /// \brief Build a new C++ const_cast expression.
1274 ///
1275 /// By default, performs semantic analysis to build the new expression.
1276 /// Subclasses may override this routine to provide different behavior.
1277 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1278 SourceLocation LAngleLoc,
1279 QualType T,
1280 SourceLocation RAngleLoc,
1281 SourceLocation LParenLoc,
1282 ExprArg SubExpr,
1283 SourceLocation RParenLoc) {
1284 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001285 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001286 LParenLoc, move(SubExpr), RParenLoc);
1287 }
Mike Stump11289f42009-09-09 15:08:12 +00001288
Douglas Gregora16548e2009-08-11 05:31:07 +00001289 /// \brief Build a new C++ functional-style cast expression.
1290 ///
1291 /// By default, performs semantic analysis to build the new expression.
1292 /// Subclasses may override this routine to provide different behavior.
1293 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
1294 QualType T,
1295 SourceLocation LParenLoc,
1296 ExprArg SubExpr,
1297 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001298 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001299 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
1300 T.getAsOpaquePtr(),
1301 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001302 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001303 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001304 RParenLoc);
1305 }
Mike Stump11289f42009-09-09 15:08:12 +00001306
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 /// \brief Build a new C++ typeid(type) expression.
1308 ///
1309 /// By default, performs semantic analysis to build the new expression.
1310 /// Subclasses may override this routine to provide different behavior.
1311 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1312 SourceLocation LParenLoc,
1313 QualType T,
1314 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001315 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001316 T.getAsOpaquePtr(), RParenLoc);
1317 }
Mike Stump11289f42009-09-09 15:08:12 +00001318
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 /// \brief Build a new C++ typeid(expr) expression.
1320 ///
1321 /// By default, performs semantic analysis to build the new expression.
1322 /// Subclasses may override this routine to provide different behavior.
1323 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1324 SourceLocation LParenLoc,
1325 ExprArg Operand,
1326 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001327 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1329 RParenLoc);
1330 if (Result.isInvalid())
1331 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001332
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1334 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001335 }
1336
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 /// \brief Build a new C++ "this" expression.
1338 ///
1339 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001340 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001342 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 QualType ThisType) {
1344 return getSema().Owned(
1345 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType));
1346 }
1347
1348 /// \brief Build a new C++ throw expression.
1349 ///
1350 /// By default, performs semantic analysis to build the new expression.
1351 /// Subclasses may override this routine to provide different behavior.
1352 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1353 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1354 }
1355
1356 /// \brief Build a new C++ default-argument expression.
1357 ///
1358 /// By default, builds a new default-argument expression, which does not
1359 /// require any semantic analysis. Subclasses may override this routine to
1360 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001361 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1362 ParmVarDecl *Param) {
1363 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1364 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 }
1366
1367 /// \brief Build a new C++ zero-initialization expression.
1368 ///
1369 /// By default, performs semantic analysis to build the new expression.
1370 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001371 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001372 SourceLocation LParenLoc,
1373 QualType T,
1374 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001375 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1376 T.getAsOpaquePtr(), LParenLoc,
1377 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001378 0, RParenLoc);
1379 }
Mike Stump11289f42009-09-09 15:08:12 +00001380
Douglas Gregora16548e2009-08-11 05:31:07 +00001381 /// \brief Build a new C++ "new" expression.
1382 ///
1383 /// By default, performs semantic analysis to build the new expression.
1384 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001385 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 bool UseGlobal,
1387 SourceLocation PlacementLParen,
1388 MultiExprArg PlacementArgs,
1389 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001390 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001391 QualType AllocType,
1392 SourceLocation TypeLoc,
1393 SourceRange TypeRange,
1394 ExprArg ArraySize,
1395 SourceLocation ConstructorLParen,
1396 MultiExprArg ConstructorArgs,
1397 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001398 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001399 PlacementLParen,
1400 move(PlacementArgs),
1401 PlacementRParen,
1402 ParenTypeId,
1403 AllocType,
1404 TypeLoc,
1405 TypeRange,
1406 move(ArraySize),
1407 ConstructorLParen,
1408 move(ConstructorArgs),
1409 ConstructorRParen);
1410 }
Mike Stump11289f42009-09-09 15:08:12 +00001411
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 /// \brief Build a new C++ "delete" expression.
1413 ///
1414 /// By default, performs semantic analysis to build the new expression.
1415 /// Subclasses may override this routine to provide different behavior.
1416 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1417 bool IsGlobalDelete,
1418 bool IsArrayForm,
1419 ExprArg Operand) {
1420 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1421 move(Operand));
1422 }
Mike Stump11289f42009-09-09 15:08:12 +00001423
Douglas Gregora16548e2009-08-11 05:31:07 +00001424 /// \brief Build a new unary type trait expression.
1425 ///
1426 /// By default, performs semantic analysis to build the new expression.
1427 /// Subclasses may override this routine to provide different behavior.
1428 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1429 SourceLocation StartLoc,
1430 SourceLocation LParenLoc,
1431 QualType T,
1432 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001433 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 T.getAsOpaquePtr(), RParenLoc);
1435 }
1436
Mike Stump11289f42009-09-09 15:08:12 +00001437 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001438 /// expression.
1439 ///
1440 /// By default, performs semantic analysis to build the new expression.
1441 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001442 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001443 SourceRange QualifierRange,
1444 DeclarationName Name,
1445 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001446 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001447 CXXScopeSpec SS;
1448 SS.setRange(QualifierRange);
1449 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001450
1451 if (TemplateArgs)
1452 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1453 *TemplateArgs);
1454
1455 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 }
1457
1458 /// \brief Build a new template-id expression.
1459 ///
1460 /// By default, performs semantic analysis to build the new expression.
1461 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001462 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1463 LookupResult &R,
1464 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001465 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001466 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001467 }
1468
1469 /// \brief Build a new object-construction expression.
1470 ///
1471 /// By default, performs semantic analysis to build the new expression.
1472 /// Subclasses may override this routine to provide different behavior.
1473 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001474 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 CXXConstructorDecl *Constructor,
1476 bool IsElidable,
1477 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001478 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1479 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1480 ConvertedArgs))
1481 return getSema().ExprError();
1482
1483 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1484 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001485 }
1486
1487 /// \brief Build a new object-construction expression.
1488 ///
1489 /// By default, performs semantic analysis to build the new expression.
1490 /// Subclasses may override this routine to provide different behavior.
1491 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1492 QualType T,
1493 SourceLocation LParenLoc,
1494 MultiExprArg Args,
1495 SourceLocation *Commas,
1496 SourceLocation RParenLoc) {
1497 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1498 T.getAsOpaquePtr(),
1499 LParenLoc,
1500 move(Args),
1501 Commas,
1502 RParenLoc);
1503 }
1504
1505 /// \brief Build a new object-construction expression.
1506 ///
1507 /// By default, performs semantic analysis to build the new expression.
1508 /// Subclasses may override this routine to provide different behavior.
1509 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1510 QualType T,
1511 SourceLocation LParenLoc,
1512 MultiExprArg Args,
1513 SourceLocation *Commas,
1514 SourceLocation RParenLoc) {
1515 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1516 /*FIXME*/LParenLoc),
1517 T.getAsOpaquePtr(),
1518 LParenLoc,
1519 move(Args),
1520 Commas,
1521 RParenLoc);
1522 }
Mike Stump11289f42009-09-09 15:08:12 +00001523
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 /// \brief Build a new member reference expression.
1525 ///
1526 /// By default, performs semantic analysis to build the new expression.
1527 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001528 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001529 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 bool IsArrow,
1531 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001532 NestedNameSpecifier *Qualifier,
1533 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001534 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001535 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001536 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001537 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001538 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001539 SS.setRange(QualifierRange);
1540 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001541
John McCall2d74de92009-12-01 22:10:20 +00001542 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1543 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001544 SS, FirstQualifierInScope,
1545 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001546 }
1547
John McCall10eae182009-11-30 22:42:35 +00001548 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001549 ///
1550 /// By default, performs semantic analysis to build the new expression.
1551 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001552 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001553 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001554 SourceLocation OperatorLoc,
1555 bool IsArrow,
1556 NestedNameSpecifier *Qualifier,
1557 SourceRange QualifierRange,
1558 LookupResult &R,
1559 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001560 CXXScopeSpec SS;
1561 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, R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001567 }
Mike Stump11289f42009-09-09 15:08:12 +00001568
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 /// \brief Build a new Objective-C @encode expression.
1570 ///
1571 /// By default, performs semantic analysis to build the new expression.
1572 /// Subclasses may override this routine to provide different behavior.
1573 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1574 QualType T,
1575 SourceLocation RParenLoc) {
1576 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1577 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001578 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001579
1580 /// \brief Build a new Objective-C protocol expression.
1581 ///
1582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
1584 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1585 SourceLocation AtLoc,
1586 SourceLocation ProtoLoc,
1587 SourceLocation LParenLoc,
1588 SourceLocation RParenLoc) {
1589 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1590 Protocol->getIdentifier(),
1591 AtLoc,
1592 ProtoLoc,
1593 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001594 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 }
Mike Stump11289f42009-09-09 15:08:12 +00001596
Douglas Gregora16548e2009-08-11 05:31:07 +00001597 /// \brief Build a new shuffle vector expression.
1598 ///
1599 /// By default, performs semantic analysis to build the new expression.
1600 /// Subclasses may override this routine to provide different behavior.
1601 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1602 MultiExprArg SubExprs,
1603 SourceLocation RParenLoc) {
1604 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001605 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001606 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1607 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1608 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1609 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001610
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 // Build a reference to the __builtin_shufflevector builtin
1612 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001613 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001615 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001617
1618 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 unsigned NumSubExprs = SubExprs.size();
1620 Expr **Subs = (Expr **)SubExprs.release();
1621 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1622 Subs, NumSubExprs,
1623 Builtin->getResultType(),
1624 RParenLoc);
1625 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001626
Douglas Gregora16548e2009-08-11 05:31:07 +00001627 // Type-check the __builtin_shufflevector expression.
1628 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1629 if (Result.isInvalid())
1630 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001631
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001633 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001635};
Douglas Gregora16548e2009-08-11 05:31:07 +00001636
Douglas Gregorebe10102009-08-20 07:17:43 +00001637template<typename Derived>
1638Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1639 if (!S)
1640 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001641
Douglas Gregorebe10102009-08-20 07:17:43 +00001642 switch (S->getStmtClass()) {
1643 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001644
Douglas Gregorebe10102009-08-20 07:17:43 +00001645 // Transform individual statement nodes
1646#define STMT(Node, Parent) \
1647 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1648#define EXPR(Node, Parent)
1649#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001650
Douglas Gregorebe10102009-08-20 07:17:43 +00001651 // Transform expressions by calling TransformExpr.
1652#define STMT(Node, Parent)
1653#define EXPR(Node, Parent) case Stmt::Node##Class:
1654#include "clang/AST/StmtNodes.def"
1655 {
1656 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1657 if (E.isInvalid())
1658 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001659
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001660 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001661 }
Mike Stump11289f42009-09-09 15:08:12 +00001662 }
1663
Douglas Gregorebe10102009-08-20 07:17:43 +00001664 return SemaRef.Owned(S->Retain());
1665}
Mike Stump11289f42009-09-09 15:08:12 +00001666
1667
Douglas Gregore922c772009-08-04 22:27:00 +00001668template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001669Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001670 if (!E)
1671 return SemaRef.Owned(E);
1672
1673 switch (E->getStmtClass()) {
1674 case Stmt::NoStmtClass: break;
1675#define STMT(Node, Parent) case Stmt::Node##Class: break;
1676#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001677 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001678#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001679 }
1680
Douglas Gregora16548e2009-08-11 05:31:07 +00001681 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001682}
1683
1684template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001685NestedNameSpecifier *
1686TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001687 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001688 QualType ObjectType,
1689 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001690 if (!NNS)
1691 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001692
Douglas Gregorebe10102009-08-20 07:17:43 +00001693 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001694 NestedNameSpecifier *Prefix = NNS->getPrefix();
1695 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001696 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001697 ObjectType,
1698 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001699 if (!Prefix)
1700 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001701
1702 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001703 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001704 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001705 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001706 }
Mike Stump11289f42009-09-09 15:08:12 +00001707
Douglas Gregor1135c352009-08-06 05:28:30 +00001708 switch (NNS->getKind()) {
1709 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001710 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001711 "Identifier nested-name-specifier with no prefix or object type");
1712 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1713 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001714 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001715
1716 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001717 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001718 ObjectType,
1719 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001720
Douglas Gregor1135c352009-08-06 05:28:30 +00001721 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001722 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001723 = cast_or_null<NamespaceDecl>(
1724 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001725 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001726 Prefix == NNS->getPrefix() &&
1727 NS == NNS->getAsNamespace())
1728 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001729
Douglas Gregor1135c352009-08-06 05:28:30 +00001730 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1731 }
Mike Stump11289f42009-09-09 15:08:12 +00001732
Douglas Gregor1135c352009-08-06 05:28:30 +00001733 case NestedNameSpecifier::Global:
1734 // There is no meaningful transformation that one could perform on the
1735 // global scope.
1736 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001737
Douglas Gregor1135c352009-08-06 05:28:30 +00001738 case NestedNameSpecifier::TypeSpecWithTemplate:
1739 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001740 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor1135c352009-08-06 05:28:30 +00001741 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001742 if (T.isNull())
1743 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001744
Douglas Gregor1135c352009-08-06 05:28:30 +00001745 if (!getDerived().AlwaysRebuild() &&
1746 Prefix == NNS->getPrefix() &&
1747 T == QualType(NNS->getAsType(), 0))
1748 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001749
1750 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1751 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregor1135c352009-08-06 05:28:30 +00001752 T);
1753 }
1754 }
Mike Stump11289f42009-09-09 15:08:12 +00001755
Douglas Gregor1135c352009-08-06 05:28:30 +00001756 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001757 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001758}
1759
1760template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001761DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001762TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001763 SourceLocation Loc,
1764 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001765 if (!Name)
1766 return Name;
1767
1768 switch (Name.getNameKind()) {
1769 case DeclarationName::Identifier:
1770 case DeclarationName::ObjCZeroArgSelector:
1771 case DeclarationName::ObjCOneArgSelector:
1772 case DeclarationName::ObjCMultiArgSelector:
1773 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001774 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001775 case DeclarationName::CXXUsingDirective:
1776 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001777
Douglas Gregorf816bd72009-09-03 22:13:48 +00001778 case DeclarationName::CXXConstructorName:
1779 case DeclarationName::CXXDestructorName:
1780 case DeclarationName::CXXConversionFunctionName: {
1781 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorc59e5612009-10-19 22:04:39 +00001782 QualType T;
1783 if (!ObjectType.isNull() &&
1784 isa<TemplateSpecializationType>(Name.getCXXNameType())) {
1785 TemplateSpecializationType *SpecType
1786 = cast<TemplateSpecializationType>(Name.getCXXNameType());
1787 T = TransformTemplateSpecializationType(SpecType, ObjectType);
1788 } else
1789 T = getDerived().TransformType(Name.getCXXNameType());
Douglas Gregorf816bd72009-09-03 22:13:48 +00001790 if (T.isNull())
1791 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001792
Douglas Gregorf816bd72009-09-03 22:13:48 +00001793 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001794 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001795 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001796 }
Mike Stump11289f42009-09-09 15:08:12 +00001797 }
1798
Douglas Gregorf816bd72009-09-03 22:13:48 +00001799 return DeclarationName();
1800}
1801
1802template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001803TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001804TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1805 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00001806 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001807 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001808 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1809 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1810 if (!NNS)
1811 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001812
Douglas Gregor71dc5092009-08-06 06:41:21 +00001813 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001814 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001815 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1816 if (!TransTemplate)
1817 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001818
Douglas Gregor71dc5092009-08-06 06:41:21 +00001819 if (!getDerived().AlwaysRebuild() &&
1820 NNS == QTN->getQualifier() &&
1821 TransTemplate == Template)
1822 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001823
Douglas Gregor71dc5092009-08-06 06:41:21 +00001824 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1825 TransTemplate);
1826 }
Mike Stump11289f42009-09-09 15:08:12 +00001827
John McCalle66edc12009-11-24 19:00:30 +00001828 // These should be getting filtered out before they make it into the AST.
1829 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001830 }
Mike Stump11289f42009-09-09 15:08:12 +00001831
Douglas Gregor71dc5092009-08-06 06:41:21 +00001832 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001833 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001834 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1835 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor308047d2009-09-09 00:23:06 +00001836 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001837 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001838
Douglas Gregor71dc5092009-08-06 06:41:21 +00001839 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001840 NNS == DTN->getQualifier() &&
1841 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001842 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001843
Douglas Gregor71395fa2009-11-04 00:56:37 +00001844 if (DTN->isIdentifier())
1845 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1846 ObjectType);
1847
1848 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1849 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001850 }
Mike Stump11289f42009-09-09 15:08:12 +00001851
Douglas Gregor71dc5092009-08-06 06:41:21 +00001852 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001853 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001854 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1855 if (!TransTemplate)
1856 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001857
Douglas Gregor71dc5092009-08-06 06:41:21 +00001858 if (!getDerived().AlwaysRebuild() &&
1859 TransTemplate == Template)
1860 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001861
Douglas Gregor71dc5092009-08-06 06:41:21 +00001862 return TemplateName(TransTemplate);
1863 }
Mike Stump11289f42009-09-09 15:08:12 +00001864
John McCalle66edc12009-11-24 19:00:30 +00001865 // These should be getting filtered out before they reach the AST.
1866 assert(false && "overloaded function decl survived to here");
1867 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00001868}
1869
1870template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001871void TreeTransform<Derived>::InventTemplateArgumentLoc(
1872 const TemplateArgument &Arg,
1873 TemplateArgumentLoc &Output) {
1874 SourceLocation Loc = getDerived().getBaseLocation();
1875 switch (Arg.getKind()) {
1876 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00001877 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00001878 break;
1879
1880 case TemplateArgument::Type:
1881 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00001882 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00001883
1884 break;
1885
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001886 case TemplateArgument::Template:
1887 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1888 break;
1889
John McCall0ad16662009-10-29 08:12:44 +00001890 case TemplateArgument::Expression:
1891 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1892 break;
1893
1894 case TemplateArgument::Declaration:
1895 case TemplateArgument::Integral:
1896 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00001897 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00001898 break;
1899 }
1900}
1901
1902template<typename Derived>
1903bool TreeTransform<Derived>::TransformTemplateArgument(
1904 const TemplateArgumentLoc &Input,
1905 TemplateArgumentLoc &Output) {
1906 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00001907 switch (Arg.getKind()) {
1908 case TemplateArgument::Null:
1909 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001910 Output = Input;
1911 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001912
Douglas Gregore922c772009-08-04 22:27:00 +00001913 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00001914 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00001915 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00001916 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00001917
1918 DI = getDerived().TransformType(DI);
1919 if (!DI) return true;
1920
1921 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1922 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001923 }
Mike Stump11289f42009-09-09 15:08:12 +00001924
Douglas Gregore922c772009-08-04 22:27:00 +00001925 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001926 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001927 DeclarationName Name;
1928 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1929 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001930 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregore922c772009-08-04 22:27:00 +00001931 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001932 if (!D) return true;
1933
John McCall0d07eb32009-10-29 18:45:58 +00001934 Expr *SourceExpr = Input.getSourceDeclExpression();
1935 if (SourceExpr) {
1936 EnterExpressionEvaluationContext Unevaluated(getSema(),
1937 Action::Unevaluated);
1938 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1939 if (E.isInvalid())
1940 SourceExpr = NULL;
1941 else {
1942 SourceExpr = E.takeAs<Expr>();
1943 SourceExpr->Retain();
1944 }
1945 }
1946
1947 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00001948 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001949 }
Mike Stump11289f42009-09-09 15:08:12 +00001950
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001951 case TemplateArgument::Template: {
1952 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1953 TemplateName Template
1954 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1955 if (Template.isNull())
1956 return true;
1957
1958 Output = TemplateArgumentLoc(TemplateArgument(Template),
1959 Input.getTemplateQualifierRange(),
1960 Input.getTemplateNameLoc());
1961 return false;
1962 }
1963
Douglas Gregore922c772009-08-04 22:27:00 +00001964 case TemplateArgument::Expression: {
1965 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00001966 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00001967 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00001968
John McCall0ad16662009-10-29 08:12:44 +00001969 Expr *InputExpr = Input.getSourceExpression();
1970 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
1971
1972 Sema::OwningExprResult E
1973 = getDerived().TransformExpr(InputExpr);
1974 if (E.isInvalid()) return true;
1975
1976 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00001977 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00001978 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
1979 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001980 }
Mike Stump11289f42009-09-09 15:08:12 +00001981
Douglas Gregore922c772009-08-04 22:27:00 +00001982 case TemplateArgument::Pack: {
1983 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
1984 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00001985 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00001986 AEnd = Arg.pack_end();
1987 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00001988
John McCall0ad16662009-10-29 08:12:44 +00001989 // FIXME: preserve source information here when we start
1990 // caring about parameter packs.
1991
John McCall0d07eb32009-10-29 18:45:58 +00001992 TemplateArgumentLoc InputArg;
1993 TemplateArgumentLoc OutputArg;
1994 getDerived().InventTemplateArgumentLoc(*A, InputArg);
1995 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00001996 return true;
1997
John McCall0d07eb32009-10-29 18:45:58 +00001998 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00001999 }
2000 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002001 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002002 true);
John McCall0d07eb32009-10-29 18:45:58 +00002003 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002004 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002005 }
2006 }
Mike Stump11289f42009-09-09 15:08:12 +00002007
Douglas Gregore922c772009-08-04 22:27:00 +00002008 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002009 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002010}
2011
Douglas Gregord6ff3322009-08-04 16:50:30 +00002012//===----------------------------------------------------------------------===//
2013// Type transformation
2014//===----------------------------------------------------------------------===//
2015
2016template<typename Derived>
2017QualType TreeTransform<Derived>::TransformType(QualType T) {
2018 if (getDerived().AlreadyTransformed(T))
2019 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002020
John McCall550e0c22009-10-21 00:40:46 +00002021 // Temporary workaround. All of these transformations should
2022 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002023 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002024 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002025
John McCallbcd03502009-12-07 02:54:59 +00002026 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002027
John McCall550e0c22009-10-21 00:40:46 +00002028 if (!NewDI)
2029 return QualType();
2030
2031 return NewDI->getType();
2032}
2033
2034template<typename Derived>
John McCallbcd03502009-12-07 02:54:59 +00002035TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002036 if (getDerived().AlreadyTransformed(DI->getType()))
2037 return DI;
2038
2039 TypeLocBuilder TLB;
2040
2041 TypeLoc TL = DI->getTypeLoc();
2042 TLB.reserve(TL.getFullDataSize());
2043
2044 QualType Result = getDerived().TransformType(TLB, TL);
2045 if (Result.isNull())
2046 return 0;
2047
John McCallbcd03502009-12-07 02:54:59 +00002048 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002049}
2050
2051template<typename Derived>
2052QualType
2053TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
2054 switch (T.getTypeLocClass()) {
2055#define ABSTRACT_TYPELOC(CLASS, PARENT)
2056#define TYPELOC(CLASS, PARENT) \
2057 case TypeLoc::CLASS: \
2058 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2059#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002060 }
Mike Stump11289f42009-09-09 15:08:12 +00002061
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002062 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002063 return QualType();
2064}
2065
2066/// FIXME: By default, this routine adds type qualifiers only to types
2067/// that can have qualifiers, and silently suppresses those qualifiers
2068/// that are not permitted (e.g., qualifiers on reference or function
2069/// types). This is the right thing for template instantiation, but
2070/// probably not for other clients.
2071template<typename Derived>
2072QualType
2073TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
2074 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002075 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002076
2077 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2078 if (Result.isNull())
2079 return QualType();
2080
2081 // Silently suppress qualifiers if the result type can't be qualified.
2082 // FIXME: this is the right thing for template instantiation, but
2083 // probably not for other clients.
2084 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002085 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002086
John McCall550e0c22009-10-21 00:40:46 +00002087 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2088
2089 TLB.push<QualifiedTypeLoc>(Result);
2090
2091 // No location information to preserve.
2092
2093 return Result;
2094}
2095
2096template <class TyLoc> static inline
2097QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2098 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2099 NewT.setNameLoc(T.getNameLoc());
2100 return T.getType();
2101}
2102
2103// Ugly metaprogramming macros because I couldn't be bothered to make
2104// the equivalent template version work.
2105#define TransformPointerLikeType(TypeClass) do { \
2106 QualType PointeeType \
2107 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2108 if (PointeeType.isNull()) \
2109 return QualType(); \
2110 \
2111 QualType Result = TL.getType(); \
2112 if (getDerived().AlwaysRebuild() || \
2113 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall70dd5f62009-10-30 00:06:24 +00002114 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2115 TL.getSigilLoc()); \
John McCall550e0c22009-10-21 00:40:46 +00002116 if (Result.isNull()) \
2117 return QualType(); \
2118 } \
2119 \
2120 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2121 NewT.setSigilLoc(TL.getSigilLoc()); \
2122 \
2123 return Result; \
2124} while(0)
2125
John McCall550e0c22009-10-21 00:40:46 +00002126template<typename Derived>
2127QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
2128 BuiltinTypeLoc T) {
2129 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002130}
Mike Stump11289f42009-09-09 15:08:12 +00002131
Douglas Gregord6ff3322009-08-04 16:50:30 +00002132template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002133QualType
John McCall550e0c22009-10-21 00:40:46 +00002134TreeTransform<Derived>::TransformFixedWidthIntType(TypeLocBuilder &TLB,
2135 FixedWidthIntTypeLoc T) {
2136 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002137}
Argyrios Kyrtzidise9189262009-08-19 01:28:17 +00002138
Douglas Gregord6ff3322009-08-04 16:50:30 +00002139template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002140QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
2141 ComplexTypeLoc T) {
2142 // FIXME: recurse?
2143 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002144}
Mike Stump11289f42009-09-09 15:08:12 +00002145
Douglas Gregord6ff3322009-08-04 16:50:30 +00002146template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002147QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
2148 PointerTypeLoc TL) {
2149 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002150}
Mike Stump11289f42009-09-09 15:08:12 +00002151
2152template<typename Derived>
2153QualType
John McCall550e0c22009-10-21 00:40:46 +00002154TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
2155 BlockPointerTypeLoc TL) {
2156 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002157}
2158
John McCall70dd5f62009-10-30 00:06:24 +00002159/// Transforms a reference type. Note that somewhat paradoxically we
2160/// don't care whether the type itself is an l-value type or an r-value
2161/// type; we only care if the type was *written* as an l-value type
2162/// or an r-value type.
2163template<typename Derived>
2164QualType
2165TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
2166 ReferenceTypeLoc TL) {
2167 const ReferenceType *T = TL.getTypePtr();
2168
2169 // Note that this works with the pointee-as-written.
2170 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2171 if (PointeeType.isNull())
2172 return QualType();
2173
2174 QualType Result = TL.getType();
2175 if (getDerived().AlwaysRebuild() ||
2176 PointeeType != T->getPointeeTypeAsWritten()) {
2177 Result = getDerived().RebuildReferenceType(PointeeType,
2178 T->isSpelledAsLValue(),
2179 TL.getSigilLoc());
2180 if (Result.isNull())
2181 return QualType();
2182 }
2183
2184 // r-value references can be rebuilt as l-value references.
2185 ReferenceTypeLoc NewTL;
2186 if (isa<LValueReferenceType>(Result))
2187 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2188 else
2189 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2190 NewTL.setSigilLoc(TL.getSigilLoc());
2191
2192 return Result;
2193}
2194
Mike Stump11289f42009-09-09 15:08:12 +00002195template<typename Derived>
2196QualType
John McCall550e0c22009-10-21 00:40:46 +00002197TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
2198 LValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002199 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002200}
2201
Mike Stump11289f42009-09-09 15:08:12 +00002202template<typename Derived>
2203QualType
John McCall550e0c22009-10-21 00:40:46 +00002204TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
2205 RValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002206 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002207}
Mike Stump11289f42009-09-09 15:08:12 +00002208
Douglas Gregord6ff3322009-08-04 16:50:30 +00002209template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002210QualType
John McCall550e0c22009-10-21 00:40:46 +00002211TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
2212 MemberPointerTypeLoc TL) {
2213 MemberPointerType *T = TL.getTypePtr();
2214
2215 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002216 if (PointeeType.isNull())
2217 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002218
John McCall550e0c22009-10-21 00:40:46 +00002219 // TODO: preserve source information for this.
2220 QualType ClassType
2221 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002222 if (ClassType.isNull())
2223 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002224
John McCall550e0c22009-10-21 00:40:46 +00002225 QualType Result = TL.getType();
2226 if (getDerived().AlwaysRebuild() ||
2227 PointeeType != T->getPointeeType() ||
2228 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002229 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2230 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002231 if (Result.isNull())
2232 return QualType();
2233 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002234
John McCall550e0c22009-10-21 00:40:46 +00002235 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2236 NewTL.setSigilLoc(TL.getSigilLoc());
2237
2238 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002239}
2240
Mike Stump11289f42009-09-09 15:08:12 +00002241template<typename Derived>
2242QualType
John McCall550e0c22009-10-21 00:40:46 +00002243TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
2244 ConstantArrayTypeLoc TL) {
2245 ConstantArrayType *T = TL.getTypePtr();
2246 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002247 if (ElementType.isNull())
2248 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002249
John McCall550e0c22009-10-21 00:40:46 +00002250 QualType Result = TL.getType();
2251 if (getDerived().AlwaysRebuild() ||
2252 ElementType != T->getElementType()) {
2253 Result = getDerived().RebuildConstantArrayType(ElementType,
2254 T->getSizeModifier(),
2255 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002256 T->getIndexTypeCVRQualifiers(),
2257 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002258 if (Result.isNull())
2259 return QualType();
2260 }
2261
2262 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2263 NewTL.setLBracketLoc(TL.getLBracketLoc());
2264 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002265
John McCall550e0c22009-10-21 00:40:46 +00002266 Expr *Size = TL.getSizeExpr();
2267 if (Size) {
2268 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2269 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2270 }
2271 NewTL.setSizeExpr(Size);
2272
2273 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002274}
Mike Stump11289f42009-09-09 15:08:12 +00002275
Douglas Gregord6ff3322009-08-04 16:50:30 +00002276template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002277QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002278 TypeLocBuilder &TLB,
2279 IncompleteArrayTypeLoc TL) {
2280 IncompleteArrayType *T = TL.getTypePtr();
2281 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002282 if (ElementType.isNull())
2283 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002284
John McCall550e0c22009-10-21 00:40:46 +00002285 QualType Result = TL.getType();
2286 if (getDerived().AlwaysRebuild() ||
2287 ElementType != T->getElementType()) {
2288 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002289 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002290 T->getIndexTypeCVRQualifiers(),
2291 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002292 if (Result.isNull())
2293 return QualType();
2294 }
2295
2296 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2297 NewTL.setLBracketLoc(TL.getLBracketLoc());
2298 NewTL.setRBracketLoc(TL.getRBracketLoc());
2299 NewTL.setSizeExpr(0);
2300
2301 return Result;
2302}
2303
2304template<typename Derived>
2305QualType
2306TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
2307 VariableArrayTypeLoc TL) {
2308 VariableArrayType *T = TL.getTypePtr();
2309 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2310 if (ElementType.isNull())
2311 return QualType();
2312
2313 // Array bounds are not potentially evaluated contexts
2314 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2315
2316 Sema::OwningExprResult SizeResult
2317 = getDerived().TransformExpr(T->getSizeExpr());
2318 if (SizeResult.isInvalid())
2319 return QualType();
2320
2321 Expr *Size = static_cast<Expr*>(SizeResult.get());
2322
2323 QualType Result = TL.getType();
2324 if (getDerived().AlwaysRebuild() ||
2325 ElementType != T->getElementType() ||
2326 Size != T->getSizeExpr()) {
2327 Result = getDerived().RebuildVariableArrayType(ElementType,
2328 T->getSizeModifier(),
2329 move(SizeResult),
2330 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002331 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002332 if (Result.isNull())
2333 return QualType();
2334 }
2335 else SizeResult.take();
2336
2337 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2338 NewTL.setLBracketLoc(TL.getLBracketLoc());
2339 NewTL.setRBracketLoc(TL.getRBracketLoc());
2340 NewTL.setSizeExpr(Size);
2341
2342 return Result;
2343}
2344
2345template<typename Derived>
2346QualType
2347TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
2348 DependentSizedArrayTypeLoc TL) {
2349 DependentSizedArrayType *T = TL.getTypePtr();
2350 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2351 if (ElementType.isNull())
2352 return QualType();
2353
2354 // Array bounds are not potentially evaluated contexts
2355 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2356
2357 Sema::OwningExprResult SizeResult
2358 = getDerived().TransformExpr(T->getSizeExpr());
2359 if (SizeResult.isInvalid())
2360 return QualType();
2361
2362 Expr *Size = static_cast<Expr*>(SizeResult.get());
2363
2364 QualType Result = TL.getType();
2365 if (getDerived().AlwaysRebuild() ||
2366 ElementType != T->getElementType() ||
2367 Size != T->getSizeExpr()) {
2368 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2369 T->getSizeModifier(),
2370 move(SizeResult),
2371 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002372 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002373 if (Result.isNull())
2374 return QualType();
2375 }
2376 else SizeResult.take();
2377
2378 // We might have any sort of array type now, but fortunately they
2379 // all have the same location layout.
2380 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2381 NewTL.setLBracketLoc(TL.getLBracketLoc());
2382 NewTL.setRBracketLoc(TL.getRBracketLoc());
2383 NewTL.setSizeExpr(Size);
2384
2385 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002386}
Mike Stump11289f42009-09-09 15:08:12 +00002387
2388template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002389QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002390 TypeLocBuilder &TLB,
2391 DependentSizedExtVectorTypeLoc TL) {
2392 DependentSizedExtVectorType *T = TL.getTypePtr();
2393
2394 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002395 QualType ElementType = getDerived().TransformType(T->getElementType());
2396 if (ElementType.isNull())
2397 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002398
Douglas Gregore922c772009-08-04 22:27:00 +00002399 // Vector sizes are not potentially evaluated contexts
2400 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2401
Douglas Gregord6ff3322009-08-04 16:50:30 +00002402 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2403 if (Size.isInvalid())
2404 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002405
John McCall550e0c22009-10-21 00:40:46 +00002406 QualType Result = TL.getType();
2407 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002408 ElementType != T->getElementType() ||
2409 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002410 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002411 move(Size),
2412 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002413 if (Result.isNull())
2414 return QualType();
2415 }
2416 else Size.take();
2417
2418 // Result might be dependent or not.
2419 if (isa<DependentSizedExtVectorType>(Result)) {
2420 DependentSizedExtVectorTypeLoc NewTL
2421 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2422 NewTL.setNameLoc(TL.getNameLoc());
2423 } else {
2424 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2425 NewTL.setNameLoc(TL.getNameLoc());
2426 }
2427
2428 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002429}
Mike Stump11289f42009-09-09 15:08:12 +00002430
2431template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002432QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
2433 VectorTypeLoc TL) {
2434 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002435 QualType ElementType = getDerived().TransformType(T->getElementType());
2436 if (ElementType.isNull())
2437 return QualType();
2438
John McCall550e0c22009-10-21 00:40:46 +00002439 QualType Result = TL.getType();
2440 if (getDerived().AlwaysRebuild() ||
2441 ElementType != T->getElementType()) {
2442 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements());
2443 if (Result.isNull())
2444 return QualType();
2445 }
2446
2447 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2448 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002449
John McCall550e0c22009-10-21 00:40:46 +00002450 return Result;
2451}
2452
2453template<typename Derived>
2454QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
2455 ExtVectorTypeLoc TL) {
2456 VectorType *T = TL.getTypePtr();
2457 QualType ElementType = getDerived().TransformType(T->getElementType());
2458 if (ElementType.isNull())
2459 return QualType();
2460
2461 QualType Result = TL.getType();
2462 if (getDerived().AlwaysRebuild() ||
2463 ElementType != T->getElementType()) {
2464 Result = getDerived().RebuildExtVectorType(ElementType,
2465 T->getNumElements(),
2466 /*FIXME*/ SourceLocation());
2467 if (Result.isNull())
2468 return QualType();
2469 }
2470
2471 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2472 NewTL.setNameLoc(TL.getNameLoc());
2473
2474 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002475}
Mike Stump11289f42009-09-09 15:08:12 +00002476
2477template<typename Derived>
2478QualType
John McCall550e0c22009-10-21 00:40:46 +00002479TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
2480 FunctionProtoTypeLoc TL) {
2481 FunctionProtoType *T = TL.getTypePtr();
2482 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002483 if (ResultType.isNull())
2484 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002485
John McCall550e0c22009-10-21 00:40:46 +00002486 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002487 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002488 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2489 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2490 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump11289f42009-09-09 15:08:12 +00002491
John McCall550e0c22009-10-21 00:40:46 +00002492 QualType NewType;
2493 ParmVarDecl *NewParm;
2494
2495 if (OldParm) {
John McCallbcd03502009-12-07 02:54:59 +00002496 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCall550e0c22009-10-21 00:40:46 +00002497 assert(OldDI->getType() == T->getArgType(i));
2498
John McCallbcd03502009-12-07 02:54:59 +00002499 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCall550e0c22009-10-21 00:40:46 +00002500 if (!NewDI)
2501 return QualType();
2502
2503 if (NewDI == OldDI)
2504 NewParm = OldParm;
2505 else
2506 NewParm = ParmVarDecl::Create(SemaRef.Context,
2507 OldParm->getDeclContext(),
2508 OldParm->getLocation(),
2509 OldParm->getIdentifier(),
2510 NewDI->getType(),
2511 NewDI,
2512 OldParm->getStorageClass(),
2513 /* DefArg */ NULL);
2514 NewType = NewParm->getType();
2515
2516 // Deal with the possibility that we don't have a parameter
2517 // declaration for this parameter.
2518 } else {
2519 NewParm = 0;
2520
2521 QualType OldType = T->getArgType(i);
2522 NewType = getDerived().TransformType(OldType);
2523 if (NewType.isNull())
2524 return QualType();
2525 }
2526
2527 ParamTypes.push_back(NewType);
2528 ParamDecls.push_back(NewParm);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002529 }
Mike Stump11289f42009-09-09 15:08:12 +00002530
John McCall550e0c22009-10-21 00:40:46 +00002531 QualType Result = TL.getType();
2532 if (getDerived().AlwaysRebuild() ||
2533 ResultType != T->getResultType() ||
2534 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2535 Result = getDerived().RebuildFunctionProtoType(ResultType,
2536 ParamTypes.data(),
2537 ParamTypes.size(),
2538 T->isVariadic(),
2539 T->getTypeQuals());
2540 if (Result.isNull())
2541 return QualType();
2542 }
Mike Stump11289f42009-09-09 15:08:12 +00002543
John McCall550e0c22009-10-21 00:40:46 +00002544 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2545 NewTL.setLParenLoc(TL.getLParenLoc());
2546 NewTL.setRParenLoc(TL.getRParenLoc());
2547 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2548 NewTL.setArg(i, ParamDecls[i]);
2549
2550 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002551}
Mike Stump11289f42009-09-09 15:08:12 +00002552
Douglas Gregord6ff3322009-08-04 16:50:30 +00002553template<typename Derived>
2554QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002555 TypeLocBuilder &TLB,
2556 FunctionNoProtoTypeLoc TL) {
2557 FunctionNoProtoType *T = TL.getTypePtr();
2558 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2559 if (ResultType.isNull())
2560 return QualType();
2561
2562 QualType Result = TL.getType();
2563 if (getDerived().AlwaysRebuild() ||
2564 ResultType != T->getResultType())
2565 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2566
2567 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2568 NewTL.setLParenLoc(TL.getLParenLoc());
2569 NewTL.setRParenLoc(TL.getRParenLoc());
2570
2571 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002572}
Mike Stump11289f42009-09-09 15:08:12 +00002573
John McCallb96ec562009-12-04 22:46:56 +00002574template<typename Derived> QualType
2575TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
2576 UnresolvedUsingTypeLoc TL) {
2577 UnresolvedUsingType *T = TL.getTypePtr();
2578 Decl *D = getDerived().TransformDecl(T->getDecl());
2579 if (!D)
2580 return QualType();
2581
2582 QualType Result = TL.getType();
2583 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2584 Result = getDerived().RebuildUnresolvedUsingType(D);
2585 if (Result.isNull())
2586 return QualType();
2587 }
2588
2589 // We might get an arbitrary type spec type back. We should at
2590 // least always get a type spec type, though.
2591 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2592 NewTL.setNameLoc(TL.getNameLoc());
2593
2594 return Result;
2595}
2596
Douglas Gregord6ff3322009-08-04 16:50:30 +00002597template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002598QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
2599 TypedefTypeLoc TL) {
2600 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002601 TypedefDecl *Typedef
2602 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2603 if (!Typedef)
2604 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002605
John McCall550e0c22009-10-21 00:40:46 +00002606 QualType Result = TL.getType();
2607 if (getDerived().AlwaysRebuild() ||
2608 Typedef != T->getDecl()) {
2609 Result = getDerived().RebuildTypedefType(Typedef);
2610 if (Result.isNull())
2611 return QualType();
2612 }
Mike Stump11289f42009-09-09 15:08:12 +00002613
John McCall550e0c22009-10-21 00:40:46 +00002614 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2615 NewTL.setNameLoc(TL.getNameLoc());
2616
2617 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002618}
Mike Stump11289f42009-09-09 15:08:12 +00002619
Douglas Gregord6ff3322009-08-04 16:50:30 +00002620template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002621QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
2622 TypeOfExprTypeLoc TL) {
2623 TypeOfExprType *T = TL.getTypePtr();
2624
Douglas Gregore922c772009-08-04 22:27:00 +00002625 // typeof expressions are not potentially evaluated contexts
2626 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002627
Douglas Gregord6ff3322009-08-04 16:50:30 +00002628 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2629 if (E.isInvalid())
2630 return QualType();
2631
John McCall550e0c22009-10-21 00:40:46 +00002632 QualType Result = TL.getType();
2633 if (getDerived().AlwaysRebuild() ||
2634 E.get() != T->getUnderlyingExpr()) {
2635 Result = getDerived().RebuildTypeOfExprType(move(E));
2636 if (Result.isNull())
2637 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002638 }
John McCall550e0c22009-10-21 00:40:46 +00002639 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002640
John McCall550e0c22009-10-21 00:40:46 +00002641 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
2642 NewTL.setNameLoc(TL.getNameLoc());
2643
2644 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002645}
Mike Stump11289f42009-09-09 15:08:12 +00002646
2647template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002648QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
2649 TypeOfTypeLoc TL) {
2650 TypeOfType *T = TL.getTypePtr();
2651
John McCallbcd03502009-12-07 02:54:59 +00002652 // FIXME: should be an inner type, or at least have a TypeSourceInfo.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002653 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2654 if (Underlying.isNull())
2655 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002656
John McCall550e0c22009-10-21 00:40:46 +00002657 QualType Result = TL.getType();
2658 if (getDerived().AlwaysRebuild() ||
2659 Underlying != T->getUnderlyingType()) {
2660 Result = getDerived().RebuildTypeOfType(Underlying);
2661 if (Result.isNull())
2662 return QualType();
2663 }
Mike Stump11289f42009-09-09 15:08:12 +00002664
John McCall550e0c22009-10-21 00:40:46 +00002665 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
2666 NewTL.setNameLoc(TL.getNameLoc());
2667
2668 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002669}
Mike Stump11289f42009-09-09 15:08:12 +00002670
2671template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002672QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
2673 DecltypeTypeLoc TL) {
2674 DecltypeType *T = TL.getTypePtr();
2675
Douglas Gregore922c772009-08-04 22:27:00 +00002676 // decltype expressions are not potentially evaluated contexts
2677 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002678
Douglas Gregord6ff3322009-08-04 16:50:30 +00002679 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2680 if (E.isInvalid())
2681 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002682
John McCall550e0c22009-10-21 00:40:46 +00002683 QualType Result = TL.getType();
2684 if (getDerived().AlwaysRebuild() ||
2685 E.get() != T->getUnderlyingExpr()) {
2686 Result = getDerived().RebuildDecltypeType(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 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2693 NewTL.setNameLoc(TL.getNameLoc());
2694
2695 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002696}
2697
2698template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002699QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
2700 RecordTypeLoc TL) {
2701 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002702 RecordDecl *Record
John McCall550e0c22009-10-21 00:40:46 +00002703 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002704 if (!Record)
2705 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002706
John McCall550e0c22009-10-21 00:40:46 +00002707 QualType Result = TL.getType();
2708 if (getDerived().AlwaysRebuild() ||
2709 Record != T->getDecl()) {
2710 Result = getDerived().RebuildRecordType(Record);
2711 if (Result.isNull())
2712 return QualType();
2713 }
Mike Stump11289f42009-09-09 15:08:12 +00002714
John McCall550e0c22009-10-21 00:40:46 +00002715 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2716 NewTL.setNameLoc(TL.getNameLoc());
2717
2718 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002719}
Mike Stump11289f42009-09-09 15:08:12 +00002720
2721template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002722QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
2723 EnumTypeLoc TL) {
2724 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002725 EnumDecl *Enum
John McCall550e0c22009-10-21 00:40:46 +00002726 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002727 if (!Enum)
2728 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002729
John McCall550e0c22009-10-21 00:40:46 +00002730 QualType Result = TL.getType();
2731 if (getDerived().AlwaysRebuild() ||
2732 Enum != T->getDecl()) {
2733 Result = getDerived().RebuildEnumType(Enum);
2734 if (Result.isNull())
2735 return QualType();
2736 }
Mike Stump11289f42009-09-09 15:08:12 +00002737
John McCall550e0c22009-10-21 00:40:46 +00002738 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2739 NewTL.setNameLoc(TL.getNameLoc());
2740
2741 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002742}
John McCallfcc33b02009-09-05 00:15:47 +00002743
2744template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002745QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
2746 ElaboratedTypeLoc TL) {
2747 ElaboratedType *T = TL.getTypePtr();
2748
2749 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002750 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2751 if (Underlying.isNull())
2752 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002753
John McCall550e0c22009-10-21 00:40:46 +00002754 QualType Result = TL.getType();
2755 if (getDerived().AlwaysRebuild() ||
2756 Underlying != T->getUnderlyingType()) {
2757 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2758 if (Result.isNull())
2759 return QualType();
2760 }
Mike Stump11289f42009-09-09 15:08:12 +00002761
John McCall550e0c22009-10-21 00:40:46 +00002762 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2763 NewTL.setNameLoc(TL.getNameLoc());
2764
2765 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002766}
Mike Stump11289f42009-09-09 15:08:12 +00002767
2768
Douglas Gregord6ff3322009-08-04 16:50:30 +00002769template<typename Derived>
2770QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002771 TypeLocBuilder &TLB,
2772 TemplateTypeParmTypeLoc TL) {
2773 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002774}
2775
Mike Stump11289f42009-09-09 15:08:12 +00002776template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002777QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002778 TypeLocBuilder &TLB,
2779 SubstTemplateTypeParmTypeLoc TL) {
2780 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002781}
2782
2783template<typename Derived>
Douglas Gregorc59e5612009-10-19 22:04:39 +00002784inline QualType
2785TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall550e0c22009-10-21 00:40:46 +00002786 TypeLocBuilder &TLB,
2787 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00002788 return TransformTemplateSpecializationType(TLB, TL, QualType());
2789}
John McCall550e0c22009-10-21 00:40:46 +00002790
John McCall0ad16662009-10-29 08:12:44 +00002791template<typename Derived>
2792QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2793 const TemplateSpecializationType *TST,
2794 QualType ObjectType) {
2795 // FIXME: this entire method is a temporary workaround; callers
2796 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00002797
John McCall0ad16662009-10-29 08:12:44 +00002798 // Fake up a TemplateSpecializationTypeLoc.
2799 TypeLocBuilder TLB;
2800 TemplateSpecializationTypeLoc TL
2801 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2802
John McCall0d07eb32009-10-29 18:45:58 +00002803 SourceLocation BaseLoc = getDerived().getBaseLocation();
2804
2805 TL.setTemplateNameLoc(BaseLoc);
2806 TL.setLAngleLoc(BaseLoc);
2807 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00002808 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2809 const TemplateArgument &TA = TST->getArg(i);
2810 TemplateArgumentLoc TAL;
2811 getDerived().InventTemplateArgumentLoc(TA, TAL);
2812 TL.setArgLocInfo(i, TAL.getLocInfo());
2813 }
2814
2815 TypeLocBuilder IgnoredTLB;
2816 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00002817}
2818
2819template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002820QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00002821 TypeLocBuilder &TLB,
2822 TemplateSpecializationTypeLoc TL,
2823 QualType ObjectType) {
2824 const TemplateSpecializationType *T = TL.getTypePtr();
2825
Mike Stump11289f42009-09-09 15:08:12 +00002826 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002827 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002828 if (Template.isNull())
2829 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002830
John McCall6b51f282009-11-23 01:53:49 +00002831 TemplateArgumentListInfo NewTemplateArgs;
2832 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2833 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2834
2835 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2836 TemplateArgumentLoc Loc;
2837 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00002838 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00002839 NewTemplateArgs.addArgument(Loc);
2840 }
Mike Stump11289f42009-09-09 15:08:12 +00002841
John McCall0ad16662009-10-29 08:12:44 +00002842 // FIXME: maybe don't rebuild if all the template arguments are the same.
2843
2844 QualType Result =
2845 getDerived().RebuildTemplateSpecializationType(Template,
2846 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00002847 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00002848
2849 if (!Result.isNull()) {
2850 TemplateSpecializationTypeLoc NewTL
2851 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2852 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2853 NewTL.setLAngleLoc(TL.getLAngleLoc());
2854 NewTL.setRAngleLoc(TL.getRAngleLoc());
2855 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2856 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002857 }
Mike Stump11289f42009-09-09 15:08:12 +00002858
John McCall0ad16662009-10-29 08:12:44 +00002859 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002860}
Mike Stump11289f42009-09-09 15:08:12 +00002861
2862template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002863QualType
2864TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
2865 QualifiedNameTypeLoc TL) {
2866 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002867 NestedNameSpecifier *NNS
2868 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2869 SourceRange());
2870 if (!NNS)
2871 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002872
Douglas Gregord6ff3322009-08-04 16:50:30 +00002873 QualType Named = getDerived().TransformType(T->getNamedType());
2874 if (Named.isNull())
2875 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002876
John McCall550e0c22009-10-21 00:40:46 +00002877 QualType Result = TL.getType();
2878 if (getDerived().AlwaysRebuild() ||
2879 NNS != T->getQualifier() ||
2880 Named != T->getNamedType()) {
2881 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2882 if (Result.isNull())
2883 return QualType();
2884 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002885
John McCall550e0c22009-10-21 00:40:46 +00002886 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2887 NewTL.setNameLoc(TL.getNameLoc());
2888
2889 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002890}
Mike Stump11289f42009-09-09 15:08:12 +00002891
2892template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002893QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
2894 TypenameTypeLoc TL) {
2895 TypenameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00002896
2897 /* FIXME: preserve source information better than this */
2898 SourceRange SR(TL.getNameLoc());
2899
Douglas Gregord6ff3322009-08-04 16:50:30 +00002900 NestedNameSpecifier *NNS
John McCall0ad16662009-10-29 08:12:44 +00002901 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002902 if (!NNS)
2903 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002904
John McCall550e0c22009-10-21 00:40:46 +00002905 QualType Result;
2906
Douglas Gregord6ff3322009-08-04 16:50:30 +00002907 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002908 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002909 = getDerived().TransformType(QualType(TemplateId, 0));
2910 if (NewTemplateId.isNull())
2911 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002912
Douglas Gregord6ff3322009-08-04 16:50:30 +00002913 if (!getDerived().AlwaysRebuild() &&
2914 NNS == T->getQualifier() &&
2915 NewTemplateId == QualType(TemplateId, 0))
2916 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002917
John McCall550e0c22009-10-21 00:40:46 +00002918 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2919 } else {
John McCall0ad16662009-10-29 08:12:44 +00002920 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002921 }
John McCall550e0c22009-10-21 00:40:46 +00002922 if (Result.isNull())
2923 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002924
John McCall550e0c22009-10-21 00:40:46 +00002925 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2926 NewTL.setNameLoc(TL.getNameLoc());
2927
2928 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002929}
Mike Stump11289f42009-09-09 15:08:12 +00002930
Douglas Gregord6ff3322009-08-04 16:50:30 +00002931template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002932QualType
2933TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
2934 ObjCInterfaceTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002935 assert(false && "TransformObjCInterfaceType unimplemented");
2936 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002937}
Mike Stump11289f42009-09-09 15:08:12 +00002938
2939template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002940QualType
2941TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
2942 ObjCObjectPointerTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002943 assert(false && "TransformObjCObjectPointerType unimplemented");
2944 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00002945}
2946
Douglas Gregord6ff3322009-08-04 16:50:30 +00002947//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00002948// Statement transformation
2949//===----------------------------------------------------------------------===//
2950template<typename Derived>
2951Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002952TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2953 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002954}
2955
2956template<typename Derived>
2957Sema::OwningStmtResult
2958TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2959 return getDerived().TransformCompoundStmt(S, false);
2960}
2961
2962template<typename Derived>
2963Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002964TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00002965 bool IsStmtExpr) {
2966 bool SubStmtChanged = false;
2967 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
2968 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
2969 B != BEnd; ++B) {
2970 OwningStmtResult Result = getDerived().TransformStmt(*B);
2971 if (Result.isInvalid())
2972 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002973
Douglas Gregorebe10102009-08-20 07:17:43 +00002974 SubStmtChanged = SubStmtChanged || Result.get() != *B;
2975 Statements.push_back(Result.takeAs<Stmt>());
2976 }
Mike Stump11289f42009-09-09 15:08:12 +00002977
Douglas Gregorebe10102009-08-20 07:17:43 +00002978 if (!getDerived().AlwaysRebuild() &&
2979 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00002980 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002981
2982 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
2983 move_arg(Statements),
2984 S->getRBracLoc(),
2985 IsStmtExpr);
2986}
Mike Stump11289f42009-09-09 15:08:12 +00002987
Douglas Gregorebe10102009-08-20 07:17:43 +00002988template<typename Derived>
2989Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002990TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00002991 OwningExprResult LHS(SemaRef), RHS(SemaRef);
2992 {
2993 // The case value expressions are not potentially evaluated.
2994 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002995
Eli Friedman06577382009-11-19 03:14:00 +00002996 // Transform the left-hand case value.
2997 LHS = getDerived().TransformExpr(S->getLHS());
2998 if (LHS.isInvalid())
2999 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003000
Eli Friedman06577382009-11-19 03:14:00 +00003001 // Transform the right-hand case value (for the GNU case-range extension).
3002 RHS = getDerived().TransformExpr(S->getRHS());
3003 if (RHS.isInvalid())
3004 return SemaRef.StmtError();
3005 }
Mike Stump11289f42009-09-09 15:08:12 +00003006
Douglas Gregorebe10102009-08-20 07:17:43 +00003007 // Build the case statement.
3008 // Case statements are always rebuilt so that they will attached to their
3009 // transformed switch statement.
3010 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3011 move(LHS),
3012 S->getEllipsisLoc(),
3013 move(RHS),
3014 S->getColonLoc());
3015 if (Case.isInvalid())
3016 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003017
Douglas Gregorebe10102009-08-20 07:17:43 +00003018 // Transform the statement following the case
3019 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3020 if (SubStmt.isInvalid())
3021 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003022
Douglas Gregorebe10102009-08-20 07:17:43 +00003023 // Attach the body to the case statement
3024 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3025}
3026
3027template<typename Derived>
3028Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003029TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003030 // Transform the statement following the default case
3031 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3032 if (SubStmt.isInvalid())
3033 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003034
Douglas Gregorebe10102009-08-20 07:17:43 +00003035 // Default statements are always rebuilt
3036 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3037 move(SubStmt));
3038}
Mike Stump11289f42009-09-09 15:08:12 +00003039
Douglas Gregorebe10102009-08-20 07:17:43 +00003040template<typename Derived>
3041Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003042TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003043 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3044 if (SubStmt.isInvalid())
3045 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003046
Douglas Gregorebe10102009-08-20 07:17:43 +00003047 // FIXME: Pass the real colon location in.
3048 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3049 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3050 move(SubStmt));
3051}
Mike Stump11289f42009-09-09 15:08:12 +00003052
Douglas Gregorebe10102009-08-20 07:17:43 +00003053template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003054Sema::OwningStmtResult
3055TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003056 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003057 OwningExprResult Cond(SemaRef);
3058 VarDecl *ConditionVar = 0;
3059 if (S->getConditionVariable()) {
3060 ConditionVar
3061 = cast_or_null<VarDecl>(
3062 getDerived().TransformDefinition(S->getConditionVariable()));
3063 if (!ConditionVar)
3064 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003065 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003066 Cond = getDerived().TransformExpr(S->getCond());
3067
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003068 if (Cond.isInvalid())
3069 return SemaRef.StmtError();
3070 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003071
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003072 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003073
Douglas Gregorebe10102009-08-20 07:17:43 +00003074 // Transform the "then" branch.
3075 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3076 if (Then.isInvalid())
3077 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003078
Douglas Gregorebe10102009-08-20 07:17:43 +00003079 // Transform the "else" branch.
3080 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3081 if (Else.isInvalid())
3082 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003083
Douglas Gregorebe10102009-08-20 07:17:43 +00003084 if (!getDerived().AlwaysRebuild() &&
3085 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003086 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003087 Then.get() == S->getThen() &&
3088 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003089 return SemaRef.Owned(S->Retain());
3090
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003091 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3092 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003093 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003094}
3095
3096template<typename Derived>
3097Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003098TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003099 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003100 OwningExprResult Cond(SemaRef);
3101 VarDecl *ConditionVar = 0;
3102 if (S->getConditionVariable()) {
3103 ConditionVar
3104 = cast_or_null<VarDecl>(
3105 getDerived().TransformDefinition(S->getConditionVariable()));
3106 if (!ConditionVar)
3107 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003108 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003109 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003110
3111 if (Cond.isInvalid())
3112 return SemaRef.StmtError();
3113 }
Mike Stump11289f42009-09-09 15:08:12 +00003114
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003115 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003116
Douglas Gregorebe10102009-08-20 07:17:43 +00003117 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003118 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3119 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003120 if (Switch.isInvalid())
3121 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003122
Douglas Gregorebe10102009-08-20 07:17:43 +00003123 // Transform the body of the switch statement.
3124 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3125 if (Body.isInvalid())
3126 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003127
Douglas Gregorebe10102009-08-20 07:17:43 +00003128 // Complete the switch statement.
3129 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3130 move(Body));
3131}
Mike Stump11289f42009-09-09 15:08:12 +00003132
Douglas Gregorebe10102009-08-20 07:17:43 +00003133template<typename Derived>
3134Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003135TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003136 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003137 OwningExprResult Cond(SemaRef);
3138 VarDecl *ConditionVar = 0;
3139 if (S->getConditionVariable()) {
3140 ConditionVar
3141 = cast_or_null<VarDecl>(
3142 getDerived().TransformDefinition(S->getConditionVariable()));
3143 if (!ConditionVar)
3144 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003145 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003146 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003147
3148 if (Cond.isInvalid())
3149 return SemaRef.StmtError();
3150 }
Mike Stump11289f42009-09-09 15:08:12 +00003151
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003152 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003153
Douglas Gregorebe10102009-08-20 07:17:43 +00003154 // Transform the body
3155 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3156 if (Body.isInvalid())
3157 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003158
Douglas Gregorebe10102009-08-20 07:17:43 +00003159 if (!getDerived().AlwaysRebuild() &&
3160 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003161 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003162 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003163 return SemaRef.Owned(S->Retain());
3164
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003165 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3166 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003167}
Mike Stump11289f42009-09-09 15:08:12 +00003168
Douglas Gregorebe10102009-08-20 07:17:43 +00003169template<typename Derived>
3170Sema::OwningStmtResult
3171TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3172 // Transform the condition
3173 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3174 if (Cond.isInvalid())
3175 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003176
Douglas Gregorebe10102009-08-20 07:17:43 +00003177 // Transform the body
3178 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3179 if (Body.isInvalid())
3180 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003181
Douglas Gregorebe10102009-08-20 07:17:43 +00003182 if (!getDerived().AlwaysRebuild() &&
3183 Cond.get() == S->getCond() &&
3184 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003185 return SemaRef.Owned(S->Retain());
3186
Douglas Gregorebe10102009-08-20 07:17:43 +00003187 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3188 /*FIXME:*/S->getWhileLoc(), move(Cond),
3189 S->getRParenLoc());
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>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003195 // Transform the initialization statement
3196 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3197 if (Init.isInvalid())
3198 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003199
Douglas Gregorebe10102009-08-20 07:17:43 +00003200 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003201 OwningExprResult Cond(SemaRef);
3202 VarDecl *ConditionVar = 0;
3203 if (S->getConditionVariable()) {
3204 ConditionVar
3205 = cast_or_null<VarDecl>(
3206 getDerived().TransformDefinition(S->getConditionVariable()));
3207 if (!ConditionVar)
3208 return SemaRef.StmtError();
3209 } else {
3210 Cond = getDerived().TransformExpr(S->getCond());
3211
3212 if (Cond.isInvalid())
3213 return SemaRef.StmtError();
3214 }
Mike Stump11289f42009-09-09 15:08:12 +00003215
Douglas Gregorebe10102009-08-20 07:17:43 +00003216 // Transform the increment
3217 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3218 if (Inc.isInvalid())
3219 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003220
Douglas Gregorebe10102009-08-20 07:17:43 +00003221 // Transform the body
3222 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3223 if (Body.isInvalid())
3224 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003225
Douglas Gregorebe10102009-08-20 07:17:43 +00003226 if (!getDerived().AlwaysRebuild() &&
3227 Init.get() == S->getInit() &&
3228 Cond.get() == S->getCond() &&
3229 Inc.get() == S->getInc() &&
3230 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003231 return SemaRef.Owned(S->Retain());
3232
Douglas Gregorebe10102009-08-20 07:17:43 +00003233 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003234 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003235 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003236 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003237 S->getRParenLoc(), move(Body));
3238}
3239
3240template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003241Sema::OwningStmtResult
3242TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003243 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003244 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003245 S->getLabel());
3246}
3247
3248template<typename Derived>
3249Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003250TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003251 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3252 if (Target.isInvalid())
3253 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003254
Douglas Gregorebe10102009-08-20 07:17:43 +00003255 if (!getDerived().AlwaysRebuild() &&
3256 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003257 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003258
3259 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3260 move(Target));
3261}
3262
3263template<typename Derived>
3264Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003265TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3266 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003267}
Mike Stump11289f42009-09-09 15:08:12 +00003268
Douglas Gregorebe10102009-08-20 07:17:43 +00003269template<typename Derived>
3270Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003271TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3272 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003273}
Mike Stump11289f42009-09-09 15:08:12 +00003274
Douglas Gregorebe10102009-08-20 07:17:43 +00003275template<typename Derived>
3276Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003277TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003278 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3279 if (Result.isInvalid())
3280 return SemaRef.StmtError();
3281
Mike Stump11289f42009-09-09 15:08:12 +00003282 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003283 // to tell whether the return type of the function has changed.
3284 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3285}
Mike Stump11289f42009-09-09 15:08:12 +00003286
Douglas Gregorebe10102009-08-20 07:17:43 +00003287template<typename Derived>
3288Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003289TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003290 bool DeclChanged = false;
3291 llvm::SmallVector<Decl *, 4> Decls;
3292 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3293 D != DEnd; ++D) {
3294 Decl *Transformed = getDerived().TransformDefinition(*D);
3295 if (!Transformed)
3296 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003297
Douglas Gregorebe10102009-08-20 07:17:43 +00003298 if (Transformed != *D)
3299 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003300
Douglas Gregorebe10102009-08-20 07:17:43 +00003301 Decls.push_back(Transformed);
3302 }
Mike Stump11289f42009-09-09 15:08:12 +00003303
Douglas Gregorebe10102009-08-20 07:17:43 +00003304 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003305 return SemaRef.Owned(S->Retain());
3306
3307 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003308 S->getStartLoc(), S->getEndLoc());
3309}
Mike Stump11289f42009-09-09 15:08:12 +00003310
Douglas Gregorebe10102009-08-20 07:17:43 +00003311template<typename Derived>
3312Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003313TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003314 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003315 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003316}
3317
3318template<typename Derived>
3319Sema::OwningStmtResult
3320TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
3321 // FIXME: Implement!
3322 assert(false && "Inline assembly cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003323 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003324}
3325
3326
3327template<typename Derived>
3328Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003329TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003330 // FIXME: Implement this
3331 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003332 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003333}
Mike Stump11289f42009-09-09 15:08:12 +00003334
Douglas Gregorebe10102009-08-20 07:17:43 +00003335template<typename Derived>
3336Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003337TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003338 // FIXME: Implement this
3339 assert(false && "Cannot transform an Objective-C @catch statement");
3340 return SemaRef.Owned(S->Retain());
3341}
Mike Stump11289f42009-09-09 15:08:12 +00003342
Douglas Gregorebe10102009-08-20 07:17:43 +00003343template<typename Derived>
3344Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003345TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003346 // FIXME: Implement this
3347 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003348 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003349}
Mike Stump11289f42009-09-09 15:08:12 +00003350
Douglas Gregorebe10102009-08-20 07:17:43 +00003351template<typename Derived>
3352Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003353TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003354 // FIXME: Implement this
3355 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003356 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003357}
Mike Stump11289f42009-09-09 15:08:12 +00003358
Douglas Gregorebe10102009-08-20 07:17:43 +00003359template<typename Derived>
3360Sema::OwningStmtResult
3361TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003362 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003363 // FIXME: Implement this
3364 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003365 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003366}
3367
3368template<typename Derived>
3369Sema::OwningStmtResult
3370TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003371 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003372 // FIXME: Implement this
3373 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003374 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003375}
3376
3377
3378template<typename Derived>
3379Sema::OwningStmtResult
3380TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3381 // Transform the exception declaration, if any.
3382 VarDecl *Var = 0;
3383 if (S->getExceptionDecl()) {
3384 VarDecl *ExceptionDecl = S->getExceptionDecl();
3385 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3386 ExceptionDecl->getDeclName());
3387
3388 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3389 if (T.isNull())
3390 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003391
Douglas Gregorebe10102009-08-20 07:17:43 +00003392 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3393 T,
John McCallbcd03502009-12-07 02:54:59 +00003394 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003395 ExceptionDecl->getIdentifier(),
3396 ExceptionDecl->getLocation(),
3397 /*FIXME: Inaccurate*/
3398 SourceRange(ExceptionDecl->getLocation()));
3399 if (!Var || Var->isInvalidDecl()) {
3400 if (Var)
3401 Var->Destroy(SemaRef.Context);
3402 return SemaRef.StmtError();
3403 }
3404 }
Mike Stump11289f42009-09-09 15:08:12 +00003405
Douglas Gregorebe10102009-08-20 07:17:43 +00003406 // Transform the actual exception handler.
3407 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3408 if (Handler.isInvalid()) {
3409 if (Var)
3410 Var->Destroy(SemaRef.Context);
3411 return SemaRef.StmtError();
3412 }
Mike Stump11289f42009-09-09 15:08:12 +00003413
Douglas Gregorebe10102009-08-20 07:17:43 +00003414 if (!getDerived().AlwaysRebuild() &&
3415 !Var &&
3416 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003417 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003418
3419 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3420 Var,
3421 move(Handler));
3422}
Mike Stump11289f42009-09-09 15:08:12 +00003423
Douglas Gregorebe10102009-08-20 07:17:43 +00003424template<typename Derived>
3425Sema::OwningStmtResult
3426TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3427 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003428 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003429 = getDerived().TransformCompoundStmt(S->getTryBlock());
3430 if (TryBlock.isInvalid())
3431 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003432
Douglas Gregorebe10102009-08-20 07:17:43 +00003433 // Transform the handlers.
3434 bool HandlerChanged = false;
3435 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3436 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003437 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003438 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3439 if (Handler.isInvalid())
3440 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003441
Douglas Gregorebe10102009-08-20 07:17:43 +00003442 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3443 Handlers.push_back(Handler.takeAs<Stmt>());
3444 }
Mike Stump11289f42009-09-09 15:08:12 +00003445
Douglas Gregorebe10102009-08-20 07:17:43 +00003446 if (!getDerived().AlwaysRebuild() &&
3447 TryBlock.get() == S->getTryBlock() &&
3448 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003449 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003450
3451 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003452 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003453}
Mike Stump11289f42009-09-09 15:08:12 +00003454
Douglas Gregorebe10102009-08-20 07:17:43 +00003455//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003456// Expression transformation
3457//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003458template<typename Derived>
3459Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003460TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003461 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003462}
Mike Stump11289f42009-09-09 15:08:12 +00003463
3464template<typename Derived>
3465Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003466TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003467 NestedNameSpecifier *Qualifier = 0;
3468 if (E->getQualifier()) {
3469 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3470 E->getQualifierRange());
3471 if (!Qualifier)
3472 return SemaRef.ExprError();
3473 }
John McCallce546572009-12-08 09:08:17 +00003474
3475 ValueDecl *ND
3476 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003477 if (!ND)
3478 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003479
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003480 if (!getDerived().AlwaysRebuild() &&
3481 Qualifier == E->getQualifier() &&
3482 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003483 !E->hasExplicitTemplateArgumentList()) {
3484
3485 // Mark it referenced in the new context regardless.
3486 // FIXME: this is a bit instantiation-specific.
3487 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3488
Mike Stump11289f42009-09-09 15:08:12 +00003489 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003490 }
John McCallce546572009-12-08 09:08:17 +00003491
3492 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3493 if (E->hasExplicitTemplateArgumentList()) {
3494 TemplateArgs = &TransArgs;
3495 TransArgs.setLAngleLoc(E->getLAngleLoc());
3496 TransArgs.setRAngleLoc(E->getRAngleLoc());
3497 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3498 TemplateArgumentLoc Loc;
3499 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3500 return SemaRef.ExprError();
3501 TransArgs.addArgument(Loc);
3502 }
3503 }
3504
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003505 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003506 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003507}
Mike Stump11289f42009-09-09 15:08:12 +00003508
Douglas Gregora16548e2009-08-11 05:31:07 +00003509template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003510Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003511TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003512 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003513}
Mike Stump11289f42009-09-09 15:08:12 +00003514
Douglas Gregora16548e2009-08-11 05:31:07 +00003515template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003516Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003517TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003518 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003519}
Mike Stump11289f42009-09-09 15:08:12 +00003520
Douglas Gregora16548e2009-08-11 05:31:07 +00003521template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003522Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003523TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003524 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003525}
Mike Stump11289f42009-09-09 15:08:12 +00003526
Douglas Gregora16548e2009-08-11 05:31:07 +00003527template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003528Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003529TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003530 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003531}
Mike Stump11289f42009-09-09 15:08:12 +00003532
Douglas Gregora16548e2009-08-11 05:31:07 +00003533template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003534Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003535TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003536 return SemaRef.Owned(E->Retain());
3537}
3538
3539template<typename Derived>
3540Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003541TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003542 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3543 if (SubExpr.isInvalid())
3544 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003545
Douglas Gregora16548e2009-08-11 05:31:07 +00003546 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003547 return SemaRef.Owned(E->Retain());
3548
3549 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003550 E->getRParen());
3551}
3552
Mike Stump11289f42009-09-09 15:08:12 +00003553template<typename Derived>
3554Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003555TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3556 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003557 if (SubExpr.isInvalid())
3558 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003559
Douglas Gregora16548e2009-08-11 05:31:07 +00003560 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003561 return SemaRef.Owned(E->Retain());
3562
Douglas Gregora16548e2009-08-11 05:31:07 +00003563 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3564 E->getOpcode(),
3565 move(SubExpr));
3566}
Mike Stump11289f42009-09-09 15:08:12 +00003567
Douglas Gregora16548e2009-08-11 05:31:07 +00003568template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003569Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003570TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003571 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003572 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003573
John McCallbcd03502009-12-07 02:54:59 +00003574 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003575 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003576 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003577
John McCall4c98fd82009-11-04 07:28:41 +00003578 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003579 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003580
John McCall4c98fd82009-11-04 07:28:41 +00003581 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003582 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003583 E->getSourceRange());
3584 }
Mike Stump11289f42009-09-09 15:08:12 +00003585
Douglas Gregora16548e2009-08-11 05:31:07 +00003586 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003587 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003588 // C++0x [expr.sizeof]p1:
3589 // The operand is either an expression, which is an unevaluated operand
3590 // [...]
3591 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003592
Douglas Gregora16548e2009-08-11 05:31:07 +00003593 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3594 if (SubExpr.isInvalid())
3595 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003596
Douglas Gregora16548e2009-08-11 05:31:07 +00003597 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3598 return SemaRef.Owned(E->Retain());
3599 }
Mike Stump11289f42009-09-09 15:08:12 +00003600
Douglas Gregora16548e2009-08-11 05:31:07 +00003601 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3602 E->isSizeOf(),
3603 E->getSourceRange());
3604}
Mike Stump11289f42009-09-09 15:08:12 +00003605
Douglas Gregora16548e2009-08-11 05:31:07 +00003606template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003607Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003608TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003609 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3610 if (LHS.isInvalid())
3611 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003612
Douglas Gregora16548e2009-08-11 05:31:07 +00003613 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3614 if (RHS.isInvalid())
3615 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003616
3617
Douglas Gregora16548e2009-08-11 05:31:07 +00003618 if (!getDerived().AlwaysRebuild() &&
3619 LHS.get() == E->getLHS() &&
3620 RHS.get() == E->getRHS())
3621 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003622
Douglas Gregora16548e2009-08-11 05:31:07 +00003623 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3624 /*FIXME:*/E->getLHS()->getLocStart(),
3625 move(RHS),
3626 E->getRBracketLoc());
3627}
Mike Stump11289f42009-09-09 15:08:12 +00003628
3629template<typename Derived>
3630Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003631TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003632 // Transform the callee.
3633 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3634 if (Callee.isInvalid())
3635 return SemaRef.ExprError();
3636
3637 // Transform arguments.
3638 bool ArgChanged = false;
3639 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3640 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3641 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3642 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3643 if (Arg.isInvalid())
3644 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003645
Douglas Gregora16548e2009-08-11 05:31:07 +00003646 // FIXME: Wrong source location information for the ','.
3647 FakeCommaLocs.push_back(
3648 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003649
3650 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003651 Args.push_back(Arg.takeAs<Expr>());
3652 }
Mike Stump11289f42009-09-09 15:08:12 +00003653
Douglas Gregora16548e2009-08-11 05:31:07 +00003654 if (!getDerived().AlwaysRebuild() &&
3655 Callee.get() == E->getCallee() &&
3656 !ArgChanged)
3657 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003658
Douglas Gregora16548e2009-08-11 05:31:07 +00003659 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003660 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003661 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3662 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3663 move_arg(Args),
3664 FakeCommaLocs.data(),
3665 E->getRParenLoc());
3666}
Mike Stump11289f42009-09-09 15:08:12 +00003667
3668template<typename Derived>
3669Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003670TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003671 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3672 if (Base.isInvalid())
3673 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003674
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003675 NestedNameSpecifier *Qualifier = 0;
3676 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003677 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003678 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3679 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003680 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003681 return SemaRef.ExprError();
3682 }
Mike Stump11289f42009-09-09 15:08:12 +00003683
Eli Friedman2cfcef62009-12-04 06:40:45 +00003684 ValueDecl *Member
3685 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003686 if (!Member)
3687 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003688
Douglas Gregora16548e2009-08-11 05:31:07 +00003689 if (!getDerived().AlwaysRebuild() &&
3690 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003691 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003692 Member == E->getMemberDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003693 !E->hasExplicitTemplateArgumentList()) {
3694
3695 // Mark it referenced in the new context regardless.
3696 // FIXME: this is a bit instantiation-specific.
3697 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00003698 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003699 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003700
John McCall6b51f282009-11-23 01:53:49 +00003701 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003702 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003703 TransArgs.setLAngleLoc(E->getLAngleLoc());
3704 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003705 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003706 TemplateArgumentLoc Loc;
3707 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003708 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003709 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003710 }
3711 }
3712
Douglas Gregora16548e2009-08-11 05:31:07 +00003713 // FIXME: Bogus source location for the operator
3714 SourceLocation FakeOperatorLoc
3715 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3716
3717 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3718 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003719 Qualifier,
3720 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003721 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003722 Member,
John McCall6b51f282009-11-23 01:53:49 +00003723 (E->hasExplicitTemplateArgumentList()
3724 ? &TransArgs : 0),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003725 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00003726}
Mike Stump11289f42009-09-09 15:08:12 +00003727
Douglas Gregora16548e2009-08-11 05:31:07 +00003728template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003729Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003730TreeTransform<Derived>::TransformCastExpr(CastExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003731 assert(false && "Cannot transform abstract class");
3732 return SemaRef.Owned(E->Retain());
3733}
3734
3735template<typename Derived>
3736Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003737TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003738 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3739 if (LHS.isInvalid())
3740 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003741
Douglas Gregora16548e2009-08-11 05:31:07 +00003742 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3743 if (RHS.isInvalid())
3744 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003745
Douglas Gregora16548e2009-08-11 05:31:07 +00003746 if (!getDerived().AlwaysRebuild() &&
3747 LHS.get() == E->getLHS() &&
3748 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003749 return SemaRef.Owned(E->Retain());
3750
Douglas Gregora16548e2009-08-11 05:31:07 +00003751 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3752 move(LHS), move(RHS));
3753}
3754
Mike Stump11289f42009-09-09 15:08:12 +00003755template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003756Sema::OwningExprResult
3757TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00003758 CompoundAssignOperator *E) {
3759 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00003760}
Mike Stump11289f42009-09-09 15:08:12 +00003761
Douglas Gregora16548e2009-08-11 05:31:07 +00003762template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003763Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003764TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003765 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3766 if (Cond.isInvalid())
3767 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003768
Douglas Gregora16548e2009-08-11 05:31:07 +00003769 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3770 if (LHS.isInvalid())
3771 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003772
Douglas Gregora16548e2009-08-11 05:31:07 +00003773 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3774 if (RHS.isInvalid())
3775 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003776
Douglas Gregora16548e2009-08-11 05:31:07 +00003777 if (!getDerived().AlwaysRebuild() &&
3778 Cond.get() == E->getCond() &&
3779 LHS.get() == E->getLHS() &&
3780 RHS.get() == E->getRHS())
3781 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003782
3783 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003784 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003785 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003786 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003787 move(RHS));
3788}
Mike Stump11289f42009-09-09 15:08:12 +00003789
3790template<typename Derived>
3791Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003792TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00003793 // Implicit casts are eliminated during transformation, since they
3794 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00003795 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003796}
Mike Stump11289f42009-09-09 15:08:12 +00003797
Douglas Gregora16548e2009-08-11 05:31:07 +00003798template<typename Derived>
3799Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003800TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003801 assert(false && "Cannot transform abstract class");
3802 return SemaRef.Owned(E->Retain());
3803}
3804
3805template<typename Derived>
3806Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003807TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003808 QualType T;
3809 {
3810 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003811 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003812 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3813 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003814
Douglas Gregora16548e2009-08-11 05:31:07 +00003815 T = getDerived().TransformType(E->getTypeAsWritten());
3816 if (T.isNull())
3817 return SemaRef.ExprError();
3818 }
Mike Stump11289f42009-09-09 15:08:12 +00003819
Douglas Gregor6131b442009-12-12 18:16:41 +00003820 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00003821 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003822 if (SubExpr.isInvalid())
3823 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003824
Douglas Gregora16548e2009-08-11 05:31:07 +00003825 if (!getDerived().AlwaysRebuild() &&
3826 T == E->getTypeAsWritten() &&
3827 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003828 return SemaRef.Owned(E->Retain());
3829
Douglas Gregora16548e2009-08-11 05:31:07 +00003830 return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T,
3831 E->getRParenLoc(),
3832 move(SubExpr));
3833}
Mike Stump11289f42009-09-09 15:08:12 +00003834
Douglas Gregora16548e2009-08-11 05:31:07 +00003835template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003836Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003837TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003838 QualType T;
3839 {
3840 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003841 SourceLocation FakeTypeLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003842 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3843 TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003844
Douglas Gregora16548e2009-08-11 05:31:07 +00003845 T = getDerived().TransformType(E->getType());
3846 if (T.isNull())
3847 return SemaRef.ExprError();
3848 }
Mike Stump11289f42009-09-09 15:08:12 +00003849
Douglas Gregora16548e2009-08-11 05:31:07 +00003850 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3851 if (Init.isInvalid())
3852 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003853
Douglas Gregora16548e2009-08-11 05:31:07 +00003854 if (!getDerived().AlwaysRebuild() &&
3855 T == E->getType() &&
3856 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003857 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003858
3859 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T,
3860 /*FIXME:*/E->getInitializer()->getLocEnd(),
3861 move(Init));
3862}
Mike Stump11289f42009-09-09 15:08:12 +00003863
Douglas Gregora16548e2009-08-11 05:31:07 +00003864template<typename Derived>
3865Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003866TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003867 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3868 if (Base.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 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003873 return SemaRef.Owned(E->Retain());
3874
Douglas Gregora16548e2009-08-11 05:31:07 +00003875 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003876 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003877 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3878 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3879 E->getAccessorLoc(),
3880 E->getAccessor());
3881}
Mike Stump11289f42009-09-09 15:08:12 +00003882
Douglas Gregora16548e2009-08-11 05:31:07 +00003883template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003884Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003885TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003886 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003887
Douglas Gregora16548e2009-08-11 05:31:07 +00003888 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3889 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3890 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3891 if (Init.isInvalid())
3892 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003893
Douglas Gregora16548e2009-08-11 05:31:07 +00003894 InitChanged = InitChanged || Init.get() != E->getInit(I);
3895 Inits.push_back(Init.takeAs<Expr>());
3896 }
Mike Stump11289f42009-09-09 15:08:12 +00003897
Douglas Gregora16548e2009-08-11 05:31:07 +00003898 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003899 return SemaRef.Owned(E->Retain());
3900
Douglas Gregora16548e2009-08-11 05:31:07 +00003901 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00003902 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00003903}
Mike Stump11289f42009-09-09 15:08:12 +00003904
Douglas Gregora16548e2009-08-11 05:31:07 +00003905template<typename Derived>
3906Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003907TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003908 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00003909
Douglas Gregorebe10102009-08-20 07:17:43 +00003910 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00003911 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3912 if (Init.isInvalid())
3913 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003914
Douglas Gregorebe10102009-08-20 07:17:43 +00003915 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00003916 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3917 bool ExprChanged = false;
3918 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3919 DEnd = E->designators_end();
3920 D != DEnd; ++D) {
3921 if (D->isFieldDesignator()) {
3922 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3923 D->getDotLoc(),
3924 D->getFieldLoc()));
3925 continue;
3926 }
Mike Stump11289f42009-09-09 15:08:12 +00003927
Douglas Gregora16548e2009-08-11 05:31:07 +00003928 if (D->isArrayDesignator()) {
3929 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3930 if (Index.isInvalid())
3931 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003932
3933 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003934 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003935
Douglas Gregora16548e2009-08-11 05:31:07 +00003936 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3937 ArrayExprs.push_back(Index.release());
3938 continue;
3939 }
Mike Stump11289f42009-09-09 15:08:12 +00003940
Douglas Gregora16548e2009-08-11 05:31:07 +00003941 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00003942 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00003943 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3944 if (Start.isInvalid())
3945 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003946
Douglas Gregora16548e2009-08-11 05:31:07 +00003947 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3948 if (End.isInvalid())
3949 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003950
3951 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003952 End.get(),
3953 D->getLBracketLoc(),
3954 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003955
Douglas Gregora16548e2009-08-11 05:31:07 +00003956 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
3957 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00003958
Douglas Gregora16548e2009-08-11 05:31:07 +00003959 ArrayExprs.push_back(Start.release());
3960 ArrayExprs.push_back(End.release());
3961 }
Mike Stump11289f42009-09-09 15:08:12 +00003962
Douglas Gregora16548e2009-08-11 05:31:07 +00003963 if (!getDerived().AlwaysRebuild() &&
3964 Init.get() == E->getInit() &&
3965 !ExprChanged)
3966 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003967
Douglas Gregora16548e2009-08-11 05:31:07 +00003968 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
3969 E->getEqualOrColonLoc(),
3970 E->usesGNUSyntax(), move(Init));
3971}
Mike Stump11289f42009-09-09 15:08:12 +00003972
Douglas Gregora16548e2009-08-11 05:31:07 +00003973template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003974Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003975TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00003976 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00003977 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3978
3979 // FIXME: Will we ever have proper type location here? Will we actually
3980 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00003981 QualType T = getDerived().TransformType(E->getType());
3982 if (T.isNull())
3983 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003984
Douglas Gregora16548e2009-08-11 05:31:07 +00003985 if (!getDerived().AlwaysRebuild() &&
3986 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00003987 return SemaRef.Owned(E->Retain());
3988
Douglas Gregora16548e2009-08-11 05:31:07 +00003989 return getDerived().RebuildImplicitValueInitExpr(T);
3990}
Mike Stump11289f42009-09-09 15:08:12 +00003991
Douglas Gregora16548e2009-08-11 05:31:07 +00003992template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003993Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003994TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003995 // FIXME: Do we want the type as written?
3996 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00003997
Douglas Gregora16548e2009-08-11 05:31:07 +00003998 {
3999 // FIXME: Source location isn't quite accurate.
4000 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4001 T = getDerived().TransformType(E->getType());
4002 if (T.isNull())
4003 return SemaRef.ExprError();
4004 }
Mike Stump11289f42009-09-09 15:08:12 +00004005
Douglas Gregora16548e2009-08-11 05:31:07 +00004006 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4007 if (SubExpr.isInvalid())
4008 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004009
Douglas Gregora16548e2009-08-11 05:31:07 +00004010 if (!getDerived().AlwaysRebuild() &&
4011 T == E->getType() &&
4012 SubExpr.get() == E->getSubExpr())
4013 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004014
Douglas Gregora16548e2009-08-11 05:31:07 +00004015 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4016 T, E->getRParenLoc());
4017}
4018
4019template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004020Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004021TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004022 bool ArgumentChanged = false;
4023 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4024 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4025 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4026 if (Init.isInvalid())
4027 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004028
Douglas Gregora16548e2009-08-11 05:31:07 +00004029 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4030 Inits.push_back(Init.takeAs<Expr>());
4031 }
Mike Stump11289f42009-09-09 15:08:12 +00004032
Douglas Gregora16548e2009-08-11 05:31:07 +00004033 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4034 move_arg(Inits),
4035 E->getRParenLoc());
4036}
Mike Stump11289f42009-09-09 15:08:12 +00004037
Douglas Gregora16548e2009-08-11 05:31:07 +00004038/// \brief Transform an address-of-label expression.
4039///
4040/// By default, the transformation of an address-of-label expression always
4041/// rebuilds the expression, so that the label identifier can be resolved to
4042/// the corresponding label statement by semantic analysis.
4043template<typename Derived>
4044Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004045TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004046 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4047 E->getLabel());
4048}
Mike Stump11289f42009-09-09 15:08:12 +00004049
4050template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004051Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004052TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004053 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004054 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4055 if (SubStmt.isInvalid())
4056 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004057
Douglas Gregora16548e2009-08-11 05:31:07 +00004058 if (!getDerived().AlwaysRebuild() &&
4059 SubStmt.get() == E->getSubStmt())
4060 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004061
4062 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004063 move(SubStmt),
4064 E->getRParenLoc());
4065}
Mike Stump11289f42009-09-09 15:08:12 +00004066
Douglas Gregora16548e2009-08-11 05:31:07 +00004067template<typename Derived>
4068Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004069TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004070 QualType T1, T2;
4071 {
4072 // FIXME: Source location isn't quite accurate.
4073 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004074
Douglas Gregora16548e2009-08-11 05:31:07 +00004075 T1 = getDerived().TransformType(E->getArgType1());
4076 if (T1.isNull())
4077 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004078
Douglas Gregora16548e2009-08-11 05:31:07 +00004079 T2 = getDerived().TransformType(E->getArgType2());
4080 if (T2.isNull())
4081 return SemaRef.ExprError();
4082 }
4083
4084 if (!getDerived().AlwaysRebuild() &&
4085 T1 == E->getArgType1() &&
4086 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004087 return SemaRef.Owned(E->Retain());
4088
Douglas Gregora16548e2009-08-11 05:31:07 +00004089 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4090 T1, T2, E->getRParenLoc());
4091}
Mike Stump11289f42009-09-09 15:08:12 +00004092
Douglas Gregora16548e2009-08-11 05:31:07 +00004093template<typename Derived>
4094Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004095TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004096 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4097 if (Cond.isInvalid())
4098 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004099
Douglas Gregora16548e2009-08-11 05:31:07 +00004100 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4101 if (LHS.isInvalid())
4102 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004103
Douglas Gregora16548e2009-08-11 05:31:07 +00004104 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4105 if (RHS.isInvalid())
4106 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004107
Douglas Gregora16548e2009-08-11 05:31:07 +00004108 if (!getDerived().AlwaysRebuild() &&
4109 Cond.get() == E->getCond() &&
4110 LHS.get() == E->getLHS() &&
4111 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004112 return SemaRef.Owned(E->Retain());
4113
Douglas Gregora16548e2009-08-11 05:31:07 +00004114 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4115 move(Cond), move(LHS), move(RHS),
4116 E->getRParenLoc());
4117}
Mike Stump11289f42009-09-09 15:08:12 +00004118
Douglas Gregora16548e2009-08-11 05:31:07 +00004119template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004120Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004121TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004122 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004123}
4124
4125template<typename Derived>
4126Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004127TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004128 switch (E->getOperator()) {
4129 case OO_New:
4130 case OO_Delete:
4131 case OO_Array_New:
4132 case OO_Array_Delete:
4133 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4134 return SemaRef.ExprError();
4135
4136 case OO_Call: {
4137 // This is a call to an object's operator().
4138 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4139
4140 // Transform the object itself.
4141 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4142 if (Object.isInvalid())
4143 return SemaRef.ExprError();
4144
4145 // FIXME: Poor location information
4146 SourceLocation FakeLParenLoc
4147 = SemaRef.PP.getLocForEndOfToken(
4148 static_cast<Expr *>(Object.get())->getLocEnd());
4149
4150 // Transform the call arguments.
4151 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4152 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4153 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004154 if (getDerived().DropCallArgument(E->getArg(I)))
4155 break;
4156
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004157 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4158 if (Arg.isInvalid())
4159 return SemaRef.ExprError();
4160
4161 // FIXME: Poor source location information.
4162 SourceLocation FakeCommaLoc
4163 = SemaRef.PP.getLocForEndOfToken(
4164 static_cast<Expr *>(Arg.get())->getLocEnd());
4165 FakeCommaLocs.push_back(FakeCommaLoc);
4166 Args.push_back(Arg.release());
4167 }
4168
4169 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4170 move_arg(Args),
4171 FakeCommaLocs.data(),
4172 E->getLocEnd());
4173 }
4174
4175#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4176 case OO_##Name:
4177#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4178#include "clang/Basic/OperatorKinds.def"
4179 case OO_Subscript:
4180 // Handled below.
4181 break;
4182
4183 case OO_Conditional:
4184 llvm_unreachable("conditional operator is not actually overloadable");
4185 return SemaRef.ExprError();
4186
4187 case OO_None:
4188 case NUM_OVERLOADED_OPERATORS:
4189 llvm_unreachable("not an overloaded operator?");
4190 return SemaRef.ExprError();
4191 }
4192
Douglas Gregora16548e2009-08-11 05:31:07 +00004193 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4194 if (Callee.isInvalid())
4195 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004196
John McCall47f29ea2009-12-08 09:21:05 +00004197 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004198 if (First.isInvalid())
4199 return SemaRef.ExprError();
4200
4201 OwningExprResult Second(SemaRef);
4202 if (E->getNumArgs() == 2) {
4203 Second = getDerived().TransformExpr(E->getArg(1));
4204 if (Second.isInvalid())
4205 return SemaRef.ExprError();
4206 }
Mike Stump11289f42009-09-09 15:08:12 +00004207
Douglas Gregora16548e2009-08-11 05:31:07 +00004208 if (!getDerived().AlwaysRebuild() &&
4209 Callee.get() == E->getCallee() &&
4210 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004211 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4212 return SemaRef.Owned(E->Retain());
4213
Douglas Gregora16548e2009-08-11 05:31:07 +00004214 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4215 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004216 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004217 move(First),
4218 move(Second));
4219}
Mike Stump11289f42009-09-09 15:08:12 +00004220
Douglas Gregora16548e2009-08-11 05:31:07 +00004221template<typename Derived>
4222Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004223TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4224 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004225}
Mike Stump11289f42009-09-09 15:08:12 +00004226
Douglas Gregora16548e2009-08-11 05:31:07 +00004227template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004228Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004229TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004230 QualType ExplicitTy;
4231 {
4232 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004233 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004234 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4235 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004236
Douglas Gregora16548e2009-08-11 05:31:07 +00004237 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4238 if (ExplicitTy.isNull())
4239 return SemaRef.ExprError();
4240 }
Mike Stump11289f42009-09-09 15:08:12 +00004241
Douglas Gregor6131b442009-12-12 18:16:41 +00004242 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004243 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004244 if (SubExpr.isInvalid())
4245 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004246
Douglas Gregora16548e2009-08-11 05:31:07 +00004247 if (!getDerived().AlwaysRebuild() &&
4248 ExplicitTy == E->getTypeAsWritten() &&
4249 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004250 return SemaRef.Owned(E->Retain());
4251
Douglas Gregora16548e2009-08-11 05:31:07 +00004252 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004253 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004254 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4255 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4256 SourceLocation FakeRParenLoc
4257 = SemaRef.PP.getLocForEndOfToken(
4258 E->getSubExpr()->getSourceRange().getEnd());
4259 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004260 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004261 FakeLAngleLoc,
4262 ExplicitTy,
4263 FakeRAngleLoc,
4264 FakeRAngleLoc,
4265 move(SubExpr),
4266 FakeRParenLoc);
4267}
Mike Stump11289f42009-09-09 15:08:12 +00004268
Douglas Gregora16548e2009-08-11 05:31:07 +00004269template<typename Derived>
4270Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004271TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4272 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004273}
Mike Stump11289f42009-09-09 15:08:12 +00004274
4275template<typename Derived>
4276Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004277TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4278 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004279}
4280
Douglas Gregora16548e2009-08-11 05:31:07 +00004281template<typename Derived>
4282Sema::OwningExprResult
4283TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004284 CXXReinterpretCastExpr *E) {
4285 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004286}
Mike Stump11289f42009-09-09 15:08:12 +00004287
Douglas Gregora16548e2009-08-11 05:31:07 +00004288template<typename Derived>
4289Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004290TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4291 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004292}
Mike Stump11289f42009-09-09 15:08:12 +00004293
Douglas Gregora16548e2009-08-11 05:31:07 +00004294template<typename Derived>
4295Sema::OwningExprResult
4296TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004297 CXXFunctionalCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004298 QualType ExplicitTy;
4299 {
4300 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004301
Douglas Gregora16548e2009-08-11 05:31:07 +00004302 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4303 if (ExplicitTy.isNull())
4304 return SemaRef.ExprError();
4305 }
Mike Stump11289f42009-09-09 15:08:12 +00004306
Douglas Gregor6131b442009-12-12 18:16:41 +00004307 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004308 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004309 if (SubExpr.isInvalid())
4310 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004311
Douglas Gregora16548e2009-08-11 05:31:07 +00004312 if (!getDerived().AlwaysRebuild() &&
4313 ExplicitTy == E->getTypeAsWritten() &&
4314 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004315 return SemaRef.Owned(E->Retain());
4316
Douglas Gregora16548e2009-08-11 05:31:07 +00004317 // FIXME: The end of the type's source range is wrong
4318 return getDerived().RebuildCXXFunctionalCastExpr(
4319 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
4320 ExplicitTy,
4321 /*FIXME:*/E->getSubExpr()->getLocStart(),
4322 move(SubExpr),
4323 E->getRParenLoc());
4324}
Mike Stump11289f42009-09-09 15:08:12 +00004325
Douglas Gregora16548e2009-08-11 05:31:07 +00004326template<typename Derived>
4327Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004328TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004329 if (E->isTypeOperand()) {
4330 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004331
Douglas Gregora16548e2009-08-11 05:31:07 +00004332 QualType T = getDerived().TransformType(E->getTypeOperand());
4333 if (T.isNull())
4334 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004335
Douglas Gregora16548e2009-08-11 05:31:07 +00004336 if (!getDerived().AlwaysRebuild() &&
4337 T == E->getTypeOperand())
4338 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004339
Douglas Gregora16548e2009-08-11 05:31:07 +00004340 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4341 /*FIXME:*/E->getLocStart(),
4342 T,
4343 E->getLocEnd());
4344 }
Mike Stump11289f42009-09-09 15:08:12 +00004345
Douglas Gregora16548e2009-08-11 05:31:07 +00004346 // We don't know whether the expression is potentially evaluated until
4347 // after we perform semantic analysis, so the expression is potentially
4348 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004349 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004350 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004351
Douglas Gregora16548e2009-08-11 05:31:07 +00004352 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4353 if (SubExpr.isInvalid())
4354 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004355
Douglas Gregora16548e2009-08-11 05:31:07 +00004356 if (!getDerived().AlwaysRebuild() &&
4357 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004358 return SemaRef.Owned(E->Retain());
4359
Douglas Gregora16548e2009-08-11 05:31:07 +00004360 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4361 /*FIXME:*/E->getLocStart(),
4362 move(SubExpr),
4363 E->getLocEnd());
4364}
4365
4366template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004367Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004368TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004369 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004370}
Mike Stump11289f42009-09-09 15:08:12 +00004371
Douglas Gregora16548e2009-08-11 05:31:07 +00004372template<typename Derived>
4373Sema::OwningExprResult
4374TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004375 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004376 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004377}
Mike Stump11289f42009-09-09 15:08:12 +00004378
Douglas Gregora16548e2009-08-11 05:31:07 +00004379template<typename Derived>
4380Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004381TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004382 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004383
Douglas Gregora16548e2009-08-11 05:31:07 +00004384 QualType T = getDerived().TransformType(E->getType());
4385 if (T.isNull())
4386 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004387
Douglas Gregora16548e2009-08-11 05:31:07 +00004388 if (!getDerived().AlwaysRebuild() &&
4389 T == E->getType())
4390 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004391
Douglas Gregora16548e2009-08-11 05:31:07 +00004392 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T);
4393}
Mike Stump11289f42009-09-09 15:08:12 +00004394
Douglas Gregora16548e2009-08-11 05:31:07 +00004395template<typename Derived>
4396Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004397TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004398 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4399 if (SubExpr.isInvalid())
4400 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004401
Douglas Gregora16548e2009-08-11 05:31:07 +00004402 if (!getDerived().AlwaysRebuild() &&
4403 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004404 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004405
4406 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4407}
Mike Stump11289f42009-09-09 15:08:12 +00004408
Douglas Gregora16548e2009-08-11 05:31:07 +00004409template<typename Derived>
4410Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004411TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004412 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004413 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4414 if (!Param)
4415 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004416
Douglas Gregora16548e2009-08-11 05:31:07 +00004417 if (getDerived().AlwaysRebuild() &&
4418 Param == E->getParam())
4419 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004420
Douglas Gregor033f6752009-12-23 23:03:06 +00004421 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00004422}
Mike Stump11289f42009-09-09 15:08:12 +00004423
Douglas Gregora16548e2009-08-11 05:31:07 +00004424template<typename Derived>
4425Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004426TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004427 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4428
4429 QualType T = getDerived().TransformType(E->getType());
4430 if (T.isNull())
4431 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004432
Douglas Gregora16548e2009-08-11 05:31:07 +00004433 if (!getDerived().AlwaysRebuild() &&
4434 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004435 return SemaRef.Owned(E->Retain());
4436
4437 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004438 /*FIXME:*/E->getTypeBeginLoc(),
4439 T,
4440 E->getRParenLoc());
4441}
Mike Stump11289f42009-09-09 15:08:12 +00004442
Douglas Gregora16548e2009-08-11 05:31:07 +00004443template<typename Derived>
4444Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004445TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004446 // Transform the type that we're allocating
4447 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4448 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4449 if (AllocType.isNull())
4450 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004451
Douglas Gregora16548e2009-08-11 05:31:07 +00004452 // Transform the size of the array we're allocating (if any).
4453 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4454 if (ArraySize.isInvalid())
4455 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004456
Douglas Gregora16548e2009-08-11 05:31:07 +00004457 // Transform the placement arguments (if any).
4458 bool ArgumentChanged = false;
4459 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4460 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4461 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4462 if (Arg.isInvalid())
4463 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004464
Douglas Gregora16548e2009-08-11 05:31:07 +00004465 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4466 PlacementArgs.push_back(Arg.take());
4467 }
Mike Stump11289f42009-09-09 15:08:12 +00004468
Douglas Gregorebe10102009-08-20 07:17:43 +00004469 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004470 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4471 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4472 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4473 if (Arg.isInvalid())
4474 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004475
Douglas Gregora16548e2009-08-11 05:31:07 +00004476 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4477 ConstructorArgs.push_back(Arg.take());
4478 }
Mike Stump11289f42009-09-09 15:08:12 +00004479
Douglas Gregora16548e2009-08-11 05:31:07 +00004480 if (!getDerived().AlwaysRebuild() &&
4481 AllocType == E->getAllocatedType() &&
4482 ArraySize.get() == E->getArraySize() &&
4483 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004484 return SemaRef.Owned(E->Retain());
4485
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004486 if (!ArraySize.get()) {
4487 // If no array size was specified, but the new expression was
4488 // instantiated with an array type (e.g., "new T" where T is
4489 // instantiated with "int[4]"), extract the outer bound from the
4490 // array type as our array size. We do this with constant and
4491 // dependently-sized array types.
4492 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4493 if (!ArrayT) {
4494 // Do nothing
4495 } else if (const ConstantArrayType *ConsArrayT
4496 = dyn_cast<ConstantArrayType>(ArrayT)) {
4497 ArraySize
4498 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4499 ConsArrayT->getSize(),
4500 SemaRef.Context.getSizeType(),
4501 /*FIXME:*/E->getLocStart()));
4502 AllocType = ConsArrayT->getElementType();
4503 } else if (const DependentSizedArrayType *DepArrayT
4504 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4505 if (DepArrayT->getSizeExpr()) {
4506 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4507 AllocType = DepArrayT->getElementType();
4508 }
4509 }
4510 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004511 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4512 E->isGlobalNew(),
4513 /*FIXME:*/E->getLocStart(),
4514 move_arg(PlacementArgs),
4515 /*FIXME:*/E->getLocStart(),
4516 E->isParenTypeId(),
4517 AllocType,
4518 /*FIXME:*/E->getLocStart(),
4519 /*FIXME:*/SourceRange(),
4520 move(ArraySize),
4521 /*FIXME:*/E->getLocStart(),
4522 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004523 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004524}
Mike Stump11289f42009-09-09 15:08:12 +00004525
Douglas Gregora16548e2009-08-11 05:31:07 +00004526template<typename Derived>
4527Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004528TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004529 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4530 if (Operand.isInvalid())
4531 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004532
Douglas Gregora16548e2009-08-11 05:31:07 +00004533 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004534 Operand.get() == E->getArgument())
4535 return SemaRef.Owned(E->Retain());
4536
Douglas Gregora16548e2009-08-11 05:31:07 +00004537 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4538 E->isGlobalDelete(),
4539 E->isArrayForm(),
4540 move(Operand));
4541}
Mike Stump11289f42009-09-09 15:08:12 +00004542
Douglas Gregora16548e2009-08-11 05:31:07 +00004543template<typename Derived>
4544Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004545TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004546 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004547 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4548 if (Base.isInvalid())
4549 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004550
Douglas Gregorad8a3362009-09-04 17:36:40 +00004551 NestedNameSpecifier *Qualifier
4552 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4553 E->getQualifierRange());
4554 if (E->getQualifier() && !Qualifier)
4555 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004556
Douglas Gregorad8a3362009-09-04 17:36:40 +00004557 QualType DestroyedType;
4558 {
4559 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4560 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4561 if (DestroyedType.isNull())
4562 return SemaRef.ExprError();
4563 }
Mike Stump11289f42009-09-09 15:08:12 +00004564
Douglas Gregorad8a3362009-09-04 17:36:40 +00004565 if (!getDerived().AlwaysRebuild() &&
4566 Base.get() == E->getBase() &&
4567 Qualifier == E->getQualifier() &&
4568 DestroyedType == E->getDestroyedType())
4569 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004570
Douglas Gregorad8a3362009-09-04 17:36:40 +00004571 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4572 E->getOperatorLoc(),
4573 E->isArrow(),
4574 E->getDestroyedTypeLoc(),
4575 DestroyedType,
4576 Qualifier,
4577 E->getQualifierRange());
4578}
Mike Stump11289f42009-09-09 15:08:12 +00004579
Douglas Gregorad8a3362009-09-04 17:36:40 +00004580template<typename Derived>
4581Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004582TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004583 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00004584 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4585
4586 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4587 Sema::LookupOrdinaryName);
4588
4589 // Transform all the decls.
4590 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4591 E = Old->decls_end(); I != E; ++I) {
4592 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00004593 if (!InstD) {
4594 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4595 // This can happen because of dependent hiding.
4596 if (isa<UsingShadowDecl>(*I))
4597 continue;
4598 else
4599 return SemaRef.ExprError();
4600 }
John McCalle66edc12009-11-24 19:00:30 +00004601
4602 // Expand using declarations.
4603 if (isa<UsingDecl>(InstD)) {
4604 UsingDecl *UD = cast<UsingDecl>(InstD);
4605 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4606 E = UD->shadow_end(); I != E; ++I)
4607 R.addDecl(*I);
4608 continue;
4609 }
4610
4611 R.addDecl(InstD);
4612 }
4613
4614 // Resolve a kind, but don't do any further analysis. If it's
4615 // ambiguous, the callee needs to deal with it.
4616 R.resolveKind();
4617
4618 // Rebuild the nested-name qualifier, if present.
4619 CXXScopeSpec SS;
4620 NestedNameSpecifier *Qualifier = 0;
4621 if (Old->getQualifier()) {
4622 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4623 Old->getQualifierRange());
4624 if (!Qualifier)
4625 return SemaRef.ExprError();
4626
4627 SS.setScopeRep(Qualifier);
4628 SS.setRange(Old->getQualifierRange());
4629 }
4630
4631 // If we have no template arguments, it's a normal declaration name.
4632 if (!Old->hasExplicitTemplateArgs())
4633 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4634
4635 // If we have template arguments, rebuild them, then rebuild the
4636 // templateid expression.
4637 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4638 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4639 TemplateArgumentLoc Loc;
4640 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4641 return SemaRef.ExprError();
4642 TransArgs.addArgument(Loc);
4643 }
4644
4645 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4646 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004647}
Mike Stump11289f42009-09-09 15:08:12 +00004648
Douglas Gregora16548e2009-08-11 05:31:07 +00004649template<typename Derived>
4650Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004651TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004652 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004653
Douglas Gregora16548e2009-08-11 05:31:07 +00004654 QualType T = getDerived().TransformType(E->getQueriedType());
4655 if (T.isNull())
4656 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004657
Douglas Gregora16548e2009-08-11 05:31:07 +00004658 if (!getDerived().AlwaysRebuild() &&
4659 T == E->getQueriedType())
4660 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004661
Douglas Gregora16548e2009-08-11 05:31:07 +00004662 // FIXME: Bad location information
4663 SourceLocation FakeLParenLoc
4664 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004665
4666 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004667 E->getLocStart(),
4668 /*FIXME:*/FakeLParenLoc,
4669 T,
4670 E->getLocEnd());
4671}
Mike Stump11289f42009-09-09 15:08:12 +00004672
Douglas Gregora16548e2009-08-11 05:31:07 +00004673template<typename Derived>
4674Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004675TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004676 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004677 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004678 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4679 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004680 if (!NNS)
4681 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004682
4683 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004684 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4685 if (!Name)
4686 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004687
John McCalle66edc12009-11-24 19:00:30 +00004688 if (!E->hasExplicitTemplateArgs()) {
4689 if (!getDerived().AlwaysRebuild() &&
4690 NNS == E->getQualifier() &&
4691 Name == E->getDeclName())
4692 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004693
John McCalle66edc12009-11-24 19:00:30 +00004694 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4695 E->getQualifierRange(),
4696 Name, E->getLocation(),
4697 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004698 }
John McCall6b51f282009-11-23 01:53:49 +00004699
4700 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004701 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004702 TemplateArgumentLoc Loc;
4703 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004704 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004705 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004706 }
4707
John McCalle66edc12009-11-24 19:00:30 +00004708 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4709 E->getQualifierRange(),
4710 Name, E->getLocation(),
4711 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004712}
4713
4714template<typename Derived>
4715Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004716TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004717 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4718
4719 QualType T = getDerived().TransformType(E->getType());
4720 if (T.isNull())
4721 return SemaRef.ExprError();
4722
4723 CXXConstructorDecl *Constructor
4724 = cast_or_null<CXXConstructorDecl>(
4725 getDerived().TransformDecl(E->getConstructor()));
4726 if (!Constructor)
4727 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004728
Douglas Gregora16548e2009-08-11 05:31:07 +00004729 bool ArgumentChanged = false;
4730 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004731 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004732 ArgEnd = E->arg_end();
4733 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00004734 if (getDerived().DropCallArgument(*Arg)) {
4735 ArgumentChanged = true;
4736 break;
4737 }
4738
Douglas Gregora16548e2009-08-11 05:31:07 +00004739 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4740 if (TransArg.isInvalid())
4741 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004742
Douglas Gregora16548e2009-08-11 05:31:07 +00004743 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4744 Args.push_back(TransArg.takeAs<Expr>());
4745 }
4746
4747 if (!getDerived().AlwaysRebuild() &&
4748 T == E->getType() &&
4749 Constructor == E->getConstructor() &&
4750 !ArgumentChanged)
4751 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004752
Douglas Gregordb121ba2009-12-14 16:27:04 +00004753 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
4754 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004755 move_arg(Args));
4756}
Mike Stump11289f42009-09-09 15:08:12 +00004757
Douglas Gregora16548e2009-08-11 05:31:07 +00004758/// \brief Transform a C++ temporary-binding expression.
4759///
Mike Stump11289f42009-09-09 15:08:12 +00004760/// The transformation of a temporary-binding expression always attempts to
4761/// bind a new temporary variable to its subexpression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004762/// subexpression itself did not change, because the temporary variable itself
4763/// must be unique.
4764template<typename Derived>
4765Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004766TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004767 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4768 if (SubExpr.isInvalid())
4769 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004770
Douglas Gregora16548e2009-08-11 05:31:07 +00004771 return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>());
4772}
Mike Stump11289f42009-09-09 15:08:12 +00004773
4774/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004775/// be destroyed after the expression is evaluated.
4776///
Mike Stump11289f42009-09-09 15:08:12 +00004777/// The transformation of a full expression always attempts to build a new
4778/// CXXExprWithTemporaries expression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004779/// subexpression itself did not change, because it will need to capture the
4780/// the new temporary variables introduced in the subexpression.
4781template<typename Derived>
4782Sema::OwningExprResult
4783TreeTransform<Derived>::TransformCXXExprWithTemporaries(
John McCall47f29ea2009-12-08 09:21:05 +00004784 CXXExprWithTemporaries *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004785 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4786 if (SubExpr.isInvalid())
4787 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004788
Douglas Gregora16548e2009-08-11 05:31:07 +00004789 return SemaRef.Owned(
Anders Carlsson6e997b22009-12-15 20:51:39 +00004790 SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004791}
Mike Stump11289f42009-09-09 15:08:12 +00004792
Douglas Gregora16548e2009-08-11 05:31:07 +00004793template<typename Derived>
4794Sema::OwningExprResult
4795TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004796 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004797 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4798 QualType T = getDerived().TransformType(E->getType());
4799 if (T.isNull())
4800 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004801
Douglas Gregora16548e2009-08-11 05:31:07 +00004802 CXXConstructorDecl *Constructor
4803 = cast_or_null<CXXConstructorDecl>(
4804 getDerived().TransformDecl(E->getConstructor()));
4805 if (!Constructor)
4806 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004807
Douglas Gregora16548e2009-08-11 05:31:07 +00004808 bool ArgumentChanged = false;
4809 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4810 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004811 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004812 ArgEnd = E->arg_end();
4813 Arg != ArgEnd; ++Arg) {
4814 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4815 if (TransArg.isInvalid())
4816 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004817
Douglas Gregora16548e2009-08-11 05:31:07 +00004818 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4819 Args.push_back((Expr *)TransArg.release());
4820 }
Mike Stump11289f42009-09-09 15:08:12 +00004821
Douglas Gregora16548e2009-08-11 05:31:07 +00004822 if (!getDerived().AlwaysRebuild() &&
4823 T == E->getType() &&
4824 Constructor == E->getConstructor() &&
4825 !ArgumentChanged)
4826 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004827
Douglas Gregora16548e2009-08-11 05:31:07 +00004828 // FIXME: Bogus location information
4829 SourceLocation CommaLoc;
4830 if (Args.size() > 1) {
4831 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004832 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004833 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4834 }
4835 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4836 T,
4837 /*FIXME:*/E->getTypeBeginLoc(),
4838 move_arg(Args),
4839 &CommaLoc,
4840 E->getLocEnd());
4841}
Mike Stump11289f42009-09-09 15:08:12 +00004842
Douglas Gregora16548e2009-08-11 05:31:07 +00004843template<typename Derived>
4844Sema::OwningExprResult
4845TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004846 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004847 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4848 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4849 if (T.isNull())
4850 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004851
Douglas Gregora16548e2009-08-11 05:31:07 +00004852 bool ArgumentChanged = false;
4853 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4854 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4855 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4856 ArgEnd = E->arg_end();
4857 Arg != ArgEnd; ++Arg) {
4858 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4859 if (TransArg.isInvalid())
4860 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004861
Douglas Gregora16548e2009-08-11 05:31:07 +00004862 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4863 FakeCommaLocs.push_back(
4864 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4865 Args.push_back(TransArg.takeAs<Expr>());
4866 }
Mike Stump11289f42009-09-09 15:08:12 +00004867
Douglas Gregora16548e2009-08-11 05:31:07 +00004868 if (!getDerived().AlwaysRebuild() &&
4869 T == E->getTypeAsWritten() &&
4870 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004871 return SemaRef.Owned(E->Retain());
4872
Douglas Gregora16548e2009-08-11 05:31:07 +00004873 // FIXME: we're faking the locations of the commas
4874 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4875 T,
4876 E->getLParenLoc(),
4877 move_arg(Args),
4878 FakeCommaLocs.data(),
4879 E->getRParenLoc());
4880}
Mike Stump11289f42009-09-09 15:08:12 +00004881
Douglas Gregora16548e2009-08-11 05:31:07 +00004882template<typename Derived>
4883Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004884TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004885 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004886 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004887 OwningExprResult Base(SemaRef, (Expr*) 0);
4888 Expr *OldBase;
4889 QualType BaseType;
4890 QualType ObjectType;
4891 if (!E->isImplicitAccess()) {
4892 OldBase = E->getBase();
4893 Base = getDerived().TransformExpr(OldBase);
4894 if (Base.isInvalid())
4895 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004896
John McCall2d74de92009-12-01 22:10:20 +00004897 // Start the member reference and compute the object's type.
4898 Sema::TypeTy *ObjectTy = 0;
4899 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4900 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004901 E->isArrow()? tok::arrow : tok::period,
John McCall2d74de92009-12-01 22:10:20 +00004902 ObjectTy);
4903 if (Base.isInvalid())
4904 return SemaRef.ExprError();
4905
4906 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
4907 BaseType = ((Expr*) Base.get())->getType();
4908 } else {
4909 OldBase = 0;
4910 BaseType = getDerived().TransformType(E->getBaseType());
4911 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
4912 }
Mike Stump11289f42009-09-09 15:08:12 +00004913
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004914 // Transform the first part of the nested-name-specifier that qualifies
4915 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004916 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004917 = getDerived().TransformFirstQualifierInScope(
4918 E->getFirstQualifierFoundInScope(),
4919 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00004920
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004921 NestedNameSpecifier *Qualifier = 0;
4922 if (E->getQualifier()) {
4923 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4924 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00004925 ObjectType,
4926 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004927 if (!Qualifier)
4928 return SemaRef.ExprError();
4929 }
Mike Stump11289f42009-09-09 15:08:12 +00004930
4931 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00004932 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00004933 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00004934 if (!Name)
4935 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004936
John McCall2d74de92009-12-01 22:10:20 +00004937 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00004938 // This is a reference to a member without an explicitly-specified
4939 // template argument list. Optimize for this common case.
4940 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00004941 Base.get() == OldBase &&
4942 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00004943 Qualifier == E->getQualifier() &&
4944 Name == E->getMember() &&
4945 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00004946 return SemaRef.Owned(E->Retain());
4947
John McCall8cd78132009-11-19 22:55:06 +00004948 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00004949 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00004950 E->isArrow(),
4951 E->getOperatorLoc(),
4952 Qualifier,
4953 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00004954 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00004955 Name,
4956 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00004957 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00004958 }
4959
John McCall6b51f282009-11-23 01:53:49 +00004960 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00004961 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004962 TemplateArgumentLoc Loc;
4963 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00004964 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004965 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00004966 }
Mike Stump11289f42009-09-09 15:08:12 +00004967
John McCall8cd78132009-11-19 22:55:06 +00004968 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00004969 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00004970 E->isArrow(),
4971 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004972 Qualifier,
4973 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004974 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00004975 Name,
4976 E->getMemberLoc(),
4977 &TransArgs);
4978}
4979
4980template<typename Derived>
4981Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004982TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00004983 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004984 OwningExprResult Base(SemaRef, (Expr*) 0);
4985 QualType BaseType;
4986 if (!Old->isImplicitAccess()) {
4987 Base = getDerived().TransformExpr(Old->getBase());
4988 if (Base.isInvalid())
4989 return SemaRef.ExprError();
4990 BaseType = ((Expr*) Base.get())->getType();
4991 } else {
4992 BaseType = getDerived().TransformType(Old->getBaseType());
4993 }
John McCall10eae182009-11-30 22:42:35 +00004994
4995 NestedNameSpecifier *Qualifier = 0;
4996 if (Old->getQualifier()) {
4997 Qualifier
4998 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4999 Old->getQualifierRange());
5000 if (Qualifier == 0)
5001 return SemaRef.ExprError();
5002 }
5003
5004 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5005 Sema::LookupOrdinaryName);
5006
5007 // Transform all the decls.
5008 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5009 E = Old->decls_end(); I != E; ++I) {
5010 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00005011 if (!InstD) {
5012 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5013 // This can happen because of dependent hiding.
5014 if (isa<UsingShadowDecl>(*I))
5015 continue;
5016 else
5017 return SemaRef.ExprError();
5018 }
John McCall10eae182009-11-30 22:42:35 +00005019
5020 // Expand using declarations.
5021 if (isa<UsingDecl>(InstD)) {
5022 UsingDecl *UD = cast<UsingDecl>(InstD);
5023 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5024 E = UD->shadow_end(); I != E; ++I)
5025 R.addDecl(*I);
5026 continue;
5027 }
5028
5029 R.addDecl(InstD);
5030 }
5031
5032 R.resolveKind();
5033
5034 TemplateArgumentListInfo TransArgs;
5035 if (Old->hasExplicitTemplateArgs()) {
5036 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5037 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5038 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5039 TemplateArgumentLoc Loc;
5040 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5041 Loc))
5042 return SemaRef.ExprError();
5043 TransArgs.addArgument(Loc);
5044 }
5045 }
5046
5047 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005048 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005049 Old->getOperatorLoc(),
5050 Old->isArrow(),
5051 Qualifier,
5052 Old->getQualifierRange(),
5053 R,
5054 (Old->hasExplicitTemplateArgs()
5055 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005056}
5057
5058template<typename Derived>
5059Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005060TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005061 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005062}
5063
Mike Stump11289f42009-09-09 15:08:12 +00005064template<typename Derived>
5065Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005066TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005067 // FIXME: poor source location
5068 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5069 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5070 if (EncodedType.isNull())
5071 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005072
Douglas Gregora16548e2009-08-11 05:31:07 +00005073 if (!getDerived().AlwaysRebuild() &&
5074 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00005075 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005076
5077 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5078 EncodedType,
5079 E->getRParenLoc());
5080}
Mike Stump11289f42009-09-09 15:08:12 +00005081
Douglas Gregora16548e2009-08-11 05:31:07 +00005082template<typename Derived>
5083Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005084TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005085 // FIXME: Implement this!
5086 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005087 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005088}
5089
Mike Stump11289f42009-09-09 15:08:12 +00005090template<typename Derived>
5091Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005092TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005093 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005094}
5095
Mike Stump11289f42009-09-09 15:08:12 +00005096template<typename Derived>
5097Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005098TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005099 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00005100 = cast_or_null<ObjCProtocolDecl>(
5101 getDerived().TransformDecl(E->getProtocol()));
5102 if (!Protocol)
5103 return SemaRef.ExprError();
5104
5105 if (!getDerived().AlwaysRebuild() &&
5106 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005107 return SemaRef.Owned(E->Retain());
5108
Douglas Gregora16548e2009-08-11 05:31:07 +00005109 return getDerived().RebuildObjCProtocolExpr(Protocol,
5110 E->getAtLoc(),
5111 /*FIXME:*/E->getAtLoc(),
5112 /*FIXME:*/E->getAtLoc(),
5113 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005114
Douglas Gregora16548e2009-08-11 05:31:07 +00005115}
5116
Mike Stump11289f42009-09-09 15:08:12 +00005117template<typename Derived>
5118Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005119TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005120 // FIXME: Implement this!
5121 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005122 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005123}
5124
Mike Stump11289f42009-09-09 15:08:12 +00005125template<typename Derived>
5126Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005127TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005128 // FIXME: Implement this!
5129 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005130 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005131}
5132
Mike Stump11289f42009-09-09 15:08:12 +00005133template<typename Derived>
5134Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005135TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005136 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005137 // FIXME: Implement this!
5138 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005139 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005140}
5141
Mike Stump11289f42009-09-09 15:08:12 +00005142template<typename Derived>
5143Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005144TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005145 // FIXME: Implement this!
5146 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005147 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005148}
5149
Mike Stump11289f42009-09-09 15:08:12 +00005150template<typename Derived>
5151Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005152TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005153 // FIXME: Implement this!
5154 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005155 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005156}
5157
Mike Stump11289f42009-09-09 15:08:12 +00005158template<typename Derived>
5159Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005160TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005161 bool ArgumentChanged = false;
5162 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5163 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5164 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5165 if (SubExpr.isInvalid())
5166 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005167
Douglas Gregora16548e2009-08-11 05:31:07 +00005168 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5169 SubExprs.push_back(SubExpr.takeAs<Expr>());
5170 }
Mike Stump11289f42009-09-09 15:08:12 +00005171
Douglas Gregora16548e2009-08-11 05:31:07 +00005172 if (!getDerived().AlwaysRebuild() &&
5173 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005174 return SemaRef.Owned(E->Retain());
5175
Douglas Gregora16548e2009-08-11 05:31:07 +00005176 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5177 move_arg(SubExprs),
5178 E->getRParenLoc());
5179}
5180
Mike Stump11289f42009-09-09 15:08:12 +00005181template<typename Derived>
5182Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005183TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005184 // FIXME: Implement this!
5185 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005186 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005187}
5188
Mike Stump11289f42009-09-09 15:08:12 +00005189template<typename Derived>
5190Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005191TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005192 // FIXME: Implement this!
5193 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005194 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005195}
Mike Stump11289f42009-09-09 15:08:12 +00005196
Douglas Gregora16548e2009-08-11 05:31:07 +00005197//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005198// Type reconstruction
5199//===----------------------------------------------------------------------===//
5200
Mike Stump11289f42009-09-09 15:08:12 +00005201template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005202QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5203 SourceLocation Star) {
5204 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005205 getDerived().getBaseEntity());
5206}
5207
Mike Stump11289f42009-09-09 15:08:12 +00005208template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005209QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5210 SourceLocation Star) {
5211 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005212 getDerived().getBaseEntity());
5213}
5214
Mike Stump11289f42009-09-09 15:08:12 +00005215template<typename Derived>
5216QualType
John McCall70dd5f62009-10-30 00:06:24 +00005217TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5218 bool WrittenAsLValue,
5219 SourceLocation Sigil) {
5220 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5221 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005222}
5223
5224template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005225QualType
John McCall70dd5f62009-10-30 00:06:24 +00005226TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5227 QualType ClassType,
5228 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005229 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005230 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005231}
5232
5233template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005234QualType
John McCall70dd5f62009-10-30 00:06:24 +00005235TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5236 SourceLocation Sigil) {
5237 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005238 getDerived().getBaseEntity());
5239}
5240
5241template<typename Derived>
5242QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005243TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5244 ArrayType::ArraySizeModifier SizeMod,
5245 const llvm::APInt *Size,
5246 Expr *SizeExpr,
5247 unsigned IndexTypeQuals,
5248 SourceRange BracketsRange) {
5249 if (SizeExpr || !Size)
5250 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5251 IndexTypeQuals, BracketsRange,
5252 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005253
5254 QualType Types[] = {
5255 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5256 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5257 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005258 };
5259 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5260 QualType SizeType;
5261 for (unsigned I = 0; I != NumTypes; ++I)
5262 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5263 SizeType = Types[I];
5264 break;
5265 }
Mike Stump11289f42009-09-09 15:08:12 +00005266
Douglas Gregord6ff3322009-08-04 16:50:30 +00005267 if (SizeType.isNull())
5268 SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false);
Mike Stump11289f42009-09-09 15:08:12 +00005269
Douglas Gregord6ff3322009-08-04 16:50:30 +00005270 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005271 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005272 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005273 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005274}
Mike Stump11289f42009-09-09 15:08:12 +00005275
Douglas Gregord6ff3322009-08-04 16:50:30 +00005276template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005277QualType
5278TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005279 ArrayType::ArraySizeModifier SizeMod,
5280 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005281 unsigned IndexTypeQuals,
5282 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005283 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005284 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005285}
5286
5287template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005288QualType
Mike Stump11289f42009-09-09 15:08:12 +00005289TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005290 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005291 unsigned IndexTypeQuals,
5292 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005293 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005294 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005295}
Mike Stump11289f42009-09-09 15:08:12 +00005296
Douglas Gregord6ff3322009-08-04 16:50:30 +00005297template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005298QualType
5299TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005300 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005301 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005302 unsigned IndexTypeQuals,
5303 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005304 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005305 SizeExpr.takeAs<Expr>(),
5306 IndexTypeQuals, BracketsRange);
5307}
5308
5309template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005310QualType
5311TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005312 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005313 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005314 unsigned IndexTypeQuals,
5315 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005316 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005317 SizeExpr.takeAs<Expr>(),
5318 IndexTypeQuals, BracketsRange);
5319}
5320
5321template<typename Derived>
5322QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
5323 unsigned NumElements) {
5324 // FIXME: semantic checking!
5325 return SemaRef.Context.getVectorType(ElementType, NumElements);
5326}
Mike Stump11289f42009-09-09 15:08:12 +00005327
Douglas Gregord6ff3322009-08-04 16:50:30 +00005328template<typename Derived>
5329QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5330 unsigned NumElements,
5331 SourceLocation AttributeLoc) {
5332 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5333 NumElements, true);
5334 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005335 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005336 AttributeLoc);
5337 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5338 AttributeLoc);
5339}
Mike Stump11289f42009-09-09 15:08:12 +00005340
Douglas Gregord6ff3322009-08-04 16:50:30 +00005341template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005342QualType
5343TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005344 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005345 SourceLocation AttributeLoc) {
5346 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5347}
Mike Stump11289f42009-09-09 15:08:12 +00005348
Douglas Gregord6ff3322009-08-04 16:50:30 +00005349template<typename Derived>
5350QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005351 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005352 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005353 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005354 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005355 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005356 Quals,
5357 getDerived().getBaseLocation(),
5358 getDerived().getBaseEntity());
5359}
Mike Stump11289f42009-09-09 15:08:12 +00005360
Douglas Gregord6ff3322009-08-04 16:50:30 +00005361template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005362QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5363 return SemaRef.Context.getFunctionNoProtoType(T);
5364}
5365
5366template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005367QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5368 assert(D && "no decl found");
5369 if (D->isInvalidDecl()) return QualType();
5370
5371 TypeDecl *Ty;
5372 if (isa<UsingDecl>(D)) {
5373 UsingDecl *Using = cast<UsingDecl>(D);
5374 assert(Using->isTypeName() &&
5375 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5376
5377 // A valid resolved using typename decl points to exactly one type decl.
5378 assert(++Using->shadow_begin() == Using->shadow_end());
5379 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5380
5381 } else {
5382 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5383 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5384 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5385 }
5386
5387 return SemaRef.Context.getTypeDeclType(Ty);
5388}
5389
5390template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005391QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005392 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5393}
5394
5395template<typename Derived>
5396QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5397 return SemaRef.Context.getTypeOfType(Underlying);
5398}
5399
5400template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005401QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005402 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5403}
5404
5405template<typename Derived>
5406QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005407 TemplateName Template,
5408 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005409 const TemplateArgumentListInfo &TemplateArgs) {
5410 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005411}
Mike Stump11289f42009-09-09 15:08:12 +00005412
Douglas Gregor1135c352009-08-06 05:28:30 +00005413template<typename Derived>
5414NestedNameSpecifier *
5415TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5416 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005417 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005418 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005419 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005420 CXXScopeSpec SS;
5421 // FIXME: The source location information is all wrong.
5422 SS.setRange(Range);
5423 SS.setScopeRep(Prefix);
5424 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005425 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005426 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005427 ObjectType,
5428 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005429 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005430}
5431
5432template<typename Derived>
5433NestedNameSpecifier *
5434TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5435 SourceRange Range,
5436 NamespaceDecl *NS) {
5437 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5438}
5439
5440template<typename Derived>
5441NestedNameSpecifier *
5442TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5443 SourceRange Range,
5444 bool TemplateKW,
5445 QualType T) {
5446 if (T->isDependentType() || T->isRecordType() ||
5447 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005448 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005449 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5450 T.getTypePtr());
5451 }
Mike Stump11289f42009-09-09 15:08:12 +00005452
Douglas Gregor1135c352009-08-06 05:28:30 +00005453 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5454 return 0;
5455}
Mike Stump11289f42009-09-09 15:08:12 +00005456
Douglas Gregor71dc5092009-08-06 06:41:21 +00005457template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005458TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005459TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5460 bool TemplateKW,
5461 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005462 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005463 Template);
5464}
5465
5466template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005467TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005468TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005469 const IdentifierInfo &II,
5470 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005471 CXXScopeSpec SS;
5472 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005473 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005474 UnqualifiedId Name;
5475 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005476 return getSema().ActOnDependentTemplateName(
5477 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005478 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005479 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005480 ObjectType.getAsOpaquePtr(),
5481 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005482 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005483}
Mike Stump11289f42009-09-09 15:08:12 +00005484
Douglas Gregora16548e2009-08-11 05:31:07 +00005485template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005486TemplateName
5487TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5488 OverloadedOperatorKind Operator,
5489 QualType ObjectType) {
5490 CXXScopeSpec SS;
5491 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5492 SS.setScopeRep(Qualifier);
5493 UnqualifiedId Name;
5494 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5495 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5496 Operator, SymbolLocations);
5497 return getSema().ActOnDependentTemplateName(
5498 /*FIXME:*/getDerived().getBaseLocation(),
5499 SS,
5500 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005501 ObjectType.getAsOpaquePtr(),
5502 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005503 .template getAsVal<TemplateName>();
5504}
5505
5506template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005507Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005508TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5509 SourceLocation OpLoc,
5510 ExprArg Callee,
5511 ExprArg First,
5512 ExprArg Second) {
5513 Expr *FirstExpr = (Expr *)First.get();
5514 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005515 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005516 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005517
Douglas Gregora16548e2009-08-11 05:31:07 +00005518 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005519 if (Op == OO_Subscript) {
5520 if (!FirstExpr->getType()->isOverloadableType() &&
5521 !SecondExpr->getType()->isOverloadableType())
5522 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005523 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005524 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005525 } else if (Op == OO_Arrow) {
5526 // -> is never a builtin operation.
5527 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005528 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005529 if (!FirstExpr->getType()->isOverloadableType()) {
5530 // The argument is not of overloadable type, so try to create a
5531 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005532 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005533 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005534
Douglas Gregora16548e2009-08-11 05:31:07 +00005535 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5536 }
5537 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005538 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005539 !SecondExpr->getType()->isOverloadableType()) {
5540 // Neither of the arguments is an overloadable type, so try to
5541 // create a built-in binary operation.
5542 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005543 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005544 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5545 if (Result.isInvalid())
5546 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005547
Douglas Gregora16548e2009-08-11 05:31:07 +00005548 First.release();
5549 Second.release();
5550 return move(Result);
5551 }
5552 }
Mike Stump11289f42009-09-09 15:08:12 +00005553
5554 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005555 // used during overload resolution.
5556 Sema::FunctionSet Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005557
John McCalld14a8642009-11-21 08:51:07 +00005558 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5559 assert(ULE->requiresADL());
5560
5561 // FIXME: Do we have to check
5562 // IsAcceptableNonMemberOperatorCandidate for each of these?
5563 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(),
5564 E = ULE->decls_end(); I != E; ++I)
5565 Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I));
5566 } else {
5567 Functions.insert(AnyFunctionDecl::getFromNamedDecl(
5568 cast<DeclRefExpr>(CalleeExpr)->getDecl()));
5569 }
Mike Stump11289f42009-09-09 15:08:12 +00005570
Douglas Gregora16548e2009-08-11 05:31:07 +00005571 // Add any functions found via argument-dependent lookup.
5572 Expr *Args[2] = { FirstExpr, SecondExpr };
5573 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005574 DeclarationName OpName
Douglas Gregora16548e2009-08-11 05:31:07 +00005575 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
Sebastian Redlc057f422009-10-23 19:23:15 +00005576 SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs,
5577 Functions);
Mike Stump11289f42009-09-09 15:08:12 +00005578
Douglas Gregora16548e2009-08-11 05:31:07 +00005579 // Create the overloaded operator invocation for unary operators.
5580 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005581 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005582 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5583 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5584 }
Mike Stump11289f42009-09-09 15:08:12 +00005585
Sebastian Redladba46e2009-10-29 20:17:01 +00005586 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005587 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5588 OpLoc,
5589 move(First),
5590 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005591
Douglas Gregora16548e2009-08-11 05:31:07 +00005592 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005593 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005594 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005595 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005596 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5597 if (Result.isInvalid())
5598 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005599
Douglas Gregora16548e2009-08-11 05:31:07 +00005600 First.release();
5601 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005602 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005603}
Mike Stump11289f42009-09-09 15:08:12 +00005604
Douglas Gregord6ff3322009-08-04 16:50:30 +00005605} // end namespace clang
5606
5607#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H