blob: 155e2e4a7debb90d5703e22d7757efb70254ae80 [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
175 /// \brief Transforms the given type into another type.
176 ///
John McCall550e0c22009-10-21 00:40:46 +0000177 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000178 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000179 /// function. This is expensive, but we don't mind, because
180 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000181 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000182 ///
183 /// \returns the transformed type.
184 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000185
John McCall550e0c22009-10-21 00:40:46 +0000186 /// \brief Transforms the given type-with-location into a new
187 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000188 ///
John McCall550e0c22009-10-21 00:40:46 +0000189 /// By default, this routine transforms a type by delegating to the
190 /// appropriate TransformXXXType to build a new type. Subclasses
191 /// may override this function (to take over all type
192 /// transformations) or some set of the TransformXXXType functions
193 /// to alter the transformation.
John McCallbcd03502009-12-07 02:54:59 +0000194 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000195
196 /// \brief Transform the given type-with-location into a new
197 /// type, collecting location information in the given builder
198 /// as necessary.
199 ///
200 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000201
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000202 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000203 ///
Mike Stump11289f42009-09-09 15:08:12 +0000204 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000205 /// appropriate TransformXXXStmt function to transform a specific kind of
206 /// statement or the TransformExpr() function to transform an expression.
207 /// Subclasses may override this function to transform statements using some
208 /// other mechanism.
209 ///
210 /// \returns the transformed statement.
Douglas Gregora16548e2009-08-11 05:31:07 +0000211 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000212
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000213 /// \brief Transform the given expression.
214 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000215 /// By default, this routine transforms an expression by delegating to the
216 /// appropriate TransformXXXExpr function to build a new expression.
217 /// Subclasses may override this function to transform expressions using some
218 /// other mechanism.
219 ///
220 /// \returns the transformed expression.
221 OwningExprResult TransformExpr(Expr *E) {
222 return getDerived().TransformExpr(E, /*isAddressOfOperand=*/false);
223 }
224
225 /// \brief Transform the given expression.
226 ///
227 /// By default, this routine transforms an expression by delegating to the
228 /// appropriate TransformXXXExpr function to build a new expression.
229 /// Subclasses may override this function to transform expressions using some
230 /// other mechanism.
231 ///
232 /// \returns the transformed expression.
233 OwningExprResult TransformExpr(Expr *E, bool isAddressOfOperand);
Mike Stump11289f42009-09-09 15:08:12 +0000234
Douglas Gregord6ff3322009-08-04 16:50:30 +0000235 /// \brief Transform the given declaration, which is referenced from a type
236 /// or expression.
237 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000238 /// By default, acts as the identity function on declarations. Subclasses
239 /// may override this function to provide alternate behavior.
240 Decl *TransformDecl(Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000241
242 /// \brief Transform the definition of the given declaration.
243 ///
Mike Stump11289f42009-09-09 15:08:12 +0000244 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000245 /// Subclasses may override this function to provide alternate behavior.
246 Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); }
Mike Stump11289f42009-09-09 15:08:12 +0000247
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000248 /// \brief Transform the given declaration, which was the first part of a
249 /// nested-name-specifier in a member access expression.
250 ///
251 /// This specific declaration transformation only applies to the first
252 /// identifier in a nested-name-specifier of a member access expression, e.g.,
253 /// the \c T in \c x->T::member
254 ///
255 /// By default, invokes TransformDecl() to transform the declaration.
256 /// Subclasses may override this function to provide alternate behavior.
257 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
258 return cast_or_null<NamedDecl>(getDerived().TransformDecl(D));
259 }
260
Douglas Gregord6ff3322009-08-04 16:50:30 +0000261 /// \brief Transform the given nested-name-specifier.
262 ///
Mike Stump11289f42009-09-09 15:08:12 +0000263 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000264 /// nested-name-specifier. Subclasses may override this function to provide
265 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000266 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000267 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000268 QualType ObjectType = QualType(),
269 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000270
Douglas Gregorf816bd72009-09-03 22:13:48 +0000271 /// \brief Transform the given declaration name.
272 ///
273 /// By default, transforms the types of conversion function, constructor,
274 /// and destructor names and then (if needed) rebuilds the declaration name.
275 /// Identifiers and selectors are returned unmodified. Sublcasses may
276 /// override this function to provide alternate behavior.
277 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +0000278 SourceLocation Loc,
279 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000280
Douglas Gregord6ff3322009-08-04 16:50:30 +0000281 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000282 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000283 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000284 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000285 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000286 TemplateName TransformTemplateName(TemplateName Name,
287 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000288
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 /// \brief Transform the given template argument.
290 ///
Mike Stump11289f42009-09-09 15:08:12 +0000291 /// By default, this operation transforms the type, expression, or
292 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000293 /// new template argument from the transformed result. Subclasses may
294 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000295 ///
296 /// Returns true if there was an error.
297 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
298 TemplateArgumentLoc &Output);
299
300 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
301 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
302 TemplateArgumentLoc &ArgLoc);
303
John McCallbcd03502009-12-07 02:54:59 +0000304 /// \brief Fakes up a TypeSourceInfo for a type.
305 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
306 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000307 getDerived().getBaseLocation());
308 }
Mike Stump11289f42009-09-09 15:08:12 +0000309
John McCall550e0c22009-10-21 00:40:46 +0000310#define ABSTRACT_TYPELOC(CLASS, PARENT)
311#define TYPELOC(CLASS, PARENT) \
312 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
313#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000314
John McCall70dd5f62009-10-30 00:06:24 +0000315 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
316
Douglas Gregorc59e5612009-10-19 22:04:39 +0000317 QualType
318 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
319 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000320
321 QualType
322 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
323 TemplateSpecializationTypeLoc TL,
324 QualType ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +0000325
Douglas Gregorebe10102009-08-20 07:17:43 +0000326 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Mike Stump11289f42009-09-09 15:08:12 +0000327
Douglas Gregorebe10102009-08-20 07:17:43 +0000328#define STMT(Node, Parent) \
329 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000330#define EXPR(Node, Parent) \
Douglas Gregorc95a1fa2009-11-04 07:01:15 +0000331 OwningExprResult Transform##Node(Node *E, bool isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +0000332#define ABSTRACT_EXPR(Node, Parent)
333#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000334
Douglas Gregord6ff3322009-08-04 16:50:30 +0000335 /// \brief Build a new pointer type given its pointee type.
336 ///
337 /// By default, performs semantic analysis when building the pointer type.
338 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000339 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000340
341 /// \brief Build a new block pointer type given its pointee type.
342 ///
Mike Stump11289f42009-09-09 15:08:12 +0000343 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000344 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000345 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000346
John McCall70dd5f62009-10-30 00:06:24 +0000347 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000348 ///
John McCall70dd5f62009-10-30 00:06:24 +0000349 /// By default, performs semantic analysis when building the
350 /// reference type. Subclasses may override this routine to provide
351 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000352 ///
John McCall70dd5f62009-10-30 00:06:24 +0000353 /// \param LValue whether the type was written with an lvalue sigil
354 /// or an rvalue sigil.
355 QualType RebuildReferenceType(QualType ReferentType,
356 bool LValue,
357 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000358
Douglas Gregord6ff3322009-08-04 16:50:30 +0000359 /// \brief Build a new member pointer type given the pointee type and the
360 /// class type it refers into.
361 ///
362 /// By default, performs semantic analysis when building the member pointer
363 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000364 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
365 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000366
John McCall550e0c22009-10-21 00:40:46 +0000367 /// \brief Build a new Objective C object pointer type.
John McCall70dd5f62009-10-30 00:06:24 +0000368 QualType RebuildObjCObjectPointerType(QualType PointeeType,
369 SourceLocation Sigil);
John McCall550e0c22009-10-21 00:40:46 +0000370
Douglas Gregord6ff3322009-08-04 16:50:30 +0000371 /// \brief Build a new array type given the element type, size
372 /// modifier, size of the array (if known), size expression, and index type
373 /// qualifiers.
374 ///
375 /// By default, performs semantic analysis when building the array type.
376 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000377 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000378 QualType RebuildArrayType(QualType ElementType,
379 ArrayType::ArraySizeModifier SizeMod,
380 const llvm::APInt *Size,
381 Expr *SizeExpr,
382 unsigned IndexTypeQuals,
383 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000384
Douglas Gregord6ff3322009-08-04 16:50:30 +0000385 /// \brief Build a new constant array type given the element type, size
386 /// modifier, (known) size of the array, and index type qualifiers.
387 ///
388 /// By default, performs semantic analysis when building the array type.
389 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000390 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000391 ArrayType::ArraySizeModifier SizeMod,
392 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000393 unsigned IndexTypeQuals,
394 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000395
Douglas Gregord6ff3322009-08-04 16:50:30 +0000396 /// \brief Build a new incomplete array type given the element type, size
397 /// modifier, and index type qualifiers.
398 ///
399 /// By default, performs semantic analysis when building the array type.
400 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000401 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000402 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000403 unsigned IndexTypeQuals,
404 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000405
Mike Stump11289f42009-09-09 15:08:12 +0000406 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000407 /// size modifier, size expression, and index type qualifiers.
408 ///
409 /// By default, performs semantic analysis when building the array type.
410 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000411 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000412 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000413 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000414 unsigned IndexTypeQuals,
415 SourceRange BracketsRange);
416
Mike Stump11289f42009-09-09 15:08:12 +0000417 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000418 /// size modifier, size expression, and index type qualifiers.
419 ///
420 /// By default, performs semantic analysis when building the array type.
421 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000422 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000424 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 unsigned IndexTypeQuals,
426 SourceRange BracketsRange);
427
428 /// \brief Build a new vector type given the element type and
429 /// number of elements.
430 ///
431 /// By default, performs semantic analysis when building the vector type.
432 /// Subclasses may override this routine to provide different behavior.
433 QualType RebuildVectorType(QualType ElementType, unsigned NumElements);
Mike Stump11289f42009-09-09 15:08:12 +0000434
Douglas Gregord6ff3322009-08-04 16:50:30 +0000435 /// \brief Build a new extended vector type given the element type and
436 /// number of elements.
437 ///
438 /// By default, performs semantic analysis when building the vector type.
439 /// Subclasses may override this routine to provide different behavior.
440 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
441 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000442
443 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000444 /// given the element type and number of elements.
445 ///
446 /// By default, performs semantic analysis when building the vector type.
447 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000448 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000449 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000451
Douglas Gregord6ff3322009-08-04 16:50:30 +0000452 /// \brief Build a new function type.
453 ///
454 /// By default, performs semantic analysis when building the function type.
455 /// Subclasses may override this routine to provide different behavior.
456 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000457 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000458 unsigned NumParamTypes,
459 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000460
John McCall550e0c22009-10-21 00:40:46 +0000461 /// \brief Build a new unprototyped function type.
462 QualType RebuildFunctionNoProtoType(QualType ResultType);
463
John McCallb96ec562009-12-04 22:46:56 +0000464 /// \brief Rebuild an unresolved typename type, given the decl that
465 /// the UnresolvedUsingTypenameDecl was transformed to.
466 QualType RebuildUnresolvedUsingType(Decl *D);
467
Douglas Gregord6ff3322009-08-04 16:50:30 +0000468 /// \brief Build a new typedef type.
469 QualType RebuildTypedefType(TypedefDecl *Typedef) {
470 return SemaRef.Context.getTypeDeclType(Typedef);
471 }
472
473 /// \brief Build a new class/struct/union type.
474 QualType RebuildRecordType(RecordDecl *Record) {
475 return SemaRef.Context.getTypeDeclType(Record);
476 }
477
478 /// \brief Build a new Enum type.
479 QualType RebuildEnumType(EnumDecl *Enum) {
480 return SemaRef.Context.getTypeDeclType(Enum);
481 }
John McCallfcc33b02009-09-05 00:15:47 +0000482
483 /// \brief Build a new elaborated type.
484 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
485 return SemaRef.Context.getElaboratedType(T, Tag);
486 }
Mike Stump11289f42009-09-09 15:08:12 +0000487
488 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000489 ///
490 /// By default, performs semantic analysis when building the typeof type.
491 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000492 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000493
Mike Stump11289f42009-09-09 15:08:12 +0000494 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000495 ///
496 /// By default, builds a new TypeOfType with the given underlying type.
497 QualType RebuildTypeOfType(QualType Underlying);
498
Mike Stump11289f42009-09-09 15:08:12 +0000499 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000500 ///
501 /// By default, performs semantic analysis when building the decltype type.
502 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000503 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000504
Douglas Gregord6ff3322009-08-04 16:50:30 +0000505 /// \brief Build a new template specialization type.
506 ///
507 /// By default, performs semantic analysis when building the template
508 /// specialization type. Subclasses may override this routine to provide
509 /// different behavior.
510 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000511 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000512 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000513
Douglas Gregord6ff3322009-08-04 16:50:30 +0000514 /// \brief Build a new qualified name type.
515 ///
Mike Stump11289f42009-09-09 15:08:12 +0000516 /// By default, builds a new QualifiedNameType type from the
517 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000518 /// this routine to provide different behavior.
519 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
520 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000521 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000522
523 /// \brief Build a new typename type that refers to a template-id.
524 ///
525 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000526 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000527 /// different behavior.
528 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
529 if (NNS->isDependent())
Mike Stump11289f42009-09-09 15:08:12 +0000530 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000531 cast<TemplateSpecializationType>(T));
Mike Stump11289f42009-09-09 15:08:12 +0000532
Douglas Gregord6ff3322009-08-04 16:50:30 +0000533 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000534 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000535
536 /// \brief Build a new typename type that refers to an identifier.
537 ///
538 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000539 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000540 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000541 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall0ad16662009-10-29 08:12:44 +0000542 const IdentifierInfo *Id,
543 SourceRange SR) {
544 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregor1135c352009-08-06 05:28:30 +0000545 }
Mike Stump11289f42009-09-09 15:08:12 +0000546
Douglas Gregor1135c352009-08-06 05:28:30 +0000547 /// \brief Build a new nested-name-specifier given the prefix and an
548 /// identifier that names the next step in the nested-name-specifier.
549 ///
550 /// By default, performs semantic analysis when building the new
551 /// nested-name-specifier. Subclasses may override this routine to provide
552 /// different behavior.
553 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
554 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000555 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000556 QualType ObjectType,
557 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000558
559 /// \brief Build a new nested-name-specifier given the prefix and the
560 /// namespace named in the next step in the nested-name-specifier.
561 ///
562 /// By default, performs semantic analysis when building the new
563 /// nested-name-specifier. Subclasses may override this routine to provide
564 /// different behavior.
565 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
566 SourceRange Range,
567 NamespaceDecl *NS);
568
569 /// \brief Build a new nested-name-specifier given the prefix and the
570 /// type named in the next step in the nested-name-specifier.
571 ///
572 /// By default, performs semantic analysis when building the new
573 /// nested-name-specifier. Subclasses may override this routine to provide
574 /// different behavior.
575 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
576 SourceRange Range,
577 bool TemplateKW,
578 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000579
580 /// \brief Build a new template name given a nested name specifier, a flag
581 /// indicating whether the "template" keyword was provided, and the template
582 /// that the template name refers to.
583 ///
584 /// By default, builds the new template name directly. Subclasses may override
585 /// this routine to provide different behavior.
586 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
587 bool TemplateKW,
588 TemplateDecl *Template);
589
Douglas Gregor71dc5092009-08-06 06:41:21 +0000590 /// \brief Build a new template name given a nested name specifier and the
591 /// name that is referred to as a template.
592 ///
593 /// By default, performs semantic analysis to determine whether the name can
594 /// be resolved to a specific template, then builds the appropriate kind of
595 /// template name. Subclasses may override this routine to provide different
596 /// behavior.
597 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000598 const IdentifierInfo &II,
599 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000600
Douglas Gregor71395fa2009-11-04 00:56:37 +0000601 /// \brief Build a new template name given a nested name specifier and the
602 /// overloaded operator name that is referred to as a template.
603 ///
604 /// By default, performs semantic analysis to determine whether the name can
605 /// be resolved to a specific template, then builds the appropriate kind of
606 /// template name. Subclasses may override this routine to provide different
607 /// behavior.
608 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
609 OverloadedOperatorKind Operator,
610 QualType ObjectType);
611
Douglas Gregorebe10102009-08-20 07:17:43 +0000612 /// \brief Build a new compound statement.
613 ///
614 /// By default, performs semantic analysis to build the new statement.
615 /// Subclasses may override this routine to provide different behavior.
616 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
617 MultiStmtArg Statements,
618 SourceLocation RBraceLoc,
619 bool IsStmtExpr) {
620 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
621 IsStmtExpr);
622 }
623
624 /// \brief Build a new case statement.
625 ///
626 /// By default, performs semantic analysis to build the new statement.
627 /// Subclasses may override this routine to provide different behavior.
628 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
629 ExprArg LHS,
630 SourceLocation EllipsisLoc,
631 ExprArg RHS,
632 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000633 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000634 ColonLoc);
635 }
Mike Stump11289f42009-09-09 15:08:12 +0000636
Douglas Gregorebe10102009-08-20 07:17:43 +0000637 /// \brief Attach the body to a new case statement.
638 ///
639 /// By default, performs semantic analysis to build the new statement.
640 /// Subclasses may override this routine to provide different behavior.
641 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
642 getSema().ActOnCaseStmtBody(S.get(), move(Body));
643 return move(S);
644 }
Mike Stump11289f42009-09-09 15:08:12 +0000645
Douglas Gregorebe10102009-08-20 07:17:43 +0000646 /// \brief Build a new default statement.
647 ///
648 /// By default, performs semantic analysis to build the new statement.
649 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000650 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000651 SourceLocation ColonLoc,
652 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000653 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000654 /*CurScope=*/0);
655 }
Mike Stump11289f42009-09-09 15:08:12 +0000656
Douglas Gregorebe10102009-08-20 07:17:43 +0000657 /// \brief Build a new label statement.
658 ///
659 /// By default, performs semantic analysis to build the new statement.
660 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000661 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000662 IdentifierInfo *Id,
663 SourceLocation ColonLoc,
664 StmtArg SubStmt) {
665 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
666 }
Mike Stump11289f42009-09-09 15:08:12 +0000667
Douglas Gregorebe10102009-08-20 07:17:43 +0000668 /// \brief Build a new "if" statement.
669 ///
670 /// By default, performs semantic analysis to build the new statement.
671 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000672 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000673 VarDecl *CondVar, StmtArg Then,
674 SourceLocation ElseLoc, StmtArg Else) {
675 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
676 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000677 }
Mike Stump11289f42009-09-09 15:08:12 +0000678
Douglas Gregorebe10102009-08-20 07:17:43 +0000679 /// \brief Start building a new switch statement.
680 ///
681 /// By default, performs semantic analysis to build the new statement.
682 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000683 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
684 VarDecl *CondVar) {
685 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000686 }
Mike Stump11289f42009-09-09 15:08:12 +0000687
Douglas Gregorebe10102009-08-20 07:17:43 +0000688 /// \brief Attach the body to the switch statement.
689 ///
690 /// By default, performs semantic analysis to build the new statement.
691 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000692 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000693 StmtArg Switch, StmtArg Body) {
694 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
695 move(Body));
696 }
697
698 /// \brief Build a new while statement.
699 ///
700 /// By default, performs semantic analysis to build the new statement.
701 /// Subclasses may override this routine to provide different behavior.
702 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
703 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000704 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000705 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000706 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
707 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000708 }
Mike Stump11289f42009-09-09 15:08:12 +0000709
Douglas Gregorebe10102009-08-20 07:17:43 +0000710 /// \brief Build a new do-while statement.
711 ///
712 /// By default, performs semantic analysis to build the new statement.
713 /// Subclasses may override this routine to provide different behavior.
714 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
715 SourceLocation WhileLoc,
716 SourceLocation LParenLoc,
717 ExprArg Cond,
718 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000719 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000720 move(Cond), RParenLoc);
721 }
722
723 /// \brief Build a new for statement.
724 ///
725 /// By default, performs semantic analysis to build the new statement.
726 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000727 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000728 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000729 StmtArg Init, Sema::FullExprArg Cond,
730 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000731 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000732 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
733 DeclPtrTy::make(CondVar),
734 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000735 }
Mike Stump11289f42009-09-09 15:08:12 +0000736
Douglas Gregorebe10102009-08-20 07:17:43 +0000737 /// \brief Build a new goto statement.
738 ///
739 /// By default, performs semantic analysis to build the new statement.
740 /// Subclasses may override this routine to provide different behavior.
741 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
742 SourceLocation LabelLoc,
743 LabelStmt *Label) {
744 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
745 }
746
747 /// \brief Build a new indirect goto statement.
748 ///
749 /// By default, performs semantic analysis to build the new statement.
750 /// Subclasses may override this routine to provide different behavior.
751 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
752 SourceLocation StarLoc,
753 ExprArg Target) {
754 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
755 }
Mike Stump11289f42009-09-09 15:08:12 +0000756
Douglas Gregorebe10102009-08-20 07:17:43 +0000757 /// \brief Build a new return statement.
758 ///
759 /// By default, performs semantic analysis to build the new statement.
760 /// Subclasses may override this routine to provide different behavior.
761 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
762 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000763
Douglas Gregorebe10102009-08-20 07:17:43 +0000764 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
765 }
Mike Stump11289f42009-09-09 15:08:12 +0000766
Douglas Gregorebe10102009-08-20 07:17:43 +0000767 /// \brief Build a new declaration statement.
768 ///
769 /// By default, performs semantic analysis to build the new statement.
770 /// Subclasses may override this routine to provide different behavior.
771 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000772 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000773 SourceLocation EndLoc) {
774 return getSema().Owned(
775 new (getSema().Context) DeclStmt(
776 DeclGroupRef::Create(getSema().Context,
777 Decls, NumDecls),
778 StartLoc, EndLoc));
779 }
Mike Stump11289f42009-09-09 15:08:12 +0000780
Douglas Gregorebe10102009-08-20 07:17:43 +0000781 /// \brief Build a new C++ exception declaration.
782 ///
783 /// By default, performs semantic analysis to build the new decaration.
784 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000785 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000786 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000787 IdentifierInfo *Name,
788 SourceLocation Loc,
789 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000790 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000791 TypeRange);
792 }
793
794 /// \brief Build a new C++ catch statement.
795 ///
796 /// By default, performs semantic analysis to build the new statement.
797 /// Subclasses may override this routine to provide different behavior.
798 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
799 VarDecl *ExceptionDecl,
800 StmtArg Handler) {
801 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000802 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000803 Handler.takeAs<Stmt>()));
804 }
Mike Stump11289f42009-09-09 15:08:12 +0000805
Douglas Gregorebe10102009-08-20 07:17:43 +0000806 /// \brief Build a new C++ try statement.
807 ///
808 /// By default, performs semantic analysis to build the new statement.
809 /// Subclasses may override this routine to provide different behavior.
810 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
811 StmtArg TryBlock,
812 MultiStmtArg Handlers) {
813 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
814 }
Mike Stump11289f42009-09-09 15:08:12 +0000815
Douglas Gregora16548e2009-08-11 05:31:07 +0000816 /// \brief Build a new expression that references a declaration.
817 ///
818 /// By default, performs semantic analysis to build the new expression.
819 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +0000820 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
821 LookupResult &R,
822 bool RequiresADL) {
823 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
824 }
825
826
827 /// \brief Build a new expression that references a declaration.
828 ///
829 /// By default, performs semantic analysis to build the new expression.
830 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000831 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
832 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +0000833 ValueDecl *VD, SourceLocation Loc,
834 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000835 CXXScopeSpec SS;
836 SS.setScopeRep(Qualifier);
837 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +0000838
839 // FIXME: loses template args.
840
841 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +0000842 }
Mike Stump11289f42009-09-09 15:08:12 +0000843
Douglas Gregora16548e2009-08-11 05:31:07 +0000844 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000845 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000846 /// By default, performs semantic analysis to build the new expression.
847 /// Subclasses may override this routine to provide different behavior.
848 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
849 SourceLocation RParen) {
850 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
851 }
852
Douglas Gregorad8a3362009-09-04 17:36:40 +0000853 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000854 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000855 /// By default, performs semantic analysis to build the new expression.
856 /// Subclasses may override this routine to provide different behavior.
857 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
858 SourceLocation OperatorLoc,
859 bool isArrow,
860 SourceLocation DestroyedTypeLoc,
861 QualType DestroyedType,
862 NestedNameSpecifier *Qualifier,
863 SourceRange QualifierRange) {
864 CXXScopeSpec SS;
865 if (Qualifier) {
866 SS.setRange(QualifierRange);
867 SS.setScopeRep(Qualifier);
868 }
869
John McCall2d74de92009-12-01 22:10:20 +0000870 QualType BaseType = ((Expr*) Base.get())->getType();
871
Mike Stump11289f42009-09-09 15:08:12 +0000872 DeclarationName Name
Douglas Gregorad8a3362009-09-04 17:36:40 +0000873 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
874 SemaRef.Context.getCanonicalType(DestroyedType));
Mike Stump11289f42009-09-09 15:08:12 +0000875
John McCall2d74de92009-12-01 22:10:20 +0000876 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
877 OperatorLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +0000878 SS, /*FIXME: FirstQualifier*/ 0,
879 Name, DestroyedTypeLoc,
880 /*TemplateArgs*/ 0);
Mike Stump11289f42009-09-09 15:08:12 +0000881 }
882
Douglas Gregora16548e2009-08-11 05:31:07 +0000883 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000884 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000885 /// By default, performs semantic analysis to build the new expression.
886 /// Subclasses may override this routine to provide different behavior.
887 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
888 UnaryOperator::Opcode Opc,
889 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000890 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +0000891 }
Mike Stump11289f42009-09-09 15:08:12 +0000892
Douglas Gregora16548e2009-08-11 05:31:07 +0000893 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000894 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000895 /// By default, performs semantic analysis to build the new expression.
896 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +0000897 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +0000898 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000899 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +0000900 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +0000901 }
902
Mike Stump11289f42009-09-09 15:08:12 +0000903 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000904 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +0000905 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000906 /// By default, performs semantic analysis to build the new expression.
907 /// Subclasses may override this routine to provide different behavior.
908 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
909 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +0000910 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000911 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
912 OpLoc, isSizeOf, R);
913 if (Result.isInvalid())
914 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000915
Douglas Gregora16548e2009-08-11 05:31:07 +0000916 SubExpr.release();
917 return move(Result);
918 }
Mike Stump11289f42009-09-09 15:08:12 +0000919
Douglas Gregora16548e2009-08-11 05:31:07 +0000920 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +0000921 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000922 /// By default, performs semantic analysis to build the new expression.
923 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000924 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000925 SourceLocation LBracketLoc,
926 ExprArg RHS,
927 SourceLocation RBracketLoc) {
928 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000929 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000930 RBracketLoc);
931 }
932
933 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000934 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000935 /// By default, performs semantic analysis to build the new expression.
936 /// Subclasses may override this routine to provide different behavior.
937 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
938 MultiExprArg Args,
939 SourceLocation *CommaLocs,
940 SourceLocation RParenLoc) {
941 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
942 move(Args), CommaLocs, RParenLoc);
943 }
944
945 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000946 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000947 /// By default, performs semantic analysis to build the new expression.
948 /// Subclasses may override this routine to provide different behavior.
949 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000950 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000951 NestedNameSpecifier *Qualifier,
952 SourceRange QualifierRange,
953 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +0000954 ValueDecl *Member,
John McCall6b51f282009-11-23 01:53:49 +0000955 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000956 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +0000957 if (!Member->getDeclName()) {
958 // We have a reference to an unnamed field.
959 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +0000960
961 MemberExpr *ME =
Anders Carlsson5da84842009-09-01 04:26:58 +0000962 new (getSema().Context) MemberExpr(Base.takeAs<Expr>(), isArrow,
963 Member, MemberLoc,
964 cast<FieldDecl>(Member)->getType());
965 return getSema().Owned(ME);
966 }
Mike Stump11289f42009-09-09 15:08:12 +0000967
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000968 CXXScopeSpec SS;
969 if (Qualifier) {
970 SS.setRange(QualifierRange);
971 SS.setScopeRep(Qualifier);
972 }
973
John McCall2d74de92009-12-01 22:10:20 +0000974 QualType BaseType = ((Expr*) Base.get())->getType();
975
976 // FIXME: wait, this is re-performing lookup?
977 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
978 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +0000979 SS, FirstQualifierInScope,
980 Member->getDeclName(), MemberLoc,
981 ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +0000982 }
Mike Stump11289f42009-09-09 15:08:12 +0000983
Douglas Gregora16548e2009-08-11 05:31:07 +0000984 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000985 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000986 /// By default, performs semantic analysis to build the new expression.
987 /// Subclasses may override this routine to provide different behavior.
988 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
989 BinaryOperator::Opcode Opc,
990 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000991 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
992 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +0000993 }
994
995 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000996 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000997 /// By default, performs semantic analysis to build the new expression.
998 /// Subclasses may override this routine to provide different behavior.
999 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1000 SourceLocation QuestionLoc,
1001 ExprArg LHS,
1002 SourceLocation ColonLoc,
1003 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001004 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001005 move(LHS), move(RHS));
1006 }
1007
1008 /// \brief Build a new implicit cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001009 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001010 /// By default, builds a new implicit cast without any semantic analysis.
1011 /// Subclasses may override this routine to provide different behavior.
1012 OwningExprResult RebuildImplicitCastExpr(QualType T, CastExpr::CastKind Kind,
1013 ExprArg SubExpr, bool isLvalue) {
1014 ImplicitCastExpr *ICE
Mike Stump11289f42009-09-09 15:08:12 +00001015 = new (getSema().Context) ImplicitCastExpr(T, Kind,
Douglas Gregora16548e2009-08-11 05:31:07 +00001016 (Expr *)SubExpr.release(),
1017 isLvalue);
1018 return getSema().Owned(ICE);
1019 }
1020
1021 /// \brief Build a new C-style cast 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 RebuildCStyleCaseExpr(SourceLocation LParenLoc,
1026 QualType ExplicitTy,
1027 SourceLocation RParenLoc,
1028 ExprArg SubExpr) {
1029 return getSema().ActOnCastExpr(/*Scope=*/0,
1030 LParenLoc,
1031 ExplicitTy.getAsOpaquePtr(),
1032 RParenLoc,
1033 move(SubExpr));
1034 }
Mike Stump11289f42009-09-09 15:08:12 +00001035
Douglas Gregora16548e2009-08-11 05:31:07 +00001036 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001037 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001038 /// By default, performs semantic analysis to build the new expression.
1039 /// Subclasses may override this routine to provide different behavior.
1040 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
1041 QualType T,
1042 SourceLocation RParenLoc,
1043 ExprArg Init) {
1044 return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(),
1045 RParenLoc, move(Init));
1046 }
Mike Stump11289f42009-09-09 15:08:12 +00001047
Douglas Gregora16548e2009-08-11 05:31:07 +00001048 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001049 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001050 /// By default, performs semantic analysis to build the new expression.
1051 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001052 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001053 SourceLocation OpLoc,
1054 SourceLocation AccessorLoc,
1055 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001056
John McCall10eae182009-11-30 22:42:35 +00001057 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001058 QualType BaseType = ((Expr*) Base.get())->getType();
1059 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001060 OpLoc, /*IsArrow*/ false,
1061 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001062 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001063 AccessorLoc,
1064 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001065 }
Mike Stump11289f42009-09-09 15:08:12 +00001066
Douglas Gregora16548e2009-08-11 05:31:07 +00001067 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001068 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001069 /// By default, performs semantic analysis to build the new expression.
1070 /// Subclasses may override this routine to provide different behavior.
1071 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1072 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001073 SourceLocation RBraceLoc,
1074 QualType ResultTy) {
1075 OwningExprResult Result
1076 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1077 if (Result.isInvalid() || ResultTy->isDependentType())
1078 return move(Result);
1079
1080 // Patch in the result type we were given, which may have been computed
1081 // when the initial InitListExpr was built.
1082 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1083 ILE->setType(ResultTy);
1084 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001085 }
Mike Stump11289f42009-09-09 15:08:12 +00001086
Douglas Gregora16548e2009-08-11 05:31:07 +00001087 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001088 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001089 /// By default, performs semantic analysis to build the new expression.
1090 /// Subclasses may override this routine to provide different behavior.
1091 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1092 MultiExprArg ArrayExprs,
1093 SourceLocation EqualOrColonLoc,
1094 bool GNUSyntax,
1095 ExprArg Init) {
1096 OwningExprResult Result
1097 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1098 move(Init));
1099 if (Result.isInvalid())
1100 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001101
Douglas Gregora16548e2009-08-11 05:31:07 +00001102 ArrayExprs.release();
1103 return move(Result);
1104 }
Mike Stump11289f42009-09-09 15:08:12 +00001105
Douglas Gregora16548e2009-08-11 05:31:07 +00001106 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001107 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001108 /// By default, builds the implicit value initialization without performing
1109 /// any semantic analysis. Subclasses may override this routine to provide
1110 /// different behavior.
1111 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1112 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1113 }
Mike Stump11289f42009-09-09 15:08:12 +00001114
Douglas Gregora16548e2009-08-11 05:31:07 +00001115 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001116 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001117 /// By default, performs semantic analysis to build the new expression.
1118 /// Subclasses may override this routine to provide different behavior.
1119 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1120 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001121 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001122 RParenLoc);
1123 }
1124
1125 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001126 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001127 /// By default, performs semantic analysis to build the new expression.
1128 /// Subclasses may override this routine to provide different behavior.
1129 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1130 MultiExprArg SubExprs,
1131 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001132 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1133 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001134 }
Mike Stump11289f42009-09-09 15:08:12 +00001135
Douglas Gregora16548e2009-08-11 05:31:07 +00001136 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001137 ///
1138 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001139 /// rather than attempting to map the label statement itself.
1140 /// Subclasses may override this routine to provide different behavior.
1141 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1142 SourceLocation LabelLoc,
1143 LabelStmt *Label) {
1144 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1145 }
Mike Stump11289f42009-09-09 15:08:12 +00001146
Douglas Gregora16548e2009-08-11 05:31:07 +00001147 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001148 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001149 /// By default, performs semantic analysis to build the new expression.
1150 /// Subclasses may override this routine to provide different behavior.
1151 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1152 StmtArg SubStmt,
1153 SourceLocation RParenLoc) {
1154 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1155 }
Mike Stump11289f42009-09-09 15:08:12 +00001156
Douglas Gregora16548e2009-08-11 05:31:07 +00001157 /// \brief Build a new __builtin_types_compatible_p expression.
1158 ///
1159 /// By default, performs semantic analysis to build the new expression.
1160 /// Subclasses may override this routine to provide different behavior.
1161 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1162 QualType T1, QualType T2,
1163 SourceLocation RParenLoc) {
1164 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1165 T1.getAsOpaquePtr(),
1166 T2.getAsOpaquePtr(),
1167 RParenLoc);
1168 }
Mike Stump11289f42009-09-09 15:08:12 +00001169
Douglas Gregora16548e2009-08-11 05:31:07 +00001170 /// \brief Build a new __builtin_choose_expr expression.
1171 ///
1172 /// By default, performs semantic analysis to build the new expression.
1173 /// Subclasses may override this routine to provide different behavior.
1174 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1175 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1176 SourceLocation RParenLoc) {
1177 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1178 move(Cond), move(LHS), move(RHS),
1179 RParenLoc);
1180 }
Mike Stump11289f42009-09-09 15:08:12 +00001181
Douglas Gregora16548e2009-08-11 05:31:07 +00001182 /// \brief Build a new overloaded operator call expression.
1183 ///
1184 /// By default, performs semantic analysis to build the new expression.
1185 /// The semantic analysis provides the behavior of template instantiation,
1186 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001187 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001188 /// argument-dependent lookup, etc. Subclasses may override this routine to
1189 /// provide different behavior.
1190 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1191 SourceLocation OpLoc,
1192 ExprArg Callee,
1193 ExprArg First,
1194 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001195
1196 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001197 /// reinterpret_cast.
1198 ///
1199 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001200 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001201 /// Subclasses may override this routine to provide different behavior.
1202 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1203 Stmt::StmtClass Class,
1204 SourceLocation LAngleLoc,
1205 QualType T,
1206 SourceLocation RAngleLoc,
1207 SourceLocation LParenLoc,
1208 ExprArg SubExpr,
1209 SourceLocation RParenLoc) {
1210 switch (Class) {
1211 case Stmt::CXXStaticCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001212 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T,
1213 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001214 move(SubExpr), RParenLoc);
1215
1216 case Stmt::CXXDynamicCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001217 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T,
1218 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001219 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001220
Douglas Gregora16548e2009-08-11 05:31:07 +00001221 case Stmt::CXXReinterpretCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001222 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T,
1223 RAngleLoc, LParenLoc,
1224 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001225 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001226
Douglas Gregora16548e2009-08-11 05:31:07 +00001227 case Stmt::CXXConstCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001228 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T,
1229 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001230 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001231
Douglas Gregora16548e2009-08-11 05:31:07 +00001232 default:
1233 assert(false && "Invalid C++ named cast");
1234 break;
1235 }
Mike Stump11289f42009-09-09 15:08:12 +00001236
Douglas Gregora16548e2009-08-11 05:31:07 +00001237 return getSema().ExprError();
1238 }
Mike Stump11289f42009-09-09 15:08:12 +00001239
Douglas Gregora16548e2009-08-11 05:31:07 +00001240 /// \brief Build a new C++ static_cast expression.
1241 ///
1242 /// By default, performs semantic analysis to build the new expression.
1243 /// Subclasses may override this routine to provide different behavior.
1244 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1245 SourceLocation LAngleLoc,
1246 QualType T,
1247 SourceLocation RAngleLoc,
1248 SourceLocation LParenLoc,
1249 ExprArg SubExpr,
1250 SourceLocation RParenLoc) {
1251 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001252 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001253 LParenLoc, move(SubExpr), RParenLoc);
1254 }
1255
1256 /// \brief Build a new C++ dynamic_cast expression.
1257 ///
1258 /// By default, performs semantic analysis to build the new expression.
1259 /// Subclasses may override this routine to provide different behavior.
1260 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1261 SourceLocation LAngleLoc,
1262 QualType T,
1263 SourceLocation RAngleLoc,
1264 SourceLocation LParenLoc,
1265 ExprArg SubExpr,
1266 SourceLocation RParenLoc) {
1267 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001268 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001269 LParenLoc, move(SubExpr), RParenLoc);
1270 }
1271
1272 /// \brief Build a new C++ reinterpret_cast expression.
1273 ///
1274 /// By default, performs semantic analysis to build the new expression.
1275 /// Subclasses may override this routine to provide different behavior.
1276 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1277 SourceLocation LAngleLoc,
1278 QualType T,
1279 SourceLocation RAngleLoc,
1280 SourceLocation LParenLoc,
1281 ExprArg SubExpr,
1282 SourceLocation RParenLoc) {
1283 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1284 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
1285 LParenLoc, move(SubExpr), RParenLoc);
1286 }
1287
1288 /// \brief Build a new C++ const_cast expression.
1289 ///
1290 /// By default, performs semantic analysis to build the new expression.
1291 /// Subclasses may override this routine to provide different behavior.
1292 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1293 SourceLocation LAngleLoc,
1294 QualType T,
1295 SourceLocation RAngleLoc,
1296 SourceLocation LParenLoc,
1297 ExprArg SubExpr,
1298 SourceLocation RParenLoc) {
1299 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001300 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001301 LParenLoc, move(SubExpr), RParenLoc);
1302 }
Mike Stump11289f42009-09-09 15:08:12 +00001303
Douglas Gregora16548e2009-08-11 05:31:07 +00001304 /// \brief Build a new C++ functional-style cast expression.
1305 ///
1306 /// By default, performs semantic analysis to build the new expression.
1307 /// Subclasses may override this routine to provide different behavior.
1308 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
1309 QualType T,
1310 SourceLocation LParenLoc,
1311 ExprArg SubExpr,
1312 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001313 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001314 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
1315 T.getAsOpaquePtr(),
1316 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001317 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001318 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 RParenLoc);
1320 }
Mike Stump11289f42009-09-09 15:08:12 +00001321
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 /// \brief Build a new C++ typeid(type) expression.
1323 ///
1324 /// By default, performs semantic analysis to build the new expression.
1325 /// Subclasses may override this routine to provide different behavior.
1326 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1327 SourceLocation LParenLoc,
1328 QualType T,
1329 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001330 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 T.getAsOpaquePtr(), RParenLoc);
1332 }
Mike Stump11289f42009-09-09 15:08:12 +00001333
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 /// \brief Build a new C++ typeid(expr) expression.
1335 ///
1336 /// By default, performs semantic analysis to build the new expression.
1337 /// Subclasses may override this routine to provide different behavior.
1338 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1339 SourceLocation LParenLoc,
1340 ExprArg Operand,
1341 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001342 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1344 RParenLoc);
1345 if (Result.isInvalid())
1346 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001347
Douglas Gregora16548e2009-08-11 05:31:07 +00001348 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1349 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001350 }
1351
Douglas Gregora16548e2009-08-11 05:31:07 +00001352 /// \brief Build a new C++ "this" expression.
1353 ///
1354 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001355 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001356 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001357 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001358 QualType ThisType) {
1359 return getSema().Owned(
1360 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType));
1361 }
1362
1363 /// \brief Build a new C++ throw expression.
1364 ///
1365 /// By default, performs semantic analysis to build the new expression.
1366 /// Subclasses may override this routine to provide different behavior.
1367 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1368 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1369 }
1370
1371 /// \brief Build a new C++ default-argument expression.
1372 ///
1373 /// By default, builds a new default-argument expression, which does not
1374 /// require any semantic analysis. Subclasses may override this routine to
1375 /// provide different behavior.
1376 OwningExprResult RebuildCXXDefaultArgExpr(ParmVarDecl *Param) {
Anders Carlssone8271232009-08-14 18:30:22 +00001377 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001378 }
1379
1380 /// \brief Build a new C++ zero-initialization expression.
1381 ///
1382 /// By default, performs semantic analysis to build the new expression.
1383 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001384 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001385 SourceLocation LParenLoc,
1386 QualType T,
1387 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001388 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1389 T.getAsOpaquePtr(), LParenLoc,
1390 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001391 0, RParenLoc);
1392 }
Mike Stump11289f42009-09-09 15:08:12 +00001393
Douglas Gregora16548e2009-08-11 05:31:07 +00001394 /// \brief Build a new C++ "new" expression.
1395 ///
1396 /// By default, performs semantic analysis to build the new expression.
1397 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001398 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001399 bool UseGlobal,
1400 SourceLocation PlacementLParen,
1401 MultiExprArg PlacementArgs,
1402 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001403 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 QualType AllocType,
1405 SourceLocation TypeLoc,
1406 SourceRange TypeRange,
1407 ExprArg ArraySize,
1408 SourceLocation ConstructorLParen,
1409 MultiExprArg ConstructorArgs,
1410 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001411 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 PlacementLParen,
1413 move(PlacementArgs),
1414 PlacementRParen,
1415 ParenTypeId,
1416 AllocType,
1417 TypeLoc,
1418 TypeRange,
1419 move(ArraySize),
1420 ConstructorLParen,
1421 move(ConstructorArgs),
1422 ConstructorRParen);
1423 }
Mike Stump11289f42009-09-09 15:08:12 +00001424
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 /// \brief Build a new C++ "delete" expression.
1426 ///
1427 /// By default, performs semantic analysis to build the new expression.
1428 /// Subclasses may override this routine to provide different behavior.
1429 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1430 bool IsGlobalDelete,
1431 bool IsArrayForm,
1432 ExprArg Operand) {
1433 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1434 move(Operand));
1435 }
Mike Stump11289f42009-09-09 15:08:12 +00001436
Douglas Gregora16548e2009-08-11 05:31:07 +00001437 /// \brief Build a new unary type trait expression.
1438 ///
1439 /// By default, performs semantic analysis to build the new expression.
1440 /// Subclasses may override this routine to provide different behavior.
1441 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1442 SourceLocation StartLoc,
1443 SourceLocation LParenLoc,
1444 QualType T,
1445 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001446 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001447 T.getAsOpaquePtr(), RParenLoc);
1448 }
1449
Mike Stump11289f42009-09-09 15:08:12 +00001450 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001451 /// expression.
1452 ///
1453 /// By default, performs semantic analysis to build the new expression.
1454 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001455 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 SourceRange QualifierRange,
1457 DeclarationName Name,
1458 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001459 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001460 CXXScopeSpec SS;
1461 SS.setRange(QualifierRange);
1462 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001463
1464 if (TemplateArgs)
1465 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1466 *TemplateArgs);
1467
1468 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001469 }
1470
1471 /// \brief Build a new template-id expression.
1472 ///
1473 /// By default, performs semantic analysis to build the new expression.
1474 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001475 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1476 LookupResult &R,
1477 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001478 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001479 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001480 }
1481
1482 /// \brief Build a new object-construction expression.
1483 ///
1484 /// By default, performs semantic analysis to build the new expression.
1485 /// Subclasses may override this routine to provide different behavior.
1486 OwningExprResult RebuildCXXConstructExpr(QualType T,
1487 CXXConstructorDecl *Constructor,
1488 bool IsElidable,
1489 MultiExprArg Args) {
Anders Carlsson1b4ebfa2009-09-05 07:40:38 +00001490 return getSema().BuildCXXConstructExpr(/*FIXME:ConstructLoc*/
1491 SourceLocation(),
1492 T, Constructor, IsElidable,
Anders Carlsson5995a3e2009-09-07 22:23:31 +00001493 move(Args));
Douglas Gregora16548e2009-08-11 05:31:07 +00001494 }
1495
1496 /// \brief Build a new object-construction expression.
1497 ///
1498 /// By default, performs semantic analysis to build the new expression.
1499 /// Subclasses may override this routine to provide different behavior.
1500 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1501 QualType T,
1502 SourceLocation LParenLoc,
1503 MultiExprArg Args,
1504 SourceLocation *Commas,
1505 SourceLocation RParenLoc) {
1506 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1507 T.getAsOpaquePtr(),
1508 LParenLoc,
1509 move(Args),
1510 Commas,
1511 RParenLoc);
1512 }
1513
1514 /// \brief Build a new object-construction expression.
1515 ///
1516 /// By default, performs semantic analysis to build the new expression.
1517 /// Subclasses may override this routine to provide different behavior.
1518 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1519 QualType T,
1520 SourceLocation LParenLoc,
1521 MultiExprArg Args,
1522 SourceLocation *Commas,
1523 SourceLocation RParenLoc) {
1524 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1525 /*FIXME*/LParenLoc),
1526 T.getAsOpaquePtr(),
1527 LParenLoc,
1528 move(Args),
1529 Commas,
1530 RParenLoc);
1531 }
Mike Stump11289f42009-09-09 15:08:12 +00001532
Douglas Gregora16548e2009-08-11 05:31:07 +00001533 /// \brief Build a new member reference expression.
1534 ///
1535 /// By default, performs semantic analysis to build the new expression.
1536 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001537 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001538 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001539 bool IsArrow,
1540 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001541 NestedNameSpecifier *Qualifier,
1542 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001543 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001544 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001545 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001546 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001547 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001548 SS.setRange(QualifierRange);
1549 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001550
John McCall2d74de92009-12-01 22:10:20 +00001551 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1552 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001553 SS, FirstQualifierInScope,
1554 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001555 }
1556
John McCall10eae182009-11-30 22:42:35 +00001557 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001558 ///
1559 /// By default, performs semantic analysis to build the new expression.
1560 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001561 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001562 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001563 SourceLocation OperatorLoc,
1564 bool IsArrow,
1565 NestedNameSpecifier *Qualifier,
1566 SourceRange QualifierRange,
1567 LookupResult &R,
1568 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001569 CXXScopeSpec SS;
1570 SS.setRange(QualifierRange);
1571 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001572
John McCall2d74de92009-12-01 22:10:20 +00001573 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1574 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001575 SS, R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001576 }
Mike Stump11289f42009-09-09 15:08:12 +00001577
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 /// \brief Build a new Objective-C @encode 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 RebuildObjCEncodeExpr(SourceLocation AtLoc,
1583 QualType T,
1584 SourceLocation RParenLoc) {
1585 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1586 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001587 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001588
1589 /// \brief Build a new Objective-C protocol expression.
1590 ///
1591 /// By default, performs semantic analysis to build the new expression.
1592 /// Subclasses may override this routine to provide different behavior.
1593 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1594 SourceLocation AtLoc,
1595 SourceLocation ProtoLoc,
1596 SourceLocation LParenLoc,
1597 SourceLocation RParenLoc) {
1598 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1599 Protocol->getIdentifier(),
1600 AtLoc,
1601 ProtoLoc,
1602 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001603 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001604 }
Mike Stump11289f42009-09-09 15:08:12 +00001605
Douglas Gregora16548e2009-08-11 05:31:07 +00001606 /// \brief Build a new shuffle vector expression.
1607 ///
1608 /// By default, performs semantic analysis to build the new expression.
1609 /// Subclasses may override this routine to provide different behavior.
1610 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1611 MultiExprArg SubExprs,
1612 SourceLocation RParenLoc) {
1613 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001614 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1616 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1617 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1618 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001619
Douglas Gregora16548e2009-08-11 05:31:07 +00001620 // Build a reference to the __builtin_shufflevector builtin
1621 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001622 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001623 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001624 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001626
1627 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 unsigned NumSubExprs = SubExprs.size();
1629 Expr **Subs = (Expr **)SubExprs.release();
1630 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1631 Subs, NumSubExprs,
1632 Builtin->getResultType(),
1633 RParenLoc);
1634 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001635
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 // Type-check the __builtin_shufflevector expression.
1637 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1638 if (Result.isInvalid())
1639 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001640
Douglas Gregora16548e2009-08-11 05:31:07 +00001641 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001642 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001644};
Douglas Gregora16548e2009-08-11 05:31:07 +00001645
Douglas Gregorebe10102009-08-20 07:17:43 +00001646template<typename Derived>
1647Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1648 if (!S)
1649 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001650
Douglas Gregorebe10102009-08-20 07:17:43 +00001651 switch (S->getStmtClass()) {
1652 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001653
Douglas Gregorebe10102009-08-20 07:17:43 +00001654 // Transform individual statement nodes
1655#define STMT(Node, Parent) \
1656 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1657#define EXPR(Node, Parent)
1658#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001659
Douglas Gregorebe10102009-08-20 07:17:43 +00001660 // Transform expressions by calling TransformExpr.
1661#define STMT(Node, Parent)
1662#define EXPR(Node, Parent) case Stmt::Node##Class:
1663#include "clang/AST/StmtNodes.def"
1664 {
1665 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1666 if (E.isInvalid())
1667 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001668
Douglas Gregor07eae022009-11-13 18:34:26 +00001669 return getSema().ActOnExprStmt(getSema().FullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001670 }
Mike Stump11289f42009-09-09 15:08:12 +00001671 }
1672
Douglas Gregorebe10102009-08-20 07:17:43 +00001673 return SemaRef.Owned(S->Retain());
1674}
Mike Stump11289f42009-09-09 15:08:12 +00001675
1676
Douglas Gregore922c772009-08-04 22:27:00 +00001677template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00001678Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E,
1679 bool isAddressOfOperand) {
1680 if (!E)
1681 return SemaRef.Owned(E);
1682
1683 switch (E->getStmtClass()) {
1684 case Stmt::NoStmtClass: break;
1685#define STMT(Node, Parent) case Stmt::Node##Class: break;
1686#define EXPR(Node, Parent) \
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00001687 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E), \
1688 isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001689#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001690 }
1691
Douglas Gregora16548e2009-08-11 05:31:07 +00001692 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001693}
1694
1695template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001696NestedNameSpecifier *
1697TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001698 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001699 QualType ObjectType,
1700 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001701 if (!NNS)
1702 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001703
Douglas Gregorebe10102009-08-20 07:17:43 +00001704 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001705 NestedNameSpecifier *Prefix = NNS->getPrefix();
1706 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001707 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001708 ObjectType,
1709 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001710 if (!Prefix)
1711 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001712
1713 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001714 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001715 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001716 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001717 }
Mike Stump11289f42009-09-09 15:08:12 +00001718
Douglas Gregor1135c352009-08-06 05:28:30 +00001719 switch (NNS->getKind()) {
1720 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001721 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001722 "Identifier nested-name-specifier with no prefix or object type");
1723 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1724 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001725 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001726
1727 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001728 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001729 ObjectType,
1730 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001731
Douglas Gregor1135c352009-08-06 05:28:30 +00001732 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001733 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001734 = cast_or_null<NamespaceDecl>(
1735 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001736 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001737 Prefix == NNS->getPrefix() &&
1738 NS == NNS->getAsNamespace())
1739 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001740
Douglas Gregor1135c352009-08-06 05:28:30 +00001741 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1742 }
Mike Stump11289f42009-09-09 15:08:12 +00001743
Douglas Gregor1135c352009-08-06 05:28:30 +00001744 case NestedNameSpecifier::Global:
1745 // There is no meaningful transformation that one could perform on the
1746 // global scope.
1747 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001748
Douglas Gregor1135c352009-08-06 05:28:30 +00001749 case NestedNameSpecifier::TypeSpecWithTemplate:
1750 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001751 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor1135c352009-08-06 05:28:30 +00001752 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001753 if (T.isNull())
1754 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001755
Douglas Gregor1135c352009-08-06 05:28:30 +00001756 if (!getDerived().AlwaysRebuild() &&
1757 Prefix == NNS->getPrefix() &&
1758 T == QualType(NNS->getAsType(), 0))
1759 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001760
1761 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1762 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregor1135c352009-08-06 05:28:30 +00001763 T);
1764 }
1765 }
Mike Stump11289f42009-09-09 15:08:12 +00001766
Douglas Gregor1135c352009-08-06 05:28:30 +00001767 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001768 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001769}
1770
1771template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001772DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001773TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001774 SourceLocation Loc,
1775 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001776 if (!Name)
1777 return Name;
1778
1779 switch (Name.getNameKind()) {
1780 case DeclarationName::Identifier:
1781 case DeclarationName::ObjCZeroArgSelector:
1782 case DeclarationName::ObjCOneArgSelector:
1783 case DeclarationName::ObjCMultiArgSelector:
1784 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001785 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001786 case DeclarationName::CXXUsingDirective:
1787 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001788
Douglas Gregorf816bd72009-09-03 22:13:48 +00001789 case DeclarationName::CXXConstructorName:
1790 case DeclarationName::CXXDestructorName:
1791 case DeclarationName::CXXConversionFunctionName: {
1792 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorc59e5612009-10-19 22:04:39 +00001793 QualType T;
1794 if (!ObjectType.isNull() &&
1795 isa<TemplateSpecializationType>(Name.getCXXNameType())) {
1796 TemplateSpecializationType *SpecType
1797 = cast<TemplateSpecializationType>(Name.getCXXNameType());
1798 T = TransformTemplateSpecializationType(SpecType, ObjectType);
1799 } else
1800 T = getDerived().TransformType(Name.getCXXNameType());
Douglas Gregorf816bd72009-09-03 22:13:48 +00001801 if (T.isNull())
1802 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001803
Douglas Gregorf816bd72009-09-03 22:13:48 +00001804 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001805 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001806 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001807 }
Mike Stump11289f42009-09-09 15:08:12 +00001808 }
1809
Douglas Gregorf816bd72009-09-03 22:13:48 +00001810 return DeclarationName();
1811}
1812
1813template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001814TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001815TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1816 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00001817 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001818 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001819 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1820 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1821 if (!NNS)
1822 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001823
Douglas Gregor71dc5092009-08-06 06:41:21 +00001824 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001825 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001826 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1827 if (!TransTemplate)
1828 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001829
Douglas Gregor71dc5092009-08-06 06:41:21 +00001830 if (!getDerived().AlwaysRebuild() &&
1831 NNS == QTN->getQualifier() &&
1832 TransTemplate == Template)
1833 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001834
Douglas Gregor71dc5092009-08-06 06:41:21 +00001835 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1836 TransTemplate);
1837 }
Mike Stump11289f42009-09-09 15:08:12 +00001838
John McCalle66edc12009-11-24 19:00:30 +00001839 // These should be getting filtered out before they make it into the AST.
1840 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001841 }
Mike Stump11289f42009-09-09 15:08:12 +00001842
Douglas Gregor71dc5092009-08-06 06:41:21 +00001843 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001844 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001845 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1846 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor308047d2009-09-09 00:23:06 +00001847 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001848 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001849
Douglas Gregor71dc5092009-08-06 06:41:21 +00001850 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001851 NNS == DTN->getQualifier() &&
1852 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001853 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001854
Douglas Gregor71395fa2009-11-04 00:56:37 +00001855 if (DTN->isIdentifier())
1856 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1857 ObjectType);
1858
1859 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1860 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001861 }
Mike Stump11289f42009-09-09 15:08:12 +00001862
Douglas Gregor71dc5092009-08-06 06:41:21 +00001863 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001864 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001865 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1866 if (!TransTemplate)
1867 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001868
Douglas Gregor71dc5092009-08-06 06:41:21 +00001869 if (!getDerived().AlwaysRebuild() &&
1870 TransTemplate == Template)
1871 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001872
Douglas Gregor71dc5092009-08-06 06:41:21 +00001873 return TemplateName(TransTemplate);
1874 }
Mike Stump11289f42009-09-09 15:08:12 +00001875
John McCalle66edc12009-11-24 19:00:30 +00001876 // These should be getting filtered out before they reach the AST.
1877 assert(false && "overloaded function decl survived to here");
1878 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00001879}
1880
1881template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001882void TreeTransform<Derived>::InventTemplateArgumentLoc(
1883 const TemplateArgument &Arg,
1884 TemplateArgumentLoc &Output) {
1885 SourceLocation Loc = getDerived().getBaseLocation();
1886 switch (Arg.getKind()) {
1887 case TemplateArgument::Null:
1888 llvm::llvm_unreachable("null template argument in TreeTransform");
1889 break;
1890
1891 case TemplateArgument::Type:
1892 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00001893 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00001894
1895 break;
1896
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001897 case TemplateArgument::Template:
1898 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1899 break;
1900
John McCall0ad16662009-10-29 08:12:44 +00001901 case TemplateArgument::Expression:
1902 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1903 break;
1904
1905 case TemplateArgument::Declaration:
1906 case TemplateArgument::Integral:
1907 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00001908 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00001909 break;
1910 }
1911}
1912
1913template<typename Derived>
1914bool TreeTransform<Derived>::TransformTemplateArgument(
1915 const TemplateArgumentLoc &Input,
1916 TemplateArgumentLoc &Output) {
1917 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00001918 switch (Arg.getKind()) {
1919 case TemplateArgument::Null:
1920 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001921 Output = Input;
1922 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001923
Douglas Gregore922c772009-08-04 22:27:00 +00001924 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00001925 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00001926 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00001927 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00001928
1929 DI = getDerived().TransformType(DI);
1930 if (!DI) return true;
1931
1932 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1933 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001934 }
Mike Stump11289f42009-09-09 15:08:12 +00001935
Douglas Gregore922c772009-08-04 22:27:00 +00001936 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001937 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001938 DeclarationName Name;
1939 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1940 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001941 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregore922c772009-08-04 22:27:00 +00001942 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001943 if (!D) return true;
1944
John McCall0d07eb32009-10-29 18:45:58 +00001945 Expr *SourceExpr = Input.getSourceDeclExpression();
1946 if (SourceExpr) {
1947 EnterExpressionEvaluationContext Unevaluated(getSema(),
1948 Action::Unevaluated);
1949 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1950 if (E.isInvalid())
1951 SourceExpr = NULL;
1952 else {
1953 SourceExpr = E.takeAs<Expr>();
1954 SourceExpr->Retain();
1955 }
1956 }
1957
1958 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00001959 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001960 }
Mike Stump11289f42009-09-09 15:08:12 +00001961
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001962 case TemplateArgument::Template: {
1963 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1964 TemplateName Template
1965 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1966 if (Template.isNull())
1967 return true;
1968
1969 Output = TemplateArgumentLoc(TemplateArgument(Template),
1970 Input.getTemplateQualifierRange(),
1971 Input.getTemplateNameLoc());
1972 return false;
1973 }
1974
Douglas Gregore922c772009-08-04 22:27:00 +00001975 case TemplateArgument::Expression: {
1976 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00001977 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00001978 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00001979
John McCall0ad16662009-10-29 08:12:44 +00001980 Expr *InputExpr = Input.getSourceExpression();
1981 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
1982
1983 Sema::OwningExprResult E
1984 = getDerived().TransformExpr(InputExpr);
1985 if (E.isInvalid()) return true;
1986
1987 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00001988 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00001989 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
1990 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001991 }
Mike Stump11289f42009-09-09 15:08:12 +00001992
Douglas Gregore922c772009-08-04 22:27:00 +00001993 case TemplateArgument::Pack: {
1994 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
1995 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00001996 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00001997 AEnd = Arg.pack_end();
1998 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00001999
John McCall0ad16662009-10-29 08:12:44 +00002000 // FIXME: preserve source information here when we start
2001 // caring about parameter packs.
2002
John McCall0d07eb32009-10-29 18:45:58 +00002003 TemplateArgumentLoc InputArg;
2004 TemplateArgumentLoc OutputArg;
2005 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2006 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002007 return true;
2008
John McCall0d07eb32009-10-29 18:45:58 +00002009 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002010 }
2011 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002012 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002013 true);
John McCall0d07eb32009-10-29 18:45:58 +00002014 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002015 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002016 }
2017 }
Mike Stump11289f42009-09-09 15:08:12 +00002018
Douglas Gregore922c772009-08-04 22:27:00 +00002019 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002020 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002021}
2022
Douglas Gregord6ff3322009-08-04 16:50:30 +00002023//===----------------------------------------------------------------------===//
2024// Type transformation
2025//===----------------------------------------------------------------------===//
2026
2027template<typename Derived>
2028QualType TreeTransform<Derived>::TransformType(QualType T) {
2029 if (getDerived().AlreadyTransformed(T))
2030 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002031
John McCall550e0c22009-10-21 00:40:46 +00002032 // Temporary workaround. All of these transformations should
2033 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002034 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002035 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002036
John McCallbcd03502009-12-07 02:54:59 +00002037 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002038
John McCall550e0c22009-10-21 00:40:46 +00002039 if (!NewDI)
2040 return QualType();
2041
2042 return NewDI->getType();
2043}
2044
2045template<typename Derived>
John McCallbcd03502009-12-07 02:54:59 +00002046TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002047 if (getDerived().AlreadyTransformed(DI->getType()))
2048 return DI;
2049
2050 TypeLocBuilder TLB;
2051
2052 TypeLoc TL = DI->getTypeLoc();
2053 TLB.reserve(TL.getFullDataSize());
2054
2055 QualType Result = getDerived().TransformType(TLB, TL);
2056 if (Result.isNull())
2057 return 0;
2058
John McCallbcd03502009-12-07 02:54:59 +00002059 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002060}
2061
2062template<typename Derived>
2063QualType
2064TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
2065 switch (T.getTypeLocClass()) {
2066#define ABSTRACT_TYPELOC(CLASS, PARENT)
2067#define TYPELOC(CLASS, PARENT) \
2068 case TypeLoc::CLASS: \
2069 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2070#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002071 }
Mike Stump11289f42009-09-09 15:08:12 +00002072
John McCall550e0c22009-10-21 00:40:46 +00002073 llvm::llvm_unreachable("unhandled type loc!");
2074 return QualType();
2075}
2076
2077/// FIXME: By default, this routine adds type qualifiers only to types
2078/// that can have qualifiers, and silently suppresses those qualifiers
2079/// that are not permitted (e.g., qualifiers on reference or function
2080/// types). This is the right thing for template instantiation, but
2081/// probably not for other clients.
2082template<typename Derived>
2083QualType
2084TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
2085 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002086 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002087
2088 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2089 if (Result.isNull())
2090 return QualType();
2091
2092 // Silently suppress qualifiers if the result type can't be qualified.
2093 // FIXME: this is the right thing for template instantiation, but
2094 // probably not for other clients.
2095 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002096 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002097
John McCall550e0c22009-10-21 00:40:46 +00002098 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2099
2100 TLB.push<QualifiedTypeLoc>(Result);
2101
2102 // No location information to preserve.
2103
2104 return Result;
2105}
2106
2107template <class TyLoc> static inline
2108QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2109 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2110 NewT.setNameLoc(T.getNameLoc());
2111 return T.getType();
2112}
2113
2114// Ugly metaprogramming macros because I couldn't be bothered to make
2115// the equivalent template version work.
2116#define TransformPointerLikeType(TypeClass) do { \
2117 QualType PointeeType \
2118 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2119 if (PointeeType.isNull()) \
2120 return QualType(); \
2121 \
2122 QualType Result = TL.getType(); \
2123 if (getDerived().AlwaysRebuild() || \
2124 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall70dd5f62009-10-30 00:06:24 +00002125 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2126 TL.getSigilLoc()); \
John McCall550e0c22009-10-21 00:40:46 +00002127 if (Result.isNull()) \
2128 return QualType(); \
2129 } \
2130 \
2131 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2132 NewT.setSigilLoc(TL.getSigilLoc()); \
2133 \
2134 return Result; \
2135} while(0)
2136
John McCall550e0c22009-10-21 00:40:46 +00002137template<typename Derived>
2138QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
2139 BuiltinTypeLoc T) {
2140 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002141}
Mike Stump11289f42009-09-09 15:08:12 +00002142
Douglas Gregord6ff3322009-08-04 16:50:30 +00002143template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002144QualType
John McCall550e0c22009-10-21 00:40:46 +00002145TreeTransform<Derived>::TransformFixedWidthIntType(TypeLocBuilder &TLB,
2146 FixedWidthIntTypeLoc T) {
2147 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002148}
Argyrios Kyrtzidise9189262009-08-19 01:28:17 +00002149
Douglas Gregord6ff3322009-08-04 16:50:30 +00002150template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002151QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
2152 ComplexTypeLoc T) {
2153 // FIXME: recurse?
2154 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002155}
Mike Stump11289f42009-09-09 15:08:12 +00002156
Douglas Gregord6ff3322009-08-04 16:50:30 +00002157template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002158QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
2159 PointerTypeLoc TL) {
2160 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002161}
Mike Stump11289f42009-09-09 15:08:12 +00002162
2163template<typename Derived>
2164QualType
John McCall550e0c22009-10-21 00:40:46 +00002165TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
2166 BlockPointerTypeLoc TL) {
2167 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002168}
2169
John McCall70dd5f62009-10-30 00:06:24 +00002170/// Transforms a reference type. Note that somewhat paradoxically we
2171/// don't care whether the type itself is an l-value type or an r-value
2172/// type; we only care if the type was *written* as an l-value type
2173/// or an r-value type.
2174template<typename Derived>
2175QualType
2176TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
2177 ReferenceTypeLoc TL) {
2178 const ReferenceType *T = TL.getTypePtr();
2179
2180 // Note that this works with the pointee-as-written.
2181 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2182 if (PointeeType.isNull())
2183 return QualType();
2184
2185 QualType Result = TL.getType();
2186 if (getDerived().AlwaysRebuild() ||
2187 PointeeType != T->getPointeeTypeAsWritten()) {
2188 Result = getDerived().RebuildReferenceType(PointeeType,
2189 T->isSpelledAsLValue(),
2190 TL.getSigilLoc());
2191 if (Result.isNull())
2192 return QualType();
2193 }
2194
2195 // r-value references can be rebuilt as l-value references.
2196 ReferenceTypeLoc NewTL;
2197 if (isa<LValueReferenceType>(Result))
2198 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2199 else
2200 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2201 NewTL.setSigilLoc(TL.getSigilLoc());
2202
2203 return Result;
2204}
2205
Mike Stump11289f42009-09-09 15:08:12 +00002206template<typename Derived>
2207QualType
John McCall550e0c22009-10-21 00:40:46 +00002208TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
2209 LValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002210 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002211}
2212
Mike Stump11289f42009-09-09 15:08:12 +00002213template<typename Derived>
2214QualType
John McCall550e0c22009-10-21 00:40:46 +00002215TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
2216 RValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002217 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002218}
Mike Stump11289f42009-09-09 15:08:12 +00002219
Douglas Gregord6ff3322009-08-04 16:50:30 +00002220template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002221QualType
John McCall550e0c22009-10-21 00:40:46 +00002222TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
2223 MemberPointerTypeLoc TL) {
2224 MemberPointerType *T = TL.getTypePtr();
2225
2226 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002227 if (PointeeType.isNull())
2228 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002229
John McCall550e0c22009-10-21 00:40:46 +00002230 // TODO: preserve source information for this.
2231 QualType ClassType
2232 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002233 if (ClassType.isNull())
2234 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002235
John McCall550e0c22009-10-21 00:40:46 +00002236 QualType Result = TL.getType();
2237 if (getDerived().AlwaysRebuild() ||
2238 PointeeType != T->getPointeeType() ||
2239 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002240 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2241 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002242 if (Result.isNull())
2243 return QualType();
2244 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002245
John McCall550e0c22009-10-21 00:40:46 +00002246 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2247 NewTL.setSigilLoc(TL.getSigilLoc());
2248
2249 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002250}
2251
Mike Stump11289f42009-09-09 15:08:12 +00002252template<typename Derived>
2253QualType
John McCall550e0c22009-10-21 00:40:46 +00002254TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
2255 ConstantArrayTypeLoc TL) {
2256 ConstantArrayType *T = TL.getTypePtr();
2257 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002258 if (ElementType.isNull())
2259 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002260
John McCall550e0c22009-10-21 00:40:46 +00002261 QualType Result = TL.getType();
2262 if (getDerived().AlwaysRebuild() ||
2263 ElementType != T->getElementType()) {
2264 Result = getDerived().RebuildConstantArrayType(ElementType,
2265 T->getSizeModifier(),
2266 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002267 T->getIndexTypeCVRQualifiers(),
2268 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002269 if (Result.isNull())
2270 return QualType();
2271 }
2272
2273 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2274 NewTL.setLBracketLoc(TL.getLBracketLoc());
2275 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002276
John McCall550e0c22009-10-21 00:40:46 +00002277 Expr *Size = TL.getSizeExpr();
2278 if (Size) {
2279 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2280 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2281 }
2282 NewTL.setSizeExpr(Size);
2283
2284 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002285}
Mike Stump11289f42009-09-09 15:08:12 +00002286
Douglas Gregord6ff3322009-08-04 16:50:30 +00002287template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002288QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002289 TypeLocBuilder &TLB,
2290 IncompleteArrayTypeLoc TL) {
2291 IncompleteArrayType *T = TL.getTypePtr();
2292 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002293 if (ElementType.isNull())
2294 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002295
John McCall550e0c22009-10-21 00:40:46 +00002296 QualType Result = TL.getType();
2297 if (getDerived().AlwaysRebuild() ||
2298 ElementType != T->getElementType()) {
2299 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002300 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002301 T->getIndexTypeCVRQualifiers(),
2302 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002303 if (Result.isNull())
2304 return QualType();
2305 }
2306
2307 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2308 NewTL.setLBracketLoc(TL.getLBracketLoc());
2309 NewTL.setRBracketLoc(TL.getRBracketLoc());
2310 NewTL.setSizeExpr(0);
2311
2312 return Result;
2313}
2314
2315template<typename Derived>
2316QualType
2317TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
2318 VariableArrayTypeLoc TL) {
2319 VariableArrayType *T = TL.getTypePtr();
2320 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2321 if (ElementType.isNull())
2322 return QualType();
2323
2324 // Array bounds are not potentially evaluated contexts
2325 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2326
2327 Sema::OwningExprResult SizeResult
2328 = getDerived().TransformExpr(T->getSizeExpr());
2329 if (SizeResult.isInvalid())
2330 return QualType();
2331
2332 Expr *Size = static_cast<Expr*>(SizeResult.get());
2333
2334 QualType Result = TL.getType();
2335 if (getDerived().AlwaysRebuild() ||
2336 ElementType != T->getElementType() ||
2337 Size != T->getSizeExpr()) {
2338 Result = getDerived().RebuildVariableArrayType(ElementType,
2339 T->getSizeModifier(),
2340 move(SizeResult),
2341 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002342 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002343 if (Result.isNull())
2344 return QualType();
2345 }
2346 else SizeResult.take();
2347
2348 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2349 NewTL.setLBracketLoc(TL.getLBracketLoc());
2350 NewTL.setRBracketLoc(TL.getRBracketLoc());
2351 NewTL.setSizeExpr(Size);
2352
2353 return Result;
2354}
2355
2356template<typename Derived>
2357QualType
2358TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
2359 DependentSizedArrayTypeLoc TL) {
2360 DependentSizedArrayType *T = TL.getTypePtr();
2361 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2362 if (ElementType.isNull())
2363 return QualType();
2364
2365 // Array bounds are not potentially evaluated contexts
2366 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2367
2368 Sema::OwningExprResult SizeResult
2369 = getDerived().TransformExpr(T->getSizeExpr());
2370 if (SizeResult.isInvalid())
2371 return QualType();
2372
2373 Expr *Size = static_cast<Expr*>(SizeResult.get());
2374
2375 QualType Result = TL.getType();
2376 if (getDerived().AlwaysRebuild() ||
2377 ElementType != T->getElementType() ||
2378 Size != T->getSizeExpr()) {
2379 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2380 T->getSizeModifier(),
2381 move(SizeResult),
2382 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002383 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002384 if (Result.isNull())
2385 return QualType();
2386 }
2387 else SizeResult.take();
2388
2389 // We might have any sort of array type now, but fortunately they
2390 // all have the same location layout.
2391 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2392 NewTL.setLBracketLoc(TL.getLBracketLoc());
2393 NewTL.setRBracketLoc(TL.getRBracketLoc());
2394 NewTL.setSizeExpr(Size);
2395
2396 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002397}
Mike Stump11289f42009-09-09 15:08:12 +00002398
2399template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002400QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002401 TypeLocBuilder &TLB,
2402 DependentSizedExtVectorTypeLoc TL) {
2403 DependentSizedExtVectorType *T = TL.getTypePtr();
2404
2405 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002406 QualType ElementType = getDerived().TransformType(T->getElementType());
2407 if (ElementType.isNull())
2408 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002409
Douglas Gregore922c772009-08-04 22:27:00 +00002410 // Vector sizes are not potentially evaluated contexts
2411 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2412
Douglas Gregord6ff3322009-08-04 16:50:30 +00002413 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2414 if (Size.isInvalid())
2415 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002416
John McCall550e0c22009-10-21 00:40:46 +00002417 QualType Result = TL.getType();
2418 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002419 ElementType != T->getElementType() ||
2420 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002421 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002422 move(Size),
2423 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002424 if (Result.isNull())
2425 return QualType();
2426 }
2427 else Size.take();
2428
2429 // Result might be dependent or not.
2430 if (isa<DependentSizedExtVectorType>(Result)) {
2431 DependentSizedExtVectorTypeLoc NewTL
2432 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2433 NewTL.setNameLoc(TL.getNameLoc());
2434 } else {
2435 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2436 NewTL.setNameLoc(TL.getNameLoc());
2437 }
2438
2439 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002440}
Mike Stump11289f42009-09-09 15:08:12 +00002441
2442template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002443QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
2444 VectorTypeLoc TL) {
2445 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002446 QualType ElementType = getDerived().TransformType(T->getElementType());
2447 if (ElementType.isNull())
2448 return QualType();
2449
John McCall550e0c22009-10-21 00:40:46 +00002450 QualType Result = TL.getType();
2451 if (getDerived().AlwaysRebuild() ||
2452 ElementType != T->getElementType()) {
2453 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements());
2454 if (Result.isNull())
2455 return QualType();
2456 }
2457
2458 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2459 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002460
John McCall550e0c22009-10-21 00:40:46 +00002461 return Result;
2462}
2463
2464template<typename Derived>
2465QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
2466 ExtVectorTypeLoc TL) {
2467 VectorType *T = TL.getTypePtr();
2468 QualType ElementType = getDerived().TransformType(T->getElementType());
2469 if (ElementType.isNull())
2470 return QualType();
2471
2472 QualType Result = TL.getType();
2473 if (getDerived().AlwaysRebuild() ||
2474 ElementType != T->getElementType()) {
2475 Result = getDerived().RebuildExtVectorType(ElementType,
2476 T->getNumElements(),
2477 /*FIXME*/ SourceLocation());
2478 if (Result.isNull())
2479 return QualType();
2480 }
2481
2482 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2483 NewTL.setNameLoc(TL.getNameLoc());
2484
2485 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002486}
Mike Stump11289f42009-09-09 15:08:12 +00002487
2488template<typename Derived>
2489QualType
John McCall550e0c22009-10-21 00:40:46 +00002490TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
2491 FunctionProtoTypeLoc TL) {
2492 FunctionProtoType *T = TL.getTypePtr();
2493 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002494 if (ResultType.isNull())
2495 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002496
John McCall550e0c22009-10-21 00:40:46 +00002497 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002498 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002499 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2500 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2501 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump11289f42009-09-09 15:08:12 +00002502
John McCall550e0c22009-10-21 00:40:46 +00002503 QualType NewType;
2504 ParmVarDecl *NewParm;
2505
2506 if (OldParm) {
John McCallbcd03502009-12-07 02:54:59 +00002507 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCall550e0c22009-10-21 00:40:46 +00002508 assert(OldDI->getType() == T->getArgType(i));
2509
John McCallbcd03502009-12-07 02:54:59 +00002510 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCall550e0c22009-10-21 00:40:46 +00002511 if (!NewDI)
2512 return QualType();
2513
2514 if (NewDI == OldDI)
2515 NewParm = OldParm;
2516 else
2517 NewParm = ParmVarDecl::Create(SemaRef.Context,
2518 OldParm->getDeclContext(),
2519 OldParm->getLocation(),
2520 OldParm->getIdentifier(),
2521 NewDI->getType(),
2522 NewDI,
2523 OldParm->getStorageClass(),
2524 /* DefArg */ NULL);
2525 NewType = NewParm->getType();
2526
2527 // Deal with the possibility that we don't have a parameter
2528 // declaration for this parameter.
2529 } else {
2530 NewParm = 0;
2531
2532 QualType OldType = T->getArgType(i);
2533 NewType = getDerived().TransformType(OldType);
2534 if (NewType.isNull())
2535 return QualType();
2536 }
2537
2538 ParamTypes.push_back(NewType);
2539 ParamDecls.push_back(NewParm);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002540 }
Mike Stump11289f42009-09-09 15:08:12 +00002541
John McCall550e0c22009-10-21 00:40:46 +00002542 QualType Result = TL.getType();
2543 if (getDerived().AlwaysRebuild() ||
2544 ResultType != T->getResultType() ||
2545 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2546 Result = getDerived().RebuildFunctionProtoType(ResultType,
2547 ParamTypes.data(),
2548 ParamTypes.size(),
2549 T->isVariadic(),
2550 T->getTypeQuals());
2551 if (Result.isNull())
2552 return QualType();
2553 }
Mike Stump11289f42009-09-09 15:08:12 +00002554
John McCall550e0c22009-10-21 00:40:46 +00002555 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2556 NewTL.setLParenLoc(TL.getLParenLoc());
2557 NewTL.setRParenLoc(TL.getRParenLoc());
2558 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2559 NewTL.setArg(i, ParamDecls[i]);
2560
2561 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002562}
Mike Stump11289f42009-09-09 15:08:12 +00002563
Douglas Gregord6ff3322009-08-04 16:50:30 +00002564template<typename Derived>
2565QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002566 TypeLocBuilder &TLB,
2567 FunctionNoProtoTypeLoc TL) {
2568 FunctionNoProtoType *T = TL.getTypePtr();
2569 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2570 if (ResultType.isNull())
2571 return QualType();
2572
2573 QualType Result = TL.getType();
2574 if (getDerived().AlwaysRebuild() ||
2575 ResultType != T->getResultType())
2576 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2577
2578 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2579 NewTL.setLParenLoc(TL.getLParenLoc());
2580 NewTL.setRParenLoc(TL.getRParenLoc());
2581
2582 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002583}
Mike Stump11289f42009-09-09 15:08:12 +00002584
John McCallb96ec562009-12-04 22:46:56 +00002585template<typename Derived> QualType
2586TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
2587 UnresolvedUsingTypeLoc TL) {
2588 UnresolvedUsingType *T = TL.getTypePtr();
2589 Decl *D = getDerived().TransformDecl(T->getDecl());
2590 if (!D)
2591 return QualType();
2592
2593 QualType Result = TL.getType();
2594 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2595 Result = getDerived().RebuildUnresolvedUsingType(D);
2596 if (Result.isNull())
2597 return QualType();
2598 }
2599
2600 // We might get an arbitrary type spec type back. We should at
2601 // least always get a type spec type, though.
2602 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2603 NewTL.setNameLoc(TL.getNameLoc());
2604
2605 return Result;
2606}
2607
Douglas Gregord6ff3322009-08-04 16:50:30 +00002608template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002609QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
2610 TypedefTypeLoc TL) {
2611 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002612 TypedefDecl *Typedef
2613 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2614 if (!Typedef)
2615 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002616
John McCall550e0c22009-10-21 00:40:46 +00002617 QualType Result = TL.getType();
2618 if (getDerived().AlwaysRebuild() ||
2619 Typedef != T->getDecl()) {
2620 Result = getDerived().RebuildTypedefType(Typedef);
2621 if (Result.isNull())
2622 return QualType();
2623 }
Mike Stump11289f42009-09-09 15:08:12 +00002624
John McCall550e0c22009-10-21 00:40:46 +00002625 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2626 NewTL.setNameLoc(TL.getNameLoc());
2627
2628 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002629}
Mike Stump11289f42009-09-09 15:08:12 +00002630
Douglas Gregord6ff3322009-08-04 16:50:30 +00002631template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002632QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
2633 TypeOfExprTypeLoc TL) {
2634 TypeOfExprType *T = TL.getTypePtr();
2635
Douglas Gregore922c772009-08-04 22:27:00 +00002636 // typeof expressions are not potentially evaluated contexts
2637 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002638
Douglas Gregord6ff3322009-08-04 16:50:30 +00002639 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2640 if (E.isInvalid())
2641 return QualType();
2642
John McCall550e0c22009-10-21 00:40:46 +00002643 QualType Result = TL.getType();
2644 if (getDerived().AlwaysRebuild() ||
2645 E.get() != T->getUnderlyingExpr()) {
2646 Result = getDerived().RebuildTypeOfExprType(move(E));
2647 if (Result.isNull())
2648 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002649 }
John McCall550e0c22009-10-21 00:40:46 +00002650 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002651
John McCall550e0c22009-10-21 00:40:46 +00002652 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
2653 NewTL.setNameLoc(TL.getNameLoc());
2654
2655 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002656}
Mike Stump11289f42009-09-09 15:08:12 +00002657
2658template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002659QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
2660 TypeOfTypeLoc TL) {
2661 TypeOfType *T = TL.getTypePtr();
2662
John McCallbcd03502009-12-07 02:54:59 +00002663 // FIXME: should be an inner type, or at least have a TypeSourceInfo.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002664 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2665 if (Underlying.isNull())
2666 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002667
John McCall550e0c22009-10-21 00:40:46 +00002668 QualType Result = TL.getType();
2669 if (getDerived().AlwaysRebuild() ||
2670 Underlying != T->getUnderlyingType()) {
2671 Result = getDerived().RebuildTypeOfType(Underlying);
2672 if (Result.isNull())
2673 return QualType();
2674 }
Mike Stump11289f42009-09-09 15:08:12 +00002675
John McCall550e0c22009-10-21 00:40:46 +00002676 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
2677 NewTL.setNameLoc(TL.getNameLoc());
2678
2679 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002680}
Mike Stump11289f42009-09-09 15:08:12 +00002681
2682template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002683QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
2684 DecltypeTypeLoc TL) {
2685 DecltypeType *T = TL.getTypePtr();
2686
Douglas Gregore922c772009-08-04 22:27:00 +00002687 // decltype expressions are not potentially evaluated contexts
2688 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002689
Douglas Gregord6ff3322009-08-04 16:50:30 +00002690 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2691 if (E.isInvalid())
2692 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002693
John McCall550e0c22009-10-21 00:40:46 +00002694 QualType Result = TL.getType();
2695 if (getDerived().AlwaysRebuild() ||
2696 E.get() != T->getUnderlyingExpr()) {
2697 Result = getDerived().RebuildDecltypeType(move(E));
2698 if (Result.isNull())
2699 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002700 }
John McCall550e0c22009-10-21 00:40:46 +00002701 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002702
John McCall550e0c22009-10-21 00:40:46 +00002703 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2704 NewTL.setNameLoc(TL.getNameLoc());
2705
2706 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002707}
2708
2709template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002710QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
2711 RecordTypeLoc TL) {
2712 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002713 RecordDecl *Record
John McCall550e0c22009-10-21 00:40:46 +00002714 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002715 if (!Record)
2716 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002717
John McCall550e0c22009-10-21 00:40:46 +00002718 QualType Result = TL.getType();
2719 if (getDerived().AlwaysRebuild() ||
2720 Record != T->getDecl()) {
2721 Result = getDerived().RebuildRecordType(Record);
2722 if (Result.isNull())
2723 return QualType();
2724 }
Mike Stump11289f42009-09-09 15:08:12 +00002725
John McCall550e0c22009-10-21 00:40:46 +00002726 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2727 NewTL.setNameLoc(TL.getNameLoc());
2728
2729 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002730}
Mike Stump11289f42009-09-09 15:08:12 +00002731
2732template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002733QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
2734 EnumTypeLoc TL) {
2735 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002736 EnumDecl *Enum
John McCall550e0c22009-10-21 00:40:46 +00002737 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002738 if (!Enum)
2739 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002740
John McCall550e0c22009-10-21 00:40:46 +00002741 QualType Result = TL.getType();
2742 if (getDerived().AlwaysRebuild() ||
2743 Enum != T->getDecl()) {
2744 Result = getDerived().RebuildEnumType(Enum);
2745 if (Result.isNull())
2746 return QualType();
2747 }
Mike Stump11289f42009-09-09 15:08:12 +00002748
John McCall550e0c22009-10-21 00:40:46 +00002749 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2750 NewTL.setNameLoc(TL.getNameLoc());
2751
2752 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002753}
John McCallfcc33b02009-09-05 00:15:47 +00002754
2755template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002756QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
2757 ElaboratedTypeLoc TL) {
2758 ElaboratedType *T = TL.getTypePtr();
2759
2760 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002761 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2762 if (Underlying.isNull())
2763 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002764
John McCall550e0c22009-10-21 00:40:46 +00002765 QualType Result = TL.getType();
2766 if (getDerived().AlwaysRebuild() ||
2767 Underlying != T->getUnderlyingType()) {
2768 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2769 if (Result.isNull())
2770 return QualType();
2771 }
Mike Stump11289f42009-09-09 15:08:12 +00002772
John McCall550e0c22009-10-21 00:40:46 +00002773 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2774 NewTL.setNameLoc(TL.getNameLoc());
2775
2776 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002777}
Mike Stump11289f42009-09-09 15:08:12 +00002778
2779
Douglas Gregord6ff3322009-08-04 16:50:30 +00002780template<typename Derived>
2781QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002782 TypeLocBuilder &TLB,
2783 TemplateTypeParmTypeLoc TL) {
2784 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002785}
2786
Mike Stump11289f42009-09-09 15:08:12 +00002787template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002788QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002789 TypeLocBuilder &TLB,
2790 SubstTemplateTypeParmTypeLoc TL) {
2791 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002792}
2793
2794template<typename Derived>
Douglas Gregorc59e5612009-10-19 22:04:39 +00002795inline QualType
2796TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall550e0c22009-10-21 00:40:46 +00002797 TypeLocBuilder &TLB,
2798 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00002799 return TransformTemplateSpecializationType(TLB, TL, QualType());
2800}
John McCall550e0c22009-10-21 00:40:46 +00002801
John McCall0ad16662009-10-29 08:12:44 +00002802template<typename Derived>
2803QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2804 const TemplateSpecializationType *TST,
2805 QualType ObjectType) {
2806 // FIXME: this entire method is a temporary workaround; callers
2807 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00002808
John McCall0ad16662009-10-29 08:12:44 +00002809 // Fake up a TemplateSpecializationTypeLoc.
2810 TypeLocBuilder TLB;
2811 TemplateSpecializationTypeLoc TL
2812 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2813
John McCall0d07eb32009-10-29 18:45:58 +00002814 SourceLocation BaseLoc = getDerived().getBaseLocation();
2815
2816 TL.setTemplateNameLoc(BaseLoc);
2817 TL.setLAngleLoc(BaseLoc);
2818 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00002819 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2820 const TemplateArgument &TA = TST->getArg(i);
2821 TemplateArgumentLoc TAL;
2822 getDerived().InventTemplateArgumentLoc(TA, TAL);
2823 TL.setArgLocInfo(i, TAL.getLocInfo());
2824 }
2825
2826 TypeLocBuilder IgnoredTLB;
2827 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00002828}
2829
2830template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002831QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00002832 TypeLocBuilder &TLB,
2833 TemplateSpecializationTypeLoc TL,
2834 QualType ObjectType) {
2835 const TemplateSpecializationType *T = TL.getTypePtr();
2836
Mike Stump11289f42009-09-09 15:08:12 +00002837 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002838 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002839 if (Template.isNull())
2840 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002841
John McCall6b51f282009-11-23 01:53:49 +00002842 TemplateArgumentListInfo NewTemplateArgs;
2843 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2844 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2845
2846 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2847 TemplateArgumentLoc Loc;
2848 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00002849 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00002850 NewTemplateArgs.addArgument(Loc);
2851 }
Mike Stump11289f42009-09-09 15:08:12 +00002852
John McCall0ad16662009-10-29 08:12:44 +00002853 // FIXME: maybe don't rebuild if all the template arguments are the same.
2854
2855 QualType Result =
2856 getDerived().RebuildTemplateSpecializationType(Template,
2857 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00002858 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00002859
2860 if (!Result.isNull()) {
2861 TemplateSpecializationTypeLoc NewTL
2862 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2863 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2864 NewTL.setLAngleLoc(TL.getLAngleLoc());
2865 NewTL.setRAngleLoc(TL.getRAngleLoc());
2866 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2867 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002868 }
Mike Stump11289f42009-09-09 15:08:12 +00002869
John McCall0ad16662009-10-29 08:12:44 +00002870 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002871}
Mike Stump11289f42009-09-09 15:08:12 +00002872
2873template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002874QualType
2875TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
2876 QualifiedNameTypeLoc TL) {
2877 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002878 NestedNameSpecifier *NNS
2879 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2880 SourceRange());
2881 if (!NNS)
2882 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002883
Douglas Gregord6ff3322009-08-04 16:50:30 +00002884 QualType Named = getDerived().TransformType(T->getNamedType());
2885 if (Named.isNull())
2886 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002887
John McCall550e0c22009-10-21 00:40:46 +00002888 QualType Result = TL.getType();
2889 if (getDerived().AlwaysRebuild() ||
2890 NNS != T->getQualifier() ||
2891 Named != T->getNamedType()) {
2892 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2893 if (Result.isNull())
2894 return QualType();
2895 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002896
John McCall550e0c22009-10-21 00:40:46 +00002897 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2898 NewTL.setNameLoc(TL.getNameLoc());
2899
2900 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002901}
Mike Stump11289f42009-09-09 15:08:12 +00002902
2903template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002904QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
2905 TypenameTypeLoc TL) {
2906 TypenameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00002907
2908 /* FIXME: preserve source information better than this */
2909 SourceRange SR(TL.getNameLoc());
2910
Douglas Gregord6ff3322009-08-04 16:50:30 +00002911 NestedNameSpecifier *NNS
John McCall0ad16662009-10-29 08:12:44 +00002912 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002913 if (!NNS)
2914 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002915
John McCall550e0c22009-10-21 00:40:46 +00002916 QualType Result;
2917
Douglas Gregord6ff3322009-08-04 16:50:30 +00002918 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002919 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002920 = getDerived().TransformType(QualType(TemplateId, 0));
2921 if (NewTemplateId.isNull())
2922 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002923
Douglas Gregord6ff3322009-08-04 16:50:30 +00002924 if (!getDerived().AlwaysRebuild() &&
2925 NNS == T->getQualifier() &&
2926 NewTemplateId == QualType(TemplateId, 0))
2927 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002928
John McCall550e0c22009-10-21 00:40:46 +00002929 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2930 } else {
John McCall0ad16662009-10-29 08:12:44 +00002931 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002932 }
John McCall550e0c22009-10-21 00:40:46 +00002933 if (Result.isNull())
2934 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002935
John McCall550e0c22009-10-21 00:40:46 +00002936 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2937 NewTL.setNameLoc(TL.getNameLoc());
2938
2939 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002940}
Mike Stump11289f42009-09-09 15:08:12 +00002941
Douglas Gregord6ff3322009-08-04 16:50:30 +00002942template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002943QualType
2944TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
2945 ObjCInterfaceTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002946 assert(false && "TransformObjCInterfaceType unimplemented");
2947 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002948}
Mike Stump11289f42009-09-09 15:08:12 +00002949
2950template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002951QualType
2952TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
2953 ObjCObjectPointerTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002954 assert(false && "TransformObjCObjectPointerType unimplemented");
2955 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00002956}
2957
Douglas Gregord6ff3322009-08-04 16:50:30 +00002958//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00002959// Statement transformation
2960//===----------------------------------------------------------------------===//
2961template<typename Derived>
2962Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002963TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2964 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002965}
2966
2967template<typename Derived>
2968Sema::OwningStmtResult
2969TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2970 return getDerived().TransformCompoundStmt(S, false);
2971}
2972
2973template<typename Derived>
2974Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002975TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00002976 bool IsStmtExpr) {
2977 bool SubStmtChanged = false;
2978 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
2979 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
2980 B != BEnd; ++B) {
2981 OwningStmtResult Result = getDerived().TransformStmt(*B);
2982 if (Result.isInvalid())
2983 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002984
Douglas Gregorebe10102009-08-20 07:17:43 +00002985 SubStmtChanged = SubStmtChanged || Result.get() != *B;
2986 Statements.push_back(Result.takeAs<Stmt>());
2987 }
Mike Stump11289f42009-09-09 15:08:12 +00002988
Douglas Gregorebe10102009-08-20 07:17:43 +00002989 if (!getDerived().AlwaysRebuild() &&
2990 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00002991 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002992
2993 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
2994 move_arg(Statements),
2995 S->getRBracLoc(),
2996 IsStmtExpr);
2997}
Mike Stump11289f42009-09-09 15:08:12 +00002998
Douglas Gregorebe10102009-08-20 07:17:43 +00002999template<typename Derived>
3000Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003001TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003002 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3003 {
3004 // The case value expressions are not potentially evaluated.
3005 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003006
Eli Friedman06577382009-11-19 03:14:00 +00003007 // Transform the left-hand case value.
3008 LHS = getDerived().TransformExpr(S->getLHS());
3009 if (LHS.isInvalid())
3010 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003011
Eli Friedman06577382009-11-19 03:14:00 +00003012 // Transform the right-hand case value (for the GNU case-range extension).
3013 RHS = getDerived().TransformExpr(S->getRHS());
3014 if (RHS.isInvalid())
3015 return SemaRef.StmtError();
3016 }
Mike Stump11289f42009-09-09 15:08:12 +00003017
Douglas Gregorebe10102009-08-20 07:17:43 +00003018 // Build the case statement.
3019 // Case statements are always rebuilt so that they will attached to their
3020 // transformed switch statement.
3021 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3022 move(LHS),
3023 S->getEllipsisLoc(),
3024 move(RHS),
3025 S->getColonLoc());
3026 if (Case.isInvalid())
3027 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003028
Douglas Gregorebe10102009-08-20 07:17:43 +00003029 // Transform the statement following the case
3030 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3031 if (SubStmt.isInvalid())
3032 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003033
Douglas Gregorebe10102009-08-20 07:17:43 +00003034 // Attach the body to the case statement
3035 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3036}
3037
3038template<typename Derived>
3039Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003040TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003041 // Transform the statement following the default case
3042 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3043 if (SubStmt.isInvalid())
3044 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003045
Douglas Gregorebe10102009-08-20 07:17:43 +00003046 // Default statements are always rebuilt
3047 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3048 move(SubStmt));
3049}
Mike Stump11289f42009-09-09 15:08:12 +00003050
Douglas Gregorebe10102009-08-20 07:17:43 +00003051template<typename Derived>
3052Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003053TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003054 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3055 if (SubStmt.isInvalid())
3056 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003057
Douglas Gregorebe10102009-08-20 07:17:43 +00003058 // FIXME: Pass the real colon location in.
3059 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3060 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3061 move(SubStmt));
3062}
Mike Stump11289f42009-09-09 15:08:12 +00003063
Douglas Gregorebe10102009-08-20 07:17:43 +00003064template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003065Sema::OwningStmtResult
3066TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003067 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003068 OwningExprResult Cond(SemaRef);
3069 VarDecl *ConditionVar = 0;
3070 if (S->getConditionVariable()) {
3071 ConditionVar
3072 = cast_or_null<VarDecl>(
3073 getDerived().TransformDefinition(S->getConditionVariable()));
3074 if (!ConditionVar)
3075 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003076 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003077 Cond = getDerived().TransformExpr(S->getCond());
3078
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003079 if (Cond.isInvalid())
3080 return SemaRef.StmtError();
3081 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003082
Douglas Gregorebe10102009-08-20 07:17:43 +00003083 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003084
Douglas Gregorebe10102009-08-20 07:17:43 +00003085 // Transform the "then" branch.
3086 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3087 if (Then.isInvalid())
3088 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003089
Douglas Gregorebe10102009-08-20 07:17:43 +00003090 // Transform the "else" branch.
3091 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3092 if (Else.isInvalid())
3093 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003094
Douglas Gregorebe10102009-08-20 07:17:43 +00003095 if (!getDerived().AlwaysRebuild() &&
3096 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003097 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003098 Then.get() == S->getThen() &&
3099 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003100 return SemaRef.Owned(S->Retain());
3101
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003102 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3103 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003104 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003105}
3106
3107template<typename Derived>
3108Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003109TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003110 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003111 OwningExprResult Cond(SemaRef);
3112 VarDecl *ConditionVar = 0;
3113 if (S->getConditionVariable()) {
3114 ConditionVar
3115 = cast_or_null<VarDecl>(
3116 getDerived().TransformDefinition(S->getConditionVariable()));
3117 if (!ConditionVar)
3118 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003119 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003120 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003121
3122 if (Cond.isInvalid())
3123 return SemaRef.StmtError();
3124 }
Mike Stump11289f42009-09-09 15:08:12 +00003125
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003126 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
3127
Douglas Gregorebe10102009-08-20 07:17:43 +00003128 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003129 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3130 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003131 if (Switch.isInvalid())
3132 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003133
Douglas Gregorebe10102009-08-20 07:17:43 +00003134 // Transform the body of the switch statement.
3135 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3136 if (Body.isInvalid())
3137 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003138
Douglas Gregorebe10102009-08-20 07:17:43 +00003139 // Complete the switch statement.
3140 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3141 move(Body));
3142}
Mike Stump11289f42009-09-09 15:08:12 +00003143
Douglas Gregorebe10102009-08-20 07:17:43 +00003144template<typename Derived>
3145Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003146TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003147 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003148 OwningExprResult Cond(SemaRef);
3149 VarDecl *ConditionVar = 0;
3150 if (S->getConditionVariable()) {
3151 ConditionVar
3152 = cast_or_null<VarDecl>(
3153 getDerived().TransformDefinition(S->getConditionVariable()));
3154 if (!ConditionVar)
3155 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003156 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003157 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003158
3159 if (Cond.isInvalid())
3160 return SemaRef.StmtError();
3161 }
Mike Stump11289f42009-09-09 15:08:12 +00003162
Douglas Gregorebe10102009-08-20 07:17:43 +00003163 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003164
Douglas Gregorebe10102009-08-20 07:17:43 +00003165 // Transform the body
3166 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3167 if (Body.isInvalid())
3168 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003169
Douglas Gregorebe10102009-08-20 07:17:43 +00003170 if (!getDerived().AlwaysRebuild() &&
3171 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003172 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003173 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003174 return SemaRef.Owned(S->Retain());
3175
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003176 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3177 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003178}
Mike Stump11289f42009-09-09 15:08:12 +00003179
Douglas Gregorebe10102009-08-20 07:17:43 +00003180template<typename Derived>
3181Sema::OwningStmtResult
3182TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3183 // Transform the condition
3184 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3185 if (Cond.isInvalid())
3186 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003187
Douglas Gregorebe10102009-08-20 07:17:43 +00003188 // Transform the body
3189 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3190 if (Body.isInvalid())
3191 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003192
Douglas Gregorebe10102009-08-20 07:17:43 +00003193 if (!getDerived().AlwaysRebuild() &&
3194 Cond.get() == S->getCond() &&
3195 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003196 return SemaRef.Owned(S->Retain());
3197
Douglas Gregorebe10102009-08-20 07:17:43 +00003198 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3199 /*FIXME:*/S->getWhileLoc(), move(Cond),
3200 S->getRParenLoc());
3201}
Mike Stump11289f42009-09-09 15:08:12 +00003202
Douglas Gregorebe10102009-08-20 07:17:43 +00003203template<typename Derived>
3204Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003205TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003206 // Transform the initialization statement
3207 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3208 if (Init.isInvalid())
3209 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003210
Douglas Gregorebe10102009-08-20 07:17:43 +00003211 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003212 OwningExprResult Cond(SemaRef);
3213 VarDecl *ConditionVar = 0;
3214 if (S->getConditionVariable()) {
3215 ConditionVar
3216 = cast_or_null<VarDecl>(
3217 getDerived().TransformDefinition(S->getConditionVariable()));
3218 if (!ConditionVar)
3219 return SemaRef.StmtError();
3220 } else {
3221 Cond = getDerived().TransformExpr(S->getCond());
3222
3223 if (Cond.isInvalid())
3224 return SemaRef.StmtError();
3225 }
Mike Stump11289f42009-09-09 15:08:12 +00003226
Douglas Gregorebe10102009-08-20 07:17:43 +00003227 // Transform the increment
3228 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3229 if (Inc.isInvalid())
3230 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003231
Douglas Gregorebe10102009-08-20 07:17:43 +00003232 // Transform the body
3233 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3234 if (Body.isInvalid())
3235 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003236
Douglas Gregorebe10102009-08-20 07:17:43 +00003237 if (!getDerived().AlwaysRebuild() &&
3238 Init.get() == S->getInit() &&
3239 Cond.get() == S->getCond() &&
3240 Inc.get() == S->getInc() &&
3241 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003242 return SemaRef.Owned(S->Retain());
3243
Douglas Gregorebe10102009-08-20 07:17:43 +00003244 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003245 move(Init), getSema().FullExpr(Cond),
3246 ConditionVar,
3247 getSema().FullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003248 S->getRParenLoc(), move(Body));
3249}
3250
3251template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003252Sema::OwningStmtResult
3253TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003254 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003255 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003256 S->getLabel());
3257}
3258
3259template<typename Derived>
3260Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003261TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003262 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3263 if (Target.isInvalid())
3264 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003265
Douglas Gregorebe10102009-08-20 07:17:43 +00003266 if (!getDerived().AlwaysRebuild() &&
3267 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003268 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003269
3270 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3271 move(Target));
3272}
3273
3274template<typename Derived>
3275Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003276TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3277 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003278}
Mike Stump11289f42009-09-09 15:08:12 +00003279
Douglas Gregorebe10102009-08-20 07:17:43 +00003280template<typename Derived>
3281Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003282TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3283 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003284}
Mike Stump11289f42009-09-09 15:08:12 +00003285
Douglas Gregorebe10102009-08-20 07:17:43 +00003286template<typename Derived>
3287Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003288TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003289 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3290 if (Result.isInvalid())
3291 return SemaRef.StmtError();
3292
Mike Stump11289f42009-09-09 15:08:12 +00003293 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003294 // to tell whether the return type of the function has changed.
3295 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3296}
Mike Stump11289f42009-09-09 15:08:12 +00003297
Douglas Gregorebe10102009-08-20 07:17:43 +00003298template<typename Derived>
3299Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003300TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003301 bool DeclChanged = false;
3302 llvm::SmallVector<Decl *, 4> Decls;
3303 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3304 D != DEnd; ++D) {
3305 Decl *Transformed = getDerived().TransformDefinition(*D);
3306 if (!Transformed)
3307 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003308
Douglas Gregorebe10102009-08-20 07:17:43 +00003309 if (Transformed != *D)
3310 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003311
Douglas Gregorebe10102009-08-20 07:17:43 +00003312 Decls.push_back(Transformed);
3313 }
Mike Stump11289f42009-09-09 15:08:12 +00003314
Douglas Gregorebe10102009-08-20 07:17:43 +00003315 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003316 return SemaRef.Owned(S->Retain());
3317
3318 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003319 S->getStartLoc(), S->getEndLoc());
3320}
Mike Stump11289f42009-09-09 15:08:12 +00003321
Douglas Gregorebe10102009-08-20 07:17:43 +00003322template<typename Derived>
3323Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003324TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003325 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003326 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003327}
3328
3329template<typename Derived>
3330Sema::OwningStmtResult
3331TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
3332 // FIXME: Implement!
3333 assert(false && "Inline assembly cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003334 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003335}
3336
3337
3338template<typename Derived>
3339Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003340TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003341 // FIXME: Implement this
3342 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003343 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003344}
Mike Stump11289f42009-09-09 15:08:12 +00003345
Douglas Gregorebe10102009-08-20 07:17:43 +00003346template<typename Derived>
3347Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003348TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003349 // FIXME: Implement this
3350 assert(false && "Cannot transform an Objective-C @catch statement");
3351 return SemaRef.Owned(S->Retain());
3352}
Mike Stump11289f42009-09-09 15:08:12 +00003353
Douglas Gregorebe10102009-08-20 07:17:43 +00003354template<typename Derived>
3355Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003356TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003357 // FIXME: Implement this
3358 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003359 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003360}
Mike Stump11289f42009-09-09 15:08:12 +00003361
Douglas Gregorebe10102009-08-20 07:17:43 +00003362template<typename Derived>
3363Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003364TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003365 // FIXME: Implement this
3366 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003367 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003368}
Mike Stump11289f42009-09-09 15:08:12 +00003369
Douglas Gregorebe10102009-08-20 07:17:43 +00003370template<typename Derived>
3371Sema::OwningStmtResult
3372TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003373 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003374 // FIXME: Implement this
3375 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003376 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003377}
3378
3379template<typename Derived>
3380Sema::OwningStmtResult
3381TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003382 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003383 // FIXME: Implement this
3384 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003385 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003386}
3387
3388
3389template<typename Derived>
3390Sema::OwningStmtResult
3391TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3392 // Transform the exception declaration, if any.
3393 VarDecl *Var = 0;
3394 if (S->getExceptionDecl()) {
3395 VarDecl *ExceptionDecl = S->getExceptionDecl();
3396 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3397 ExceptionDecl->getDeclName());
3398
3399 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3400 if (T.isNull())
3401 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003402
Douglas Gregorebe10102009-08-20 07:17:43 +00003403 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3404 T,
John McCallbcd03502009-12-07 02:54:59 +00003405 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003406 ExceptionDecl->getIdentifier(),
3407 ExceptionDecl->getLocation(),
3408 /*FIXME: Inaccurate*/
3409 SourceRange(ExceptionDecl->getLocation()));
3410 if (!Var || Var->isInvalidDecl()) {
3411 if (Var)
3412 Var->Destroy(SemaRef.Context);
3413 return SemaRef.StmtError();
3414 }
3415 }
Mike Stump11289f42009-09-09 15:08:12 +00003416
Douglas Gregorebe10102009-08-20 07:17:43 +00003417 // Transform the actual exception handler.
3418 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3419 if (Handler.isInvalid()) {
3420 if (Var)
3421 Var->Destroy(SemaRef.Context);
3422 return SemaRef.StmtError();
3423 }
Mike Stump11289f42009-09-09 15:08:12 +00003424
Douglas Gregorebe10102009-08-20 07:17:43 +00003425 if (!getDerived().AlwaysRebuild() &&
3426 !Var &&
3427 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003428 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003429
3430 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3431 Var,
3432 move(Handler));
3433}
Mike Stump11289f42009-09-09 15:08:12 +00003434
Douglas Gregorebe10102009-08-20 07:17:43 +00003435template<typename Derived>
3436Sema::OwningStmtResult
3437TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3438 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003439 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003440 = getDerived().TransformCompoundStmt(S->getTryBlock());
3441 if (TryBlock.isInvalid())
3442 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003443
Douglas Gregorebe10102009-08-20 07:17:43 +00003444 // Transform the handlers.
3445 bool HandlerChanged = false;
3446 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3447 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003448 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003449 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3450 if (Handler.isInvalid())
3451 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003452
Douglas Gregorebe10102009-08-20 07:17:43 +00003453 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3454 Handlers.push_back(Handler.takeAs<Stmt>());
3455 }
Mike Stump11289f42009-09-09 15:08:12 +00003456
Douglas Gregorebe10102009-08-20 07:17:43 +00003457 if (!getDerived().AlwaysRebuild() &&
3458 TryBlock.get() == S->getTryBlock() &&
3459 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003460 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003461
3462 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003463 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003464}
Mike Stump11289f42009-09-09 15:08:12 +00003465
Douglas Gregorebe10102009-08-20 07:17:43 +00003466//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003467// Expression transformation
3468//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003469template<typename Derived>
3470Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003471TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E,
3472 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003473 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003474}
Mike Stump11289f42009-09-09 15:08:12 +00003475
3476template<typename Derived>
3477Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003478TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E,
3479 bool isAddressOfOperand) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003480 NestedNameSpecifier *Qualifier = 0;
3481 if (E->getQualifier()) {
3482 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3483 E->getQualifierRange());
3484 if (!Qualifier)
3485 return SemaRef.ExprError();
3486 }
John McCallce546572009-12-08 09:08:17 +00003487
3488 ValueDecl *ND
3489 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003490 if (!ND)
3491 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003492
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003493 if (!getDerived().AlwaysRebuild() &&
3494 Qualifier == E->getQualifier() &&
3495 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003496 !E->hasExplicitTemplateArgumentList()) {
3497
3498 // Mark it referenced in the new context regardless.
3499 // FIXME: this is a bit instantiation-specific.
3500 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3501
Mike Stump11289f42009-09-09 15:08:12 +00003502 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003503 }
John McCallce546572009-12-08 09:08:17 +00003504
3505 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3506 if (E->hasExplicitTemplateArgumentList()) {
3507 TemplateArgs = &TransArgs;
3508 TransArgs.setLAngleLoc(E->getLAngleLoc());
3509 TransArgs.setRAngleLoc(E->getRAngleLoc());
3510 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3511 TemplateArgumentLoc Loc;
3512 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3513 return SemaRef.ExprError();
3514 TransArgs.addArgument(Loc);
3515 }
3516 }
3517
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003518 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003519 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003520}
Mike Stump11289f42009-09-09 15:08:12 +00003521
Douglas Gregora16548e2009-08-11 05:31:07 +00003522template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003523Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003524TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E,
3525 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003526 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003527}
Mike Stump11289f42009-09-09 15:08:12 +00003528
Douglas Gregora16548e2009-08-11 05:31:07 +00003529template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003530Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003531TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E,
3532 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003533 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003534}
Mike Stump11289f42009-09-09 15:08:12 +00003535
Douglas Gregora16548e2009-08-11 05:31:07 +00003536template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003537Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003538TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E,
3539 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003540 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003541}
Mike Stump11289f42009-09-09 15:08:12 +00003542
Douglas Gregora16548e2009-08-11 05:31:07 +00003543template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003544Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003545TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E,
3546 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003547 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003548}
Mike Stump11289f42009-09-09 15:08:12 +00003549
Douglas Gregora16548e2009-08-11 05:31:07 +00003550template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003551Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003552TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E,
3553 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003554 return SemaRef.Owned(E->Retain());
3555}
3556
3557template<typename Derived>
3558Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003559TreeTransform<Derived>::TransformParenExpr(ParenExpr *E,
3560 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003561 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3562 if (SubExpr.isInvalid())
3563 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003564
Douglas Gregora16548e2009-08-11 05:31:07 +00003565 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003566 return SemaRef.Owned(E->Retain());
3567
3568 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003569 E->getRParen());
3570}
3571
Mike Stump11289f42009-09-09 15:08:12 +00003572template<typename Derived>
3573Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003574TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E,
3575 bool isAddressOfOperand) {
3576 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr(),
3577 E->getOpcode() == UnaryOperator::AddrOf);
Douglas Gregora16548e2009-08-11 05:31:07 +00003578 if (SubExpr.isInvalid())
3579 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003580
Douglas Gregora16548e2009-08-11 05:31:07 +00003581 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003582 return SemaRef.Owned(E->Retain());
3583
Douglas Gregora16548e2009-08-11 05:31:07 +00003584 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3585 E->getOpcode(),
3586 move(SubExpr));
3587}
Mike Stump11289f42009-09-09 15:08:12 +00003588
Douglas Gregora16548e2009-08-11 05:31:07 +00003589template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003590Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003591TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E,
3592 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003593 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003594 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003595
John McCallbcd03502009-12-07 02:54:59 +00003596 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003597 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003598 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003599
John McCall4c98fd82009-11-04 07:28:41 +00003600 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003601 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003602
John McCall4c98fd82009-11-04 07:28:41 +00003603 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003604 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003605 E->getSourceRange());
3606 }
Mike Stump11289f42009-09-09 15:08:12 +00003607
Douglas Gregora16548e2009-08-11 05:31:07 +00003608 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003609 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003610 // C++0x [expr.sizeof]p1:
3611 // The operand is either an expression, which is an unevaluated operand
3612 // [...]
3613 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003614
Douglas Gregora16548e2009-08-11 05:31:07 +00003615 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3616 if (SubExpr.isInvalid())
3617 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003618
Douglas Gregora16548e2009-08-11 05:31:07 +00003619 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3620 return SemaRef.Owned(E->Retain());
3621 }
Mike Stump11289f42009-09-09 15:08:12 +00003622
Douglas Gregora16548e2009-08-11 05:31:07 +00003623 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3624 E->isSizeOf(),
3625 E->getSourceRange());
3626}
Mike Stump11289f42009-09-09 15:08:12 +00003627
Douglas Gregora16548e2009-08-11 05:31:07 +00003628template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003629Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003630TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E,
3631 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003632 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3633 if (LHS.isInvalid())
3634 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003635
Douglas Gregora16548e2009-08-11 05:31:07 +00003636 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3637 if (RHS.isInvalid())
3638 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003639
3640
Douglas Gregora16548e2009-08-11 05:31:07 +00003641 if (!getDerived().AlwaysRebuild() &&
3642 LHS.get() == E->getLHS() &&
3643 RHS.get() == E->getRHS())
3644 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003645
Douglas Gregora16548e2009-08-11 05:31:07 +00003646 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3647 /*FIXME:*/E->getLHS()->getLocStart(),
3648 move(RHS),
3649 E->getRBracketLoc());
3650}
Mike Stump11289f42009-09-09 15:08:12 +00003651
3652template<typename Derived>
3653Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003654TreeTransform<Derived>::TransformCallExpr(CallExpr *E,
3655 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003656 // Transform the callee.
3657 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3658 if (Callee.isInvalid())
3659 return SemaRef.ExprError();
3660
3661 // Transform arguments.
3662 bool ArgChanged = false;
3663 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3664 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3665 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3666 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3667 if (Arg.isInvalid())
3668 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003669
Douglas Gregora16548e2009-08-11 05:31:07 +00003670 // FIXME: Wrong source location information for the ','.
3671 FakeCommaLocs.push_back(
3672 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003673
3674 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003675 Args.push_back(Arg.takeAs<Expr>());
3676 }
Mike Stump11289f42009-09-09 15:08:12 +00003677
Douglas Gregora16548e2009-08-11 05:31:07 +00003678 if (!getDerived().AlwaysRebuild() &&
3679 Callee.get() == E->getCallee() &&
3680 !ArgChanged)
3681 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003682
Douglas Gregora16548e2009-08-11 05:31:07 +00003683 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003684 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003685 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3686 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3687 move_arg(Args),
3688 FakeCommaLocs.data(),
3689 E->getRParenLoc());
3690}
Mike Stump11289f42009-09-09 15:08:12 +00003691
3692template<typename Derived>
3693Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003694TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E,
3695 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003696 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3697 if (Base.isInvalid())
3698 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003699
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003700 NestedNameSpecifier *Qualifier = 0;
3701 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003702 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003703 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3704 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003705 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003706 return SemaRef.ExprError();
3707 }
Mike Stump11289f42009-09-09 15:08:12 +00003708
Eli Friedman2cfcef62009-12-04 06:40:45 +00003709 ValueDecl *Member
3710 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003711 if (!Member)
3712 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003713
Douglas Gregora16548e2009-08-11 05:31:07 +00003714 if (!getDerived().AlwaysRebuild() &&
3715 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003716 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003717 Member == E->getMemberDecl() &&
3718 !E->hasExplicitTemplateArgumentList())
Mike Stump11289f42009-09-09 15:08:12 +00003719 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003720
John McCall6b51f282009-11-23 01:53:49 +00003721 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003722 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003723 TransArgs.setLAngleLoc(E->getLAngleLoc());
3724 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003725 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003726 TemplateArgumentLoc Loc;
3727 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003728 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003729 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003730 }
3731 }
3732
Douglas Gregora16548e2009-08-11 05:31:07 +00003733 // FIXME: Bogus source location for the operator
3734 SourceLocation FakeOperatorLoc
3735 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3736
3737 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3738 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003739 Qualifier,
3740 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003741 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003742 Member,
John McCall6b51f282009-11-23 01:53:49 +00003743 (E->hasExplicitTemplateArgumentList()
3744 ? &TransArgs : 0),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003745 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00003746}
Mike Stump11289f42009-09-09 15:08:12 +00003747
Douglas Gregora16548e2009-08-11 05:31:07 +00003748template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003749Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003750TreeTransform<Derived>::TransformCastExpr(CastExpr *E,
3751 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003752 assert(false && "Cannot transform abstract class");
3753 return SemaRef.Owned(E->Retain());
3754}
3755
3756template<typename Derived>
3757Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003758TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E,
3759 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003760 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3761 if (LHS.isInvalid())
3762 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003763
Douglas Gregora16548e2009-08-11 05:31:07 +00003764 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3765 if (RHS.isInvalid())
3766 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003767
Douglas Gregora16548e2009-08-11 05:31:07 +00003768 if (!getDerived().AlwaysRebuild() &&
3769 LHS.get() == E->getLHS() &&
3770 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003771 return SemaRef.Owned(E->Retain());
3772
Douglas Gregora16548e2009-08-11 05:31:07 +00003773 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3774 move(LHS), move(RHS));
3775}
3776
Mike Stump11289f42009-09-09 15:08:12 +00003777template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003778Sema::OwningExprResult
3779TreeTransform<Derived>::TransformCompoundAssignOperator(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003780 CompoundAssignOperator *E,
3781 bool isAddressOfOperand) {
3782 return getDerived().TransformBinaryOperator(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00003783}
Mike Stump11289f42009-09-09 15:08:12 +00003784
Douglas Gregora16548e2009-08-11 05:31:07 +00003785template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003786Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003787TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E,
3788 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003789 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3790 if (Cond.isInvalid())
3791 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003792
Douglas Gregora16548e2009-08-11 05:31:07 +00003793 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3794 if (LHS.isInvalid())
3795 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003796
Douglas Gregora16548e2009-08-11 05:31:07 +00003797 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3798 if (RHS.isInvalid())
3799 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003800
Douglas Gregora16548e2009-08-11 05:31:07 +00003801 if (!getDerived().AlwaysRebuild() &&
3802 Cond.get() == E->getCond() &&
3803 LHS.get() == E->getLHS() &&
3804 RHS.get() == E->getRHS())
3805 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003806
3807 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003808 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003809 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003810 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003811 move(RHS));
3812}
Mike Stump11289f42009-09-09 15:08:12 +00003813
3814template<typename Derived>
3815Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003816TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E,
3817 bool isAddressOfOperand) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00003818 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3819
3820 // FIXME: Will we ever have type information here? It seems like we won't,
3821 // so do we even need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00003822 QualType T = getDerived().TransformType(E->getType());
3823 if (T.isNull())
3824 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003825
Douglas Gregora16548e2009-08-11 05:31:07 +00003826 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3827 if (SubExpr.isInvalid())
3828 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003829
Douglas Gregora16548e2009-08-11 05:31:07 +00003830 if (!getDerived().AlwaysRebuild() &&
3831 T == E->getType() &&
3832 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003833 return SemaRef.Owned(E->Retain());
3834
Douglas Gregora16548e2009-08-11 05:31:07 +00003835 return getDerived().RebuildImplicitCastExpr(T, E->getCastKind(),
Mike Stump11289f42009-09-09 15:08:12 +00003836 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00003837 E->isLvalueCast());
3838}
Mike Stump11289f42009-09-09 15:08:12 +00003839
Douglas Gregora16548e2009-08-11 05:31:07 +00003840template<typename Derived>
3841Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003842TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E,
3843 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003844 assert(false && "Cannot transform abstract class");
3845 return SemaRef.Owned(E->Retain());
3846}
3847
3848template<typename Derived>
3849Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003850TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E,
3851 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003852 QualType T;
3853 {
3854 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003855 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003856 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3857 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003858
Douglas Gregora16548e2009-08-11 05:31:07 +00003859 T = getDerived().TransformType(E->getTypeAsWritten());
3860 if (T.isNull())
3861 return SemaRef.ExprError();
3862 }
Mike Stump11289f42009-09-09 15:08:12 +00003863
Douglas Gregora16548e2009-08-11 05:31:07 +00003864 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3865 if (SubExpr.isInvalid())
3866 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003867
Douglas Gregora16548e2009-08-11 05:31:07 +00003868 if (!getDerived().AlwaysRebuild() &&
3869 T == E->getTypeAsWritten() &&
3870 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003871 return SemaRef.Owned(E->Retain());
3872
Douglas Gregora16548e2009-08-11 05:31:07 +00003873 return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T,
3874 E->getRParenLoc(),
3875 move(SubExpr));
3876}
Mike Stump11289f42009-09-09 15:08:12 +00003877
Douglas Gregora16548e2009-08-11 05:31:07 +00003878template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003879Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003880TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E,
3881 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003882 QualType T;
3883 {
3884 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003885 SourceLocation FakeTypeLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003886 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3887 TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003888
Douglas Gregora16548e2009-08-11 05:31:07 +00003889 T = getDerived().TransformType(E->getType());
3890 if (T.isNull())
3891 return SemaRef.ExprError();
3892 }
Mike Stump11289f42009-09-09 15:08:12 +00003893
Douglas Gregora16548e2009-08-11 05:31:07 +00003894 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3895 if (Init.isInvalid())
3896 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003897
Douglas Gregora16548e2009-08-11 05:31:07 +00003898 if (!getDerived().AlwaysRebuild() &&
3899 T == E->getType() &&
3900 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003901 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003902
3903 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T,
3904 /*FIXME:*/E->getInitializer()->getLocEnd(),
3905 move(Init));
3906}
Mike Stump11289f42009-09-09 15:08:12 +00003907
Douglas Gregora16548e2009-08-11 05:31:07 +00003908template<typename Derived>
3909Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003910TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E,
3911 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003912 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3913 if (Base.isInvalid())
3914 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003915
Douglas Gregora16548e2009-08-11 05:31:07 +00003916 if (!getDerived().AlwaysRebuild() &&
3917 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003918 return SemaRef.Owned(E->Retain());
3919
Douglas Gregora16548e2009-08-11 05:31:07 +00003920 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003921 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003922 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3923 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3924 E->getAccessorLoc(),
3925 E->getAccessor());
3926}
Mike Stump11289f42009-09-09 15:08:12 +00003927
Douglas Gregora16548e2009-08-11 05:31:07 +00003928template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003929Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003930TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E,
3931 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003932 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003933
Douglas Gregora16548e2009-08-11 05:31:07 +00003934 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3935 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3936 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3937 if (Init.isInvalid())
3938 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003939
Douglas Gregora16548e2009-08-11 05:31:07 +00003940 InitChanged = InitChanged || Init.get() != E->getInit(I);
3941 Inits.push_back(Init.takeAs<Expr>());
3942 }
Mike Stump11289f42009-09-09 15:08:12 +00003943
Douglas Gregora16548e2009-08-11 05:31:07 +00003944 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003945 return SemaRef.Owned(E->Retain());
3946
Douglas Gregora16548e2009-08-11 05:31:07 +00003947 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00003948 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00003949}
Mike Stump11289f42009-09-09 15:08:12 +00003950
Douglas Gregora16548e2009-08-11 05:31:07 +00003951template<typename Derived>
3952Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003953TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E,
3954 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003955 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00003956
Douglas Gregorebe10102009-08-20 07:17:43 +00003957 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00003958 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3959 if (Init.isInvalid())
3960 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003961
Douglas Gregorebe10102009-08-20 07:17:43 +00003962 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00003963 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3964 bool ExprChanged = false;
3965 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3966 DEnd = E->designators_end();
3967 D != DEnd; ++D) {
3968 if (D->isFieldDesignator()) {
3969 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3970 D->getDotLoc(),
3971 D->getFieldLoc()));
3972 continue;
3973 }
Mike Stump11289f42009-09-09 15:08:12 +00003974
Douglas Gregora16548e2009-08-11 05:31:07 +00003975 if (D->isArrayDesignator()) {
3976 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3977 if (Index.isInvalid())
3978 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003979
3980 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003981 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003982
Douglas Gregora16548e2009-08-11 05:31:07 +00003983 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3984 ArrayExprs.push_back(Index.release());
3985 continue;
3986 }
Mike Stump11289f42009-09-09 15:08:12 +00003987
Douglas Gregora16548e2009-08-11 05:31:07 +00003988 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00003989 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00003990 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3991 if (Start.isInvalid())
3992 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003993
Douglas Gregora16548e2009-08-11 05:31:07 +00003994 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3995 if (End.isInvalid())
3996 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003997
3998 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003999 End.get(),
4000 D->getLBracketLoc(),
4001 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004002
Douglas Gregora16548e2009-08-11 05:31:07 +00004003 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4004 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004005
Douglas Gregora16548e2009-08-11 05:31:07 +00004006 ArrayExprs.push_back(Start.release());
4007 ArrayExprs.push_back(End.release());
4008 }
Mike Stump11289f42009-09-09 15:08:12 +00004009
Douglas Gregora16548e2009-08-11 05:31:07 +00004010 if (!getDerived().AlwaysRebuild() &&
4011 Init.get() == E->getInit() &&
4012 !ExprChanged)
4013 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004014
Douglas Gregora16548e2009-08-11 05:31:07 +00004015 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4016 E->getEqualOrColonLoc(),
4017 E->usesGNUSyntax(), move(Init));
4018}
Mike Stump11289f42009-09-09 15:08:12 +00004019
Douglas Gregora16548e2009-08-11 05:31:07 +00004020template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004021Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004022TreeTransform<Derived>::TransformImplicitValueInitExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004023 ImplicitValueInitExpr *E,
4024 bool isAddressOfOperand) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004025 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4026
4027 // FIXME: Will we ever have proper type location here? Will we actually
4028 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004029 QualType T = getDerived().TransformType(E->getType());
4030 if (T.isNull())
4031 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004032
Douglas Gregora16548e2009-08-11 05:31:07 +00004033 if (!getDerived().AlwaysRebuild() &&
4034 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004035 return SemaRef.Owned(E->Retain());
4036
Douglas Gregora16548e2009-08-11 05:31:07 +00004037 return getDerived().RebuildImplicitValueInitExpr(T);
4038}
Mike Stump11289f42009-09-09 15:08:12 +00004039
Douglas Gregora16548e2009-08-11 05:31:07 +00004040template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004041Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004042TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E,
4043 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004044 // FIXME: Do we want the type as written?
4045 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004046
Douglas Gregora16548e2009-08-11 05:31:07 +00004047 {
4048 // FIXME: Source location isn't quite accurate.
4049 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4050 T = getDerived().TransformType(E->getType());
4051 if (T.isNull())
4052 return SemaRef.ExprError();
4053 }
Mike Stump11289f42009-09-09 15:08:12 +00004054
Douglas Gregora16548e2009-08-11 05:31:07 +00004055 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4056 if (SubExpr.isInvalid())
4057 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004058
Douglas Gregora16548e2009-08-11 05:31:07 +00004059 if (!getDerived().AlwaysRebuild() &&
4060 T == E->getType() &&
4061 SubExpr.get() == E->getSubExpr())
4062 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004063
Douglas Gregora16548e2009-08-11 05:31:07 +00004064 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4065 T, E->getRParenLoc());
4066}
4067
4068template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004069Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004070TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E,
4071 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004072 bool ArgumentChanged = false;
4073 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4074 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4075 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4076 if (Init.isInvalid())
4077 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004078
Douglas Gregora16548e2009-08-11 05:31:07 +00004079 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4080 Inits.push_back(Init.takeAs<Expr>());
4081 }
Mike Stump11289f42009-09-09 15:08:12 +00004082
Douglas Gregora16548e2009-08-11 05:31:07 +00004083 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4084 move_arg(Inits),
4085 E->getRParenLoc());
4086}
Mike Stump11289f42009-09-09 15:08:12 +00004087
Douglas Gregora16548e2009-08-11 05:31:07 +00004088/// \brief Transform an address-of-label expression.
4089///
4090/// By default, the transformation of an address-of-label expression always
4091/// rebuilds the expression, so that the label identifier can be resolved to
4092/// the corresponding label statement by semantic analysis.
4093template<typename Derived>
4094Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004095TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E,
4096 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004097 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4098 E->getLabel());
4099}
Mike Stump11289f42009-09-09 15:08:12 +00004100
4101template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004102Sema::OwningExprResult
4103TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E,
4104 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004105 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004106 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4107 if (SubStmt.isInvalid())
4108 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004109
Douglas Gregora16548e2009-08-11 05:31:07 +00004110 if (!getDerived().AlwaysRebuild() &&
4111 SubStmt.get() == E->getSubStmt())
4112 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004113
4114 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004115 move(SubStmt),
4116 E->getRParenLoc());
4117}
Mike Stump11289f42009-09-09 15:08:12 +00004118
Douglas Gregora16548e2009-08-11 05:31:07 +00004119template<typename Derived>
4120Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004121TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E,
4122 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004123 QualType T1, T2;
4124 {
4125 // FIXME: Source location isn't quite accurate.
4126 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004127
Douglas Gregora16548e2009-08-11 05:31:07 +00004128 T1 = getDerived().TransformType(E->getArgType1());
4129 if (T1.isNull())
4130 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004131
Douglas Gregora16548e2009-08-11 05:31:07 +00004132 T2 = getDerived().TransformType(E->getArgType2());
4133 if (T2.isNull())
4134 return SemaRef.ExprError();
4135 }
4136
4137 if (!getDerived().AlwaysRebuild() &&
4138 T1 == E->getArgType1() &&
4139 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004140 return SemaRef.Owned(E->Retain());
4141
Douglas Gregora16548e2009-08-11 05:31:07 +00004142 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4143 T1, T2, E->getRParenLoc());
4144}
Mike Stump11289f42009-09-09 15:08:12 +00004145
Douglas Gregora16548e2009-08-11 05:31:07 +00004146template<typename Derived>
4147Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004148TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E,
4149 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004150 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4151 if (Cond.isInvalid())
4152 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004153
Douglas Gregora16548e2009-08-11 05:31:07 +00004154 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4155 if (LHS.isInvalid())
4156 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004157
Douglas Gregora16548e2009-08-11 05:31:07 +00004158 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4159 if (RHS.isInvalid())
4160 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004161
Douglas Gregora16548e2009-08-11 05:31:07 +00004162 if (!getDerived().AlwaysRebuild() &&
4163 Cond.get() == E->getCond() &&
4164 LHS.get() == E->getLHS() &&
4165 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004166 return SemaRef.Owned(E->Retain());
4167
Douglas Gregora16548e2009-08-11 05:31:07 +00004168 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4169 move(Cond), move(LHS), move(RHS),
4170 E->getRParenLoc());
4171}
Mike Stump11289f42009-09-09 15:08:12 +00004172
Douglas Gregora16548e2009-08-11 05:31:07 +00004173template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004174Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004175TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E,
4176 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004177 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004178}
4179
4180template<typename Derived>
4181Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004182TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E,
4183 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004184 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4185 if (Callee.isInvalid())
4186 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004187
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004188 OwningExprResult First
4189 = getDerived().TransformExpr(E->getArg(0),
4190 E->getNumArgs() == 1 && E->getOperator() == OO_Amp);
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
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004216TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E,
4217 bool isAddressOfOperand) {
4218 return getDerived().TransformCallExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004219}
Mike Stump11289f42009-09-09 15:08:12 +00004220
Douglas Gregora16548e2009-08-11 05:31:07 +00004221template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004222Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004223TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E,
4224 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004225 QualType ExplicitTy;
4226 {
4227 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004228 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004229 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4230 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004231
Douglas Gregora16548e2009-08-11 05:31:07 +00004232 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4233 if (ExplicitTy.isNull())
4234 return SemaRef.ExprError();
4235 }
Mike Stump11289f42009-09-09 15:08:12 +00004236
Douglas Gregora16548e2009-08-11 05:31:07 +00004237 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4238 if (SubExpr.isInvalid())
4239 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004240
Douglas Gregora16548e2009-08-11 05:31:07 +00004241 if (!getDerived().AlwaysRebuild() &&
4242 ExplicitTy == E->getTypeAsWritten() &&
4243 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004244 return SemaRef.Owned(E->Retain());
4245
Douglas Gregora16548e2009-08-11 05:31:07 +00004246 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004247 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004248 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4249 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4250 SourceLocation FakeRParenLoc
4251 = SemaRef.PP.getLocForEndOfToken(
4252 E->getSubExpr()->getSourceRange().getEnd());
4253 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004254 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004255 FakeLAngleLoc,
4256 ExplicitTy,
4257 FakeRAngleLoc,
4258 FakeRAngleLoc,
4259 move(SubExpr),
4260 FakeRParenLoc);
4261}
Mike Stump11289f42009-09-09 15:08:12 +00004262
Douglas Gregora16548e2009-08-11 05:31:07 +00004263template<typename Derived>
4264Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004265TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E,
4266 bool isAddressOfOperand) {
4267 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004268}
Mike Stump11289f42009-09-09 15:08:12 +00004269
4270template<typename Derived>
4271Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004272TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E,
4273 bool isAddressOfOperand) {
4274 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Mike Stump11289f42009-09-09 15:08:12 +00004275}
4276
Douglas Gregora16548e2009-08-11 05:31:07 +00004277template<typename Derived>
4278Sema::OwningExprResult
4279TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004280 CXXReinterpretCastExpr *E,
4281 bool isAddressOfOperand) {
4282 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004283}
Mike Stump11289f42009-09-09 15:08:12 +00004284
Douglas Gregora16548e2009-08-11 05:31:07 +00004285template<typename Derived>
4286Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004287TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E,
4288 bool isAddressOfOperand) {
4289 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004290}
Mike Stump11289f42009-09-09 15:08:12 +00004291
Douglas Gregora16548e2009-08-11 05:31:07 +00004292template<typename Derived>
4293Sema::OwningExprResult
4294TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004295 CXXFunctionalCastExpr *E,
4296 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004297 QualType ExplicitTy;
4298 {
4299 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004300
Douglas Gregora16548e2009-08-11 05:31:07 +00004301 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4302 if (ExplicitTy.isNull())
4303 return SemaRef.ExprError();
4304 }
Mike Stump11289f42009-09-09 15:08:12 +00004305
Douglas Gregora16548e2009-08-11 05:31:07 +00004306 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4307 if (SubExpr.isInvalid())
4308 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004309
Douglas Gregora16548e2009-08-11 05:31:07 +00004310 if (!getDerived().AlwaysRebuild() &&
4311 ExplicitTy == E->getTypeAsWritten() &&
4312 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004313 return SemaRef.Owned(E->Retain());
4314
Douglas Gregora16548e2009-08-11 05:31:07 +00004315 // FIXME: The end of the type's source range is wrong
4316 return getDerived().RebuildCXXFunctionalCastExpr(
4317 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
4318 ExplicitTy,
4319 /*FIXME:*/E->getSubExpr()->getLocStart(),
4320 move(SubExpr),
4321 E->getRParenLoc());
4322}
Mike Stump11289f42009-09-09 15:08:12 +00004323
Douglas Gregora16548e2009-08-11 05:31:07 +00004324template<typename Derived>
4325Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004326TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E,
4327 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004328 if (E->isTypeOperand()) {
4329 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004330
Douglas Gregora16548e2009-08-11 05:31:07 +00004331 QualType T = getDerived().TransformType(E->getTypeOperand());
4332 if (T.isNull())
4333 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004334
Douglas Gregora16548e2009-08-11 05:31:07 +00004335 if (!getDerived().AlwaysRebuild() &&
4336 T == E->getTypeOperand())
4337 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004338
Douglas Gregora16548e2009-08-11 05:31:07 +00004339 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4340 /*FIXME:*/E->getLocStart(),
4341 T,
4342 E->getLocEnd());
4343 }
Mike Stump11289f42009-09-09 15:08:12 +00004344
Douglas Gregora16548e2009-08-11 05:31:07 +00004345 // We don't know whether the expression is potentially evaluated until
4346 // after we perform semantic analysis, so the expression is potentially
4347 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004348 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004349 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004350
Douglas Gregora16548e2009-08-11 05:31:07 +00004351 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4352 if (SubExpr.isInvalid())
4353 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004354
Douglas Gregora16548e2009-08-11 05:31:07 +00004355 if (!getDerived().AlwaysRebuild() &&
4356 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004357 return SemaRef.Owned(E->Retain());
4358
Douglas Gregora16548e2009-08-11 05:31:07 +00004359 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4360 /*FIXME:*/E->getLocStart(),
4361 move(SubExpr),
4362 E->getLocEnd());
4363}
4364
4365template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004366Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004367TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E,
4368 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004369 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004370}
Mike Stump11289f42009-09-09 15:08:12 +00004371
Douglas Gregora16548e2009-08-11 05:31:07 +00004372template<typename Derived>
4373Sema::OwningExprResult
4374TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004375 CXXNullPtrLiteralExpr *E,
4376 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004377 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004378}
Mike Stump11289f42009-09-09 15:08:12 +00004379
Douglas Gregora16548e2009-08-11 05:31:07 +00004380template<typename Derived>
4381Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004382TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E,
4383 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004384 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004385
Douglas Gregora16548e2009-08-11 05:31:07 +00004386 QualType T = getDerived().TransformType(E->getType());
4387 if (T.isNull())
4388 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004389
Douglas Gregora16548e2009-08-11 05:31:07 +00004390 if (!getDerived().AlwaysRebuild() &&
4391 T == E->getType())
4392 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004393
Douglas Gregora16548e2009-08-11 05:31:07 +00004394 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T);
4395}
Mike Stump11289f42009-09-09 15:08:12 +00004396
Douglas Gregora16548e2009-08-11 05:31:07 +00004397template<typename Derived>
4398Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004399TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E,
4400 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004401 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4402 if (SubExpr.isInvalid())
4403 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004404
Douglas Gregora16548e2009-08-11 05:31:07 +00004405 if (!getDerived().AlwaysRebuild() &&
4406 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004407 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004408
4409 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4410}
Mike Stump11289f42009-09-09 15:08:12 +00004411
Douglas Gregora16548e2009-08-11 05:31:07 +00004412template<typename Derived>
4413Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004414TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E,
4415 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004416 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004417 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4418 if (!Param)
4419 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004420
Douglas Gregora16548e2009-08-11 05:31:07 +00004421 if (getDerived().AlwaysRebuild() &&
4422 Param == E->getParam())
4423 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004424
Douglas Gregora16548e2009-08-11 05:31:07 +00004425 return getDerived().RebuildCXXDefaultArgExpr(Param);
4426}
Mike Stump11289f42009-09-09 15:08:12 +00004427
Douglas Gregora16548e2009-08-11 05:31:07 +00004428template<typename Derived>
4429Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004430TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E,
4431 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004432 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4433
4434 QualType T = getDerived().TransformType(E->getType());
4435 if (T.isNull())
4436 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004437
Douglas Gregora16548e2009-08-11 05:31:07 +00004438 if (!getDerived().AlwaysRebuild() &&
4439 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004440 return SemaRef.Owned(E->Retain());
4441
4442 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004443 /*FIXME:*/E->getTypeBeginLoc(),
4444 T,
4445 E->getRParenLoc());
4446}
Mike Stump11289f42009-09-09 15:08:12 +00004447
Douglas Gregora16548e2009-08-11 05:31:07 +00004448template<typename Derived>
4449Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004450TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E,
4451 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004452 // Transform the type that we're allocating
4453 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4454 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4455 if (AllocType.isNull())
4456 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004457
Douglas Gregora16548e2009-08-11 05:31:07 +00004458 // Transform the size of the array we're allocating (if any).
4459 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4460 if (ArraySize.isInvalid())
4461 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004462
Douglas Gregora16548e2009-08-11 05:31:07 +00004463 // Transform the placement arguments (if any).
4464 bool ArgumentChanged = false;
4465 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4466 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4467 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4468 if (Arg.isInvalid())
4469 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004470
Douglas Gregora16548e2009-08-11 05:31:07 +00004471 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4472 PlacementArgs.push_back(Arg.take());
4473 }
Mike Stump11289f42009-09-09 15:08:12 +00004474
Douglas Gregorebe10102009-08-20 07:17:43 +00004475 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004476 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4477 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4478 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4479 if (Arg.isInvalid())
4480 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004481
Douglas Gregora16548e2009-08-11 05:31:07 +00004482 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4483 ConstructorArgs.push_back(Arg.take());
4484 }
Mike Stump11289f42009-09-09 15:08:12 +00004485
Douglas Gregora16548e2009-08-11 05:31:07 +00004486 if (!getDerived().AlwaysRebuild() &&
4487 AllocType == E->getAllocatedType() &&
4488 ArraySize.get() == E->getArraySize() &&
4489 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004490 return SemaRef.Owned(E->Retain());
4491
Douglas Gregora16548e2009-08-11 05:31:07 +00004492 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4493 E->isGlobalNew(),
4494 /*FIXME:*/E->getLocStart(),
4495 move_arg(PlacementArgs),
4496 /*FIXME:*/E->getLocStart(),
4497 E->isParenTypeId(),
4498 AllocType,
4499 /*FIXME:*/E->getLocStart(),
4500 /*FIXME:*/SourceRange(),
4501 move(ArraySize),
4502 /*FIXME:*/E->getLocStart(),
4503 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004504 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004505}
Mike Stump11289f42009-09-09 15:08:12 +00004506
Douglas Gregora16548e2009-08-11 05:31:07 +00004507template<typename Derived>
4508Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004509TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E,
4510 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004511 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4512 if (Operand.isInvalid())
4513 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004514
Douglas Gregora16548e2009-08-11 05:31:07 +00004515 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004516 Operand.get() == E->getArgument())
4517 return SemaRef.Owned(E->Retain());
4518
Douglas Gregora16548e2009-08-11 05:31:07 +00004519 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4520 E->isGlobalDelete(),
4521 E->isArrayForm(),
4522 move(Operand));
4523}
Mike Stump11289f42009-09-09 15:08:12 +00004524
Douglas Gregora16548e2009-08-11 05:31:07 +00004525template<typename Derived>
4526Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004527TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004528 CXXPseudoDestructorExpr *E,
4529 bool isAddressOfOperand) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004530 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4531 if (Base.isInvalid())
4532 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004533
Douglas Gregorad8a3362009-09-04 17:36:40 +00004534 NestedNameSpecifier *Qualifier
4535 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4536 E->getQualifierRange());
4537 if (E->getQualifier() && !Qualifier)
4538 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004539
Douglas Gregorad8a3362009-09-04 17:36:40 +00004540 QualType DestroyedType;
4541 {
4542 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4543 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4544 if (DestroyedType.isNull())
4545 return SemaRef.ExprError();
4546 }
Mike Stump11289f42009-09-09 15:08:12 +00004547
Douglas Gregorad8a3362009-09-04 17:36:40 +00004548 if (!getDerived().AlwaysRebuild() &&
4549 Base.get() == E->getBase() &&
4550 Qualifier == E->getQualifier() &&
4551 DestroyedType == E->getDestroyedType())
4552 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004553
Douglas Gregorad8a3362009-09-04 17:36:40 +00004554 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4555 E->getOperatorLoc(),
4556 E->isArrow(),
4557 E->getDestroyedTypeLoc(),
4558 DestroyedType,
4559 Qualifier,
4560 E->getQualifierRange());
4561}
Mike Stump11289f42009-09-09 15:08:12 +00004562
Douglas Gregorad8a3362009-09-04 17:36:40 +00004563template<typename Derived>
4564Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004565TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCalle66edc12009-11-24 19:00:30 +00004566 UnresolvedLookupExpr *Old,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004567 bool isAddressOfOperand) {
John McCalle66edc12009-11-24 19:00:30 +00004568 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4569
4570 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4571 Sema::LookupOrdinaryName);
4572
4573 // Transform all the decls.
4574 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4575 E = Old->decls_end(); I != E; ++I) {
4576 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
4577 if (!InstD)
4578 return SemaRef.ExprError();
4579
4580 // Expand using declarations.
4581 if (isa<UsingDecl>(InstD)) {
4582 UsingDecl *UD = cast<UsingDecl>(InstD);
4583 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4584 E = UD->shadow_end(); I != E; ++I)
4585 R.addDecl(*I);
4586 continue;
4587 }
4588
4589 R.addDecl(InstD);
4590 }
4591
4592 // Resolve a kind, but don't do any further analysis. If it's
4593 // ambiguous, the callee needs to deal with it.
4594 R.resolveKind();
4595
4596 // Rebuild the nested-name qualifier, if present.
4597 CXXScopeSpec SS;
4598 NestedNameSpecifier *Qualifier = 0;
4599 if (Old->getQualifier()) {
4600 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4601 Old->getQualifierRange());
4602 if (!Qualifier)
4603 return SemaRef.ExprError();
4604
4605 SS.setScopeRep(Qualifier);
4606 SS.setRange(Old->getQualifierRange());
4607 }
4608
4609 // If we have no template arguments, it's a normal declaration name.
4610 if (!Old->hasExplicitTemplateArgs())
4611 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4612
4613 // If we have template arguments, rebuild them, then rebuild the
4614 // templateid expression.
4615 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4616 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4617 TemplateArgumentLoc Loc;
4618 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4619 return SemaRef.ExprError();
4620 TransArgs.addArgument(Loc);
4621 }
4622
4623 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4624 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004625}
Mike Stump11289f42009-09-09 15:08:12 +00004626
Douglas Gregora16548e2009-08-11 05:31:07 +00004627template<typename Derived>
4628Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004629TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E,
4630 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004631 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004632
Douglas Gregora16548e2009-08-11 05:31:07 +00004633 QualType T = getDerived().TransformType(E->getQueriedType());
4634 if (T.isNull())
4635 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004636
Douglas Gregora16548e2009-08-11 05:31:07 +00004637 if (!getDerived().AlwaysRebuild() &&
4638 T == E->getQueriedType())
4639 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004640
Douglas Gregora16548e2009-08-11 05:31:07 +00004641 // FIXME: Bad location information
4642 SourceLocation FakeLParenLoc
4643 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004644
4645 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004646 E->getLocStart(),
4647 /*FIXME:*/FakeLParenLoc,
4648 T,
4649 E->getLocEnd());
4650}
Mike Stump11289f42009-09-09 15:08:12 +00004651
Douglas Gregora16548e2009-08-11 05:31:07 +00004652template<typename Derived>
4653Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004654TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
4655 DependentScopeDeclRefExpr *E,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004656 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004657 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004658 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4659 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004660 if (!NNS)
4661 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004662
4663 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004664 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4665 if (!Name)
4666 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004667
John McCalle66edc12009-11-24 19:00:30 +00004668 if (!E->hasExplicitTemplateArgs()) {
4669 if (!getDerived().AlwaysRebuild() &&
4670 NNS == E->getQualifier() &&
4671 Name == E->getDeclName())
4672 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004673
John McCalle66edc12009-11-24 19:00:30 +00004674 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4675 E->getQualifierRange(),
4676 Name, E->getLocation(),
4677 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004678 }
John McCall6b51f282009-11-23 01:53:49 +00004679
4680 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004681 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004682 TemplateArgumentLoc Loc;
4683 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004684 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004685 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004686 }
4687
John McCalle66edc12009-11-24 19:00:30 +00004688 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4689 E->getQualifierRange(),
4690 Name, E->getLocation(),
4691 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004692}
4693
4694template<typename Derived>
4695Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004696TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E,
4697 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004698 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4699
4700 QualType T = getDerived().TransformType(E->getType());
4701 if (T.isNull())
4702 return SemaRef.ExprError();
4703
4704 CXXConstructorDecl *Constructor
4705 = cast_or_null<CXXConstructorDecl>(
4706 getDerived().TransformDecl(E->getConstructor()));
4707 if (!Constructor)
4708 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004709
Douglas Gregora16548e2009-08-11 05:31:07 +00004710 bool ArgumentChanged = false;
4711 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004712 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004713 ArgEnd = E->arg_end();
4714 Arg != ArgEnd; ++Arg) {
4715 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4716 if (TransArg.isInvalid())
4717 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004718
Douglas Gregora16548e2009-08-11 05:31:07 +00004719 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4720 Args.push_back(TransArg.takeAs<Expr>());
4721 }
4722
4723 if (!getDerived().AlwaysRebuild() &&
4724 T == E->getType() &&
4725 Constructor == E->getConstructor() &&
4726 !ArgumentChanged)
4727 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004728
Douglas Gregora16548e2009-08-11 05:31:07 +00004729 return getDerived().RebuildCXXConstructExpr(T, Constructor, E->isElidable(),
4730 move_arg(Args));
4731}
Mike Stump11289f42009-09-09 15:08:12 +00004732
Douglas Gregora16548e2009-08-11 05:31:07 +00004733/// \brief Transform a C++ temporary-binding expression.
4734///
Mike Stump11289f42009-09-09 15:08:12 +00004735/// The transformation of a temporary-binding expression always attempts to
4736/// bind a new temporary variable to its subexpression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004737/// subexpression itself did not change, because the temporary variable itself
4738/// must be unique.
4739template<typename Derived>
4740Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004741TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E,
4742 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004743 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4744 if (SubExpr.isInvalid())
4745 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004746
Douglas Gregora16548e2009-08-11 05:31:07 +00004747 return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>());
4748}
Mike Stump11289f42009-09-09 15:08:12 +00004749
4750/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004751/// be destroyed after the expression is evaluated.
4752///
Mike Stump11289f42009-09-09 15:08:12 +00004753/// The transformation of a full expression always attempts to build a new
4754/// CXXExprWithTemporaries expression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004755/// subexpression itself did not change, because it will need to capture the
4756/// the new temporary variables introduced in the subexpression.
4757template<typename Derived>
4758Sema::OwningExprResult
4759TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004760 CXXExprWithTemporaries *E,
4761 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004762 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4763 if (SubExpr.isInvalid())
4764 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004765
Douglas Gregora16548e2009-08-11 05:31:07 +00004766 return SemaRef.Owned(
4767 SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(),
4768 E->shouldDestroyTemporaries()));
4769}
Mike Stump11289f42009-09-09 15:08:12 +00004770
Douglas Gregora16548e2009-08-11 05:31:07 +00004771template<typename Derived>
4772Sema::OwningExprResult
4773TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004774 CXXTemporaryObjectExpr *E,
4775 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004776 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4777 QualType T = getDerived().TransformType(E->getType());
4778 if (T.isNull())
4779 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004780
Douglas Gregora16548e2009-08-11 05:31:07 +00004781 CXXConstructorDecl *Constructor
4782 = cast_or_null<CXXConstructorDecl>(
4783 getDerived().TransformDecl(E->getConstructor()));
4784 if (!Constructor)
4785 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004786
Douglas Gregora16548e2009-08-11 05:31:07 +00004787 bool ArgumentChanged = false;
4788 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4789 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004790 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004791 ArgEnd = E->arg_end();
4792 Arg != ArgEnd; ++Arg) {
4793 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4794 if (TransArg.isInvalid())
4795 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004796
Douglas Gregora16548e2009-08-11 05:31:07 +00004797 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4798 Args.push_back((Expr *)TransArg.release());
4799 }
Mike Stump11289f42009-09-09 15:08:12 +00004800
Douglas Gregora16548e2009-08-11 05:31:07 +00004801 if (!getDerived().AlwaysRebuild() &&
4802 T == E->getType() &&
4803 Constructor == E->getConstructor() &&
4804 !ArgumentChanged)
4805 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004806
Douglas Gregora16548e2009-08-11 05:31:07 +00004807 // FIXME: Bogus location information
4808 SourceLocation CommaLoc;
4809 if (Args.size() > 1) {
4810 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004811 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004812 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4813 }
4814 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4815 T,
4816 /*FIXME:*/E->getTypeBeginLoc(),
4817 move_arg(Args),
4818 &CommaLoc,
4819 E->getLocEnd());
4820}
Mike Stump11289f42009-09-09 15:08:12 +00004821
Douglas Gregora16548e2009-08-11 05:31:07 +00004822template<typename Derived>
4823Sema::OwningExprResult
4824TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004825 CXXUnresolvedConstructExpr *E,
4826 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004827 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4828 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4829 if (T.isNull())
4830 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004831
Douglas Gregora16548e2009-08-11 05:31:07 +00004832 bool ArgumentChanged = false;
4833 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4834 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4835 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4836 ArgEnd = E->arg_end();
4837 Arg != ArgEnd; ++Arg) {
4838 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4839 if (TransArg.isInvalid())
4840 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004841
Douglas Gregora16548e2009-08-11 05:31:07 +00004842 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4843 FakeCommaLocs.push_back(
4844 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4845 Args.push_back(TransArg.takeAs<Expr>());
4846 }
Mike Stump11289f42009-09-09 15:08:12 +00004847
Douglas Gregora16548e2009-08-11 05:31:07 +00004848 if (!getDerived().AlwaysRebuild() &&
4849 T == E->getTypeAsWritten() &&
4850 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004851 return SemaRef.Owned(E->Retain());
4852
Douglas Gregora16548e2009-08-11 05:31:07 +00004853 // FIXME: we're faking the locations of the commas
4854 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4855 T,
4856 E->getLParenLoc(),
4857 move_arg(Args),
4858 FakeCommaLocs.data(),
4859 E->getRParenLoc());
4860}
Mike Stump11289f42009-09-09 15:08:12 +00004861
Douglas Gregora16548e2009-08-11 05:31:07 +00004862template<typename Derived>
4863Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004864TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
4865 CXXDependentScopeMemberExpr *E,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004866 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004867 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004868 OwningExprResult Base(SemaRef, (Expr*) 0);
4869 Expr *OldBase;
4870 QualType BaseType;
4871 QualType ObjectType;
4872 if (!E->isImplicitAccess()) {
4873 OldBase = E->getBase();
4874 Base = getDerived().TransformExpr(OldBase);
4875 if (Base.isInvalid())
4876 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004877
John McCall2d74de92009-12-01 22:10:20 +00004878 // Start the member reference and compute the object's type.
4879 Sema::TypeTy *ObjectTy = 0;
4880 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4881 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004882 E->isArrow()? tok::arrow : tok::period,
John McCall2d74de92009-12-01 22:10:20 +00004883 ObjectTy);
4884 if (Base.isInvalid())
4885 return SemaRef.ExprError();
4886
4887 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
4888 BaseType = ((Expr*) Base.get())->getType();
4889 } else {
4890 OldBase = 0;
4891 BaseType = getDerived().TransformType(E->getBaseType());
4892 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
4893 }
Mike Stump11289f42009-09-09 15:08:12 +00004894
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004895 // Transform the first part of the nested-name-specifier that qualifies
4896 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004897 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004898 = getDerived().TransformFirstQualifierInScope(
4899 E->getFirstQualifierFoundInScope(),
4900 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00004901
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004902 NestedNameSpecifier *Qualifier = 0;
4903 if (E->getQualifier()) {
4904 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4905 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00004906 ObjectType,
4907 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004908 if (!Qualifier)
4909 return SemaRef.ExprError();
4910 }
Mike Stump11289f42009-09-09 15:08:12 +00004911
4912 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00004913 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00004914 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00004915 if (!Name)
4916 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004917
John McCall2d74de92009-12-01 22:10:20 +00004918 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00004919 // This is a reference to a member without an explicitly-specified
4920 // template argument list. Optimize for this common case.
4921 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00004922 Base.get() == OldBase &&
4923 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00004924 Qualifier == E->getQualifier() &&
4925 Name == E->getMember() &&
4926 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00004927 return SemaRef.Owned(E->Retain());
4928
John McCall8cd78132009-11-19 22:55:06 +00004929 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00004930 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00004931 E->isArrow(),
4932 E->getOperatorLoc(),
4933 Qualifier,
4934 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00004935 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00004936 Name,
4937 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00004938 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00004939 }
4940
John McCall6b51f282009-11-23 01:53:49 +00004941 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00004942 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004943 TemplateArgumentLoc Loc;
4944 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00004945 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004946 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00004947 }
Mike Stump11289f42009-09-09 15:08:12 +00004948
John McCall8cd78132009-11-19 22:55:06 +00004949 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00004950 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00004951 E->isArrow(),
4952 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004953 Qualifier,
4954 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004955 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00004956 Name,
4957 E->getMemberLoc(),
4958 &TransArgs);
4959}
4960
4961template<typename Derived>
4962Sema::OwningExprResult
4963TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old,
4964 bool isAddressOfOperand) {
4965 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004966 OwningExprResult Base(SemaRef, (Expr*) 0);
4967 QualType BaseType;
4968 if (!Old->isImplicitAccess()) {
4969 Base = getDerived().TransformExpr(Old->getBase());
4970 if (Base.isInvalid())
4971 return SemaRef.ExprError();
4972 BaseType = ((Expr*) Base.get())->getType();
4973 } else {
4974 BaseType = getDerived().TransformType(Old->getBaseType());
4975 }
John McCall10eae182009-11-30 22:42:35 +00004976
4977 NestedNameSpecifier *Qualifier = 0;
4978 if (Old->getQualifier()) {
4979 Qualifier
4980 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4981 Old->getQualifierRange());
4982 if (Qualifier == 0)
4983 return SemaRef.ExprError();
4984 }
4985
4986 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
4987 Sema::LookupOrdinaryName);
4988
4989 // Transform all the decls.
4990 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
4991 E = Old->decls_end(); I != E; ++I) {
4992 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
4993 if (!InstD)
4994 return SemaRef.ExprError();
4995
4996 // Expand using declarations.
4997 if (isa<UsingDecl>(InstD)) {
4998 UsingDecl *UD = cast<UsingDecl>(InstD);
4999 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5000 E = UD->shadow_end(); I != E; ++I)
5001 R.addDecl(*I);
5002 continue;
5003 }
5004
5005 R.addDecl(InstD);
5006 }
5007
5008 R.resolveKind();
5009
5010 TemplateArgumentListInfo TransArgs;
5011 if (Old->hasExplicitTemplateArgs()) {
5012 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5013 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5014 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5015 TemplateArgumentLoc Loc;
5016 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5017 Loc))
5018 return SemaRef.ExprError();
5019 TransArgs.addArgument(Loc);
5020 }
5021 }
5022
5023 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005024 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005025 Old->getOperatorLoc(),
5026 Old->isArrow(),
5027 Qualifier,
5028 Old->getQualifierRange(),
5029 R,
5030 (Old->hasExplicitTemplateArgs()
5031 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005032}
5033
5034template<typename Derived>
5035Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005036TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E,
5037 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00005038 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005039}
5040
Mike Stump11289f42009-09-09 15:08:12 +00005041template<typename Derived>
5042Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005043TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E,
5044 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005045 // FIXME: poor source location
5046 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5047 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5048 if (EncodedType.isNull())
5049 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005050
Douglas Gregora16548e2009-08-11 05:31:07 +00005051 if (!getDerived().AlwaysRebuild() &&
5052 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00005053 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005054
5055 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5056 EncodedType,
5057 E->getRParenLoc());
5058}
Mike Stump11289f42009-09-09 15:08:12 +00005059
Douglas Gregora16548e2009-08-11 05:31:07 +00005060template<typename Derived>
5061Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005062TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E,
5063 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005064 // FIXME: Implement this!
5065 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005066 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005067}
5068
Mike Stump11289f42009-09-09 15:08:12 +00005069template<typename Derived>
5070Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005071TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E,
5072 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00005073 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005074}
5075
Mike Stump11289f42009-09-09 15:08:12 +00005076template<typename Derived>
5077Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005078TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E,
5079 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00005080 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00005081 = cast_or_null<ObjCProtocolDecl>(
5082 getDerived().TransformDecl(E->getProtocol()));
5083 if (!Protocol)
5084 return SemaRef.ExprError();
5085
5086 if (!getDerived().AlwaysRebuild() &&
5087 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005088 return SemaRef.Owned(E->Retain());
5089
Douglas Gregora16548e2009-08-11 05:31:07 +00005090 return getDerived().RebuildObjCProtocolExpr(Protocol,
5091 E->getAtLoc(),
5092 /*FIXME:*/E->getAtLoc(),
5093 /*FIXME:*/E->getAtLoc(),
5094 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005095
Douglas Gregora16548e2009-08-11 05:31:07 +00005096}
5097
Mike Stump11289f42009-09-09 15:08:12 +00005098template<typename Derived>
5099Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005100TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E,
5101 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005102 // FIXME: Implement this!
5103 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005104 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005105}
5106
Mike Stump11289f42009-09-09 15:08:12 +00005107template<typename Derived>
5108Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005109TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E,
5110 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005111 // FIXME: Implement this!
5112 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005113 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005114}
5115
Mike Stump11289f42009-09-09 15:08:12 +00005116template<typename Derived>
5117Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005118TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005119 ObjCImplicitSetterGetterRefExpr *E,
5120 bool isAddressOfOperand) {
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
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005128TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E,
5129 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005130 // FIXME: Implement this!
5131 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005132 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005133}
5134
Mike Stump11289f42009-09-09 15:08:12 +00005135template<typename Derived>
5136Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005137TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E,
5138 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005139 // FIXME: Implement this!
5140 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005141 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005142}
5143
Mike Stump11289f42009-09-09 15:08:12 +00005144template<typename Derived>
5145Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005146TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E,
5147 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005148 bool ArgumentChanged = false;
5149 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5150 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5151 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5152 if (SubExpr.isInvalid())
5153 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005154
Douglas Gregora16548e2009-08-11 05:31:07 +00005155 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5156 SubExprs.push_back(SubExpr.takeAs<Expr>());
5157 }
Mike Stump11289f42009-09-09 15:08:12 +00005158
Douglas Gregora16548e2009-08-11 05:31:07 +00005159 if (!getDerived().AlwaysRebuild() &&
5160 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005161 return SemaRef.Owned(E->Retain());
5162
Douglas Gregora16548e2009-08-11 05:31:07 +00005163 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5164 move_arg(SubExprs),
5165 E->getRParenLoc());
5166}
5167
Mike Stump11289f42009-09-09 15:08:12 +00005168template<typename Derived>
5169Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005170TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E,
5171 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005172 // FIXME: Implement this!
5173 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005174 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005175}
5176
Mike Stump11289f42009-09-09 15:08:12 +00005177template<typename Derived>
5178Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005179TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E,
5180 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005181 // FIXME: Implement this!
5182 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005183 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005184}
Mike Stump11289f42009-09-09 15:08:12 +00005185
Douglas Gregora16548e2009-08-11 05:31:07 +00005186//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005187// Type reconstruction
5188//===----------------------------------------------------------------------===//
5189
Mike Stump11289f42009-09-09 15:08:12 +00005190template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005191QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5192 SourceLocation Star) {
5193 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005194 getDerived().getBaseEntity());
5195}
5196
Mike Stump11289f42009-09-09 15:08:12 +00005197template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005198QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5199 SourceLocation Star) {
5200 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005201 getDerived().getBaseEntity());
5202}
5203
Mike Stump11289f42009-09-09 15:08:12 +00005204template<typename Derived>
5205QualType
John McCall70dd5f62009-10-30 00:06:24 +00005206TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5207 bool WrittenAsLValue,
5208 SourceLocation Sigil) {
5209 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5210 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005211}
5212
5213template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005214QualType
John McCall70dd5f62009-10-30 00:06:24 +00005215TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5216 QualType ClassType,
5217 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005218 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005219 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005220}
5221
5222template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005223QualType
John McCall70dd5f62009-10-30 00:06:24 +00005224TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5225 SourceLocation Sigil) {
5226 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005227 getDerived().getBaseEntity());
5228}
5229
5230template<typename Derived>
5231QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005232TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5233 ArrayType::ArraySizeModifier SizeMod,
5234 const llvm::APInt *Size,
5235 Expr *SizeExpr,
5236 unsigned IndexTypeQuals,
5237 SourceRange BracketsRange) {
5238 if (SizeExpr || !Size)
5239 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5240 IndexTypeQuals, BracketsRange,
5241 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005242
5243 QualType Types[] = {
5244 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5245 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5246 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005247 };
5248 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5249 QualType SizeType;
5250 for (unsigned I = 0; I != NumTypes; ++I)
5251 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5252 SizeType = Types[I];
5253 break;
5254 }
Mike Stump11289f42009-09-09 15:08:12 +00005255
Douglas Gregord6ff3322009-08-04 16:50:30 +00005256 if (SizeType.isNull())
5257 SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false);
Mike Stump11289f42009-09-09 15:08:12 +00005258
Douglas Gregord6ff3322009-08-04 16:50:30 +00005259 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005260 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005261 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005262 getDerived().getBaseEntity());
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>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005268 ArrayType::ArraySizeModifier SizeMod,
5269 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005270 unsigned IndexTypeQuals,
5271 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005272 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005273 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005274}
5275
5276template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005277QualType
Mike Stump11289f42009-09-09 15:08:12 +00005278TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005279 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005280 unsigned IndexTypeQuals,
5281 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005282 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005283 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005284}
Mike Stump11289f42009-09-09 15:08:12 +00005285
Douglas Gregord6ff3322009-08-04 16:50:30 +00005286template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005287QualType
5288TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005289 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005290 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005291 unsigned IndexTypeQuals,
5292 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005293 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005294 SizeExpr.takeAs<Expr>(),
5295 IndexTypeQuals, BracketsRange);
5296}
5297
5298template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005299QualType
5300TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005301 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005302 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005303 unsigned IndexTypeQuals,
5304 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005305 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005306 SizeExpr.takeAs<Expr>(),
5307 IndexTypeQuals, BracketsRange);
5308}
5309
5310template<typename Derived>
5311QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
5312 unsigned NumElements) {
5313 // FIXME: semantic checking!
5314 return SemaRef.Context.getVectorType(ElementType, NumElements);
5315}
Mike Stump11289f42009-09-09 15:08:12 +00005316
Douglas Gregord6ff3322009-08-04 16:50:30 +00005317template<typename Derived>
5318QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5319 unsigned NumElements,
5320 SourceLocation AttributeLoc) {
5321 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5322 NumElements, true);
5323 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005324 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005325 AttributeLoc);
5326 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5327 AttributeLoc);
5328}
Mike Stump11289f42009-09-09 15:08:12 +00005329
Douglas Gregord6ff3322009-08-04 16:50:30 +00005330template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005331QualType
5332TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005333 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005334 SourceLocation AttributeLoc) {
5335 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5336}
Mike Stump11289f42009-09-09 15:08:12 +00005337
Douglas Gregord6ff3322009-08-04 16:50:30 +00005338template<typename Derived>
5339QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005340 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005341 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005342 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005343 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005344 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005345 Quals,
5346 getDerived().getBaseLocation(),
5347 getDerived().getBaseEntity());
5348}
Mike Stump11289f42009-09-09 15:08:12 +00005349
Douglas Gregord6ff3322009-08-04 16:50:30 +00005350template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005351QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5352 return SemaRef.Context.getFunctionNoProtoType(T);
5353}
5354
5355template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005356QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5357 assert(D && "no decl found");
5358 if (D->isInvalidDecl()) return QualType();
5359
5360 TypeDecl *Ty;
5361 if (isa<UsingDecl>(D)) {
5362 UsingDecl *Using = cast<UsingDecl>(D);
5363 assert(Using->isTypeName() &&
5364 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5365
5366 // A valid resolved using typename decl points to exactly one type decl.
5367 assert(++Using->shadow_begin() == Using->shadow_end());
5368 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5369
5370 } else {
5371 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5372 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5373 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5374 }
5375
5376 return SemaRef.Context.getTypeDeclType(Ty);
5377}
5378
5379template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005380QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005381 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5382}
5383
5384template<typename Derived>
5385QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5386 return SemaRef.Context.getTypeOfType(Underlying);
5387}
5388
5389template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005390QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005391 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5392}
5393
5394template<typename Derived>
5395QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005396 TemplateName Template,
5397 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005398 const TemplateArgumentListInfo &TemplateArgs) {
5399 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005400}
Mike Stump11289f42009-09-09 15:08:12 +00005401
Douglas Gregor1135c352009-08-06 05:28:30 +00005402template<typename Derived>
5403NestedNameSpecifier *
5404TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5405 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005406 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005407 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005408 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005409 CXXScopeSpec SS;
5410 // FIXME: The source location information is all wrong.
5411 SS.setRange(Range);
5412 SS.setScopeRep(Prefix);
5413 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005414 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005415 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005416 ObjectType,
5417 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005418 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005419}
5420
5421template<typename Derived>
5422NestedNameSpecifier *
5423TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5424 SourceRange Range,
5425 NamespaceDecl *NS) {
5426 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5427}
5428
5429template<typename Derived>
5430NestedNameSpecifier *
5431TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5432 SourceRange Range,
5433 bool TemplateKW,
5434 QualType T) {
5435 if (T->isDependentType() || T->isRecordType() ||
5436 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005437 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005438 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5439 T.getTypePtr());
5440 }
Mike Stump11289f42009-09-09 15:08:12 +00005441
Douglas Gregor1135c352009-08-06 05:28:30 +00005442 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5443 return 0;
5444}
Mike Stump11289f42009-09-09 15:08:12 +00005445
Douglas Gregor71dc5092009-08-06 06:41:21 +00005446template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005447TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005448TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5449 bool TemplateKW,
5450 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005451 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005452 Template);
5453}
5454
5455template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005456TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005457TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005458 const IdentifierInfo &II,
5459 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005460 CXXScopeSpec SS;
5461 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005462 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005463 UnqualifiedId Name;
5464 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005465 return getSema().ActOnDependentTemplateName(
5466 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005467 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005468 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005469 ObjectType.getAsOpaquePtr(),
5470 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005471 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005472}
Mike Stump11289f42009-09-09 15:08:12 +00005473
Douglas Gregora16548e2009-08-11 05:31:07 +00005474template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005475TemplateName
5476TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5477 OverloadedOperatorKind Operator,
5478 QualType ObjectType) {
5479 CXXScopeSpec SS;
5480 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5481 SS.setScopeRep(Qualifier);
5482 UnqualifiedId Name;
5483 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5484 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5485 Operator, SymbolLocations);
5486 return getSema().ActOnDependentTemplateName(
5487 /*FIXME:*/getDerived().getBaseLocation(),
5488 SS,
5489 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005490 ObjectType.getAsOpaquePtr(),
5491 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005492 .template getAsVal<TemplateName>();
5493}
5494
5495template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005496Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005497TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5498 SourceLocation OpLoc,
5499 ExprArg Callee,
5500 ExprArg First,
5501 ExprArg Second) {
5502 Expr *FirstExpr = (Expr *)First.get();
5503 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005504 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005505 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005506
Douglas Gregora16548e2009-08-11 05:31:07 +00005507 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005508 if (Op == OO_Subscript) {
5509 if (!FirstExpr->getType()->isOverloadableType() &&
5510 !SecondExpr->getType()->isOverloadableType())
5511 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005512 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005513 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005514 } else if (Op == OO_Arrow) {
5515 // -> is never a builtin operation.
5516 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005517 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005518 if (!FirstExpr->getType()->isOverloadableType()) {
5519 // The argument is not of overloadable type, so try to create a
5520 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005521 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005522 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005523
Douglas Gregora16548e2009-08-11 05:31:07 +00005524 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5525 }
5526 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005527 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005528 !SecondExpr->getType()->isOverloadableType()) {
5529 // Neither of the arguments is an overloadable type, so try to
5530 // create a built-in binary operation.
5531 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005532 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005533 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5534 if (Result.isInvalid())
5535 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005536
Douglas Gregora16548e2009-08-11 05:31:07 +00005537 First.release();
5538 Second.release();
5539 return move(Result);
5540 }
5541 }
Mike Stump11289f42009-09-09 15:08:12 +00005542
5543 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005544 // used during overload resolution.
5545 Sema::FunctionSet Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005546
John McCalld14a8642009-11-21 08:51:07 +00005547 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5548 assert(ULE->requiresADL());
5549
5550 // FIXME: Do we have to check
5551 // IsAcceptableNonMemberOperatorCandidate for each of these?
5552 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(),
5553 E = ULE->decls_end(); I != E; ++I)
5554 Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I));
5555 } else {
5556 Functions.insert(AnyFunctionDecl::getFromNamedDecl(
5557 cast<DeclRefExpr>(CalleeExpr)->getDecl()));
5558 }
Mike Stump11289f42009-09-09 15:08:12 +00005559
Douglas Gregora16548e2009-08-11 05:31:07 +00005560 // Add any functions found via argument-dependent lookup.
5561 Expr *Args[2] = { FirstExpr, SecondExpr };
5562 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005563 DeclarationName OpName
Douglas Gregora16548e2009-08-11 05:31:07 +00005564 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
Sebastian Redlc057f422009-10-23 19:23:15 +00005565 SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs,
5566 Functions);
Mike Stump11289f42009-09-09 15:08:12 +00005567
Douglas Gregora16548e2009-08-11 05:31:07 +00005568 // Create the overloaded operator invocation for unary operators.
5569 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005570 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005571 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5572 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5573 }
Mike Stump11289f42009-09-09 15:08:12 +00005574
Sebastian Redladba46e2009-10-29 20:17:01 +00005575 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005576 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5577 OpLoc,
5578 move(First),
5579 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005580
Douglas Gregora16548e2009-08-11 05:31:07 +00005581 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005582 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005583 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005584 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005585 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5586 if (Result.isInvalid())
5587 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005588
Douglas Gregora16548e2009-08-11 05:31:07 +00005589 First.release();
5590 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005591 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005592}
Mike Stump11289f42009-09-09 15:08:12 +00005593
Douglas Gregord6ff3322009-08-04 16:50:30 +00005594} // end namespace clang
5595
5596#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H