blob: 5152a2975560ce5529645cd5cb5dc6a7a87f9793 [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.
1361 OwningExprResult RebuildCXXDefaultArgExpr(ParmVarDecl *Param) {
Anders Carlssone8271232009-08-14 18:30:22 +00001362 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001363 }
1364
1365 /// \brief Build a new C++ zero-initialization expression.
1366 ///
1367 /// By default, performs semantic analysis to build the new expression.
1368 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001369 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001370 SourceLocation LParenLoc,
1371 QualType T,
1372 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001373 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1374 T.getAsOpaquePtr(), LParenLoc,
1375 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001376 0, RParenLoc);
1377 }
Mike Stump11289f42009-09-09 15:08:12 +00001378
Douglas Gregora16548e2009-08-11 05:31:07 +00001379 /// \brief Build a new C++ "new" expression.
1380 ///
1381 /// By default, performs semantic analysis to build the new expression.
1382 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001383 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001384 bool UseGlobal,
1385 SourceLocation PlacementLParen,
1386 MultiExprArg PlacementArgs,
1387 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001388 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001389 QualType AllocType,
1390 SourceLocation TypeLoc,
1391 SourceRange TypeRange,
1392 ExprArg ArraySize,
1393 SourceLocation ConstructorLParen,
1394 MultiExprArg ConstructorArgs,
1395 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001396 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001397 PlacementLParen,
1398 move(PlacementArgs),
1399 PlacementRParen,
1400 ParenTypeId,
1401 AllocType,
1402 TypeLoc,
1403 TypeRange,
1404 move(ArraySize),
1405 ConstructorLParen,
1406 move(ConstructorArgs),
1407 ConstructorRParen);
1408 }
Mike Stump11289f42009-09-09 15:08:12 +00001409
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 /// \brief Build a new C++ "delete" expression.
1411 ///
1412 /// By default, performs semantic analysis to build the new expression.
1413 /// Subclasses may override this routine to provide different behavior.
1414 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1415 bool IsGlobalDelete,
1416 bool IsArrayForm,
1417 ExprArg Operand) {
1418 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1419 move(Operand));
1420 }
Mike Stump11289f42009-09-09 15:08:12 +00001421
Douglas Gregora16548e2009-08-11 05:31:07 +00001422 /// \brief Build a new unary type trait expression.
1423 ///
1424 /// By default, performs semantic analysis to build the new expression.
1425 /// Subclasses may override this routine to provide different behavior.
1426 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1427 SourceLocation StartLoc,
1428 SourceLocation LParenLoc,
1429 QualType T,
1430 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001431 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001432 T.getAsOpaquePtr(), RParenLoc);
1433 }
1434
Mike Stump11289f42009-09-09 15:08:12 +00001435 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 /// expression.
1437 ///
1438 /// By default, performs semantic analysis to build the new expression.
1439 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001440 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001441 SourceRange QualifierRange,
1442 DeclarationName Name,
1443 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001444 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001445 CXXScopeSpec SS;
1446 SS.setRange(QualifierRange);
1447 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001448
1449 if (TemplateArgs)
1450 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1451 *TemplateArgs);
1452
1453 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001454 }
1455
1456 /// \brief Build a new template-id expression.
1457 ///
1458 /// By default, performs semantic analysis to build the new expression.
1459 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001460 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1461 LookupResult &R,
1462 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001463 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001464 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001465 }
1466
1467 /// \brief Build a new object-construction expression.
1468 ///
1469 /// By default, performs semantic analysis to build the new expression.
1470 /// Subclasses may override this routine to provide different behavior.
1471 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001472 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001473 CXXConstructorDecl *Constructor,
1474 bool IsElidable,
1475 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001476 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1477 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1478 ConvertedArgs))
1479 return getSema().ExprError();
1480
1481 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1482 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001483 }
1484
1485 /// \brief Build a new object-construction expression.
1486 ///
1487 /// By default, performs semantic analysis to build the new expression.
1488 /// Subclasses may override this routine to provide different behavior.
1489 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1490 QualType T,
1491 SourceLocation LParenLoc,
1492 MultiExprArg Args,
1493 SourceLocation *Commas,
1494 SourceLocation RParenLoc) {
1495 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1496 T.getAsOpaquePtr(),
1497 LParenLoc,
1498 move(Args),
1499 Commas,
1500 RParenLoc);
1501 }
1502
1503 /// \brief Build a new object-construction expression.
1504 ///
1505 /// By default, performs semantic analysis to build the new expression.
1506 /// Subclasses may override this routine to provide different behavior.
1507 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1508 QualType T,
1509 SourceLocation LParenLoc,
1510 MultiExprArg Args,
1511 SourceLocation *Commas,
1512 SourceLocation RParenLoc) {
1513 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1514 /*FIXME*/LParenLoc),
1515 T.getAsOpaquePtr(),
1516 LParenLoc,
1517 move(Args),
1518 Commas,
1519 RParenLoc);
1520 }
Mike Stump11289f42009-09-09 15:08:12 +00001521
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 /// \brief Build a new member reference expression.
1523 ///
1524 /// By default, performs semantic analysis to build the new expression.
1525 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001526 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001527 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 bool IsArrow,
1529 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001530 NestedNameSpecifier *Qualifier,
1531 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001532 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001533 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001534 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001535 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001537 SS.setRange(QualifierRange);
1538 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001539
John McCall2d74de92009-12-01 22:10:20 +00001540 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1541 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001542 SS, FirstQualifierInScope,
1543 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001544 }
1545
John McCall10eae182009-11-30 22:42:35 +00001546 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001547 ///
1548 /// By default, performs semantic analysis to build the new expression.
1549 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001550 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001551 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001552 SourceLocation OperatorLoc,
1553 bool IsArrow,
1554 NestedNameSpecifier *Qualifier,
1555 SourceRange QualifierRange,
1556 LookupResult &R,
1557 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001558 CXXScopeSpec SS;
1559 SS.setRange(QualifierRange);
1560 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001561
John McCall2d74de92009-12-01 22:10:20 +00001562 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1563 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001564 SS, R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001565 }
Mike Stump11289f42009-09-09 15:08:12 +00001566
Douglas Gregora16548e2009-08-11 05:31:07 +00001567 /// \brief Build a new Objective-C @encode expression.
1568 ///
1569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
1571 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1572 QualType T,
1573 SourceLocation RParenLoc) {
1574 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1575 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001576 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001577
1578 /// \brief Build a new Objective-C protocol expression.
1579 ///
1580 /// By default, performs semantic analysis to build the new expression.
1581 /// Subclasses may override this routine to provide different behavior.
1582 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1583 SourceLocation AtLoc,
1584 SourceLocation ProtoLoc,
1585 SourceLocation LParenLoc,
1586 SourceLocation RParenLoc) {
1587 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1588 Protocol->getIdentifier(),
1589 AtLoc,
1590 ProtoLoc,
1591 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001592 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 }
Mike Stump11289f42009-09-09 15:08:12 +00001594
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 /// \brief Build a new shuffle vector expression.
1596 ///
1597 /// By default, performs semantic analysis to build the new expression.
1598 /// Subclasses may override this routine to provide different behavior.
1599 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1600 MultiExprArg SubExprs,
1601 SourceLocation RParenLoc) {
1602 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001603 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001604 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1605 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1606 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1607 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001608
Douglas Gregora16548e2009-08-11 05:31:07 +00001609 // Build a reference to the __builtin_shufflevector builtin
1610 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001611 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001613 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001615
1616 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 unsigned NumSubExprs = SubExprs.size();
1618 Expr **Subs = (Expr **)SubExprs.release();
1619 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1620 Subs, NumSubExprs,
1621 Builtin->getResultType(),
1622 RParenLoc);
1623 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001624
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 // Type-check the __builtin_shufflevector expression.
1626 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1627 if (Result.isInvalid())
1628 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001629
Douglas Gregora16548e2009-08-11 05:31:07 +00001630 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001631 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001633};
Douglas Gregora16548e2009-08-11 05:31:07 +00001634
Douglas Gregorebe10102009-08-20 07:17:43 +00001635template<typename Derived>
1636Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1637 if (!S)
1638 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001639
Douglas Gregorebe10102009-08-20 07:17:43 +00001640 switch (S->getStmtClass()) {
1641 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001642
Douglas Gregorebe10102009-08-20 07:17:43 +00001643 // Transform individual statement nodes
1644#define STMT(Node, Parent) \
1645 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1646#define EXPR(Node, Parent)
1647#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001648
Douglas Gregorebe10102009-08-20 07:17:43 +00001649 // Transform expressions by calling TransformExpr.
1650#define STMT(Node, Parent)
1651#define EXPR(Node, Parent) case Stmt::Node##Class:
1652#include "clang/AST/StmtNodes.def"
1653 {
1654 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1655 if (E.isInvalid())
1656 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001657
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001658 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001659 }
Mike Stump11289f42009-09-09 15:08:12 +00001660 }
1661
Douglas Gregorebe10102009-08-20 07:17:43 +00001662 return SemaRef.Owned(S->Retain());
1663}
Mike Stump11289f42009-09-09 15:08:12 +00001664
1665
Douglas Gregore922c772009-08-04 22:27:00 +00001666template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001667Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001668 if (!E)
1669 return SemaRef.Owned(E);
1670
1671 switch (E->getStmtClass()) {
1672 case Stmt::NoStmtClass: break;
1673#define STMT(Node, Parent) case Stmt::Node##Class: break;
1674#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001675 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001676#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001677 }
1678
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001680}
1681
1682template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001683NestedNameSpecifier *
1684TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001685 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001686 QualType ObjectType,
1687 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001688 if (!NNS)
1689 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001690
Douglas Gregorebe10102009-08-20 07:17:43 +00001691 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001692 NestedNameSpecifier *Prefix = NNS->getPrefix();
1693 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001694 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001695 ObjectType,
1696 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001697 if (!Prefix)
1698 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001699
1700 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001701 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001702 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001703 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001704 }
Mike Stump11289f42009-09-09 15:08:12 +00001705
Douglas Gregor1135c352009-08-06 05:28:30 +00001706 switch (NNS->getKind()) {
1707 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001708 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001709 "Identifier nested-name-specifier with no prefix or object type");
1710 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1711 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001712 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001713
1714 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001715 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001716 ObjectType,
1717 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001718
Douglas Gregor1135c352009-08-06 05:28:30 +00001719 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001720 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001721 = cast_or_null<NamespaceDecl>(
1722 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001723 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001724 Prefix == NNS->getPrefix() &&
1725 NS == NNS->getAsNamespace())
1726 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001727
Douglas Gregor1135c352009-08-06 05:28:30 +00001728 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1729 }
Mike Stump11289f42009-09-09 15:08:12 +00001730
Douglas Gregor1135c352009-08-06 05:28:30 +00001731 case NestedNameSpecifier::Global:
1732 // There is no meaningful transformation that one could perform on the
1733 // global scope.
1734 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001735
Douglas Gregor1135c352009-08-06 05:28:30 +00001736 case NestedNameSpecifier::TypeSpecWithTemplate:
1737 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001738 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor1135c352009-08-06 05:28:30 +00001739 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001740 if (T.isNull())
1741 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001742
Douglas Gregor1135c352009-08-06 05:28:30 +00001743 if (!getDerived().AlwaysRebuild() &&
1744 Prefix == NNS->getPrefix() &&
1745 T == QualType(NNS->getAsType(), 0))
1746 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001747
1748 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1749 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregor1135c352009-08-06 05:28:30 +00001750 T);
1751 }
1752 }
Mike Stump11289f42009-09-09 15:08:12 +00001753
Douglas Gregor1135c352009-08-06 05:28:30 +00001754 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001755 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001756}
1757
1758template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001759DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001760TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001761 SourceLocation Loc,
1762 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001763 if (!Name)
1764 return Name;
1765
1766 switch (Name.getNameKind()) {
1767 case DeclarationName::Identifier:
1768 case DeclarationName::ObjCZeroArgSelector:
1769 case DeclarationName::ObjCOneArgSelector:
1770 case DeclarationName::ObjCMultiArgSelector:
1771 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001772 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001773 case DeclarationName::CXXUsingDirective:
1774 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001775
Douglas Gregorf816bd72009-09-03 22:13:48 +00001776 case DeclarationName::CXXConstructorName:
1777 case DeclarationName::CXXDestructorName:
1778 case DeclarationName::CXXConversionFunctionName: {
1779 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorc59e5612009-10-19 22:04:39 +00001780 QualType T;
1781 if (!ObjectType.isNull() &&
1782 isa<TemplateSpecializationType>(Name.getCXXNameType())) {
1783 TemplateSpecializationType *SpecType
1784 = cast<TemplateSpecializationType>(Name.getCXXNameType());
1785 T = TransformTemplateSpecializationType(SpecType, ObjectType);
1786 } else
1787 T = getDerived().TransformType(Name.getCXXNameType());
Douglas Gregorf816bd72009-09-03 22:13:48 +00001788 if (T.isNull())
1789 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001790
Douglas Gregorf816bd72009-09-03 22:13:48 +00001791 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001792 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001793 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001794 }
Mike Stump11289f42009-09-09 15:08:12 +00001795 }
1796
Douglas Gregorf816bd72009-09-03 22:13:48 +00001797 return DeclarationName();
1798}
1799
1800template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001801TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001802TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1803 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00001804 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001805 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001806 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1807 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1808 if (!NNS)
1809 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001810
Douglas Gregor71dc5092009-08-06 06:41:21 +00001811 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001812 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001813 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1814 if (!TransTemplate)
1815 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001816
Douglas Gregor71dc5092009-08-06 06:41:21 +00001817 if (!getDerived().AlwaysRebuild() &&
1818 NNS == QTN->getQualifier() &&
1819 TransTemplate == Template)
1820 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001821
Douglas Gregor71dc5092009-08-06 06:41:21 +00001822 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1823 TransTemplate);
1824 }
Mike Stump11289f42009-09-09 15:08:12 +00001825
John McCalle66edc12009-11-24 19:00:30 +00001826 // These should be getting filtered out before they make it into the AST.
1827 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001828 }
Mike Stump11289f42009-09-09 15:08:12 +00001829
Douglas Gregor71dc5092009-08-06 06:41:21 +00001830 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001831 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001832 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1833 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor308047d2009-09-09 00:23:06 +00001834 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001835 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001836
Douglas Gregor71dc5092009-08-06 06:41:21 +00001837 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001838 NNS == DTN->getQualifier() &&
1839 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001840 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001841
Douglas Gregor71395fa2009-11-04 00:56:37 +00001842 if (DTN->isIdentifier())
1843 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1844 ObjectType);
1845
1846 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1847 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001848 }
Mike Stump11289f42009-09-09 15:08:12 +00001849
Douglas Gregor71dc5092009-08-06 06:41:21 +00001850 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001851 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001852 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1853 if (!TransTemplate)
1854 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001855
Douglas Gregor71dc5092009-08-06 06:41:21 +00001856 if (!getDerived().AlwaysRebuild() &&
1857 TransTemplate == Template)
1858 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001859
Douglas Gregor71dc5092009-08-06 06:41:21 +00001860 return TemplateName(TransTemplate);
1861 }
Mike Stump11289f42009-09-09 15:08:12 +00001862
John McCalle66edc12009-11-24 19:00:30 +00001863 // These should be getting filtered out before they reach the AST.
1864 assert(false && "overloaded function decl survived to here");
1865 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00001866}
1867
1868template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001869void TreeTransform<Derived>::InventTemplateArgumentLoc(
1870 const TemplateArgument &Arg,
1871 TemplateArgumentLoc &Output) {
1872 SourceLocation Loc = getDerived().getBaseLocation();
1873 switch (Arg.getKind()) {
1874 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00001875 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00001876 break;
1877
1878 case TemplateArgument::Type:
1879 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00001880 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00001881
1882 break;
1883
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001884 case TemplateArgument::Template:
1885 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1886 break;
1887
John McCall0ad16662009-10-29 08:12:44 +00001888 case TemplateArgument::Expression:
1889 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1890 break;
1891
1892 case TemplateArgument::Declaration:
1893 case TemplateArgument::Integral:
1894 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00001895 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00001896 break;
1897 }
1898}
1899
1900template<typename Derived>
1901bool TreeTransform<Derived>::TransformTemplateArgument(
1902 const TemplateArgumentLoc &Input,
1903 TemplateArgumentLoc &Output) {
1904 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00001905 switch (Arg.getKind()) {
1906 case TemplateArgument::Null:
1907 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001908 Output = Input;
1909 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001910
Douglas Gregore922c772009-08-04 22:27:00 +00001911 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00001912 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00001913 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00001914 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00001915
1916 DI = getDerived().TransformType(DI);
1917 if (!DI) return true;
1918
1919 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1920 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001921 }
Mike Stump11289f42009-09-09 15:08:12 +00001922
Douglas Gregore922c772009-08-04 22:27:00 +00001923 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001924 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001925 DeclarationName Name;
1926 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1927 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001928 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregore922c772009-08-04 22:27:00 +00001929 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001930 if (!D) return true;
1931
John McCall0d07eb32009-10-29 18:45:58 +00001932 Expr *SourceExpr = Input.getSourceDeclExpression();
1933 if (SourceExpr) {
1934 EnterExpressionEvaluationContext Unevaluated(getSema(),
1935 Action::Unevaluated);
1936 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1937 if (E.isInvalid())
1938 SourceExpr = NULL;
1939 else {
1940 SourceExpr = E.takeAs<Expr>();
1941 SourceExpr->Retain();
1942 }
1943 }
1944
1945 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00001946 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001947 }
Mike Stump11289f42009-09-09 15:08:12 +00001948
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001949 case TemplateArgument::Template: {
1950 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1951 TemplateName Template
1952 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1953 if (Template.isNull())
1954 return true;
1955
1956 Output = TemplateArgumentLoc(TemplateArgument(Template),
1957 Input.getTemplateQualifierRange(),
1958 Input.getTemplateNameLoc());
1959 return false;
1960 }
1961
Douglas Gregore922c772009-08-04 22:27:00 +00001962 case TemplateArgument::Expression: {
1963 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00001964 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00001965 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00001966
John McCall0ad16662009-10-29 08:12:44 +00001967 Expr *InputExpr = Input.getSourceExpression();
1968 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
1969
1970 Sema::OwningExprResult E
1971 = getDerived().TransformExpr(InputExpr);
1972 if (E.isInvalid()) return true;
1973
1974 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00001975 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00001976 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
1977 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001978 }
Mike Stump11289f42009-09-09 15:08:12 +00001979
Douglas Gregore922c772009-08-04 22:27:00 +00001980 case TemplateArgument::Pack: {
1981 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
1982 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00001983 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00001984 AEnd = Arg.pack_end();
1985 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00001986
John McCall0ad16662009-10-29 08:12:44 +00001987 // FIXME: preserve source information here when we start
1988 // caring about parameter packs.
1989
John McCall0d07eb32009-10-29 18:45:58 +00001990 TemplateArgumentLoc InputArg;
1991 TemplateArgumentLoc OutputArg;
1992 getDerived().InventTemplateArgumentLoc(*A, InputArg);
1993 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00001994 return true;
1995
John McCall0d07eb32009-10-29 18:45:58 +00001996 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00001997 }
1998 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00001999 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002000 true);
John McCall0d07eb32009-10-29 18:45:58 +00002001 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002002 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002003 }
2004 }
Mike Stump11289f42009-09-09 15:08:12 +00002005
Douglas Gregore922c772009-08-04 22:27:00 +00002006 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002007 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002008}
2009
Douglas Gregord6ff3322009-08-04 16:50:30 +00002010//===----------------------------------------------------------------------===//
2011// Type transformation
2012//===----------------------------------------------------------------------===//
2013
2014template<typename Derived>
2015QualType TreeTransform<Derived>::TransformType(QualType T) {
2016 if (getDerived().AlreadyTransformed(T))
2017 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002018
John McCall550e0c22009-10-21 00:40:46 +00002019 // Temporary workaround. All of these transformations should
2020 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002021 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002022 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002023
John McCallbcd03502009-12-07 02:54:59 +00002024 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002025
John McCall550e0c22009-10-21 00:40:46 +00002026 if (!NewDI)
2027 return QualType();
2028
2029 return NewDI->getType();
2030}
2031
2032template<typename Derived>
John McCallbcd03502009-12-07 02:54:59 +00002033TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002034 if (getDerived().AlreadyTransformed(DI->getType()))
2035 return DI;
2036
2037 TypeLocBuilder TLB;
2038
2039 TypeLoc TL = DI->getTypeLoc();
2040 TLB.reserve(TL.getFullDataSize());
2041
2042 QualType Result = getDerived().TransformType(TLB, TL);
2043 if (Result.isNull())
2044 return 0;
2045
John McCallbcd03502009-12-07 02:54:59 +00002046 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002047}
2048
2049template<typename Derived>
2050QualType
2051TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
2052 switch (T.getTypeLocClass()) {
2053#define ABSTRACT_TYPELOC(CLASS, PARENT)
2054#define TYPELOC(CLASS, PARENT) \
2055 case TypeLoc::CLASS: \
2056 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2057#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002058 }
Mike Stump11289f42009-09-09 15:08:12 +00002059
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002060 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002061 return QualType();
2062}
2063
2064/// FIXME: By default, this routine adds type qualifiers only to types
2065/// that can have qualifiers, and silently suppresses those qualifiers
2066/// that are not permitted (e.g., qualifiers on reference or function
2067/// types). This is the right thing for template instantiation, but
2068/// probably not for other clients.
2069template<typename Derived>
2070QualType
2071TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
2072 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002073 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002074
2075 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2076 if (Result.isNull())
2077 return QualType();
2078
2079 // Silently suppress qualifiers if the result type can't be qualified.
2080 // FIXME: this is the right thing for template instantiation, but
2081 // probably not for other clients.
2082 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002083 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002084
John McCall550e0c22009-10-21 00:40:46 +00002085 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2086
2087 TLB.push<QualifiedTypeLoc>(Result);
2088
2089 // No location information to preserve.
2090
2091 return Result;
2092}
2093
2094template <class TyLoc> static inline
2095QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2096 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2097 NewT.setNameLoc(T.getNameLoc());
2098 return T.getType();
2099}
2100
2101// Ugly metaprogramming macros because I couldn't be bothered to make
2102// the equivalent template version work.
2103#define TransformPointerLikeType(TypeClass) do { \
2104 QualType PointeeType \
2105 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2106 if (PointeeType.isNull()) \
2107 return QualType(); \
2108 \
2109 QualType Result = TL.getType(); \
2110 if (getDerived().AlwaysRebuild() || \
2111 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall70dd5f62009-10-30 00:06:24 +00002112 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2113 TL.getSigilLoc()); \
John McCall550e0c22009-10-21 00:40:46 +00002114 if (Result.isNull()) \
2115 return QualType(); \
2116 } \
2117 \
2118 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2119 NewT.setSigilLoc(TL.getSigilLoc()); \
2120 \
2121 return Result; \
2122} while(0)
2123
John McCall550e0c22009-10-21 00:40:46 +00002124template<typename Derived>
2125QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
2126 BuiltinTypeLoc T) {
2127 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002128}
Mike Stump11289f42009-09-09 15:08:12 +00002129
Douglas Gregord6ff3322009-08-04 16:50:30 +00002130template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002131QualType
John McCall550e0c22009-10-21 00:40:46 +00002132TreeTransform<Derived>::TransformFixedWidthIntType(TypeLocBuilder &TLB,
2133 FixedWidthIntTypeLoc T) {
2134 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002135}
Argyrios Kyrtzidise9189262009-08-19 01:28:17 +00002136
Douglas Gregord6ff3322009-08-04 16:50:30 +00002137template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002138QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
2139 ComplexTypeLoc T) {
2140 // FIXME: recurse?
2141 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002142}
Mike Stump11289f42009-09-09 15:08:12 +00002143
Douglas Gregord6ff3322009-08-04 16:50:30 +00002144template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002145QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
2146 PointerTypeLoc TL) {
2147 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002148}
Mike Stump11289f42009-09-09 15:08:12 +00002149
2150template<typename Derived>
2151QualType
John McCall550e0c22009-10-21 00:40:46 +00002152TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
2153 BlockPointerTypeLoc TL) {
2154 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002155}
2156
John McCall70dd5f62009-10-30 00:06:24 +00002157/// Transforms a reference type. Note that somewhat paradoxically we
2158/// don't care whether the type itself is an l-value type or an r-value
2159/// type; we only care if the type was *written* as an l-value type
2160/// or an r-value type.
2161template<typename Derived>
2162QualType
2163TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
2164 ReferenceTypeLoc TL) {
2165 const ReferenceType *T = TL.getTypePtr();
2166
2167 // Note that this works with the pointee-as-written.
2168 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2169 if (PointeeType.isNull())
2170 return QualType();
2171
2172 QualType Result = TL.getType();
2173 if (getDerived().AlwaysRebuild() ||
2174 PointeeType != T->getPointeeTypeAsWritten()) {
2175 Result = getDerived().RebuildReferenceType(PointeeType,
2176 T->isSpelledAsLValue(),
2177 TL.getSigilLoc());
2178 if (Result.isNull())
2179 return QualType();
2180 }
2181
2182 // r-value references can be rebuilt as l-value references.
2183 ReferenceTypeLoc NewTL;
2184 if (isa<LValueReferenceType>(Result))
2185 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2186 else
2187 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2188 NewTL.setSigilLoc(TL.getSigilLoc());
2189
2190 return Result;
2191}
2192
Mike Stump11289f42009-09-09 15:08:12 +00002193template<typename Derived>
2194QualType
John McCall550e0c22009-10-21 00:40:46 +00002195TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
2196 LValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002197 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002198}
2199
Mike Stump11289f42009-09-09 15:08:12 +00002200template<typename Derived>
2201QualType
John McCall550e0c22009-10-21 00:40:46 +00002202TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
2203 RValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002204 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002205}
Mike Stump11289f42009-09-09 15:08:12 +00002206
Douglas Gregord6ff3322009-08-04 16:50:30 +00002207template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002208QualType
John McCall550e0c22009-10-21 00:40:46 +00002209TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
2210 MemberPointerTypeLoc TL) {
2211 MemberPointerType *T = TL.getTypePtr();
2212
2213 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002214 if (PointeeType.isNull())
2215 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002216
John McCall550e0c22009-10-21 00:40:46 +00002217 // TODO: preserve source information for this.
2218 QualType ClassType
2219 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002220 if (ClassType.isNull())
2221 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002222
John McCall550e0c22009-10-21 00:40:46 +00002223 QualType Result = TL.getType();
2224 if (getDerived().AlwaysRebuild() ||
2225 PointeeType != T->getPointeeType() ||
2226 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002227 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2228 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002229 if (Result.isNull())
2230 return QualType();
2231 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002232
John McCall550e0c22009-10-21 00:40:46 +00002233 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2234 NewTL.setSigilLoc(TL.getSigilLoc());
2235
2236 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002237}
2238
Mike Stump11289f42009-09-09 15:08:12 +00002239template<typename Derived>
2240QualType
John McCall550e0c22009-10-21 00:40:46 +00002241TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
2242 ConstantArrayTypeLoc TL) {
2243 ConstantArrayType *T = TL.getTypePtr();
2244 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002245 if (ElementType.isNull())
2246 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002247
John McCall550e0c22009-10-21 00:40:46 +00002248 QualType Result = TL.getType();
2249 if (getDerived().AlwaysRebuild() ||
2250 ElementType != T->getElementType()) {
2251 Result = getDerived().RebuildConstantArrayType(ElementType,
2252 T->getSizeModifier(),
2253 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002254 T->getIndexTypeCVRQualifiers(),
2255 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002256 if (Result.isNull())
2257 return QualType();
2258 }
2259
2260 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2261 NewTL.setLBracketLoc(TL.getLBracketLoc());
2262 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002263
John McCall550e0c22009-10-21 00:40:46 +00002264 Expr *Size = TL.getSizeExpr();
2265 if (Size) {
2266 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2267 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2268 }
2269 NewTL.setSizeExpr(Size);
2270
2271 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002272}
Mike Stump11289f42009-09-09 15:08:12 +00002273
Douglas Gregord6ff3322009-08-04 16:50:30 +00002274template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002275QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002276 TypeLocBuilder &TLB,
2277 IncompleteArrayTypeLoc TL) {
2278 IncompleteArrayType *T = TL.getTypePtr();
2279 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002280 if (ElementType.isNull())
2281 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002282
John McCall550e0c22009-10-21 00:40:46 +00002283 QualType Result = TL.getType();
2284 if (getDerived().AlwaysRebuild() ||
2285 ElementType != T->getElementType()) {
2286 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002287 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002288 T->getIndexTypeCVRQualifiers(),
2289 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002290 if (Result.isNull())
2291 return QualType();
2292 }
2293
2294 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2295 NewTL.setLBracketLoc(TL.getLBracketLoc());
2296 NewTL.setRBracketLoc(TL.getRBracketLoc());
2297 NewTL.setSizeExpr(0);
2298
2299 return Result;
2300}
2301
2302template<typename Derived>
2303QualType
2304TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
2305 VariableArrayTypeLoc TL) {
2306 VariableArrayType *T = TL.getTypePtr();
2307 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2308 if (ElementType.isNull())
2309 return QualType();
2310
2311 // Array bounds are not potentially evaluated contexts
2312 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2313
2314 Sema::OwningExprResult SizeResult
2315 = getDerived().TransformExpr(T->getSizeExpr());
2316 if (SizeResult.isInvalid())
2317 return QualType();
2318
2319 Expr *Size = static_cast<Expr*>(SizeResult.get());
2320
2321 QualType Result = TL.getType();
2322 if (getDerived().AlwaysRebuild() ||
2323 ElementType != T->getElementType() ||
2324 Size != T->getSizeExpr()) {
2325 Result = getDerived().RebuildVariableArrayType(ElementType,
2326 T->getSizeModifier(),
2327 move(SizeResult),
2328 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002329 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002330 if (Result.isNull())
2331 return QualType();
2332 }
2333 else SizeResult.take();
2334
2335 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2336 NewTL.setLBracketLoc(TL.getLBracketLoc());
2337 NewTL.setRBracketLoc(TL.getRBracketLoc());
2338 NewTL.setSizeExpr(Size);
2339
2340 return Result;
2341}
2342
2343template<typename Derived>
2344QualType
2345TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
2346 DependentSizedArrayTypeLoc TL) {
2347 DependentSizedArrayType *T = TL.getTypePtr();
2348 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2349 if (ElementType.isNull())
2350 return QualType();
2351
2352 // Array bounds are not potentially evaluated contexts
2353 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2354
2355 Sema::OwningExprResult SizeResult
2356 = getDerived().TransformExpr(T->getSizeExpr());
2357 if (SizeResult.isInvalid())
2358 return QualType();
2359
2360 Expr *Size = static_cast<Expr*>(SizeResult.get());
2361
2362 QualType Result = TL.getType();
2363 if (getDerived().AlwaysRebuild() ||
2364 ElementType != T->getElementType() ||
2365 Size != T->getSizeExpr()) {
2366 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2367 T->getSizeModifier(),
2368 move(SizeResult),
2369 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002370 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002371 if (Result.isNull())
2372 return QualType();
2373 }
2374 else SizeResult.take();
2375
2376 // We might have any sort of array type now, but fortunately they
2377 // all have the same location layout.
2378 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2379 NewTL.setLBracketLoc(TL.getLBracketLoc());
2380 NewTL.setRBracketLoc(TL.getRBracketLoc());
2381 NewTL.setSizeExpr(Size);
2382
2383 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002384}
Mike Stump11289f42009-09-09 15:08:12 +00002385
2386template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002387QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002388 TypeLocBuilder &TLB,
2389 DependentSizedExtVectorTypeLoc TL) {
2390 DependentSizedExtVectorType *T = TL.getTypePtr();
2391
2392 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002393 QualType ElementType = getDerived().TransformType(T->getElementType());
2394 if (ElementType.isNull())
2395 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002396
Douglas Gregore922c772009-08-04 22:27:00 +00002397 // Vector sizes are not potentially evaluated contexts
2398 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2399
Douglas Gregord6ff3322009-08-04 16:50:30 +00002400 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2401 if (Size.isInvalid())
2402 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002403
John McCall550e0c22009-10-21 00:40:46 +00002404 QualType Result = TL.getType();
2405 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002406 ElementType != T->getElementType() ||
2407 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002408 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002409 move(Size),
2410 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002411 if (Result.isNull())
2412 return QualType();
2413 }
2414 else Size.take();
2415
2416 // Result might be dependent or not.
2417 if (isa<DependentSizedExtVectorType>(Result)) {
2418 DependentSizedExtVectorTypeLoc NewTL
2419 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2420 NewTL.setNameLoc(TL.getNameLoc());
2421 } else {
2422 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2423 NewTL.setNameLoc(TL.getNameLoc());
2424 }
2425
2426 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002427}
Mike Stump11289f42009-09-09 15:08:12 +00002428
2429template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002430QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
2431 VectorTypeLoc TL) {
2432 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002433 QualType ElementType = getDerived().TransformType(T->getElementType());
2434 if (ElementType.isNull())
2435 return QualType();
2436
John McCall550e0c22009-10-21 00:40:46 +00002437 QualType Result = TL.getType();
2438 if (getDerived().AlwaysRebuild() ||
2439 ElementType != T->getElementType()) {
2440 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements());
2441 if (Result.isNull())
2442 return QualType();
2443 }
2444
2445 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2446 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002447
John McCall550e0c22009-10-21 00:40:46 +00002448 return Result;
2449}
2450
2451template<typename Derived>
2452QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
2453 ExtVectorTypeLoc TL) {
2454 VectorType *T = TL.getTypePtr();
2455 QualType ElementType = getDerived().TransformType(T->getElementType());
2456 if (ElementType.isNull())
2457 return QualType();
2458
2459 QualType Result = TL.getType();
2460 if (getDerived().AlwaysRebuild() ||
2461 ElementType != T->getElementType()) {
2462 Result = getDerived().RebuildExtVectorType(ElementType,
2463 T->getNumElements(),
2464 /*FIXME*/ SourceLocation());
2465 if (Result.isNull())
2466 return QualType();
2467 }
2468
2469 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2470 NewTL.setNameLoc(TL.getNameLoc());
2471
2472 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002473}
Mike Stump11289f42009-09-09 15:08:12 +00002474
2475template<typename Derived>
2476QualType
John McCall550e0c22009-10-21 00:40:46 +00002477TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
2478 FunctionProtoTypeLoc TL) {
2479 FunctionProtoType *T = TL.getTypePtr();
2480 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002481 if (ResultType.isNull())
2482 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002483
John McCall550e0c22009-10-21 00:40:46 +00002484 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002485 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002486 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2487 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2488 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump11289f42009-09-09 15:08:12 +00002489
John McCall550e0c22009-10-21 00:40:46 +00002490 QualType NewType;
2491 ParmVarDecl *NewParm;
2492
2493 if (OldParm) {
John McCallbcd03502009-12-07 02:54:59 +00002494 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCall550e0c22009-10-21 00:40:46 +00002495 assert(OldDI->getType() == T->getArgType(i));
2496
John McCallbcd03502009-12-07 02:54:59 +00002497 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCall550e0c22009-10-21 00:40:46 +00002498 if (!NewDI)
2499 return QualType();
2500
2501 if (NewDI == OldDI)
2502 NewParm = OldParm;
2503 else
2504 NewParm = ParmVarDecl::Create(SemaRef.Context,
2505 OldParm->getDeclContext(),
2506 OldParm->getLocation(),
2507 OldParm->getIdentifier(),
2508 NewDI->getType(),
2509 NewDI,
2510 OldParm->getStorageClass(),
2511 /* DefArg */ NULL);
2512 NewType = NewParm->getType();
2513
2514 // Deal with the possibility that we don't have a parameter
2515 // declaration for this parameter.
2516 } else {
2517 NewParm = 0;
2518
2519 QualType OldType = T->getArgType(i);
2520 NewType = getDerived().TransformType(OldType);
2521 if (NewType.isNull())
2522 return QualType();
2523 }
2524
2525 ParamTypes.push_back(NewType);
2526 ParamDecls.push_back(NewParm);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002527 }
Mike Stump11289f42009-09-09 15:08:12 +00002528
John McCall550e0c22009-10-21 00:40:46 +00002529 QualType Result = TL.getType();
2530 if (getDerived().AlwaysRebuild() ||
2531 ResultType != T->getResultType() ||
2532 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2533 Result = getDerived().RebuildFunctionProtoType(ResultType,
2534 ParamTypes.data(),
2535 ParamTypes.size(),
2536 T->isVariadic(),
2537 T->getTypeQuals());
2538 if (Result.isNull())
2539 return QualType();
2540 }
Mike Stump11289f42009-09-09 15:08:12 +00002541
John McCall550e0c22009-10-21 00:40:46 +00002542 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2543 NewTL.setLParenLoc(TL.getLParenLoc());
2544 NewTL.setRParenLoc(TL.getRParenLoc());
2545 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2546 NewTL.setArg(i, ParamDecls[i]);
2547
2548 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002549}
Mike Stump11289f42009-09-09 15:08:12 +00002550
Douglas Gregord6ff3322009-08-04 16:50:30 +00002551template<typename Derived>
2552QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002553 TypeLocBuilder &TLB,
2554 FunctionNoProtoTypeLoc TL) {
2555 FunctionNoProtoType *T = TL.getTypePtr();
2556 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2557 if (ResultType.isNull())
2558 return QualType();
2559
2560 QualType Result = TL.getType();
2561 if (getDerived().AlwaysRebuild() ||
2562 ResultType != T->getResultType())
2563 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2564
2565 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2566 NewTL.setLParenLoc(TL.getLParenLoc());
2567 NewTL.setRParenLoc(TL.getRParenLoc());
2568
2569 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002570}
Mike Stump11289f42009-09-09 15:08:12 +00002571
John McCallb96ec562009-12-04 22:46:56 +00002572template<typename Derived> QualType
2573TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
2574 UnresolvedUsingTypeLoc TL) {
2575 UnresolvedUsingType *T = TL.getTypePtr();
2576 Decl *D = getDerived().TransformDecl(T->getDecl());
2577 if (!D)
2578 return QualType();
2579
2580 QualType Result = TL.getType();
2581 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2582 Result = getDerived().RebuildUnresolvedUsingType(D);
2583 if (Result.isNull())
2584 return QualType();
2585 }
2586
2587 // We might get an arbitrary type spec type back. We should at
2588 // least always get a type spec type, though.
2589 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2590 NewTL.setNameLoc(TL.getNameLoc());
2591
2592 return Result;
2593}
2594
Douglas Gregord6ff3322009-08-04 16:50:30 +00002595template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002596QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
2597 TypedefTypeLoc TL) {
2598 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002599 TypedefDecl *Typedef
2600 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2601 if (!Typedef)
2602 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002603
John McCall550e0c22009-10-21 00:40:46 +00002604 QualType Result = TL.getType();
2605 if (getDerived().AlwaysRebuild() ||
2606 Typedef != T->getDecl()) {
2607 Result = getDerived().RebuildTypedefType(Typedef);
2608 if (Result.isNull())
2609 return QualType();
2610 }
Mike Stump11289f42009-09-09 15:08:12 +00002611
John McCall550e0c22009-10-21 00:40:46 +00002612 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2613 NewTL.setNameLoc(TL.getNameLoc());
2614
2615 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002616}
Mike Stump11289f42009-09-09 15:08:12 +00002617
Douglas Gregord6ff3322009-08-04 16:50:30 +00002618template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002619QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
2620 TypeOfExprTypeLoc TL) {
2621 TypeOfExprType *T = TL.getTypePtr();
2622
Douglas Gregore922c772009-08-04 22:27:00 +00002623 // typeof expressions are not potentially evaluated contexts
2624 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002625
Douglas Gregord6ff3322009-08-04 16:50:30 +00002626 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2627 if (E.isInvalid())
2628 return QualType();
2629
John McCall550e0c22009-10-21 00:40:46 +00002630 QualType Result = TL.getType();
2631 if (getDerived().AlwaysRebuild() ||
2632 E.get() != T->getUnderlyingExpr()) {
2633 Result = getDerived().RebuildTypeOfExprType(move(E));
2634 if (Result.isNull())
2635 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002636 }
John McCall550e0c22009-10-21 00:40:46 +00002637 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002638
John McCall550e0c22009-10-21 00:40:46 +00002639 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
2640 NewTL.setNameLoc(TL.getNameLoc());
2641
2642 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002643}
Mike Stump11289f42009-09-09 15:08:12 +00002644
2645template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002646QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
2647 TypeOfTypeLoc TL) {
2648 TypeOfType *T = TL.getTypePtr();
2649
John McCallbcd03502009-12-07 02:54:59 +00002650 // FIXME: should be an inner type, or at least have a TypeSourceInfo.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002651 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2652 if (Underlying.isNull())
2653 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002654
John McCall550e0c22009-10-21 00:40:46 +00002655 QualType Result = TL.getType();
2656 if (getDerived().AlwaysRebuild() ||
2657 Underlying != T->getUnderlyingType()) {
2658 Result = getDerived().RebuildTypeOfType(Underlying);
2659 if (Result.isNull())
2660 return QualType();
2661 }
Mike Stump11289f42009-09-09 15:08:12 +00002662
John McCall550e0c22009-10-21 00:40:46 +00002663 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
2664 NewTL.setNameLoc(TL.getNameLoc());
2665
2666 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002667}
Mike Stump11289f42009-09-09 15:08:12 +00002668
2669template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002670QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
2671 DecltypeTypeLoc TL) {
2672 DecltypeType *T = TL.getTypePtr();
2673
Douglas Gregore922c772009-08-04 22:27:00 +00002674 // decltype expressions are not potentially evaluated contexts
2675 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002676
Douglas Gregord6ff3322009-08-04 16:50:30 +00002677 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2678 if (E.isInvalid())
2679 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002680
John McCall550e0c22009-10-21 00:40:46 +00002681 QualType Result = TL.getType();
2682 if (getDerived().AlwaysRebuild() ||
2683 E.get() != T->getUnderlyingExpr()) {
2684 Result = getDerived().RebuildDecltypeType(move(E));
2685 if (Result.isNull())
2686 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002687 }
John McCall550e0c22009-10-21 00:40:46 +00002688 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002689
John McCall550e0c22009-10-21 00:40:46 +00002690 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2691 NewTL.setNameLoc(TL.getNameLoc());
2692
2693 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002694}
2695
2696template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002697QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
2698 RecordTypeLoc TL) {
2699 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002700 RecordDecl *Record
John McCall550e0c22009-10-21 00:40:46 +00002701 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002702 if (!Record)
2703 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002704
John McCall550e0c22009-10-21 00:40:46 +00002705 QualType Result = TL.getType();
2706 if (getDerived().AlwaysRebuild() ||
2707 Record != T->getDecl()) {
2708 Result = getDerived().RebuildRecordType(Record);
2709 if (Result.isNull())
2710 return QualType();
2711 }
Mike Stump11289f42009-09-09 15:08:12 +00002712
John McCall550e0c22009-10-21 00:40:46 +00002713 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2714 NewTL.setNameLoc(TL.getNameLoc());
2715
2716 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002717}
Mike Stump11289f42009-09-09 15:08:12 +00002718
2719template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002720QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
2721 EnumTypeLoc TL) {
2722 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002723 EnumDecl *Enum
John McCall550e0c22009-10-21 00:40:46 +00002724 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002725 if (!Enum)
2726 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002727
John McCall550e0c22009-10-21 00:40:46 +00002728 QualType Result = TL.getType();
2729 if (getDerived().AlwaysRebuild() ||
2730 Enum != T->getDecl()) {
2731 Result = getDerived().RebuildEnumType(Enum);
2732 if (Result.isNull())
2733 return QualType();
2734 }
Mike Stump11289f42009-09-09 15:08:12 +00002735
John McCall550e0c22009-10-21 00:40:46 +00002736 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2737 NewTL.setNameLoc(TL.getNameLoc());
2738
2739 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002740}
John McCallfcc33b02009-09-05 00:15:47 +00002741
2742template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002743QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
2744 ElaboratedTypeLoc TL) {
2745 ElaboratedType *T = TL.getTypePtr();
2746
2747 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002748 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2749 if (Underlying.isNull())
2750 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002751
John McCall550e0c22009-10-21 00:40:46 +00002752 QualType Result = TL.getType();
2753 if (getDerived().AlwaysRebuild() ||
2754 Underlying != T->getUnderlyingType()) {
2755 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2756 if (Result.isNull())
2757 return QualType();
2758 }
Mike Stump11289f42009-09-09 15:08:12 +00002759
John McCall550e0c22009-10-21 00:40:46 +00002760 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2761 NewTL.setNameLoc(TL.getNameLoc());
2762
2763 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002764}
Mike Stump11289f42009-09-09 15:08:12 +00002765
2766
Douglas Gregord6ff3322009-08-04 16:50:30 +00002767template<typename Derived>
2768QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002769 TypeLocBuilder &TLB,
2770 TemplateTypeParmTypeLoc TL) {
2771 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002772}
2773
Mike Stump11289f42009-09-09 15:08:12 +00002774template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002775QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002776 TypeLocBuilder &TLB,
2777 SubstTemplateTypeParmTypeLoc TL) {
2778 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002779}
2780
2781template<typename Derived>
Douglas Gregorc59e5612009-10-19 22:04:39 +00002782inline QualType
2783TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall550e0c22009-10-21 00:40:46 +00002784 TypeLocBuilder &TLB,
2785 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00002786 return TransformTemplateSpecializationType(TLB, TL, QualType());
2787}
John McCall550e0c22009-10-21 00:40:46 +00002788
John McCall0ad16662009-10-29 08:12:44 +00002789template<typename Derived>
2790QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2791 const TemplateSpecializationType *TST,
2792 QualType ObjectType) {
2793 // FIXME: this entire method is a temporary workaround; callers
2794 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00002795
John McCall0ad16662009-10-29 08:12:44 +00002796 // Fake up a TemplateSpecializationTypeLoc.
2797 TypeLocBuilder TLB;
2798 TemplateSpecializationTypeLoc TL
2799 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2800
John McCall0d07eb32009-10-29 18:45:58 +00002801 SourceLocation BaseLoc = getDerived().getBaseLocation();
2802
2803 TL.setTemplateNameLoc(BaseLoc);
2804 TL.setLAngleLoc(BaseLoc);
2805 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00002806 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2807 const TemplateArgument &TA = TST->getArg(i);
2808 TemplateArgumentLoc TAL;
2809 getDerived().InventTemplateArgumentLoc(TA, TAL);
2810 TL.setArgLocInfo(i, TAL.getLocInfo());
2811 }
2812
2813 TypeLocBuilder IgnoredTLB;
2814 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00002815}
2816
2817template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002818QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00002819 TypeLocBuilder &TLB,
2820 TemplateSpecializationTypeLoc TL,
2821 QualType ObjectType) {
2822 const TemplateSpecializationType *T = TL.getTypePtr();
2823
Mike Stump11289f42009-09-09 15:08:12 +00002824 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002825 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002826 if (Template.isNull())
2827 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002828
John McCall6b51f282009-11-23 01:53:49 +00002829 TemplateArgumentListInfo NewTemplateArgs;
2830 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2831 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2832
2833 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2834 TemplateArgumentLoc Loc;
2835 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00002836 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00002837 NewTemplateArgs.addArgument(Loc);
2838 }
Mike Stump11289f42009-09-09 15:08:12 +00002839
John McCall0ad16662009-10-29 08:12:44 +00002840 // FIXME: maybe don't rebuild if all the template arguments are the same.
2841
2842 QualType Result =
2843 getDerived().RebuildTemplateSpecializationType(Template,
2844 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00002845 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00002846
2847 if (!Result.isNull()) {
2848 TemplateSpecializationTypeLoc NewTL
2849 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2850 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2851 NewTL.setLAngleLoc(TL.getLAngleLoc());
2852 NewTL.setRAngleLoc(TL.getRAngleLoc());
2853 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2854 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002855 }
Mike Stump11289f42009-09-09 15:08:12 +00002856
John McCall0ad16662009-10-29 08:12:44 +00002857 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002858}
Mike Stump11289f42009-09-09 15:08:12 +00002859
2860template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002861QualType
2862TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
2863 QualifiedNameTypeLoc TL) {
2864 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002865 NestedNameSpecifier *NNS
2866 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2867 SourceRange());
2868 if (!NNS)
2869 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002870
Douglas Gregord6ff3322009-08-04 16:50:30 +00002871 QualType Named = getDerived().TransformType(T->getNamedType());
2872 if (Named.isNull())
2873 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002874
John McCall550e0c22009-10-21 00:40:46 +00002875 QualType Result = TL.getType();
2876 if (getDerived().AlwaysRebuild() ||
2877 NNS != T->getQualifier() ||
2878 Named != T->getNamedType()) {
2879 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2880 if (Result.isNull())
2881 return QualType();
2882 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002883
John McCall550e0c22009-10-21 00:40:46 +00002884 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2885 NewTL.setNameLoc(TL.getNameLoc());
2886
2887 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002888}
Mike Stump11289f42009-09-09 15:08:12 +00002889
2890template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002891QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
2892 TypenameTypeLoc TL) {
2893 TypenameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00002894
2895 /* FIXME: preserve source information better than this */
2896 SourceRange SR(TL.getNameLoc());
2897
Douglas Gregord6ff3322009-08-04 16:50:30 +00002898 NestedNameSpecifier *NNS
John McCall0ad16662009-10-29 08:12:44 +00002899 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002900 if (!NNS)
2901 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002902
John McCall550e0c22009-10-21 00:40:46 +00002903 QualType Result;
2904
Douglas Gregord6ff3322009-08-04 16:50:30 +00002905 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002906 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002907 = getDerived().TransformType(QualType(TemplateId, 0));
2908 if (NewTemplateId.isNull())
2909 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002910
Douglas Gregord6ff3322009-08-04 16:50:30 +00002911 if (!getDerived().AlwaysRebuild() &&
2912 NNS == T->getQualifier() &&
2913 NewTemplateId == QualType(TemplateId, 0))
2914 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002915
John McCall550e0c22009-10-21 00:40:46 +00002916 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2917 } else {
John McCall0ad16662009-10-29 08:12:44 +00002918 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002919 }
John McCall550e0c22009-10-21 00:40:46 +00002920 if (Result.isNull())
2921 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002922
John McCall550e0c22009-10-21 00:40:46 +00002923 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2924 NewTL.setNameLoc(TL.getNameLoc());
2925
2926 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002927}
Mike Stump11289f42009-09-09 15:08:12 +00002928
Douglas Gregord6ff3322009-08-04 16:50:30 +00002929template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002930QualType
2931TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
2932 ObjCInterfaceTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002933 assert(false && "TransformObjCInterfaceType unimplemented");
2934 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002935}
Mike Stump11289f42009-09-09 15:08:12 +00002936
2937template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002938QualType
2939TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
2940 ObjCObjectPointerTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002941 assert(false && "TransformObjCObjectPointerType unimplemented");
2942 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00002943}
2944
Douglas Gregord6ff3322009-08-04 16:50:30 +00002945//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00002946// Statement transformation
2947//===----------------------------------------------------------------------===//
2948template<typename Derived>
2949Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002950TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2951 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002952}
2953
2954template<typename Derived>
2955Sema::OwningStmtResult
2956TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2957 return getDerived().TransformCompoundStmt(S, false);
2958}
2959
2960template<typename Derived>
2961Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002962TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00002963 bool IsStmtExpr) {
2964 bool SubStmtChanged = false;
2965 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
2966 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
2967 B != BEnd; ++B) {
2968 OwningStmtResult Result = getDerived().TransformStmt(*B);
2969 if (Result.isInvalid())
2970 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002971
Douglas Gregorebe10102009-08-20 07:17:43 +00002972 SubStmtChanged = SubStmtChanged || Result.get() != *B;
2973 Statements.push_back(Result.takeAs<Stmt>());
2974 }
Mike Stump11289f42009-09-09 15:08:12 +00002975
Douglas Gregorebe10102009-08-20 07:17:43 +00002976 if (!getDerived().AlwaysRebuild() &&
2977 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00002978 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002979
2980 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
2981 move_arg(Statements),
2982 S->getRBracLoc(),
2983 IsStmtExpr);
2984}
Mike Stump11289f42009-09-09 15:08:12 +00002985
Douglas Gregorebe10102009-08-20 07:17:43 +00002986template<typename Derived>
2987Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002988TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00002989 OwningExprResult LHS(SemaRef), RHS(SemaRef);
2990 {
2991 // The case value expressions are not potentially evaluated.
2992 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002993
Eli Friedman06577382009-11-19 03:14:00 +00002994 // Transform the left-hand case value.
2995 LHS = getDerived().TransformExpr(S->getLHS());
2996 if (LHS.isInvalid())
2997 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002998
Eli Friedman06577382009-11-19 03:14:00 +00002999 // Transform the right-hand case value (for the GNU case-range extension).
3000 RHS = getDerived().TransformExpr(S->getRHS());
3001 if (RHS.isInvalid())
3002 return SemaRef.StmtError();
3003 }
Mike Stump11289f42009-09-09 15:08:12 +00003004
Douglas Gregorebe10102009-08-20 07:17:43 +00003005 // Build the case statement.
3006 // Case statements are always rebuilt so that they will attached to their
3007 // transformed switch statement.
3008 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3009 move(LHS),
3010 S->getEllipsisLoc(),
3011 move(RHS),
3012 S->getColonLoc());
3013 if (Case.isInvalid())
3014 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003015
Douglas Gregorebe10102009-08-20 07:17:43 +00003016 // Transform the statement following the case
3017 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3018 if (SubStmt.isInvalid())
3019 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003020
Douglas Gregorebe10102009-08-20 07:17:43 +00003021 // Attach the body to the case statement
3022 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3023}
3024
3025template<typename Derived>
3026Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003027TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003028 // Transform the statement following the default case
3029 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3030 if (SubStmt.isInvalid())
3031 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003032
Douglas Gregorebe10102009-08-20 07:17:43 +00003033 // Default statements are always rebuilt
3034 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3035 move(SubStmt));
3036}
Mike Stump11289f42009-09-09 15:08:12 +00003037
Douglas Gregorebe10102009-08-20 07:17:43 +00003038template<typename Derived>
3039Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003040TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003041 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3042 if (SubStmt.isInvalid())
3043 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003044
Douglas Gregorebe10102009-08-20 07:17:43 +00003045 // FIXME: Pass the real colon location in.
3046 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3047 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3048 move(SubStmt));
3049}
Mike Stump11289f42009-09-09 15:08:12 +00003050
Douglas Gregorebe10102009-08-20 07:17:43 +00003051template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003052Sema::OwningStmtResult
3053TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003054 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003055 OwningExprResult Cond(SemaRef);
3056 VarDecl *ConditionVar = 0;
3057 if (S->getConditionVariable()) {
3058 ConditionVar
3059 = cast_or_null<VarDecl>(
3060 getDerived().TransformDefinition(S->getConditionVariable()));
3061 if (!ConditionVar)
3062 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003063 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003064 Cond = getDerived().TransformExpr(S->getCond());
3065
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003066 if (Cond.isInvalid())
3067 return SemaRef.StmtError();
3068 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003069
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003070 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003071
Douglas Gregorebe10102009-08-20 07:17:43 +00003072 // Transform the "then" branch.
3073 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3074 if (Then.isInvalid())
3075 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003076
Douglas Gregorebe10102009-08-20 07:17:43 +00003077 // Transform the "else" branch.
3078 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3079 if (Else.isInvalid())
3080 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003081
Douglas Gregorebe10102009-08-20 07:17:43 +00003082 if (!getDerived().AlwaysRebuild() &&
3083 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003084 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003085 Then.get() == S->getThen() &&
3086 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003087 return SemaRef.Owned(S->Retain());
3088
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003089 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3090 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003091 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003092}
3093
3094template<typename Derived>
3095Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003096TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003097 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003098 OwningExprResult Cond(SemaRef);
3099 VarDecl *ConditionVar = 0;
3100 if (S->getConditionVariable()) {
3101 ConditionVar
3102 = cast_or_null<VarDecl>(
3103 getDerived().TransformDefinition(S->getConditionVariable()));
3104 if (!ConditionVar)
3105 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003106 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003107 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003108
3109 if (Cond.isInvalid())
3110 return SemaRef.StmtError();
3111 }
Mike Stump11289f42009-09-09 15:08:12 +00003112
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003113 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003114
Douglas Gregorebe10102009-08-20 07:17:43 +00003115 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003116 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3117 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003118 if (Switch.isInvalid())
3119 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003120
Douglas Gregorebe10102009-08-20 07:17:43 +00003121 // Transform the body of the switch statement.
3122 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3123 if (Body.isInvalid())
3124 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003125
Douglas Gregorebe10102009-08-20 07:17:43 +00003126 // Complete the switch statement.
3127 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3128 move(Body));
3129}
Mike Stump11289f42009-09-09 15:08:12 +00003130
Douglas Gregorebe10102009-08-20 07:17:43 +00003131template<typename Derived>
3132Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003133TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003134 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003135 OwningExprResult Cond(SemaRef);
3136 VarDecl *ConditionVar = 0;
3137 if (S->getConditionVariable()) {
3138 ConditionVar
3139 = cast_or_null<VarDecl>(
3140 getDerived().TransformDefinition(S->getConditionVariable()));
3141 if (!ConditionVar)
3142 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003143 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003144 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003145
3146 if (Cond.isInvalid())
3147 return SemaRef.StmtError();
3148 }
Mike Stump11289f42009-09-09 15:08:12 +00003149
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003150 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003151
Douglas Gregorebe10102009-08-20 07:17:43 +00003152 // Transform the body
3153 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3154 if (Body.isInvalid())
3155 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003156
Douglas Gregorebe10102009-08-20 07:17:43 +00003157 if (!getDerived().AlwaysRebuild() &&
3158 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003159 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003160 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003161 return SemaRef.Owned(S->Retain());
3162
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003163 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3164 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003165}
Mike Stump11289f42009-09-09 15:08:12 +00003166
Douglas Gregorebe10102009-08-20 07:17:43 +00003167template<typename Derived>
3168Sema::OwningStmtResult
3169TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3170 // Transform the condition
3171 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3172 if (Cond.isInvalid())
3173 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003174
Douglas Gregorebe10102009-08-20 07:17:43 +00003175 // Transform the body
3176 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3177 if (Body.isInvalid())
3178 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003179
Douglas Gregorebe10102009-08-20 07:17:43 +00003180 if (!getDerived().AlwaysRebuild() &&
3181 Cond.get() == S->getCond() &&
3182 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003183 return SemaRef.Owned(S->Retain());
3184
Douglas Gregorebe10102009-08-20 07:17:43 +00003185 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3186 /*FIXME:*/S->getWhileLoc(), move(Cond),
3187 S->getRParenLoc());
3188}
Mike Stump11289f42009-09-09 15:08:12 +00003189
Douglas Gregorebe10102009-08-20 07:17:43 +00003190template<typename Derived>
3191Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003192TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003193 // Transform the initialization statement
3194 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3195 if (Init.isInvalid())
3196 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003197
Douglas Gregorebe10102009-08-20 07:17:43 +00003198 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003199 OwningExprResult Cond(SemaRef);
3200 VarDecl *ConditionVar = 0;
3201 if (S->getConditionVariable()) {
3202 ConditionVar
3203 = cast_or_null<VarDecl>(
3204 getDerived().TransformDefinition(S->getConditionVariable()));
3205 if (!ConditionVar)
3206 return SemaRef.StmtError();
3207 } else {
3208 Cond = getDerived().TransformExpr(S->getCond());
3209
3210 if (Cond.isInvalid())
3211 return SemaRef.StmtError();
3212 }
Mike Stump11289f42009-09-09 15:08:12 +00003213
Douglas Gregorebe10102009-08-20 07:17:43 +00003214 // Transform the increment
3215 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3216 if (Inc.isInvalid())
3217 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003218
Douglas Gregorebe10102009-08-20 07:17:43 +00003219 // Transform the body
3220 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3221 if (Body.isInvalid())
3222 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003223
Douglas Gregorebe10102009-08-20 07:17:43 +00003224 if (!getDerived().AlwaysRebuild() &&
3225 Init.get() == S->getInit() &&
3226 Cond.get() == S->getCond() &&
3227 Inc.get() == S->getInc() &&
3228 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003229 return SemaRef.Owned(S->Retain());
3230
Douglas Gregorebe10102009-08-20 07:17:43 +00003231 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003232 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003233 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003234 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003235 S->getRParenLoc(), move(Body));
3236}
3237
3238template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003239Sema::OwningStmtResult
3240TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003241 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003242 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003243 S->getLabel());
3244}
3245
3246template<typename Derived>
3247Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003248TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003249 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3250 if (Target.isInvalid())
3251 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003252
Douglas Gregorebe10102009-08-20 07:17:43 +00003253 if (!getDerived().AlwaysRebuild() &&
3254 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003255 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003256
3257 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3258 move(Target));
3259}
3260
3261template<typename Derived>
3262Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003263TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3264 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003265}
Mike Stump11289f42009-09-09 15:08:12 +00003266
Douglas Gregorebe10102009-08-20 07:17:43 +00003267template<typename Derived>
3268Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003269TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3270 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003271}
Mike Stump11289f42009-09-09 15:08:12 +00003272
Douglas Gregorebe10102009-08-20 07:17:43 +00003273template<typename Derived>
3274Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003275TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003276 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3277 if (Result.isInvalid())
3278 return SemaRef.StmtError();
3279
Mike Stump11289f42009-09-09 15:08:12 +00003280 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003281 // to tell whether the return type of the function has changed.
3282 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3283}
Mike Stump11289f42009-09-09 15:08:12 +00003284
Douglas Gregorebe10102009-08-20 07:17:43 +00003285template<typename Derived>
3286Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003287TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003288 bool DeclChanged = false;
3289 llvm::SmallVector<Decl *, 4> Decls;
3290 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3291 D != DEnd; ++D) {
3292 Decl *Transformed = getDerived().TransformDefinition(*D);
3293 if (!Transformed)
3294 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003295
Douglas Gregorebe10102009-08-20 07:17:43 +00003296 if (Transformed != *D)
3297 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003298
Douglas Gregorebe10102009-08-20 07:17:43 +00003299 Decls.push_back(Transformed);
3300 }
Mike Stump11289f42009-09-09 15:08:12 +00003301
Douglas Gregorebe10102009-08-20 07:17:43 +00003302 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003303 return SemaRef.Owned(S->Retain());
3304
3305 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003306 S->getStartLoc(), S->getEndLoc());
3307}
Mike Stump11289f42009-09-09 15:08:12 +00003308
Douglas Gregorebe10102009-08-20 07:17:43 +00003309template<typename Derived>
3310Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003311TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003312 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003313 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003314}
3315
3316template<typename Derived>
3317Sema::OwningStmtResult
3318TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
3319 // FIXME: Implement!
3320 assert(false && "Inline assembly cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003321 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003322}
3323
3324
3325template<typename Derived>
3326Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003327TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003328 // FIXME: Implement this
3329 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003330 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003331}
Mike Stump11289f42009-09-09 15:08:12 +00003332
Douglas Gregorebe10102009-08-20 07:17:43 +00003333template<typename Derived>
3334Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003335TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003336 // FIXME: Implement this
3337 assert(false && "Cannot transform an Objective-C @catch statement");
3338 return SemaRef.Owned(S->Retain());
3339}
Mike Stump11289f42009-09-09 15:08:12 +00003340
Douglas Gregorebe10102009-08-20 07:17:43 +00003341template<typename Derived>
3342Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003343TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003344 // FIXME: Implement this
3345 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003346 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003347}
Mike Stump11289f42009-09-09 15:08:12 +00003348
Douglas Gregorebe10102009-08-20 07:17:43 +00003349template<typename Derived>
3350Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003351TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003352 // FIXME: Implement this
3353 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003354 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003355}
Mike Stump11289f42009-09-09 15:08:12 +00003356
Douglas Gregorebe10102009-08-20 07:17:43 +00003357template<typename Derived>
3358Sema::OwningStmtResult
3359TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003360 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003361 // FIXME: Implement this
3362 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003363 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003364}
3365
3366template<typename Derived>
3367Sema::OwningStmtResult
3368TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003369 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003370 // FIXME: Implement this
3371 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003372 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003373}
3374
3375
3376template<typename Derived>
3377Sema::OwningStmtResult
3378TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3379 // Transform the exception declaration, if any.
3380 VarDecl *Var = 0;
3381 if (S->getExceptionDecl()) {
3382 VarDecl *ExceptionDecl = S->getExceptionDecl();
3383 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3384 ExceptionDecl->getDeclName());
3385
3386 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3387 if (T.isNull())
3388 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003389
Douglas Gregorebe10102009-08-20 07:17:43 +00003390 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3391 T,
John McCallbcd03502009-12-07 02:54:59 +00003392 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003393 ExceptionDecl->getIdentifier(),
3394 ExceptionDecl->getLocation(),
3395 /*FIXME: Inaccurate*/
3396 SourceRange(ExceptionDecl->getLocation()));
3397 if (!Var || Var->isInvalidDecl()) {
3398 if (Var)
3399 Var->Destroy(SemaRef.Context);
3400 return SemaRef.StmtError();
3401 }
3402 }
Mike Stump11289f42009-09-09 15:08:12 +00003403
Douglas Gregorebe10102009-08-20 07:17:43 +00003404 // Transform the actual exception handler.
3405 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3406 if (Handler.isInvalid()) {
3407 if (Var)
3408 Var->Destroy(SemaRef.Context);
3409 return SemaRef.StmtError();
3410 }
Mike Stump11289f42009-09-09 15:08:12 +00003411
Douglas Gregorebe10102009-08-20 07:17:43 +00003412 if (!getDerived().AlwaysRebuild() &&
3413 !Var &&
3414 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003415 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003416
3417 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3418 Var,
3419 move(Handler));
3420}
Mike Stump11289f42009-09-09 15:08:12 +00003421
Douglas Gregorebe10102009-08-20 07:17:43 +00003422template<typename Derived>
3423Sema::OwningStmtResult
3424TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3425 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003426 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003427 = getDerived().TransformCompoundStmt(S->getTryBlock());
3428 if (TryBlock.isInvalid())
3429 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003430
Douglas Gregorebe10102009-08-20 07:17:43 +00003431 // Transform the handlers.
3432 bool HandlerChanged = false;
3433 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3434 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003435 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003436 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3437 if (Handler.isInvalid())
3438 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003439
Douglas Gregorebe10102009-08-20 07:17:43 +00003440 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3441 Handlers.push_back(Handler.takeAs<Stmt>());
3442 }
Mike Stump11289f42009-09-09 15:08:12 +00003443
Douglas Gregorebe10102009-08-20 07:17:43 +00003444 if (!getDerived().AlwaysRebuild() &&
3445 TryBlock.get() == S->getTryBlock() &&
3446 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003447 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003448
3449 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003450 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003451}
Mike Stump11289f42009-09-09 15:08:12 +00003452
Douglas Gregorebe10102009-08-20 07:17:43 +00003453//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003454// Expression transformation
3455//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003456template<typename Derived>
3457Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003458TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003459 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003460}
Mike Stump11289f42009-09-09 15:08:12 +00003461
3462template<typename Derived>
3463Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003464TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003465 NestedNameSpecifier *Qualifier = 0;
3466 if (E->getQualifier()) {
3467 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3468 E->getQualifierRange());
3469 if (!Qualifier)
3470 return SemaRef.ExprError();
3471 }
John McCallce546572009-12-08 09:08:17 +00003472
3473 ValueDecl *ND
3474 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003475 if (!ND)
3476 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003477
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003478 if (!getDerived().AlwaysRebuild() &&
3479 Qualifier == E->getQualifier() &&
3480 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003481 !E->hasExplicitTemplateArgumentList()) {
3482
3483 // Mark it referenced in the new context regardless.
3484 // FIXME: this is a bit instantiation-specific.
3485 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3486
Mike Stump11289f42009-09-09 15:08:12 +00003487 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003488 }
John McCallce546572009-12-08 09:08:17 +00003489
3490 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3491 if (E->hasExplicitTemplateArgumentList()) {
3492 TemplateArgs = &TransArgs;
3493 TransArgs.setLAngleLoc(E->getLAngleLoc());
3494 TransArgs.setRAngleLoc(E->getRAngleLoc());
3495 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3496 TemplateArgumentLoc Loc;
3497 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3498 return SemaRef.ExprError();
3499 TransArgs.addArgument(Loc);
3500 }
3501 }
3502
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003503 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003504 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003505}
Mike Stump11289f42009-09-09 15:08:12 +00003506
Douglas Gregora16548e2009-08-11 05:31:07 +00003507template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003508Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003509TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003510 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003511}
Mike Stump11289f42009-09-09 15:08:12 +00003512
Douglas Gregora16548e2009-08-11 05:31:07 +00003513template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003514Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003515TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003516 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003517}
Mike Stump11289f42009-09-09 15:08:12 +00003518
Douglas Gregora16548e2009-08-11 05:31:07 +00003519template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003520Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003521TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003522 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003523}
Mike Stump11289f42009-09-09 15:08:12 +00003524
Douglas Gregora16548e2009-08-11 05:31:07 +00003525template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003526Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003527TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003528 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003529}
Mike Stump11289f42009-09-09 15:08:12 +00003530
Douglas Gregora16548e2009-08-11 05:31:07 +00003531template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003532Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003533TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003534 return SemaRef.Owned(E->Retain());
3535}
3536
3537template<typename Derived>
3538Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003539TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003540 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3541 if (SubExpr.isInvalid())
3542 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003543
Douglas Gregora16548e2009-08-11 05:31:07 +00003544 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003545 return SemaRef.Owned(E->Retain());
3546
3547 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003548 E->getRParen());
3549}
3550
Mike Stump11289f42009-09-09 15:08:12 +00003551template<typename Derived>
3552Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003553TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3554 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003555 if (SubExpr.isInvalid())
3556 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003557
Douglas Gregora16548e2009-08-11 05:31:07 +00003558 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003559 return SemaRef.Owned(E->Retain());
3560
Douglas Gregora16548e2009-08-11 05:31:07 +00003561 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3562 E->getOpcode(),
3563 move(SubExpr));
3564}
Mike Stump11289f42009-09-09 15:08:12 +00003565
Douglas Gregora16548e2009-08-11 05:31:07 +00003566template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003567Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003568TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003569 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003570 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003571
John McCallbcd03502009-12-07 02:54:59 +00003572 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003573 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003574 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003575
John McCall4c98fd82009-11-04 07:28:41 +00003576 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003577 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003578
John McCall4c98fd82009-11-04 07:28:41 +00003579 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003580 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003581 E->getSourceRange());
3582 }
Mike Stump11289f42009-09-09 15:08:12 +00003583
Douglas Gregora16548e2009-08-11 05:31:07 +00003584 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003585 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003586 // C++0x [expr.sizeof]p1:
3587 // The operand is either an expression, which is an unevaluated operand
3588 // [...]
3589 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003590
Douglas Gregora16548e2009-08-11 05:31:07 +00003591 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3592 if (SubExpr.isInvalid())
3593 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003594
Douglas Gregora16548e2009-08-11 05:31:07 +00003595 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3596 return SemaRef.Owned(E->Retain());
3597 }
Mike Stump11289f42009-09-09 15:08:12 +00003598
Douglas Gregora16548e2009-08-11 05:31:07 +00003599 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3600 E->isSizeOf(),
3601 E->getSourceRange());
3602}
Mike Stump11289f42009-09-09 15:08:12 +00003603
Douglas Gregora16548e2009-08-11 05:31:07 +00003604template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003605Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003606TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003607 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3608 if (LHS.isInvalid())
3609 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003610
Douglas Gregora16548e2009-08-11 05:31:07 +00003611 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3612 if (RHS.isInvalid())
3613 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003614
3615
Douglas Gregora16548e2009-08-11 05:31:07 +00003616 if (!getDerived().AlwaysRebuild() &&
3617 LHS.get() == E->getLHS() &&
3618 RHS.get() == E->getRHS())
3619 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003620
Douglas Gregora16548e2009-08-11 05:31:07 +00003621 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3622 /*FIXME:*/E->getLHS()->getLocStart(),
3623 move(RHS),
3624 E->getRBracketLoc());
3625}
Mike Stump11289f42009-09-09 15:08:12 +00003626
3627template<typename Derived>
3628Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003629TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003630 // Transform the callee.
3631 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3632 if (Callee.isInvalid())
3633 return SemaRef.ExprError();
3634
3635 // Transform arguments.
3636 bool ArgChanged = false;
3637 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3638 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3639 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3640 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3641 if (Arg.isInvalid())
3642 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003643
Douglas Gregora16548e2009-08-11 05:31:07 +00003644 // FIXME: Wrong source location information for the ','.
3645 FakeCommaLocs.push_back(
3646 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003647
3648 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003649 Args.push_back(Arg.takeAs<Expr>());
3650 }
Mike Stump11289f42009-09-09 15:08:12 +00003651
Douglas Gregora16548e2009-08-11 05:31:07 +00003652 if (!getDerived().AlwaysRebuild() &&
3653 Callee.get() == E->getCallee() &&
3654 !ArgChanged)
3655 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003656
Douglas Gregora16548e2009-08-11 05:31:07 +00003657 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003658 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003659 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3660 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3661 move_arg(Args),
3662 FakeCommaLocs.data(),
3663 E->getRParenLoc());
3664}
Mike Stump11289f42009-09-09 15:08:12 +00003665
3666template<typename Derived>
3667Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003668TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003669 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3670 if (Base.isInvalid())
3671 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003672
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003673 NestedNameSpecifier *Qualifier = 0;
3674 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003675 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003676 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3677 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003678 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003679 return SemaRef.ExprError();
3680 }
Mike Stump11289f42009-09-09 15:08:12 +00003681
Eli Friedman2cfcef62009-12-04 06:40:45 +00003682 ValueDecl *Member
3683 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003684 if (!Member)
3685 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003686
Douglas Gregora16548e2009-08-11 05:31:07 +00003687 if (!getDerived().AlwaysRebuild() &&
3688 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003689 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003690 Member == E->getMemberDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003691 !E->hasExplicitTemplateArgumentList()) {
3692
3693 // Mark it referenced in the new context regardless.
3694 // FIXME: this is a bit instantiation-specific.
3695 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00003696 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003697 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003698
John McCall6b51f282009-11-23 01:53:49 +00003699 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003700 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003701 TransArgs.setLAngleLoc(E->getLAngleLoc());
3702 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003703 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003704 TemplateArgumentLoc Loc;
3705 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003706 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003707 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003708 }
3709 }
3710
Douglas Gregora16548e2009-08-11 05:31:07 +00003711 // FIXME: Bogus source location for the operator
3712 SourceLocation FakeOperatorLoc
3713 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3714
3715 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3716 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003717 Qualifier,
3718 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003719 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003720 Member,
John McCall6b51f282009-11-23 01:53:49 +00003721 (E->hasExplicitTemplateArgumentList()
3722 ? &TransArgs : 0),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003723 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00003724}
Mike Stump11289f42009-09-09 15:08:12 +00003725
Douglas Gregora16548e2009-08-11 05:31:07 +00003726template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003727Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003728TreeTransform<Derived>::TransformCastExpr(CastExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003729 assert(false && "Cannot transform abstract class");
3730 return SemaRef.Owned(E->Retain());
3731}
3732
3733template<typename Derived>
3734Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003735TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003736 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3737 if (LHS.isInvalid())
3738 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003739
Douglas Gregora16548e2009-08-11 05:31:07 +00003740 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3741 if (RHS.isInvalid())
3742 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003743
Douglas Gregora16548e2009-08-11 05:31:07 +00003744 if (!getDerived().AlwaysRebuild() &&
3745 LHS.get() == E->getLHS() &&
3746 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003747 return SemaRef.Owned(E->Retain());
3748
Douglas Gregora16548e2009-08-11 05:31:07 +00003749 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3750 move(LHS), move(RHS));
3751}
3752
Mike Stump11289f42009-09-09 15:08:12 +00003753template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003754Sema::OwningExprResult
3755TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00003756 CompoundAssignOperator *E) {
3757 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00003758}
Mike Stump11289f42009-09-09 15:08:12 +00003759
Douglas Gregora16548e2009-08-11 05:31:07 +00003760template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003761Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003762TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003763 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3764 if (Cond.isInvalid())
3765 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003766
Douglas Gregora16548e2009-08-11 05:31:07 +00003767 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3768 if (LHS.isInvalid())
3769 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003770
Douglas Gregora16548e2009-08-11 05:31:07 +00003771 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3772 if (RHS.isInvalid())
3773 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003774
Douglas Gregora16548e2009-08-11 05:31:07 +00003775 if (!getDerived().AlwaysRebuild() &&
3776 Cond.get() == E->getCond() &&
3777 LHS.get() == E->getLHS() &&
3778 RHS.get() == E->getRHS())
3779 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003780
3781 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003782 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003783 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003784 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003785 move(RHS));
3786}
Mike Stump11289f42009-09-09 15:08:12 +00003787
3788template<typename Derived>
3789Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003790TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00003791 // Implicit casts are eliminated during transformation, since they
3792 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00003793 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003794}
Mike Stump11289f42009-09-09 15:08:12 +00003795
Douglas Gregora16548e2009-08-11 05:31:07 +00003796template<typename Derived>
3797Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003798TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003799 assert(false && "Cannot transform abstract class");
3800 return SemaRef.Owned(E->Retain());
3801}
3802
3803template<typename Derived>
3804Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003805TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003806 QualType T;
3807 {
3808 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003809 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003810 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3811 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003812
Douglas Gregora16548e2009-08-11 05:31:07 +00003813 T = getDerived().TransformType(E->getTypeAsWritten());
3814 if (T.isNull())
3815 return SemaRef.ExprError();
3816 }
Mike Stump11289f42009-09-09 15:08:12 +00003817
Douglas Gregor6131b442009-12-12 18:16:41 +00003818 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00003819 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003820 if (SubExpr.isInvalid())
3821 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003822
Douglas Gregora16548e2009-08-11 05:31:07 +00003823 if (!getDerived().AlwaysRebuild() &&
3824 T == E->getTypeAsWritten() &&
3825 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003826 return SemaRef.Owned(E->Retain());
3827
Douglas Gregora16548e2009-08-11 05:31:07 +00003828 return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T,
3829 E->getRParenLoc(),
3830 move(SubExpr));
3831}
Mike Stump11289f42009-09-09 15:08:12 +00003832
Douglas Gregora16548e2009-08-11 05:31:07 +00003833template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003834Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003835TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003836 QualType T;
3837 {
3838 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003839 SourceLocation FakeTypeLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003840 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3841 TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003842
Douglas Gregora16548e2009-08-11 05:31:07 +00003843 T = getDerived().TransformType(E->getType());
3844 if (T.isNull())
3845 return SemaRef.ExprError();
3846 }
Mike Stump11289f42009-09-09 15:08:12 +00003847
Douglas Gregora16548e2009-08-11 05:31:07 +00003848 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3849 if (Init.isInvalid())
3850 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003851
Douglas Gregora16548e2009-08-11 05:31:07 +00003852 if (!getDerived().AlwaysRebuild() &&
3853 T == E->getType() &&
3854 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003855 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003856
3857 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T,
3858 /*FIXME:*/E->getInitializer()->getLocEnd(),
3859 move(Init));
3860}
Mike Stump11289f42009-09-09 15:08:12 +00003861
Douglas Gregora16548e2009-08-11 05:31:07 +00003862template<typename Derived>
3863Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003864TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003865 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3866 if (Base.isInvalid())
3867 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003868
Douglas Gregora16548e2009-08-11 05:31:07 +00003869 if (!getDerived().AlwaysRebuild() &&
3870 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003871 return SemaRef.Owned(E->Retain());
3872
Douglas Gregora16548e2009-08-11 05:31:07 +00003873 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003874 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003875 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3876 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3877 E->getAccessorLoc(),
3878 E->getAccessor());
3879}
Mike Stump11289f42009-09-09 15:08:12 +00003880
Douglas Gregora16548e2009-08-11 05:31:07 +00003881template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003882Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003883TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003884 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003885
Douglas Gregora16548e2009-08-11 05:31:07 +00003886 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3887 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3888 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3889 if (Init.isInvalid())
3890 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003891
Douglas Gregora16548e2009-08-11 05:31:07 +00003892 InitChanged = InitChanged || Init.get() != E->getInit(I);
3893 Inits.push_back(Init.takeAs<Expr>());
3894 }
Mike Stump11289f42009-09-09 15:08:12 +00003895
Douglas Gregora16548e2009-08-11 05:31:07 +00003896 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003897 return SemaRef.Owned(E->Retain());
3898
Douglas Gregora16548e2009-08-11 05:31:07 +00003899 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00003900 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00003901}
Mike Stump11289f42009-09-09 15:08:12 +00003902
Douglas Gregora16548e2009-08-11 05:31:07 +00003903template<typename Derived>
3904Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003905TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003906 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00003907
Douglas Gregorebe10102009-08-20 07:17:43 +00003908 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00003909 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3910 if (Init.isInvalid())
3911 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003912
Douglas Gregorebe10102009-08-20 07:17:43 +00003913 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00003914 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3915 bool ExprChanged = false;
3916 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3917 DEnd = E->designators_end();
3918 D != DEnd; ++D) {
3919 if (D->isFieldDesignator()) {
3920 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3921 D->getDotLoc(),
3922 D->getFieldLoc()));
3923 continue;
3924 }
Mike Stump11289f42009-09-09 15:08:12 +00003925
Douglas Gregora16548e2009-08-11 05:31:07 +00003926 if (D->isArrayDesignator()) {
3927 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3928 if (Index.isInvalid())
3929 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003930
3931 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003932 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003933
Douglas Gregora16548e2009-08-11 05:31:07 +00003934 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3935 ArrayExprs.push_back(Index.release());
3936 continue;
3937 }
Mike Stump11289f42009-09-09 15:08:12 +00003938
Douglas Gregora16548e2009-08-11 05:31:07 +00003939 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00003940 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00003941 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3942 if (Start.isInvalid())
3943 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003944
Douglas Gregora16548e2009-08-11 05:31:07 +00003945 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3946 if (End.isInvalid())
3947 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003948
3949 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003950 End.get(),
3951 D->getLBracketLoc(),
3952 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003953
Douglas Gregora16548e2009-08-11 05:31:07 +00003954 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
3955 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00003956
Douglas Gregora16548e2009-08-11 05:31:07 +00003957 ArrayExprs.push_back(Start.release());
3958 ArrayExprs.push_back(End.release());
3959 }
Mike Stump11289f42009-09-09 15:08:12 +00003960
Douglas Gregora16548e2009-08-11 05:31:07 +00003961 if (!getDerived().AlwaysRebuild() &&
3962 Init.get() == E->getInit() &&
3963 !ExprChanged)
3964 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003965
Douglas Gregora16548e2009-08-11 05:31:07 +00003966 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
3967 E->getEqualOrColonLoc(),
3968 E->usesGNUSyntax(), move(Init));
3969}
Mike Stump11289f42009-09-09 15:08:12 +00003970
Douglas Gregora16548e2009-08-11 05:31:07 +00003971template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003972Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003973TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00003974 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00003975 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3976
3977 // FIXME: Will we ever have proper type location here? Will we actually
3978 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00003979 QualType T = getDerived().TransformType(E->getType());
3980 if (T.isNull())
3981 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003982
Douglas Gregora16548e2009-08-11 05:31:07 +00003983 if (!getDerived().AlwaysRebuild() &&
3984 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00003985 return SemaRef.Owned(E->Retain());
3986
Douglas Gregora16548e2009-08-11 05:31:07 +00003987 return getDerived().RebuildImplicitValueInitExpr(T);
3988}
Mike Stump11289f42009-09-09 15:08:12 +00003989
Douglas Gregora16548e2009-08-11 05:31:07 +00003990template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003991Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003992TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003993 // FIXME: Do we want the type as written?
3994 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00003995
Douglas Gregora16548e2009-08-11 05:31:07 +00003996 {
3997 // FIXME: Source location isn't quite accurate.
3998 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
3999 T = getDerived().TransformType(E->getType());
4000 if (T.isNull())
4001 return SemaRef.ExprError();
4002 }
Mike Stump11289f42009-09-09 15:08:12 +00004003
Douglas Gregora16548e2009-08-11 05:31:07 +00004004 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4005 if (SubExpr.isInvalid())
4006 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004007
Douglas Gregora16548e2009-08-11 05:31:07 +00004008 if (!getDerived().AlwaysRebuild() &&
4009 T == E->getType() &&
4010 SubExpr.get() == E->getSubExpr())
4011 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004012
Douglas Gregora16548e2009-08-11 05:31:07 +00004013 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4014 T, E->getRParenLoc());
4015}
4016
4017template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004018Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004019TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004020 bool ArgumentChanged = false;
4021 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4022 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4023 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4024 if (Init.isInvalid())
4025 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004026
Douglas Gregora16548e2009-08-11 05:31:07 +00004027 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4028 Inits.push_back(Init.takeAs<Expr>());
4029 }
Mike Stump11289f42009-09-09 15:08:12 +00004030
Douglas Gregora16548e2009-08-11 05:31:07 +00004031 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4032 move_arg(Inits),
4033 E->getRParenLoc());
4034}
Mike Stump11289f42009-09-09 15:08:12 +00004035
Douglas Gregora16548e2009-08-11 05:31:07 +00004036/// \brief Transform an address-of-label expression.
4037///
4038/// By default, the transformation of an address-of-label expression always
4039/// rebuilds the expression, so that the label identifier can be resolved to
4040/// the corresponding label statement by semantic analysis.
4041template<typename Derived>
4042Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004043TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004044 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4045 E->getLabel());
4046}
Mike Stump11289f42009-09-09 15:08:12 +00004047
4048template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004049Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004050TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004051 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004052 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4053 if (SubStmt.isInvalid())
4054 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004055
Douglas Gregora16548e2009-08-11 05:31:07 +00004056 if (!getDerived().AlwaysRebuild() &&
4057 SubStmt.get() == E->getSubStmt())
4058 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004059
4060 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004061 move(SubStmt),
4062 E->getRParenLoc());
4063}
Mike Stump11289f42009-09-09 15:08:12 +00004064
Douglas Gregora16548e2009-08-11 05:31:07 +00004065template<typename Derived>
4066Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004067TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004068 QualType T1, T2;
4069 {
4070 // FIXME: Source location isn't quite accurate.
4071 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004072
Douglas Gregora16548e2009-08-11 05:31:07 +00004073 T1 = getDerived().TransformType(E->getArgType1());
4074 if (T1.isNull())
4075 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004076
Douglas Gregora16548e2009-08-11 05:31:07 +00004077 T2 = getDerived().TransformType(E->getArgType2());
4078 if (T2.isNull())
4079 return SemaRef.ExprError();
4080 }
4081
4082 if (!getDerived().AlwaysRebuild() &&
4083 T1 == E->getArgType1() &&
4084 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004085 return SemaRef.Owned(E->Retain());
4086
Douglas Gregora16548e2009-08-11 05:31:07 +00004087 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4088 T1, T2, E->getRParenLoc());
4089}
Mike Stump11289f42009-09-09 15:08:12 +00004090
Douglas Gregora16548e2009-08-11 05:31:07 +00004091template<typename Derived>
4092Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004093TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004094 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4095 if (Cond.isInvalid())
4096 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004097
Douglas Gregora16548e2009-08-11 05:31:07 +00004098 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4099 if (LHS.isInvalid())
4100 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004101
Douglas Gregora16548e2009-08-11 05:31:07 +00004102 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4103 if (RHS.isInvalid())
4104 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004105
Douglas Gregora16548e2009-08-11 05:31:07 +00004106 if (!getDerived().AlwaysRebuild() &&
4107 Cond.get() == E->getCond() &&
4108 LHS.get() == E->getLHS() &&
4109 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004110 return SemaRef.Owned(E->Retain());
4111
Douglas Gregora16548e2009-08-11 05:31:07 +00004112 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4113 move(Cond), move(LHS), move(RHS),
4114 E->getRParenLoc());
4115}
Mike Stump11289f42009-09-09 15:08:12 +00004116
Douglas Gregora16548e2009-08-11 05:31:07 +00004117template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004118Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004119TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004120 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004121}
4122
4123template<typename Derived>
4124Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004125TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004126 switch (E->getOperator()) {
4127 case OO_New:
4128 case OO_Delete:
4129 case OO_Array_New:
4130 case OO_Array_Delete:
4131 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4132 return SemaRef.ExprError();
4133
4134 case OO_Call: {
4135 // This is a call to an object's operator().
4136 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4137
4138 // Transform the object itself.
4139 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4140 if (Object.isInvalid())
4141 return SemaRef.ExprError();
4142
4143 // FIXME: Poor location information
4144 SourceLocation FakeLParenLoc
4145 = SemaRef.PP.getLocForEndOfToken(
4146 static_cast<Expr *>(Object.get())->getLocEnd());
4147
4148 // Transform the call arguments.
4149 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4150 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4151 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004152 if (getDerived().DropCallArgument(E->getArg(I)))
4153 break;
4154
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004155 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4156 if (Arg.isInvalid())
4157 return SemaRef.ExprError();
4158
4159 // FIXME: Poor source location information.
4160 SourceLocation FakeCommaLoc
4161 = SemaRef.PP.getLocForEndOfToken(
4162 static_cast<Expr *>(Arg.get())->getLocEnd());
4163 FakeCommaLocs.push_back(FakeCommaLoc);
4164 Args.push_back(Arg.release());
4165 }
4166
4167 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4168 move_arg(Args),
4169 FakeCommaLocs.data(),
4170 E->getLocEnd());
4171 }
4172
4173#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4174 case OO_##Name:
4175#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4176#include "clang/Basic/OperatorKinds.def"
4177 case OO_Subscript:
4178 // Handled below.
4179 break;
4180
4181 case OO_Conditional:
4182 llvm_unreachable("conditional operator is not actually overloadable");
4183 return SemaRef.ExprError();
4184
4185 case OO_None:
4186 case NUM_OVERLOADED_OPERATORS:
4187 llvm_unreachable("not an overloaded operator?");
4188 return SemaRef.ExprError();
4189 }
4190
Douglas Gregora16548e2009-08-11 05:31:07 +00004191 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4192 if (Callee.isInvalid())
4193 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004194
John McCall47f29ea2009-12-08 09:21:05 +00004195 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004196 if (First.isInvalid())
4197 return SemaRef.ExprError();
4198
4199 OwningExprResult Second(SemaRef);
4200 if (E->getNumArgs() == 2) {
4201 Second = getDerived().TransformExpr(E->getArg(1));
4202 if (Second.isInvalid())
4203 return SemaRef.ExprError();
4204 }
Mike Stump11289f42009-09-09 15:08:12 +00004205
Douglas Gregora16548e2009-08-11 05:31:07 +00004206 if (!getDerived().AlwaysRebuild() &&
4207 Callee.get() == E->getCallee() &&
4208 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004209 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4210 return SemaRef.Owned(E->Retain());
4211
Douglas Gregora16548e2009-08-11 05:31:07 +00004212 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4213 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004214 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004215 move(First),
4216 move(Second));
4217}
Mike Stump11289f42009-09-09 15:08:12 +00004218
Douglas Gregora16548e2009-08-11 05:31:07 +00004219template<typename Derived>
4220Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004221TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4222 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004223}
Mike Stump11289f42009-09-09 15:08:12 +00004224
Douglas Gregora16548e2009-08-11 05:31:07 +00004225template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004226Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004227TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004228 QualType ExplicitTy;
4229 {
4230 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004231 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004232 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4233 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004234
Douglas Gregora16548e2009-08-11 05:31:07 +00004235 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4236 if (ExplicitTy.isNull())
4237 return SemaRef.ExprError();
4238 }
Mike Stump11289f42009-09-09 15:08:12 +00004239
Douglas Gregor6131b442009-12-12 18:16:41 +00004240 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004241 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004242 if (SubExpr.isInvalid())
4243 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004244
Douglas Gregora16548e2009-08-11 05:31:07 +00004245 if (!getDerived().AlwaysRebuild() &&
4246 ExplicitTy == E->getTypeAsWritten() &&
4247 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004248 return SemaRef.Owned(E->Retain());
4249
Douglas Gregora16548e2009-08-11 05:31:07 +00004250 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004251 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004252 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4253 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4254 SourceLocation FakeRParenLoc
4255 = SemaRef.PP.getLocForEndOfToken(
4256 E->getSubExpr()->getSourceRange().getEnd());
4257 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004258 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004259 FakeLAngleLoc,
4260 ExplicitTy,
4261 FakeRAngleLoc,
4262 FakeRAngleLoc,
4263 move(SubExpr),
4264 FakeRParenLoc);
4265}
Mike Stump11289f42009-09-09 15:08:12 +00004266
Douglas Gregora16548e2009-08-11 05:31:07 +00004267template<typename Derived>
4268Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004269TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4270 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004271}
Mike Stump11289f42009-09-09 15:08:12 +00004272
4273template<typename Derived>
4274Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004275TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4276 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004277}
4278
Douglas Gregora16548e2009-08-11 05:31:07 +00004279template<typename Derived>
4280Sema::OwningExprResult
4281TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004282 CXXReinterpretCastExpr *E) {
4283 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004284}
Mike Stump11289f42009-09-09 15:08:12 +00004285
Douglas Gregora16548e2009-08-11 05:31:07 +00004286template<typename Derived>
4287Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004288TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4289 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004290}
Mike Stump11289f42009-09-09 15:08:12 +00004291
Douglas Gregora16548e2009-08-11 05:31:07 +00004292template<typename Derived>
4293Sema::OwningExprResult
4294TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004295 CXXFunctionalCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004296 QualType ExplicitTy;
4297 {
4298 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004299
Douglas Gregora16548e2009-08-11 05:31:07 +00004300 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4301 if (ExplicitTy.isNull())
4302 return SemaRef.ExprError();
4303 }
Mike Stump11289f42009-09-09 15:08:12 +00004304
Douglas Gregor6131b442009-12-12 18:16:41 +00004305 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004306 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004307 if (SubExpr.isInvalid())
4308 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004309
Douglas Gregora16548e2009-08-11 05:31:07 +00004310 if (!getDerived().AlwaysRebuild() &&
4311 ExplicitTy == E->getTypeAsWritten() &&
4312 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004313 return SemaRef.Owned(E->Retain());
4314
Douglas Gregora16548e2009-08-11 05:31:07 +00004315 // FIXME: The end of the type's source range is wrong
4316 return getDerived().RebuildCXXFunctionalCastExpr(
4317 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
4318 ExplicitTy,
4319 /*FIXME:*/E->getSubExpr()->getLocStart(),
4320 move(SubExpr),
4321 E->getRParenLoc());
4322}
Mike Stump11289f42009-09-09 15:08:12 +00004323
Douglas Gregora16548e2009-08-11 05:31:07 +00004324template<typename Derived>
4325Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004326TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004327 if (E->isTypeOperand()) {
4328 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004329
Douglas Gregora16548e2009-08-11 05:31:07 +00004330 QualType T = getDerived().TransformType(E->getTypeOperand());
4331 if (T.isNull())
4332 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004333
Douglas Gregora16548e2009-08-11 05:31:07 +00004334 if (!getDerived().AlwaysRebuild() &&
4335 T == E->getTypeOperand())
4336 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004337
Douglas Gregora16548e2009-08-11 05:31:07 +00004338 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4339 /*FIXME:*/E->getLocStart(),
4340 T,
4341 E->getLocEnd());
4342 }
Mike Stump11289f42009-09-09 15:08:12 +00004343
Douglas Gregora16548e2009-08-11 05:31:07 +00004344 // We don't know whether the expression is potentially evaluated until
4345 // after we perform semantic analysis, so the expression is potentially
4346 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004347 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004348 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004349
Douglas Gregora16548e2009-08-11 05:31:07 +00004350 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4351 if (SubExpr.isInvalid())
4352 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004353
Douglas Gregora16548e2009-08-11 05:31:07 +00004354 if (!getDerived().AlwaysRebuild() &&
4355 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004356 return SemaRef.Owned(E->Retain());
4357
Douglas Gregora16548e2009-08-11 05:31:07 +00004358 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4359 /*FIXME:*/E->getLocStart(),
4360 move(SubExpr),
4361 E->getLocEnd());
4362}
4363
4364template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004365Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004366TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004367 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004368}
Mike Stump11289f42009-09-09 15:08:12 +00004369
Douglas Gregora16548e2009-08-11 05:31:07 +00004370template<typename Derived>
4371Sema::OwningExprResult
4372TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004373 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004374 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004375}
Mike Stump11289f42009-09-09 15:08:12 +00004376
Douglas Gregora16548e2009-08-11 05:31:07 +00004377template<typename Derived>
4378Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004379TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004380 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004381
Douglas Gregora16548e2009-08-11 05:31:07 +00004382 QualType T = getDerived().TransformType(E->getType());
4383 if (T.isNull())
4384 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004385
Douglas Gregora16548e2009-08-11 05:31:07 +00004386 if (!getDerived().AlwaysRebuild() &&
4387 T == E->getType())
4388 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004389
Douglas Gregora16548e2009-08-11 05:31:07 +00004390 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T);
4391}
Mike Stump11289f42009-09-09 15:08:12 +00004392
Douglas Gregora16548e2009-08-11 05:31:07 +00004393template<typename Derived>
4394Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004395TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004396 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4397 if (SubExpr.isInvalid())
4398 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004399
Douglas Gregora16548e2009-08-11 05:31:07 +00004400 if (!getDerived().AlwaysRebuild() &&
4401 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004402 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004403
4404 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4405}
Mike Stump11289f42009-09-09 15:08:12 +00004406
Douglas Gregora16548e2009-08-11 05:31:07 +00004407template<typename Derived>
4408Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004409TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004410 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004411 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4412 if (!Param)
4413 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004414
Douglas Gregora16548e2009-08-11 05:31:07 +00004415 if (getDerived().AlwaysRebuild() &&
4416 Param == E->getParam())
4417 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004418
Douglas Gregora16548e2009-08-11 05:31:07 +00004419 return getDerived().RebuildCXXDefaultArgExpr(Param);
4420}
Mike Stump11289f42009-09-09 15:08:12 +00004421
Douglas Gregora16548e2009-08-11 05:31:07 +00004422template<typename Derived>
4423Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004424TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004425 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4426
4427 QualType T = getDerived().TransformType(E->getType());
4428 if (T.isNull())
4429 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004430
Douglas Gregora16548e2009-08-11 05:31:07 +00004431 if (!getDerived().AlwaysRebuild() &&
4432 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004433 return SemaRef.Owned(E->Retain());
4434
4435 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004436 /*FIXME:*/E->getTypeBeginLoc(),
4437 T,
4438 E->getRParenLoc());
4439}
Mike Stump11289f42009-09-09 15:08:12 +00004440
Douglas Gregora16548e2009-08-11 05:31:07 +00004441template<typename Derived>
4442Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004443TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004444 // Transform the type that we're allocating
4445 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4446 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4447 if (AllocType.isNull())
4448 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004449
Douglas Gregora16548e2009-08-11 05:31:07 +00004450 // Transform the size of the array we're allocating (if any).
4451 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4452 if (ArraySize.isInvalid())
4453 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004454
Douglas Gregora16548e2009-08-11 05:31:07 +00004455 // Transform the placement arguments (if any).
4456 bool ArgumentChanged = false;
4457 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4458 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4459 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4460 if (Arg.isInvalid())
4461 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004462
Douglas Gregora16548e2009-08-11 05:31:07 +00004463 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4464 PlacementArgs.push_back(Arg.take());
4465 }
Mike Stump11289f42009-09-09 15:08:12 +00004466
Douglas Gregorebe10102009-08-20 07:17:43 +00004467 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004468 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4469 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4470 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4471 if (Arg.isInvalid())
4472 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004473
Douglas Gregora16548e2009-08-11 05:31:07 +00004474 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4475 ConstructorArgs.push_back(Arg.take());
4476 }
Mike Stump11289f42009-09-09 15:08:12 +00004477
Douglas Gregora16548e2009-08-11 05:31:07 +00004478 if (!getDerived().AlwaysRebuild() &&
4479 AllocType == E->getAllocatedType() &&
4480 ArraySize.get() == E->getArraySize() &&
4481 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004482 return SemaRef.Owned(E->Retain());
4483
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004484 if (!ArraySize.get()) {
4485 // If no array size was specified, but the new expression was
4486 // instantiated with an array type (e.g., "new T" where T is
4487 // instantiated with "int[4]"), extract the outer bound from the
4488 // array type as our array size. We do this with constant and
4489 // dependently-sized array types.
4490 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4491 if (!ArrayT) {
4492 // Do nothing
4493 } else if (const ConstantArrayType *ConsArrayT
4494 = dyn_cast<ConstantArrayType>(ArrayT)) {
4495 ArraySize
4496 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4497 ConsArrayT->getSize(),
4498 SemaRef.Context.getSizeType(),
4499 /*FIXME:*/E->getLocStart()));
4500 AllocType = ConsArrayT->getElementType();
4501 } else if (const DependentSizedArrayType *DepArrayT
4502 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4503 if (DepArrayT->getSizeExpr()) {
4504 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4505 AllocType = DepArrayT->getElementType();
4506 }
4507 }
4508 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004509 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4510 E->isGlobalNew(),
4511 /*FIXME:*/E->getLocStart(),
4512 move_arg(PlacementArgs),
4513 /*FIXME:*/E->getLocStart(),
4514 E->isParenTypeId(),
4515 AllocType,
4516 /*FIXME:*/E->getLocStart(),
4517 /*FIXME:*/SourceRange(),
4518 move(ArraySize),
4519 /*FIXME:*/E->getLocStart(),
4520 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004521 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004522}
Mike Stump11289f42009-09-09 15:08:12 +00004523
Douglas Gregora16548e2009-08-11 05:31:07 +00004524template<typename Derived>
4525Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004526TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004527 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4528 if (Operand.isInvalid())
4529 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004530
Douglas Gregora16548e2009-08-11 05:31:07 +00004531 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004532 Operand.get() == E->getArgument())
4533 return SemaRef.Owned(E->Retain());
4534
Douglas Gregora16548e2009-08-11 05:31:07 +00004535 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4536 E->isGlobalDelete(),
4537 E->isArrayForm(),
4538 move(Operand));
4539}
Mike Stump11289f42009-09-09 15:08:12 +00004540
Douglas Gregora16548e2009-08-11 05:31:07 +00004541template<typename Derived>
4542Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004543TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004544 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004545 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4546 if (Base.isInvalid())
4547 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004548
Douglas Gregorad8a3362009-09-04 17:36:40 +00004549 NestedNameSpecifier *Qualifier
4550 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4551 E->getQualifierRange());
4552 if (E->getQualifier() && !Qualifier)
4553 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004554
Douglas Gregorad8a3362009-09-04 17:36:40 +00004555 QualType DestroyedType;
4556 {
4557 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4558 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4559 if (DestroyedType.isNull())
4560 return SemaRef.ExprError();
4561 }
Mike Stump11289f42009-09-09 15:08:12 +00004562
Douglas Gregorad8a3362009-09-04 17:36:40 +00004563 if (!getDerived().AlwaysRebuild() &&
4564 Base.get() == E->getBase() &&
4565 Qualifier == E->getQualifier() &&
4566 DestroyedType == E->getDestroyedType())
4567 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004568
Douglas Gregorad8a3362009-09-04 17:36:40 +00004569 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4570 E->getOperatorLoc(),
4571 E->isArrow(),
4572 E->getDestroyedTypeLoc(),
4573 DestroyedType,
4574 Qualifier,
4575 E->getQualifierRange());
4576}
Mike Stump11289f42009-09-09 15:08:12 +00004577
Douglas Gregorad8a3362009-09-04 17:36:40 +00004578template<typename Derived>
4579Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004580TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004581 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00004582 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4583
4584 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4585 Sema::LookupOrdinaryName);
4586
4587 // Transform all the decls.
4588 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4589 E = Old->decls_end(); I != E; ++I) {
4590 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00004591 if (!InstD) {
4592 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4593 // This can happen because of dependent hiding.
4594 if (isa<UsingShadowDecl>(*I))
4595 continue;
4596 else
4597 return SemaRef.ExprError();
4598 }
John McCalle66edc12009-11-24 19:00:30 +00004599
4600 // Expand using declarations.
4601 if (isa<UsingDecl>(InstD)) {
4602 UsingDecl *UD = cast<UsingDecl>(InstD);
4603 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4604 E = UD->shadow_end(); I != E; ++I)
4605 R.addDecl(*I);
4606 continue;
4607 }
4608
4609 R.addDecl(InstD);
4610 }
4611
4612 // Resolve a kind, but don't do any further analysis. If it's
4613 // ambiguous, the callee needs to deal with it.
4614 R.resolveKind();
4615
4616 // Rebuild the nested-name qualifier, if present.
4617 CXXScopeSpec SS;
4618 NestedNameSpecifier *Qualifier = 0;
4619 if (Old->getQualifier()) {
4620 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4621 Old->getQualifierRange());
4622 if (!Qualifier)
4623 return SemaRef.ExprError();
4624
4625 SS.setScopeRep(Qualifier);
4626 SS.setRange(Old->getQualifierRange());
4627 }
4628
4629 // If we have no template arguments, it's a normal declaration name.
4630 if (!Old->hasExplicitTemplateArgs())
4631 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4632
4633 // If we have template arguments, rebuild them, then rebuild the
4634 // templateid expression.
4635 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4636 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4637 TemplateArgumentLoc Loc;
4638 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4639 return SemaRef.ExprError();
4640 TransArgs.addArgument(Loc);
4641 }
4642
4643 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4644 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004645}
Mike Stump11289f42009-09-09 15:08:12 +00004646
Douglas Gregora16548e2009-08-11 05:31:07 +00004647template<typename Derived>
4648Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004649TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004650 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004651
Douglas Gregora16548e2009-08-11 05:31:07 +00004652 QualType T = getDerived().TransformType(E->getQueriedType());
4653 if (T.isNull())
4654 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004655
Douglas Gregora16548e2009-08-11 05:31:07 +00004656 if (!getDerived().AlwaysRebuild() &&
4657 T == E->getQueriedType())
4658 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004659
Douglas Gregora16548e2009-08-11 05:31:07 +00004660 // FIXME: Bad location information
4661 SourceLocation FakeLParenLoc
4662 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004663
4664 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004665 E->getLocStart(),
4666 /*FIXME:*/FakeLParenLoc,
4667 T,
4668 E->getLocEnd());
4669}
Mike Stump11289f42009-09-09 15:08:12 +00004670
Douglas Gregora16548e2009-08-11 05:31:07 +00004671template<typename Derived>
4672Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004673TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004674 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004675 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004676 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4677 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004678 if (!NNS)
4679 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004680
4681 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004682 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4683 if (!Name)
4684 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004685
John McCalle66edc12009-11-24 19:00:30 +00004686 if (!E->hasExplicitTemplateArgs()) {
4687 if (!getDerived().AlwaysRebuild() &&
4688 NNS == E->getQualifier() &&
4689 Name == E->getDeclName())
4690 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004691
John McCalle66edc12009-11-24 19:00:30 +00004692 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4693 E->getQualifierRange(),
4694 Name, E->getLocation(),
4695 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004696 }
John McCall6b51f282009-11-23 01:53:49 +00004697
4698 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004699 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004700 TemplateArgumentLoc Loc;
4701 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004702 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004703 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004704 }
4705
John McCalle66edc12009-11-24 19:00:30 +00004706 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4707 E->getQualifierRange(),
4708 Name, E->getLocation(),
4709 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004710}
4711
4712template<typename Derived>
4713Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004714TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004715 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4716
4717 QualType T = getDerived().TransformType(E->getType());
4718 if (T.isNull())
4719 return SemaRef.ExprError();
4720
4721 CXXConstructorDecl *Constructor
4722 = cast_or_null<CXXConstructorDecl>(
4723 getDerived().TransformDecl(E->getConstructor()));
4724 if (!Constructor)
4725 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004726
Douglas Gregora16548e2009-08-11 05:31:07 +00004727 bool ArgumentChanged = false;
4728 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004729 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004730 ArgEnd = E->arg_end();
4731 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00004732 if (getDerived().DropCallArgument(*Arg)) {
4733 ArgumentChanged = true;
4734 break;
4735 }
4736
Douglas Gregora16548e2009-08-11 05:31:07 +00004737 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4738 if (TransArg.isInvalid())
4739 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004740
Douglas Gregora16548e2009-08-11 05:31:07 +00004741 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4742 Args.push_back(TransArg.takeAs<Expr>());
4743 }
4744
4745 if (!getDerived().AlwaysRebuild() &&
4746 T == E->getType() &&
4747 Constructor == E->getConstructor() &&
4748 !ArgumentChanged)
4749 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004750
Douglas Gregordb121ba2009-12-14 16:27:04 +00004751 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
4752 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004753 move_arg(Args));
4754}
Mike Stump11289f42009-09-09 15:08:12 +00004755
Douglas Gregora16548e2009-08-11 05:31:07 +00004756/// \brief Transform a C++ temporary-binding expression.
4757///
Mike Stump11289f42009-09-09 15:08:12 +00004758/// The transformation of a temporary-binding expression always attempts to
4759/// bind a new temporary variable to its subexpression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004760/// subexpression itself did not change, because the temporary variable itself
4761/// must be unique.
4762template<typename Derived>
4763Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004764TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004765 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4766 if (SubExpr.isInvalid())
4767 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004768
Douglas Gregora16548e2009-08-11 05:31:07 +00004769 return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>());
4770}
Mike Stump11289f42009-09-09 15:08:12 +00004771
4772/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004773/// be destroyed after the expression is evaluated.
4774///
Mike Stump11289f42009-09-09 15:08:12 +00004775/// The transformation of a full expression always attempts to build a new
4776/// CXXExprWithTemporaries expression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004777/// subexpression itself did not change, because it will need to capture the
4778/// the new temporary variables introduced in the subexpression.
4779template<typename Derived>
4780Sema::OwningExprResult
4781TreeTransform<Derived>::TransformCXXExprWithTemporaries(
John McCall47f29ea2009-12-08 09:21:05 +00004782 CXXExprWithTemporaries *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004783 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4784 if (SubExpr.isInvalid())
4785 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004786
Douglas Gregora16548e2009-08-11 05:31:07 +00004787 return SemaRef.Owned(
Anders Carlsson6e997b22009-12-15 20:51:39 +00004788 SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004789}
Mike Stump11289f42009-09-09 15:08:12 +00004790
Douglas Gregora16548e2009-08-11 05:31:07 +00004791template<typename Derived>
4792Sema::OwningExprResult
4793TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004794 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004795 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4796 QualType T = getDerived().TransformType(E->getType());
4797 if (T.isNull())
4798 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004799
Douglas Gregora16548e2009-08-11 05:31:07 +00004800 CXXConstructorDecl *Constructor
4801 = cast_or_null<CXXConstructorDecl>(
4802 getDerived().TransformDecl(E->getConstructor()));
4803 if (!Constructor)
4804 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004805
Douglas Gregora16548e2009-08-11 05:31:07 +00004806 bool ArgumentChanged = false;
4807 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4808 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004809 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004810 ArgEnd = E->arg_end();
4811 Arg != ArgEnd; ++Arg) {
4812 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4813 if (TransArg.isInvalid())
4814 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004815
Douglas Gregora16548e2009-08-11 05:31:07 +00004816 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4817 Args.push_back((Expr *)TransArg.release());
4818 }
Mike Stump11289f42009-09-09 15:08:12 +00004819
Douglas Gregora16548e2009-08-11 05:31:07 +00004820 if (!getDerived().AlwaysRebuild() &&
4821 T == E->getType() &&
4822 Constructor == E->getConstructor() &&
4823 !ArgumentChanged)
4824 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004825
Douglas Gregora16548e2009-08-11 05:31:07 +00004826 // FIXME: Bogus location information
4827 SourceLocation CommaLoc;
4828 if (Args.size() > 1) {
4829 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004830 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004831 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4832 }
4833 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4834 T,
4835 /*FIXME:*/E->getTypeBeginLoc(),
4836 move_arg(Args),
4837 &CommaLoc,
4838 E->getLocEnd());
4839}
Mike Stump11289f42009-09-09 15:08:12 +00004840
Douglas Gregora16548e2009-08-11 05:31:07 +00004841template<typename Derived>
4842Sema::OwningExprResult
4843TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004844 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004845 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4846 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4847 if (T.isNull())
4848 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004849
Douglas Gregora16548e2009-08-11 05:31:07 +00004850 bool ArgumentChanged = false;
4851 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4852 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4853 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4854 ArgEnd = E->arg_end();
4855 Arg != ArgEnd; ++Arg) {
4856 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4857 if (TransArg.isInvalid())
4858 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004859
Douglas Gregora16548e2009-08-11 05:31:07 +00004860 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4861 FakeCommaLocs.push_back(
4862 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4863 Args.push_back(TransArg.takeAs<Expr>());
4864 }
Mike Stump11289f42009-09-09 15:08:12 +00004865
Douglas Gregora16548e2009-08-11 05:31:07 +00004866 if (!getDerived().AlwaysRebuild() &&
4867 T == E->getTypeAsWritten() &&
4868 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004869 return SemaRef.Owned(E->Retain());
4870
Douglas Gregora16548e2009-08-11 05:31:07 +00004871 // FIXME: we're faking the locations of the commas
4872 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4873 T,
4874 E->getLParenLoc(),
4875 move_arg(Args),
4876 FakeCommaLocs.data(),
4877 E->getRParenLoc());
4878}
Mike Stump11289f42009-09-09 15:08:12 +00004879
Douglas Gregora16548e2009-08-11 05:31:07 +00004880template<typename Derived>
4881Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004882TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004883 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004884 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004885 OwningExprResult Base(SemaRef, (Expr*) 0);
4886 Expr *OldBase;
4887 QualType BaseType;
4888 QualType ObjectType;
4889 if (!E->isImplicitAccess()) {
4890 OldBase = E->getBase();
4891 Base = getDerived().TransformExpr(OldBase);
4892 if (Base.isInvalid())
4893 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004894
John McCall2d74de92009-12-01 22:10:20 +00004895 // Start the member reference and compute the object's type.
4896 Sema::TypeTy *ObjectTy = 0;
4897 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4898 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004899 E->isArrow()? tok::arrow : tok::period,
John McCall2d74de92009-12-01 22:10:20 +00004900 ObjectTy);
4901 if (Base.isInvalid())
4902 return SemaRef.ExprError();
4903
4904 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
4905 BaseType = ((Expr*) Base.get())->getType();
4906 } else {
4907 OldBase = 0;
4908 BaseType = getDerived().TransformType(E->getBaseType());
4909 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
4910 }
Mike Stump11289f42009-09-09 15:08:12 +00004911
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004912 // Transform the first part of the nested-name-specifier that qualifies
4913 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004914 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004915 = getDerived().TransformFirstQualifierInScope(
4916 E->getFirstQualifierFoundInScope(),
4917 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00004918
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004919 NestedNameSpecifier *Qualifier = 0;
4920 if (E->getQualifier()) {
4921 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4922 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00004923 ObjectType,
4924 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004925 if (!Qualifier)
4926 return SemaRef.ExprError();
4927 }
Mike Stump11289f42009-09-09 15:08:12 +00004928
4929 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00004930 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00004931 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00004932 if (!Name)
4933 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004934
John McCall2d74de92009-12-01 22:10:20 +00004935 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00004936 // This is a reference to a member without an explicitly-specified
4937 // template argument list. Optimize for this common case.
4938 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00004939 Base.get() == OldBase &&
4940 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00004941 Qualifier == E->getQualifier() &&
4942 Name == E->getMember() &&
4943 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00004944 return SemaRef.Owned(E->Retain());
4945
John McCall8cd78132009-11-19 22:55:06 +00004946 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00004947 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00004948 E->isArrow(),
4949 E->getOperatorLoc(),
4950 Qualifier,
4951 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00004952 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00004953 Name,
4954 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00004955 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00004956 }
4957
John McCall6b51f282009-11-23 01:53:49 +00004958 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00004959 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004960 TemplateArgumentLoc Loc;
4961 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00004962 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004963 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00004964 }
Mike Stump11289f42009-09-09 15:08:12 +00004965
John McCall8cd78132009-11-19 22:55:06 +00004966 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00004967 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00004968 E->isArrow(),
4969 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004970 Qualifier,
4971 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004972 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00004973 Name,
4974 E->getMemberLoc(),
4975 &TransArgs);
4976}
4977
4978template<typename Derived>
4979Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004980TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00004981 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004982 OwningExprResult Base(SemaRef, (Expr*) 0);
4983 QualType BaseType;
4984 if (!Old->isImplicitAccess()) {
4985 Base = getDerived().TransformExpr(Old->getBase());
4986 if (Base.isInvalid())
4987 return SemaRef.ExprError();
4988 BaseType = ((Expr*) Base.get())->getType();
4989 } else {
4990 BaseType = getDerived().TransformType(Old->getBaseType());
4991 }
John McCall10eae182009-11-30 22:42:35 +00004992
4993 NestedNameSpecifier *Qualifier = 0;
4994 if (Old->getQualifier()) {
4995 Qualifier
4996 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4997 Old->getQualifierRange());
4998 if (Qualifier == 0)
4999 return SemaRef.ExprError();
5000 }
5001
5002 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5003 Sema::LookupOrdinaryName);
5004
5005 // Transform all the decls.
5006 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5007 E = Old->decls_end(); I != E; ++I) {
5008 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00005009 if (!InstD) {
5010 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5011 // This can happen because of dependent hiding.
5012 if (isa<UsingShadowDecl>(*I))
5013 continue;
5014 else
5015 return SemaRef.ExprError();
5016 }
John McCall10eae182009-11-30 22:42:35 +00005017
5018 // Expand using declarations.
5019 if (isa<UsingDecl>(InstD)) {
5020 UsingDecl *UD = cast<UsingDecl>(InstD);
5021 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5022 E = UD->shadow_end(); I != E; ++I)
5023 R.addDecl(*I);
5024 continue;
5025 }
5026
5027 R.addDecl(InstD);
5028 }
5029
5030 R.resolveKind();
5031
5032 TemplateArgumentListInfo TransArgs;
5033 if (Old->hasExplicitTemplateArgs()) {
5034 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5035 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5036 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5037 TemplateArgumentLoc Loc;
5038 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5039 Loc))
5040 return SemaRef.ExprError();
5041 TransArgs.addArgument(Loc);
5042 }
5043 }
5044
5045 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005046 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005047 Old->getOperatorLoc(),
5048 Old->isArrow(),
5049 Qualifier,
5050 Old->getQualifierRange(),
5051 R,
5052 (Old->hasExplicitTemplateArgs()
5053 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005054}
5055
5056template<typename Derived>
5057Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005058TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005059 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005060}
5061
Mike Stump11289f42009-09-09 15:08:12 +00005062template<typename Derived>
5063Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005064TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005065 // FIXME: poor source location
5066 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5067 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5068 if (EncodedType.isNull())
5069 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005070
Douglas Gregora16548e2009-08-11 05:31:07 +00005071 if (!getDerived().AlwaysRebuild() &&
5072 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00005073 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005074
5075 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5076 EncodedType,
5077 E->getRParenLoc());
5078}
Mike Stump11289f42009-09-09 15:08:12 +00005079
Douglas Gregora16548e2009-08-11 05:31:07 +00005080template<typename Derived>
5081Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005082TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005083 // FIXME: Implement this!
5084 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005085 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005086}
5087
Mike Stump11289f42009-09-09 15:08:12 +00005088template<typename Derived>
5089Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005090TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005091 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005092}
5093
Mike Stump11289f42009-09-09 15:08:12 +00005094template<typename Derived>
5095Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005096TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005097 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00005098 = cast_or_null<ObjCProtocolDecl>(
5099 getDerived().TransformDecl(E->getProtocol()));
5100 if (!Protocol)
5101 return SemaRef.ExprError();
5102
5103 if (!getDerived().AlwaysRebuild() &&
5104 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005105 return SemaRef.Owned(E->Retain());
5106
Douglas Gregora16548e2009-08-11 05:31:07 +00005107 return getDerived().RebuildObjCProtocolExpr(Protocol,
5108 E->getAtLoc(),
5109 /*FIXME:*/E->getAtLoc(),
5110 /*FIXME:*/E->getAtLoc(),
5111 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005112
Douglas Gregora16548e2009-08-11 05:31:07 +00005113}
5114
Mike Stump11289f42009-09-09 15:08:12 +00005115template<typename Derived>
5116Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005117TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005118 // FIXME: Implement this!
5119 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005120 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005121}
5122
Mike Stump11289f42009-09-09 15:08:12 +00005123template<typename Derived>
5124Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005125TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005126 // FIXME: Implement this!
5127 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005128 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005129}
5130
Mike Stump11289f42009-09-09 15:08:12 +00005131template<typename Derived>
5132Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005133TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005134 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005135 // FIXME: Implement this!
5136 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005137 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005138}
5139
Mike Stump11289f42009-09-09 15:08:12 +00005140template<typename Derived>
5141Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005142TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005143 // FIXME: Implement this!
5144 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005145 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005146}
5147
Mike Stump11289f42009-09-09 15:08:12 +00005148template<typename Derived>
5149Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005150TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005151 // FIXME: Implement this!
5152 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005153 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005154}
5155
Mike Stump11289f42009-09-09 15:08:12 +00005156template<typename Derived>
5157Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005158TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005159 bool ArgumentChanged = false;
5160 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5161 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5162 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5163 if (SubExpr.isInvalid())
5164 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005165
Douglas Gregora16548e2009-08-11 05:31:07 +00005166 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5167 SubExprs.push_back(SubExpr.takeAs<Expr>());
5168 }
Mike Stump11289f42009-09-09 15:08:12 +00005169
Douglas Gregora16548e2009-08-11 05:31:07 +00005170 if (!getDerived().AlwaysRebuild() &&
5171 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005172 return SemaRef.Owned(E->Retain());
5173
Douglas Gregora16548e2009-08-11 05:31:07 +00005174 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5175 move_arg(SubExprs),
5176 E->getRParenLoc());
5177}
5178
Mike Stump11289f42009-09-09 15:08:12 +00005179template<typename Derived>
5180Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005181TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005182 // FIXME: Implement this!
5183 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005184 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005185}
5186
Mike Stump11289f42009-09-09 15:08:12 +00005187template<typename Derived>
5188Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005189TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005190 // FIXME: Implement this!
5191 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005192 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005193}
Mike Stump11289f42009-09-09 15:08:12 +00005194
Douglas Gregora16548e2009-08-11 05:31:07 +00005195//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005196// Type reconstruction
5197//===----------------------------------------------------------------------===//
5198
Mike Stump11289f42009-09-09 15:08:12 +00005199template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005200QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5201 SourceLocation Star) {
5202 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005203 getDerived().getBaseEntity());
5204}
5205
Mike Stump11289f42009-09-09 15:08:12 +00005206template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005207QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5208 SourceLocation Star) {
5209 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005210 getDerived().getBaseEntity());
5211}
5212
Mike Stump11289f42009-09-09 15:08:12 +00005213template<typename Derived>
5214QualType
John McCall70dd5f62009-10-30 00:06:24 +00005215TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5216 bool WrittenAsLValue,
5217 SourceLocation Sigil) {
5218 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5219 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005220}
5221
5222template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005223QualType
John McCall70dd5f62009-10-30 00:06:24 +00005224TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5225 QualType ClassType,
5226 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005227 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005228 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005229}
5230
5231template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005232QualType
John McCall70dd5f62009-10-30 00:06:24 +00005233TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5234 SourceLocation Sigil) {
5235 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005236 getDerived().getBaseEntity());
5237}
5238
5239template<typename Derived>
5240QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005241TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5242 ArrayType::ArraySizeModifier SizeMod,
5243 const llvm::APInt *Size,
5244 Expr *SizeExpr,
5245 unsigned IndexTypeQuals,
5246 SourceRange BracketsRange) {
5247 if (SizeExpr || !Size)
5248 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5249 IndexTypeQuals, BracketsRange,
5250 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005251
5252 QualType Types[] = {
5253 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5254 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5255 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005256 };
5257 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5258 QualType SizeType;
5259 for (unsigned I = 0; I != NumTypes; ++I)
5260 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5261 SizeType = Types[I];
5262 break;
5263 }
Mike Stump11289f42009-09-09 15:08:12 +00005264
Douglas Gregord6ff3322009-08-04 16:50:30 +00005265 if (SizeType.isNull())
5266 SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false);
Mike Stump11289f42009-09-09 15:08:12 +00005267
Douglas Gregord6ff3322009-08-04 16:50:30 +00005268 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005269 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005270 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005271 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005272}
Mike Stump11289f42009-09-09 15:08:12 +00005273
Douglas Gregord6ff3322009-08-04 16:50:30 +00005274template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005275QualType
5276TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005277 ArrayType::ArraySizeModifier SizeMod,
5278 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005279 unsigned IndexTypeQuals,
5280 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005281 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005282 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005283}
5284
5285template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005286QualType
Mike Stump11289f42009-09-09 15:08:12 +00005287TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005288 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005289 unsigned IndexTypeQuals,
5290 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005291 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005292 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005293}
Mike Stump11289f42009-09-09 15:08:12 +00005294
Douglas Gregord6ff3322009-08-04 16:50:30 +00005295template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005296QualType
5297TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005298 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005299 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005300 unsigned IndexTypeQuals,
5301 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005302 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005303 SizeExpr.takeAs<Expr>(),
5304 IndexTypeQuals, BracketsRange);
5305}
5306
5307template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005308QualType
5309TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005310 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005311 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005312 unsigned IndexTypeQuals,
5313 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005314 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005315 SizeExpr.takeAs<Expr>(),
5316 IndexTypeQuals, BracketsRange);
5317}
5318
5319template<typename Derived>
5320QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
5321 unsigned NumElements) {
5322 // FIXME: semantic checking!
5323 return SemaRef.Context.getVectorType(ElementType, NumElements);
5324}
Mike Stump11289f42009-09-09 15:08:12 +00005325
Douglas Gregord6ff3322009-08-04 16:50:30 +00005326template<typename Derived>
5327QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5328 unsigned NumElements,
5329 SourceLocation AttributeLoc) {
5330 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5331 NumElements, true);
5332 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005333 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005334 AttributeLoc);
5335 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5336 AttributeLoc);
5337}
Mike Stump11289f42009-09-09 15:08:12 +00005338
Douglas Gregord6ff3322009-08-04 16:50:30 +00005339template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005340QualType
5341TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005342 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005343 SourceLocation AttributeLoc) {
5344 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5345}
Mike Stump11289f42009-09-09 15:08:12 +00005346
Douglas Gregord6ff3322009-08-04 16:50:30 +00005347template<typename Derived>
5348QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005349 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005350 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005351 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005352 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005353 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005354 Quals,
5355 getDerived().getBaseLocation(),
5356 getDerived().getBaseEntity());
5357}
Mike Stump11289f42009-09-09 15:08:12 +00005358
Douglas Gregord6ff3322009-08-04 16:50:30 +00005359template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005360QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5361 return SemaRef.Context.getFunctionNoProtoType(T);
5362}
5363
5364template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005365QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5366 assert(D && "no decl found");
5367 if (D->isInvalidDecl()) return QualType();
5368
5369 TypeDecl *Ty;
5370 if (isa<UsingDecl>(D)) {
5371 UsingDecl *Using = cast<UsingDecl>(D);
5372 assert(Using->isTypeName() &&
5373 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5374
5375 // A valid resolved using typename decl points to exactly one type decl.
5376 assert(++Using->shadow_begin() == Using->shadow_end());
5377 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5378
5379 } else {
5380 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5381 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5382 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5383 }
5384
5385 return SemaRef.Context.getTypeDeclType(Ty);
5386}
5387
5388template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005389QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005390 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5391}
5392
5393template<typename Derived>
5394QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5395 return SemaRef.Context.getTypeOfType(Underlying);
5396}
5397
5398template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005399QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005400 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5401}
5402
5403template<typename Derived>
5404QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005405 TemplateName Template,
5406 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005407 const TemplateArgumentListInfo &TemplateArgs) {
5408 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005409}
Mike Stump11289f42009-09-09 15:08:12 +00005410
Douglas Gregor1135c352009-08-06 05:28:30 +00005411template<typename Derived>
5412NestedNameSpecifier *
5413TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5414 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005415 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005416 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005417 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005418 CXXScopeSpec SS;
5419 // FIXME: The source location information is all wrong.
5420 SS.setRange(Range);
5421 SS.setScopeRep(Prefix);
5422 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005423 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005424 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005425 ObjectType,
5426 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005427 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005428}
5429
5430template<typename Derived>
5431NestedNameSpecifier *
5432TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5433 SourceRange Range,
5434 NamespaceDecl *NS) {
5435 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5436}
5437
5438template<typename Derived>
5439NestedNameSpecifier *
5440TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5441 SourceRange Range,
5442 bool TemplateKW,
5443 QualType T) {
5444 if (T->isDependentType() || T->isRecordType() ||
5445 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005446 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005447 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5448 T.getTypePtr());
5449 }
Mike Stump11289f42009-09-09 15:08:12 +00005450
Douglas Gregor1135c352009-08-06 05:28:30 +00005451 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5452 return 0;
5453}
Mike Stump11289f42009-09-09 15:08:12 +00005454
Douglas Gregor71dc5092009-08-06 06:41:21 +00005455template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005456TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005457TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5458 bool TemplateKW,
5459 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005460 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005461 Template);
5462}
5463
5464template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005465TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005466TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005467 const IdentifierInfo &II,
5468 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005469 CXXScopeSpec SS;
5470 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005471 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005472 UnqualifiedId Name;
5473 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005474 return getSema().ActOnDependentTemplateName(
5475 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005476 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005477 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005478 ObjectType.getAsOpaquePtr(),
5479 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005480 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005481}
Mike Stump11289f42009-09-09 15:08:12 +00005482
Douglas Gregora16548e2009-08-11 05:31:07 +00005483template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005484TemplateName
5485TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5486 OverloadedOperatorKind Operator,
5487 QualType ObjectType) {
5488 CXXScopeSpec SS;
5489 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5490 SS.setScopeRep(Qualifier);
5491 UnqualifiedId Name;
5492 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5493 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5494 Operator, SymbolLocations);
5495 return getSema().ActOnDependentTemplateName(
5496 /*FIXME:*/getDerived().getBaseLocation(),
5497 SS,
5498 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005499 ObjectType.getAsOpaquePtr(),
5500 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005501 .template getAsVal<TemplateName>();
5502}
5503
5504template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005505Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005506TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5507 SourceLocation OpLoc,
5508 ExprArg Callee,
5509 ExprArg First,
5510 ExprArg Second) {
5511 Expr *FirstExpr = (Expr *)First.get();
5512 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005513 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005514 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005515
Douglas Gregora16548e2009-08-11 05:31:07 +00005516 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005517 if (Op == OO_Subscript) {
5518 if (!FirstExpr->getType()->isOverloadableType() &&
5519 !SecondExpr->getType()->isOverloadableType())
5520 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005521 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005522 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005523 } else if (Op == OO_Arrow) {
5524 // -> is never a builtin operation.
5525 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005526 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005527 if (!FirstExpr->getType()->isOverloadableType()) {
5528 // The argument is not of overloadable type, so try to create a
5529 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005530 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005531 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005532
Douglas Gregora16548e2009-08-11 05:31:07 +00005533 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5534 }
5535 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005536 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005537 !SecondExpr->getType()->isOverloadableType()) {
5538 // Neither of the arguments is an overloadable type, so try to
5539 // create a built-in binary operation.
5540 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005541 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005542 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5543 if (Result.isInvalid())
5544 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005545
Douglas Gregora16548e2009-08-11 05:31:07 +00005546 First.release();
5547 Second.release();
5548 return move(Result);
5549 }
5550 }
Mike Stump11289f42009-09-09 15:08:12 +00005551
5552 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005553 // used during overload resolution.
5554 Sema::FunctionSet Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005555
John McCalld14a8642009-11-21 08:51:07 +00005556 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5557 assert(ULE->requiresADL());
5558
5559 // FIXME: Do we have to check
5560 // IsAcceptableNonMemberOperatorCandidate for each of these?
5561 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(),
5562 E = ULE->decls_end(); I != E; ++I)
5563 Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I));
5564 } else {
5565 Functions.insert(AnyFunctionDecl::getFromNamedDecl(
5566 cast<DeclRefExpr>(CalleeExpr)->getDecl()));
5567 }
Mike Stump11289f42009-09-09 15:08:12 +00005568
Douglas Gregora16548e2009-08-11 05:31:07 +00005569 // Add any functions found via argument-dependent lookup.
5570 Expr *Args[2] = { FirstExpr, SecondExpr };
5571 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005572 DeclarationName OpName
Douglas Gregora16548e2009-08-11 05:31:07 +00005573 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
Sebastian Redlc057f422009-10-23 19:23:15 +00005574 SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs,
5575 Functions);
Mike Stump11289f42009-09-09 15:08:12 +00005576
Douglas Gregora16548e2009-08-11 05:31:07 +00005577 // Create the overloaded operator invocation for unary operators.
5578 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005579 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005580 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5581 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5582 }
Mike Stump11289f42009-09-09 15:08:12 +00005583
Sebastian Redladba46e2009-10-29 20:17:01 +00005584 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005585 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5586 OpLoc,
5587 move(First),
5588 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005589
Douglas Gregora16548e2009-08-11 05:31:07 +00005590 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005591 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005592 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005593 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005594 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5595 if (Result.isInvalid())
5596 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005597
Douglas Gregora16548e2009-08-11 05:31:07 +00005598 First.release();
5599 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005600 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005601}
Mike Stump11289f42009-09-09 15:08:12 +00005602
Douglas Gregord6ff3322009-08-04 16:50:30 +00005603} // end namespace clang
5604
5605#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H