blob: 1071aebe17721eb8e1f0557fae82371dfda579c1 [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
Douglas Gregord6ff3322009-08-04 16:50:30 +0000464 /// \brief Build a new typedef type.
465 QualType RebuildTypedefType(TypedefDecl *Typedef) {
466 return SemaRef.Context.getTypeDeclType(Typedef);
467 }
468
469 /// \brief Build a new class/struct/union type.
470 QualType RebuildRecordType(RecordDecl *Record) {
471 return SemaRef.Context.getTypeDeclType(Record);
472 }
473
474 /// \brief Build a new Enum type.
475 QualType RebuildEnumType(EnumDecl *Enum) {
476 return SemaRef.Context.getTypeDeclType(Enum);
477 }
John McCallfcc33b02009-09-05 00:15:47 +0000478
479 /// \brief Build a new elaborated type.
480 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
481 return SemaRef.Context.getElaboratedType(T, Tag);
482 }
Mike Stump11289f42009-09-09 15:08:12 +0000483
484 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000485 ///
486 /// By default, performs semantic analysis when building the typeof type.
487 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000488 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000489
Mike Stump11289f42009-09-09 15:08:12 +0000490 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000491 ///
492 /// By default, builds a new TypeOfType with the given underlying type.
493 QualType RebuildTypeOfType(QualType Underlying);
494
Mike Stump11289f42009-09-09 15:08:12 +0000495 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000496 ///
497 /// By default, performs semantic analysis when building the decltype type.
498 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000499 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000500
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501 /// \brief Build a new template specialization type.
502 ///
503 /// By default, performs semantic analysis when building the template
504 /// specialization type. Subclasses may override this routine to provide
505 /// different behavior.
506 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000507 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000508 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000509
Douglas Gregord6ff3322009-08-04 16:50:30 +0000510 /// \brief Build a new qualified name type.
511 ///
Mike Stump11289f42009-09-09 15:08:12 +0000512 /// By default, builds a new QualifiedNameType type from the
513 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000514 /// this routine to provide different behavior.
515 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
516 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000517 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000518
519 /// \brief Build a new typename type that refers to a template-id.
520 ///
521 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000522 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000523 /// different behavior.
524 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
525 if (NNS->isDependent())
Mike Stump11289f42009-09-09 15:08:12 +0000526 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000527 cast<TemplateSpecializationType>(T));
Mike Stump11289f42009-09-09 15:08:12 +0000528
Douglas Gregord6ff3322009-08-04 16:50:30 +0000529 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000530 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000531
532 /// \brief Build a new typename type that refers to an identifier.
533 ///
534 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000535 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000536 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000537 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall0ad16662009-10-29 08:12:44 +0000538 const IdentifierInfo *Id,
539 SourceRange SR) {
540 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregor1135c352009-08-06 05:28:30 +0000541 }
Mike Stump11289f42009-09-09 15:08:12 +0000542
Douglas Gregor1135c352009-08-06 05:28:30 +0000543 /// \brief Build a new nested-name-specifier given the prefix and an
544 /// identifier that names the next step in the nested-name-specifier.
545 ///
546 /// By default, performs semantic analysis when building the new
547 /// nested-name-specifier. Subclasses may override this routine to provide
548 /// different behavior.
549 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
550 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000551 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000552 QualType ObjectType,
553 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000554
555 /// \brief Build a new nested-name-specifier given the prefix and the
556 /// namespace named in the next step in the nested-name-specifier.
557 ///
558 /// By default, performs semantic analysis when building the new
559 /// nested-name-specifier. Subclasses may override this routine to provide
560 /// different behavior.
561 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
562 SourceRange Range,
563 NamespaceDecl *NS);
564
565 /// \brief Build a new nested-name-specifier given the prefix and the
566 /// type named in the next step in the nested-name-specifier.
567 ///
568 /// By default, performs semantic analysis when building the new
569 /// nested-name-specifier. Subclasses may override this routine to provide
570 /// different behavior.
571 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
572 SourceRange Range,
573 bool TemplateKW,
574 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000575
576 /// \brief Build a new template name given a nested name specifier, a flag
577 /// indicating whether the "template" keyword was provided, and the template
578 /// that the template name refers to.
579 ///
580 /// By default, builds the new template name directly. Subclasses may override
581 /// this routine to provide different behavior.
582 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
583 bool TemplateKW,
584 TemplateDecl *Template);
585
Douglas Gregor71dc5092009-08-06 06:41:21 +0000586 /// \brief Build a new template name given a nested name specifier and the
587 /// name that is referred to as a template.
588 ///
589 /// By default, performs semantic analysis to determine whether the name can
590 /// be resolved to a specific template, then builds the appropriate kind of
591 /// template name. Subclasses may override this routine to provide different
592 /// behavior.
593 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000594 const IdentifierInfo &II,
595 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000596
Douglas Gregor71395fa2009-11-04 00:56:37 +0000597 /// \brief Build a new template name given a nested name specifier and the
598 /// overloaded operator name that is referred to as a template.
599 ///
600 /// By default, performs semantic analysis to determine whether the name can
601 /// be resolved to a specific template, then builds the appropriate kind of
602 /// template name. Subclasses may override this routine to provide different
603 /// behavior.
604 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
605 OverloadedOperatorKind Operator,
606 QualType ObjectType);
607
Douglas Gregorebe10102009-08-20 07:17:43 +0000608 /// \brief Build a new compound statement.
609 ///
610 /// By default, performs semantic analysis to build the new statement.
611 /// Subclasses may override this routine to provide different behavior.
612 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
613 MultiStmtArg Statements,
614 SourceLocation RBraceLoc,
615 bool IsStmtExpr) {
616 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
617 IsStmtExpr);
618 }
619
620 /// \brief Build a new case statement.
621 ///
622 /// By default, performs semantic analysis to build the new statement.
623 /// Subclasses may override this routine to provide different behavior.
624 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
625 ExprArg LHS,
626 SourceLocation EllipsisLoc,
627 ExprArg RHS,
628 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000629 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000630 ColonLoc);
631 }
Mike Stump11289f42009-09-09 15:08:12 +0000632
Douglas Gregorebe10102009-08-20 07:17:43 +0000633 /// \brief Attach the body to a new case statement.
634 ///
635 /// By default, performs semantic analysis to build the new statement.
636 /// Subclasses may override this routine to provide different behavior.
637 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
638 getSema().ActOnCaseStmtBody(S.get(), move(Body));
639 return move(S);
640 }
Mike Stump11289f42009-09-09 15:08:12 +0000641
Douglas Gregorebe10102009-08-20 07:17:43 +0000642 /// \brief Build a new default statement.
643 ///
644 /// By default, performs semantic analysis to build the new statement.
645 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000646 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000647 SourceLocation ColonLoc,
648 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000649 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000650 /*CurScope=*/0);
651 }
Mike Stump11289f42009-09-09 15:08:12 +0000652
Douglas Gregorebe10102009-08-20 07:17:43 +0000653 /// \brief Build a new label statement.
654 ///
655 /// By default, performs semantic analysis to build the new statement.
656 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000657 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000658 IdentifierInfo *Id,
659 SourceLocation ColonLoc,
660 StmtArg SubStmt) {
661 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
662 }
Mike Stump11289f42009-09-09 15:08:12 +0000663
Douglas Gregorebe10102009-08-20 07:17:43 +0000664 /// \brief Build a new "if" statement.
665 ///
666 /// By default, performs semantic analysis to build the new statement.
667 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000668 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000669 VarDecl *CondVar, StmtArg Then,
670 SourceLocation ElseLoc, StmtArg Else) {
671 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
672 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000673 }
Mike Stump11289f42009-09-09 15:08:12 +0000674
Douglas Gregorebe10102009-08-20 07:17:43 +0000675 /// \brief Start building a new switch statement.
676 ///
677 /// By default, performs semantic analysis to build the new statement.
678 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000679 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
680 VarDecl *CondVar) {
681 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000682 }
Mike Stump11289f42009-09-09 15:08:12 +0000683
Douglas Gregorebe10102009-08-20 07:17:43 +0000684 /// \brief Attach the body to the switch statement.
685 ///
686 /// By default, performs semantic analysis to build the new statement.
687 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000688 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000689 StmtArg Switch, StmtArg Body) {
690 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
691 move(Body));
692 }
693
694 /// \brief Build a new while statement.
695 ///
696 /// By default, performs semantic analysis to build the new statement.
697 /// Subclasses may override this routine to provide different behavior.
698 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
699 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000700 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000701 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000702 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
703 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000704 }
Mike Stump11289f42009-09-09 15:08:12 +0000705
Douglas Gregorebe10102009-08-20 07:17:43 +0000706 /// \brief Build a new do-while statement.
707 ///
708 /// By default, performs semantic analysis to build the new statement.
709 /// Subclasses may override this routine to provide different behavior.
710 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
711 SourceLocation WhileLoc,
712 SourceLocation LParenLoc,
713 ExprArg Cond,
714 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000715 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000716 move(Cond), RParenLoc);
717 }
718
719 /// \brief Build a new for statement.
720 ///
721 /// By default, performs semantic analysis to build the new statement.
722 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000723 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000724 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000725 StmtArg Init, Sema::FullExprArg Cond,
726 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000727 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000728 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
729 DeclPtrTy::make(CondVar),
730 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000731 }
Mike Stump11289f42009-09-09 15:08:12 +0000732
Douglas Gregorebe10102009-08-20 07:17:43 +0000733 /// \brief Build a new goto statement.
734 ///
735 /// By default, performs semantic analysis to build the new statement.
736 /// Subclasses may override this routine to provide different behavior.
737 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
738 SourceLocation LabelLoc,
739 LabelStmt *Label) {
740 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
741 }
742
743 /// \brief Build a new indirect goto statement.
744 ///
745 /// By default, performs semantic analysis to build the new statement.
746 /// Subclasses may override this routine to provide different behavior.
747 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
748 SourceLocation StarLoc,
749 ExprArg Target) {
750 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
751 }
Mike Stump11289f42009-09-09 15:08:12 +0000752
Douglas Gregorebe10102009-08-20 07:17:43 +0000753 /// \brief Build a new return statement.
754 ///
755 /// By default, performs semantic analysis to build the new statement.
756 /// Subclasses may override this routine to provide different behavior.
757 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
758 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000759
Douglas Gregorebe10102009-08-20 07:17:43 +0000760 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
761 }
Mike Stump11289f42009-09-09 15:08:12 +0000762
Douglas Gregorebe10102009-08-20 07:17:43 +0000763 /// \brief Build a new declaration statement.
764 ///
765 /// By default, performs semantic analysis to build the new statement.
766 /// Subclasses may override this routine to provide different behavior.
767 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000768 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000769 SourceLocation EndLoc) {
770 return getSema().Owned(
771 new (getSema().Context) DeclStmt(
772 DeclGroupRef::Create(getSema().Context,
773 Decls, NumDecls),
774 StartLoc, EndLoc));
775 }
Mike Stump11289f42009-09-09 15:08:12 +0000776
Douglas Gregorebe10102009-08-20 07:17:43 +0000777 /// \brief Build a new C++ exception declaration.
778 ///
779 /// By default, performs semantic analysis to build the new decaration.
780 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000781 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
Douglas Gregorebe10102009-08-20 07:17:43 +0000782 DeclaratorInfo *Declarator,
783 IdentifierInfo *Name,
784 SourceLocation Loc,
785 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000786 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000787 TypeRange);
788 }
789
790 /// \brief Build a new C++ catch statement.
791 ///
792 /// By default, performs semantic analysis to build the new statement.
793 /// Subclasses may override this routine to provide different behavior.
794 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
795 VarDecl *ExceptionDecl,
796 StmtArg Handler) {
797 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000798 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000799 Handler.takeAs<Stmt>()));
800 }
Mike Stump11289f42009-09-09 15:08:12 +0000801
Douglas Gregorebe10102009-08-20 07:17:43 +0000802 /// \brief Build a new C++ try statement.
803 ///
804 /// By default, performs semantic analysis to build the new statement.
805 /// Subclasses may override this routine to provide different behavior.
806 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
807 StmtArg TryBlock,
808 MultiStmtArg Handlers) {
809 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
810 }
Mike Stump11289f42009-09-09 15:08:12 +0000811
Douglas Gregora16548e2009-08-11 05:31:07 +0000812 /// \brief Build a new expression that references a declaration.
813 ///
814 /// By default, performs semantic analysis to build the new expression.
815 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +0000816 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
817 LookupResult &R,
818 bool RequiresADL) {
819 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
820 }
821
822
823 /// \brief Build a new expression that references a declaration.
824 ///
825 /// By default, performs semantic analysis to build the new expression.
826 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000827 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
828 SourceRange QualifierRange,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +0000829 NamedDecl *ND, SourceLocation Loc,
830 bool isAddressOfOperand) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000831 CXXScopeSpec SS;
832 SS.setScopeRep(Qualifier);
833 SS.setRange(QualifierRange);
Douglas Gregora16548e2009-08-11 05:31:07 +0000834 return getSema().BuildDeclarationNameExpr(Loc, ND,
835 /*FIXME:*/false,
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000836 &SS,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +0000837 isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +0000838 }
Mike Stump11289f42009-09-09 15:08:12 +0000839
Douglas Gregora16548e2009-08-11 05:31:07 +0000840 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000841 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000842 /// By default, performs semantic analysis to build the new expression.
843 /// Subclasses may override this routine to provide different behavior.
844 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
845 SourceLocation RParen) {
846 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
847 }
848
Douglas Gregorad8a3362009-09-04 17:36:40 +0000849 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000850 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000851 /// By default, performs semantic analysis to build the new expression.
852 /// Subclasses may override this routine to provide different behavior.
853 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
854 SourceLocation OperatorLoc,
855 bool isArrow,
856 SourceLocation DestroyedTypeLoc,
857 QualType DestroyedType,
858 NestedNameSpecifier *Qualifier,
859 SourceRange QualifierRange) {
860 CXXScopeSpec SS;
861 if (Qualifier) {
862 SS.setRange(QualifierRange);
863 SS.setScopeRep(Qualifier);
864 }
865
Mike Stump11289f42009-09-09 15:08:12 +0000866 DeclarationName Name
Douglas Gregorad8a3362009-09-04 17:36:40 +0000867 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
868 SemaRef.Context.getCanonicalType(DestroyedType));
Mike Stump11289f42009-09-09 15:08:12 +0000869
870 return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base),
Douglas Gregorad8a3362009-09-04 17:36:40 +0000871 OperatorLoc,
872 isArrow? tok::arrow : tok::period,
873 DestroyedTypeLoc,
874 Name,
875 Sema::DeclPtrTy::make((Decl *)0),
876 &SS);
Mike Stump11289f42009-09-09 15:08:12 +0000877 }
878
Douglas Gregora16548e2009-08-11 05:31:07 +0000879 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000880 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000881 /// By default, performs semantic analysis to build the new expression.
882 /// Subclasses may override this routine to provide different behavior.
883 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
884 UnaryOperator::Opcode Opc,
885 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000886 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +0000887 }
Mike Stump11289f42009-09-09 15:08:12 +0000888
Douglas Gregora16548e2009-08-11 05:31:07 +0000889 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000890 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000891 /// By default, performs semantic analysis to build the new expression.
892 /// Subclasses may override this routine to provide different behavior.
John McCall4c98fd82009-11-04 07:28:41 +0000893 OwningExprResult RebuildSizeOfAlignOf(DeclaratorInfo *DInfo,
894 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000895 bool isSizeOf, SourceRange R) {
John McCall4c98fd82009-11-04 07:28:41 +0000896 return getSema().CreateSizeOfAlignOfExpr(DInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +0000897 }
898
Mike Stump11289f42009-09-09 15:08:12 +0000899 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000900 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +0000901 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000902 /// By default, performs semantic analysis to build the new expression.
903 /// Subclasses may override this routine to provide different behavior.
904 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
905 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +0000906 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000907 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
908 OpLoc, isSizeOf, R);
909 if (Result.isInvalid())
910 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000911
Douglas Gregora16548e2009-08-11 05:31:07 +0000912 SubExpr.release();
913 return move(Result);
914 }
Mike Stump11289f42009-09-09 15:08:12 +0000915
Douglas Gregora16548e2009-08-11 05:31:07 +0000916 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +0000917 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000918 /// By default, performs semantic analysis to build the new expression.
919 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000920 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000921 SourceLocation LBracketLoc,
922 ExprArg RHS,
923 SourceLocation RBracketLoc) {
924 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000925 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000926 RBracketLoc);
927 }
928
929 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000930 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000931 /// By default, performs semantic analysis to build the new expression.
932 /// Subclasses may override this routine to provide different behavior.
933 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
934 MultiExprArg Args,
935 SourceLocation *CommaLocs,
936 SourceLocation RParenLoc) {
937 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
938 move(Args), CommaLocs, RParenLoc);
939 }
940
941 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000942 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000943 /// By default, performs semantic analysis to build the new expression.
944 /// Subclasses may override this routine to provide different behavior.
945 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000946 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000947 NestedNameSpecifier *Qualifier,
948 SourceRange QualifierRange,
949 SourceLocation MemberLoc,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000950 NamedDecl *Member,
John McCall6b51f282009-11-23 01:53:49 +0000951 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000952 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +0000953 if (!Member->getDeclName()) {
954 // We have a reference to an unnamed field.
955 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +0000956
957 MemberExpr *ME =
Anders Carlsson5da84842009-09-01 04:26:58 +0000958 new (getSema().Context) MemberExpr(Base.takeAs<Expr>(), isArrow,
959 Member, MemberLoc,
960 cast<FieldDecl>(Member)->getType());
961 return getSema().Owned(ME);
962 }
Mike Stump11289f42009-09-09 15:08:12 +0000963
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000964 CXXScopeSpec SS;
965 if (Qualifier) {
966 SS.setRange(QualifierRange);
967 SS.setScopeRep(Qualifier);
968 }
969
Douglas Gregorf14b46f2009-08-31 20:00:26 +0000970 return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000971 isArrow? tok::arrow : tok::period,
972 MemberLoc,
Douglas Gregorf14b46f2009-08-31 20:00:26 +0000973 Member->getDeclName(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000974 ExplicitTemplateArgs,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000975 /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0),
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000976 &SS,
977 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +0000978 }
Mike Stump11289f42009-09-09 15:08:12 +0000979
Douglas Gregora16548e2009-08-11 05:31:07 +0000980 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000981 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000982 /// By default, performs semantic analysis to build the new expression.
983 /// Subclasses may override this routine to provide different behavior.
984 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
985 BinaryOperator::Opcode Opc,
986 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000987 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
988 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +0000989 }
990
991 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000992 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000993 /// By default, performs semantic analysis to build the new expression.
994 /// Subclasses may override this routine to provide different behavior.
995 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
996 SourceLocation QuestionLoc,
997 ExprArg LHS,
998 SourceLocation ColonLoc,
999 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001000 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001001 move(LHS), move(RHS));
1002 }
1003
1004 /// \brief Build a new implicit cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001005 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001006 /// By default, builds a new implicit cast without any semantic analysis.
1007 /// Subclasses may override this routine to provide different behavior.
1008 OwningExprResult RebuildImplicitCastExpr(QualType T, CastExpr::CastKind Kind,
1009 ExprArg SubExpr, bool isLvalue) {
1010 ImplicitCastExpr *ICE
Mike Stump11289f42009-09-09 15:08:12 +00001011 = new (getSema().Context) ImplicitCastExpr(T, Kind,
Douglas Gregora16548e2009-08-11 05:31:07 +00001012 (Expr *)SubExpr.release(),
1013 isLvalue);
1014 return getSema().Owned(ICE);
1015 }
1016
1017 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001018 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001019 /// By default, performs semantic analysis to build the new expression.
1020 /// Subclasses may override this routine to provide different behavior.
1021 OwningExprResult RebuildCStyleCaseExpr(SourceLocation LParenLoc,
1022 QualType ExplicitTy,
1023 SourceLocation RParenLoc,
1024 ExprArg SubExpr) {
1025 return getSema().ActOnCastExpr(/*Scope=*/0,
1026 LParenLoc,
1027 ExplicitTy.getAsOpaquePtr(),
1028 RParenLoc,
1029 move(SubExpr));
1030 }
Mike Stump11289f42009-09-09 15:08:12 +00001031
Douglas Gregora16548e2009-08-11 05:31:07 +00001032 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001033 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001034 /// By default, performs semantic analysis to build the new expression.
1035 /// Subclasses may override this routine to provide different behavior.
1036 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
1037 QualType T,
1038 SourceLocation RParenLoc,
1039 ExprArg Init) {
1040 return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(),
1041 RParenLoc, move(Init));
1042 }
Mike Stump11289f42009-09-09 15:08:12 +00001043
Douglas Gregora16548e2009-08-11 05:31:07 +00001044 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001045 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001046 /// By default, performs semantic analysis to build the new expression.
1047 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001048 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001049 SourceLocation OpLoc,
1050 SourceLocation AccessorLoc,
1051 IdentifierInfo &Accessor) {
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001052 return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001053 tok::period, AccessorLoc,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001054 DeclarationName(&Accessor),
Douglas Gregora16548e2009-08-11 05:31:07 +00001055 /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0));
1056 }
Mike Stump11289f42009-09-09 15:08:12 +00001057
Douglas Gregora16548e2009-08-11 05:31:07 +00001058 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001059 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001060 /// By default, performs semantic analysis to build the new expression.
1061 /// Subclasses may override this routine to provide different behavior.
1062 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1063 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001064 SourceLocation RBraceLoc,
1065 QualType ResultTy) {
1066 OwningExprResult Result
1067 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1068 if (Result.isInvalid() || ResultTy->isDependentType())
1069 return move(Result);
1070
1071 // Patch in the result type we were given, which may have been computed
1072 // when the initial InitListExpr was built.
1073 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1074 ILE->setType(ResultTy);
1075 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001076 }
Mike Stump11289f42009-09-09 15:08:12 +00001077
Douglas Gregora16548e2009-08-11 05:31:07 +00001078 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001079 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001080 /// By default, performs semantic analysis to build the new expression.
1081 /// Subclasses may override this routine to provide different behavior.
1082 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1083 MultiExprArg ArrayExprs,
1084 SourceLocation EqualOrColonLoc,
1085 bool GNUSyntax,
1086 ExprArg Init) {
1087 OwningExprResult Result
1088 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1089 move(Init));
1090 if (Result.isInvalid())
1091 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001092
Douglas Gregora16548e2009-08-11 05:31:07 +00001093 ArrayExprs.release();
1094 return move(Result);
1095 }
Mike Stump11289f42009-09-09 15:08:12 +00001096
Douglas Gregora16548e2009-08-11 05:31:07 +00001097 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001098 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001099 /// By default, builds the implicit value initialization without performing
1100 /// any semantic analysis. Subclasses may override this routine to provide
1101 /// different behavior.
1102 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1103 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1104 }
Mike Stump11289f42009-09-09 15:08:12 +00001105
Douglas Gregora16548e2009-08-11 05:31:07 +00001106 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001107 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001108 /// By default, performs semantic analysis to build the new expression.
1109 /// Subclasses may override this routine to provide different behavior.
1110 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1111 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001112 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001113 RParenLoc);
1114 }
1115
1116 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001117 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001118 /// By default, performs semantic analysis to build the new expression.
1119 /// Subclasses may override this routine to provide different behavior.
1120 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1121 MultiExprArg SubExprs,
1122 SourceLocation RParenLoc) {
1123 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
1124 }
Mike Stump11289f42009-09-09 15:08:12 +00001125
Douglas Gregora16548e2009-08-11 05:31:07 +00001126 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001127 ///
1128 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001129 /// rather than attempting to map the label statement itself.
1130 /// Subclasses may override this routine to provide different behavior.
1131 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1132 SourceLocation LabelLoc,
1133 LabelStmt *Label) {
1134 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1135 }
Mike Stump11289f42009-09-09 15:08:12 +00001136
Douglas Gregora16548e2009-08-11 05:31:07 +00001137 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001138 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001139 /// By default, performs semantic analysis to build the new expression.
1140 /// Subclasses may override this routine to provide different behavior.
1141 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1142 StmtArg SubStmt,
1143 SourceLocation RParenLoc) {
1144 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1145 }
Mike Stump11289f42009-09-09 15:08:12 +00001146
Douglas Gregora16548e2009-08-11 05:31:07 +00001147 /// \brief Build a new __builtin_types_compatible_p expression.
1148 ///
1149 /// By default, performs semantic analysis to build the new expression.
1150 /// Subclasses may override this routine to provide different behavior.
1151 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1152 QualType T1, QualType T2,
1153 SourceLocation RParenLoc) {
1154 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1155 T1.getAsOpaquePtr(),
1156 T2.getAsOpaquePtr(),
1157 RParenLoc);
1158 }
Mike Stump11289f42009-09-09 15:08:12 +00001159
Douglas Gregora16548e2009-08-11 05:31:07 +00001160 /// \brief Build a new __builtin_choose_expr expression.
1161 ///
1162 /// By default, performs semantic analysis to build the new expression.
1163 /// Subclasses may override this routine to provide different behavior.
1164 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1165 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1166 SourceLocation RParenLoc) {
1167 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1168 move(Cond), move(LHS), move(RHS),
1169 RParenLoc);
1170 }
Mike Stump11289f42009-09-09 15:08:12 +00001171
Douglas Gregora16548e2009-08-11 05:31:07 +00001172 /// \brief Build a new overloaded operator call expression.
1173 ///
1174 /// By default, performs semantic analysis to build the new expression.
1175 /// The semantic analysis provides the behavior of template instantiation,
1176 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001177 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001178 /// argument-dependent lookup, etc. Subclasses may override this routine to
1179 /// provide different behavior.
1180 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1181 SourceLocation OpLoc,
1182 ExprArg Callee,
1183 ExprArg First,
1184 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001185
1186 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001187 /// reinterpret_cast.
1188 ///
1189 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001190 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001191 /// Subclasses may override this routine to provide different behavior.
1192 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1193 Stmt::StmtClass Class,
1194 SourceLocation LAngleLoc,
1195 QualType T,
1196 SourceLocation RAngleLoc,
1197 SourceLocation LParenLoc,
1198 ExprArg SubExpr,
1199 SourceLocation RParenLoc) {
1200 switch (Class) {
1201 case Stmt::CXXStaticCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001202 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T,
1203 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001204 move(SubExpr), RParenLoc);
1205
1206 case Stmt::CXXDynamicCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001207 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T,
1208 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001209 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001210
Douglas Gregora16548e2009-08-11 05:31:07 +00001211 case Stmt::CXXReinterpretCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001212 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T,
1213 RAngleLoc, LParenLoc,
1214 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001216
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 case Stmt::CXXConstCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001218 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T,
1219 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001221
Douglas Gregora16548e2009-08-11 05:31:07 +00001222 default:
1223 assert(false && "Invalid C++ named cast");
1224 break;
1225 }
Mike Stump11289f42009-09-09 15:08:12 +00001226
Douglas Gregora16548e2009-08-11 05:31:07 +00001227 return getSema().ExprError();
1228 }
Mike Stump11289f42009-09-09 15:08:12 +00001229
Douglas Gregora16548e2009-08-11 05:31:07 +00001230 /// \brief Build a new C++ static_cast expression.
1231 ///
1232 /// By default, performs semantic analysis to build the new expression.
1233 /// Subclasses may override this routine to provide different behavior.
1234 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1235 SourceLocation LAngleLoc,
1236 QualType T,
1237 SourceLocation RAngleLoc,
1238 SourceLocation LParenLoc,
1239 ExprArg SubExpr,
1240 SourceLocation RParenLoc) {
1241 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001242 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001243 LParenLoc, move(SubExpr), RParenLoc);
1244 }
1245
1246 /// \brief Build a new C++ dynamic_cast expression.
1247 ///
1248 /// By default, performs semantic analysis to build the new expression.
1249 /// Subclasses may override this routine to provide different behavior.
1250 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1251 SourceLocation LAngleLoc,
1252 QualType T,
1253 SourceLocation RAngleLoc,
1254 SourceLocation LParenLoc,
1255 ExprArg SubExpr,
1256 SourceLocation RParenLoc) {
1257 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001258 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001259 LParenLoc, move(SubExpr), RParenLoc);
1260 }
1261
1262 /// \brief Build a new C++ reinterpret_cast expression.
1263 ///
1264 /// By default, performs semantic analysis to build the new expression.
1265 /// Subclasses may override this routine to provide different behavior.
1266 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1267 SourceLocation LAngleLoc,
1268 QualType T,
1269 SourceLocation RAngleLoc,
1270 SourceLocation LParenLoc,
1271 ExprArg SubExpr,
1272 SourceLocation RParenLoc) {
1273 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1274 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
1275 LParenLoc, move(SubExpr), RParenLoc);
1276 }
1277
1278 /// \brief Build a new C++ const_cast expression.
1279 ///
1280 /// By default, performs semantic analysis to build the new expression.
1281 /// Subclasses may override this routine to provide different behavior.
1282 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1283 SourceLocation LAngleLoc,
1284 QualType T,
1285 SourceLocation RAngleLoc,
1286 SourceLocation LParenLoc,
1287 ExprArg SubExpr,
1288 SourceLocation RParenLoc) {
1289 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001290 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001291 LParenLoc, move(SubExpr), RParenLoc);
1292 }
Mike Stump11289f42009-09-09 15:08:12 +00001293
Douglas Gregora16548e2009-08-11 05:31:07 +00001294 /// \brief Build a new C++ functional-style cast expression.
1295 ///
1296 /// By default, performs semantic analysis to build the new expression.
1297 /// Subclasses may override this routine to provide different behavior.
1298 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
1299 QualType T,
1300 SourceLocation LParenLoc,
1301 ExprArg SubExpr,
1302 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001303 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001304 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
1305 T.getAsOpaquePtr(),
1306 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001307 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001308 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 RParenLoc);
1310 }
Mike Stump11289f42009-09-09 15:08:12 +00001311
Douglas Gregora16548e2009-08-11 05:31:07 +00001312 /// \brief Build a new C++ typeid(type) expression.
1313 ///
1314 /// By default, performs semantic analysis to build the new expression.
1315 /// Subclasses may override this routine to provide different behavior.
1316 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1317 SourceLocation LParenLoc,
1318 QualType T,
1319 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001320 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 T.getAsOpaquePtr(), RParenLoc);
1322 }
Mike Stump11289f42009-09-09 15:08:12 +00001323
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 /// \brief Build a new C++ typeid(expr) expression.
1325 ///
1326 /// By default, performs semantic analysis to build the new expression.
1327 /// Subclasses may override this routine to provide different behavior.
1328 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1329 SourceLocation LParenLoc,
1330 ExprArg Operand,
1331 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001332 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1334 RParenLoc);
1335 if (Result.isInvalid())
1336 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001337
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1339 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001340 }
1341
Douglas Gregora16548e2009-08-11 05:31:07 +00001342 /// \brief Build a new C++ "this" expression.
1343 ///
1344 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001345 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001346 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001347 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001348 QualType ThisType) {
1349 return getSema().Owned(
1350 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType));
1351 }
1352
1353 /// \brief Build a new C++ throw expression.
1354 ///
1355 /// By default, performs semantic analysis to build the new expression.
1356 /// Subclasses may override this routine to provide different behavior.
1357 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1358 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1359 }
1360
1361 /// \brief Build a new C++ default-argument expression.
1362 ///
1363 /// By default, builds a new default-argument expression, which does not
1364 /// require any semantic analysis. Subclasses may override this routine to
1365 /// provide different behavior.
1366 OwningExprResult RebuildCXXDefaultArgExpr(ParmVarDecl *Param) {
Anders Carlssone8271232009-08-14 18:30:22 +00001367 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001368 }
1369
1370 /// \brief Build a new C++ zero-initialization expression.
1371 ///
1372 /// By default, performs semantic analysis to build the new expression.
1373 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001374 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001375 SourceLocation LParenLoc,
1376 QualType T,
1377 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001378 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1379 T.getAsOpaquePtr(), LParenLoc,
1380 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001381 0, RParenLoc);
1382 }
Mike Stump11289f42009-09-09 15:08:12 +00001383
Douglas Gregora16548e2009-08-11 05:31:07 +00001384 /// \brief Build a new C++ "new" expression.
1385 ///
1386 /// By default, performs semantic analysis to build the new expression.
1387 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001388 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001389 bool UseGlobal,
1390 SourceLocation PlacementLParen,
1391 MultiExprArg PlacementArgs,
1392 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001393 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001394 QualType AllocType,
1395 SourceLocation TypeLoc,
1396 SourceRange TypeRange,
1397 ExprArg ArraySize,
1398 SourceLocation ConstructorLParen,
1399 MultiExprArg ConstructorArgs,
1400 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001401 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001402 PlacementLParen,
1403 move(PlacementArgs),
1404 PlacementRParen,
1405 ParenTypeId,
1406 AllocType,
1407 TypeLoc,
1408 TypeRange,
1409 move(ArraySize),
1410 ConstructorLParen,
1411 move(ConstructorArgs),
1412 ConstructorRParen);
1413 }
Mike Stump11289f42009-09-09 15:08:12 +00001414
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 /// \brief Build a new C++ "delete" expression.
1416 ///
1417 /// By default, performs semantic analysis to build the new expression.
1418 /// Subclasses may override this routine to provide different behavior.
1419 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1420 bool IsGlobalDelete,
1421 bool IsArrayForm,
1422 ExprArg Operand) {
1423 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1424 move(Operand));
1425 }
Mike Stump11289f42009-09-09 15:08:12 +00001426
Douglas Gregora16548e2009-08-11 05:31:07 +00001427 /// \brief Build a new unary type trait expression.
1428 ///
1429 /// By default, performs semantic analysis to build the new expression.
1430 /// Subclasses may override this routine to provide different behavior.
1431 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1432 SourceLocation StartLoc,
1433 SourceLocation LParenLoc,
1434 QualType T,
1435 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001436 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001437 T.getAsOpaquePtr(), RParenLoc);
1438 }
1439
Mike Stump11289f42009-09-09 15:08:12 +00001440 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001441 /// expression.
1442 ///
1443 /// By default, performs semantic analysis to build the new expression.
1444 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001445 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001446 SourceRange QualifierRange,
1447 DeclarationName Name,
1448 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001449 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001450 CXXScopeSpec SS;
1451 SS.setRange(QualifierRange);
1452 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001453
1454 if (TemplateArgs)
1455 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1456 *TemplateArgs);
1457
1458 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001459 }
1460
1461 /// \brief Build a new template-id expression.
1462 ///
1463 /// By default, performs semantic analysis to build the new expression.
1464 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001465 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1466 LookupResult &R,
1467 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001468 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001469 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 }
1471
1472 /// \brief Build a new object-construction expression.
1473 ///
1474 /// By default, performs semantic analysis to build the new expression.
1475 /// Subclasses may override this routine to provide different behavior.
1476 OwningExprResult RebuildCXXConstructExpr(QualType T,
1477 CXXConstructorDecl *Constructor,
1478 bool IsElidable,
1479 MultiExprArg Args) {
Anders Carlsson1b4ebfa2009-09-05 07:40:38 +00001480 return getSema().BuildCXXConstructExpr(/*FIXME:ConstructLoc*/
1481 SourceLocation(),
1482 T, Constructor, IsElidable,
Anders Carlsson5995a3e2009-09-07 22:23:31 +00001483 move(Args));
Douglas Gregora16548e2009-08-11 05:31:07 +00001484 }
1485
1486 /// \brief Build a new object-construction expression.
1487 ///
1488 /// By default, performs semantic analysis to build the new expression.
1489 /// Subclasses may override this routine to provide different behavior.
1490 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1491 QualType T,
1492 SourceLocation LParenLoc,
1493 MultiExprArg Args,
1494 SourceLocation *Commas,
1495 SourceLocation RParenLoc) {
1496 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1497 T.getAsOpaquePtr(),
1498 LParenLoc,
1499 move(Args),
1500 Commas,
1501 RParenLoc);
1502 }
1503
1504 /// \brief Build a new object-construction expression.
1505 ///
1506 /// By default, performs semantic analysis to build the new expression.
1507 /// Subclasses may override this routine to provide different behavior.
1508 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1509 QualType T,
1510 SourceLocation LParenLoc,
1511 MultiExprArg Args,
1512 SourceLocation *Commas,
1513 SourceLocation RParenLoc) {
1514 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1515 /*FIXME*/LParenLoc),
1516 T.getAsOpaquePtr(),
1517 LParenLoc,
1518 move(Args),
1519 Commas,
1520 RParenLoc);
1521 }
Mike Stump11289f42009-09-09 15:08:12 +00001522
Douglas Gregora16548e2009-08-11 05:31:07 +00001523 /// \brief Build a new member reference expression.
1524 ///
1525 /// By default, performs semantic analysis to build the new expression.
1526 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001527 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 bool IsArrow,
1529 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001530 NestedNameSpecifier *Qualifier,
1531 SourceRange QualifierRange,
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001533 SourceLocation MemberLoc,
1534 NamedDecl *FirstQualifierInScope) {
Douglas Gregor2168a9f2009-08-11 15:56:57 +00001535 OwningExprResult Base = move(BaseE);
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001537
Douglas Gregora16548e2009-08-11 05:31:07 +00001538 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001539 SS.setRange(QualifierRange);
1540 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001541
Douglas Gregor308047d2009-09-09 00:23:06 +00001542 return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 move(Base), OperatorLoc, OpKind,
Douglas Gregorf14b46f2009-08-31 20:00:26 +00001544 MemberLoc,
1545 Name,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001546 /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001547 &SS,
1548 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00001549 }
1550
Douglas Gregor308047d2009-09-09 00:23:06 +00001551 /// \brief Build a new member reference expression with explicit template
1552 /// arguments.
1553 ///
1554 /// By default, performs semantic analysis to build the new expression.
1555 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001556 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
Douglas Gregor308047d2009-09-09 00:23:06 +00001557 bool IsArrow,
1558 SourceLocation OperatorLoc,
1559 NestedNameSpecifier *Qualifier,
1560 SourceRange QualifierRange,
1561 TemplateName Template,
1562 SourceLocation TemplateNameLoc,
1563 NamedDecl *FirstQualifierInScope,
John McCall6b51f282009-11-23 01:53:49 +00001564 const TemplateArgumentListInfo &TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001565 OwningExprResult Base = move(BaseE);
1566 tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period;
Mike Stump11289f42009-09-09 15:08:12 +00001567
Douglas Gregor308047d2009-09-09 00:23:06 +00001568 CXXScopeSpec SS;
1569 SS.setRange(QualifierRange);
1570 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001571
Douglas Gregor308047d2009-09-09 00:23:06 +00001572 // FIXME: We're going to end up looking up the template based on its name,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001573 // twice! Also, duplicates part of Sema::BuildMemberAccessExpr.
Douglas Gregor308047d2009-09-09 00:23:06 +00001574 DeclarationName Name;
1575 if (TemplateDecl *ActualTemplate = Template.getAsTemplateDecl())
1576 Name = ActualTemplate->getDeclName();
Mike Stump11289f42009-09-09 15:08:12 +00001577 else if (OverloadedFunctionDecl *Ovl
Douglas Gregor308047d2009-09-09 00:23:06 +00001578 = Template.getAsOverloadedFunctionDecl())
1579 Name = Ovl->getDeclName();
Douglas Gregor71395fa2009-11-04 00:56:37 +00001580 else {
1581 DependentTemplateName *DTN = Template.getAsDependentTemplateName();
1582 if (DTN->isIdentifier())
1583 Name = DTN->getIdentifier();
1584 else
1585 Name = SemaRef.Context.DeclarationNames.getCXXOperatorName(
1586 DTN->getOperator());
1587 }
John McCall6b51f282009-11-23 01:53:49 +00001588 return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0, move(Base),
1589 OperatorLoc, OpKind,
1590 TemplateNameLoc, Name,
1591 &TemplateArgs,
1592 Sema::DeclPtrTy(), &SS);
Douglas Gregor308047d2009-09-09 00:23:06 +00001593 }
Mike Stump11289f42009-09-09 15:08:12 +00001594
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 /// \brief Build a new Objective-C @encode expression.
1596 ///
1597 /// By default, performs semantic analysis to build the new expression.
1598 /// Subclasses may override this routine to provide different behavior.
1599 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1600 QualType T,
1601 SourceLocation RParenLoc) {
1602 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1603 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001604 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001605
1606 /// \brief Build a new Objective-C protocol 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 RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1611 SourceLocation AtLoc,
1612 SourceLocation ProtoLoc,
1613 SourceLocation LParenLoc,
1614 SourceLocation RParenLoc) {
1615 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1616 Protocol->getIdentifier(),
1617 AtLoc,
1618 ProtoLoc,
1619 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001620 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001621 }
Mike Stump11289f42009-09-09 15:08:12 +00001622
Douglas Gregora16548e2009-08-11 05:31:07 +00001623 /// \brief Build a new shuffle vector expression.
1624 ///
1625 /// By default, performs semantic analysis to build the new expression.
1626 /// Subclasses may override this routine to provide different behavior.
1627 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1628 MultiExprArg SubExprs,
1629 SourceLocation RParenLoc) {
1630 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001631 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1633 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1634 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1635 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001636
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 // Build a reference to the __builtin_shufflevector builtin
1638 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001639 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001641 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001643
1644 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 unsigned NumSubExprs = SubExprs.size();
1646 Expr **Subs = (Expr **)SubExprs.release();
1647 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1648 Subs, NumSubExprs,
1649 Builtin->getResultType(),
1650 RParenLoc);
1651 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001652
Douglas Gregora16548e2009-08-11 05:31:07 +00001653 // Type-check the __builtin_shufflevector expression.
1654 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1655 if (Result.isInvalid())
1656 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001657
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001659 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001661};
Douglas Gregora16548e2009-08-11 05:31:07 +00001662
Douglas Gregorebe10102009-08-20 07:17:43 +00001663template<typename Derived>
1664Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1665 if (!S)
1666 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001667
Douglas Gregorebe10102009-08-20 07:17:43 +00001668 switch (S->getStmtClass()) {
1669 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001670
Douglas Gregorebe10102009-08-20 07:17:43 +00001671 // Transform individual statement nodes
1672#define STMT(Node, Parent) \
1673 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1674#define EXPR(Node, Parent)
1675#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001676
Douglas Gregorebe10102009-08-20 07:17:43 +00001677 // Transform expressions by calling TransformExpr.
1678#define STMT(Node, Parent)
1679#define EXPR(Node, Parent) case Stmt::Node##Class:
1680#include "clang/AST/StmtNodes.def"
1681 {
1682 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1683 if (E.isInvalid())
1684 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001685
Douglas Gregor07eae022009-11-13 18:34:26 +00001686 return getSema().ActOnExprStmt(getSema().FullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001687 }
Mike Stump11289f42009-09-09 15:08:12 +00001688 }
1689
Douglas Gregorebe10102009-08-20 07:17:43 +00001690 return SemaRef.Owned(S->Retain());
1691}
Mike Stump11289f42009-09-09 15:08:12 +00001692
1693
Douglas Gregore922c772009-08-04 22:27:00 +00001694template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00001695Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E,
1696 bool isAddressOfOperand) {
1697 if (!E)
1698 return SemaRef.Owned(E);
1699
1700 switch (E->getStmtClass()) {
1701 case Stmt::NoStmtClass: break;
1702#define STMT(Node, Parent) case Stmt::Node##Class: break;
1703#define EXPR(Node, Parent) \
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00001704 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E), \
1705 isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001706#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001707 }
1708
Douglas Gregora16548e2009-08-11 05:31:07 +00001709 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001710}
1711
1712template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001713NestedNameSpecifier *
1714TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001715 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001716 QualType ObjectType,
1717 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001718 if (!NNS)
1719 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001720
Douglas Gregorebe10102009-08-20 07:17:43 +00001721 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001722 NestedNameSpecifier *Prefix = NNS->getPrefix();
1723 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001724 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001725 ObjectType,
1726 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001727 if (!Prefix)
1728 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001729
1730 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001731 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001732 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001733 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001734 }
Mike Stump11289f42009-09-09 15:08:12 +00001735
Douglas Gregor1135c352009-08-06 05:28:30 +00001736 switch (NNS->getKind()) {
1737 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001738 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001739 "Identifier nested-name-specifier with no prefix or object type");
1740 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1741 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001742 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001743
1744 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001745 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001746 ObjectType,
1747 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001748
Douglas Gregor1135c352009-08-06 05:28:30 +00001749 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001750 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001751 = cast_or_null<NamespaceDecl>(
1752 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001753 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001754 Prefix == NNS->getPrefix() &&
1755 NS == NNS->getAsNamespace())
1756 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001757
Douglas Gregor1135c352009-08-06 05:28:30 +00001758 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1759 }
Mike Stump11289f42009-09-09 15:08:12 +00001760
Douglas Gregor1135c352009-08-06 05:28:30 +00001761 case NestedNameSpecifier::Global:
1762 // There is no meaningful transformation that one could perform on the
1763 // global scope.
1764 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001765
Douglas Gregor1135c352009-08-06 05:28:30 +00001766 case NestedNameSpecifier::TypeSpecWithTemplate:
1767 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001768 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor1135c352009-08-06 05:28:30 +00001769 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001770 if (T.isNull())
1771 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001772
Douglas Gregor1135c352009-08-06 05:28:30 +00001773 if (!getDerived().AlwaysRebuild() &&
1774 Prefix == NNS->getPrefix() &&
1775 T == QualType(NNS->getAsType(), 0))
1776 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001777
1778 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1779 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregor1135c352009-08-06 05:28:30 +00001780 T);
1781 }
1782 }
Mike Stump11289f42009-09-09 15:08:12 +00001783
Douglas Gregor1135c352009-08-06 05:28:30 +00001784 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001785 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001786}
1787
1788template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001789DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001790TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001791 SourceLocation Loc,
1792 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001793 if (!Name)
1794 return Name;
1795
1796 switch (Name.getNameKind()) {
1797 case DeclarationName::Identifier:
1798 case DeclarationName::ObjCZeroArgSelector:
1799 case DeclarationName::ObjCOneArgSelector:
1800 case DeclarationName::ObjCMultiArgSelector:
1801 case DeclarationName::CXXOperatorName:
1802 case DeclarationName::CXXUsingDirective:
1803 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001804
Douglas Gregorf816bd72009-09-03 22:13:48 +00001805 case DeclarationName::CXXConstructorName:
1806 case DeclarationName::CXXDestructorName:
1807 case DeclarationName::CXXConversionFunctionName: {
1808 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorc59e5612009-10-19 22:04:39 +00001809 QualType T;
1810 if (!ObjectType.isNull() &&
1811 isa<TemplateSpecializationType>(Name.getCXXNameType())) {
1812 TemplateSpecializationType *SpecType
1813 = cast<TemplateSpecializationType>(Name.getCXXNameType());
1814 T = TransformTemplateSpecializationType(SpecType, ObjectType);
1815 } else
1816 T = getDerived().TransformType(Name.getCXXNameType());
Douglas Gregorf816bd72009-09-03 22:13:48 +00001817 if (T.isNull())
1818 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001819
Douglas Gregorf816bd72009-09-03 22:13:48 +00001820 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001821 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001822 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001823 }
Mike Stump11289f42009-09-09 15:08:12 +00001824 }
1825
Douglas Gregorf816bd72009-09-03 22:13:48 +00001826 return DeclarationName();
1827}
1828
1829template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001830TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001831TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1832 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00001833 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001834 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001835 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1836 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1837 if (!NNS)
1838 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001839
Douglas Gregor71dc5092009-08-06 06:41:21 +00001840 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001841 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001842 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1843 if (!TransTemplate)
1844 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001845
Douglas Gregor71dc5092009-08-06 06:41:21 +00001846 if (!getDerived().AlwaysRebuild() &&
1847 NNS == QTN->getQualifier() &&
1848 TransTemplate == Template)
1849 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001850
Douglas Gregor71dc5092009-08-06 06:41:21 +00001851 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1852 TransTemplate);
1853 }
Mike Stump11289f42009-09-09 15:08:12 +00001854
John McCalle66edc12009-11-24 19:00:30 +00001855 // These should be getting filtered out before they make it into the AST.
1856 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001857 }
Mike Stump11289f42009-09-09 15:08:12 +00001858
Douglas Gregor71dc5092009-08-06 06:41:21 +00001859 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001860 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001861 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1862 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor308047d2009-09-09 00:23:06 +00001863 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001864 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001865
Douglas Gregor71dc5092009-08-06 06:41:21 +00001866 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001867 NNS == DTN->getQualifier() &&
1868 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001869 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001870
Douglas Gregor71395fa2009-11-04 00:56:37 +00001871 if (DTN->isIdentifier())
1872 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1873 ObjectType);
1874
1875 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1876 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001877 }
Mike Stump11289f42009-09-09 15:08:12 +00001878
Douglas Gregor71dc5092009-08-06 06:41:21 +00001879 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001880 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001881 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1882 if (!TransTemplate)
1883 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001884
Douglas Gregor71dc5092009-08-06 06:41:21 +00001885 if (!getDerived().AlwaysRebuild() &&
1886 TransTemplate == Template)
1887 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001888
Douglas Gregor71dc5092009-08-06 06:41:21 +00001889 return TemplateName(TransTemplate);
1890 }
Mike Stump11289f42009-09-09 15:08:12 +00001891
John McCalle66edc12009-11-24 19:00:30 +00001892 // These should be getting filtered out before they reach the AST.
1893 assert(false && "overloaded function decl survived to here");
1894 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00001895}
1896
1897template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001898void TreeTransform<Derived>::InventTemplateArgumentLoc(
1899 const TemplateArgument &Arg,
1900 TemplateArgumentLoc &Output) {
1901 SourceLocation Loc = getDerived().getBaseLocation();
1902 switch (Arg.getKind()) {
1903 case TemplateArgument::Null:
1904 llvm::llvm_unreachable("null template argument in TreeTransform");
1905 break;
1906
1907 case TemplateArgument::Type:
1908 Output = TemplateArgumentLoc(Arg,
1909 SemaRef.Context.getTrivialDeclaratorInfo(Arg.getAsType(), Loc));
1910
1911 break;
1912
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001913 case TemplateArgument::Template:
1914 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1915 break;
1916
John McCall0ad16662009-10-29 08:12:44 +00001917 case TemplateArgument::Expression:
1918 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1919 break;
1920
1921 case TemplateArgument::Declaration:
1922 case TemplateArgument::Integral:
1923 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00001924 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00001925 break;
1926 }
1927}
1928
1929template<typename Derived>
1930bool TreeTransform<Derived>::TransformTemplateArgument(
1931 const TemplateArgumentLoc &Input,
1932 TemplateArgumentLoc &Output) {
1933 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00001934 switch (Arg.getKind()) {
1935 case TemplateArgument::Null:
1936 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001937 Output = Input;
1938 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001939
Douglas Gregore922c772009-08-04 22:27:00 +00001940 case TemplateArgument::Type: {
John McCall0ad16662009-10-29 08:12:44 +00001941 DeclaratorInfo *DI = Input.getSourceDeclaratorInfo();
1942 if (DI == NULL)
1943 DI = InventDeclaratorInfo(Input.getArgument().getAsType());
1944
1945 DI = getDerived().TransformType(DI);
1946 if (!DI) return true;
1947
1948 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1949 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001950 }
Mike Stump11289f42009-09-09 15:08:12 +00001951
Douglas Gregore922c772009-08-04 22:27:00 +00001952 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001953 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001954 DeclarationName Name;
1955 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1956 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001957 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregore922c772009-08-04 22:27:00 +00001958 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001959 if (!D) return true;
1960
John McCall0d07eb32009-10-29 18:45:58 +00001961 Expr *SourceExpr = Input.getSourceDeclExpression();
1962 if (SourceExpr) {
1963 EnterExpressionEvaluationContext Unevaluated(getSema(),
1964 Action::Unevaluated);
1965 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1966 if (E.isInvalid())
1967 SourceExpr = NULL;
1968 else {
1969 SourceExpr = E.takeAs<Expr>();
1970 SourceExpr->Retain();
1971 }
1972 }
1973
1974 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00001975 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001976 }
Mike Stump11289f42009-09-09 15:08:12 +00001977
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001978 case TemplateArgument::Template: {
1979 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1980 TemplateName Template
1981 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1982 if (Template.isNull())
1983 return true;
1984
1985 Output = TemplateArgumentLoc(TemplateArgument(Template),
1986 Input.getTemplateQualifierRange(),
1987 Input.getTemplateNameLoc());
1988 return false;
1989 }
1990
Douglas Gregore922c772009-08-04 22:27:00 +00001991 case TemplateArgument::Expression: {
1992 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00001993 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00001994 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00001995
John McCall0ad16662009-10-29 08:12:44 +00001996 Expr *InputExpr = Input.getSourceExpression();
1997 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
1998
1999 Sema::OwningExprResult E
2000 = getDerived().TransformExpr(InputExpr);
2001 if (E.isInvalid()) return true;
2002
2003 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002004 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002005 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2006 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002007 }
Mike Stump11289f42009-09-09 15:08:12 +00002008
Douglas Gregore922c772009-08-04 22:27:00 +00002009 case TemplateArgument::Pack: {
2010 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2011 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002012 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002013 AEnd = Arg.pack_end();
2014 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002015
John McCall0ad16662009-10-29 08:12:44 +00002016 // FIXME: preserve source information here when we start
2017 // caring about parameter packs.
2018
John McCall0d07eb32009-10-29 18:45:58 +00002019 TemplateArgumentLoc InputArg;
2020 TemplateArgumentLoc OutputArg;
2021 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2022 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002023 return true;
2024
John McCall0d07eb32009-10-29 18:45:58 +00002025 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002026 }
2027 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002028 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002029 true);
John McCall0d07eb32009-10-29 18:45:58 +00002030 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002031 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002032 }
2033 }
Mike Stump11289f42009-09-09 15:08:12 +00002034
Douglas Gregore922c772009-08-04 22:27:00 +00002035 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002036 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002037}
2038
Douglas Gregord6ff3322009-08-04 16:50:30 +00002039//===----------------------------------------------------------------------===//
2040// Type transformation
2041//===----------------------------------------------------------------------===//
2042
2043template<typename Derived>
2044QualType TreeTransform<Derived>::TransformType(QualType T) {
2045 if (getDerived().AlreadyTransformed(T))
2046 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002047
John McCall550e0c22009-10-21 00:40:46 +00002048 // Temporary workaround. All of these transformations should
2049 // eventually turn into transformations on TypeLocs.
2050 DeclaratorInfo *DI = getSema().Context.CreateDeclaratorInfo(T);
John McCallde889892009-10-21 00:44:26 +00002051 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002052
2053 DeclaratorInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002054
John McCall550e0c22009-10-21 00:40:46 +00002055 if (!NewDI)
2056 return QualType();
2057
2058 return NewDI->getType();
2059}
2060
2061template<typename Derived>
2062DeclaratorInfo *TreeTransform<Derived>::TransformType(DeclaratorInfo *DI) {
2063 if (getDerived().AlreadyTransformed(DI->getType()))
2064 return DI;
2065
2066 TypeLocBuilder TLB;
2067
2068 TypeLoc TL = DI->getTypeLoc();
2069 TLB.reserve(TL.getFullDataSize());
2070
2071 QualType Result = getDerived().TransformType(TLB, TL);
2072 if (Result.isNull())
2073 return 0;
2074
2075 return TLB.getDeclaratorInfo(SemaRef.Context, Result);
2076}
2077
2078template<typename Derived>
2079QualType
2080TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
2081 switch (T.getTypeLocClass()) {
2082#define ABSTRACT_TYPELOC(CLASS, PARENT)
2083#define TYPELOC(CLASS, PARENT) \
2084 case TypeLoc::CLASS: \
2085 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2086#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002087 }
Mike Stump11289f42009-09-09 15:08:12 +00002088
John McCall550e0c22009-10-21 00:40:46 +00002089 llvm::llvm_unreachable("unhandled type loc!");
2090 return QualType();
2091}
2092
2093/// FIXME: By default, this routine adds type qualifiers only to types
2094/// that can have qualifiers, and silently suppresses those qualifiers
2095/// that are not permitted (e.g., qualifiers on reference or function
2096/// types). This is the right thing for template instantiation, but
2097/// probably not for other clients.
2098template<typename Derived>
2099QualType
2100TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
2101 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002102 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002103
2104 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2105 if (Result.isNull())
2106 return QualType();
2107
2108 // Silently suppress qualifiers if the result type can't be qualified.
2109 // FIXME: this is the right thing for template instantiation, but
2110 // probably not for other clients.
2111 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002112 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002113
John McCall550e0c22009-10-21 00:40:46 +00002114 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2115
2116 TLB.push<QualifiedTypeLoc>(Result);
2117
2118 // No location information to preserve.
2119
2120 return Result;
2121}
2122
2123template <class TyLoc> static inline
2124QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2125 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2126 NewT.setNameLoc(T.getNameLoc());
2127 return T.getType();
2128}
2129
2130// Ugly metaprogramming macros because I couldn't be bothered to make
2131// the equivalent template version work.
2132#define TransformPointerLikeType(TypeClass) do { \
2133 QualType PointeeType \
2134 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2135 if (PointeeType.isNull()) \
2136 return QualType(); \
2137 \
2138 QualType Result = TL.getType(); \
2139 if (getDerived().AlwaysRebuild() || \
2140 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall70dd5f62009-10-30 00:06:24 +00002141 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2142 TL.getSigilLoc()); \
John McCall550e0c22009-10-21 00:40:46 +00002143 if (Result.isNull()) \
2144 return QualType(); \
2145 } \
2146 \
2147 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2148 NewT.setSigilLoc(TL.getSigilLoc()); \
2149 \
2150 return Result; \
2151} while(0)
2152
John McCall550e0c22009-10-21 00:40:46 +00002153template<typename Derived>
2154QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
2155 BuiltinTypeLoc T) {
2156 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002157}
Mike Stump11289f42009-09-09 15:08:12 +00002158
Douglas Gregord6ff3322009-08-04 16:50:30 +00002159template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002160QualType
John McCall550e0c22009-10-21 00:40:46 +00002161TreeTransform<Derived>::TransformFixedWidthIntType(TypeLocBuilder &TLB,
2162 FixedWidthIntTypeLoc T) {
2163 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002164}
Argyrios Kyrtzidise9189262009-08-19 01:28:17 +00002165
Douglas Gregord6ff3322009-08-04 16:50:30 +00002166template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002167QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
2168 ComplexTypeLoc T) {
2169 // FIXME: recurse?
2170 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002171}
Mike Stump11289f42009-09-09 15:08:12 +00002172
Douglas Gregord6ff3322009-08-04 16:50:30 +00002173template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002174QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
2175 PointerTypeLoc TL) {
2176 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002177}
Mike Stump11289f42009-09-09 15:08:12 +00002178
2179template<typename Derived>
2180QualType
John McCall550e0c22009-10-21 00:40:46 +00002181TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
2182 BlockPointerTypeLoc TL) {
2183 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002184}
2185
John McCall70dd5f62009-10-30 00:06:24 +00002186/// Transforms a reference type. Note that somewhat paradoxically we
2187/// don't care whether the type itself is an l-value type or an r-value
2188/// type; we only care if the type was *written* as an l-value type
2189/// or an r-value type.
2190template<typename Derived>
2191QualType
2192TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
2193 ReferenceTypeLoc TL) {
2194 const ReferenceType *T = TL.getTypePtr();
2195
2196 // Note that this works with the pointee-as-written.
2197 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2198 if (PointeeType.isNull())
2199 return QualType();
2200
2201 QualType Result = TL.getType();
2202 if (getDerived().AlwaysRebuild() ||
2203 PointeeType != T->getPointeeTypeAsWritten()) {
2204 Result = getDerived().RebuildReferenceType(PointeeType,
2205 T->isSpelledAsLValue(),
2206 TL.getSigilLoc());
2207 if (Result.isNull())
2208 return QualType();
2209 }
2210
2211 // r-value references can be rebuilt as l-value references.
2212 ReferenceTypeLoc NewTL;
2213 if (isa<LValueReferenceType>(Result))
2214 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2215 else
2216 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2217 NewTL.setSigilLoc(TL.getSigilLoc());
2218
2219 return Result;
2220}
2221
Mike Stump11289f42009-09-09 15:08:12 +00002222template<typename Derived>
2223QualType
John McCall550e0c22009-10-21 00:40:46 +00002224TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
2225 LValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002226 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002227}
2228
Mike Stump11289f42009-09-09 15:08:12 +00002229template<typename Derived>
2230QualType
John McCall550e0c22009-10-21 00:40:46 +00002231TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
2232 RValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002233 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002234}
Mike Stump11289f42009-09-09 15:08:12 +00002235
Douglas Gregord6ff3322009-08-04 16:50:30 +00002236template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002237QualType
John McCall550e0c22009-10-21 00:40:46 +00002238TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
2239 MemberPointerTypeLoc TL) {
2240 MemberPointerType *T = TL.getTypePtr();
2241
2242 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002243 if (PointeeType.isNull())
2244 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002245
John McCall550e0c22009-10-21 00:40:46 +00002246 // TODO: preserve source information for this.
2247 QualType ClassType
2248 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002249 if (ClassType.isNull())
2250 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002251
John McCall550e0c22009-10-21 00:40:46 +00002252 QualType Result = TL.getType();
2253 if (getDerived().AlwaysRebuild() ||
2254 PointeeType != T->getPointeeType() ||
2255 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002256 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2257 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002258 if (Result.isNull())
2259 return QualType();
2260 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002261
John McCall550e0c22009-10-21 00:40:46 +00002262 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2263 NewTL.setSigilLoc(TL.getSigilLoc());
2264
2265 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002266}
2267
Mike Stump11289f42009-09-09 15:08:12 +00002268template<typename Derived>
2269QualType
John McCall550e0c22009-10-21 00:40:46 +00002270TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
2271 ConstantArrayTypeLoc TL) {
2272 ConstantArrayType *T = TL.getTypePtr();
2273 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002274 if (ElementType.isNull())
2275 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002276
John McCall550e0c22009-10-21 00:40:46 +00002277 QualType Result = TL.getType();
2278 if (getDerived().AlwaysRebuild() ||
2279 ElementType != T->getElementType()) {
2280 Result = getDerived().RebuildConstantArrayType(ElementType,
2281 T->getSizeModifier(),
2282 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002283 T->getIndexTypeCVRQualifiers(),
2284 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002285 if (Result.isNull())
2286 return QualType();
2287 }
2288
2289 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2290 NewTL.setLBracketLoc(TL.getLBracketLoc());
2291 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002292
John McCall550e0c22009-10-21 00:40:46 +00002293 Expr *Size = TL.getSizeExpr();
2294 if (Size) {
2295 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2296 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2297 }
2298 NewTL.setSizeExpr(Size);
2299
2300 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002301}
Mike Stump11289f42009-09-09 15:08:12 +00002302
Douglas Gregord6ff3322009-08-04 16:50:30 +00002303template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002304QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002305 TypeLocBuilder &TLB,
2306 IncompleteArrayTypeLoc TL) {
2307 IncompleteArrayType *T = TL.getTypePtr();
2308 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002309 if (ElementType.isNull())
2310 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002311
John McCall550e0c22009-10-21 00:40:46 +00002312 QualType Result = TL.getType();
2313 if (getDerived().AlwaysRebuild() ||
2314 ElementType != T->getElementType()) {
2315 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002316 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002317 T->getIndexTypeCVRQualifiers(),
2318 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002319 if (Result.isNull())
2320 return QualType();
2321 }
2322
2323 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2324 NewTL.setLBracketLoc(TL.getLBracketLoc());
2325 NewTL.setRBracketLoc(TL.getRBracketLoc());
2326 NewTL.setSizeExpr(0);
2327
2328 return Result;
2329}
2330
2331template<typename Derived>
2332QualType
2333TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
2334 VariableArrayTypeLoc TL) {
2335 VariableArrayType *T = TL.getTypePtr();
2336 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2337 if (ElementType.isNull())
2338 return QualType();
2339
2340 // Array bounds are not potentially evaluated contexts
2341 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2342
2343 Sema::OwningExprResult SizeResult
2344 = getDerived().TransformExpr(T->getSizeExpr());
2345 if (SizeResult.isInvalid())
2346 return QualType();
2347
2348 Expr *Size = static_cast<Expr*>(SizeResult.get());
2349
2350 QualType Result = TL.getType();
2351 if (getDerived().AlwaysRebuild() ||
2352 ElementType != T->getElementType() ||
2353 Size != T->getSizeExpr()) {
2354 Result = getDerived().RebuildVariableArrayType(ElementType,
2355 T->getSizeModifier(),
2356 move(SizeResult),
2357 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002358 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002359 if (Result.isNull())
2360 return QualType();
2361 }
2362 else SizeResult.take();
2363
2364 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2365 NewTL.setLBracketLoc(TL.getLBracketLoc());
2366 NewTL.setRBracketLoc(TL.getRBracketLoc());
2367 NewTL.setSizeExpr(Size);
2368
2369 return Result;
2370}
2371
2372template<typename Derived>
2373QualType
2374TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
2375 DependentSizedArrayTypeLoc TL) {
2376 DependentSizedArrayType *T = TL.getTypePtr();
2377 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2378 if (ElementType.isNull())
2379 return QualType();
2380
2381 // Array bounds are not potentially evaluated contexts
2382 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2383
2384 Sema::OwningExprResult SizeResult
2385 = getDerived().TransformExpr(T->getSizeExpr());
2386 if (SizeResult.isInvalid())
2387 return QualType();
2388
2389 Expr *Size = static_cast<Expr*>(SizeResult.get());
2390
2391 QualType Result = TL.getType();
2392 if (getDerived().AlwaysRebuild() ||
2393 ElementType != T->getElementType() ||
2394 Size != T->getSizeExpr()) {
2395 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2396 T->getSizeModifier(),
2397 move(SizeResult),
2398 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002399 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002400 if (Result.isNull())
2401 return QualType();
2402 }
2403 else SizeResult.take();
2404
2405 // We might have any sort of array type now, but fortunately they
2406 // all have the same location layout.
2407 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2408 NewTL.setLBracketLoc(TL.getLBracketLoc());
2409 NewTL.setRBracketLoc(TL.getRBracketLoc());
2410 NewTL.setSizeExpr(Size);
2411
2412 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002413}
Mike Stump11289f42009-09-09 15:08:12 +00002414
2415template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002416QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002417 TypeLocBuilder &TLB,
2418 DependentSizedExtVectorTypeLoc TL) {
2419 DependentSizedExtVectorType *T = TL.getTypePtr();
2420
2421 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002422 QualType ElementType = getDerived().TransformType(T->getElementType());
2423 if (ElementType.isNull())
2424 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002425
Douglas Gregore922c772009-08-04 22:27:00 +00002426 // Vector sizes are not potentially evaluated contexts
2427 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2428
Douglas Gregord6ff3322009-08-04 16:50:30 +00002429 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2430 if (Size.isInvalid())
2431 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002432
John McCall550e0c22009-10-21 00:40:46 +00002433 QualType Result = TL.getType();
2434 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002435 ElementType != T->getElementType() ||
2436 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002437 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002438 move(Size),
2439 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002440 if (Result.isNull())
2441 return QualType();
2442 }
2443 else Size.take();
2444
2445 // Result might be dependent or not.
2446 if (isa<DependentSizedExtVectorType>(Result)) {
2447 DependentSizedExtVectorTypeLoc NewTL
2448 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2449 NewTL.setNameLoc(TL.getNameLoc());
2450 } else {
2451 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2452 NewTL.setNameLoc(TL.getNameLoc());
2453 }
2454
2455 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002456}
Mike Stump11289f42009-09-09 15:08:12 +00002457
2458template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002459QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
2460 VectorTypeLoc TL) {
2461 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002462 QualType ElementType = getDerived().TransformType(T->getElementType());
2463 if (ElementType.isNull())
2464 return QualType();
2465
John McCall550e0c22009-10-21 00:40:46 +00002466 QualType Result = TL.getType();
2467 if (getDerived().AlwaysRebuild() ||
2468 ElementType != T->getElementType()) {
2469 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements());
2470 if (Result.isNull())
2471 return QualType();
2472 }
2473
2474 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2475 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002476
John McCall550e0c22009-10-21 00:40:46 +00002477 return Result;
2478}
2479
2480template<typename Derived>
2481QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
2482 ExtVectorTypeLoc TL) {
2483 VectorType *T = TL.getTypePtr();
2484 QualType ElementType = getDerived().TransformType(T->getElementType());
2485 if (ElementType.isNull())
2486 return QualType();
2487
2488 QualType Result = TL.getType();
2489 if (getDerived().AlwaysRebuild() ||
2490 ElementType != T->getElementType()) {
2491 Result = getDerived().RebuildExtVectorType(ElementType,
2492 T->getNumElements(),
2493 /*FIXME*/ SourceLocation());
2494 if (Result.isNull())
2495 return QualType();
2496 }
2497
2498 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2499 NewTL.setNameLoc(TL.getNameLoc());
2500
2501 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002502}
Mike Stump11289f42009-09-09 15:08:12 +00002503
2504template<typename Derived>
2505QualType
John McCall550e0c22009-10-21 00:40:46 +00002506TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
2507 FunctionProtoTypeLoc TL) {
2508 FunctionProtoType *T = TL.getTypePtr();
2509 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002510 if (ResultType.isNull())
2511 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002512
John McCall550e0c22009-10-21 00:40:46 +00002513 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002514 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002515 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2516 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2517 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump11289f42009-09-09 15:08:12 +00002518
John McCall550e0c22009-10-21 00:40:46 +00002519 QualType NewType;
2520 ParmVarDecl *NewParm;
2521
2522 if (OldParm) {
2523 DeclaratorInfo *OldDI = OldParm->getDeclaratorInfo();
2524 assert(OldDI->getType() == T->getArgType(i));
2525
2526 DeclaratorInfo *NewDI = getDerived().TransformType(OldDI);
2527 if (!NewDI)
2528 return QualType();
2529
2530 if (NewDI == OldDI)
2531 NewParm = OldParm;
2532 else
2533 NewParm = ParmVarDecl::Create(SemaRef.Context,
2534 OldParm->getDeclContext(),
2535 OldParm->getLocation(),
2536 OldParm->getIdentifier(),
2537 NewDI->getType(),
2538 NewDI,
2539 OldParm->getStorageClass(),
2540 /* DefArg */ NULL);
2541 NewType = NewParm->getType();
2542
2543 // Deal with the possibility that we don't have a parameter
2544 // declaration for this parameter.
2545 } else {
2546 NewParm = 0;
2547
2548 QualType OldType = T->getArgType(i);
2549 NewType = getDerived().TransformType(OldType);
2550 if (NewType.isNull())
2551 return QualType();
2552 }
2553
2554 ParamTypes.push_back(NewType);
2555 ParamDecls.push_back(NewParm);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002556 }
Mike Stump11289f42009-09-09 15:08:12 +00002557
John McCall550e0c22009-10-21 00:40:46 +00002558 QualType Result = TL.getType();
2559 if (getDerived().AlwaysRebuild() ||
2560 ResultType != T->getResultType() ||
2561 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2562 Result = getDerived().RebuildFunctionProtoType(ResultType,
2563 ParamTypes.data(),
2564 ParamTypes.size(),
2565 T->isVariadic(),
2566 T->getTypeQuals());
2567 if (Result.isNull())
2568 return QualType();
2569 }
Mike Stump11289f42009-09-09 15:08:12 +00002570
John McCall550e0c22009-10-21 00:40:46 +00002571 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2572 NewTL.setLParenLoc(TL.getLParenLoc());
2573 NewTL.setRParenLoc(TL.getRParenLoc());
2574 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2575 NewTL.setArg(i, ParamDecls[i]);
2576
2577 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002578}
Mike Stump11289f42009-09-09 15:08:12 +00002579
Douglas Gregord6ff3322009-08-04 16:50:30 +00002580template<typename Derived>
2581QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002582 TypeLocBuilder &TLB,
2583 FunctionNoProtoTypeLoc TL) {
2584 FunctionNoProtoType *T = TL.getTypePtr();
2585 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2586 if (ResultType.isNull())
2587 return QualType();
2588
2589 QualType Result = TL.getType();
2590 if (getDerived().AlwaysRebuild() ||
2591 ResultType != T->getResultType())
2592 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2593
2594 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2595 NewTL.setLParenLoc(TL.getLParenLoc());
2596 NewTL.setRParenLoc(TL.getRParenLoc());
2597
2598 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002599}
Mike Stump11289f42009-09-09 15:08:12 +00002600
Douglas Gregord6ff3322009-08-04 16:50:30 +00002601template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002602QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
2603 TypedefTypeLoc TL) {
2604 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002605 TypedefDecl *Typedef
2606 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2607 if (!Typedef)
2608 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002609
John McCall550e0c22009-10-21 00:40:46 +00002610 QualType Result = TL.getType();
2611 if (getDerived().AlwaysRebuild() ||
2612 Typedef != T->getDecl()) {
2613 Result = getDerived().RebuildTypedefType(Typedef);
2614 if (Result.isNull())
2615 return QualType();
2616 }
Mike Stump11289f42009-09-09 15:08:12 +00002617
John McCall550e0c22009-10-21 00:40:46 +00002618 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2619 NewTL.setNameLoc(TL.getNameLoc());
2620
2621 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002622}
Mike Stump11289f42009-09-09 15:08:12 +00002623
Douglas Gregord6ff3322009-08-04 16:50:30 +00002624template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002625QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
2626 TypeOfExprTypeLoc TL) {
2627 TypeOfExprType *T = TL.getTypePtr();
2628
Douglas Gregore922c772009-08-04 22:27:00 +00002629 // typeof expressions are not potentially evaluated contexts
2630 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002631
Douglas Gregord6ff3322009-08-04 16:50:30 +00002632 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2633 if (E.isInvalid())
2634 return QualType();
2635
John McCall550e0c22009-10-21 00:40:46 +00002636 QualType Result = TL.getType();
2637 if (getDerived().AlwaysRebuild() ||
2638 E.get() != T->getUnderlyingExpr()) {
2639 Result = getDerived().RebuildTypeOfExprType(move(E));
2640 if (Result.isNull())
2641 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002642 }
John McCall550e0c22009-10-21 00:40:46 +00002643 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002644
John McCall550e0c22009-10-21 00:40:46 +00002645 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
2646 NewTL.setNameLoc(TL.getNameLoc());
2647
2648 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002649}
Mike Stump11289f42009-09-09 15:08:12 +00002650
2651template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002652QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
2653 TypeOfTypeLoc TL) {
2654 TypeOfType *T = TL.getTypePtr();
2655
2656 // FIXME: should be an inner type, or at least have a DeclaratorInfo.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002657 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2658 if (Underlying.isNull())
2659 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002660
John McCall550e0c22009-10-21 00:40:46 +00002661 QualType Result = TL.getType();
2662 if (getDerived().AlwaysRebuild() ||
2663 Underlying != T->getUnderlyingType()) {
2664 Result = getDerived().RebuildTypeOfType(Underlying);
2665 if (Result.isNull())
2666 return QualType();
2667 }
Mike Stump11289f42009-09-09 15:08:12 +00002668
John McCall550e0c22009-10-21 00:40:46 +00002669 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
2670 NewTL.setNameLoc(TL.getNameLoc());
2671
2672 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002673}
Mike Stump11289f42009-09-09 15:08:12 +00002674
2675template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002676QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
2677 DecltypeTypeLoc TL) {
2678 DecltypeType *T = TL.getTypePtr();
2679
Douglas Gregore922c772009-08-04 22:27:00 +00002680 // decltype expressions are not potentially evaluated contexts
2681 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002682
Douglas Gregord6ff3322009-08-04 16:50:30 +00002683 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2684 if (E.isInvalid())
2685 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002686
John McCall550e0c22009-10-21 00:40:46 +00002687 QualType Result = TL.getType();
2688 if (getDerived().AlwaysRebuild() ||
2689 E.get() != T->getUnderlyingExpr()) {
2690 Result = getDerived().RebuildDecltypeType(move(E));
2691 if (Result.isNull())
2692 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002693 }
John McCall550e0c22009-10-21 00:40:46 +00002694 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002695
John McCall550e0c22009-10-21 00:40:46 +00002696 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2697 NewTL.setNameLoc(TL.getNameLoc());
2698
2699 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002700}
2701
2702template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002703QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
2704 RecordTypeLoc TL) {
2705 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002706 RecordDecl *Record
John McCall550e0c22009-10-21 00:40:46 +00002707 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002708 if (!Record)
2709 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002710
John McCall550e0c22009-10-21 00:40:46 +00002711 QualType Result = TL.getType();
2712 if (getDerived().AlwaysRebuild() ||
2713 Record != T->getDecl()) {
2714 Result = getDerived().RebuildRecordType(Record);
2715 if (Result.isNull())
2716 return QualType();
2717 }
Mike Stump11289f42009-09-09 15:08:12 +00002718
John McCall550e0c22009-10-21 00:40:46 +00002719 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2720 NewTL.setNameLoc(TL.getNameLoc());
2721
2722 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002723}
Mike Stump11289f42009-09-09 15:08:12 +00002724
2725template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002726QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
2727 EnumTypeLoc TL) {
2728 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002729 EnumDecl *Enum
John McCall550e0c22009-10-21 00:40:46 +00002730 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002731 if (!Enum)
2732 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002733
John McCall550e0c22009-10-21 00:40:46 +00002734 QualType Result = TL.getType();
2735 if (getDerived().AlwaysRebuild() ||
2736 Enum != T->getDecl()) {
2737 Result = getDerived().RebuildEnumType(Enum);
2738 if (Result.isNull())
2739 return QualType();
2740 }
Mike Stump11289f42009-09-09 15:08:12 +00002741
John McCall550e0c22009-10-21 00:40:46 +00002742 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2743 NewTL.setNameLoc(TL.getNameLoc());
2744
2745 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002746}
John McCallfcc33b02009-09-05 00:15:47 +00002747
2748template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002749QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
2750 ElaboratedTypeLoc TL) {
2751 ElaboratedType *T = TL.getTypePtr();
2752
2753 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002754 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2755 if (Underlying.isNull())
2756 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002757
John McCall550e0c22009-10-21 00:40:46 +00002758 QualType Result = TL.getType();
2759 if (getDerived().AlwaysRebuild() ||
2760 Underlying != T->getUnderlyingType()) {
2761 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2762 if (Result.isNull())
2763 return QualType();
2764 }
Mike Stump11289f42009-09-09 15:08:12 +00002765
John McCall550e0c22009-10-21 00:40:46 +00002766 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2767 NewTL.setNameLoc(TL.getNameLoc());
2768
2769 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002770}
Mike Stump11289f42009-09-09 15:08:12 +00002771
2772
Douglas Gregord6ff3322009-08-04 16:50:30 +00002773template<typename Derived>
2774QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002775 TypeLocBuilder &TLB,
2776 TemplateTypeParmTypeLoc TL) {
2777 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002778}
2779
Mike Stump11289f42009-09-09 15:08:12 +00002780template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002781QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002782 TypeLocBuilder &TLB,
2783 SubstTemplateTypeParmTypeLoc TL) {
2784 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002785}
2786
2787template<typename Derived>
Douglas Gregorc59e5612009-10-19 22:04:39 +00002788inline QualType
2789TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall550e0c22009-10-21 00:40:46 +00002790 TypeLocBuilder &TLB,
2791 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00002792 return TransformTemplateSpecializationType(TLB, TL, QualType());
2793}
John McCall550e0c22009-10-21 00:40:46 +00002794
John McCall0ad16662009-10-29 08:12:44 +00002795template<typename Derived>
2796QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2797 const TemplateSpecializationType *TST,
2798 QualType ObjectType) {
2799 // FIXME: this entire method is a temporary workaround; callers
2800 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00002801
John McCall0ad16662009-10-29 08:12:44 +00002802 // Fake up a TemplateSpecializationTypeLoc.
2803 TypeLocBuilder TLB;
2804 TemplateSpecializationTypeLoc TL
2805 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2806
John McCall0d07eb32009-10-29 18:45:58 +00002807 SourceLocation BaseLoc = getDerived().getBaseLocation();
2808
2809 TL.setTemplateNameLoc(BaseLoc);
2810 TL.setLAngleLoc(BaseLoc);
2811 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00002812 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2813 const TemplateArgument &TA = TST->getArg(i);
2814 TemplateArgumentLoc TAL;
2815 getDerived().InventTemplateArgumentLoc(TA, TAL);
2816 TL.setArgLocInfo(i, TAL.getLocInfo());
2817 }
2818
2819 TypeLocBuilder IgnoredTLB;
2820 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00002821}
2822
2823template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002824QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00002825 TypeLocBuilder &TLB,
2826 TemplateSpecializationTypeLoc TL,
2827 QualType ObjectType) {
2828 const TemplateSpecializationType *T = TL.getTypePtr();
2829
Mike Stump11289f42009-09-09 15:08:12 +00002830 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002831 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002832 if (Template.isNull())
2833 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002834
John McCall6b51f282009-11-23 01:53:49 +00002835 TemplateArgumentListInfo NewTemplateArgs;
2836 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2837 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2838
2839 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2840 TemplateArgumentLoc Loc;
2841 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00002842 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00002843 NewTemplateArgs.addArgument(Loc);
2844 }
Mike Stump11289f42009-09-09 15:08:12 +00002845
John McCall0ad16662009-10-29 08:12:44 +00002846 // FIXME: maybe don't rebuild if all the template arguments are the same.
2847
2848 QualType Result =
2849 getDerived().RebuildTemplateSpecializationType(Template,
2850 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00002851 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00002852
2853 if (!Result.isNull()) {
2854 TemplateSpecializationTypeLoc NewTL
2855 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2856 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2857 NewTL.setLAngleLoc(TL.getLAngleLoc());
2858 NewTL.setRAngleLoc(TL.getRAngleLoc());
2859 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2860 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002861 }
Mike Stump11289f42009-09-09 15:08:12 +00002862
John McCall0ad16662009-10-29 08:12:44 +00002863 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002864}
Mike Stump11289f42009-09-09 15:08:12 +00002865
2866template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002867QualType
2868TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
2869 QualifiedNameTypeLoc TL) {
2870 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002871 NestedNameSpecifier *NNS
2872 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2873 SourceRange());
2874 if (!NNS)
2875 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002876
Douglas Gregord6ff3322009-08-04 16:50:30 +00002877 QualType Named = getDerived().TransformType(T->getNamedType());
2878 if (Named.isNull())
2879 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002880
John McCall550e0c22009-10-21 00:40:46 +00002881 QualType Result = TL.getType();
2882 if (getDerived().AlwaysRebuild() ||
2883 NNS != T->getQualifier() ||
2884 Named != T->getNamedType()) {
2885 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2886 if (Result.isNull())
2887 return QualType();
2888 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002889
John McCall550e0c22009-10-21 00:40:46 +00002890 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2891 NewTL.setNameLoc(TL.getNameLoc());
2892
2893 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002894}
Mike Stump11289f42009-09-09 15:08:12 +00002895
2896template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002897QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
2898 TypenameTypeLoc TL) {
2899 TypenameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00002900
2901 /* FIXME: preserve source information better than this */
2902 SourceRange SR(TL.getNameLoc());
2903
Douglas Gregord6ff3322009-08-04 16:50:30 +00002904 NestedNameSpecifier *NNS
John McCall0ad16662009-10-29 08:12:44 +00002905 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002906 if (!NNS)
2907 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002908
John McCall550e0c22009-10-21 00:40:46 +00002909 QualType Result;
2910
Douglas Gregord6ff3322009-08-04 16:50:30 +00002911 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002912 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002913 = getDerived().TransformType(QualType(TemplateId, 0));
2914 if (NewTemplateId.isNull())
2915 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002916
Douglas Gregord6ff3322009-08-04 16:50:30 +00002917 if (!getDerived().AlwaysRebuild() &&
2918 NNS == T->getQualifier() &&
2919 NewTemplateId == QualType(TemplateId, 0))
2920 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002921
John McCall550e0c22009-10-21 00:40:46 +00002922 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2923 } else {
John McCall0ad16662009-10-29 08:12:44 +00002924 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002925 }
John McCall550e0c22009-10-21 00:40:46 +00002926 if (Result.isNull())
2927 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002928
John McCall550e0c22009-10-21 00:40:46 +00002929 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2930 NewTL.setNameLoc(TL.getNameLoc());
2931
2932 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002933}
Mike Stump11289f42009-09-09 15:08:12 +00002934
Douglas Gregord6ff3322009-08-04 16:50:30 +00002935template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002936QualType
2937TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
2938 ObjCInterfaceTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002939 assert(false && "TransformObjCInterfaceType unimplemented");
2940 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002941}
Mike Stump11289f42009-09-09 15:08:12 +00002942
2943template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002944QualType
2945TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
2946 ObjCObjectPointerTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002947 assert(false && "TransformObjCObjectPointerType unimplemented");
2948 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00002949}
2950
Douglas Gregord6ff3322009-08-04 16:50:30 +00002951//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00002952// Statement transformation
2953//===----------------------------------------------------------------------===//
2954template<typename Derived>
2955Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002956TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2957 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002958}
2959
2960template<typename Derived>
2961Sema::OwningStmtResult
2962TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2963 return getDerived().TransformCompoundStmt(S, false);
2964}
2965
2966template<typename Derived>
2967Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002968TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00002969 bool IsStmtExpr) {
2970 bool SubStmtChanged = false;
2971 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
2972 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
2973 B != BEnd; ++B) {
2974 OwningStmtResult Result = getDerived().TransformStmt(*B);
2975 if (Result.isInvalid())
2976 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002977
Douglas Gregorebe10102009-08-20 07:17:43 +00002978 SubStmtChanged = SubStmtChanged || Result.get() != *B;
2979 Statements.push_back(Result.takeAs<Stmt>());
2980 }
Mike Stump11289f42009-09-09 15:08:12 +00002981
Douglas Gregorebe10102009-08-20 07:17:43 +00002982 if (!getDerived().AlwaysRebuild() &&
2983 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00002984 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002985
2986 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
2987 move_arg(Statements),
2988 S->getRBracLoc(),
2989 IsStmtExpr);
2990}
Mike Stump11289f42009-09-09 15:08:12 +00002991
Douglas Gregorebe10102009-08-20 07:17:43 +00002992template<typename Derived>
2993Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002994TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00002995 OwningExprResult LHS(SemaRef), RHS(SemaRef);
2996 {
2997 // The case value expressions are not potentially evaluated.
2998 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002999
Eli Friedman06577382009-11-19 03:14:00 +00003000 // Transform the left-hand case value.
3001 LHS = getDerived().TransformExpr(S->getLHS());
3002 if (LHS.isInvalid())
3003 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003004
Eli Friedman06577382009-11-19 03:14:00 +00003005 // Transform the right-hand case value (for the GNU case-range extension).
3006 RHS = getDerived().TransformExpr(S->getRHS());
3007 if (RHS.isInvalid())
3008 return SemaRef.StmtError();
3009 }
Mike Stump11289f42009-09-09 15:08:12 +00003010
Douglas Gregorebe10102009-08-20 07:17:43 +00003011 // Build the case statement.
3012 // Case statements are always rebuilt so that they will attached to their
3013 // transformed switch statement.
3014 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3015 move(LHS),
3016 S->getEllipsisLoc(),
3017 move(RHS),
3018 S->getColonLoc());
3019 if (Case.isInvalid())
3020 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003021
Douglas Gregorebe10102009-08-20 07:17:43 +00003022 // Transform the statement following the case
3023 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3024 if (SubStmt.isInvalid())
3025 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003026
Douglas Gregorebe10102009-08-20 07:17:43 +00003027 // Attach the body to the case statement
3028 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3029}
3030
3031template<typename Derived>
3032Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003033TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003034 // Transform the statement following the default case
3035 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3036 if (SubStmt.isInvalid())
3037 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003038
Douglas Gregorebe10102009-08-20 07:17:43 +00003039 // Default statements are always rebuilt
3040 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3041 move(SubStmt));
3042}
Mike Stump11289f42009-09-09 15:08:12 +00003043
Douglas Gregorebe10102009-08-20 07:17:43 +00003044template<typename Derived>
3045Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003046TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003047 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3048 if (SubStmt.isInvalid())
3049 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003050
Douglas Gregorebe10102009-08-20 07:17:43 +00003051 // FIXME: Pass the real colon location in.
3052 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3053 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3054 move(SubStmt));
3055}
Mike Stump11289f42009-09-09 15:08:12 +00003056
Douglas Gregorebe10102009-08-20 07:17:43 +00003057template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003058Sema::OwningStmtResult
3059TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003060 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003061 OwningExprResult Cond(SemaRef);
3062 VarDecl *ConditionVar = 0;
3063 if (S->getConditionVariable()) {
3064 ConditionVar
3065 = cast_or_null<VarDecl>(
3066 getDerived().TransformDefinition(S->getConditionVariable()));
3067 if (!ConditionVar)
3068 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003069 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003070 Cond = getDerived().TransformExpr(S->getCond());
3071
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003072 if (Cond.isInvalid())
3073 return SemaRef.StmtError();
3074 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003075
Douglas Gregorebe10102009-08-20 07:17:43 +00003076 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003077
Douglas Gregorebe10102009-08-20 07:17:43 +00003078 // Transform the "then" branch.
3079 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3080 if (Then.isInvalid())
3081 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003082
Douglas Gregorebe10102009-08-20 07:17:43 +00003083 // Transform the "else" branch.
3084 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3085 if (Else.isInvalid())
3086 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003087
Douglas Gregorebe10102009-08-20 07:17:43 +00003088 if (!getDerived().AlwaysRebuild() &&
3089 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003090 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003091 Then.get() == S->getThen() &&
3092 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003093 return SemaRef.Owned(S->Retain());
3094
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003095 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3096 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003097 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003098}
3099
3100template<typename Derived>
3101Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003102TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003103 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003104 OwningExprResult Cond(SemaRef);
3105 VarDecl *ConditionVar = 0;
3106 if (S->getConditionVariable()) {
3107 ConditionVar
3108 = cast_or_null<VarDecl>(
3109 getDerived().TransformDefinition(S->getConditionVariable()));
3110 if (!ConditionVar)
3111 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003112 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003113 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003114
3115 if (Cond.isInvalid())
3116 return SemaRef.StmtError();
3117 }
Mike Stump11289f42009-09-09 15:08:12 +00003118
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003119 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
3120
Douglas Gregorebe10102009-08-20 07:17:43 +00003121 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003122 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3123 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003124 if (Switch.isInvalid())
3125 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003126
Douglas Gregorebe10102009-08-20 07:17:43 +00003127 // Transform the body of the switch statement.
3128 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3129 if (Body.isInvalid())
3130 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003131
Douglas Gregorebe10102009-08-20 07:17:43 +00003132 // Complete the switch statement.
3133 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3134 move(Body));
3135}
Mike Stump11289f42009-09-09 15:08:12 +00003136
Douglas Gregorebe10102009-08-20 07:17:43 +00003137template<typename Derived>
3138Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003139TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003140 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003141 OwningExprResult Cond(SemaRef);
3142 VarDecl *ConditionVar = 0;
3143 if (S->getConditionVariable()) {
3144 ConditionVar
3145 = cast_or_null<VarDecl>(
3146 getDerived().TransformDefinition(S->getConditionVariable()));
3147 if (!ConditionVar)
3148 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003149 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003150 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003151
3152 if (Cond.isInvalid())
3153 return SemaRef.StmtError();
3154 }
Mike Stump11289f42009-09-09 15:08:12 +00003155
Douglas Gregorebe10102009-08-20 07:17:43 +00003156 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003157
Douglas Gregorebe10102009-08-20 07:17:43 +00003158 // Transform the body
3159 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3160 if (Body.isInvalid())
3161 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003162
Douglas Gregorebe10102009-08-20 07:17:43 +00003163 if (!getDerived().AlwaysRebuild() &&
3164 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003165 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003166 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003167 return SemaRef.Owned(S->Retain());
3168
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003169 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3170 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003171}
Mike Stump11289f42009-09-09 15:08:12 +00003172
Douglas Gregorebe10102009-08-20 07:17:43 +00003173template<typename Derived>
3174Sema::OwningStmtResult
3175TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3176 // Transform the condition
3177 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3178 if (Cond.isInvalid())
3179 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003180
Douglas Gregorebe10102009-08-20 07:17:43 +00003181 // Transform the body
3182 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3183 if (Body.isInvalid())
3184 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003185
Douglas Gregorebe10102009-08-20 07:17:43 +00003186 if (!getDerived().AlwaysRebuild() &&
3187 Cond.get() == S->getCond() &&
3188 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003189 return SemaRef.Owned(S->Retain());
3190
Douglas Gregorebe10102009-08-20 07:17:43 +00003191 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3192 /*FIXME:*/S->getWhileLoc(), move(Cond),
3193 S->getRParenLoc());
3194}
Mike Stump11289f42009-09-09 15:08:12 +00003195
Douglas Gregorebe10102009-08-20 07:17:43 +00003196template<typename Derived>
3197Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003198TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003199 // Transform the initialization statement
3200 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3201 if (Init.isInvalid())
3202 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003203
Douglas Gregorebe10102009-08-20 07:17:43 +00003204 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003205 OwningExprResult Cond(SemaRef);
3206 VarDecl *ConditionVar = 0;
3207 if (S->getConditionVariable()) {
3208 ConditionVar
3209 = cast_or_null<VarDecl>(
3210 getDerived().TransformDefinition(S->getConditionVariable()));
3211 if (!ConditionVar)
3212 return SemaRef.StmtError();
3213 } else {
3214 Cond = getDerived().TransformExpr(S->getCond());
3215
3216 if (Cond.isInvalid())
3217 return SemaRef.StmtError();
3218 }
Mike Stump11289f42009-09-09 15:08:12 +00003219
Douglas Gregorebe10102009-08-20 07:17:43 +00003220 // Transform the increment
3221 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3222 if (Inc.isInvalid())
3223 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003224
Douglas Gregorebe10102009-08-20 07:17:43 +00003225 // Transform the body
3226 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3227 if (Body.isInvalid())
3228 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003229
Douglas Gregorebe10102009-08-20 07:17:43 +00003230 if (!getDerived().AlwaysRebuild() &&
3231 Init.get() == S->getInit() &&
3232 Cond.get() == S->getCond() &&
3233 Inc.get() == S->getInc() &&
3234 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003235 return SemaRef.Owned(S->Retain());
3236
Douglas Gregorebe10102009-08-20 07:17:43 +00003237 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003238 move(Init), getSema().FullExpr(Cond),
3239 ConditionVar,
3240 getSema().FullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003241 S->getRParenLoc(), move(Body));
3242}
3243
3244template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003245Sema::OwningStmtResult
3246TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003247 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003248 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003249 S->getLabel());
3250}
3251
3252template<typename Derived>
3253Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003254TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003255 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3256 if (Target.isInvalid())
3257 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003258
Douglas Gregorebe10102009-08-20 07:17:43 +00003259 if (!getDerived().AlwaysRebuild() &&
3260 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003261 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003262
3263 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3264 move(Target));
3265}
3266
3267template<typename Derived>
3268Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003269TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3270 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003271}
Mike Stump11289f42009-09-09 15:08:12 +00003272
Douglas Gregorebe10102009-08-20 07:17:43 +00003273template<typename Derived>
3274Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003275TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3276 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003277}
Mike Stump11289f42009-09-09 15:08:12 +00003278
Douglas Gregorebe10102009-08-20 07:17:43 +00003279template<typename Derived>
3280Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003281TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003282 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3283 if (Result.isInvalid())
3284 return SemaRef.StmtError();
3285
Mike Stump11289f42009-09-09 15:08:12 +00003286 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003287 // to tell whether the return type of the function has changed.
3288 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3289}
Mike Stump11289f42009-09-09 15:08:12 +00003290
Douglas Gregorebe10102009-08-20 07:17:43 +00003291template<typename Derived>
3292Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003293TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003294 bool DeclChanged = false;
3295 llvm::SmallVector<Decl *, 4> Decls;
3296 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3297 D != DEnd; ++D) {
3298 Decl *Transformed = getDerived().TransformDefinition(*D);
3299 if (!Transformed)
3300 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003301
Douglas Gregorebe10102009-08-20 07:17:43 +00003302 if (Transformed != *D)
3303 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003304
Douglas Gregorebe10102009-08-20 07:17:43 +00003305 Decls.push_back(Transformed);
3306 }
Mike Stump11289f42009-09-09 15:08:12 +00003307
Douglas Gregorebe10102009-08-20 07:17:43 +00003308 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003309 return SemaRef.Owned(S->Retain());
3310
3311 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003312 S->getStartLoc(), S->getEndLoc());
3313}
Mike Stump11289f42009-09-09 15:08:12 +00003314
Douglas Gregorebe10102009-08-20 07:17:43 +00003315template<typename Derived>
3316Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003317TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003318 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003319 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003320}
3321
3322template<typename Derived>
3323Sema::OwningStmtResult
3324TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
3325 // FIXME: Implement!
3326 assert(false && "Inline assembly cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003327 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003328}
3329
3330
3331template<typename Derived>
3332Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003333TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003334 // FIXME: Implement this
3335 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003336 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003337}
Mike Stump11289f42009-09-09 15:08:12 +00003338
Douglas Gregorebe10102009-08-20 07:17:43 +00003339template<typename Derived>
3340Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003341TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003342 // FIXME: Implement this
3343 assert(false && "Cannot transform an Objective-C @catch statement");
3344 return SemaRef.Owned(S->Retain());
3345}
Mike Stump11289f42009-09-09 15:08:12 +00003346
Douglas Gregorebe10102009-08-20 07:17:43 +00003347template<typename Derived>
3348Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003349TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003350 // FIXME: Implement this
3351 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003352 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003353}
Mike Stump11289f42009-09-09 15:08:12 +00003354
Douglas Gregorebe10102009-08-20 07:17:43 +00003355template<typename Derived>
3356Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003357TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003358 // FIXME: Implement this
3359 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003360 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003361}
Mike Stump11289f42009-09-09 15:08:12 +00003362
Douglas Gregorebe10102009-08-20 07:17:43 +00003363template<typename Derived>
3364Sema::OwningStmtResult
3365TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003366 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003367 // FIXME: Implement this
3368 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003369 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003370}
3371
3372template<typename Derived>
3373Sema::OwningStmtResult
3374TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003375 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003376 // FIXME: Implement this
3377 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003378 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003379}
3380
3381
3382template<typename Derived>
3383Sema::OwningStmtResult
3384TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3385 // Transform the exception declaration, if any.
3386 VarDecl *Var = 0;
3387 if (S->getExceptionDecl()) {
3388 VarDecl *ExceptionDecl = S->getExceptionDecl();
3389 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3390 ExceptionDecl->getDeclName());
3391
3392 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3393 if (T.isNull())
3394 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003395
Douglas Gregorebe10102009-08-20 07:17:43 +00003396 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3397 T,
3398 ExceptionDecl->getDeclaratorInfo(),
3399 ExceptionDecl->getIdentifier(),
3400 ExceptionDecl->getLocation(),
3401 /*FIXME: Inaccurate*/
3402 SourceRange(ExceptionDecl->getLocation()));
3403 if (!Var || Var->isInvalidDecl()) {
3404 if (Var)
3405 Var->Destroy(SemaRef.Context);
3406 return SemaRef.StmtError();
3407 }
3408 }
Mike Stump11289f42009-09-09 15:08:12 +00003409
Douglas Gregorebe10102009-08-20 07:17:43 +00003410 // Transform the actual exception handler.
3411 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3412 if (Handler.isInvalid()) {
3413 if (Var)
3414 Var->Destroy(SemaRef.Context);
3415 return SemaRef.StmtError();
3416 }
Mike Stump11289f42009-09-09 15:08:12 +00003417
Douglas Gregorebe10102009-08-20 07:17:43 +00003418 if (!getDerived().AlwaysRebuild() &&
3419 !Var &&
3420 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003421 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003422
3423 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3424 Var,
3425 move(Handler));
3426}
Mike Stump11289f42009-09-09 15:08:12 +00003427
Douglas Gregorebe10102009-08-20 07:17:43 +00003428template<typename Derived>
3429Sema::OwningStmtResult
3430TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3431 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003432 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003433 = getDerived().TransformCompoundStmt(S->getTryBlock());
3434 if (TryBlock.isInvalid())
3435 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003436
Douglas Gregorebe10102009-08-20 07:17:43 +00003437 // Transform the handlers.
3438 bool HandlerChanged = false;
3439 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3440 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003441 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003442 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3443 if (Handler.isInvalid())
3444 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003445
Douglas Gregorebe10102009-08-20 07:17:43 +00003446 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3447 Handlers.push_back(Handler.takeAs<Stmt>());
3448 }
Mike Stump11289f42009-09-09 15:08:12 +00003449
Douglas Gregorebe10102009-08-20 07:17:43 +00003450 if (!getDerived().AlwaysRebuild() &&
3451 TryBlock.get() == S->getTryBlock() &&
3452 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003453 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003454
3455 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003456 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003457}
Mike Stump11289f42009-09-09 15:08:12 +00003458
Douglas Gregorebe10102009-08-20 07:17:43 +00003459//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003460// Expression transformation
3461//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003462template<typename Derived>
3463Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003464TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E,
3465 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003466 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003467}
Mike Stump11289f42009-09-09 15:08:12 +00003468
3469template<typename Derived>
3470Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003471TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E,
3472 bool isAddressOfOperand) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003473 NestedNameSpecifier *Qualifier = 0;
3474 if (E->getQualifier()) {
3475 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3476 E->getQualifierRange());
3477 if (!Qualifier)
3478 return SemaRef.ExprError();
3479 }
3480
Mike Stump11289f42009-09-09 15:08:12 +00003481 NamedDecl *ND
Douglas Gregora16548e2009-08-11 05:31:07 +00003482 = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl()));
3483 if (!ND)
3484 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003485
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003486 if (!getDerived().AlwaysRebuild() &&
3487 Qualifier == E->getQualifier() &&
3488 ND == E->getDecl() &&
3489 !E->hasExplicitTemplateArgumentList())
Mike Stump11289f42009-09-09 15:08:12 +00003490 return SemaRef.Owned(E->Retain());
3491
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003492 // FIXME: We're losing the explicit template arguments in this transformation.
3493
John McCall0ad16662009-10-29 08:12:44 +00003494 llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003495 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall0ad16662009-10-29 08:12:44 +00003496 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I],
3497 TransArgs[I]))
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003498 return SemaRef.ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003499 }
3500
3501 // FIXME: Pass the qualifier/qualifier range along.
3502 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003503 ND, E->getLocation(),
3504 isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00003505}
Mike Stump11289f42009-09-09 15:08:12 +00003506
Douglas Gregora16548e2009-08-11 05:31:07 +00003507template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003508Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003509TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E,
3510 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003511 return SemaRef.Owned(E->Retain());
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>::TransformFloatingLiteral(FloatingLiteral *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>::TransformImaginaryLiteral(ImaginaryLiteral *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>::TransformStringLiteral(StringLiteral *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>::TransformCharacterLiteral(CharacterLiteral *E,
3538 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003539 return SemaRef.Owned(E->Retain());
3540}
3541
3542template<typename Derived>
3543Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003544TreeTransform<Derived>::TransformParenExpr(ParenExpr *E,
3545 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003546 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3547 if (SubExpr.isInvalid())
3548 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003549
Douglas Gregora16548e2009-08-11 05:31:07 +00003550 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003551 return SemaRef.Owned(E->Retain());
3552
3553 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003554 E->getRParen());
3555}
3556
Mike Stump11289f42009-09-09 15:08:12 +00003557template<typename Derived>
3558Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003559TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E,
3560 bool isAddressOfOperand) {
3561 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr(),
3562 E->getOpcode() == UnaryOperator::AddrOf);
Douglas Gregora16548e2009-08-11 05:31:07 +00003563 if (SubExpr.isInvalid())
3564 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003565
Douglas Gregora16548e2009-08-11 05:31:07 +00003566 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003567 return SemaRef.Owned(E->Retain());
3568
Douglas Gregora16548e2009-08-11 05:31:07 +00003569 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3570 E->getOpcode(),
3571 move(SubExpr));
3572}
Mike Stump11289f42009-09-09 15:08:12 +00003573
Douglas Gregora16548e2009-08-11 05:31:07 +00003574template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003575Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003576TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E,
3577 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003578 if (E->isArgumentType()) {
John McCall4c98fd82009-11-04 07:28:41 +00003579 DeclaratorInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003580
John McCall4c98fd82009-11-04 07:28:41 +00003581 DeclaratorInfo *NewT = getDerived().TransformType(OldT);
3582 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003583 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003584
John McCall4c98fd82009-11-04 07:28:41 +00003585 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003586 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003587
John McCall4c98fd82009-11-04 07:28:41 +00003588 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003589 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003590 E->getSourceRange());
3591 }
Mike Stump11289f42009-09-09 15:08:12 +00003592
Douglas Gregora16548e2009-08-11 05:31:07 +00003593 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003594 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003595 // C++0x [expr.sizeof]p1:
3596 // The operand is either an expression, which is an unevaluated operand
3597 // [...]
3598 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003599
Douglas Gregora16548e2009-08-11 05:31:07 +00003600 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3601 if (SubExpr.isInvalid())
3602 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003603
Douglas Gregora16548e2009-08-11 05:31:07 +00003604 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3605 return SemaRef.Owned(E->Retain());
3606 }
Mike Stump11289f42009-09-09 15:08:12 +00003607
Douglas Gregora16548e2009-08-11 05:31:07 +00003608 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3609 E->isSizeOf(),
3610 E->getSourceRange());
3611}
Mike Stump11289f42009-09-09 15:08:12 +00003612
Douglas Gregora16548e2009-08-11 05:31:07 +00003613template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003614Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003615TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E,
3616 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003617 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3618 if (LHS.isInvalid())
3619 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003620
Douglas Gregora16548e2009-08-11 05:31:07 +00003621 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3622 if (RHS.isInvalid())
3623 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003624
3625
Douglas Gregora16548e2009-08-11 05:31:07 +00003626 if (!getDerived().AlwaysRebuild() &&
3627 LHS.get() == E->getLHS() &&
3628 RHS.get() == E->getRHS())
3629 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003630
Douglas Gregora16548e2009-08-11 05:31:07 +00003631 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3632 /*FIXME:*/E->getLHS()->getLocStart(),
3633 move(RHS),
3634 E->getRBracketLoc());
3635}
Mike Stump11289f42009-09-09 15:08:12 +00003636
3637template<typename Derived>
3638Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003639TreeTransform<Derived>::TransformCallExpr(CallExpr *E,
3640 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003641 // Transform the callee.
3642 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3643 if (Callee.isInvalid())
3644 return SemaRef.ExprError();
3645
3646 // Transform arguments.
3647 bool ArgChanged = false;
3648 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3649 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3650 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3651 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3652 if (Arg.isInvalid())
3653 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003654
Douglas Gregora16548e2009-08-11 05:31:07 +00003655 // FIXME: Wrong source location information for the ','.
3656 FakeCommaLocs.push_back(
3657 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003658
3659 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003660 Args.push_back(Arg.takeAs<Expr>());
3661 }
Mike Stump11289f42009-09-09 15:08:12 +00003662
Douglas Gregora16548e2009-08-11 05:31:07 +00003663 if (!getDerived().AlwaysRebuild() &&
3664 Callee.get() == E->getCallee() &&
3665 !ArgChanged)
3666 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003667
Douglas Gregora16548e2009-08-11 05:31:07 +00003668 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003669 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003670 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3671 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3672 move_arg(Args),
3673 FakeCommaLocs.data(),
3674 E->getRParenLoc());
3675}
Mike Stump11289f42009-09-09 15:08:12 +00003676
3677template<typename Derived>
3678Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003679TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E,
3680 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003681 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3682 if (Base.isInvalid())
3683 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003684
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003685 NestedNameSpecifier *Qualifier = 0;
3686 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003687 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003688 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3689 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003690 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003691 return SemaRef.ExprError();
3692 }
Mike Stump11289f42009-09-09 15:08:12 +00003693
3694 NamedDecl *Member
Douglas Gregora16548e2009-08-11 05:31:07 +00003695 = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getMemberDecl()));
3696 if (!Member)
3697 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003698
Douglas Gregora16548e2009-08-11 05:31:07 +00003699 if (!getDerived().AlwaysRebuild() &&
3700 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003701 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003702 Member == E->getMemberDecl() &&
3703 !E->hasExplicitTemplateArgumentList())
Mike Stump11289f42009-09-09 15:08:12 +00003704 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003705
John McCall6b51f282009-11-23 01:53:49 +00003706 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003707 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003708 TransArgs.setLAngleLoc(E->getLAngleLoc());
3709 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003710 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003711 TemplateArgumentLoc Loc;
3712 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003713 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003714 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003715 }
3716 }
3717
Douglas Gregora16548e2009-08-11 05:31:07 +00003718 // FIXME: Bogus source location for the operator
3719 SourceLocation FakeOperatorLoc
3720 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3721
3722 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3723 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003724 Qualifier,
3725 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003726 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003727 Member,
John McCall6b51f282009-11-23 01:53:49 +00003728 (E->hasExplicitTemplateArgumentList()
3729 ? &TransArgs : 0),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003730 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00003731}
Mike Stump11289f42009-09-09 15:08:12 +00003732
Douglas Gregora16548e2009-08-11 05:31:07 +00003733template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003734Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003735TreeTransform<Derived>::TransformCastExpr(CastExpr *E,
3736 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003737 assert(false && "Cannot transform abstract class");
3738 return SemaRef.Owned(E->Retain());
3739}
3740
3741template<typename Derived>
3742Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003743TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E,
3744 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003745 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3746 if (LHS.isInvalid())
3747 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003748
Douglas Gregora16548e2009-08-11 05:31:07 +00003749 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3750 if (RHS.isInvalid())
3751 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003752
Douglas Gregora16548e2009-08-11 05:31:07 +00003753 if (!getDerived().AlwaysRebuild() &&
3754 LHS.get() == E->getLHS() &&
3755 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003756 return SemaRef.Owned(E->Retain());
3757
Douglas Gregora16548e2009-08-11 05:31:07 +00003758 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3759 move(LHS), move(RHS));
3760}
3761
Mike Stump11289f42009-09-09 15:08:12 +00003762template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003763Sema::OwningExprResult
3764TreeTransform<Derived>::TransformCompoundAssignOperator(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003765 CompoundAssignOperator *E,
3766 bool isAddressOfOperand) {
3767 return getDerived().TransformBinaryOperator(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00003768}
Mike Stump11289f42009-09-09 15:08:12 +00003769
Douglas Gregora16548e2009-08-11 05:31:07 +00003770template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003771Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003772TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E,
3773 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003774 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3775 if (Cond.isInvalid())
3776 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003777
Douglas Gregora16548e2009-08-11 05:31:07 +00003778 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3779 if (LHS.isInvalid())
3780 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003781
Douglas Gregora16548e2009-08-11 05:31:07 +00003782 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3783 if (RHS.isInvalid())
3784 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003785
Douglas Gregora16548e2009-08-11 05:31:07 +00003786 if (!getDerived().AlwaysRebuild() &&
3787 Cond.get() == E->getCond() &&
3788 LHS.get() == E->getLHS() &&
3789 RHS.get() == E->getRHS())
3790 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003791
3792 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003793 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003794 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003795 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003796 move(RHS));
3797}
Mike Stump11289f42009-09-09 15:08:12 +00003798
3799template<typename Derived>
3800Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003801TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E,
3802 bool isAddressOfOperand) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00003803 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3804
3805 // FIXME: Will we ever have type information here? It seems like we won't,
3806 // so do we even need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00003807 QualType T = getDerived().TransformType(E->getType());
3808 if (T.isNull())
3809 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003810
Douglas Gregora16548e2009-08-11 05:31:07 +00003811 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3812 if (SubExpr.isInvalid())
3813 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003814
Douglas Gregora16548e2009-08-11 05:31:07 +00003815 if (!getDerived().AlwaysRebuild() &&
3816 T == E->getType() &&
3817 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003818 return SemaRef.Owned(E->Retain());
3819
Douglas Gregora16548e2009-08-11 05:31:07 +00003820 return getDerived().RebuildImplicitCastExpr(T, E->getCastKind(),
Mike Stump11289f42009-09-09 15:08:12 +00003821 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00003822 E->isLvalueCast());
3823}
Mike Stump11289f42009-09-09 15:08:12 +00003824
Douglas Gregora16548e2009-08-11 05:31:07 +00003825template<typename Derived>
3826Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003827TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E,
3828 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003829 assert(false && "Cannot transform abstract class");
3830 return SemaRef.Owned(E->Retain());
3831}
3832
3833template<typename Derived>
3834Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003835TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E,
3836 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003837 QualType T;
3838 {
3839 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003840 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003841 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3842 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003843
Douglas Gregora16548e2009-08-11 05:31:07 +00003844 T = getDerived().TransformType(E->getTypeAsWritten());
3845 if (T.isNull())
3846 return SemaRef.ExprError();
3847 }
Mike Stump11289f42009-09-09 15:08:12 +00003848
Douglas Gregora16548e2009-08-11 05:31:07 +00003849 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3850 if (SubExpr.isInvalid())
3851 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003852
Douglas Gregora16548e2009-08-11 05:31:07 +00003853 if (!getDerived().AlwaysRebuild() &&
3854 T == E->getTypeAsWritten() &&
3855 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003856 return SemaRef.Owned(E->Retain());
3857
Douglas Gregora16548e2009-08-11 05:31:07 +00003858 return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T,
3859 E->getRParenLoc(),
3860 move(SubExpr));
3861}
Mike Stump11289f42009-09-09 15:08:12 +00003862
Douglas Gregora16548e2009-08-11 05:31:07 +00003863template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003864Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003865TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E,
3866 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003867 QualType T;
3868 {
3869 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003870 SourceLocation FakeTypeLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003871 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3872 TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003873
Douglas Gregora16548e2009-08-11 05:31:07 +00003874 T = getDerived().TransformType(E->getType());
3875 if (T.isNull())
3876 return SemaRef.ExprError();
3877 }
Mike Stump11289f42009-09-09 15:08:12 +00003878
Douglas Gregora16548e2009-08-11 05:31:07 +00003879 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3880 if (Init.isInvalid())
3881 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003882
Douglas Gregora16548e2009-08-11 05:31:07 +00003883 if (!getDerived().AlwaysRebuild() &&
3884 T == E->getType() &&
3885 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003886 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003887
3888 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T,
3889 /*FIXME:*/E->getInitializer()->getLocEnd(),
3890 move(Init));
3891}
Mike Stump11289f42009-09-09 15:08:12 +00003892
Douglas Gregora16548e2009-08-11 05:31:07 +00003893template<typename Derived>
3894Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003895TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E,
3896 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003897 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3898 if (Base.isInvalid())
3899 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003900
Douglas Gregora16548e2009-08-11 05:31:07 +00003901 if (!getDerived().AlwaysRebuild() &&
3902 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003903 return SemaRef.Owned(E->Retain());
3904
Douglas Gregora16548e2009-08-11 05:31:07 +00003905 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003906 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003907 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3908 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3909 E->getAccessorLoc(),
3910 E->getAccessor());
3911}
Mike Stump11289f42009-09-09 15:08:12 +00003912
Douglas Gregora16548e2009-08-11 05:31:07 +00003913template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003914Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003915TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E,
3916 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003917 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003918
Douglas Gregora16548e2009-08-11 05:31:07 +00003919 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3920 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3921 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3922 if (Init.isInvalid())
3923 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003924
Douglas Gregora16548e2009-08-11 05:31:07 +00003925 InitChanged = InitChanged || Init.get() != E->getInit(I);
3926 Inits.push_back(Init.takeAs<Expr>());
3927 }
Mike Stump11289f42009-09-09 15:08:12 +00003928
Douglas Gregora16548e2009-08-11 05:31:07 +00003929 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003930 return SemaRef.Owned(E->Retain());
3931
Douglas Gregora16548e2009-08-11 05:31:07 +00003932 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00003933 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00003934}
Mike Stump11289f42009-09-09 15:08:12 +00003935
Douglas Gregora16548e2009-08-11 05:31:07 +00003936template<typename Derived>
3937Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003938TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E,
3939 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003940 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00003941
Douglas Gregorebe10102009-08-20 07:17:43 +00003942 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00003943 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3944 if (Init.isInvalid())
3945 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003946
Douglas Gregorebe10102009-08-20 07:17:43 +00003947 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00003948 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3949 bool ExprChanged = false;
3950 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3951 DEnd = E->designators_end();
3952 D != DEnd; ++D) {
3953 if (D->isFieldDesignator()) {
3954 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3955 D->getDotLoc(),
3956 D->getFieldLoc()));
3957 continue;
3958 }
Mike Stump11289f42009-09-09 15:08:12 +00003959
Douglas Gregora16548e2009-08-11 05:31:07 +00003960 if (D->isArrayDesignator()) {
3961 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3962 if (Index.isInvalid())
3963 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003964
3965 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003966 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003967
Douglas Gregora16548e2009-08-11 05:31:07 +00003968 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3969 ArrayExprs.push_back(Index.release());
3970 continue;
3971 }
Mike Stump11289f42009-09-09 15:08:12 +00003972
Douglas Gregora16548e2009-08-11 05:31:07 +00003973 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00003974 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00003975 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3976 if (Start.isInvalid())
3977 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003978
Douglas Gregora16548e2009-08-11 05:31:07 +00003979 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3980 if (End.isInvalid())
3981 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003982
3983 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003984 End.get(),
3985 D->getLBracketLoc(),
3986 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003987
Douglas Gregora16548e2009-08-11 05:31:07 +00003988 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
3989 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00003990
Douglas Gregora16548e2009-08-11 05:31:07 +00003991 ArrayExprs.push_back(Start.release());
3992 ArrayExprs.push_back(End.release());
3993 }
Mike Stump11289f42009-09-09 15:08:12 +00003994
Douglas Gregora16548e2009-08-11 05:31:07 +00003995 if (!getDerived().AlwaysRebuild() &&
3996 Init.get() == E->getInit() &&
3997 !ExprChanged)
3998 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003999
Douglas Gregora16548e2009-08-11 05:31:07 +00004000 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4001 E->getEqualOrColonLoc(),
4002 E->usesGNUSyntax(), move(Init));
4003}
Mike Stump11289f42009-09-09 15:08:12 +00004004
Douglas Gregora16548e2009-08-11 05:31:07 +00004005template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004006Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004007TreeTransform<Derived>::TransformImplicitValueInitExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004008 ImplicitValueInitExpr *E,
4009 bool isAddressOfOperand) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004010 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4011
4012 // FIXME: Will we ever have proper type location here? Will we actually
4013 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004014 QualType T = getDerived().TransformType(E->getType());
4015 if (T.isNull())
4016 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004017
Douglas Gregora16548e2009-08-11 05:31:07 +00004018 if (!getDerived().AlwaysRebuild() &&
4019 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004020 return SemaRef.Owned(E->Retain());
4021
Douglas Gregora16548e2009-08-11 05:31:07 +00004022 return getDerived().RebuildImplicitValueInitExpr(T);
4023}
Mike Stump11289f42009-09-09 15:08:12 +00004024
Douglas Gregora16548e2009-08-11 05:31:07 +00004025template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004026Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004027TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E,
4028 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004029 // FIXME: Do we want the type as written?
4030 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004031
Douglas Gregora16548e2009-08-11 05:31:07 +00004032 {
4033 // FIXME: Source location isn't quite accurate.
4034 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4035 T = getDerived().TransformType(E->getType());
4036 if (T.isNull())
4037 return SemaRef.ExprError();
4038 }
Mike Stump11289f42009-09-09 15:08:12 +00004039
Douglas Gregora16548e2009-08-11 05:31:07 +00004040 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4041 if (SubExpr.isInvalid())
4042 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004043
Douglas Gregora16548e2009-08-11 05:31:07 +00004044 if (!getDerived().AlwaysRebuild() &&
4045 T == E->getType() &&
4046 SubExpr.get() == E->getSubExpr())
4047 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004048
Douglas Gregora16548e2009-08-11 05:31:07 +00004049 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4050 T, E->getRParenLoc());
4051}
4052
4053template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004054Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004055TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E,
4056 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004057 bool ArgumentChanged = false;
4058 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4059 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4060 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4061 if (Init.isInvalid())
4062 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004063
Douglas Gregora16548e2009-08-11 05:31:07 +00004064 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4065 Inits.push_back(Init.takeAs<Expr>());
4066 }
Mike Stump11289f42009-09-09 15:08:12 +00004067
Douglas Gregora16548e2009-08-11 05:31:07 +00004068 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4069 move_arg(Inits),
4070 E->getRParenLoc());
4071}
Mike Stump11289f42009-09-09 15:08:12 +00004072
Douglas Gregora16548e2009-08-11 05:31:07 +00004073/// \brief Transform an address-of-label expression.
4074///
4075/// By default, the transformation of an address-of-label expression always
4076/// rebuilds the expression, so that the label identifier can be resolved to
4077/// the corresponding label statement by semantic analysis.
4078template<typename Derived>
4079Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004080TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E,
4081 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004082 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4083 E->getLabel());
4084}
Mike Stump11289f42009-09-09 15:08:12 +00004085
4086template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004087Sema::OwningExprResult
4088TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E,
4089 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004090 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004091 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4092 if (SubStmt.isInvalid())
4093 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004094
Douglas Gregora16548e2009-08-11 05:31:07 +00004095 if (!getDerived().AlwaysRebuild() &&
4096 SubStmt.get() == E->getSubStmt())
4097 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004098
4099 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004100 move(SubStmt),
4101 E->getRParenLoc());
4102}
Mike Stump11289f42009-09-09 15:08:12 +00004103
Douglas Gregora16548e2009-08-11 05:31:07 +00004104template<typename Derived>
4105Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004106TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E,
4107 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004108 QualType T1, T2;
4109 {
4110 // FIXME: Source location isn't quite accurate.
4111 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004112
Douglas Gregora16548e2009-08-11 05:31:07 +00004113 T1 = getDerived().TransformType(E->getArgType1());
4114 if (T1.isNull())
4115 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004116
Douglas Gregora16548e2009-08-11 05:31:07 +00004117 T2 = getDerived().TransformType(E->getArgType2());
4118 if (T2.isNull())
4119 return SemaRef.ExprError();
4120 }
4121
4122 if (!getDerived().AlwaysRebuild() &&
4123 T1 == E->getArgType1() &&
4124 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004125 return SemaRef.Owned(E->Retain());
4126
Douglas Gregora16548e2009-08-11 05:31:07 +00004127 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4128 T1, T2, E->getRParenLoc());
4129}
Mike Stump11289f42009-09-09 15:08:12 +00004130
Douglas Gregora16548e2009-08-11 05:31:07 +00004131template<typename Derived>
4132Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004133TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E,
4134 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004135 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4136 if (Cond.isInvalid())
4137 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004138
Douglas Gregora16548e2009-08-11 05:31:07 +00004139 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4140 if (LHS.isInvalid())
4141 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004142
Douglas Gregora16548e2009-08-11 05:31:07 +00004143 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4144 if (RHS.isInvalid())
4145 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004146
Douglas Gregora16548e2009-08-11 05:31:07 +00004147 if (!getDerived().AlwaysRebuild() &&
4148 Cond.get() == E->getCond() &&
4149 LHS.get() == E->getLHS() &&
4150 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004151 return SemaRef.Owned(E->Retain());
4152
Douglas Gregora16548e2009-08-11 05:31:07 +00004153 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4154 move(Cond), move(LHS), move(RHS),
4155 E->getRParenLoc());
4156}
Mike Stump11289f42009-09-09 15:08:12 +00004157
Douglas Gregora16548e2009-08-11 05:31:07 +00004158template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004159Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004160TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E,
4161 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004162 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004163}
4164
4165template<typename Derived>
4166Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004167TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E,
4168 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004169 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4170 if (Callee.isInvalid())
4171 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004172
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004173 OwningExprResult First
4174 = getDerived().TransformExpr(E->getArg(0),
4175 E->getNumArgs() == 1 && E->getOperator() == OO_Amp);
Douglas Gregora16548e2009-08-11 05:31:07 +00004176 if (First.isInvalid())
4177 return SemaRef.ExprError();
4178
4179 OwningExprResult Second(SemaRef);
4180 if (E->getNumArgs() == 2) {
4181 Second = getDerived().TransformExpr(E->getArg(1));
4182 if (Second.isInvalid())
4183 return SemaRef.ExprError();
4184 }
Mike Stump11289f42009-09-09 15:08:12 +00004185
Douglas Gregora16548e2009-08-11 05:31:07 +00004186 if (!getDerived().AlwaysRebuild() &&
4187 Callee.get() == E->getCallee() &&
4188 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004189 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4190 return SemaRef.Owned(E->Retain());
4191
Douglas Gregora16548e2009-08-11 05:31:07 +00004192 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4193 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004194 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004195 move(First),
4196 move(Second));
4197}
Mike Stump11289f42009-09-09 15:08:12 +00004198
Douglas Gregora16548e2009-08-11 05:31:07 +00004199template<typename Derived>
4200Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004201TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E,
4202 bool isAddressOfOperand) {
4203 return getDerived().TransformCallExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004204}
Mike Stump11289f42009-09-09 15:08:12 +00004205
Douglas Gregora16548e2009-08-11 05:31:07 +00004206template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004207Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004208TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E,
4209 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004210 QualType ExplicitTy;
4211 {
4212 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004213 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004214 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4215 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004216
Douglas Gregora16548e2009-08-11 05:31:07 +00004217 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4218 if (ExplicitTy.isNull())
4219 return SemaRef.ExprError();
4220 }
Mike Stump11289f42009-09-09 15:08:12 +00004221
Douglas Gregora16548e2009-08-11 05:31:07 +00004222 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4223 if (SubExpr.isInvalid())
4224 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004225
Douglas Gregora16548e2009-08-11 05:31:07 +00004226 if (!getDerived().AlwaysRebuild() &&
4227 ExplicitTy == E->getTypeAsWritten() &&
4228 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004229 return SemaRef.Owned(E->Retain());
4230
Douglas Gregora16548e2009-08-11 05:31:07 +00004231 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004232 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004233 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4234 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4235 SourceLocation FakeRParenLoc
4236 = SemaRef.PP.getLocForEndOfToken(
4237 E->getSubExpr()->getSourceRange().getEnd());
4238 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004239 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004240 FakeLAngleLoc,
4241 ExplicitTy,
4242 FakeRAngleLoc,
4243 FakeRAngleLoc,
4244 move(SubExpr),
4245 FakeRParenLoc);
4246}
Mike Stump11289f42009-09-09 15:08:12 +00004247
Douglas Gregora16548e2009-08-11 05:31:07 +00004248template<typename Derived>
4249Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004250TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E,
4251 bool isAddressOfOperand) {
4252 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004253}
Mike Stump11289f42009-09-09 15:08:12 +00004254
4255template<typename Derived>
4256Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004257TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E,
4258 bool isAddressOfOperand) {
4259 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Mike Stump11289f42009-09-09 15:08:12 +00004260}
4261
Douglas Gregora16548e2009-08-11 05:31:07 +00004262template<typename Derived>
4263Sema::OwningExprResult
4264TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004265 CXXReinterpretCastExpr *E,
4266 bool isAddressOfOperand) {
4267 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004268}
Mike Stump11289f42009-09-09 15:08:12 +00004269
Douglas Gregora16548e2009-08-11 05:31:07 +00004270template<typename Derived>
4271Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004272TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *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
4279TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004280 CXXFunctionalCastExpr *E,
4281 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004282 QualType ExplicitTy;
4283 {
4284 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004285
Douglas Gregora16548e2009-08-11 05:31:07 +00004286 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4287 if (ExplicitTy.isNull())
4288 return SemaRef.ExprError();
4289 }
Mike Stump11289f42009-09-09 15:08:12 +00004290
Douglas Gregora16548e2009-08-11 05:31:07 +00004291 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4292 if (SubExpr.isInvalid())
4293 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004294
Douglas Gregora16548e2009-08-11 05:31:07 +00004295 if (!getDerived().AlwaysRebuild() &&
4296 ExplicitTy == E->getTypeAsWritten() &&
4297 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004298 return SemaRef.Owned(E->Retain());
4299
Douglas Gregora16548e2009-08-11 05:31:07 +00004300 // FIXME: The end of the type's source range is wrong
4301 return getDerived().RebuildCXXFunctionalCastExpr(
4302 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
4303 ExplicitTy,
4304 /*FIXME:*/E->getSubExpr()->getLocStart(),
4305 move(SubExpr),
4306 E->getRParenLoc());
4307}
Mike Stump11289f42009-09-09 15:08:12 +00004308
Douglas Gregora16548e2009-08-11 05:31:07 +00004309template<typename Derived>
4310Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004311TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E,
4312 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004313 if (E->isTypeOperand()) {
4314 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004315
Douglas Gregora16548e2009-08-11 05:31:07 +00004316 QualType T = getDerived().TransformType(E->getTypeOperand());
4317 if (T.isNull())
4318 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004319
Douglas Gregora16548e2009-08-11 05:31:07 +00004320 if (!getDerived().AlwaysRebuild() &&
4321 T == E->getTypeOperand())
4322 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004323
Douglas Gregora16548e2009-08-11 05:31:07 +00004324 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4325 /*FIXME:*/E->getLocStart(),
4326 T,
4327 E->getLocEnd());
4328 }
Mike Stump11289f42009-09-09 15:08:12 +00004329
Douglas Gregora16548e2009-08-11 05:31:07 +00004330 // We don't know whether the expression is potentially evaluated until
4331 // after we perform semantic analysis, so the expression is potentially
4332 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004333 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004334 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004335
Douglas Gregora16548e2009-08-11 05:31:07 +00004336 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4337 if (SubExpr.isInvalid())
4338 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004339
Douglas Gregora16548e2009-08-11 05:31:07 +00004340 if (!getDerived().AlwaysRebuild() &&
4341 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004342 return SemaRef.Owned(E->Retain());
4343
Douglas Gregora16548e2009-08-11 05:31:07 +00004344 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4345 /*FIXME:*/E->getLocStart(),
4346 move(SubExpr),
4347 E->getLocEnd());
4348}
4349
4350template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004351Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004352TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E,
4353 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004354 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004355}
Mike Stump11289f42009-09-09 15:08:12 +00004356
Douglas Gregora16548e2009-08-11 05:31:07 +00004357template<typename Derived>
4358Sema::OwningExprResult
4359TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004360 CXXNullPtrLiteralExpr *E,
4361 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004362 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004363}
Mike Stump11289f42009-09-09 15:08:12 +00004364
Douglas Gregora16548e2009-08-11 05:31:07 +00004365template<typename Derived>
4366Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004367TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E,
4368 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004369 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004370
Douglas Gregora16548e2009-08-11 05:31:07 +00004371 QualType T = getDerived().TransformType(E->getType());
4372 if (T.isNull())
4373 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004374
Douglas Gregora16548e2009-08-11 05:31:07 +00004375 if (!getDerived().AlwaysRebuild() &&
4376 T == E->getType())
4377 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004378
Douglas Gregora16548e2009-08-11 05:31:07 +00004379 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T);
4380}
Mike Stump11289f42009-09-09 15:08:12 +00004381
Douglas Gregora16548e2009-08-11 05:31:07 +00004382template<typename Derived>
4383Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004384TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E,
4385 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004386 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4387 if (SubExpr.isInvalid())
4388 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004389
Douglas Gregora16548e2009-08-11 05:31:07 +00004390 if (!getDerived().AlwaysRebuild() &&
4391 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004392 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004393
4394 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4395}
Mike Stump11289f42009-09-09 15:08:12 +00004396
Douglas Gregora16548e2009-08-11 05:31:07 +00004397template<typename Derived>
4398Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004399TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E,
4400 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004401 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004402 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4403 if (!Param)
4404 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004405
Douglas Gregora16548e2009-08-11 05:31:07 +00004406 if (getDerived().AlwaysRebuild() &&
4407 Param == E->getParam())
4408 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004409
Douglas Gregora16548e2009-08-11 05:31:07 +00004410 return getDerived().RebuildCXXDefaultArgExpr(Param);
4411}
Mike Stump11289f42009-09-09 15:08:12 +00004412
Douglas Gregora16548e2009-08-11 05:31:07 +00004413template<typename Derived>
4414Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004415TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E,
4416 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004417 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4418
4419 QualType T = getDerived().TransformType(E->getType());
4420 if (T.isNull())
4421 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004422
Douglas Gregora16548e2009-08-11 05:31:07 +00004423 if (!getDerived().AlwaysRebuild() &&
4424 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004425 return SemaRef.Owned(E->Retain());
4426
4427 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004428 /*FIXME:*/E->getTypeBeginLoc(),
4429 T,
4430 E->getRParenLoc());
4431}
Mike Stump11289f42009-09-09 15:08:12 +00004432
Douglas Gregora16548e2009-08-11 05:31:07 +00004433template<typename Derived>
4434Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004435TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E,
4436 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004437 // Transform the type that we're allocating
4438 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4439 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4440 if (AllocType.isNull())
4441 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004442
Douglas Gregora16548e2009-08-11 05:31:07 +00004443 // Transform the size of the array we're allocating (if any).
4444 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4445 if (ArraySize.isInvalid())
4446 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004447
Douglas Gregora16548e2009-08-11 05:31:07 +00004448 // Transform the placement arguments (if any).
4449 bool ArgumentChanged = false;
4450 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4451 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4452 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4453 if (Arg.isInvalid())
4454 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004455
Douglas Gregora16548e2009-08-11 05:31:07 +00004456 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4457 PlacementArgs.push_back(Arg.take());
4458 }
Mike Stump11289f42009-09-09 15:08:12 +00004459
Douglas Gregorebe10102009-08-20 07:17:43 +00004460 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004461 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4462 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4463 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4464 if (Arg.isInvalid())
4465 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004466
Douglas Gregora16548e2009-08-11 05:31:07 +00004467 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4468 ConstructorArgs.push_back(Arg.take());
4469 }
Mike Stump11289f42009-09-09 15:08:12 +00004470
Douglas Gregora16548e2009-08-11 05:31:07 +00004471 if (!getDerived().AlwaysRebuild() &&
4472 AllocType == E->getAllocatedType() &&
4473 ArraySize.get() == E->getArraySize() &&
4474 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004475 return SemaRef.Owned(E->Retain());
4476
Douglas Gregora16548e2009-08-11 05:31:07 +00004477 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4478 E->isGlobalNew(),
4479 /*FIXME:*/E->getLocStart(),
4480 move_arg(PlacementArgs),
4481 /*FIXME:*/E->getLocStart(),
4482 E->isParenTypeId(),
4483 AllocType,
4484 /*FIXME:*/E->getLocStart(),
4485 /*FIXME:*/SourceRange(),
4486 move(ArraySize),
4487 /*FIXME:*/E->getLocStart(),
4488 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004489 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004490}
Mike Stump11289f42009-09-09 15:08:12 +00004491
Douglas Gregora16548e2009-08-11 05:31:07 +00004492template<typename Derived>
4493Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004494TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E,
4495 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004496 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4497 if (Operand.isInvalid())
4498 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004499
Douglas Gregora16548e2009-08-11 05:31:07 +00004500 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004501 Operand.get() == E->getArgument())
4502 return SemaRef.Owned(E->Retain());
4503
Douglas Gregora16548e2009-08-11 05:31:07 +00004504 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4505 E->isGlobalDelete(),
4506 E->isArrayForm(),
4507 move(Operand));
4508}
Mike Stump11289f42009-09-09 15:08:12 +00004509
Douglas Gregora16548e2009-08-11 05:31:07 +00004510template<typename Derived>
4511Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004512TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004513 CXXPseudoDestructorExpr *E,
4514 bool isAddressOfOperand) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004515 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4516 if (Base.isInvalid())
4517 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004518
Douglas Gregorad8a3362009-09-04 17:36:40 +00004519 NestedNameSpecifier *Qualifier
4520 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4521 E->getQualifierRange());
4522 if (E->getQualifier() && !Qualifier)
4523 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004524
Douglas Gregorad8a3362009-09-04 17:36:40 +00004525 QualType DestroyedType;
4526 {
4527 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4528 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4529 if (DestroyedType.isNull())
4530 return SemaRef.ExprError();
4531 }
Mike Stump11289f42009-09-09 15:08:12 +00004532
Douglas Gregorad8a3362009-09-04 17:36:40 +00004533 if (!getDerived().AlwaysRebuild() &&
4534 Base.get() == E->getBase() &&
4535 Qualifier == E->getQualifier() &&
4536 DestroyedType == E->getDestroyedType())
4537 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004538
Douglas Gregorad8a3362009-09-04 17:36:40 +00004539 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4540 E->getOperatorLoc(),
4541 E->isArrow(),
4542 E->getDestroyedTypeLoc(),
4543 DestroyedType,
4544 Qualifier,
4545 E->getQualifierRange());
4546}
Mike Stump11289f42009-09-09 15:08:12 +00004547
Douglas Gregorad8a3362009-09-04 17:36:40 +00004548template<typename Derived>
4549Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004550TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCalle66edc12009-11-24 19:00:30 +00004551 UnresolvedLookupExpr *Old,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004552 bool isAddressOfOperand) {
John McCalle66edc12009-11-24 19:00:30 +00004553 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4554
4555 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4556 Sema::LookupOrdinaryName);
4557
4558 // Transform all the decls.
4559 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4560 E = Old->decls_end(); I != E; ++I) {
4561 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
4562 if (!InstD)
4563 return SemaRef.ExprError();
4564
4565 // Expand using declarations.
4566 if (isa<UsingDecl>(InstD)) {
4567 UsingDecl *UD = cast<UsingDecl>(InstD);
4568 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4569 E = UD->shadow_end(); I != E; ++I)
4570 R.addDecl(*I);
4571 continue;
4572 }
4573
4574 R.addDecl(InstD);
4575 }
4576
4577 // Resolve a kind, but don't do any further analysis. If it's
4578 // ambiguous, the callee needs to deal with it.
4579 R.resolveKind();
4580
4581 // Rebuild the nested-name qualifier, if present.
4582 CXXScopeSpec SS;
4583 NestedNameSpecifier *Qualifier = 0;
4584 if (Old->getQualifier()) {
4585 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4586 Old->getQualifierRange());
4587 if (!Qualifier)
4588 return SemaRef.ExprError();
4589
4590 SS.setScopeRep(Qualifier);
4591 SS.setRange(Old->getQualifierRange());
4592 }
4593
4594 // If we have no template arguments, it's a normal declaration name.
4595 if (!Old->hasExplicitTemplateArgs())
4596 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4597
4598 // If we have template arguments, rebuild them, then rebuild the
4599 // templateid expression.
4600 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4601 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4602 TemplateArgumentLoc Loc;
4603 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4604 return SemaRef.ExprError();
4605 TransArgs.addArgument(Loc);
4606 }
4607
4608 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4609 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004610}
Mike Stump11289f42009-09-09 15:08:12 +00004611
Douglas Gregora16548e2009-08-11 05:31:07 +00004612template<typename Derived>
4613Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004614TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E,
4615 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004616 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004617
Douglas Gregora16548e2009-08-11 05:31:07 +00004618 QualType T = getDerived().TransformType(E->getQueriedType());
4619 if (T.isNull())
4620 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004621
Douglas Gregora16548e2009-08-11 05:31:07 +00004622 if (!getDerived().AlwaysRebuild() &&
4623 T == E->getQueriedType())
4624 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004625
Douglas Gregora16548e2009-08-11 05:31:07 +00004626 // FIXME: Bad location information
4627 SourceLocation FakeLParenLoc
4628 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004629
4630 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004631 E->getLocStart(),
4632 /*FIXME:*/FakeLParenLoc,
4633 T,
4634 E->getLocEnd());
4635}
Mike Stump11289f42009-09-09 15:08:12 +00004636
Douglas Gregora16548e2009-08-11 05:31:07 +00004637template<typename Derived>
4638Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004639TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
4640 DependentScopeDeclRefExpr *E,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004641 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004642 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004643 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4644 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004645 if (!NNS)
4646 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004647
4648 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004649 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4650 if (!Name)
4651 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004652
John McCalle66edc12009-11-24 19:00:30 +00004653 if (!E->hasExplicitTemplateArgs()) {
4654 if (!getDerived().AlwaysRebuild() &&
4655 NNS == E->getQualifier() &&
4656 Name == E->getDeclName())
4657 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004658
John McCalle66edc12009-11-24 19:00:30 +00004659 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4660 E->getQualifierRange(),
4661 Name, E->getLocation(),
4662 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004663 }
John McCall6b51f282009-11-23 01:53:49 +00004664
4665 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004666 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004667 TemplateArgumentLoc Loc;
4668 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004669 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004670 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004671 }
4672
John McCalle66edc12009-11-24 19:00:30 +00004673 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4674 E->getQualifierRange(),
4675 Name, E->getLocation(),
4676 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004677}
4678
4679template<typename Derived>
4680Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004681TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E,
4682 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004683 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4684
4685 QualType T = getDerived().TransformType(E->getType());
4686 if (T.isNull())
4687 return SemaRef.ExprError();
4688
4689 CXXConstructorDecl *Constructor
4690 = cast_or_null<CXXConstructorDecl>(
4691 getDerived().TransformDecl(E->getConstructor()));
4692 if (!Constructor)
4693 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004694
Douglas Gregora16548e2009-08-11 05:31:07 +00004695 bool ArgumentChanged = false;
4696 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004697 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004698 ArgEnd = E->arg_end();
4699 Arg != ArgEnd; ++Arg) {
4700 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4701 if (TransArg.isInvalid())
4702 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004703
Douglas Gregora16548e2009-08-11 05:31:07 +00004704 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4705 Args.push_back(TransArg.takeAs<Expr>());
4706 }
4707
4708 if (!getDerived().AlwaysRebuild() &&
4709 T == E->getType() &&
4710 Constructor == E->getConstructor() &&
4711 !ArgumentChanged)
4712 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004713
Douglas Gregora16548e2009-08-11 05:31:07 +00004714 return getDerived().RebuildCXXConstructExpr(T, Constructor, E->isElidable(),
4715 move_arg(Args));
4716}
Mike Stump11289f42009-09-09 15:08:12 +00004717
Douglas Gregora16548e2009-08-11 05:31:07 +00004718/// \brief Transform a C++ temporary-binding expression.
4719///
Mike Stump11289f42009-09-09 15:08:12 +00004720/// The transformation of a temporary-binding expression always attempts to
4721/// bind a new temporary variable to its subexpression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004722/// subexpression itself did not change, because the temporary variable itself
4723/// must be unique.
4724template<typename Derived>
4725Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004726TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E,
4727 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004728 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4729 if (SubExpr.isInvalid())
4730 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004731
Douglas Gregora16548e2009-08-11 05:31:07 +00004732 return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>());
4733}
Mike Stump11289f42009-09-09 15:08:12 +00004734
4735/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004736/// be destroyed after the expression is evaluated.
4737///
Mike Stump11289f42009-09-09 15:08:12 +00004738/// The transformation of a full expression always attempts to build a new
4739/// CXXExprWithTemporaries expression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004740/// subexpression itself did not change, because it will need to capture the
4741/// the new temporary variables introduced in the subexpression.
4742template<typename Derived>
4743Sema::OwningExprResult
4744TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004745 CXXExprWithTemporaries *E,
4746 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004747 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4748 if (SubExpr.isInvalid())
4749 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004750
Douglas Gregora16548e2009-08-11 05:31:07 +00004751 return SemaRef.Owned(
4752 SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(),
4753 E->shouldDestroyTemporaries()));
4754}
Mike Stump11289f42009-09-09 15:08:12 +00004755
Douglas Gregora16548e2009-08-11 05:31:07 +00004756template<typename Derived>
4757Sema::OwningExprResult
4758TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004759 CXXTemporaryObjectExpr *E,
4760 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004761 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4762 QualType T = getDerived().TransformType(E->getType());
4763 if (T.isNull())
4764 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004765
Douglas Gregora16548e2009-08-11 05:31:07 +00004766 CXXConstructorDecl *Constructor
4767 = cast_or_null<CXXConstructorDecl>(
4768 getDerived().TransformDecl(E->getConstructor()));
4769 if (!Constructor)
4770 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004771
Douglas Gregora16548e2009-08-11 05:31:07 +00004772 bool ArgumentChanged = false;
4773 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4774 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004775 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004776 ArgEnd = E->arg_end();
4777 Arg != ArgEnd; ++Arg) {
4778 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4779 if (TransArg.isInvalid())
4780 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004781
Douglas Gregora16548e2009-08-11 05:31:07 +00004782 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4783 Args.push_back((Expr *)TransArg.release());
4784 }
Mike Stump11289f42009-09-09 15:08:12 +00004785
Douglas Gregora16548e2009-08-11 05:31:07 +00004786 if (!getDerived().AlwaysRebuild() &&
4787 T == E->getType() &&
4788 Constructor == E->getConstructor() &&
4789 !ArgumentChanged)
4790 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004791
Douglas Gregora16548e2009-08-11 05:31:07 +00004792 // FIXME: Bogus location information
4793 SourceLocation CommaLoc;
4794 if (Args.size() > 1) {
4795 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004796 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004797 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4798 }
4799 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4800 T,
4801 /*FIXME:*/E->getTypeBeginLoc(),
4802 move_arg(Args),
4803 &CommaLoc,
4804 E->getLocEnd());
4805}
Mike Stump11289f42009-09-09 15:08:12 +00004806
Douglas Gregora16548e2009-08-11 05:31:07 +00004807template<typename Derived>
4808Sema::OwningExprResult
4809TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004810 CXXUnresolvedConstructExpr *E,
4811 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004812 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4813 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4814 if (T.isNull())
4815 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004816
Douglas Gregora16548e2009-08-11 05:31:07 +00004817 bool ArgumentChanged = false;
4818 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4819 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4820 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4821 ArgEnd = E->arg_end();
4822 Arg != ArgEnd; ++Arg) {
4823 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4824 if (TransArg.isInvalid())
4825 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004826
Douglas Gregora16548e2009-08-11 05:31:07 +00004827 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4828 FakeCommaLocs.push_back(
4829 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4830 Args.push_back(TransArg.takeAs<Expr>());
4831 }
Mike Stump11289f42009-09-09 15:08:12 +00004832
Douglas Gregora16548e2009-08-11 05:31:07 +00004833 if (!getDerived().AlwaysRebuild() &&
4834 T == E->getTypeAsWritten() &&
4835 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004836 return SemaRef.Owned(E->Retain());
4837
Douglas Gregora16548e2009-08-11 05:31:07 +00004838 // FIXME: we're faking the locations of the commas
4839 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4840 T,
4841 E->getLParenLoc(),
4842 move_arg(Args),
4843 FakeCommaLocs.data(),
4844 E->getRParenLoc());
4845}
Mike Stump11289f42009-09-09 15:08:12 +00004846
Douglas Gregora16548e2009-08-11 05:31:07 +00004847template<typename Derived>
4848Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004849TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
4850 CXXDependentScopeMemberExpr *E,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004851 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004852 // Transform the base of the expression.
4853 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4854 if (Base.isInvalid())
4855 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004856
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004857 // Start the member reference and compute the object's type.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004858 Sema::TypeTy *ObjectType = 0;
Mike Stump11289f42009-09-09 15:08:12 +00004859 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004860 E->getOperatorLoc(),
4861 E->isArrow()? tok::arrow : tok::period,
4862 ObjectType);
4863 if (Base.isInvalid())
4864 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004865
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004866 // Transform the first part of the nested-name-specifier that qualifies
4867 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004868 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004869 = getDerived().TransformFirstQualifierInScope(
4870 E->getFirstQualifierFoundInScope(),
4871 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00004872
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004873 NestedNameSpecifier *Qualifier = 0;
4874 if (E->getQualifier()) {
4875 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4876 E->getQualifierRange(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004877 QualType::getFromOpaquePtr(ObjectType),
4878 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004879 if (!Qualifier)
4880 return SemaRef.ExprError();
4881 }
Mike Stump11289f42009-09-09 15:08:12 +00004882
4883 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00004884 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
4885 QualType::getFromOpaquePtr(ObjectType));
Douglas Gregorf816bd72009-09-03 22:13:48 +00004886 if (!Name)
4887 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004888
Douglas Gregor308047d2009-09-09 00:23:06 +00004889 if (!E->hasExplicitTemplateArgumentList()) {
4890 // This is a reference to a member without an explicitly-specified
4891 // template argument list. Optimize for this common case.
4892 if (!getDerived().AlwaysRebuild() &&
4893 Base.get() == E->getBase() &&
4894 Qualifier == E->getQualifier() &&
4895 Name == E->getMember() &&
4896 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00004897 return SemaRef.Owned(E->Retain());
4898
John McCall8cd78132009-11-19 22:55:06 +00004899 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
Douglas Gregor308047d2009-09-09 00:23:06 +00004900 E->isArrow(),
4901 E->getOperatorLoc(),
4902 Qualifier,
4903 E->getQualifierRange(),
4904 Name,
4905 E->getMemberLoc(),
4906 FirstQualifierInScope);
4907 }
4908
4909 // FIXME: This is an ugly hack, which forces the same template name to
4910 // be looked up multiple times. Yuck!
Douglas Gregor71395fa2009-11-04 00:56:37 +00004911 TemporaryBase Rebase(*this, E->getMemberLoc(), DeclarationName());
4912 TemplateName OrigTemplateName;
4913 if (const IdentifierInfo *II = Name.getAsIdentifierInfo())
4914 OrigTemplateName = SemaRef.Context.getDependentTemplateName(0, II);
4915 else
4916 OrigTemplateName
4917 = SemaRef.Context.getDependentTemplateName(0,
4918 Name.getCXXOverloadedOperator());
Mike Stump11289f42009-09-09 15:08:12 +00004919
4920 TemplateName Template
4921 = getDerived().TransformTemplateName(OrigTemplateName,
Douglas Gregor308047d2009-09-09 00:23:06 +00004922 QualType::getFromOpaquePtr(ObjectType));
4923 if (Template.isNull())
4924 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004925
John McCall6b51f282009-11-23 01:53:49 +00004926 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00004927 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004928 TemplateArgumentLoc Loc;
4929 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00004930 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004931 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00004932 }
Mike Stump11289f42009-09-09 15:08:12 +00004933
John McCall8cd78132009-11-19 22:55:06 +00004934 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
Douglas Gregora16548e2009-08-11 05:31:07 +00004935 E->isArrow(),
4936 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004937 Qualifier,
4938 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004939 Template,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004940 E->getMemberLoc(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004941 FirstQualifierInScope,
John McCall6b51f282009-11-23 01:53:49 +00004942 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004943}
4944
4945template<typename Derived>
4946Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004947TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E,
4948 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004949 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004950}
4951
Mike Stump11289f42009-09-09 15:08:12 +00004952template<typename Derived>
4953Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004954TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E,
4955 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004956 // FIXME: poor source location
4957 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
4958 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
4959 if (EncodedType.isNull())
4960 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004961
Douglas Gregora16548e2009-08-11 05:31:07 +00004962 if (!getDerived().AlwaysRebuild() &&
4963 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00004964 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004965
4966 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
4967 EncodedType,
4968 E->getRParenLoc());
4969}
Mike Stump11289f42009-09-09 15:08:12 +00004970
Douglas Gregora16548e2009-08-11 05:31:07 +00004971template<typename Derived>
4972Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004973TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E,
4974 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004975 // FIXME: Implement this!
4976 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004977 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004978}
4979
Mike Stump11289f42009-09-09 15:08:12 +00004980template<typename Derived>
4981Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004982TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E,
4983 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004984 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004985}
4986
Mike Stump11289f42009-09-09 15:08:12 +00004987template<typename Derived>
4988Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004989TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E,
4990 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004991 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00004992 = cast_or_null<ObjCProtocolDecl>(
4993 getDerived().TransformDecl(E->getProtocol()));
4994 if (!Protocol)
4995 return SemaRef.ExprError();
4996
4997 if (!getDerived().AlwaysRebuild() &&
4998 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00004999 return SemaRef.Owned(E->Retain());
5000
Douglas Gregora16548e2009-08-11 05:31:07 +00005001 return getDerived().RebuildObjCProtocolExpr(Protocol,
5002 E->getAtLoc(),
5003 /*FIXME:*/E->getAtLoc(),
5004 /*FIXME:*/E->getAtLoc(),
5005 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005006
Douglas Gregora16548e2009-08-11 05:31:07 +00005007}
5008
Mike Stump11289f42009-09-09 15:08:12 +00005009template<typename Derived>
5010Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005011TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E,
5012 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005013 // FIXME: Implement this!
5014 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005015 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005016}
5017
Mike Stump11289f42009-09-09 15:08:12 +00005018template<typename Derived>
5019Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005020TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E,
5021 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005022 // FIXME: Implement this!
5023 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005024 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005025}
5026
Mike Stump11289f42009-09-09 15:08:12 +00005027template<typename Derived>
5028Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005029TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005030 ObjCImplicitSetterGetterRefExpr *E,
5031 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005032 // FIXME: Implement this!
5033 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005034 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005035}
5036
Mike Stump11289f42009-09-09 15:08:12 +00005037template<typename Derived>
5038Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005039TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E,
5040 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005041 // FIXME: Implement this!
5042 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005043 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005044}
5045
Mike Stump11289f42009-09-09 15:08:12 +00005046template<typename Derived>
5047Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005048TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E,
5049 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005050 // FIXME: Implement this!
5051 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005052 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005053}
5054
Mike Stump11289f42009-09-09 15:08:12 +00005055template<typename Derived>
5056Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005057TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E,
5058 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005059 bool ArgumentChanged = false;
5060 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5061 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5062 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5063 if (SubExpr.isInvalid())
5064 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005065
Douglas Gregora16548e2009-08-11 05:31:07 +00005066 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5067 SubExprs.push_back(SubExpr.takeAs<Expr>());
5068 }
Mike Stump11289f42009-09-09 15:08:12 +00005069
Douglas Gregora16548e2009-08-11 05:31:07 +00005070 if (!getDerived().AlwaysRebuild() &&
5071 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005072 return SemaRef.Owned(E->Retain());
5073
Douglas Gregora16548e2009-08-11 05:31:07 +00005074 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5075 move_arg(SubExprs),
5076 E->getRParenLoc());
5077}
5078
Mike Stump11289f42009-09-09 15:08:12 +00005079template<typename Derived>
5080Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005081TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E,
5082 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005083 // FIXME: Implement this!
5084 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005085 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005086}
5087
Mike Stump11289f42009-09-09 15:08:12 +00005088template<typename Derived>
5089Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005090TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E,
5091 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005092 // FIXME: Implement this!
5093 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005094 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005095}
Mike Stump11289f42009-09-09 15:08:12 +00005096
Douglas Gregora16548e2009-08-11 05:31:07 +00005097//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005098// Type reconstruction
5099//===----------------------------------------------------------------------===//
5100
Mike Stump11289f42009-09-09 15:08:12 +00005101template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005102QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5103 SourceLocation Star) {
5104 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005105 getDerived().getBaseEntity());
5106}
5107
Mike Stump11289f42009-09-09 15:08:12 +00005108template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005109QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5110 SourceLocation Star) {
5111 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005112 getDerived().getBaseEntity());
5113}
5114
Mike Stump11289f42009-09-09 15:08:12 +00005115template<typename Derived>
5116QualType
John McCall70dd5f62009-10-30 00:06:24 +00005117TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5118 bool WrittenAsLValue,
5119 SourceLocation Sigil) {
5120 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5121 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005122}
5123
5124template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005125QualType
John McCall70dd5f62009-10-30 00:06:24 +00005126TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5127 QualType ClassType,
5128 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005129 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005130 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005131}
5132
5133template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005134QualType
John McCall70dd5f62009-10-30 00:06:24 +00005135TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5136 SourceLocation Sigil) {
5137 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005138 getDerived().getBaseEntity());
5139}
5140
5141template<typename Derived>
5142QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005143TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5144 ArrayType::ArraySizeModifier SizeMod,
5145 const llvm::APInt *Size,
5146 Expr *SizeExpr,
5147 unsigned IndexTypeQuals,
5148 SourceRange BracketsRange) {
5149 if (SizeExpr || !Size)
5150 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5151 IndexTypeQuals, BracketsRange,
5152 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005153
5154 QualType Types[] = {
5155 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5156 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5157 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005158 };
5159 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5160 QualType SizeType;
5161 for (unsigned I = 0; I != NumTypes; ++I)
5162 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5163 SizeType = Types[I];
5164 break;
5165 }
Mike Stump11289f42009-09-09 15:08:12 +00005166
Douglas Gregord6ff3322009-08-04 16:50:30 +00005167 if (SizeType.isNull())
5168 SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false);
Mike Stump11289f42009-09-09 15:08:12 +00005169
Douglas Gregord6ff3322009-08-04 16:50:30 +00005170 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005171 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005172 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005173 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005174}
Mike Stump11289f42009-09-09 15:08:12 +00005175
Douglas Gregord6ff3322009-08-04 16:50:30 +00005176template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005177QualType
5178TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005179 ArrayType::ArraySizeModifier SizeMod,
5180 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005181 unsigned IndexTypeQuals,
5182 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005183 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005184 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005185}
5186
5187template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005188QualType
Mike Stump11289f42009-09-09 15:08:12 +00005189TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005190 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005191 unsigned IndexTypeQuals,
5192 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005193 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005194 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005195}
Mike Stump11289f42009-09-09 15:08:12 +00005196
Douglas Gregord6ff3322009-08-04 16:50:30 +00005197template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005198QualType
5199TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005200 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005201 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005202 unsigned IndexTypeQuals,
5203 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005204 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005205 SizeExpr.takeAs<Expr>(),
5206 IndexTypeQuals, BracketsRange);
5207}
5208
5209template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005210QualType
5211TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005212 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005213 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005214 unsigned IndexTypeQuals,
5215 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005216 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005217 SizeExpr.takeAs<Expr>(),
5218 IndexTypeQuals, BracketsRange);
5219}
5220
5221template<typename Derived>
5222QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
5223 unsigned NumElements) {
5224 // FIXME: semantic checking!
5225 return SemaRef.Context.getVectorType(ElementType, NumElements);
5226}
Mike Stump11289f42009-09-09 15:08:12 +00005227
Douglas Gregord6ff3322009-08-04 16:50:30 +00005228template<typename Derived>
5229QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5230 unsigned NumElements,
5231 SourceLocation AttributeLoc) {
5232 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5233 NumElements, true);
5234 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005235 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005236 AttributeLoc);
5237 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5238 AttributeLoc);
5239}
Mike Stump11289f42009-09-09 15:08:12 +00005240
Douglas Gregord6ff3322009-08-04 16:50:30 +00005241template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005242QualType
5243TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005244 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005245 SourceLocation AttributeLoc) {
5246 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5247}
Mike Stump11289f42009-09-09 15:08:12 +00005248
Douglas Gregord6ff3322009-08-04 16:50:30 +00005249template<typename Derived>
5250QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005251 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005252 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005253 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005254 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005255 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005256 Quals,
5257 getDerived().getBaseLocation(),
5258 getDerived().getBaseEntity());
5259}
Mike Stump11289f42009-09-09 15:08:12 +00005260
Douglas Gregord6ff3322009-08-04 16:50:30 +00005261template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005262QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5263 return SemaRef.Context.getFunctionNoProtoType(T);
5264}
5265
5266template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005267QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005268 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5269}
5270
5271template<typename Derived>
5272QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5273 return SemaRef.Context.getTypeOfType(Underlying);
5274}
5275
5276template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005277QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005278 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5279}
5280
5281template<typename Derived>
5282QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005283 TemplateName Template,
5284 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005285 const TemplateArgumentListInfo &TemplateArgs) {
5286 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005287}
Mike Stump11289f42009-09-09 15:08:12 +00005288
Douglas Gregor1135c352009-08-06 05:28:30 +00005289template<typename Derived>
5290NestedNameSpecifier *
5291TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5292 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005293 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005294 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005295 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005296 CXXScopeSpec SS;
5297 // FIXME: The source location information is all wrong.
5298 SS.setRange(Range);
5299 SS.setScopeRep(Prefix);
5300 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005301 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005302 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005303 ObjectType,
5304 FirstQualifierInScope,
Douglas Gregore861bac2009-08-25 22:51:20 +00005305 false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005306}
5307
5308template<typename Derived>
5309NestedNameSpecifier *
5310TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5311 SourceRange Range,
5312 NamespaceDecl *NS) {
5313 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5314}
5315
5316template<typename Derived>
5317NestedNameSpecifier *
5318TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5319 SourceRange Range,
5320 bool TemplateKW,
5321 QualType T) {
5322 if (T->isDependentType() || T->isRecordType() ||
5323 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005324 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005325 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5326 T.getTypePtr());
5327 }
Mike Stump11289f42009-09-09 15:08:12 +00005328
Douglas Gregor1135c352009-08-06 05:28:30 +00005329 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5330 return 0;
5331}
Mike Stump11289f42009-09-09 15:08:12 +00005332
Douglas Gregor71dc5092009-08-06 06:41:21 +00005333template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005334TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005335TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5336 bool TemplateKW,
5337 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005338 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005339 Template);
5340}
5341
5342template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005343TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005344TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005345 const IdentifierInfo &II,
5346 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005347 CXXScopeSpec SS;
5348 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005349 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005350 UnqualifiedId Name;
5351 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005352 return getSema().ActOnDependentTemplateName(
5353 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005354 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005355 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005356 ObjectType.getAsOpaquePtr(),
5357 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005358 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005359}
Mike Stump11289f42009-09-09 15:08:12 +00005360
Douglas Gregora16548e2009-08-11 05:31:07 +00005361template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005362TemplateName
5363TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5364 OverloadedOperatorKind Operator,
5365 QualType ObjectType) {
5366 CXXScopeSpec SS;
5367 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5368 SS.setScopeRep(Qualifier);
5369 UnqualifiedId Name;
5370 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5371 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5372 Operator, SymbolLocations);
5373 return getSema().ActOnDependentTemplateName(
5374 /*FIXME:*/getDerived().getBaseLocation(),
5375 SS,
5376 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005377 ObjectType.getAsOpaquePtr(),
5378 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005379 .template getAsVal<TemplateName>();
5380}
5381
5382template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005383Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005384TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5385 SourceLocation OpLoc,
5386 ExprArg Callee,
5387 ExprArg First,
5388 ExprArg Second) {
5389 Expr *FirstExpr = (Expr *)First.get();
5390 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005391 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005392 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005393
Douglas Gregora16548e2009-08-11 05:31:07 +00005394 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005395 if (Op == OO_Subscript) {
5396 if (!FirstExpr->getType()->isOverloadableType() &&
5397 !SecondExpr->getType()->isOverloadableType())
5398 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005399 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005400 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005401 } else if (Op == OO_Arrow) {
5402 // -> is never a builtin operation.
5403 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005404 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005405 if (!FirstExpr->getType()->isOverloadableType()) {
5406 // The argument is not of overloadable type, so try to create a
5407 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005408 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005409 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005410
Douglas Gregora16548e2009-08-11 05:31:07 +00005411 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5412 }
5413 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005414 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005415 !SecondExpr->getType()->isOverloadableType()) {
5416 // Neither of the arguments is an overloadable type, so try to
5417 // create a built-in binary operation.
5418 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005419 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005420 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5421 if (Result.isInvalid())
5422 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005423
Douglas Gregora16548e2009-08-11 05:31:07 +00005424 First.release();
5425 Second.release();
5426 return move(Result);
5427 }
5428 }
Mike Stump11289f42009-09-09 15:08:12 +00005429
5430 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005431 // used during overload resolution.
5432 Sema::FunctionSet Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005433
John McCalld14a8642009-11-21 08:51:07 +00005434 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5435 assert(ULE->requiresADL());
5436
5437 // FIXME: Do we have to check
5438 // IsAcceptableNonMemberOperatorCandidate for each of these?
5439 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(),
5440 E = ULE->decls_end(); I != E; ++I)
5441 Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I));
5442 } else {
5443 Functions.insert(AnyFunctionDecl::getFromNamedDecl(
5444 cast<DeclRefExpr>(CalleeExpr)->getDecl()));
5445 }
Mike Stump11289f42009-09-09 15:08:12 +00005446
Douglas Gregora16548e2009-08-11 05:31:07 +00005447 // Add any functions found via argument-dependent lookup.
5448 Expr *Args[2] = { FirstExpr, SecondExpr };
5449 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005450 DeclarationName OpName
Douglas Gregora16548e2009-08-11 05:31:07 +00005451 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
Sebastian Redlc057f422009-10-23 19:23:15 +00005452 SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs,
5453 Functions);
Mike Stump11289f42009-09-09 15:08:12 +00005454
Douglas Gregora16548e2009-08-11 05:31:07 +00005455 // Create the overloaded operator invocation for unary operators.
5456 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005457 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005458 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5459 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5460 }
Mike Stump11289f42009-09-09 15:08:12 +00005461
Sebastian Redladba46e2009-10-29 20:17:01 +00005462 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005463 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5464 OpLoc,
5465 move(First),
5466 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005467
Douglas Gregora16548e2009-08-11 05:31:07 +00005468 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005469 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005470 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005471 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005472 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5473 if (Result.isInvalid())
5474 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005475
Douglas Gregora16548e2009-08-11 05:31:07 +00005476 First.release();
5477 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005478 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005479}
Mike Stump11289f42009-09-09 15:08:12 +00005480
Douglas Gregord6ff3322009-08-04 16:50:30 +00005481} // end namespace clang
5482
5483#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H