blob: cc5722297fc42d11ecab42bdac7b9a4f79ecd25e [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
Douglas Gregor07eae022009-11-13 18:34:26 +00001658 return getSema().ActOnExprStmt(getSema().FullExpr(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
Douglas Gregorebe10102009-08-20 07:17:43 +00003070 Sema::FullExprArg FullCond(getSema().FullExpr(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
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003113 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
3114
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
Douglas Gregorebe10102009-08-20 07:17:43 +00003150 Sema::FullExprArg FullCond(getSema().FullExpr(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(),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003232 move(Init), getSema().FullExpr(Cond),
3233 ConditionVar,
3234 getSema().FullExpr(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() &&
3691 !E->hasExplicitTemplateArgumentList())
Mike Stump11289f42009-09-09 15:08:12 +00003692 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003693
John McCall6b51f282009-11-23 01:53:49 +00003694 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003695 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003696 TransArgs.setLAngleLoc(E->getLAngleLoc());
3697 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003698 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003699 TemplateArgumentLoc Loc;
3700 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003701 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003702 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003703 }
3704 }
3705
Douglas Gregora16548e2009-08-11 05:31:07 +00003706 // FIXME: Bogus source location for the operator
3707 SourceLocation FakeOperatorLoc
3708 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3709
3710 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3711 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003712 Qualifier,
3713 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003714 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003715 Member,
John McCall6b51f282009-11-23 01:53:49 +00003716 (E->hasExplicitTemplateArgumentList()
3717 ? &TransArgs : 0),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003718 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00003719}
Mike Stump11289f42009-09-09 15:08:12 +00003720
Douglas Gregora16548e2009-08-11 05:31:07 +00003721template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003722Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003723TreeTransform<Derived>::TransformCastExpr(CastExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003724 assert(false && "Cannot transform abstract class");
3725 return SemaRef.Owned(E->Retain());
3726}
3727
3728template<typename Derived>
3729Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003730TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003731 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3732 if (LHS.isInvalid())
3733 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003734
Douglas Gregora16548e2009-08-11 05:31:07 +00003735 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3736 if (RHS.isInvalid())
3737 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003738
Douglas Gregora16548e2009-08-11 05:31:07 +00003739 if (!getDerived().AlwaysRebuild() &&
3740 LHS.get() == E->getLHS() &&
3741 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003742 return SemaRef.Owned(E->Retain());
3743
Douglas Gregora16548e2009-08-11 05:31:07 +00003744 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3745 move(LHS), move(RHS));
3746}
3747
Mike Stump11289f42009-09-09 15:08:12 +00003748template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003749Sema::OwningExprResult
3750TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00003751 CompoundAssignOperator *E) {
3752 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00003753}
Mike Stump11289f42009-09-09 15:08:12 +00003754
Douglas Gregora16548e2009-08-11 05:31:07 +00003755template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003756Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003757TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003758 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3759 if (Cond.isInvalid())
3760 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003761
Douglas Gregora16548e2009-08-11 05:31:07 +00003762 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3763 if (LHS.isInvalid())
3764 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003765
Douglas Gregora16548e2009-08-11 05:31:07 +00003766 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3767 if (RHS.isInvalid())
3768 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003769
Douglas Gregora16548e2009-08-11 05:31:07 +00003770 if (!getDerived().AlwaysRebuild() &&
3771 Cond.get() == E->getCond() &&
3772 LHS.get() == E->getLHS() &&
3773 RHS.get() == E->getRHS())
3774 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003775
3776 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003777 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003778 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003779 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003780 move(RHS));
3781}
Mike Stump11289f42009-09-09 15:08:12 +00003782
3783template<typename Derived>
3784Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003785TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00003786 // Implicit casts are eliminated during transformation, since they
3787 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00003788 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003789}
Mike Stump11289f42009-09-09 15:08:12 +00003790
Douglas Gregora16548e2009-08-11 05:31:07 +00003791template<typename Derived>
3792Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003793TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003794 assert(false && "Cannot transform abstract class");
3795 return SemaRef.Owned(E->Retain());
3796}
3797
3798template<typename Derived>
3799Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003800TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003801 QualType T;
3802 {
3803 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003804 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003805 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3806 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003807
Douglas Gregora16548e2009-08-11 05:31:07 +00003808 T = getDerived().TransformType(E->getTypeAsWritten());
3809 if (T.isNull())
3810 return SemaRef.ExprError();
3811 }
Mike Stump11289f42009-09-09 15:08:12 +00003812
Douglas Gregor6131b442009-12-12 18:16:41 +00003813 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00003814 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003815 if (SubExpr.isInvalid())
3816 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003817
Douglas Gregora16548e2009-08-11 05:31:07 +00003818 if (!getDerived().AlwaysRebuild() &&
3819 T == E->getTypeAsWritten() &&
3820 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003821 return SemaRef.Owned(E->Retain());
3822
Douglas Gregora16548e2009-08-11 05:31:07 +00003823 return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T,
3824 E->getRParenLoc(),
3825 move(SubExpr));
3826}
Mike Stump11289f42009-09-09 15:08:12 +00003827
Douglas Gregora16548e2009-08-11 05:31:07 +00003828template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003829Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003830TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003831 QualType T;
3832 {
3833 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003834 SourceLocation FakeTypeLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003835 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3836 TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003837
Douglas Gregora16548e2009-08-11 05:31:07 +00003838 T = getDerived().TransformType(E->getType());
3839 if (T.isNull())
3840 return SemaRef.ExprError();
3841 }
Mike Stump11289f42009-09-09 15:08:12 +00003842
Douglas Gregora16548e2009-08-11 05:31:07 +00003843 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3844 if (Init.isInvalid())
3845 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003846
Douglas Gregora16548e2009-08-11 05:31:07 +00003847 if (!getDerived().AlwaysRebuild() &&
3848 T == E->getType() &&
3849 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003850 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003851
3852 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T,
3853 /*FIXME:*/E->getInitializer()->getLocEnd(),
3854 move(Init));
3855}
Mike Stump11289f42009-09-09 15:08:12 +00003856
Douglas Gregora16548e2009-08-11 05:31:07 +00003857template<typename Derived>
3858Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003859TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003860 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3861 if (Base.isInvalid())
3862 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003863
Douglas Gregora16548e2009-08-11 05:31:07 +00003864 if (!getDerived().AlwaysRebuild() &&
3865 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003866 return SemaRef.Owned(E->Retain());
3867
Douglas Gregora16548e2009-08-11 05:31:07 +00003868 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003869 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003870 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3871 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3872 E->getAccessorLoc(),
3873 E->getAccessor());
3874}
Mike Stump11289f42009-09-09 15:08:12 +00003875
Douglas Gregora16548e2009-08-11 05:31:07 +00003876template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003877Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003878TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003879 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003880
Douglas Gregora16548e2009-08-11 05:31:07 +00003881 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3882 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3883 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3884 if (Init.isInvalid())
3885 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003886
Douglas Gregora16548e2009-08-11 05:31:07 +00003887 InitChanged = InitChanged || Init.get() != E->getInit(I);
3888 Inits.push_back(Init.takeAs<Expr>());
3889 }
Mike Stump11289f42009-09-09 15:08:12 +00003890
Douglas Gregora16548e2009-08-11 05:31:07 +00003891 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003892 return SemaRef.Owned(E->Retain());
3893
Douglas Gregora16548e2009-08-11 05:31:07 +00003894 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00003895 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00003896}
Mike Stump11289f42009-09-09 15:08:12 +00003897
Douglas Gregora16548e2009-08-11 05:31:07 +00003898template<typename Derived>
3899Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003900TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003901 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00003902
Douglas Gregorebe10102009-08-20 07:17:43 +00003903 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00003904 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3905 if (Init.isInvalid())
3906 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003907
Douglas Gregorebe10102009-08-20 07:17:43 +00003908 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00003909 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3910 bool ExprChanged = false;
3911 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3912 DEnd = E->designators_end();
3913 D != DEnd; ++D) {
3914 if (D->isFieldDesignator()) {
3915 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3916 D->getDotLoc(),
3917 D->getFieldLoc()));
3918 continue;
3919 }
Mike Stump11289f42009-09-09 15:08:12 +00003920
Douglas Gregora16548e2009-08-11 05:31:07 +00003921 if (D->isArrayDesignator()) {
3922 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3923 if (Index.isInvalid())
3924 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003925
3926 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003927 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003928
Douglas Gregora16548e2009-08-11 05:31:07 +00003929 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3930 ArrayExprs.push_back(Index.release());
3931 continue;
3932 }
Mike Stump11289f42009-09-09 15:08:12 +00003933
Douglas Gregora16548e2009-08-11 05:31:07 +00003934 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00003935 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00003936 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3937 if (Start.isInvalid())
3938 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003939
Douglas Gregora16548e2009-08-11 05:31:07 +00003940 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3941 if (End.isInvalid())
3942 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003943
3944 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003945 End.get(),
3946 D->getLBracketLoc(),
3947 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003948
Douglas Gregora16548e2009-08-11 05:31:07 +00003949 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
3950 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00003951
Douglas Gregora16548e2009-08-11 05:31:07 +00003952 ArrayExprs.push_back(Start.release());
3953 ArrayExprs.push_back(End.release());
3954 }
Mike Stump11289f42009-09-09 15:08:12 +00003955
Douglas Gregora16548e2009-08-11 05:31:07 +00003956 if (!getDerived().AlwaysRebuild() &&
3957 Init.get() == E->getInit() &&
3958 !ExprChanged)
3959 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003960
Douglas Gregora16548e2009-08-11 05:31:07 +00003961 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
3962 E->getEqualOrColonLoc(),
3963 E->usesGNUSyntax(), move(Init));
3964}
Mike Stump11289f42009-09-09 15:08:12 +00003965
Douglas Gregora16548e2009-08-11 05:31:07 +00003966template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003967Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003968TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00003969 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00003970 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3971
3972 // FIXME: Will we ever have proper type location here? Will we actually
3973 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00003974 QualType T = getDerived().TransformType(E->getType());
3975 if (T.isNull())
3976 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003977
Douglas Gregora16548e2009-08-11 05:31:07 +00003978 if (!getDerived().AlwaysRebuild() &&
3979 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00003980 return SemaRef.Owned(E->Retain());
3981
Douglas Gregora16548e2009-08-11 05:31:07 +00003982 return getDerived().RebuildImplicitValueInitExpr(T);
3983}
Mike Stump11289f42009-09-09 15:08:12 +00003984
Douglas Gregora16548e2009-08-11 05:31:07 +00003985template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003986Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003987TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003988 // FIXME: Do we want the type as written?
3989 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00003990
Douglas Gregora16548e2009-08-11 05:31:07 +00003991 {
3992 // FIXME: Source location isn't quite accurate.
3993 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
3994 T = getDerived().TransformType(E->getType());
3995 if (T.isNull())
3996 return SemaRef.ExprError();
3997 }
Mike Stump11289f42009-09-09 15:08:12 +00003998
Douglas Gregora16548e2009-08-11 05:31:07 +00003999 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4000 if (SubExpr.isInvalid())
4001 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004002
Douglas Gregora16548e2009-08-11 05:31:07 +00004003 if (!getDerived().AlwaysRebuild() &&
4004 T == E->getType() &&
4005 SubExpr.get() == E->getSubExpr())
4006 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004007
Douglas Gregora16548e2009-08-11 05:31:07 +00004008 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4009 T, E->getRParenLoc());
4010}
4011
4012template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004013Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004014TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004015 bool ArgumentChanged = false;
4016 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4017 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4018 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4019 if (Init.isInvalid())
4020 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004021
Douglas Gregora16548e2009-08-11 05:31:07 +00004022 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4023 Inits.push_back(Init.takeAs<Expr>());
4024 }
Mike Stump11289f42009-09-09 15:08:12 +00004025
Douglas Gregora16548e2009-08-11 05:31:07 +00004026 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4027 move_arg(Inits),
4028 E->getRParenLoc());
4029}
Mike Stump11289f42009-09-09 15:08:12 +00004030
Douglas Gregora16548e2009-08-11 05:31:07 +00004031/// \brief Transform an address-of-label expression.
4032///
4033/// By default, the transformation of an address-of-label expression always
4034/// rebuilds the expression, so that the label identifier can be resolved to
4035/// the corresponding label statement by semantic analysis.
4036template<typename Derived>
4037Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004038TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004039 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4040 E->getLabel());
4041}
Mike Stump11289f42009-09-09 15:08:12 +00004042
4043template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004044Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004045TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004046 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004047 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4048 if (SubStmt.isInvalid())
4049 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004050
Douglas Gregora16548e2009-08-11 05:31:07 +00004051 if (!getDerived().AlwaysRebuild() &&
4052 SubStmt.get() == E->getSubStmt())
4053 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004054
4055 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004056 move(SubStmt),
4057 E->getRParenLoc());
4058}
Mike Stump11289f42009-09-09 15:08:12 +00004059
Douglas Gregora16548e2009-08-11 05:31:07 +00004060template<typename Derived>
4061Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004062TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004063 QualType T1, T2;
4064 {
4065 // FIXME: Source location isn't quite accurate.
4066 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004067
Douglas Gregora16548e2009-08-11 05:31:07 +00004068 T1 = getDerived().TransformType(E->getArgType1());
4069 if (T1.isNull())
4070 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004071
Douglas Gregora16548e2009-08-11 05:31:07 +00004072 T2 = getDerived().TransformType(E->getArgType2());
4073 if (T2.isNull())
4074 return SemaRef.ExprError();
4075 }
4076
4077 if (!getDerived().AlwaysRebuild() &&
4078 T1 == E->getArgType1() &&
4079 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004080 return SemaRef.Owned(E->Retain());
4081
Douglas Gregora16548e2009-08-11 05:31:07 +00004082 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4083 T1, T2, E->getRParenLoc());
4084}
Mike Stump11289f42009-09-09 15:08:12 +00004085
Douglas Gregora16548e2009-08-11 05:31:07 +00004086template<typename Derived>
4087Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004088TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004089 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4090 if (Cond.isInvalid())
4091 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004092
Douglas Gregora16548e2009-08-11 05:31:07 +00004093 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4094 if (LHS.isInvalid())
4095 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004096
Douglas Gregora16548e2009-08-11 05:31:07 +00004097 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4098 if (RHS.isInvalid())
4099 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004100
Douglas Gregora16548e2009-08-11 05:31:07 +00004101 if (!getDerived().AlwaysRebuild() &&
4102 Cond.get() == E->getCond() &&
4103 LHS.get() == E->getLHS() &&
4104 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004105 return SemaRef.Owned(E->Retain());
4106
Douglas Gregora16548e2009-08-11 05:31:07 +00004107 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4108 move(Cond), move(LHS), move(RHS),
4109 E->getRParenLoc());
4110}
Mike Stump11289f42009-09-09 15:08:12 +00004111
Douglas Gregora16548e2009-08-11 05:31:07 +00004112template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004113Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004114TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004115 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004116}
4117
4118template<typename Derived>
4119Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004120TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004121 switch (E->getOperator()) {
4122 case OO_New:
4123 case OO_Delete:
4124 case OO_Array_New:
4125 case OO_Array_Delete:
4126 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4127 return SemaRef.ExprError();
4128
4129 case OO_Call: {
4130 // This is a call to an object's operator().
4131 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4132
4133 // Transform the object itself.
4134 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4135 if (Object.isInvalid())
4136 return SemaRef.ExprError();
4137
4138 // FIXME: Poor location information
4139 SourceLocation FakeLParenLoc
4140 = SemaRef.PP.getLocForEndOfToken(
4141 static_cast<Expr *>(Object.get())->getLocEnd());
4142
4143 // Transform the call arguments.
4144 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4145 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4146 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004147 if (getDerived().DropCallArgument(E->getArg(I)))
4148 break;
4149
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004150 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4151 if (Arg.isInvalid())
4152 return SemaRef.ExprError();
4153
4154 // FIXME: Poor source location information.
4155 SourceLocation FakeCommaLoc
4156 = SemaRef.PP.getLocForEndOfToken(
4157 static_cast<Expr *>(Arg.get())->getLocEnd());
4158 FakeCommaLocs.push_back(FakeCommaLoc);
4159 Args.push_back(Arg.release());
4160 }
4161
4162 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4163 move_arg(Args),
4164 FakeCommaLocs.data(),
4165 E->getLocEnd());
4166 }
4167
4168#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4169 case OO_##Name:
4170#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4171#include "clang/Basic/OperatorKinds.def"
4172 case OO_Subscript:
4173 // Handled below.
4174 break;
4175
4176 case OO_Conditional:
4177 llvm_unreachable("conditional operator is not actually overloadable");
4178 return SemaRef.ExprError();
4179
4180 case OO_None:
4181 case NUM_OVERLOADED_OPERATORS:
4182 llvm_unreachable("not an overloaded operator?");
4183 return SemaRef.ExprError();
4184 }
4185
Douglas Gregora16548e2009-08-11 05:31:07 +00004186 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4187 if (Callee.isInvalid())
4188 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004189
John McCall47f29ea2009-12-08 09:21:05 +00004190 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004191 if (First.isInvalid())
4192 return SemaRef.ExprError();
4193
4194 OwningExprResult Second(SemaRef);
4195 if (E->getNumArgs() == 2) {
4196 Second = getDerived().TransformExpr(E->getArg(1));
4197 if (Second.isInvalid())
4198 return SemaRef.ExprError();
4199 }
Mike Stump11289f42009-09-09 15:08:12 +00004200
Douglas Gregora16548e2009-08-11 05:31:07 +00004201 if (!getDerived().AlwaysRebuild() &&
4202 Callee.get() == E->getCallee() &&
4203 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004204 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4205 return SemaRef.Owned(E->Retain());
4206
Douglas Gregora16548e2009-08-11 05:31:07 +00004207 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4208 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004209 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004210 move(First),
4211 move(Second));
4212}
Mike Stump11289f42009-09-09 15:08:12 +00004213
Douglas Gregora16548e2009-08-11 05:31:07 +00004214template<typename Derived>
4215Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004216TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4217 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004218}
Mike Stump11289f42009-09-09 15:08:12 +00004219
Douglas Gregora16548e2009-08-11 05:31:07 +00004220template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004221Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004222TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004223 QualType ExplicitTy;
4224 {
4225 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004226 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004227 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4228 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004229
Douglas Gregora16548e2009-08-11 05:31:07 +00004230 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4231 if (ExplicitTy.isNull())
4232 return SemaRef.ExprError();
4233 }
Mike Stump11289f42009-09-09 15:08:12 +00004234
Douglas Gregor6131b442009-12-12 18:16:41 +00004235 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004236 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004237 if (SubExpr.isInvalid())
4238 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004239
Douglas Gregora16548e2009-08-11 05:31:07 +00004240 if (!getDerived().AlwaysRebuild() &&
4241 ExplicitTy == E->getTypeAsWritten() &&
4242 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004243 return SemaRef.Owned(E->Retain());
4244
Douglas Gregora16548e2009-08-11 05:31:07 +00004245 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004246 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004247 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4248 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4249 SourceLocation FakeRParenLoc
4250 = SemaRef.PP.getLocForEndOfToken(
4251 E->getSubExpr()->getSourceRange().getEnd());
4252 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004253 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004254 FakeLAngleLoc,
4255 ExplicitTy,
4256 FakeRAngleLoc,
4257 FakeRAngleLoc,
4258 move(SubExpr),
4259 FakeRParenLoc);
4260}
Mike Stump11289f42009-09-09 15:08:12 +00004261
Douglas Gregora16548e2009-08-11 05:31:07 +00004262template<typename Derived>
4263Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004264TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4265 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004266}
Mike Stump11289f42009-09-09 15:08:12 +00004267
4268template<typename Derived>
4269Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004270TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4271 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004272}
4273
Douglas Gregora16548e2009-08-11 05:31:07 +00004274template<typename Derived>
4275Sema::OwningExprResult
4276TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004277 CXXReinterpretCastExpr *E) {
4278 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004279}
Mike Stump11289f42009-09-09 15:08:12 +00004280
Douglas Gregora16548e2009-08-11 05:31:07 +00004281template<typename Derived>
4282Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004283TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4284 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004285}
Mike Stump11289f42009-09-09 15:08:12 +00004286
Douglas Gregora16548e2009-08-11 05:31:07 +00004287template<typename Derived>
4288Sema::OwningExprResult
4289TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004290 CXXFunctionalCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004291 QualType ExplicitTy;
4292 {
4293 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004294
Douglas Gregora16548e2009-08-11 05:31:07 +00004295 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4296 if (ExplicitTy.isNull())
4297 return SemaRef.ExprError();
4298 }
Mike Stump11289f42009-09-09 15:08:12 +00004299
Douglas Gregor6131b442009-12-12 18:16:41 +00004300 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004301 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004302 if (SubExpr.isInvalid())
4303 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004304
Douglas Gregora16548e2009-08-11 05:31:07 +00004305 if (!getDerived().AlwaysRebuild() &&
4306 ExplicitTy == E->getTypeAsWritten() &&
4307 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004308 return SemaRef.Owned(E->Retain());
4309
Douglas Gregora16548e2009-08-11 05:31:07 +00004310 // FIXME: The end of the type's source range is wrong
4311 return getDerived().RebuildCXXFunctionalCastExpr(
4312 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
4313 ExplicitTy,
4314 /*FIXME:*/E->getSubExpr()->getLocStart(),
4315 move(SubExpr),
4316 E->getRParenLoc());
4317}
Mike Stump11289f42009-09-09 15:08:12 +00004318
Douglas Gregora16548e2009-08-11 05:31:07 +00004319template<typename Derived>
4320Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004321TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004322 if (E->isTypeOperand()) {
4323 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004324
Douglas Gregora16548e2009-08-11 05:31:07 +00004325 QualType T = getDerived().TransformType(E->getTypeOperand());
4326 if (T.isNull())
4327 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004328
Douglas Gregora16548e2009-08-11 05:31:07 +00004329 if (!getDerived().AlwaysRebuild() &&
4330 T == E->getTypeOperand())
4331 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004332
Douglas Gregora16548e2009-08-11 05:31:07 +00004333 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4334 /*FIXME:*/E->getLocStart(),
4335 T,
4336 E->getLocEnd());
4337 }
Mike Stump11289f42009-09-09 15:08:12 +00004338
Douglas Gregora16548e2009-08-11 05:31:07 +00004339 // We don't know whether the expression is potentially evaluated until
4340 // after we perform semantic analysis, so the expression is potentially
4341 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004342 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004343 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004344
Douglas Gregora16548e2009-08-11 05:31:07 +00004345 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4346 if (SubExpr.isInvalid())
4347 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004348
Douglas Gregora16548e2009-08-11 05:31:07 +00004349 if (!getDerived().AlwaysRebuild() &&
4350 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004351 return SemaRef.Owned(E->Retain());
4352
Douglas Gregora16548e2009-08-11 05:31:07 +00004353 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4354 /*FIXME:*/E->getLocStart(),
4355 move(SubExpr),
4356 E->getLocEnd());
4357}
4358
4359template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004360Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004361TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004362 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004363}
Mike Stump11289f42009-09-09 15:08:12 +00004364
Douglas Gregora16548e2009-08-11 05:31:07 +00004365template<typename Derived>
4366Sema::OwningExprResult
4367TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004368 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004369 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004370}
Mike Stump11289f42009-09-09 15:08:12 +00004371
Douglas Gregora16548e2009-08-11 05:31:07 +00004372template<typename Derived>
4373Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004374TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004375 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004376
Douglas Gregora16548e2009-08-11 05:31:07 +00004377 QualType T = getDerived().TransformType(E->getType());
4378 if (T.isNull())
4379 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004380
Douglas Gregora16548e2009-08-11 05:31:07 +00004381 if (!getDerived().AlwaysRebuild() &&
4382 T == E->getType())
4383 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004384
Douglas Gregora16548e2009-08-11 05:31:07 +00004385 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T);
4386}
Mike Stump11289f42009-09-09 15:08:12 +00004387
Douglas Gregora16548e2009-08-11 05:31:07 +00004388template<typename Derived>
4389Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004390TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004391 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4392 if (SubExpr.isInvalid())
4393 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004394
Douglas Gregora16548e2009-08-11 05:31:07 +00004395 if (!getDerived().AlwaysRebuild() &&
4396 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004397 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004398
4399 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4400}
Mike Stump11289f42009-09-09 15:08:12 +00004401
Douglas Gregora16548e2009-08-11 05:31:07 +00004402template<typename Derived>
4403Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004404TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004405 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004406 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4407 if (!Param)
4408 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004409
Douglas Gregora16548e2009-08-11 05:31:07 +00004410 if (getDerived().AlwaysRebuild() &&
4411 Param == E->getParam())
4412 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004413
Douglas Gregora16548e2009-08-11 05:31:07 +00004414 return getDerived().RebuildCXXDefaultArgExpr(Param);
4415}
Mike Stump11289f42009-09-09 15:08:12 +00004416
Douglas Gregora16548e2009-08-11 05:31:07 +00004417template<typename Derived>
4418Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004419TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004420 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4421
4422 QualType T = getDerived().TransformType(E->getType());
4423 if (T.isNull())
4424 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004425
Douglas Gregora16548e2009-08-11 05:31:07 +00004426 if (!getDerived().AlwaysRebuild() &&
4427 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004428 return SemaRef.Owned(E->Retain());
4429
4430 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004431 /*FIXME:*/E->getTypeBeginLoc(),
4432 T,
4433 E->getRParenLoc());
4434}
Mike Stump11289f42009-09-09 15:08:12 +00004435
Douglas Gregora16548e2009-08-11 05:31:07 +00004436template<typename Derived>
4437Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004438TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004439 // Transform the type that we're allocating
4440 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4441 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4442 if (AllocType.isNull())
4443 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004444
Douglas Gregora16548e2009-08-11 05:31:07 +00004445 // Transform the size of the array we're allocating (if any).
4446 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4447 if (ArraySize.isInvalid())
4448 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004449
Douglas Gregora16548e2009-08-11 05:31:07 +00004450 // Transform the placement arguments (if any).
4451 bool ArgumentChanged = false;
4452 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4453 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4454 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4455 if (Arg.isInvalid())
4456 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004457
Douglas Gregora16548e2009-08-11 05:31:07 +00004458 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4459 PlacementArgs.push_back(Arg.take());
4460 }
Mike Stump11289f42009-09-09 15:08:12 +00004461
Douglas Gregorebe10102009-08-20 07:17:43 +00004462 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004463 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4464 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4465 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4466 if (Arg.isInvalid())
4467 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004468
Douglas Gregora16548e2009-08-11 05:31:07 +00004469 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4470 ConstructorArgs.push_back(Arg.take());
4471 }
Mike Stump11289f42009-09-09 15:08:12 +00004472
Douglas Gregora16548e2009-08-11 05:31:07 +00004473 if (!getDerived().AlwaysRebuild() &&
4474 AllocType == E->getAllocatedType() &&
4475 ArraySize.get() == E->getArraySize() &&
4476 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004477 return SemaRef.Owned(E->Retain());
4478
Douglas Gregora16548e2009-08-11 05:31:07 +00004479 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4480 E->isGlobalNew(),
4481 /*FIXME:*/E->getLocStart(),
4482 move_arg(PlacementArgs),
4483 /*FIXME:*/E->getLocStart(),
4484 E->isParenTypeId(),
4485 AllocType,
4486 /*FIXME:*/E->getLocStart(),
4487 /*FIXME:*/SourceRange(),
4488 move(ArraySize),
4489 /*FIXME:*/E->getLocStart(),
4490 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004491 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004492}
Mike Stump11289f42009-09-09 15:08:12 +00004493
Douglas Gregora16548e2009-08-11 05:31:07 +00004494template<typename Derived>
4495Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004496TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004497 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4498 if (Operand.isInvalid())
4499 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004500
Douglas Gregora16548e2009-08-11 05:31:07 +00004501 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004502 Operand.get() == E->getArgument())
4503 return SemaRef.Owned(E->Retain());
4504
Douglas Gregora16548e2009-08-11 05:31:07 +00004505 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4506 E->isGlobalDelete(),
4507 E->isArrayForm(),
4508 move(Operand));
4509}
Mike Stump11289f42009-09-09 15:08:12 +00004510
Douglas Gregora16548e2009-08-11 05:31:07 +00004511template<typename Derived>
4512Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004513TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004514 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004515 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4516 if (Base.isInvalid())
4517 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004518
Douglas Gregorad8a3362009-09-04 17:36:40 +00004519 NestedNameSpecifier *Qualifier
4520 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4521 E->getQualifierRange());
4522 if (E->getQualifier() && !Qualifier)
4523 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004524
Douglas Gregorad8a3362009-09-04 17:36:40 +00004525 QualType DestroyedType;
4526 {
4527 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4528 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4529 if (DestroyedType.isNull())
4530 return SemaRef.ExprError();
4531 }
Mike Stump11289f42009-09-09 15:08:12 +00004532
Douglas Gregorad8a3362009-09-04 17:36:40 +00004533 if (!getDerived().AlwaysRebuild() &&
4534 Base.get() == E->getBase() &&
4535 Qualifier == E->getQualifier() &&
4536 DestroyedType == E->getDestroyedType())
4537 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004538
Douglas Gregorad8a3362009-09-04 17:36:40 +00004539 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4540 E->getOperatorLoc(),
4541 E->isArrow(),
4542 E->getDestroyedTypeLoc(),
4543 DestroyedType,
4544 Qualifier,
4545 E->getQualifierRange());
4546}
Mike Stump11289f42009-09-09 15:08:12 +00004547
Douglas Gregorad8a3362009-09-04 17:36:40 +00004548template<typename Derived>
4549Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004550TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004551 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00004552 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4553
4554 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4555 Sema::LookupOrdinaryName);
4556
4557 // Transform all the decls.
4558 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4559 E = Old->decls_end(); I != E; ++I) {
4560 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00004561 if (!InstD) {
4562 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4563 // This can happen because of dependent hiding.
4564 if (isa<UsingShadowDecl>(*I))
4565 continue;
4566 else
4567 return SemaRef.ExprError();
4568 }
John McCalle66edc12009-11-24 19:00:30 +00004569
4570 // Expand using declarations.
4571 if (isa<UsingDecl>(InstD)) {
4572 UsingDecl *UD = cast<UsingDecl>(InstD);
4573 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4574 E = UD->shadow_end(); I != E; ++I)
4575 R.addDecl(*I);
4576 continue;
4577 }
4578
4579 R.addDecl(InstD);
4580 }
4581
4582 // Resolve a kind, but don't do any further analysis. If it's
4583 // ambiguous, the callee needs to deal with it.
4584 R.resolveKind();
4585
4586 // Rebuild the nested-name qualifier, if present.
4587 CXXScopeSpec SS;
4588 NestedNameSpecifier *Qualifier = 0;
4589 if (Old->getQualifier()) {
4590 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4591 Old->getQualifierRange());
4592 if (!Qualifier)
4593 return SemaRef.ExprError();
4594
4595 SS.setScopeRep(Qualifier);
4596 SS.setRange(Old->getQualifierRange());
4597 }
4598
4599 // If we have no template arguments, it's a normal declaration name.
4600 if (!Old->hasExplicitTemplateArgs())
4601 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4602
4603 // If we have template arguments, rebuild them, then rebuild the
4604 // templateid expression.
4605 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4606 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4607 TemplateArgumentLoc Loc;
4608 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4609 return SemaRef.ExprError();
4610 TransArgs.addArgument(Loc);
4611 }
4612
4613 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4614 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004615}
Mike Stump11289f42009-09-09 15:08:12 +00004616
Douglas Gregora16548e2009-08-11 05:31:07 +00004617template<typename Derived>
4618Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004619TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004620 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004621
Douglas Gregora16548e2009-08-11 05:31:07 +00004622 QualType T = getDerived().TransformType(E->getQueriedType());
4623 if (T.isNull())
4624 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004625
Douglas Gregora16548e2009-08-11 05:31:07 +00004626 if (!getDerived().AlwaysRebuild() &&
4627 T == E->getQueriedType())
4628 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004629
Douglas Gregora16548e2009-08-11 05:31:07 +00004630 // FIXME: Bad location information
4631 SourceLocation FakeLParenLoc
4632 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004633
4634 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004635 E->getLocStart(),
4636 /*FIXME:*/FakeLParenLoc,
4637 T,
4638 E->getLocEnd());
4639}
Mike Stump11289f42009-09-09 15:08:12 +00004640
Douglas Gregora16548e2009-08-11 05:31:07 +00004641template<typename Derived>
4642Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004643TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004644 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004645 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004646 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4647 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004648 if (!NNS)
4649 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004650
4651 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004652 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4653 if (!Name)
4654 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004655
John McCalle66edc12009-11-24 19:00:30 +00004656 if (!E->hasExplicitTemplateArgs()) {
4657 if (!getDerived().AlwaysRebuild() &&
4658 NNS == E->getQualifier() &&
4659 Name == E->getDeclName())
4660 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004661
John McCalle66edc12009-11-24 19:00:30 +00004662 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4663 E->getQualifierRange(),
4664 Name, E->getLocation(),
4665 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004666 }
John McCall6b51f282009-11-23 01:53:49 +00004667
4668 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004669 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004670 TemplateArgumentLoc Loc;
4671 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004672 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004673 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004674 }
4675
John McCalle66edc12009-11-24 19:00:30 +00004676 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4677 E->getQualifierRange(),
4678 Name, E->getLocation(),
4679 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004680}
4681
4682template<typename Derived>
4683Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004684TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004685 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4686
4687 QualType T = getDerived().TransformType(E->getType());
4688 if (T.isNull())
4689 return SemaRef.ExprError();
4690
4691 CXXConstructorDecl *Constructor
4692 = cast_or_null<CXXConstructorDecl>(
4693 getDerived().TransformDecl(E->getConstructor()));
4694 if (!Constructor)
4695 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004696
Douglas Gregora16548e2009-08-11 05:31:07 +00004697 bool ArgumentChanged = false;
4698 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004699 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004700 ArgEnd = E->arg_end();
4701 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00004702 if (getDerived().DropCallArgument(*Arg)) {
4703 ArgumentChanged = true;
4704 break;
4705 }
4706
Douglas Gregora16548e2009-08-11 05:31:07 +00004707 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4708 if (TransArg.isInvalid())
4709 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004710
Douglas Gregora16548e2009-08-11 05:31:07 +00004711 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4712 Args.push_back(TransArg.takeAs<Expr>());
4713 }
4714
4715 if (!getDerived().AlwaysRebuild() &&
4716 T == E->getType() &&
4717 Constructor == E->getConstructor() &&
4718 !ArgumentChanged)
4719 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004720
Douglas Gregordb121ba2009-12-14 16:27:04 +00004721 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
4722 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004723 move_arg(Args));
4724}
Mike Stump11289f42009-09-09 15:08:12 +00004725
Douglas Gregora16548e2009-08-11 05:31:07 +00004726/// \brief Transform a C++ temporary-binding expression.
4727///
Mike Stump11289f42009-09-09 15:08:12 +00004728/// The transformation of a temporary-binding expression always attempts to
4729/// bind a new temporary variable to its subexpression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004730/// subexpression itself did not change, because the temporary variable itself
4731/// must be unique.
4732template<typename Derived>
4733Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004734TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004735 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4736 if (SubExpr.isInvalid())
4737 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004738
Douglas Gregora16548e2009-08-11 05:31:07 +00004739 return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>());
4740}
Mike Stump11289f42009-09-09 15:08:12 +00004741
4742/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004743/// be destroyed after the expression is evaluated.
4744///
Mike Stump11289f42009-09-09 15:08:12 +00004745/// The transformation of a full expression always attempts to build a new
4746/// CXXExprWithTemporaries expression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004747/// subexpression itself did not change, because it will need to capture the
4748/// the new temporary variables introduced in the subexpression.
4749template<typename Derived>
4750Sema::OwningExprResult
4751TreeTransform<Derived>::TransformCXXExprWithTemporaries(
John McCall47f29ea2009-12-08 09:21:05 +00004752 CXXExprWithTemporaries *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004753 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4754 if (SubExpr.isInvalid())
4755 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004756
Douglas Gregora16548e2009-08-11 05:31:07 +00004757 return SemaRef.Owned(
Anders Carlsson6e997b22009-12-15 20:51:39 +00004758 SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004759}
Mike Stump11289f42009-09-09 15:08:12 +00004760
Douglas Gregora16548e2009-08-11 05:31:07 +00004761template<typename Derived>
4762Sema::OwningExprResult
4763TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004764 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004765 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4766 QualType T = getDerived().TransformType(E->getType());
4767 if (T.isNull())
4768 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004769
Douglas Gregora16548e2009-08-11 05:31:07 +00004770 CXXConstructorDecl *Constructor
4771 = cast_or_null<CXXConstructorDecl>(
4772 getDerived().TransformDecl(E->getConstructor()));
4773 if (!Constructor)
4774 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004775
Douglas Gregora16548e2009-08-11 05:31:07 +00004776 bool ArgumentChanged = false;
4777 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4778 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004779 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004780 ArgEnd = E->arg_end();
4781 Arg != ArgEnd; ++Arg) {
4782 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4783 if (TransArg.isInvalid())
4784 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004785
Douglas Gregora16548e2009-08-11 05:31:07 +00004786 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4787 Args.push_back((Expr *)TransArg.release());
4788 }
Mike Stump11289f42009-09-09 15:08:12 +00004789
Douglas Gregora16548e2009-08-11 05:31:07 +00004790 if (!getDerived().AlwaysRebuild() &&
4791 T == E->getType() &&
4792 Constructor == E->getConstructor() &&
4793 !ArgumentChanged)
4794 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004795
Douglas Gregora16548e2009-08-11 05:31:07 +00004796 // FIXME: Bogus location information
4797 SourceLocation CommaLoc;
4798 if (Args.size() > 1) {
4799 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004800 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004801 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4802 }
4803 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4804 T,
4805 /*FIXME:*/E->getTypeBeginLoc(),
4806 move_arg(Args),
4807 &CommaLoc,
4808 E->getLocEnd());
4809}
Mike Stump11289f42009-09-09 15:08:12 +00004810
Douglas Gregora16548e2009-08-11 05:31:07 +00004811template<typename Derived>
4812Sema::OwningExprResult
4813TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004814 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004815 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4816 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4817 if (T.isNull())
4818 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004819
Douglas Gregora16548e2009-08-11 05:31:07 +00004820 bool ArgumentChanged = false;
4821 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4822 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4823 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4824 ArgEnd = E->arg_end();
4825 Arg != ArgEnd; ++Arg) {
4826 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4827 if (TransArg.isInvalid())
4828 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004829
Douglas Gregora16548e2009-08-11 05:31:07 +00004830 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4831 FakeCommaLocs.push_back(
4832 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4833 Args.push_back(TransArg.takeAs<Expr>());
4834 }
Mike Stump11289f42009-09-09 15:08:12 +00004835
Douglas Gregora16548e2009-08-11 05:31:07 +00004836 if (!getDerived().AlwaysRebuild() &&
4837 T == E->getTypeAsWritten() &&
4838 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004839 return SemaRef.Owned(E->Retain());
4840
Douglas Gregora16548e2009-08-11 05:31:07 +00004841 // FIXME: we're faking the locations of the commas
4842 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4843 T,
4844 E->getLParenLoc(),
4845 move_arg(Args),
4846 FakeCommaLocs.data(),
4847 E->getRParenLoc());
4848}
Mike Stump11289f42009-09-09 15:08:12 +00004849
Douglas Gregora16548e2009-08-11 05:31:07 +00004850template<typename Derived>
4851Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004852TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004853 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004854 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004855 OwningExprResult Base(SemaRef, (Expr*) 0);
4856 Expr *OldBase;
4857 QualType BaseType;
4858 QualType ObjectType;
4859 if (!E->isImplicitAccess()) {
4860 OldBase = E->getBase();
4861 Base = getDerived().TransformExpr(OldBase);
4862 if (Base.isInvalid())
4863 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004864
John McCall2d74de92009-12-01 22:10:20 +00004865 // Start the member reference and compute the object's type.
4866 Sema::TypeTy *ObjectTy = 0;
4867 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4868 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004869 E->isArrow()? tok::arrow : tok::period,
John McCall2d74de92009-12-01 22:10:20 +00004870 ObjectTy);
4871 if (Base.isInvalid())
4872 return SemaRef.ExprError();
4873
4874 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
4875 BaseType = ((Expr*) Base.get())->getType();
4876 } else {
4877 OldBase = 0;
4878 BaseType = getDerived().TransformType(E->getBaseType());
4879 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
4880 }
Mike Stump11289f42009-09-09 15:08:12 +00004881
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004882 // Transform the first part of the nested-name-specifier that qualifies
4883 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004884 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004885 = getDerived().TransformFirstQualifierInScope(
4886 E->getFirstQualifierFoundInScope(),
4887 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00004888
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004889 NestedNameSpecifier *Qualifier = 0;
4890 if (E->getQualifier()) {
4891 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4892 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00004893 ObjectType,
4894 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004895 if (!Qualifier)
4896 return SemaRef.ExprError();
4897 }
Mike Stump11289f42009-09-09 15:08:12 +00004898
4899 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00004900 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00004901 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00004902 if (!Name)
4903 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004904
John McCall2d74de92009-12-01 22:10:20 +00004905 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00004906 // This is a reference to a member without an explicitly-specified
4907 // template argument list. Optimize for this common case.
4908 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00004909 Base.get() == OldBase &&
4910 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00004911 Qualifier == E->getQualifier() &&
4912 Name == E->getMember() &&
4913 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00004914 return SemaRef.Owned(E->Retain());
4915
John McCall8cd78132009-11-19 22:55:06 +00004916 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00004917 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00004918 E->isArrow(),
4919 E->getOperatorLoc(),
4920 Qualifier,
4921 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00004922 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00004923 Name,
4924 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00004925 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00004926 }
4927
John McCall6b51f282009-11-23 01:53:49 +00004928 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00004929 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004930 TemplateArgumentLoc Loc;
4931 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00004932 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004933 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00004934 }
Mike Stump11289f42009-09-09 15:08:12 +00004935
John McCall8cd78132009-11-19 22:55:06 +00004936 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00004937 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00004938 E->isArrow(),
4939 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004940 Qualifier,
4941 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004942 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00004943 Name,
4944 E->getMemberLoc(),
4945 &TransArgs);
4946}
4947
4948template<typename Derived>
4949Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004950TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00004951 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004952 OwningExprResult Base(SemaRef, (Expr*) 0);
4953 QualType BaseType;
4954 if (!Old->isImplicitAccess()) {
4955 Base = getDerived().TransformExpr(Old->getBase());
4956 if (Base.isInvalid())
4957 return SemaRef.ExprError();
4958 BaseType = ((Expr*) Base.get())->getType();
4959 } else {
4960 BaseType = getDerived().TransformType(Old->getBaseType());
4961 }
John McCall10eae182009-11-30 22:42:35 +00004962
4963 NestedNameSpecifier *Qualifier = 0;
4964 if (Old->getQualifier()) {
4965 Qualifier
4966 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4967 Old->getQualifierRange());
4968 if (Qualifier == 0)
4969 return SemaRef.ExprError();
4970 }
4971
4972 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
4973 Sema::LookupOrdinaryName);
4974
4975 // Transform all the decls.
4976 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
4977 E = Old->decls_end(); I != E; ++I) {
4978 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00004979 if (!InstD) {
4980 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4981 // This can happen because of dependent hiding.
4982 if (isa<UsingShadowDecl>(*I))
4983 continue;
4984 else
4985 return SemaRef.ExprError();
4986 }
John McCall10eae182009-11-30 22:42:35 +00004987
4988 // Expand using declarations.
4989 if (isa<UsingDecl>(InstD)) {
4990 UsingDecl *UD = cast<UsingDecl>(InstD);
4991 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4992 E = UD->shadow_end(); I != E; ++I)
4993 R.addDecl(*I);
4994 continue;
4995 }
4996
4997 R.addDecl(InstD);
4998 }
4999
5000 R.resolveKind();
5001
5002 TemplateArgumentListInfo TransArgs;
5003 if (Old->hasExplicitTemplateArgs()) {
5004 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5005 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5006 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5007 TemplateArgumentLoc Loc;
5008 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5009 Loc))
5010 return SemaRef.ExprError();
5011 TransArgs.addArgument(Loc);
5012 }
5013 }
5014
5015 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005016 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005017 Old->getOperatorLoc(),
5018 Old->isArrow(),
5019 Qualifier,
5020 Old->getQualifierRange(),
5021 R,
5022 (Old->hasExplicitTemplateArgs()
5023 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005024}
5025
5026template<typename Derived>
5027Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005028TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005029 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005030}
5031
Mike Stump11289f42009-09-09 15:08:12 +00005032template<typename Derived>
5033Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005034TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005035 // FIXME: poor source location
5036 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5037 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5038 if (EncodedType.isNull())
5039 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005040
Douglas Gregora16548e2009-08-11 05:31:07 +00005041 if (!getDerived().AlwaysRebuild() &&
5042 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00005043 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005044
5045 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5046 EncodedType,
5047 E->getRParenLoc());
5048}
Mike Stump11289f42009-09-09 15:08:12 +00005049
Douglas Gregora16548e2009-08-11 05:31:07 +00005050template<typename Derived>
5051Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005052TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005053 // FIXME: Implement this!
5054 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005055 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005056}
5057
Mike Stump11289f42009-09-09 15:08:12 +00005058template<typename Derived>
5059Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005060TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005061 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005062}
5063
Mike Stump11289f42009-09-09 15:08:12 +00005064template<typename Derived>
5065Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005066TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005067 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00005068 = cast_or_null<ObjCProtocolDecl>(
5069 getDerived().TransformDecl(E->getProtocol()));
5070 if (!Protocol)
5071 return SemaRef.ExprError();
5072
5073 if (!getDerived().AlwaysRebuild() &&
5074 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005075 return SemaRef.Owned(E->Retain());
5076
Douglas Gregora16548e2009-08-11 05:31:07 +00005077 return getDerived().RebuildObjCProtocolExpr(Protocol,
5078 E->getAtLoc(),
5079 /*FIXME:*/E->getAtLoc(),
5080 /*FIXME:*/E->getAtLoc(),
5081 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005082
Douglas Gregora16548e2009-08-11 05:31:07 +00005083}
5084
Mike Stump11289f42009-09-09 15:08:12 +00005085template<typename Derived>
5086Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005087TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005088 // FIXME: Implement this!
5089 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005090 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005091}
5092
Mike Stump11289f42009-09-09 15:08:12 +00005093template<typename Derived>
5094Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005095TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005096 // FIXME: Implement this!
5097 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005098 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005099}
5100
Mike Stump11289f42009-09-09 15:08:12 +00005101template<typename Derived>
5102Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005103TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005104 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005105 // FIXME: Implement this!
5106 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005107 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005108}
5109
Mike Stump11289f42009-09-09 15:08:12 +00005110template<typename Derived>
5111Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005112TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005113 // FIXME: Implement this!
5114 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005115 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005116}
5117
Mike Stump11289f42009-09-09 15:08:12 +00005118template<typename Derived>
5119Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005120TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005121 // FIXME: Implement this!
5122 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005123 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005124}
5125
Mike Stump11289f42009-09-09 15:08:12 +00005126template<typename Derived>
5127Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005128TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005129 bool ArgumentChanged = false;
5130 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5131 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5132 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5133 if (SubExpr.isInvalid())
5134 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005135
Douglas Gregora16548e2009-08-11 05:31:07 +00005136 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5137 SubExprs.push_back(SubExpr.takeAs<Expr>());
5138 }
Mike Stump11289f42009-09-09 15:08:12 +00005139
Douglas Gregora16548e2009-08-11 05:31:07 +00005140 if (!getDerived().AlwaysRebuild() &&
5141 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005142 return SemaRef.Owned(E->Retain());
5143
Douglas Gregora16548e2009-08-11 05:31:07 +00005144 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5145 move_arg(SubExprs),
5146 E->getRParenLoc());
5147}
5148
Mike Stump11289f42009-09-09 15:08:12 +00005149template<typename Derived>
5150Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005151TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005152 // FIXME: Implement this!
5153 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005154 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005155}
5156
Mike Stump11289f42009-09-09 15:08:12 +00005157template<typename Derived>
5158Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005159TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005160 // FIXME: Implement this!
5161 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005162 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005163}
Mike Stump11289f42009-09-09 15:08:12 +00005164
Douglas Gregora16548e2009-08-11 05:31:07 +00005165//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005166// Type reconstruction
5167//===----------------------------------------------------------------------===//
5168
Mike Stump11289f42009-09-09 15:08:12 +00005169template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005170QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5171 SourceLocation Star) {
5172 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005173 getDerived().getBaseEntity());
5174}
5175
Mike Stump11289f42009-09-09 15:08:12 +00005176template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005177QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5178 SourceLocation Star) {
5179 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005180 getDerived().getBaseEntity());
5181}
5182
Mike Stump11289f42009-09-09 15:08:12 +00005183template<typename Derived>
5184QualType
John McCall70dd5f62009-10-30 00:06:24 +00005185TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5186 bool WrittenAsLValue,
5187 SourceLocation Sigil) {
5188 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5189 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005190}
5191
5192template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005193QualType
John McCall70dd5f62009-10-30 00:06:24 +00005194TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5195 QualType ClassType,
5196 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005197 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005198 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005199}
5200
5201template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005202QualType
John McCall70dd5f62009-10-30 00:06:24 +00005203TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5204 SourceLocation Sigil) {
5205 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005206 getDerived().getBaseEntity());
5207}
5208
5209template<typename Derived>
5210QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005211TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5212 ArrayType::ArraySizeModifier SizeMod,
5213 const llvm::APInt *Size,
5214 Expr *SizeExpr,
5215 unsigned IndexTypeQuals,
5216 SourceRange BracketsRange) {
5217 if (SizeExpr || !Size)
5218 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5219 IndexTypeQuals, BracketsRange,
5220 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005221
5222 QualType Types[] = {
5223 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5224 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5225 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005226 };
5227 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5228 QualType SizeType;
5229 for (unsigned I = 0; I != NumTypes; ++I)
5230 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5231 SizeType = Types[I];
5232 break;
5233 }
Mike Stump11289f42009-09-09 15:08:12 +00005234
Douglas Gregord6ff3322009-08-04 16:50:30 +00005235 if (SizeType.isNull())
5236 SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false);
Mike Stump11289f42009-09-09 15:08:12 +00005237
Douglas Gregord6ff3322009-08-04 16:50:30 +00005238 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005239 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005240 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005241 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005242}
Mike Stump11289f42009-09-09 15:08:12 +00005243
Douglas Gregord6ff3322009-08-04 16:50:30 +00005244template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005245QualType
5246TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005247 ArrayType::ArraySizeModifier SizeMod,
5248 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005249 unsigned IndexTypeQuals,
5250 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005251 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005252 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005253}
5254
5255template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005256QualType
Mike Stump11289f42009-09-09 15:08:12 +00005257TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005258 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005259 unsigned IndexTypeQuals,
5260 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005261 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005262 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005263}
Mike Stump11289f42009-09-09 15:08:12 +00005264
Douglas Gregord6ff3322009-08-04 16:50:30 +00005265template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005266QualType
5267TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005268 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005269 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005270 unsigned IndexTypeQuals,
5271 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005272 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005273 SizeExpr.takeAs<Expr>(),
5274 IndexTypeQuals, BracketsRange);
5275}
5276
5277template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005278QualType
5279TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005280 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005281 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005282 unsigned IndexTypeQuals,
5283 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005284 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005285 SizeExpr.takeAs<Expr>(),
5286 IndexTypeQuals, BracketsRange);
5287}
5288
5289template<typename Derived>
5290QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
5291 unsigned NumElements) {
5292 // FIXME: semantic checking!
5293 return SemaRef.Context.getVectorType(ElementType, NumElements);
5294}
Mike Stump11289f42009-09-09 15:08:12 +00005295
Douglas Gregord6ff3322009-08-04 16:50:30 +00005296template<typename Derived>
5297QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5298 unsigned NumElements,
5299 SourceLocation AttributeLoc) {
5300 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5301 NumElements, true);
5302 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005303 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005304 AttributeLoc);
5305 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5306 AttributeLoc);
5307}
Mike Stump11289f42009-09-09 15:08:12 +00005308
Douglas Gregord6ff3322009-08-04 16:50:30 +00005309template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005310QualType
5311TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005312 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005313 SourceLocation AttributeLoc) {
5314 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5315}
Mike Stump11289f42009-09-09 15:08:12 +00005316
Douglas Gregord6ff3322009-08-04 16:50:30 +00005317template<typename Derived>
5318QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005319 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005320 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005321 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005322 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005323 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005324 Quals,
5325 getDerived().getBaseLocation(),
5326 getDerived().getBaseEntity());
5327}
Mike Stump11289f42009-09-09 15:08:12 +00005328
Douglas Gregord6ff3322009-08-04 16:50:30 +00005329template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005330QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5331 return SemaRef.Context.getFunctionNoProtoType(T);
5332}
5333
5334template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005335QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5336 assert(D && "no decl found");
5337 if (D->isInvalidDecl()) return QualType();
5338
5339 TypeDecl *Ty;
5340 if (isa<UsingDecl>(D)) {
5341 UsingDecl *Using = cast<UsingDecl>(D);
5342 assert(Using->isTypeName() &&
5343 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5344
5345 // A valid resolved using typename decl points to exactly one type decl.
5346 assert(++Using->shadow_begin() == Using->shadow_end());
5347 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5348
5349 } else {
5350 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5351 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5352 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5353 }
5354
5355 return SemaRef.Context.getTypeDeclType(Ty);
5356}
5357
5358template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005359QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005360 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5361}
5362
5363template<typename Derived>
5364QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5365 return SemaRef.Context.getTypeOfType(Underlying);
5366}
5367
5368template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005369QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005370 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5371}
5372
5373template<typename Derived>
5374QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005375 TemplateName Template,
5376 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005377 const TemplateArgumentListInfo &TemplateArgs) {
5378 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005379}
Mike Stump11289f42009-09-09 15:08:12 +00005380
Douglas Gregor1135c352009-08-06 05:28:30 +00005381template<typename Derived>
5382NestedNameSpecifier *
5383TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5384 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005385 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005386 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005387 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005388 CXXScopeSpec SS;
5389 // FIXME: The source location information is all wrong.
5390 SS.setRange(Range);
5391 SS.setScopeRep(Prefix);
5392 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005393 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005394 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005395 ObjectType,
5396 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005397 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005398}
5399
5400template<typename Derived>
5401NestedNameSpecifier *
5402TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5403 SourceRange Range,
5404 NamespaceDecl *NS) {
5405 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5406}
5407
5408template<typename Derived>
5409NestedNameSpecifier *
5410TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5411 SourceRange Range,
5412 bool TemplateKW,
5413 QualType T) {
5414 if (T->isDependentType() || T->isRecordType() ||
5415 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005416 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005417 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5418 T.getTypePtr());
5419 }
Mike Stump11289f42009-09-09 15:08:12 +00005420
Douglas Gregor1135c352009-08-06 05:28:30 +00005421 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5422 return 0;
5423}
Mike Stump11289f42009-09-09 15:08:12 +00005424
Douglas Gregor71dc5092009-08-06 06:41:21 +00005425template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005426TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005427TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5428 bool TemplateKW,
5429 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005430 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005431 Template);
5432}
5433
5434template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005435TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005436TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005437 const IdentifierInfo &II,
5438 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005439 CXXScopeSpec SS;
5440 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005441 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005442 UnqualifiedId Name;
5443 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005444 return getSema().ActOnDependentTemplateName(
5445 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005446 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005447 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005448 ObjectType.getAsOpaquePtr(),
5449 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005450 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005451}
Mike Stump11289f42009-09-09 15:08:12 +00005452
Douglas Gregora16548e2009-08-11 05:31:07 +00005453template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005454TemplateName
5455TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5456 OverloadedOperatorKind Operator,
5457 QualType ObjectType) {
5458 CXXScopeSpec SS;
5459 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5460 SS.setScopeRep(Qualifier);
5461 UnqualifiedId Name;
5462 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5463 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5464 Operator, SymbolLocations);
5465 return getSema().ActOnDependentTemplateName(
5466 /*FIXME:*/getDerived().getBaseLocation(),
5467 SS,
5468 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005469 ObjectType.getAsOpaquePtr(),
5470 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005471 .template getAsVal<TemplateName>();
5472}
5473
5474template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005475Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005476TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5477 SourceLocation OpLoc,
5478 ExprArg Callee,
5479 ExprArg First,
5480 ExprArg Second) {
5481 Expr *FirstExpr = (Expr *)First.get();
5482 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005483 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005484 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005485
Douglas Gregora16548e2009-08-11 05:31:07 +00005486 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005487 if (Op == OO_Subscript) {
5488 if (!FirstExpr->getType()->isOverloadableType() &&
5489 !SecondExpr->getType()->isOverloadableType())
5490 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005491 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005492 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005493 } else if (Op == OO_Arrow) {
5494 // -> is never a builtin operation.
5495 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005496 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005497 if (!FirstExpr->getType()->isOverloadableType()) {
5498 // The argument is not of overloadable type, so try to create a
5499 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005500 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005501 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005502
Douglas Gregora16548e2009-08-11 05:31:07 +00005503 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5504 }
5505 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005506 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005507 !SecondExpr->getType()->isOverloadableType()) {
5508 // Neither of the arguments is an overloadable type, so try to
5509 // create a built-in binary operation.
5510 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005511 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005512 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5513 if (Result.isInvalid())
5514 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005515
Douglas Gregora16548e2009-08-11 05:31:07 +00005516 First.release();
5517 Second.release();
5518 return move(Result);
5519 }
5520 }
Mike Stump11289f42009-09-09 15:08:12 +00005521
5522 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005523 // used during overload resolution.
5524 Sema::FunctionSet Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005525
John McCalld14a8642009-11-21 08:51:07 +00005526 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5527 assert(ULE->requiresADL());
5528
5529 // FIXME: Do we have to check
5530 // IsAcceptableNonMemberOperatorCandidate for each of these?
5531 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(),
5532 E = ULE->decls_end(); I != E; ++I)
5533 Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I));
5534 } else {
5535 Functions.insert(AnyFunctionDecl::getFromNamedDecl(
5536 cast<DeclRefExpr>(CalleeExpr)->getDecl()));
5537 }
Mike Stump11289f42009-09-09 15:08:12 +00005538
Douglas Gregora16548e2009-08-11 05:31:07 +00005539 // Add any functions found via argument-dependent lookup.
5540 Expr *Args[2] = { FirstExpr, SecondExpr };
5541 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005542 DeclarationName OpName
Douglas Gregora16548e2009-08-11 05:31:07 +00005543 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
Sebastian Redlc057f422009-10-23 19:23:15 +00005544 SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs,
5545 Functions);
Mike Stump11289f42009-09-09 15:08:12 +00005546
Douglas Gregora16548e2009-08-11 05:31:07 +00005547 // Create the overloaded operator invocation for unary operators.
5548 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005549 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005550 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5551 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5552 }
Mike Stump11289f42009-09-09 15:08:12 +00005553
Sebastian Redladba46e2009-10-29 20:17:01 +00005554 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005555 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5556 OpLoc,
5557 move(First),
5558 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005559
Douglas Gregora16548e2009-08-11 05:31:07 +00005560 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005561 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005562 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005563 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005564 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5565 if (Result.isInvalid())
5566 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005567
Douglas Gregora16548e2009-08-11 05:31:07 +00005568 First.release();
5569 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005570 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005571}
Mike Stump11289f42009-09-09 15:08:12 +00005572
Douglas Gregord6ff3322009-08-04 16:50:30 +00005573} // end namespace clang
5574
5575#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H