blob: 8c251e70403e202d654f54fc696cae30e11e8c91 [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
178 /// DeclaratorInfo for it and delegating to the appropriate
179 /// function. This is expensive, but we don't mind, because
180 /// this method is deprecated anyway; all users should be
181 /// switched to storing DeclaratorInfos.
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.
194 DeclaratorInfo *TransformType(DeclaratorInfo *DI);
195
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
304 /// \brief Fakes up a DeclaratorInfo for a type.
305 DeclaratorInfo *InventDeclaratorInfo(QualType T) {
306 return SemaRef.Context.getTrivialDeclaratorInfo(T,
307 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,
Douglas Gregorebe10102009-08-20 07:17:43 +0000786 DeclaratorInfo *Declarator,
787 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,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +0000833 NamedDecl *ND, SourceLocation Loc,
834 bool isAddressOfOperand) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000835 CXXScopeSpec SS;
836 SS.setScopeRep(Qualifier);
837 SS.setRange(QualifierRange);
Douglas Gregora16548e2009-08-11 05:31:07 +0000838 return getSema().BuildDeclarationNameExpr(Loc, ND,
839 /*FIXME:*/false,
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000840 &SS,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +0000841 isAddressOfOperand);
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 McCall4c98fd82009-11-04 07:28:41 +0000897 OwningExprResult RebuildSizeOfAlignOf(DeclaratorInfo *DInfo,
898 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000899 bool isSizeOf, SourceRange R) {
John McCall4c98fd82009-11-04 07:28:41 +0000900 return getSema().CreateSizeOfAlignOfExpr(DInfo, 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,
1893 SemaRef.Context.getTrivialDeclaratorInfo(Arg.getAsType(), Loc));
1894
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 McCall0ad16662009-10-29 08:12:44 +00001925 DeclaratorInfo *DI = Input.getSourceDeclaratorInfo();
1926 if (DI == NULL)
1927 DI = InventDeclaratorInfo(Input.getArgument().getAsType());
1928
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.
2034 DeclaratorInfo *DI = getSema().Context.CreateDeclaratorInfo(T);
John McCallde889892009-10-21 00:44:26 +00002035 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002036
2037 DeclaratorInfo *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>
2046DeclaratorInfo *TreeTransform<Derived>::TransformType(DeclaratorInfo *DI) {
2047 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
2059 return TLB.getDeclaratorInfo(SemaRef.Context, Result);
2060}
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) {
2507 DeclaratorInfo *OldDI = OldParm->getDeclaratorInfo();
2508 assert(OldDI->getType() == T->getArgType(i));
2509
2510 DeclaratorInfo *NewDI = getDerived().TransformType(OldDI);
2511 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
2663 // FIXME: should be an inner type, or at least have a DeclaratorInfo.
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,
3405 ExceptionDecl->getDeclaratorInfo(),
3406 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 }
3487
Mike Stump11289f42009-09-09 15:08:12 +00003488 NamedDecl *ND
Douglas Gregora16548e2009-08-11 05:31:07 +00003489 = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl()));
3490 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() &&
3496 !E->hasExplicitTemplateArgumentList())
Mike Stump11289f42009-09-09 15:08:12 +00003497 return SemaRef.Owned(E->Retain());
3498
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003499 // FIXME: We're losing the explicit template arguments in this transformation.
3500
John McCall0ad16662009-10-29 08:12:44 +00003501 llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003502 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall0ad16662009-10-29 08:12:44 +00003503 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I],
3504 TransArgs[I]))
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003505 return SemaRef.ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003506 }
3507
3508 // FIXME: Pass the qualifier/qualifier range along.
3509 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003510 ND, E->getLocation(),
3511 isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00003512}
Mike Stump11289f42009-09-09 15:08:12 +00003513
Douglas Gregora16548e2009-08-11 05:31:07 +00003514template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003515Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003516TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E,
3517 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003518 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003519}
Mike Stump11289f42009-09-09 15:08:12 +00003520
Douglas Gregora16548e2009-08-11 05:31:07 +00003521template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003522Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003523TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E,
3524 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003525 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003526}
Mike Stump11289f42009-09-09 15:08:12 +00003527
Douglas Gregora16548e2009-08-11 05:31:07 +00003528template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003529Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003530TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E,
3531 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003532 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003533}
Mike Stump11289f42009-09-09 15:08:12 +00003534
Douglas Gregora16548e2009-08-11 05:31:07 +00003535template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003536Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003537TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E,
3538 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003539 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003540}
Mike Stump11289f42009-09-09 15:08:12 +00003541
Douglas Gregora16548e2009-08-11 05:31:07 +00003542template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003543Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003544TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E,
3545 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003546 return SemaRef.Owned(E->Retain());
3547}
3548
3549template<typename Derived>
3550Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003551TreeTransform<Derived>::TransformParenExpr(ParenExpr *E,
3552 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003553 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3554 if (SubExpr.isInvalid())
3555 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003556
Douglas Gregora16548e2009-08-11 05:31:07 +00003557 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003558 return SemaRef.Owned(E->Retain());
3559
3560 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003561 E->getRParen());
3562}
3563
Mike Stump11289f42009-09-09 15:08:12 +00003564template<typename Derived>
3565Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003566TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E,
3567 bool isAddressOfOperand) {
3568 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr(),
3569 E->getOpcode() == UnaryOperator::AddrOf);
Douglas Gregora16548e2009-08-11 05:31:07 +00003570 if (SubExpr.isInvalid())
3571 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003572
Douglas Gregora16548e2009-08-11 05:31:07 +00003573 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003574 return SemaRef.Owned(E->Retain());
3575
Douglas Gregora16548e2009-08-11 05:31:07 +00003576 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3577 E->getOpcode(),
3578 move(SubExpr));
3579}
Mike Stump11289f42009-09-09 15:08:12 +00003580
Douglas Gregora16548e2009-08-11 05:31:07 +00003581template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003582Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003583TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E,
3584 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003585 if (E->isArgumentType()) {
John McCall4c98fd82009-11-04 07:28:41 +00003586 DeclaratorInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003587
John McCall4c98fd82009-11-04 07:28:41 +00003588 DeclaratorInfo *NewT = getDerived().TransformType(OldT);
3589 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003590 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003591
John McCall4c98fd82009-11-04 07:28:41 +00003592 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003593 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003594
John McCall4c98fd82009-11-04 07:28:41 +00003595 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003596 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003597 E->getSourceRange());
3598 }
Mike Stump11289f42009-09-09 15:08:12 +00003599
Douglas Gregora16548e2009-08-11 05:31:07 +00003600 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003601 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003602 // C++0x [expr.sizeof]p1:
3603 // The operand is either an expression, which is an unevaluated operand
3604 // [...]
3605 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003606
Douglas Gregora16548e2009-08-11 05:31:07 +00003607 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3608 if (SubExpr.isInvalid())
3609 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003610
Douglas Gregora16548e2009-08-11 05:31:07 +00003611 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3612 return SemaRef.Owned(E->Retain());
3613 }
Mike Stump11289f42009-09-09 15:08:12 +00003614
Douglas Gregora16548e2009-08-11 05:31:07 +00003615 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3616 E->isSizeOf(),
3617 E->getSourceRange());
3618}
Mike Stump11289f42009-09-09 15:08:12 +00003619
Douglas Gregora16548e2009-08-11 05:31:07 +00003620template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003621Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003622TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E,
3623 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003624 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3625 if (LHS.isInvalid())
3626 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003627
Douglas Gregora16548e2009-08-11 05:31:07 +00003628 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3629 if (RHS.isInvalid())
3630 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003631
3632
Douglas Gregora16548e2009-08-11 05:31:07 +00003633 if (!getDerived().AlwaysRebuild() &&
3634 LHS.get() == E->getLHS() &&
3635 RHS.get() == E->getRHS())
3636 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003637
Douglas Gregora16548e2009-08-11 05:31:07 +00003638 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3639 /*FIXME:*/E->getLHS()->getLocStart(),
3640 move(RHS),
3641 E->getRBracketLoc());
3642}
Mike Stump11289f42009-09-09 15:08:12 +00003643
3644template<typename Derived>
3645Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003646TreeTransform<Derived>::TransformCallExpr(CallExpr *E,
3647 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003648 // Transform the callee.
3649 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3650 if (Callee.isInvalid())
3651 return SemaRef.ExprError();
3652
3653 // Transform arguments.
3654 bool ArgChanged = false;
3655 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3656 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3657 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3658 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3659 if (Arg.isInvalid())
3660 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003661
Douglas Gregora16548e2009-08-11 05:31:07 +00003662 // FIXME: Wrong source location information for the ','.
3663 FakeCommaLocs.push_back(
3664 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003665
3666 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003667 Args.push_back(Arg.takeAs<Expr>());
3668 }
Mike Stump11289f42009-09-09 15:08:12 +00003669
Douglas Gregora16548e2009-08-11 05:31:07 +00003670 if (!getDerived().AlwaysRebuild() &&
3671 Callee.get() == E->getCallee() &&
3672 !ArgChanged)
3673 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003674
Douglas Gregora16548e2009-08-11 05:31:07 +00003675 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003676 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003677 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3678 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3679 move_arg(Args),
3680 FakeCommaLocs.data(),
3681 E->getRParenLoc());
3682}
Mike Stump11289f42009-09-09 15:08:12 +00003683
3684template<typename Derived>
3685Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003686TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E,
3687 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003688 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3689 if (Base.isInvalid())
3690 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003691
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003692 NestedNameSpecifier *Qualifier = 0;
3693 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003694 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003695 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3696 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003697 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003698 return SemaRef.ExprError();
3699 }
Mike Stump11289f42009-09-09 15:08:12 +00003700
Eli Friedman2cfcef62009-12-04 06:40:45 +00003701 ValueDecl *Member
3702 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003703 if (!Member)
3704 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003705
Douglas Gregora16548e2009-08-11 05:31:07 +00003706 if (!getDerived().AlwaysRebuild() &&
3707 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003708 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003709 Member == E->getMemberDecl() &&
3710 !E->hasExplicitTemplateArgumentList())
Mike Stump11289f42009-09-09 15:08:12 +00003711 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003712
John McCall6b51f282009-11-23 01:53:49 +00003713 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003714 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003715 TransArgs.setLAngleLoc(E->getLAngleLoc());
3716 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003717 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003718 TemplateArgumentLoc Loc;
3719 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003720 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003721 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003722 }
3723 }
3724
Douglas Gregora16548e2009-08-11 05:31:07 +00003725 // FIXME: Bogus source location for the operator
3726 SourceLocation FakeOperatorLoc
3727 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3728
3729 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3730 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003731 Qualifier,
3732 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003733 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003734 Member,
John McCall6b51f282009-11-23 01:53:49 +00003735 (E->hasExplicitTemplateArgumentList()
3736 ? &TransArgs : 0),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003737 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00003738}
Mike Stump11289f42009-09-09 15:08:12 +00003739
Douglas Gregora16548e2009-08-11 05:31:07 +00003740template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003741Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003742TreeTransform<Derived>::TransformCastExpr(CastExpr *E,
3743 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003744 assert(false && "Cannot transform abstract class");
3745 return SemaRef.Owned(E->Retain());
3746}
3747
3748template<typename Derived>
3749Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003750TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E,
3751 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003752 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3753 if (LHS.isInvalid())
3754 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003755
Douglas Gregora16548e2009-08-11 05:31:07 +00003756 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3757 if (RHS.isInvalid())
3758 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003759
Douglas Gregora16548e2009-08-11 05:31:07 +00003760 if (!getDerived().AlwaysRebuild() &&
3761 LHS.get() == E->getLHS() &&
3762 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003763 return SemaRef.Owned(E->Retain());
3764
Douglas Gregora16548e2009-08-11 05:31:07 +00003765 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3766 move(LHS), move(RHS));
3767}
3768
Mike Stump11289f42009-09-09 15:08:12 +00003769template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003770Sema::OwningExprResult
3771TreeTransform<Derived>::TransformCompoundAssignOperator(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003772 CompoundAssignOperator *E,
3773 bool isAddressOfOperand) {
3774 return getDerived().TransformBinaryOperator(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00003775}
Mike Stump11289f42009-09-09 15:08:12 +00003776
Douglas Gregora16548e2009-08-11 05:31:07 +00003777template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003778Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003779TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E,
3780 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003781 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3782 if (Cond.isInvalid())
3783 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003784
Douglas Gregora16548e2009-08-11 05:31:07 +00003785 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3786 if (LHS.isInvalid())
3787 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003788
Douglas Gregora16548e2009-08-11 05:31:07 +00003789 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3790 if (RHS.isInvalid())
3791 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003792
Douglas Gregora16548e2009-08-11 05:31:07 +00003793 if (!getDerived().AlwaysRebuild() &&
3794 Cond.get() == E->getCond() &&
3795 LHS.get() == E->getLHS() &&
3796 RHS.get() == E->getRHS())
3797 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003798
3799 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003800 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003801 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003802 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003803 move(RHS));
3804}
Mike Stump11289f42009-09-09 15:08:12 +00003805
3806template<typename Derived>
3807Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003808TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E,
3809 bool isAddressOfOperand) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00003810 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3811
3812 // FIXME: Will we ever have type information here? It seems like we won't,
3813 // so do we even need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00003814 QualType T = getDerived().TransformType(E->getType());
3815 if (T.isNull())
3816 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003817
Douglas Gregora16548e2009-08-11 05:31:07 +00003818 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3819 if (SubExpr.isInvalid())
3820 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003821
Douglas Gregora16548e2009-08-11 05:31:07 +00003822 if (!getDerived().AlwaysRebuild() &&
3823 T == E->getType() &&
3824 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003825 return SemaRef.Owned(E->Retain());
3826
Douglas Gregora16548e2009-08-11 05:31:07 +00003827 return getDerived().RebuildImplicitCastExpr(T, E->getCastKind(),
Mike Stump11289f42009-09-09 15:08:12 +00003828 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00003829 E->isLvalueCast());
3830}
Mike Stump11289f42009-09-09 15:08:12 +00003831
Douglas Gregora16548e2009-08-11 05:31:07 +00003832template<typename Derived>
3833Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003834TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E,
3835 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003836 assert(false && "Cannot transform abstract class");
3837 return SemaRef.Owned(E->Retain());
3838}
3839
3840template<typename Derived>
3841Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003842TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E,
3843 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003844 QualType T;
3845 {
3846 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003847 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003848 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3849 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003850
Douglas Gregora16548e2009-08-11 05:31:07 +00003851 T = getDerived().TransformType(E->getTypeAsWritten());
3852 if (T.isNull())
3853 return SemaRef.ExprError();
3854 }
Mike Stump11289f42009-09-09 15:08:12 +00003855
Douglas Gregora16548e2009-08-11 05:31:07 +00003856 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3857 if (SubExpr.isInvalid())
3858 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003859
Douglas Gregora16548e2009-08-11 05:31:07 +00003860 if (!getDerived().AlwaysRebuild() &&
3861 T == E->getTypeAsWritten() &&
3862 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003863 return SemaRef.Owned(E->Retain());
3864
Douglas Gregora16548e2009-08-11 05:31:07 +00003865 return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T,
3866 E->getRParenLoc(),
3867 move(SubExpr));
3868}
Mike Stump11289f42009-09-09 15:08:12 +00003869
Douglas Gregora16548e2009-08-11 05:31:07 +00003870template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003871Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003872TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E,
3873 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003874 QualType T;
3875 {
3876 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003877 SourceLocation FakeTypeLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003878 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3879 TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003880
Douglas Gregora16548e2009-08-11 05:31:07 +00003881 T = getDerived().TransformType(E->getType());
3882 if (T.isNull())
3883 return SemaRef.ExprError();
3884 }
Mike Stump11289f42009-09-09 15:08:12 +00003885
Douglas Gregora16548e2009-08-11 05:31:07 +00003886 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3887 if (Init.isInvalid())
3888 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003889
Douglas Gregora16548e2009-08-11 05:31:07 +00003890 if (!getDerived().AlwaysRebuild() &&
3891 T == E->getType() &&
3892 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003893 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003894
3895 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T,
3896 /*FIXME:*/E->getInitializer()->getLocEnd(),
3897 move(Init));
3898}
Mike Stump11289f42009-09-09 15:08:12 +00003899
Douglas Gregora16548e2009-08-11 05:31:07 +00003900template<typename Derived>
3901Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003902TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E,
3903 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003904 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3905 if (Base.isInvalid())
3906 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003907
Douglas Gregora16548e2009-08-11 05:31:07 +00003908 if (!getDerived().AlwaysRebuild() &&
3909 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003910 return SemaRef.Owned(E->Retain());
3911
Douglas Gregora16548e2009-08-11 05:31:07 +00003912 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003913 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003914 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3915 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3916 E->getAccessorLoc(),
3917 E->getAccessor());
3918}
Mike Stump11289f42009-09-09 15:08:12 +00003919
Douglas Gregora16548e2009-08-11 05:31:07 +00003920template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003921Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003922TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E,
3923 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003924 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003925
Douglas Gregora16548e2009-08-11 05:31:07 +00003926 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3927 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3928 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3929 if (Init.isInvalid())
3930 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003931
Douglas Gregora16548e2009-08-11 05:31:07 +00003932 InitChanged = InitChanged || Init.get() != E->getInit(I);
3933 Inits.push_back(Init.takeAs<Expr>());
3934 }
Mike Stump11289f42009-09-09 15:08:12 +00003935
Douglas Gregora16548e2009-08-11 05:31:07 +00003936 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003937 return SemaRef.Owned(E->Retain());
3938
Douglas Gregora16548e2009-08-11 05:31:07 +00003939 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00003940 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00003941}
Mike Stump11289f42009-09-09 15:08:12 +00003942
Douglas Gregora16548e2009-08-11 05:31:07 +00003943template<typename Derived>
3944Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003945TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E,
3946 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003947 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00003948
Douglas Gregorebe10102009-08-20 07:17:43 +00003949 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00003950 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3951 if (Init.isInvalid())
3952 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003953
Douglas Gregorebe10102009-08-20 07:17:43 +00003954 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00003955 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3956 bool ExprChanged = false;
3957 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3958 DEnd = E->designators_end();
3959 D != DEnd; ++D) {
3960 if (D->isFieldDesignator()) {
3961 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3962 D->getDotLoc(),
3963 D->getFieldLoc()));
3964 continue;
3965 }
Mike Stump11289f42009-09-09 15:08:12 +00003966
Douglas Gregora16548e2009-08-11 05:31:07 +00003967 if (D->isArrayDesignator()) {
3968 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3969 if (Index.isInvalid())
3970 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003971
3972 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003973 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003974
Douglas Gregora16548e2009-08-11 05:31:07 +00003975 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3976 ArrayExprs.push_back(Index.release());
3977 continue;
3978 }
Mike Stump11289f42009-09-09 15:08:12 +00003979
Douglas Gregora16548e2009-08-11 05:31:07 +00003980 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00003981 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00003982 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3983 if (Start.isInvalid())
3984 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003985
Douglas Gregora16548e2009-08-11 05:31:07 +00003986 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3987 if (End.isInvalid())
3988 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003989
3990 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003991 End.get(),
3992 D->getLBracketLoc(),
3993 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003994
Douglas Gregora16548e2009-08-11 05:31:07 +00003995 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
3996 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00003997
Douglas Gregora16548e2009-08-11 05:31:07 +00003998 ArrayExprs.push_back(Start.release());
3999 ArrayExprs.push_back(End.release());
4000 }
Mike Stump11289f42009-09-09 15:08:12 +00004001
Douglas Gregora16548e2009-08-11 05:31:07 +00004002 if (!getDerived().AlwaysRebuild() &&
4003 Init.get() == E->getInit() &&
4004 !ExprChanged)
4005 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004006
Douglas Gregora16548e2009-08-11 05:31:07 +00004007 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4008 E->getEqualOrColonLoc(),
4009 E->usesGNUSyntax(), move(Init));
4010}
Mike Stump11289f42009-09-09 15:08:12 +00004011
Douglas Gregora16548e2009-08-11 05:31:07 +00004012template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004013Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004014TreeTransform<Derived>::TransformImplicitValueInitExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004015 ImplicitValueInitExpr *E,
4016 bool isAddressOfOperand) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004017 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4018
4019 // FIXME: Will we ever have proper type location here? Will we actually
4020 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004021 QualType T = getDerived().TransformType(E->getType());
4022 if (T.isNull())
4023 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004024
Douglas Gregora16548e2009-08-11 05:31:07 +00004025 if (!getDerived().AlwaysRebuild() &&
4026 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004027 return SemaRef.Owned(E->Retain());
4028
Douglas Gregora16548e2009-08-11 05:31:07 +00004029 return getDerived().RebuildImplicitValueInitExpr(T);
4030}
Mike Stump11289f42009-09-09 15:08:12 +00004031
Douglas Gregora16548e2009-08-11 05:31:07 +00004032template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004033Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004034TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E,
4035 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004036 // FIXME: Do we want the type as written?
4037 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004038
Douglas Gregora16548e2009-08-11 05:31:07 +00004039 {
4040 // FIXME: Source location isn't quite accurate.
4041 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4042 T = getDerived().TransformType(E->getType());
4043 if (T.isNull())
4044 return SemaRef.ExprError();
4045 }
Mike Stump11289f42009-09-09 15:08:12 +00004046
Douglas Gregora16548e2009-08-11 05:31:07 +00004047 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4048 if (SubExpr.isInvalid())
4049 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004050
Douglas Gregora16548e2009-08-11 05:31:07 +00004051 if (!getDerived().AlwaysRebuild() &&
4052 T == E->getType() &&
4053 SubExpr.get() == E->getSubExpr())
4054 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004055
Douglas Gregora16548e2009-08-11 05:31:07 +00004056 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4057 T, E->getRParenLoc());
4058}
4059
4060template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004061Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004062TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E,
4063 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004064 bool ArgumentChanged = false;
4065 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4066 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4067 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4068 if (Init.isInvalid())
4069 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004070
Douglas Gregora16548e2009-08-11 05:31:07 +00004071 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4072 Inits.push_back(Init.takeAs<Expr>());
4073 }
Mike Stump11289f42009-09-09 15:08:12 +00004074
Douglas Gregora16548e2009-08-11 05:31:07 +00004075 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4076 move_arg(Inits),
4077 E->getRParenLoc());
4078}
Mike Stump11289f42009-09-09 15:08:12 +00004079
Douglas Gregora16548e2009-08-11 05:31:07 +00004080/// \brief Transform an address-of-label expression.
4081///
4082/// By default, the transformation of an address-of-label expression always
4083/// rebuilds the expression, so that the label identifier can be resolved to
4084/// the corresponding label statement by semantic analysis.
4085template<typename Derived>
4086Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004087TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E,
4088 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004089 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4090 E->getLabel());
4091}
Mike Stump11289f42009-09-09 15:08:12 +00004092
4093template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004094Sema::OwningExprResult
4095TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E,
4096 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004097 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004098 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4099 if (SubStmt.isInvalid())
4100 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004101
Douglas Gregora16548e2009-08-11 05:31:07 +00004102 if (!getDerived().AlwaysRebuild() &&
4103 SubStmt.get() == E->getSubStmt())
4104 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004105
4106 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004107 move(SubStmt),
4108 E->getRParenLoc());
4109}
Mike Stump11289f42009-09-09 15:08:12 +00004110
Douglas Gregora16548e2009-08-11 05:31:07 +00004111template<typename Derived>
4112Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004113TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E,
4114 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004115 QualType T1, T2;
4116 {
4117 // FIXME: Source location isn't quite accurate.
4118 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004119
Douglas Gregora16548e2009-08-11 05:31:07 +00004120 T1 = getDerived().TransformType(E->getArgType1());
4121 if (T1.isNull())
4122 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004123
Douglas Gregora16548e2009-08-11 05:31:07 +00004124 T2 = getDerived().TransformType(E->getArgType2());
4125 if (T2.isNull())
4126 return SemaRef.ExprError();
4127 }
4128
4129 if (!getDerived().AlwaysRebuild() &&
4130 T1 == E->getArgType1() &&
4131 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004132 return SemaRef.Owned(E->Retain());
4133
Douglas Gregora16548e2009-08-11 05:31:07 +00004134 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4135 T1, T2, E->getRParenLoc());
4136}
Mike Stump11289f42009-09-09 15:08:12 +00004137
Douglas Gregora16548e2009-08-11 05:31:07 +00004138template<typename Derived>
4139Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004140TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E,
4141 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004142 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4143 if (Cond.isInvalid())
4144 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004145
Douglas Gregora16548e2009-08-11 05:31:07 +00004146 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4147 if (LHS.isInvalid())
4148 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004149
Douglas Gregora16548e2009-08-11 05:31:07 +00004150 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4151 if (RHS.isInvalid())
4152 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004153
Douglas Gregora16548e2009-08-11 05:31:07 +00004154 if (!getDerived().AlwaysRebuild() &&
4155 Cond.get() == E->getCond() &&
4156 LHS.get() == E->getLHS() &&
4157 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004158 return SemaRef.Owned(E->Retain());
4159
Douglas Gregora16548e2009-08-11 05:31:07 +00004160 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4161 move(Cond), move(LHS), move(RHS),
4162 E->getRParenLoc());
4163}
Mike Stump11289f42009-09-09 15:08:12 +00004164
Douglas Gregora16548e2009-08-11 05:31:07 +00004165template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004166Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004167TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E,
4168 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004169 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004170}
4171
4172template<typename Derived>
4173Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004174TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E,
4175 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004176 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4177 if (Callee.isInvalid())
4178 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004179
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004180 OwningExprResult First
4181 = getDerived().TransformExpr(E->getArg(0),
4182 E->getNumArgs() == 1 && E->getOperator() == OO_Amp);
Douglas Gregora16548e2009-08-11 05:31:07 +00004183 if (First.isInvalid())
4184 return SemaRef.ExprError();
4185
4186 OwningExprResult Second(SemaRef);
4187 if (E->getNumArgs() == 2) {
4188 Second = getDerived().TransformExpr(E->getArg(1));
4189 if (Second.isInvalid())
4190 return SemaRef.ExprError();
4191 }
Mike Stump11289f42009-09-09 15:08:12 +00004192
Douglas Gregora16548e2009-08-11 05:31:07 +00004193 if (!getDerived().AlwaysRebuild() &&
4194 Callee.get() == E->getCallee() &&
4195 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004196 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4197 return SemaRef.Owned(E->Retain());
4198
Douglas Gregora16548e2009-08-11 05:31:07 +00004199 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4200 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004201 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004202 move(First),
4203 move(Second));
4204}
Mike Stump11289f42009-09-09 15:08:12 +00004205
Douglas Gregora16548e2009-08-11 05:31:07 +00004206template<typename Derived>
4207Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004208TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E,
4209 bool isAddressOfOperand) {
4210 return getDerived().TransformCallExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004211}
Mike Stump11289f42009-09-09 15:08:12 +00004212
Douglas Gregora16548e2009-08-11 05:31:07 +00004213template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004214Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004215TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E,
4216 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004217 QualType ExplicitTy;
4218 {
4219 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004220 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004221 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4222 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004223
Douglas Gregora16548e2009-08-11 05:31:07 +00004224 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4225 if (ExplicitTy.isNull())
4226 return SemaRef.ExprError();
4227 }
Mike Stump11289f42009-09-09 15:08:12 +00004228
Douglas Gregora16548e2009-08-11 05:31:07 +00004229 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4230 if (SubExpr.isInvalid())
4231 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004232
Douglas Gregora16548e2009-08-11 05:31:07 +00004233 if (!getDerived().AlwaysRebuild() &&
4234 ExplicitTy == E->getTypeAsWritten() &&
4235 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004236 return SemaRef.Owned(E->Retain());
4237
Douglas Gregora16548e2009-08-11 05:31:07 +00004238 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004239 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004240 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4241 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4242 SourceLocation FakeRParenLoc
4243 = SemaRef.PP.getLocForEndOfToken(
4244 E->getSubExpr()->getSourceRange().getEnd());
4245 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004246 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004247 FakeLAngleLoc,
4248 ExplicitTy,
4249 FakeRAngleLoc,
4250 FakeRAngleLoc,
4251 move(SubExpr),
4252 FakeRParenLoc);
4253}
Mike Stump11289f42009-09-09 15:08:12 +00004254
Douglas Gregora16548e2009-08-11 05:31:07 +00004255template<typename Derived>
4256Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004257TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E,
4258 bool isAddressOfOperand) {
4259 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004260}
Mike Stump11289f42009-09-09 15:08:12 +00004261
4262template<typename Derived>
4263Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004264TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E,
4265 bool isAddressOfOperand) {
4266 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Mike Stump11289f42009-09-09 15:08:12 +00004267}
4268
Douglas Gregora16548e2009-08-11 05:31:07 +00004269template<typename Derived>
4270Sema::OwningExprResult
4271TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004272 CXXReinterpretCastExpr *E,
4273 bool isAddressOfOperand) {
4274 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004275}
Mike Stump11289f42009-09-09 15:08:12 +00004276
Douglas Gregora16548e2009-08-11 05:31:07 +00004277template<typename Derived>
4278Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004279TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E,
4280 bool isAddressOfOperand) {
4281 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004282}
Mike Stump11289f42009-09-09 15:08:12 +00004283
Douglas Gregora16548e2009-08-11 05:31:07 +00004284template<typename Derived>
4285Sema::OwningExprResult
4286TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004287 CXXFunctionalCastExpr *E,
4288 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004289 QualType ExplicitTy;
4290 {
4291 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004292
Douglas Gregora16548e2009-08-11 05:31:07 +00004293 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4294 if (ExplicitTy.isNull())
4295 return SemaRef.ExprError();
4296 }
Mike Stump11289f42009-09-09 15:08:12 +00004297
Douglas Gregora16548e2009-08-11 05:31:07 +00004298 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4299 if (SubExpr.isInvalid())
4300 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004301
Douglas Gregora16548e2009-08-11 05:31:07 +00004302 if (!getDerived().AlwaysRebuild() &&
4303 ExplicitTy == E->getTypeAsWritten() &&
4304 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004305 return SemaRef.Owned(E->Retain());
4306
Douglas Gregora16548e2009-08-11 05:31:07 +00004307 // FIXME: The end of the type's source range is wrong
4308 return getDerived().RebuildCXXFunctionalCastExpr(
4309 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
4310 ExplicitTy,
4311 /*FIXME:*/E->getSubExpr()->getLocStart(),
4312 move(SubExpr),
4313 E->getRParenLoc());
4314}
Mike Stump11289f42009-09-09 15:08:12 +00004315
Douglas Gregora16548e2009-08-11 05:31:07 +00004316template<typename Derived>
4317Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004318TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E,
4319 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004320 if (E->isTypeOperand()) {
4321 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004322
Douglas Gregora16548e2009-08-11 05:31:07 +00004323 QualType T = getDerived().TransformType(E->getTypeOperand());
4324 if (T.isNull())
4325 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004326
Douglas Gregora16548e2009-08-11 05:31:07 +00004327 if (!getDerived().AlwaysRebuild() &&
4328 T == E->getTypeOperand())
4329 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004330
Douglas Gregora16548e2009-08-11 05:31:07 +00004331 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4332 /*FIXME:*/E->getLocStart(),
4333 T,
4334 E->getLocEnd());
4335 }
Mike Stump11289f42009-09-09 15:08:12 +00004336
Douglas Gregora16548e2009-08-11 05:31:07 +00004337 // We don't know whether the expression is potentially evaluated until
4338 // after we perform semantic analysis, so the expression is potentially
4339 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004340 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004341 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004342
Douglas Gregora16548e2009-08-11 05:31:07 +00004343 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4344 if (SubExpr.isInvalid())
4345 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004346
Douglas Gregora16548e2009-08-11 05:31:07 +00004347 if (!getDerived().AlwaysRebuild() &&
4348 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004349 return SemaRef.Owned(E->Retain());
4350
Douglas Gregora16548e2009-08-11 05:31:07 +00004351 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4352 /*FIXME:*/E->getLocStart(),
4353 move(SubExpr),
4354 E->getLocEnd());
4355}
4356
4357template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004358Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004359TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E,
4360 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004361 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004362}
Mike Stump11289f42009-09-09 15:08:12 +00004363
Douglas Gregora16548e2009-08-11 05:31:07 +00004364template<typename Derived>
4365Sema::OwningExprResult
4366TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004367 CXXNullPtrLiteralExpr *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
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004374TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E,
4375 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004376 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004377
Douglas Gregora16548e2009-08-11 05:31:07 +00004378 QualType T = getDerived().TransformType(E->getType());
4379 if (T.isNull())
4380 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004381
Douglas Gregora16548e2009-08-11 05:31:07 +00004382 if (!getDerived().AlwaysRebuild() &&
4383 T == E->getType())
4384 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004385
Douglas Gregora16548e2009-08-11 05:31:07 +00004386 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T);
4387}
Mike Stump11289f42009-09-09 15:08:12 +00004388
Douglas Gregora16548e2009-08-11 05:31:07 +00004389template<typename Derived>
4390Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004391TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E,
4392 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004393 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4394 if (SubExpr.isInvalid())
4395 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004396
Douglas Gregora16548e2009-08-11 05:31:07 +00004397 if (!getDerived().AlwaysRebuild() &&
4398 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004399 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004400
4401 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4402}
Mike Stump11289f42009-09-09 15:08:12 +00004403
Douglas Gregora16548e2009-08-11 05:31:07 +00004404template<typename Derived>
4405Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004406TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E,
4407 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004408 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004409 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4410 if (!Param)
4411 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004412
Douglas Gregora16548e2009-08-11 05:31:07 +00004413 if (getDerived().AlwaysRebuild() &&
4414 Param == E->getParam())
4415 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004416
Douglas Gregora16548e2009-08-11 05:31:07 +00004417 return getDerived().RebuildCXXDefaultArgExpr(Param);
4418}
Mike Stump11289f42009-09-09 15:08:12 +00004419
Douglas Gregora16548e2009-08-11 05:31:07 +00004420template<typename Derived>
4421Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004422TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E,
4423 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004424 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4425
4426 QualType T = getDerived().TransformType(E->getType());
4427 if (T.isNull())
4428 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004429
Douglas Gregora16548e2009-08-11 05:31:07 +00004430 if (!getDerived().AlwaysRebuild() &&
4431 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004432 return SemaRef.Owned(E->Retain());
4433
4434 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004435 /*FIXME:*/E->getTypeBeginLoc(),
4436 T,
4437 E->getRParenLoc());
4438}
Mike Stump11289f42009-09-09 15:08:12 +00004439
Douglas Gregora16548e2009-08-11 05:31:07 +00004440template<typename Derived>
4441Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004442TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E,
4443 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004444 // Transform the type that we're allocating
4445 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4446 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4447 if (AllocType.isNull())
4448 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004449
Douglas Gregora16548e2009-08-11 05:31:07 +00004450 // Transform the size of the array we're allocating (if any).
4451 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4452 if (ArraySize.isInvalid())
4453 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004454
Douglas Gregora16548e2009-08-11 05:31:07 +00004455 // Transform the placement arguments (if any).
4456 bool ArgumentChanged = false;
4457 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4458 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4459 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4460 if (Arg.isInvalid())
4461 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004462
Douglas Gregora16548e2009-08-11 05:31:07 +00004463 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4464 PlacementArgs.push_back(Arg.take());
4465 }
Mike Stump11289f42009-09-09 15:08:12 +00004466
Douglas Gregorebe10102009-08-20 07:17:43 +00004467 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004468 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4469 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4470 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4471 if (Arg.isInvalid())
4472 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004473
Douglas Gregora16548e2009-08-11 05:31:07 +00004474 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4475 ConstructorArgs.push_back(Arg.take());
4476 }
Mike Stump11289f42009-09-09 15:08:12 +00004477
Douglas Gregora16548e2009-08-11 05:31:07 +00004478 if (!getDerived().AlwaysRebuild() &&
4479 AllocType == E->getAllocatedType() &&
4480 ArraySize.get() == E->getArraySize() &&
4481 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004482 return SemaRef.Owned(E->Retain());
4483
Douglas Gregora16548e2009-08-11 05:31:07 +00004484 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4485 E->isGlobalNew(),
4486 /*FIXME:*/E->getLocStart(),
4487 move_arg(PlacementArgs),
4488 /*FIXME:*/E->getLocStart(),
4489 E->isParenTypeId(),
4490 AllocType,
4491 /*FIXME:*/E->getLocStart(),
4492 /*FIXME:*/SourceRange(),
4493 move(ArraySize),
4494 /*FIXME:*/E->getLocStart(),
4495 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004496 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004497}
Mike Stump11289f42009-09-09 15:08:12 +00004498
Douglas Gregora16548e2009-08-11 05:31:07 +00004499template<typename Derived>
4500Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004501TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E,
4502 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004503 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4504 if (Operand.isInvalid())
4505 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004506
Douglas Gregora16548e2009-08-11 05:31:07 +00004507 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004508 Operand.get() == E->getArgument())
4509 return SemaRef.Owned(E->Retain());
4510
Douglas Gregora16548e2009-08-11 05:31:07 +00004511 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4512 E->isGlobalDelete(),
4513 E->isArrayForm(),
4514 move(Operand));
4515}
Mike Stump11289f42009-09-09 15:08:12 +00004516
Douglas Gregora16548e2009-08-11 05:31:07 +00004517template<typename Derived>
4518Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004519TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004520 CXXPseudoDestructorExpr *E,
4521 bool isAddressOfOperand) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004522 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4523 if (Base.isInvalid())
4524 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004525
Douglas Gregorad8a3362009-09-04 17:36:40 +00004526 NestedNameSpecifier *Qualifier
4527 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4528 E->getQualifierRange());
4529 if (E->getQualifier() && !Qualifier)
4530 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004531
Douglas Gregorad8a3362009-09-04 17:36:40 +00004532 QualType DestroyedType;
4533 {
4534 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4535 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4536 if (DestroyedType.isNull())
4537 return SemaRef.ExprError();
4538 }
Mike Stump11289f42009-09-09 15:08:12 +00004539
Douglas Gregorad8a3362009-09-04 17:36:40 +00004540 if (!getDerived().AlwaysRebuild() &&
4541 Base.get() == E->getBase() &&
4542 Qualifier == E->getQualifier() &&
4543 DestroyedType == E->getDestroyedType())
4544 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004545
Douglas Gregorad8a3362009-09-04 17:36:40 +00004546 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4547 E->getOperatorLoc(),
4548 E->isArrow(),
4549 E->getDestroyedTypeLoc(),
4550 DestroyedType,
4551 Qualifier,
4552 E->getQualifierRange());
4553}
Mike Stump11289f42009-09-09 15:08:12 +00004554
Douglas Gregorad8a3362009-09-04 17:36:40 +00004555template<typename Derived>
4556Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004557TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCalle66edc12009-11-24 19:00:30 +00004558 UnresolvedLookupExpr *Old,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004559 bool isAddressOfOperand) {
John McCalle66edc12009-11-24 19:00:30 +00004560 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4561
4562 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4563 Sema::LookupOrdinaryName);
4564
4565 // Transform all the decls.
4566 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4567 E = Old->decls_end(); I != E; ++I) {
4568 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
4569 if (!InstD)
4570 return SemaRef.ExprError();
4571
4572 // Expand using declarations.
4573 if (isa<UsingDecl>(InstD)) {
4574 UsingDecl *UD = cast<UsingDecl>(InstD);
4575 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4576 E = UD->shadow_end(); I != E; ++I)
4577 R.addDecl(*I);
4578 continue;
4579 }
4580
4581 R.addDecl(InstD);
4582 }
4583
4584 // Resolve a kind, but don't do any further analysis. If it's
4585 // ambiguous, the callee needs to deal with it.
4586 R.resolveKind();
4587
4588 // Rebuild the nested-name qualifier, if present.
4589 CXXScopeSpec SS;
4590 NestedNameSpecifier *Qualifier = 0;
4591 if (Old->getQualifier()) {
4592 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4593 Old->getQualifierRange());
4594 if (!Qualifier)
4595 return SemaRef.ExprError();
4596
4597 SS.setScopeRep(Qualifier);
4598 SS.setRange(Old->getQualifierRange());
4599 }
4600
4601 // If we have no template arguments, it's a normal declaration name.
4602 if (!Old->hasExplicitTemplateArgs())
4603 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4604
4605 // If we have template arguments, rebuild them, then rebuild the
4606 // templateid expression.
4607 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4608 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4609 TemplateArgumentLoc Loc;
4610 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4611 return SemaRef.ExprError();
4612 TransArgs.addArgument(Loc);
4613 }
4614
4615 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4616 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004617}
Mike Stump11289f42009-09-09 15:08:12 +00004618
Douglas Gregora16548e2009-08-11 05:31:07 +00004619template<typename Derived>
4620Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004621TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E,
4622 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004623 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004624
Douglas Gregora16548e2009-08-11 05:31:07 +00004625 QualType T = getDerived().TransformType(E->getQueriedType());
4626 if (T.isNull())
4627 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004628
Douglas Gregora16548e2009-08-11 05:31:07 +00004629 if (!getDerived().AlwaysRebuild() &&
4630 T == E->getQueriedType())
4631 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004632
Douglas Gregora16548e2009-08-11 05:31:07 +00004633 // FIXME: Bad location information
4634 SourceLocation FakeLParenLoc
4635 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004636
4637 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004638 E->getLocStart(),
4639 /*FIXME:*/FakeLParenLoc,
4640 T,
4641 E->getLocEnd());
4642}
Mike Stump11289f42009-09-09 15:08:12 +00004643
Douglas Gregora16548e2009-08-11 05:31:07 +00004644template<typename Derived>
4645Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004646TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
4647 DependentScopeDeclRefExpr *E,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004648 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004649 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004650 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4651 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004652 if (!NNS)
4653 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004654
4655 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004656 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4657 if (!Name)
4658 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004659
John McCalle66edc12009-11-24 19:00:30 +00004660 if (!E->hasExplicitTemplateArgs()) {
4661 if (!getDerived().AlwaysRebuild() &&
4662 NNS == E->getQualifier() &&
4663 Name == E->getDeclName())
4664 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004665
John McCalle66edc12009-11-24 19:00:30 +00004666 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4667 E->getQualifierRange(),
4668 Name, E->getLocation(),
4669 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004670 }
John McCall6b51f282009-11-23 01:53:49 +00004671
4672 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004673 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004674 TemplateArgumentLoc Loc;
4675 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004676 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004677 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004678 }
4679
John McCalle66edc12009-11-24 19:00:30 +00004680 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4681 E->getQualifierRange(),
4682 Name, E->getLocation(),
4683 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004684}
4685
4686template<typename Derived>
4687Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004688TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E,
4689 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004690 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4691
4692 QualType T = getDerived().TransformType(E->getType());
4693 if (T.isNull())
4694 return SemaRef.ExprError();
4695
4696 CXXConstructorDecl *Constructor
4697 = cast_or_null<CXXConstructorDecl>(
4698 getDerived().TransformDecl(E->getConstructor()));
4699 if (!Constructor)
4700 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004701
Douglas Gregora16548e2009-08-11 05:31:07 +00004702 bool ArgumentChanged = false;
4703 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004704 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004705 ArgEnd = E->arg_end();
4706 Arg != ArgEnd; ++Arg) {
4707 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4708 if (TransArg.isInvalid())
4709 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004710
Douglas Gregora16548e2009-08-11 05:31:07 +00004711 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4712 Args.push_back(TransArg.takeAs<Expr>());
4713 }
4714
4715 if (!getDerived().AlwaysRebuild() &&
4716 T == E->getType() &&
4717 Constructor == E->getConstructor() &&
4718 !ArgumentChanged)
4719 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004720
Douglas Gregora16548e2009-08-11 05:31:07 +00004721 return getDerived().RebuildCXXConstructExpr(T, Constructor, E->isElidable(),
4722 move_arg(Args));
4723}
Mike Stump11289f42009-09-09 15:08:12 +00004724
Douglas Gregora16548e2009-08-11 05:31:07 +00004725/// \brief Transform a C++ temporary-binding expression.
4726///
Mike Stump11289f42009-09-09 15:08:12 +00004727/// The transformation of a temporary-binding expression always attempts to
4728/// bind a new temporary variable to its subexpression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004729/// subexpression itself did not change, because the temporary variable itself
4730/// must be unique.
4731template<typename Derived>
4732Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004733TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E,
4734 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004735 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4736 if (SubExpr.isInvalid())
4737 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004738
Douglas Gregora16548e2009-08-11 05:31:07 +00004739 return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>());
4740}
Mike Stump11289f42009-09-09 15:08:12 +00004741
4742/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004743/// be destroyed after the expression is evaluated.
4744///
Mike Stump11289f42009-09-09 15:08:12 +00004745/// The transformation of a full expression always attempts to build a new
4746/// CXXExprWithTemporaries expression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004747/// subexpression itself did not change, because it will need to capture the
4748/// the new temporary variables introduced in the subexpression.
4749template<typename Derived>
4750Sema::OwningExprResult
4751TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004752 CXXExprWithTemporaries *E,
4753 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004754 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4755 if (SubExpr.isInvalid())
4756 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004757
Douglas Gregora16548e2009-08-11 05:31:07 +00004758 return SemaRef.Owned(
4759 SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(),
4760 E->shouldDestroyTemporaries()));
4761}
Mike Stump11289f42009-09-09 15:08:12 +00004762
Douglas Gregora16548e2009-08-11 05:31:07 +00004763template<typename Derived>
4764Sema::OwningExprResult
4765TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004766 CXXTemporaryObjectExpr *E,
4767 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004768 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4769 QualType T = getDerived().TransformType(E->getType());
4770 if (T.isNull())
4771 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004772
Douglas Gregora16548e2009-08-11 05:31:07 +00004773 CXXConstructorDecl *Constructor
4774 = cast_or_null<CXXConstructorDecl>(
4775 getDerived().TransformDecl(E->getConstructor()));
4776 if (!Constructor)
4777 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004778
Douglas Gregora16548e2009-08-11 05:31:07 +00004779 bool ArgumentChanged = false;
4780 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4781 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004782 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004783 ArgEnd = E->arg_end();
4784 Arg != ArgEnd; ++Arg) {
4785 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4786 if (TransArg.isInvalid())
4787 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004788
Douglas Gregora16548e2009-08-11 05:31:07 +00004789 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4790 Args.push_back((Expr *)TransArg.release());
4791 }
Mike Stump11289f42009-09-09 15:08:12 +00004792
Douglas Gregora16548e2009-08-11 05:31:07 +00004793 if (!getDerived().AlwaysRebuild() &&
4794 T == E->getType() &&
4795 Constructor == E->getConstructor() &&
4796 !ArgumentChanged)
4797 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004798
Douglas Gregora16548e2009-08-11 05:31:07 +00004799 // FIXME: Bogus location information
4800 SourceLocation CommaLoc;
4801 if (Args.size() > 1) {
4802 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004803 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004804 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4805 }
4806 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4807 T,
4808 /*FIXME:*/E->getTypeBeginLoc(),
4809 move_arg(Args),
4810 &CommaLoc,
4811 E->getLocEnd());
4812}
Mike Stump11289f42009-09-09 15:08:12 +00004813
Douglas Gregora16548e2009-08-11 05:31:07 +00004814template<typename Derived>
4815Sema::OwningExprResult
4816TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004817 CXXUnresolvedConstructExpr *E,
4818 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004819 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4820 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4821 if (T.isNull())
4822 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004823
Douglas Gregora16548e2009-08-11 05:31:07 +00004824 bool ArgumentChanged = false;
4825 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4826 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4827 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4828 ArgEnd = E->arg_end();
4829 Arg != ArgEnd; ++Arg) {
4830 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4831 if (TransArg.isInvalid())
4832 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004833
Douglas Gregora16548e2009-08-11 05:31:07 +00004834 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4835 FakeCommaLocs.push_back(
4836 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4837 Args.push_back(TransArg.takeAs<Expr>());
4838 }
Mike Stump11289f42009-09-09 15:08:12 +00004839
Douglas Gregora16548e2009-08-11 05:31:07 +00004840 if (!getDerived().AlwaysRebuild() &&
4841 T == E->getTypeAsWritten() &&
4842 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004843 return SemaRef.Owned(E->Retain());
4844
Douglas Gregora16548e2009-08-11 05:31:07 +00004845 // FIXME: we're faking the locations of the commas
4846 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4847 T,
4848 E->getLParenLoc(),
4849 move_arg(Args),
4850 FakeCommaLocs.data(),
4851 E->getRParenLoc());
4852}
Mike Stump11289f42009-09-09 15:08:12 +00004853
Douglas Gregora16548e2009-08-11 05:31:07 +00004854template<typename Derived>
4855Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004856TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
4857 CXXDependentScopeMemberExpr *E,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004858 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004859 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004860 OwningExprResult Base(SemaRef, (Expr*) 0);
4861 Expr *OldBase;
4862 QualType BaseType;
4863 QualType ObjectType;
4864 if (!E->isImplicitAccess()) {
4865 OldBase = E->getBase();
4866 Base = getDerived().TransformExpr(OldBase);
4867 if (Base.isInvalid())
4868 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004869
John McCall2d74de92009-12-01 22:10:20 +00004870 // Start the member reference and compute the object's type.
4871 Sema::TypeTy *ObjectTy = 0;
4872 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4873 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004874 E->isArrow()? tok::arrow : tok::period,
John McCall2d74de92009-12-01 22:10:20 +00004875 ObjectTy);
4876 if (Base.isInvalid())
4877 return SemaRef.ExprError();
4878
4879 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
4880 BaseType = ((Expr*) Base.get())->getType();
4881 } else {
4882 OldBase = 0;
4883 BaseType = getDerived().TransformType(E->getBaseType());
4884 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
4885 }
Mike Stump11289f42009-09-09 15:08:12 +00004886
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004887 // Transform the first part of the nested-name-specifier that qualifies
4888 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004889 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004890 = getDerived().TransformFirstQualifierInScope(
4891 E->getFirstQualifierFoundInScope(),
4892 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00004893
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004894 NestedNameSpecifier *Qualifier = 0;
4895 if (E->getQualifier()) {
4896 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4897 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00004898 ObjectType,
4899 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004900 if (!Qualifier)
4901 return SemaRef.ExprError();
4902 }
Mike Stump11289f42009-09-09 15:08:12 +00004903
4904 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00004905 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00004906 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00004907 if (!Name)
4908 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004909
John McCall2d74de92009-12-01 22:10:20 +00004910 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00004911 // This is a reference to a member without an explicitly-specified
4912 // template argument list. Optimize for this common case.
4913 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00004914 Base.get() == OldBase &&
4915 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00004916 Qualifier == E->getQualifier() &&
4917 Name == E->getMember() &&
4918 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00004919 return SemaRef.Owned(E->Retain());
4920
John McCall8cd78132009-11-19 22:55:06 +00004921 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00004922 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00004923 E->isArrow(),
4924 E->getOperatorLoc(),
4925 Qualifier,
4926 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00004927 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00004928 Name,
4929 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00004930 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00004931 }
4932
John McCall6b51f282009-11-23 01:53:49 +00004933 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00004934 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004935 TemplateArgumentLoc Loc;
4936 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00004937 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004938 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00004939 }
Mike Stump11289f42009-09-09 15:08:12 +00004940
John McCall8cd78132009-11-19 22:55:06 +00004941 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00004942 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00004943 E->isArrow(),
4944 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004945 Qualifier,
4946 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004947 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00004948 Name,
4949 E->getMemberLoc(),
4950 &TransArgs);
4951}
4952
4953template<typename Derived>
4954Sema::OwningExprResult
4955TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old,
4956 bool isAddressOfOperand) {
4957 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004958 OwningExprResult Base(SemaRef, (Expr*) 0);
4959 QualType BaseType;
4960 if (!Old->isImplicitAccess()) {
4961 Base = getDerived().TransformExpr(Old->getBase());
4962 if (Base.isInvalid())
4963 return SemaRef.ExprError();
4964 BaseType = ((Expr*) Base.get())->getType();
4965 } else {
4966 BaseType = getDerived().TransformType(Old->getBaseType());
4967 }
John McCall10eae182009-11-30 22:42:35 +00004968
4969 NestedNameSpecifier *Qualifier = 0;
4970 if (Old->getQualifier()) {
4971 Qualifier
4972 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4973 Old->getQualifierRange());
4974 if (Qualifier == 0)
4975 return SemaRef.ExprError();
4976 }
4977
4978 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
4979 Sema::LookupOrdinaryName);
4980
4981 // Transform all the decls.
4982 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
4983 E = Old->decls_end(); I != E; ++I) {
4984 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
4985 if (!InstD)
4986 return SemaRef.ExprError();
4987
4988 // Expand using declarations.
4989 if (isa<UsingDecl>(InstD)) {
4990 UsingDecl *UD = cast<UsingDecl>(InstD);
4991 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4992 E = UD->shadow_end(); I != E; ++I)
4993 R.addDecl(*I);
4994 continue;
4995 }
4996
4997 R.addDecl(InstD);
4998 }
4999
5000 R.resolveKind();
5001
5002 TemplateArgumentListInfo TransArgs;
5003 if (Old->hasExplicitTemplateArgs()) {
5004 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5005 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5006 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5007 TemplateArgumentLoc Loc;
5008 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5009 Loc))
5010 return SemaRef.ExprError();
5011 TransArgs.addArgument(Loc);
5012 }
5013 }
5014
5015 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005016 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005017 Old->getOperatorLoc(),
5018 Old->isArrow(),
5019 Qualifier,
5020 Old->getQualifierRange(),
5021 R,
5022 (Old->hasExplicitTemplateArgs()
5023 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005024}
5025
5026template<typename Derived>
5027Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005028TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E,
5029 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00005030 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005031}
5032
Mike Stump11289f42009-09-09 15:08:12 +00005033template<typename Derived>
5034Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005035TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E,
5036 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005037 // FIXME: poor source location
5038 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5039 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5040 if (EncodedType.isNull())
5041 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005042
Douglas Gregora16548e2009-08-11 05:31:07 +00005043 if (!getDerived().AlwaysRebuild() &&
5044 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00005045 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005046
5047 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5048 EncodedType,
5049 E->getRParenLoc());
5050}
Mike Stump11289f42009-09-09 15:08:12 +00005051
Douglas Gregora16548e2009-08-11 05:31:07 +00005052template<typename Derived>
5053Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005054TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E,
5055 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005056 // FIXME: Implement this!
5057 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005058 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005059}
5060
Mike Stump11289f42009-09-09 15:08:12 +00005061template<typename Derived>
5062Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005063TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E,
5064 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00005065 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005066}
5067
Mike Stump11289f42009-09-09 15:08:12 +00005068template<typename Derived>
5069Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005070TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E,
5071 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00005072 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00005073 = cast_or_null<ObjCProtocolDecl>(
5074 getDerived().TransformDecl(E->getProtocol()));
5075 if (!Protocol)
5076 return SemaRef.ExprError();
5077
5078 if (!getDerived().AlwaysRebuild() &&
5079 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005080 return SemaRef.Owned(E->Retain());
5081
Douglas Gregora16548e2009-08-11 05:31:07 +00005082 return getDerived().RebuildObjCProtocolExpr(Protocol,
5083 E->getAtLoc(),
5084 /*FIXME:*/E->getAtLoc(),
5085 /*FIXME:*/E->getAtLoc(),
5086 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005087
Douglas Gregora16548e2009-08-11 05:31:07 +00005088}
5089
Mike Stump11289f42009-09-09 15:08:12 +00005090template<typename Derived>
5091Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005092TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E,
5093 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005094 // FIXME: Implement this!
5095 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005096 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005097}
5098
Mike Stump11289f42009-09-09 15:08:12 +00005099template<typename Derived>
5100Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005101TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E,
5102 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005103 // FIXME: Implement this!
5104 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005105 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005106}
5107
Mike Stump11289f42009-09-09 15:08:12 +00005108template<typename Derived>
5109Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005110TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005111 ObjCImplicitSetterGetterRefExpr *E,
5112 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005113 // FIXME: Implement this!
5114 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005115 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005116}
5117
Mike Stump11289f42009-09-09 15:08:12 +00005118template<typename Derived>
5119Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005120TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E,
5121 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005122 // FIXME: Implement this!
5123 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005124 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005125}
5126
Mike Stump11289f42009-09-09 15:08:12 +00005127template<typename Derived>
5128Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005129TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E,
5130 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005131 // FIXME: Implement this!
5132 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005133 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005134}
5135
Mike Stump11289f42009-09-09 15:08:12 +00005136template<typename Derived>
5137Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005138TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E,
5139 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005140 bool ArgumentChanged = false;
5141 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5142 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5143 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5144 if (SubExpr.isInvalid())
5145 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005146
Douglas Gregora16548e2009-08-11 05:31:07 +00005147 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5148 SubExprs.push_back(SubExpr.takeAs<Expr>());
5149 }
Mike Stump11289f42009-09-09 15:08:12 +00005150
Douglas Gregora16548e2009-08-11 05:31:07 +00005151 if (!getDerived().AlwaysRebuild() &&
5152 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005153 return SemaRef.Owned(E->Retain());
5154
Douglas Gregora16548e2009-08-11 05:31:07 +00005155 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5156 move_arg(SubExprs),
5157 E->getRParenLoc());
5158}
5159
Mike Stump11289f42009-09-09 15:08:12 +00005160template<typename Derived>
5161Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005162TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E,
5163 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005164 // FIXME: Implement this!
5165 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005166 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005167}
5168
Mike Stump11289f42009-09-09 15:08:12 +00005169template<typename Derived>
5170Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005171TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E,
5172 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005173 // FIXME: Implement this!
5174 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005175 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005176}
Mike Stump11289f42009-09-09 15:08:12 +00005177
Douglas Gregora16548e2009-08-11 05:31:07 +00005178//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005179// Type reconstruction
5180//===----------------------------------------------------------------------===//
5181
Mike Stump11289f42009-09-09 15:08:12 +00005182template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005183QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5184 SourceLocation Star) {
5185 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005186 getDerived().getBaseEntity());
5187}
5188
Mike Stump11289f42009-09-09 15:08:12 +00005189template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005190QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5191 SourceLocation Star) {
5192 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005193 getDerived().getBaseEntity());
5194}
5195
Mike Stump11289f42009-09-09 15:08:12 +00005196template<typename Derived>
5197QualType
John McCall70dd5f62009-10-30 00:06:24 +00005198TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5199 bool WrittenAsLValue,
5200 SourceLocation Sigil) {
5201 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5202 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005203}
5204
5205template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005206QualType
John McCall70dd5f62009-10-30 00:06:24 +00005207TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5208 QualType ClassType,
5209 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005210 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005211 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005212}
5213
5214template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005215QualType
John McCall70dd5f62009-10-30 00:06:24 +00005216TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5217 SourceLocation Sigil) {
5218 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005219 getDerived().getBaseEntity());
5220}
5221
5222template<typename Derived>
5223QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005224TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5225 ArrayType::ArraySizeModifier SizeMod,
5226 const llvm::APInt *Size,
5227 Expr *SizeExpr,
5228 unsigned IndexTypeQuals,
5229 SourceRange BracketsRange) {
5230 if (SizeExpr || !Size)
5231 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5232 IndexTypeQuals, BracketsRange,
5233 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005234
5235 QualType Types[] = {
5236 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5237 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5238 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005239 };
5240 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5241 QualType SizeType;
5242 for (unsigned I = 0; I != NumTypes; ++I)
5243 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5244 SizeType = Types[I];
5245 break;
5246 }
Mike Stump11289f42009-09-09 15:08:12 +00005247
Douglas Gregord6ff3322009-08-04 16:50:30 +00005248 if (SizeType.isNull())
5249 SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false);
Mike Stump11289f42009-09-09 15:08:12 +00005250
Douglas Gregord6ff3322009-08-04 16:50:30 +00005251 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005252 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005253 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005254 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005255}
Mike Stump11289f42009-09-09 15:08:12 +00005256
Douglas Gregord6ff3322009-08-04 16:50:30 +00005257template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005258QualType
5259TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005260 ArrayType::ArraySizeModifier SizeMod,
5261 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005262 unsigned IndexTypeQuals,
5263 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005264 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005265 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005266}
5267
5268template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005269QualType
Mike Stump11289f42009-09-09 15:08:12 +00005270TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005271 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005272 unsigned IndexTypeQuals,
5273 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005274 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005275 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005276}
Mike Stump11289f42009-09-09 15:08:12 +00005277
Douglas Gregord6ff3322009-08-04 16:50:30 +00005278template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005279QualType
5280TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005281 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005282 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005283 unsigned IndexTypeQuals,
5284 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005285 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005286 SizeExpr.takeAs<Expr>(),
5287 IndexTypeQuals, BracketsRange);
5288}
5289
5290template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005291QualType
5292TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005293 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005294 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005295 unsigned IndexTypeQuals,
5296 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005297 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005298 SizeExpr.takeAs<Expr>(),
5299 IndexTypeQuals, BracketsRange);
5300}
5301
5302template<typename Derived>
5303QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
5304 unsigned NumElements) {
5305 // FIXME: semantic checking!
5306 return SemaRef.Context.getVectorType(ElementType, NumElements);
5307}
Mike Stump11289f42009-09-09 15:08:12 +00005308
Douglas Gregord6ff3322009-08-04 16:50:30 +00005309template<typename Derived>
5310QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5311 unsigned NumElements,
5312 SourceLocation AttributeLoc) {
5313 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5314 NumElements, true);
5315 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005316 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005317 AttributeLoc);
5318 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5319 AttributeLoc);
5320}
Mike Stump11289f42009-09-09 15:08:12 +00005321
Douglas Gregord6ff3322009-08-04 16:50:30 +00005322template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005323QualType
5324TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005325 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005326 SourceLocation AttributeLoc) {
5327 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5328}
Mike Stump11289f42009-09-09 15:08:12 +00005329
Douglas Gregord6ff3322009-08-04 16:50:30 +00005330template<typename Derived>
5331QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005332 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005333 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005334 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005335 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005336 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005337 Quals,
5338 getDerived().getBaseLocation(),
5339 getDerived().getBaseEntity());
5340}
Mike Stump11289f42009-09-09 15:08:12 +00005341
Douglas Gregord6ff3322009-08-04 16:50:30 +00005342template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005343QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5344 return SemaRef.Context.getFunctionNoProtoType(T);
5345}
5346
5347template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005348QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5349 assert(D && "no decl found");
5350 if (D->isInvalidDecl()) return QualType();
5351
5352 TypeDecl *Ty;
5353 if (isa<UsingDecl>(D)) {
5354 UsingDecl *Using = cast<UsingDecl>(D);
5355 assert(Using->isTypeName() &&
5356 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5357
5358 // A valid resolved using typename decl points to exactly one type decl.
5359 assert(++Using->shadow_begin() == Using->shadow_end());
5360 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5361
5362 } else {
5363 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5364 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5365 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5366 }
5367
5368 return SemaRef.Context.getTypeDeclType(Ty);
5369}
5370
5371template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005372QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005373 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5374}
5375
5376template<typename Derived>
5377QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5378 return SemaRef.Context.getTypeOfType(Underlying);
5379}
5380
5381template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005382QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005383 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5384}
5385
5386template<typename Derived>
5387QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005388 TemplateName Template,
5389 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005390 const TemplateArgumentListInfo &TemplateArgs) {
5391 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005392}
Mike Stump11289f42009-09-09 15:08:12 +00005393
Douglas Gregor1135c352009-08-06 05:28:30 +00005394template<typename Derived>
5395NestedNameSpecifier *
5396TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5397 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005398 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005399 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005400 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005401 CXXScopeSpec SS;
5402 // FIXME: The source location information is all wrong.
5403 SS.setRange(Range);
5404 SS.setScopeRep(Prefix);
5405 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005406 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005407 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005408 ObjectType,
5409 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005410 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005411}
5412
5413template<typename Derived>
5414NestedNameSpecifier *
5415TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5416 SourceRange Range,
5417 NamespaceDecl *NS) {
5418 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5419}
5420
5421template<typename Derived>
5422NestedNameSpecifier *
5423TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5424 SourceRange Range,
5425 bool TemplateKW,
5426 QualType T) {
5427 if (T->isDependentType() || T->isRecordType() ||
5428 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005429 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005430 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5431 T.getTypePtr());
5432 }
Mike Stump11289f42009-09-09 15:08:12 +00005433
Douglas Gregor1135c352009-08-06 05:28:30 +00005434 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5435 return 0;
5436}
Mike Stump11289f42009-09-09 15:08:12 +00005437
Douglas Gregor71dc5092009-08-06 06:41:21 +00005438template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005439TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005440TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5441 bool TemplateKW,
5442 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005443 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005444 Template);
5445}
5446
5447template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005448TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005449TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005450 const IdentifierInfo &II,
5451 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005452 CXXScopeSpec SS;
5453 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005454 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005455 UnqualifiedId Name;
5456 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005457 return getSema().ActOnDependentTemplateName(
5458 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005459 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005460 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005461 ObjectType.getAsOpaquePtr(),
5462 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005463 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005464}
Mike Stump11289f42009-09-09 15:08:12 +00005465
Douglas Gregora16548e2009-08-11 05:31:07 +00005466template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005467TemplateName
5468TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5469 OverloadedOperatorKind Operator,
5470 QualType ObjectType) {
5471 CXXScopeSpec SS;
5472 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5473 SS.setScopeRep(Qualifier);
5474 UnqualifiedId Name;
5475 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5476 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5477 Operator, SymbolLocations);
5478 return getSema().ActOnDependentTemplateName(
5479 /*FIXME:*/getDerived().getBaseLocation(),
5480 SS,
5481 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005482 ObjectType.getAsOpaquePtr(),
5483 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005484 .template getAsVal<TemplateName>();
5485}
5486
5487template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005488Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005489TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5490 SourceLocation OpLoc,
5491 ExprArg Callee,
5492 ExprArg First,
5493 ExprArg Second) {
5494 Expr *FirstExpr = (Expr *)First.get();
5495 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005496 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005497 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005498
Douglas Gregora16548e2009-08-11 05:31:07 +00005499 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005500 if (Op == OO_Subscript) {
5501 if (!FirstExpr->getType()->isOverloadableType() &&
5502 !SecondExpr->getType()->isOverloadableType())
5503 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005504 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005505 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005506 } else if (Op == OO_Arrow) {
5507 // -> is never a builtin operation.
5508 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005509 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005510 if (!FirstExpr->getType()->isOverloadableType()) {
5511 // The argument is not of overloadable type, so try to create a
5512 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005513 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005514 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005515
Douglas Gregora16548e2009-08-11 05:31:07 +00005516 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5517 }
5518 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005519 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005520 !SecondExpr->getType()->isOverloadableType()) {
5521 // Neither of the arguments is an overloadable type, so try to
5522 // create a built-in binary operation.
5523 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005524 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005525 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5526 if (Result.isInvalid())
5527 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005528
Douglas Gregora16548e2009-08-11 05:31:07 +00005529 First.release();
5530 Second.release();
5531 return move(Result);
5532 }
5533 }
Mike Stump11289f42009-09-09 15:08:12 +00005534
5535 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005536 // used during overload resolution.
5537 Sema::FunctionSet Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005538
John McCalld14a8642009-11-21 08:51:07 +00005539 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5540 assert(ULE->requiresADL());
5541
5542 // FIXME: Do we have to check
5543 // IsAcceptableNonMemberOperatorCandidate for each of these?
5544 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(),
5545 E = ULE->decls_end(); I != E; ++I)
5546 Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I));
5547 } else {
5548 Functions.insert(AnyFunctionDecl::getFromNamedDecl(
5549 cast<DeclRefExpr>(CalleeExpr)->getDecl()));
5550 }
Mike Stump11289f42009-09-09 15:08:12 +00005551
Douglas Gregora16548e2009-08-11 05:31:07 +00005552 // Add any functions found via argument-dependent lookup.
5553 Expr *Args[2] = { FirstExpr, SecondExpr };
5554 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005555 DeclarationName OpName
Douglas Gregora16548e2009-08-11 05:31:07 +00005556 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
Sebastian Redlc057f422009-10-23 19:23:15 +00005557 SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs,
5558 Functions);
Mike Stump11289f42009-09-09 15:08:12 +00005559
Douglas Gregora16548e2009-08-11 05:31:07 +00005560 // Create the overloaded operator invocation for unary operators.
5561 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005562 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005563 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5564 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5565 }
Mike Stump11289f42009-09-09 15:08:12 +00005566
Sebastian Redladba46e2009-10-29 20:17:01 +00005567 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005568 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5569 OpLoc,
5570 move(First),
5571 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005572
Douglas Gregora16548e2009-08-11 05:31:07 +00005573 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005574 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005575 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005576 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005577 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5578 if (Result.isInvalid())
5579 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005580
Douglas Gregora16548e2009-08-11 05:31:07 +00005581 First.release();
5582 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005583 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005584}
Mike Stump11289f42009-09-09 15:08:12 +00005585
Douglas Gregord6ff3322009-08-04 16:50:30 +00005586} // end namespace clang
5587
5588#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H