blob: d226c1eb5c251162317f2b3f1127536c8a5fa57f [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"
Douglas Gregor1135c352009-08-06 05:28:30 +000017#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000019#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000020#include "clang/AST/ExprCXX.h"
21#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000022#include "clang/AST/Stmt.h"
23#include "clang/AST/StmtCXX.h"
24#include "clang/AST/StmtObjC.h"
John McCall550e0c22009-10-21 00:40:46 +000025#include "clang/AST/TypeLocBuilder.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000026#include "clang/Parse/Ownership.h"
27#include "clang/Parse/Designator.h"
28#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000029#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000030#include <algorithm>
31
32namespace clang {
Mike Stump11289f42009-09-09 15:08:12 +000033
Douglas Gregord6ff3322009-08-04 16:50:30 +000034/// \brief A semantic tree transformation that allows one to transform one
35/// abstract syntax tree into another.
36///
Mike Stump11289f42009-09-09 15:08:12 +000037/// A new tree transformation is defined by creating a new subclass \c X of
38/// \c TreeTransform<X> and then overriding certain operations to provide
39/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000040/// instantiation is implemented as a tree transformation where the
41/// transformation of TemplateTypeParmType nodes involves substituting the
42/// template arguments for their corresponding template parameters; a similar
43/// transformation is performed for non-type template parameters and
44/// template template parameters.
45///
46/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000047/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// override any of the transformation or rebuild operators by providing an
49/// operation with the same signature as the default implementation. The
50/// overridding function should not be virtual.
51///
52/// Semantic tree transformations are split into two stages, either of which
53/// can be replaced by a subclass. The "transform" step transforms an AST node
54/// or the parts of an AST node using the various transformation functions,
55/// then passes the pieces on to the "rebuild" step, which constructs a new AST
56/// node of the appropriate kind from the pieces. The default transformation
57/// routines recursively transform the operands to composite AST nodes (e.g.,
58/// the pointee type of a PointerType node) and, if any of those operand nodes
59/// were changed by the transformation, invokes the rebuild operation to create
60/// a new AST node.
61///
Mike Stump11289f42009-09-09 15:08:12 +000062/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000063/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000064/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
65/// TransformTemplateName(), or TransformTemplateArgument() with entirely
66/// new implementations.
67///
68/// For more fine-grained transformations, subclasses can replace any of the
69/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000070/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000071/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000072/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// parameters. Additionally, subclasses can override the \c RebuildXXX
74/// functions to control how AST nodes are rebuilt when their operands change.
75/// By default, \c TreeTransform will invoke semantic analysis to rebuild
76/// AST nodes. However, certain other tree transformations (e.g, cloning) may
77/// be able to use more efficient rebuild steps.
78///
79/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000080/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
82/// operands have not changed (\c AlwaysRebuild()), and customize the
83/// default locations and entity names used for type-checking
84/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000085template<typename Derived>
86class TreeTransform {
87protected:
88 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000089
90public:
Douglas Gregora16548e2009-08-11 05:31:07 +000091 typedef Sema::OwningStmtResult OwningStmtResult;
92 typedef Sema::OwningExprResult OwningExprResult;
93 typedef Sema::StmtArg StmtArg;
94 typedef Sema::ExprArg ExprArg;
95 typedef Sema::MultiExprArg MultiExprArg;
Douglas Gregorebe10102009-08-20 07:17:43 +000096 typedef Sema::MultiStmtArg MultiStmtArg;
Mike Stump11289f42009-09-09 15:08:12 +000097
Douglas Gregord6ff3322009-08-04 16:50:30 +000098 /// \brief Initializes a new tree transformer.
99 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000100
Douglas Gregord6ff3322009-08-04 16:50:30 +0000101 /// \brief Retrieves a reference to the derived class.
102 Derived &getDerived() { return static_cast<Derived&>(*this); }
103
104 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000105 const Derived &getDerived() const {
106 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000107 }
108
109 /// \brief Retrieves a reference to the semantic analysis object used for
110 /// this tree transform.
111 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113 /// \brief Whether the transformation should always rebuild AST nodes, even
114 /// if none of the children have changed.
115 ///
116 /// Subclasses may override this function to specify when the transformation
117 /// should rebuild all AST nodes.
118 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000119
Douglas Gregord6ff3322009-08-04 16:50:30 +0000120 /// \brief Returns the location of the entity being transformed, if that
121 /// information was not available elsewhere in the AST.
122 ///
Mike Stump11289f42009-09-09 15:08:12 +0000123 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// provide an alternative implementation that provides better location
125 /// information.
126 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000127
Douglas Gregord6ff3322009-08-04 16:50:30 +0000128 /// \brief Returns the name of the entity being transformed, if that
129 /// information was not available elsewhere in the AST.
130 ///
131 /// By default, returns an empty name. Subclasses can provide an alternative
132 /// implementation with a more precise name.
133 DeclarationName getBaseEntity() { return DeclarationName(); }
134
Douglas Gregora16548e2009-08-11 05:31:07 +0000135 /// \brief Sets the "base" location and entity when that
136 /// information is known based on another transformation.
137 ///
138 /// By default, the source location and entity are ignored. Subclasses can
139 /// override this function to provide a customized implementation.
140 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000141
Douglas Gregora16548e2009-08-11 05:31:07 +0000142 /// \brief RAII object that temporarily sets the base location and entity
143 /// used for reporting diagnostics in types.
144 class TemporaryBase {
145 TreeTransform &Self;
146 SourceLocation OldLocation;
147 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000148
Douglas Gregora16548e2009-08-11 05:31:07 +0000149 public:
150 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000151 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000152 OldLocation = Self.getDerived().getBaseLocation();
153 OldEntity = Self.getDerived().getBaseEntity();
154 Self.getDerived().setBase(Location, Entity);
155 }
Mike Stump11289f42009-09-09 15:08:12 +0000156
Douglas Gregora16548e2009-08-11 05:31:07 +0000157 ~TemporaryBase() {
158 Self.getDerived().setBase(OldLocation, OldEntity);
159 }
160 };
Mike Stump11289f42009-09-09 15:08:12 +0000161
162 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000163 /// transformed.
164 ///
165 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000166 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000167 /// not change. For example, template instantiation need not traverse
168 /// non-dependent types.
169 bool AlreadyTransformed(QualType T) {
170 return T.isNull();
171 }
172
173 /// \brief Transforms the given type into another type.
174 ///
John McCall550e0c22009-10-21 00:40:46 +0000175 /// By default, this routine transforms a type by creating a
176 /// DeclaratorInfo for it and delegating to the appropriate
177 /// function. This is expensive, but we don't mind, because
178 /// this method is deprecated anyway; all users should be
179 /// switched to storing DeclaratorInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000180 ///
181 /// \returns the transformed type.
182 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000183
John McCall550e0c22009-10-21 00:40:46 +0000184 /// \brief Transforms the given type-with-location into a new
185 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000186 ///
John McCall550e0c22009-10-21 00:40:46 +0000187 /// By default, this routine transforms a type by delegating to the
188 /// appropriate TransformXXXType to build a new type. Subclasses
189 /// may override this function (to take over all type
190 /// transformations) or some set of the TransformXXXType functions
191 /// to alter the transformation.
192 DeclaratorInfo *TransformType(DeclaratorInfo *DI);
193
194 /// \brief Transform the given type-with-location into a new
195 /// type, collecting location information in the given builder
196 /// as necessary.
197 ///
198 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000199
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000200 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000201 ///
Mike Stump11289f42009-09-09 15:08:12 +0000202 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000203 /// appropriate TransformXXXStmt function to transform a specific kind of
204 /// statement or the TransformExpr() function to transform an expression.
205 /// Subclasses may override this function to transform statements using some
206 /// other mechanism.
207 ///
208 /// \returns the transformed statement.
Douglas Gregora16548e2009-08-11 05:31:07 +0000209 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000210
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000211 /// \brief Transform the given expression.
212 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000213 /// By default, this routine transforms an expression by delegating to the
214 /// appropriate TransformXXXExpr function to build a new expression.
215 /// Subclasses may override this function to transform expressions using some
216 /// other mechanism.
217 ///
218 /// \returns the transformed expression.
219 OwningExprResult TransformExpr(Expr *E) {
220 return getDerived().TransformExpr(E, /*isAddressOfOperand=*/false);
221 }
222
223 /// \brief Transform the given expression.
224 ///
225 /// By default, this routine transforms an expression by delegating to the
226 /// appropriate TransformXXXExpr function to build a new expression.
227 /// Subclasses may override this function to transform expressions using some
228 /// other mechanism.
229 ///
230 /// \returns the transformed expression.
231 OwningExprResult TransformExpr(Expr *E, bool isAddressOfOperand);
Mike Stump11289f42009-09-09 15:08:12 +0000232
Douglas Gregord6ff3322009-08-04 16:50:30 +0000233 /// \brief Transform the given declaration, which is referenced from a type
234 /// or expression.
235 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000236 /// By default, acts as the identity function on declarations. Subclasses
237 /// may override this function to provide alternate behavior.
238 Decl *TransformDecl(Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000239
240 /// \brief Transform the definition of the given declaration.
241 ///
Mike Stump11289f42009-09-09 15:08:12 +0000242 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000243 /// Subclasses may override this function to provide alternate behavior.
244 Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); }
Mike Stump11289f42009-09-09 15:08:12 +0000245
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000246 /// \brief Transform the given declaration, which was the first part of a
247 /// nested-name-specifier in a member access expression.
248 ///
249 /// This specific declaration transformation only applies to the first
250 /// identifier in a nested-name-specifier of a member access expression, e.g.,
251 /// the \c T in \c x->T::member
252 ///
253 /// By default, invokes TransformDecl() to transform the declaration.
254 /// Subclasses may override this function to provide alternate behavior.
255 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
256 return cast_or_null<NamedDecl>(getDerived().TransformDecl(D));
257 }
258
Douglas Gregord6ff3322009-08-04 16:50:30 +0000259 /// \brief Transform the given nested-name-specifier.
260 ///
Mike Stump11289f42009-09-09 15:08:12 +0000261 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000262 /// nested-name-specifier. Subclasses may override this function to provide
263 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000264 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000265 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000266 QualType ObjectType = QualType(),
267 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000268
Douglas Gregorf816bd72009-09-03 22:13:48 +0000269 /// \brief Transform the given declaration name.
270 ///
271 /// By default, transforms the types of conversion function, constructor,
272 /// and destructor names and then (if needed) rebuilds the declaration name.
273 /// Identifiers and selectors are returned unmodified. Sublcasses may
274 /// override this function to provide alternate behavior.
275 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +0000276 SourceLocation Loc,
277 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000278
Douglas Gregord6ff3322009-08-04 16:50:30 +0000279 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000280 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000281 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000282 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000283 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000284 TemplateName TransformTemplateName(TemplateName Name,
285 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000286
Douglas Gregord6ff3322009-08-04 16:50:30 +0000287 /// \brief Transform the given template argument.
288 ///
Mike Stump11289f42009-09-09 15:08:12 +0000289 /// By default, this operation transforms the type, expression, or
290 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000291 /// new template argument from the transformed result. Subclasses may
292 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000293 ///
294 /// Returns true if there was an error.
295 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
296 TemplateArgumentLoc &Output);
297
298 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
299 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
300 TemplateArgumentLoc &ArgLoc);
301
302 /// \brief Fakes up a DeclaratorInfo for a type.
303 DeclaratorInfo *InventDeclaratorInfo(QualType T) {
304 return SemaRef.Context.getTrivialDeclaratorInfo(T,
305 getDerived().getBaseLocation());
306 }
Mike Stump11289f42009-09-09 15:08:12 +0000307
John McCall550e0c22009-10-21 00:40:46 +0000308#define ABSTRACT_TYPELOC(CLASS, PARENT)
309#define TYPELOC(CLASS, PARENT) \
310 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
311#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000312
John McCall70dd5f62009-10-30 00:06:24 +0000313 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
314
Douglas Gregorc59e5612009-10-19 22:04:39 +0000315 QualType
316 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
317 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000318
319 QualType
320 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
321 TemplateSpecializationTypeLoc TL,
322 QualType ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +0000323
Douglas Gregorebe10102009-08-20 07:17:43 +0000324 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Mike Stump11289f42009-09-09 15:08:12 +0000325
Douglas Gregorebe10102009-08-20 07:17:43 +0000326#define STMT(Node, Parent) \
327 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000328#define EXPR(Node, Parent) \
Douglas Gregorc95a1fa2009-11-04 07:01:15 +0000329 OwningExprResult Transform##Node(Node *E, bool isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +0000330#define ABSTRACT_EXPR(Node, Parent)
331#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000332
Douglas Gregord6ff3322009-08-04 16:50:30 +0000333 /// \brief Build a new pointer type given its pointee type.
334 ///
335 /// By default, performs semantic analysis when building the pointer type.
336 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000337 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000338
339 /// \brief Build a new block pointer type given its pointee type.
340 ///
Mike Stump11289f42009-09-09 15:08:12 +0000341 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000342 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000343 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000344
John McCall70dd5f62009-10-30 00:06:24 +0000345 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000346 ///
John McCall70dd5f62009-10-30 00:06:24 +0000347 /// By default, performs semantic analysis when building the
348 /// reference type. Subclasses may override this routine to provide
349 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 ///
John McCall70dd5f62009-10-30 00:06:24 +0000351 /// \param LValue whether the type was written with an lvalue sigil
352 /// or an rvalue sigil.
353 QualType RebuildReferenceType(QualType ReferentType,
354 bool LValue,
355 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000356
Douglas Gregord6ff3322009-08-04 16:50:30 +0000357 /// \brief Build a new member pointer type given the pointee type and the
358 /// class type it refers into.
359 ///
360 /// By default, performs semantic analysis when building the member pointer
361 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000362 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
363 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000364
John McCall550e0c22009-10-21 00:40:46 +0000365 /// \brief Build a new Objective C object pointer type.
John McCall70dd5f62009-10-30 00:06:24 +0000366 QualType RebuildObjCObjectPointerType(QualType PointeeType,
367 SourceLocation Sigil);
John McCall550e0c22009-10-21 00:40:46 +0000368
Douglas Gregord6ff3322009-08-04 16:50:30 +0000369 /// \brief Build a new array type given the element type, size
370 /// modifier, size of the array (if known), size expression, and index type
371 /// qualifiers.
372 ///
373 /// By default, performs semantic analysis when building the array type.
374 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000375 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000376 QualType RebuildArrayType(QualType ElementType,
377 ArrayType::ArraySizeModifier SizeMod,
378 const llvm::APInt *Size,
379 Expr *SizeExpr,
380 unsigned IndexTypeQuals,
381 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000382
Douglas Gregord6ff3322009-08-04 16:50:30 +0000383 /// \brief Build a new constant array type given the element type, size
384 /// modifier, (known) size of the array, and index type qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000388 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000389 ArrayType::ArraySizeModifier SizeMod,
390 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000391 unsigned IndexTypeQuals,
392 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000393
Douglas Gregord6ff3322009-08-04 16:50:30 +0000394 /// \brief Build a new incomplete array type given the element type, size
395 /// modifier, and index type qualifiers.
396 ///
397 /// By default, performs semantic analysis when building the array type.
398 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000399 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000400 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000401 unsigned IndexTypeQuals,
402 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000403
Mike Stump11289f42009-09-09 15:08:12 +0000404 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000405 /// size modifier, size expression, and index type qualifiers.
406 ///
407 /// By default, performs semantic analysis when building the array type.
408 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000409 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000410 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000411 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000412 unsigned IndexTypeQuals,
413 SourceRange BracketsRange);
414
Mike Stump11289f42009-09-09 15:08:12 +0000415 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416 /// size modifier, size expression, and index type qualifiers.
417 ///
418 /// By default, performs semantic analysis when building the array type.
419 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000420 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000421 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000422 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 unsigned IndexTypeQuals,
424 SourceRange BracketsRange);
425
426 /// \brief Build a new vector type given the element type and
427 /// number of elements.
428 ///
429 /// By default, performs semantic analysis when building the vector type.
430 /// Subclasses may override this routine to provide different behavior.
431 QualType RebuildVectorType(QualType ElementType, unsigned NumElements);
Mike Stump11289f42009-09-09 15:08:12 +0000432
Douglas Gregord6ff3322009-08-04 16:50:30 +0000433 /// \brief Build a new extended vector type given the element type and
434 /// number of elements.
435 ///
436 /// By default, performs semantic analysis when building the vector type.
437 /// Subclasses may override this routine to provide different behavior.
438 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
439 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000440
441 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000442 /// given the element type and number of elements.
443 ///
444 /// By default, performs semantic analysis when building the vector type.
445 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000446 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000447 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000448 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 /// \brief Build a new function type.
451 ///
452 /// By default, performs semantic analysis when building the function type.
453 /// Subclasses may override this routine to provide different behavior.
454 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000455 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000456 unsigned NumParamTypes,
457 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000458
John McCall550e0c22009-10-21 00:40:46 +0000459 /// \brief Build a new unprototyped function type.
460 QualType RebuildFunctionNoProtoType(QualType ResultType);
461
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 /// \brief Build a new typedef type.
463 QualType RebuildTypedefType(TypedefDecl *Typedef) {
464 return SemaRef.Context.getTypeDeclType(Typedef);
465 }
466
467 /// \brief Build a new class/struct/union type.
468 QualType RebuildRecordType(RecordDecl *Record) {
469 return SemaRef.Context.getTypeDeclType(Record);
470 }
471
472 /// \brief Build a new Enum type.
473 QualType RebuildEnumType(EnumDecl *Enum) {
474 return SemaRef.Context.getTypeDeclType(Enum);
475 }
John McCallfcc33b02009-09-05 00:15:47 +0000476
477 /// \brief Build a new elaborated type.
478 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
479 return SemaRef.Context.getElaboratedType(T, Tag);
480 }
Mike Stump11289f42009-09-09 15:08:12 +0000481
482 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000483 ///
484 /// By default, performs semantic analysis when building the typeof type.
485 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000486 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000487
Mike Stump11289f42009-09-09 15:08:12 +0000488 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000489 ///
490 /// By default, builds a new TypeOfType with the given underlying type.
491 QualType RebuildTypeOfType(QualType Underlying);
492
Mike Stump11289f42009-09-09 15:08:12 +0000493 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000494 ///
495 /// By default, performs semantic analysis when building the decltype type.
496 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000497 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000498
Douglas Gregord6ff3322009-08-04 16:50:30 +0000499 /// \brief Build a new template specialization type.
500 ///
501 /// By default, performs semantic analysis when building the template
502 /// specialization type. Subclasses may override this routine to provide
503 /// different behavior.
504 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000505 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000506 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000507
Douglas Gregord6ff3322009-08-04 16:50:30 +0000508 /// \brief Build a new qualified name type.
509 ///
Mike Stump11289f42009-09-09 15:08:12 +0000510 /// By default, builds a new QualifiedNameType type from the
511 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 /// this routine to provide different behavior.
513 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
514 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000515 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000516
517 /// \brief Build a new typename type that refers to a template-id.
518 ///
519 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000520 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000521 /// different behavior.
522 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
523 if (NNS->isDependent())
Mike Stump11289f42009-09-09 15:08:12 +0000524 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000525 cast<TemplateSpecializationType>(T));
Mike Stump11289f42009-09-09 15:08:12 +0000526
Douglas Gregord6ff3322009-08-04 16:50:30 +0000527 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000528 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000529
530 /// \brief Build a new typename type that refers to an identifier.
531 ///
532 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000533 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000534 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000535 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall0ad16662009-10-29 08:12:44 +0000536 const IdentifierInfo *Id,
537 SourceRange SR) {
538 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregor1135c352009-08-06 05:28:30 +0000539 }
Mike Stump11289f42009-09-09 15:08:12 +0000540
Douglas Gregor1135c352009-08-06 05:28:30 +0000541 /// \brief Build a new nested-name-specifier given the prefix and an
542 /// identifier that names the next step in the nested-name-specifier.
543 ///
544 /// By default, performs semantic analysis when building the new
545 /// nested-name-specifier. Subclasses may override this routine to provide
546 /// different behavior.
547 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
548 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000549 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000550 QualType ObjectType,
551 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000552
553 /// \brief Build a new nested-name-specifier given the prefix and the
554 /// namespace named in the next step in the nested-name-specifier.
555 ///
556 /// By default, performs semantic analysis when building the new
557 /// nested-name-specifier. Subclasses may override this routine to provide
558 /// different behavior.
559 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
560 SourceRange Range,
561 NamespaceDecl *NS);
562
563 /// \brief Build a new nested-name-specifier given the prefix and the
564 /// type named in the next step in the nested-name-specifier.
565 ///
566 /// By default, performs semantic analysis when building the new
567 /// nested-name-specifier. Subclasses may override this routine to provide
568 /// different behavior.
569 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
570 SourceRange Range,
571 bool TemplateKW,
572 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000573
574 /// \brief Build a new template name given a nested name specifier, a flag
575 /// indicating whether the "template" keyword was provided, and the template
576 /// that the template name refers to.
577 ///
578 /// By default, builds the new template name directly. Subclasses may override
579 /// this routine to provide different behavior.
580 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
581 bool TemplateKW,
582 TemplateDecl *Template);
583
584 /// \brief Build a new template name given a nested name specifier, a flag
585 /// indicating whether the "template" keyword was provided, and a set of
586 /// overloaded function templates.
587 ///
588 /// By default, builds the new template name directly. Subclasses may override
589 /// this routine to provide different behavior.
590 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
591 bool TemplateKW,
592 OverloadedFunctionDecl *Ovl);
Mike Stump11289f42009-09-09 15:08:12 +0000593
Douglas Gregor71dc5092009-08-06 06:41:21 +0000594 /// \brief Build a new template name given a nested name specifier and the
595 /// name that is referred to as a template.
596 ///
597 /// By default, performs semantic analysis to determine whether the name can
598 /// be resolved to a specific template, then builds the appropriate kind of
599 /// template name. Subclasses may override this routine to provide different
600 /// behavior.
601 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000602 const IdentifierInfo &II,
603 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000604
Douglas Gregor71395fa2009-11-04 00:56:37 +0000605 /// \brief Build a new template name given a nested name specifier and the
606 /// overloaded operator name that is referred to as a template.
607 ///
608 /// By default, performs semantic analysis to determine whether the name can
609 /// be resolved to a specific template, then builds the appropriate kind of
610 /// template name. Subclasses may override this routine to provide different
611 /// behavior.
612 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
613 OverloadedOperatorKind Operator,
614 QualType ObjectType);
615
Douglas Gregorebe10102009-08-20 07:17:43 +0000616 /// \brief Build a new compound statement.
617 ///
618 /// By default, performs semantic analysis to build the new statement.
619 /// Subclasses may override this routine to provide different behavior.
620 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
621 MultiStmtArg Statements,
622 SourceLocation RBraceLoc,
623 bool IsStmtExpr) {
624 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
625 IsStmtExpr);
626 }
627
628 /// \brief Build a new case statement.
629 ///
630 /// By default, performs semantic analysis to build the new statement.
631 /// Subclasses may override this routine to provide different behavior.
632 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
633 ExprArg LHS,
634 SourceLocation EllipsisLoc,
635 ExprArg RHS,
636 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000637 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000638 ColonLoc);
639 }
Mike Stump11289f42009-09-09 15:08:12 +0000640
Douglas Gregorebe10102009-08-20 07:17:43 +0000641 /// \brief Attach the body to a new case statement.
642 ///
643 /// By default, performs semantic analysis to build the new statement.
644 /// Subclasses may override this routine to provide different behavior.
645 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
646 getSema().ActOnCaseStmtBody(S.get(), move(Body));
647 return move(S);
648 }
Mike Stump11289f42009-09-09 15:08:12 +0000649
Douglas Gregorebe10102009-08-20 07:17:43 +0000650 /// \brief Build a new default statement.
651 ///
652 /// By default, performs semantic analysis to build the new statement.
653 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000654 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000655 SourceLocation ColonLoc,
656 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000657 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000658 /*CurScope=*/0);
659 }
Mike Stump11289f42009-09-09 15:08:12 +0000660
Douglas Gregorebe10102009-08-20 07:17:43 +0000661 /// \brief Build a new label statement.
662 ///
663 /// By default, performs semantic analysis to build the new statement.
664 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000665 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000666 IdentifierInfo *Id,
667 SourceLocation ColonLoc,
668 StmtArg SubStmt) {
669 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
670 }
Mike Stump11289f42009-09-09 15:08:12 +0000671
Douglas Gregorebe10102009-08-20 07:17:43 +0000672 /// \brief Build a new "if" statement.
673 ///
674 /// By default, performs semantic analysis to build the new statement.
675 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000676 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
677 StmtArg Then, SourceLocation ElseLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000678 StmtArg Else) {
679 return getSema().ActOnIfStmt(IfLoc, Cond, move(Then), ElseLoc, move(Else));
680 }
Mike Stump11289f42009-09-09 15:08:12 +0000681
Douglas Gregorebe10102009-08-20 07:17:43 +0000682 /// \brief Start building a new switch statement.
683 ///
684 /// By default, performs semantic analysis to build the new statement.
685 /// Subclasses may override this routine to provide different behavior.
686 OwningStmtResult RebuildSwitchStmtStart(ExprArg Cond) {
687 return getSema().ActOnStartOfSwitchStmt(move(Cond));
688 }
Mike Stump11289f42009-09-09 15:08:12 +0000689
Douglas Gregorebe10102009-08-20 07:17:43 +0000690 /// \brief Attach the body to the switch statement.
691 ///
692 /// By default, performs semantic analysis to build the new statement.
693 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000694 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000695 StmtArg Switch, StmtArg Body) {
696 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
697 move(Body));
698 }
699
700 /// \brief Build a new while statement.
701 ///
702 /// By default, performs semantic analysis to build the new statement.
703 /// Subclasses may override this routine to provide different behavior.
704 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
705 Sema::FullExprArg Cond,
706 StmtArg Body) {
707 return getSema().ActOnWhileStmt(WhileLoc, Cond, move(Body));
708 }
Mike Stump11289f42009-09-09 15:08:12 +0000709
Douglas Gregorebe10102009-08-20 07:17:43 +0000710 /// \brief Build a new do-while statement.
711 ///
712 /// By default, performs semantic analysis to build the new statement.
713 /// Subclasses may override this routine to provide different behavior.
714 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
715 SourceLocation WhileLoc,
716 SourceLocation LParenLoc,
717 ExprArg Cond,
718 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000719 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000720 move(Cond), RParenLoc);
721 }
722
723 /// \brief Build a new for statement.
724 ///
725 /// By default, performs semantic analysis to build the new statement.
726 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000727 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000728 SourceLocation LParenLoc,
729 StmtArg Init, ExprArg Cond, ExprArg Inc,
730 SourceLocation RParenLoc, StmtArg Body) {
Mike Stump11289f42009-09-09 15:08:12 +0000731 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), move(Cond),
Douglas Gregorebe10102009-08-20 07:17:43 +0000732 move(Inc), RParenLoc, move(Body));
733 }
Mike Stump11289f42009-09-09 15:08:12 +0000734
Douglas Gregorebe10102009-08-20 07:17:43 +0000735 /// \brief Build a new goto statement.
736 ///
737 /// By default, performs semantic analysis to build the new statement.
738 /// Subclasses may override this routine to provide different behavior.
739 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
740 SourceLocation LabelLoc,
741 LabelStmt *Label) {
742 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
743 }
744
745 /// \brief Build a new indirect goto statement.
746 ///
747 /// By default, performs semantic analysis to build the new statement.
748 /// Subclasses may override this routine to provide different behavior.
749 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
750 SourceLocation StarLoc,
751 ExprArg Target) {
752 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
753 }
Mike Stump11289f42009-09-09 15:08:12 +0000754
Douglas Gregorebe10102009-08-20 07:17:43 +0000755 /// \brief Build a new return statement.
756 ///
757 /// By default, performs semantic analysis to build the new statement.
758 /// Subclasses may override this routine to provide different behavior.
759 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
760 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000761
Douglas Gregorebe10102009-08-20 07:17:43 +0000762 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
763 }
Mike Stump11289f42009-09-09 15:08:12 +0000764
Douglas Gregorebe10102009-08-20 07:17:43 +0000765 /// \brief Build a new declaration statement.
766 ///
767 /// By default, performs semantic analysis to build the new statement.
768 /// Subclasses may override this routine to provide different behavior.
769 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000770 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000771 SourceLocation EndLoc) {
772 return getSema().Owned(
773 new (getSema().Context) DeclStmt(
774 DeclGroupRef::Create(getSema().Context,
775 Decls, NumDecls),
776 StartLoc, EndLoc));
777 }
Mike Stump11289f42009-09-09 15:08:12 +0000778
Douglas Gregorebe10102009-08-20 07:17:43 +0000779 /// \brief Build a new C++ exception declaration.
780 ///
781 /// By default, performs semantic analysis to build the new decaration.
782 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000783 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
Douglas Gregorebe10102009-08-20 07:17:43 +0000784 DeclaratorInfo *Declarator,
785 IdentifierInfo *Name,
786 SourceLocation Loc,
787 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000788 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000789 TypeRange);
790 }
791
792 /// \brief Build a new C++ catch statement.
793 ///
794 /// By default, performs semantic analysis to build the new statement.
795 /// Subclasses may override this routine to provide different behavior.
796 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
797 VarDecl *ExceptionDecl,
798 StmtArg Handler) {
799 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000800 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000801 Handler.takeAs<Stmt>()));
802 }
Mike Stump11289f42009-09-09 15:08:12 +0000803
Douglas Gregorebe10102009-08-20 07:17:43 +0000804 /// \brief Build a new C++ try statement.
805 ///
806 /// By default, performs semantic analysis to build the new statement.
807 /// Subclasses may override this routine to provide different behavior.
808 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
809 StmtArg TryBlock,
810 MultiStmtArg Handlers) {
811 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
812 }
Mike Stump11289f42009-09-09 15:08:12 +0000813
Douglas Gregora16548e2009-08-11 05:31:07 +0000814 /// \brief Build a new expression that references a declaration.
815 ///
816 /// By default, performs semantic analysis to build the new expression.
817 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000818 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
819 SourceRange QualifierRange,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +0000820 NamedDecl *ND, SourceLocation Loc,
821 bool isAddressOfOperand) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000822 CXXScopeSpec SS;
823 SS.setScopeRep(Qualifier);
824 SS.setRange(QualifierRange);
Douglas Gregora16548e2009-08-11 05:31:07 +0000825 return getSema().BuildDeclarationNameExpr(Loc, ND,
826 /*FIXME:*/false,
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000827 &SS,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +0000828 isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +0000829 }
Mike Stump11289f42009-09-09 15:08:12 +0000830
Douglas Gregora16548e2009-08-11 05:31:07 +0000831 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000832 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000833 /// By default, performs semantic analysis to build the new expression.
834 /// Subclasses may override this routine to provide different behavior.
835 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
836 SourceLocation RParen) {
837 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
838 }
839
Douglas Gregorad8a3362009-09-04 17:36:40 +0000840 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000841 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000842 /// By default, performs semantic analysis to build the new expression.
843 /// Subclasses may override this routine to provide different behavior.
844 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
845 SourceLocation OperatorLoc,
846 bool isArrow,
847 SourceLocation DestroyedTypeLoc,
848 QualType DestroyedType,
849 NestedNameSpecifier *Qualifier,
850 SourceRange QualifierRange) {
851 CXXScopeSpec SS;
852 if (Qualifier) {
853 SS.setRange(QualifierRange);
854 SS.setScopeRep(Qualifier);
855 }
856
Mike Stump11289f42009-09-09 15:08:12 +0000857 DeclarationName Name
Douglas Gregorad8a3362009-09-04 17:36:40 +0000858 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
859 SemaRef.Context.getCanonicalType(DestroyedType));
Mike Stump11289f42009-09-09 15:08:12 +0000860
861 return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base),
Douglas Gregorad8a3362009-09-04 17:36:40 +0000862 OperatorLoc,
863 isArrow? tok::arrow : tok::period,
864 DestroyedTypeLoc,
865 Name,
866 Sema::DeclPtrTy::make((Decl *)0),
867 &SS);
Mike Stump11289f42009-09-09 15:08:12 +0000868 }
869
Douglas Gregora16548e2009-08-11 05:31:07 +0000870 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000871 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000872 /// By default, performs semantic analysis to build the new expression.
873 /// Subclasses may override this routine to provide different behavior.
874 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
875 UnaryOperator::Opcode Opc,
876 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000877 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +0000878 }
Mike Stump11289f42009-09-09 15:08:12 +0000879
Douglas Gregora16548e2009-08-11 05:31:07 +0000880 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000881 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000882 /// By default, performs semantic analysis to build the new expression.
883 /// Subclasses may override this routine to provide different behavior.
John McCall4c98fd82009-11-04 07:28:41 +0000884 OwningExprResult RebuildSizeOfAlignOf(DeclaratorInfo *DInfo,
885 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000886 bool isSizeOf, SourceRange R) {
John McCall4c98fd82009-11-04 07:28:41 +0000887 return getSema().CreateSizeOfAlignOfExpr(DInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +0000888 }
889
Mike Stump11289f42009-09-09 15:08:12 +0000890 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000891 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +0000892 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000893 /// By default, performs semantic analysis to build the new expression.
894 /// Subclasses may override this routine to provide different behavior.
895 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
896 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +0000897 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000898 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
899 OpLoc, isSizeOf, R);
900 if (Result.isInvalid())
901 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000902
Douglas Gregora16548e2009-08-11 05:31:07 +0000903 SubExpr.release();
904 return move(Result);
905 }
Mike Stump11289f42009-09-09 15:08:12 +0000906
Douglas Gregora16548e2009-08-11 05:31:07 +0000907 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +0000908 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000909 /// By default, performs semantic analysis to build the new expression.
910 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000911 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000912 SourceLocation LBracketLoc,
913 ExprArg RHS,
914 SourceLocation RBracketLoc) {
915 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000916 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000917 RBracketLoc);
918 }
919
920 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000921 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000922 /// By default, performs semantic analysis to build the new expression.
923 /// Subclasses may override this routine to provide different behavior.
924 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
925 MultiExprArg Args,
926 SourceLocation *CommaLocs,
927 SourceLocation RParenLoc) {
928 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
929 move(Args), CommaLocs, RParenLoc);
930 }
931
932 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000933 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000934 /// By default, performs semantic analysis to build the new expression.
935 /// Subclasses may override this routine to provide different behavior.
936 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000937 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000938 NestedNameSpecifier *Qualifier,
939 SourceRange QualifierRange,
940 SourceLocation MemberLoc,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000941 NamedDecl *Member,
John McCall6b51f282009-11-23 01:53:49 +0000942 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000943 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +0000944 if (!Member->getDeclName()) {
945 // We have a reference to an unnamed field.
946 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +0000947
948 MemberExpr *ME =
Anders Carlsson5da84842009-09-01 04:26:58 +0000949 new (getSema().Context) MemberExpr(Base.takeAs<Expr>(), isArrow,
950 Member, MemberLoc,
951 cast<FieldDecl>(Member)->getType());
952 return getSema().Owned(ME);
953 }
Mike Stump11289f42009-09-09 15:08:12 +0000954
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000955 CXXScopeSpec SS;
956 if (Qualifier) {
957 SS.setRange(QualifierRange);
958 SS.setScopeRep(Qualifier);
959 }
960
Douglas Gregorf14b46f2009-08-31 20:00:26 +0000961 return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000962 isArrow? tok::arrow : tok::period,
963 MemberLoc,
Douglas Gregorf14b46f2009-08-31 20:00:26 +0000964 Member->getDeclName(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000965 ExplicitTemplateArgs,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000966 /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0),
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000967 &SS,
968 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +0000969 }
Mike Stump11289f42009-09-09 15:08:12 +0000970
Douglas Gregora16548e2009-08-11 05:31:07 +0000971 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000972 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000973 /// By default, performs semantic analysis to build the new expression.
974 /// Subclasses may override this routine to provide different behavior.
975 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
976 BinaryOperator::Opcode Opc,
977 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000978 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
979 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +0000980 }
981
982 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000983 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000984 /// By default, performs semantic analysis to build the new expression.
985 /// Subclasses may override this routine to provide different behavior.
986 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
987 SourceLocation QuestionLoc,
988 ExprArg LHS,
989 SourceLocation ColonLoc,
990 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +0000991 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +0000992 move(LHS), move(RHS));
993 }
994
995 /// \brief Build a new implicit cast expression.
Mike Stump11289f42009-09-09 15:08:12 +0000996 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000997 /// By default, builds a new implicit cast without any semantic analysis.
998 /// Subclasses may override this routine to provide different behavior.
999 OwningExprResult RebuildImplicitCastExpr(QualType T, CastExpr::CastKind Kind,
1000 ExprArg SubExpr, bool isLvalue) {
1001 ImplicitCastExpr *ICE
Mike Stump11289f42009-09-09 15:08:12 +00001002 = new (getSema().Context) ImplicitCastExpr(T, Kind,
Douglas Gregora16548e2009-08-11 05:31:07 +00001003 (Expr *)SubExpr.release(),
1004 isLvalue);
1005 return getSema().Owned(ICE);
1006 }
1007
1008 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001009 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001010 /// By default, performs semantic analysis to build the new expression.
1011 /// Subclasses may override this routine to provide different behavior.
1012 OwningExprResult RebuildCStyleCaseExpr(SourceLocation LParenLoc,
1013 QualType ExplicitTy,
1014 SourceLocation RParenLoc,
1015 ExprArg SubExpr) {
1016 return getSema().ActOnCastExpr(/*Scope=*/0,
1017 LParenLoc,
1018 ExplicitTy.getAsOpaquePtr(),
1019 RParenLoc,
1020 move(SubExpr));
1021 }
Mike Stump11289f42009-09-09 15:08:12 +00001022
Douglas Gregora16548e2009-08-11 05:31:07 +00001023 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001024 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001025 /// By default, performs semantic analysis to build the new expression.
1026 /// Subclasses may override this routine to provide different behavior.
1027 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
1028 QualType T,
1029 SourceLocation RParenLoc,
1030 ExprArg Init) {
1031 return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(),
1032 RParenLoc, move(Init));
1033 }
Mike Stump11289f42009-09-09 15:08:12 +00001034
Douglas Gregora16548e2009-08-11 05:31:07 +00001035 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001036 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001037 /// By default, performs semantic analysis to build the new expression.
1038 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001039 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001040 SourceLocation OpLoc,
1041 SourceLocation AccessorLoc,
1042 IdentifierInfo &Accessor) {
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001043 return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001044 tok::period, AccessorLoc,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001045 DeclarationName(&Accessor),
Douglas Gregora16548e2009-08-11 05:31:07 +00001046 /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0));
1047 }
Mike Stump11289f42009-09-09 15:08:12 +00001048
Douglas Gregora16548e2009-08-11 05:31:07 +00001049 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001050 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001051 /// By default, performs semantic analysis to build the new expression.
1052 /// Subclasses may override this routine to provide different behavior.
1053 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1054 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001055 SourceLocation RBraceLoc,
1056 QualType ResultTy) {
1057 OwningExprResult Result
1058 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1059 if (Result.isInvalid() || ResultTy->isDependentType())
1060 return move(Result);
1061
1062 // Patch in the result type we were given, which may have been computed
1063 // when the initial InitListExpr was built.
1064 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1065 ILE->setType(ResultTy);
1066 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001067 }
Mike Stump11289f42009-09-09 15:08:12 +00001068
Douglas Gregora16548e2009-08-11 05:31:07 +00001069 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001070 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001071 /// By default, performs semantic analysis to build the new expression.
1072 /// Subclasses may override this routine to provide different behavior.
1073 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1074 MultiExprArg ArrayExprs,
1075 SourceLocation EqualOrColonLoc,
1076 bool GNUSyntax,
1077 ExprArg Init) {
1078 OwningExprResult Result
1079 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1080 move(Init));
1081 if (Result.isInvalid())
1082 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001083
Douglas Gregora16548e2009-08-11 05:31:07 +00001084 ArrayExprs.release();
1085 return move(Result);
1086 }
Mike Stump11289f42009-09-09 15:08:12 +00001087
Douglas Gregora16548e2009-08-11 05:31:07 +00001088 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001089 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001090 /// By default, builds the implicit value initialization without performing
1091 /// any semantic analysis. Subclasses may override this routine to provide
1092 /// different behavior.
1093 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1094 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1095 }
Mike Stump11289f42009-09-09 15:08:12 +00001096
Douglas Gregora16548e2009-08-11 05:31:07 +00001097 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001098 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001099 /// By default, performs semantic analysis to build the new expression.
1100 /// Subclasses may override this routine to provide different behavior.
1101 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1102 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001103 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001104 RParenLoc);
1105 }
1106
1107 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001108 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001109 /// By default, performs semantic analysis to build the new expression.
1110 /// Subclasses may override this routine to provide different behavior.
1111 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1112 MultiExprArg SubExprs,
1113 SourceLocation RParenLoc) {
1114 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
1115 }
Mike Stump11289f42009-09-09 15:08:12 +00001116
Douglas Gregora16548e2009-08-11 05:31:07 +00001117 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001118 ///
1119 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001120 /// rather than attempting to map the label statement itself.
1121 /// Subclasses may override this routine to provide different behavior.
1122 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1123 SourceLocation LabelLoc,
1124 LabelStmt *Label) {
1125 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1126 }
Mike Stump11289f42009-09-09 15:08:12 +00001127
Douglas Gregora16548e2009-08-11 05:31:07 +00001128 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001129 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001130 /// By default, performs semantic analysis to build the new expression.
1131 /// Subclasses may override this routine to provide different behavior.
1132 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1133 StmtArg SubStmt,
1134 SourceLocation RParenLoc) {
1135 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1136 }
Mike Stump11289f42009-09-09 15:08:12 +00001137
Douglas Gregora16548e2009-08-11 05:31:07 +00001138 /// \brief Build a new __builtin_types_compatible_p expression.
1139 ///
1140 /// By default, performs semantic analysis to build the new expression.
1141 /// Subclasses may override this routine to provide different behavior.
1142 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1143 QualType T1, QualType T2,
1144 SourceLocation RParenLoc) {
1145 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1146 T1.getAsOpaquePtr(),
1147 T2.getAsOpaquePtr(),
1148 RParenLoc);
1149 }
Mike Stump11289f42009-09-09 15:08:12 +00001150
Douglas Gregora16548e2009-08-11 05:31:07 +00001151 /// \brief Build a new __builtin_choose_expr expression.
1152 ///
1153 /// By default, performs semantic analysis to build the new expression.
1154 /// Subclasses may override this routine to provide different behavior.
1155 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1156 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1157 SourceLocation RParenLoc) {
1158 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1159 move(Cond), move(LHS), move(RHS),
1160 RParenLoc);
1161 }
Mike Stump11289f42009-09-09 15:08:12 +00001162
Douglas Gregora16548e2009-08-11 05:31:07 +00001163 /// \brief Build a new overloaded operator call expression.
1164 ///
1165 /// By default, performs semantic analysis to build the new expression.
1166 /// The semantic analysis provides the behavior of template instantiation,
1167 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001168 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001169 /// argument-dependent lookup, etc. Subclasses may override this routine to
1170 /// provide different behavior.
1171 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1172 SourceLocation OpLoc,
1173 ExprArg Callee,
1174 ExprArg First,
1175 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001176
1177 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001178 /// reinterpret_cast.
1179 ///
1180 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001181 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001182 /// Subclasses may override this routine to provide different behavior.
1183 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1184 Stmt::StmtClass Class,
1185 SourceLocation LAngleLoc,
1186 QualType T,
1187 SourceLocation RAngleLoc,
1188 SourceLocation LParenLoc,
1189 ExprArg SubExpr,
1190 SourceLocation RParenLoc) {
1191 switch (Class) {
1192 case Stmt::CXXStaticCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001193 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T,
1194 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001195 move(SubExpr), RParenLoc);
1196
1197 case Stmt::CXXDynamicCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001198 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T,
1199 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001200 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001201
Douglas Gregora16548e2009-08-11 05:31:07 +00001202 case Stmt::CXXReinterpretCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001203 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T,
1204 RAngleLoc, LParenLoc,
1205 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001207
Douglas Gregora16548e2009-08-11 05:31:07 +00001208 case Stmt::CXXConstCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001209 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T,
1210 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001211 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001212
Douglas Gregora16548e2009-08-11 05:31:07 +00001213 default:
1214 assert(false && "Invalid C++ named cast");
1215 break;
1216 }
Mike Stump11289f42009-09-09 15:08:12 +00001217
Douglas Gregora16548e2009-08-11 05:31:07 +00001218 return getSema().ExprError();
1219 }
Mike Stump11289f42009-09-09 15:08:12 +00001220
Douglas Gregora16548e2009-08-11 05:31:07 +00001221 /// \brief Build a new C++ static_cast expression.
1222 ///
1223 /// By default, performs semantic analysis to build the new expression.
1224 /// Subclasses may override this routine to provide different behavior.
1225 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1226 SourceLocation LAngleLoc,
1227 QualType T,
1228 SourceLocation RAngleLoc,
1229 SourceLocation LParenLoc,
1230 ExprArg SubExpr,
1231 SourceLocation RParenLoc) {
1232 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001233 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001234 LParenLoc, move(SubExpr), RParenLoc);
1235 }
1236
1237 /// \brief Build a new C++ dynamic_cast expression.
1238 ///
1239 /// By default, performs semantic analysis to build the new expression.
1240 /// Subclasses may override this routine to provide different behavior.
1241 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1242 SourceLocation LAngleLoc,
1243 QualType T,
1244 SourceLocation RAngleLoc,
1245 SourceLocation LParenLoc,
1246 ExprArg SubExpr,
1247 SourceLocation RParenLoc) {
1248 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001249 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001250 LParenLoc, move(SubExpr), RParenLoc);
1251 }
1252
1253 /// \brief Build a new C++ reinterpret_cast expression.
1254 ///
1255 /// By default, performs semantic analysis to build the new expression.
1256 /// Subclasses may override this routine to provide different behavior.
1257 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1258 SourceLocation LAngleLoc,
1259 QualType T,
1260 SourceLocation RAngleLoc,
1261 SourceLocation LParenLoc,
1262 ExprArg SubExpr,
1263 SourceLocation RParenLoc) {
1264 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1265 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
1266 LParenLoc, move(SubExpr), RParenLoc);
1267 }
1268
1269 /// \brief Build a new C++ const_cast expression.
1270 ///
1271 /// By default, performs semantic analysis to build the new expression.
1272 /// Subclasses may override this routine to provide different behavior.
1273 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1274 SourceLocation LAngleLoc,
1275 QualType T,
1276 SourceLocation RAngleLoc,
1277 SourceLocation LParenLoc,
1278 ExprArg SubExpr,
1279 SourceLocation RParenLoc) {
1280 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001281 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001282 LParenLoc, move(SubExpr), RParenLoc);
1283 }
Mike Stump11289f42009-09-09 15:08:12 +00001284
Douglas Gregora16548e2009-08-11 05:31:07 +00001285 /// \brief Build a new C++ functional-style cast expression.
1286 ///
1287 /// By default, performs semantic analysis to build the new expression.
1288 /// Subclasses may override this routine to provide different behavior.
1289 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
1290 QualType T,
1291 SourceLocation LParenLoc,
1292 ExprArg SubExpr,
1293 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001294 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001295 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
1296 T.getAsOpaquePtr(),
1297 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001298 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001299 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001300 RParenLoc);
1301 }
Mike Stump11289f42009-09-09 15:08:12 +00001302
Douglas Gregora16548e2009-08-11 05:31:07 +00001303 /// \brief Build a new C++ typeid(type) expression.
1304 ///
1305 /// By default, performs semantic analysis to build the new expression.
1306 /// Subclasses may override this routine to provide different behavior.
1307 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1308 SourceLocation LParenLoc,
1309 QualType T,
1310 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001311 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001312 T.getAsOpaquePtr(), RParenLoc);
1313 }
Mike Stump11289f42009-09-09 15:08:12 +00001314
Douglas Gregora16548e2009-08-11 05:31:07 +00001315 /// \brief Build a new C++ typeid(expr) expression.
1316 ///
1317 /// By default, performs semantic analysis to build the new expression.
1318 /// Subclasses may override this routine to provide different behavior.
1319 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1320 SourceLocation LParenLoc,
1321 ExprArg Operand,
1322 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001323 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1325 RParenLoc);
1326 if (Result.isInvalid())
1327 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001328
Douglas Gregora16548e2009-08-11 05:31:07 +00001329 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1330 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001331 }
1332
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 /// \brief Build a new C++ "this" expression.
1334 ///
1335 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001336 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001338 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001339 QualType ThisType) {
1340 return getSema().Owned(
1341 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType));
1342 }
1343
1344 /// \brief Build a new C++ throw expression.
1345 ///
1346 /// By default, performs semantic analysis to build the new expression.
1347 /// Subclasses may override this routine to provide different behavior.
1348 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1349 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1350 }
1351
1352 /// \brief Build a new C++ default-argument expression.
1353 ///
1354 /// By default, builds a new default-argument expression, which does not
1355 /// require any semantic analysis. Subclasses may override this routine to
1356 /// provide different behavior.
1357 OwningExprResult RebuildCXXDefaultArgExpr(ParmVarDecl *Param) {
Anders Carlssone8271232009-08-14 18:30:22 +00001358 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001359 }
1360
1361 /// \brief Build a new C++ zero-initialization expression.
1362 ///
1363 /// By default, performs semantic analysis to build the new expression.
1364 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001365 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001366 SourceLocation LParenLoc,
1367 QualType T,
1368 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001369 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1370 T.getAsOpaquePtr(), LParenLoc,
1371 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001372 0, RParenLoc);
1373 }
Mike Stump11289f42009-09-09 15:08:12 +00001374
Douglas Gregora16548e2009-08-11 05:31:07 +00001375 /// \brief Build a new C++ conditional declaration expression.
1376 ///
1377 /// By default, performs semantic analysis to build the new expression.
1378 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001379 OwningExprResult RebuildCXXConditionDeclExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001380 SourceLocation EqLoc,
1381 VarDecl *Var) {
1382 return SemaRef.Owned(new (SemaRef.Context) CXXConditionDeclExpr(StartLoc,
1383 EqLoc,
1384 Var));
1385 }
Mike Stump11289f42009-09-09 15:08:12 +00001386
Douglas Gregora16548e2009-08-11 05:31:07 +00001387 /// \brief Build a new C++ "new" expression.
1388 ///
1389 /// By default, performs semantic analysis to build the new expression.
1390 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001391 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001392 bool UseGlobal,
1393 SourceLocation PlacementLParen,
1394 MultiExprArg PlacementArgs,
1395 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001396 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001397 QualType AllocType,
1398 SourceLocation TypeLoc,
1399 SourceRange TypeRange,
1400 ExprArg ArraySize,
1401 SourceLocation ConstructorLParen,
1402 MultiExprArg ConstructorArgs,
1403 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001404 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001405 PlacementLParen,
1406 move(PlacementArgs),
1407 PlacementRParen,
1408 ParenTypeId,
1409 AllocType,
1410 TypeLoc,
1411 TypeRange,
1412 move(ArraySize),
1413 ConstructorLParen,
1414 move(ConstructorArgs),
1415 ConstructorRParen);
1416 }
Mike Stump11289f42009-09-09 15:08:12 +00001417
Douglas Gregora16548e2009-08-11 05:31:07 +00001418 /// \brief Build a new C++ "delete" expression.
1419 ///
1420 /// By default, performs semantic analysis to build the new expression.
1421 /// Subclasses may override this routine to provide different behavior.
1422 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1423 bool IsGlobalDelete,
1424 bool IsArrayForm,
1425 ExprArg Operand) {
1426 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1427 move(Operand));
1428 }
Mike Stump11289f42009-09-09 15:08:12 +00001429
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 /// \brief Build a new unary type trait expression.
1431 ///
1432 /// By default, performs semantic analysis to build the new expression.
1433 /// Subclasses may override this routine to provide different behavior.
1434 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1435 SourceLocation StartLoc,
1436 SourceLocation LParenLoc,
1437 QualType T,
1438 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001439 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001440 T.getAsOpaquePtr(), RParenLoc);
1441 }
1442
Mike Stump11289f42009-09-09 15:08:12 +00001443 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 /// expression.
1445 ///
1446 /// By default, performs semantic analysis to build the new expression.
1447 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001448 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001449 SourceRange QualifierRange,
1450 DeclarationName Name,
1451 SourceLocation Location,
1452 bool IsAddressOfOperand) {
1453 CXXScopeSpec SS;
1454 SS.setRange(QualifierRange);
1455 SS.setScopeRep(NNS);
Mike Stump11289f42009-09-09 15:08:12 +00001456 return getSema().ActOnDeclarationNameExpr(/*Scope=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001457 Location,
1458 Name,
1459 /*Trailing lparen=*/false,
1460 &SS,
1461 IsAddressOfOperand);
1462 }
1463
1464 /// \brief Build a new template-id expression.
1465 ///
1466 /// By default, performs semantic analysis to build the new expression.
1467 /// Subclasses may override this routine to provide different behavior.
Douglas Gregord019ff62009-10-22 17:20:55 +00001468 OwningExprResult RebuildTemplateIdExpr(NestedNameSpecifier *Qualifier,
1469 SourceRange QualifierRange,
1470 TemplateName Template,
Douglas Gregora16548e2009-08-11 05:31:07 +00001471 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +00001472 const TemplateArgumentListInfo &TemplateArgs) {
Douglas Gregord019ff62009-10-22 17:20:55 +00001473 return getSema().BuildTemplateIdExpr(Qualifier, QualifierRange,
John McCall6b51f282009-11-23 01:53:49 +00001474 Template, TemplateLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 }
1476
1477 /// \brief Build a new object-construction expression.
1478 ///
1479 /// By default, performs semantic analysis to build the new expression.
1480 /// Subclasses may override this routine to provide different behavior.
1481 OwningExprResult RebuildCXXConstructExpr(QualType T,
1482 CXXConstructorDecl *Constructor,
1483 bool IsElidable,
1484 MultiExprArg Args) {
Anders Carlsson1b4ebfa2009-09-05 07:40:38 +00001485 return getSema().BuildCXXConstructExpr(/*FIXME:ConstructLoc*/
1486 SourceLocation(),
1487 T, Constructor, IsElidable,
Anders Carlsson5995a3e2009-09-07 22:23:31 +00001488 move(Args));
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 }
1490
1491 /// \brief Build a new object-construction expression.
1492 ///
1493 /// By default, performs semantic analysis to build the new expression.
1494 /// Subclasses may override this routine to provide different behavior.
1495 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1496 QualType T,
1497 SourceLocation LParenLoc,
1498 MultiExprArg Args,
1499 SourceLocation *Commas,
1500 SourceLocation RParenLoc) {
1501 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1502 T.getAsOpaquePtr(),
1503 LParenLoc,
1504 move(Args),
1505 Commas,
1506 RParenLoc);
1507 }
1508
1509 /// \brief Build a new object-construction expression.
1510 ///
1511 /// By default, performs semantic analysis to build the new expression.
1512 /// Subclasses may override this routine to provide different behavior.
1513 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1514 QualType T,
1515 SourceLocation LParenLoc,
1516 MultiExprArg Args,
1517 SourceLocation *Commas,
1518 SourceLocation RParenLoc) {
1519 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1520 /*FIXME*/LParenLoc),
1521 T.getAsOpaquePtr(),
1522 LParenLoc,
1523 move(Args),
1524 Commas,
1525 RParenLoc);
1526 }
Mike Stump11289f42009-09-09 15:08:12 +00001527
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 /// \brief Build a new member reference expression.
1529 ///
1530 /// By default, performs semantic analysis to build the new expression.
1531 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001532 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
Douglas Gregora16548e2009-08-11 05:31:07 +00001533 bool IsArrow,
1534 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001535 NestedNameSpecifier *Qualifier,
1536 SourceRange QualifierRange,
Douglas Gregora16548e2009-08-11 05:31:07 +00001537 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001538 SourceLocation MemberLoc,
1539 NamedDecl *FirstQualifierInScope) {
Douglas Gregor2168a9f2009-08-11 15:56:57 +00001540 OwningExprResult Base = move(BaseE);
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001542
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001544 SS.setRange(QualifierRange);
1545 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001546
Douglas Gregor308047d2009-09-09 00:23:06 +00001547 return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 move(Base), OperatorLoc, OpKind,
Douglas Gregorf14b46f2009-08-31 20:00:26 +00001549 MemberLoc,
1550 Name,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001551 /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001552 &SS,
1553 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00001554 }
1555
Douglas Gregor308047d2009-09-09 00:23:06 +00001556 /// \brief Build a new member reference expression with explicit template
1557 /// arguments.
1558 ///
1559 /// By default, performs semantic analysis to build the new expression.
1560 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001561 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
Douglas Gregor308047d2009-09-09 00:23:06 +00001562 bool IsArrow,
1563 SourceLocation OperatorLoc,
1564 NestedNameSpecifier *Qualifier,
1565 SourceRange QualifierRange,
1566 TemplateName Template,
1567 SourceLocation TemplateNameLoc,
1568 NamedDecl *FirstQualifierInScope,
John McCall6b51f282009-11-23 01:53:49 +00001569 const TemplateArgumentListInfo &TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001570 OwningExprResult Base = move(BaseE);
1571 tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period;
Mike Stump11289f42009-09-09 15:08:12 +00001572
Douglas Gregor308047d2009-09-09 00:23:06 +00001573 CXXScopeSpec SS;
1574 SS.setRange(QualifierRange);
1575 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001576
Douglas Gregor308047d2009-09-09 00:23:06 +00001577 // FIXME: We're going to end up looking up the template based on its name,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001578 // twice! Also, duplicates part of Sema::BuildMemberAccessExpr.
Douglas Gregor308047d2009-09-09 00:23:06 +00001579 DeclarationName Name;
1580 if (TemplateDecl *ActualTemplate = Template.getAsTemplateDecl())
1581 Name = ActualTemplate->getDeclName();
Mike Stump11289f42009-09-09 15:08:12 +00001582 else if (OverloadedFunctionDecl *Ovl
Douglas Gregor308047d2009-09-09 00:23:06 +00001583 = Template.getAsOverloadedFunctionDecl())
1584 Name = Ovl->getDeclName();
Douglas Gregor71395fa2009-11-04 00:56:37 +00001585 else {
1586 DependentTemplateName *DTN = Template.getAsDependentTemplateName();
1587 if (DTN->isIdentifier())
1588 Name = DTN->getIdentifier();
1589 else
1590 Name = SemaRef.Context.DeclarationNames.getCXXOperatorName(
1591 DTN->getOperator());
1592 }
John McCall6b51f282009-11-23 01:53:49 +00001593 return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0, move(Base),
1594 OperatorLoc, OpKind,
1595 TemplateNameLoc, Name,
1596 &TemplateArgs,
1597 Sema::DeclPtrTy(), &SS);
Douglas Gregor308047d2009-09-09 00:23:06 +00001598 }
Mike Stump11289f42009-09-09 15:08:12 +00001599
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 /// \brief Build a new Objective-C @encode expression.
1601 ///
1602 /// By default, performs semantic analysis to build the new expression.
1603 /// Subclasses may override this routine to provide different behavior.
1604 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1605 QualType T,
1606 SourceLocation RParenLoc) {
1607 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1608 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001609 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001610
1611 /// \brief Build a new Objective-C protocol expression.
1612 ///
1613 /// By default, performs semantic analysis to build the new expression.
1614 /// Subclasses may override this routine to provide different behavior.
1615 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1616 SourceLocation AtLoc,
1617 SourceLocation ProtoLoc,
1618 SourceLocation LParenLoc,
1619 SourceLocation RParenLoc) {
1620 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1621 Protocol->getIdentifier(),
1622 AtLoc,
1623 ProtoLoc,
1624 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001625 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 }
Mike Stump11289f42009-09-09 15:08:12 +00001627
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 /// \brief Build a new shuffle vector expression.
1629 ///
1630 /// By default, performs semantic analysis to build the new expression.
1631 /// Subclasses may override this routine to provide different behavior.
1632 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1633 MultiExprArg SubExprs,
1634 SourceLocation RParenLoc) {
1635 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001636 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1638 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1639 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1640 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001641
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 // Build a reference to the __builtin_shufflevector builtin
1643 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001644 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001646 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001648
1649 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 unsigned NumSubExprs = SubExprs.size();
1651 Expr **Subs = (Expr **)SubExprs.release();
1652 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1653 Subs, NumSubExprs,
1654 Builtin->getResultType(),
1655 RParenLoc);
1656 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001657
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 // Type-check the __builtin_shufflevector expression.
1659 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1660 if (Result.isInvalid())
1661 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001662
Douglas Gregora16548e2009-08-11 05:31:07 +00001663 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001664 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001666};
Douglas Gregora16548e2009-08-11 05:31:07 +00001667
Douglas Gregorebe10102009-08-20 07:17:43 +00001668template<typename Derived>
1669Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1670 if (!S)
1671 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001672
Douglas Gregorebe10102009-08-20 07:17:43 +00001673 switch (S->getStmtClass()) {
1674 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001675
Douglas Gregorebe10102009-08-20 07:17:43 +00001676 // Transform individual statement nodes
1677#define STMT(Node, Parent) \
1678 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1679#define EXPR(Node, Parent)
1680#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001681
Douglas Gregorebe10102009-08-20 07:17:43 +00001682 // Transform expressions by calling TransformExpr.
1683#define STMT(Node, Parent)
1684#define EXPR(Node, Parent) case Stmt::Node##Class:
1685#include "clang/AST/StmtNodes.def"
1686 {
1687 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1688 if (E.isInvalid())
1689 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001690
Douglas Gregor07eae022009-11-13 18:34:26 +00001691 return getSema().ActOnExprStmt(getSema().FullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001692 }
Mike Stump11289f42009-09-09 15:08:12 +00001693 }
1694
Douglas Gregorebe10102009-08-20 07:17:43 +00001695 return SemaRef.Owned(S->Retain());
1696}
Mike Stump11289f42009-09-09 15:08:12 +00001697
1698
Douglas Gregore922c772009-08-04 22:27:00 +00001699template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00001700Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E,
1701 bool isAddressOfOperand) {
1702 if (!E)
1703 return SemaRef.Owned(E);
1704
1705 switch (E->getStmtClass()) {
1706 case Stmt::NoStmtClass: break;
1707#define STMT(Node, Parent) case Stmt::Node##Class: break;
1708#define EXPR(Node, Parent) \
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00001709 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E), \
1710 isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001711#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001712 }
1713
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001715}
1716
1717template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001718NestedNameSpecifier *
1719TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001720 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001721 QualType ObjectType,
1722 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001723 if (!NNS)
1724 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001725
Douglas Gregorebe10102009-08-20 07:17:43 +00001726 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001727 NestedNameSpecifier *Prefix = NNS->getPrefix();
1728 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001729 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001730 ObjectType,
1731 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001732 if (!Prefix)
1733 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001734
1735 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001736 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001737 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001738 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001739 }
Mike Stump11289f42009-09-09 15:08:12 +00001740
Douglas Gregor1135c352009-08-06 05:28:30 +00001741 switch (NNS->getKind()) {
1742 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001743 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001744 "Identifier nested-name-specifier with no prefix or object type");
1745 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1746 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001747 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001748
1749 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001750 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001751 ObjectType,
1752 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001753
Douglas Gregor1135c352009-08-06 05:28:30 +00001754 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001755 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001756 = cast_or_null<NamespaceDecl>(
1757 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001758 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001759 Prefix == NNS->getPrefix() &&
1760 NS == NNS->getAsNamespace())
1761 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001762
Douglas Gregor1135c352009-08-06 05:28:30 +00001763 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1764 }
Mike Stump11289f42009-09-09 15:08:12 +00001765
Douglas Gregor1135c352009-08-06 05:28:30 +00001766 case NestedNameSpecifier::Global:
1767 // There is no meaningful transformation that one could perform on the
1768 // global scope.
1769 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001770
Douglas Gregor1135c352009-08-06 05:28:30 +00001771 case NestedNameSpecifier::TypeSpecWithTemplate:
1772 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001773 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor1135c352009-08-06 05:28:30 +00001774 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001775 if (T.isNull())
1776 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001777
Douglas Gregor1135c352009-08-06 05:28:30 +00001778 if (!getDerived().AlwaysRebuild() &&
1779 Prefix == NNS->getPrefix() &&
1780 T == QualType(NNS->getAsType(), 0))
1781 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001782
1783 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1784 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregor1135c352009-08-06 05:28:30 +00001785 T);
1786 }
1787 }
Mike Stump11289f42009-09-09 15:08:12 +00001788
Douglas Gregor1135c352009-08-06 05:28:30 +00001789 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001790 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001791}
1792
1793template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001794DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001795TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001796 SourceLocation Loc,
1797 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001798 if (!Name)
1799 return Name;
1800
1801 switch (Name.getNameKind()) {
1802 case DeclarationName::Identifier:
1803 case DeclarationName::ObjCZeroArgSelector:
1804 case DeclarationName::ObjCOneArgSelector:
1805 case DeclarationName::ObjCMultiArgSelector:
1806 case DeclarationName::CXXOperatorName:
1807 case DeclarationName::CXXUsingDirective:
1808 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001809
Douglas Gregorf816bd72009-09-03 22:13:48 +00001810 case DeclarationName::CXXConstructorName:
1811 case DeclarationName::CXXDestructorName:
1812 case DeclarationName::CXXConversionFunctionName: {
1813 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorc59e5612009-10-19 22:04:39 +00001814 QualType T;
1815 if (!ObjectType.isNull() &&
1816 isa<TemplateSpecializationType>(Name.getCXXNameType())) {
1817 TemplateSpecializationType *SpecType
1818 = cast<TemplateSpecializationType>(Name.getCXXNameType());
1819 T = TransformTemplateSpecializationType(SpecType, ObjectType);
1820 } else
1821 T = getDerived().TransformType(Name.getCXXNameType());
Douglas Gregorf816bd72009-09-03 22:13:48 +00001822 if (T.isNull())
1823 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001824
Douglas Gregorf816bd72009-09-03 22:13:48 +00001825 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001826 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001827 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001828 }
Mike Stump11289f42009-09-09 15:08:12 +00001829 }
1830
Douglas Gregorf816bd72009-09-03 22:13:48 +00001831 return DeclarationName();
1832}
1833
1834template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001835TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001836TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1837 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00001838 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001839 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001840 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1841 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1842 if (!NNS)
1843 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001844
Douglas Gregor71dc5092009-08-06 06:41:21 +00001845 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001846 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001847 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1848 if (!TransTemplate)
1849 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001850
Douglas Gregor71dc5092009-08-06 06:41:21 +00001851 if (!getDerived().AlwaysRebuild() &&
1852 NNS == QTN->getQualifier() &&
1853 TransTemplate == Template)
1854 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001855
Douglas Gregor71dc5092009-08-06 06:41:21 +00001856 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1857 TransTemplate);
1858 }
Mike Stump11289f42009-09-09 15:08:12 +00001859
Douglas Gregor71dc5092009-08-06 06:41:21 +00001860 OverloadedFunctionDecl *Ovl = QTN->getOverloadedFunctionDecl();
1861 assert(Ovl && "Not a template name or an overload set?");
Mike Stump11289f42009-09-09 15:08:12 +00001862 OverloadedFunctionDecl *TransOvl
Douglas Gregor71dc5092009-08-06 06:41:21 +00001863 = cast_or_null<OverloadedFunctionDecl>(getDerived().TransformDecl(Ovl));
1864 if (!TransOvl)
1865 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001866
Douglas Gregor71dc5092009-08-06 06:41:21 +00001867 if (!getDerived().AlwaysRebuild() &&
1868 NNS == QTN->getQualifier() &&
1869 TransOvl == Ovl)
1870 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001871
Douglas Gregor71dc5092009-08-06 06:41:21 +00001872 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1873 TransOvl);
1874 }
Mike Stump11289f42009-09-09 15:08:12 +00001875
Douglas Gregor71dc5092009-08-06 06:41:21 +00001876 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001877 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001878 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1879 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor308047d2009-09-09 00:23:06 +00001880 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001881 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001882
Douglas Gregor71dc5092009-08-06 06:41:21 +00001883 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001884 NNS == DTN->getQualifier() &&
1885 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001886 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001887
Douglas Gregor71395fa2009-11-04 00:56:37 +00001888 if (DTN->isIdentifier())
1889 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1890 ObjectType);
1891
1892 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1893 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001894 }
Mike Stump11289f42009-09-09 15:08:12 +00001895
Douglas Gregor71dc5092009-08-06 06:41:21 +00001896 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001897 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001898 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1899 if (!TransTemplate)
1900 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001901
Douglas Gregor71dc5092009-08-06 06:41:21 +00001902 if (!getDerived().AlwaysRebuild() &&
1903 TransTemplate == Template)
1904 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001905
Douglas Gregor71dc5092009-08-06 06:41:21 +00001906 return TemplateName(TransTemplate);
1907 }
Mike Stump11289f42009-09-09 15:08:12 +00001908
Douglas Gregor71dc5092009-08-06 06:41:21 +00001909 OverloadedFunctionDecl *Ovl = Name.getAsOverloadedFunctionDecl();
1910 assert(Ovl && "Not a template name or an overload set?");
Mike Stump11289f42009-09-09 15:08:12 +00001911 OverloadedFunctionDecl *TransOvl
Douglas Gregor71dc5092009-08-06 06:41:21 +00001912 = cast_or_null<OverloadedFunctionDecl>(getDerived().TransformDecl(Ovl));
1913 if (!TransOvl)
1914 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001915
Douglas Gregor71dc5092009-08-06 06:41:21 +00001916 if (!getDerived().AlwaysRebuild() &&
1917 TransOvl == Ovl)
1918 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001919
Douglas Gregor71dc5092009-08-06 06:41:21 +00001920 return TemplateName(TransOvl);
1921}
1922
1923template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001924void TreeTransform<Derived>::InventTemplateArgumentLoc(
1925 const TemplateArgument &Arg,
1926 TemplateArgumentLoc &Output) {
1927 SourceLocation Loc = getDerived().getBaseLocation();
1928 switch (Arg.getKind()) {
1929 case TemplateArgument::Null:
1930 llvm::llvm_unreachable("null template argument in TreeTransform");
1931 break;
1932
1933 case TemplateArgument::Type:
1934 Output = TemplateArgumentLoc(Arg,
1935 SemaRef.Context.getTrivialDeclaratorInfo(Arg.getAsType(), Loc));
1936
1937 break;
1938
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001939 case TemplateArgument::Template:
1940 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1941 break;
1942
John McCall0ad16662009-10-29 08:12:44 +00001943 case TemplateArgument::Expression:
1944 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1945 break;
1946
1947 case TemplateArgument::Declaration:
1948 case TemplateArgument::Integral:
1949 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00001950 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00001951 break;
1952 }
1953}
1954
1955template<typename Derived>
1956bool TreeTransform<Derived>::TransformTemplateArgument(
1957 const TemplateArgumentLoc &Input,
1958 TemplateArgumentLoc &Output) {
1959 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00001960 switch (Arg.getKind()) {
1961 case TemplateArgument::Null:
1962 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001963 Output = Input;
1964 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001965
Douglas Gregore922c772009-08-04 22:27:00 +00001966 case TemplateArgument::Type: {
John McCall0ad16662009-10-29 08:12:44 +00001967 DeclaratorInfo *DI = Input.getSourceDeclaratorInfo();
1968 if (DI == NULL)
1969 DI = InventDeclaratorInfo(Input.getArgument().getAsType());
1970
1971 DI = getDerived().TransformType(DI);
1972 if (!DI) return true;
1973
1974 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1975 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001976 }
Mike Stump11289f42009-09-09 15:08:12 +00001977
Douglas Gregore922c772009-08-04 22:27:00 +00001978 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001979 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001980 DeclarationName Name;
1981 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1982 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001983 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregore922c772009-08-04 22:27:00 +00001984 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001985 if (!D) return true;
1986
John McCall0d07eb32009-10-29 18:45:58 +00001987 Expr *SourceExpr = Input.getSourceDeclExpression();
1988 if (SourceExpr) {
1989 EnterExpressionEvaluationContext Unevaluated(getSema(),
1990 Action::Unevaluated);
1991 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1992 if (E.isInvalid())
1993 SourceExpr = NULL;
1994 else {
1995 SourceExpr = E.takeAs<Expr>();
1996 SourceExpr->Retain();
1997 }
1998 }
1999
2000 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002001 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002002 }
Mike Stump11289f42009-09-09 15:08:12 +00002003
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002004 case TemplateArgument::Template: {
2005 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
2006 TemplateName Template
2007 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2008 if (Template.isNull())
2009 return true;
2010
2011 Output = TemplateArgumentLoc(TemplateArgument(Template),
2012 Input.getTemplateQualifierRange(),
2013 Input.getTemplateNameLoc());
2014 return false;
2015 }
2016
Douglas Gregore922c772009-08-04 22:27:00 +00002017 case TemplateArgument::Expression: {
2018 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002019 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002020 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002021
John McCall0ad16662009-10-29 08:12:44 +00002022 Expr *InputExpr = Input.getSourceExpression();
2023 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2024
2025 Sema::OwningExprResult E
2026 = getDerived().TransformExpr(InputExpr);
2027 if (E.isInvalid()) return true;
2028
2029 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002030 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002031 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2032 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002033 }
Mike Stump11289f42009-09-09 15:08:12 +00002034
Douglas Gregore922c772009-08-04 22:27:00 +00002035 case TemplateArgument::Pack: {
2036 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2037 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002038 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002039 AEnd = Arg.pack_end();
2040 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002041
John McCall0ad16662009-10-29 08:12:44 +00002042 // FIXME: preserve source information here when we start
2043 // caring about parameter packs.
2044
John McCall0d07eb32009-10-29 18:45:58 +00002045 TemplateArgumentLoc InputArg;
2046 TemplateArgumentLoc OutputArg;
2047 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2048 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002049 return true;
2050
John McCall0d07eb32009-10-29 18:45:58 +00002051 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002052 }
2053 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002054 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002055 true);
John McCall0d07eb32009-10-29 18:45:58 +00002056 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002057 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002058 }
2059 }
Mike Stump11289f42009-09-09 15:08:12 +00002060
Douglas Gregore922c772009-08-04 22:27:00 +00002061 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002062 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002063}
2064
Douglas Gregord6ff3322009-08-04 16:50:30 +00002065//===----------------------------------------------------------------------===//
2066// Type transformation
2067//===----------------------------------------------------------------------===//
2068
2069template<typename Derived>
2070QualType TreeTransform<Derived>::TransformType(QualType T) {
2071 if (getDerived().AlreadyTransformed(T))
2072 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002073
John McCall550e0c22009-10-21 00:40:46 +00002074 // Temporary workaround. All of these transformations should
2075 // eventually turn into transformations on TypeLocs.
2076 DeclaratorInfo *DI = getSema().Context.CreateDeclaratorInfo(T);
John McCallde889892009-10-21 00:44:26 +00002077 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002078
2079 DeclaratorInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002080
John McCall550e0c22009-10-21 00:40:46 +00002081 if (!NewDI)
2082 return QualType();
2083
2084 return NewDI->getType();
2085}
2086
2087template<typename Derived>
2088DeclaratorInfo *TreeTransform<Derived>::TransformType(DeclaratorInfo *DI) {
2089 if (getDerived().AlreadyTransformed(DI->getType()))
2090 return DI;
2091
2092 TypeLocBuilder TLB;
2093
2094 TypeLoc TL = DI->getTypeLoc();
2095 TLB.reserve(TL.getFullDataSize());
2096
2097 QualType Result = getDerived().TransformType(TLB, TL);
2098 if (Result.isNull())
2099 return 0;
2100
2101 return TLB.getDeclaratorInfo(SemaRef.Context, Result);
2102}
2103
2104template<typename Derived>
2105QualType
2106TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
2107 switch (T.getTypeLocClass()) {
2108#define ABSTRACT_TYPELOC(CLASS, PARENT)
2109#define TYPELOC(CLASS, PARENT) \
2110 case TypeLoc::CLASS: \
2111 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2112#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002113 }
Mike Stump11289f42009-09-09 15:08:12 +00002114
John McCall550e0c22009-10-21 00:40:46 +00002115 llvm::llvm_unreachable("unhandled type loc!");
2116 return QualType();
2117}
2118
2119/// FIXME: By default, this routine adds type qualifiers only to types
2120/// that can have qualifiers, and silently suppresses those qualifiers
2121/// that are not permitted (e.g., qualifiers on reference or function
2122/// types). This is the right thing for template instantiation, but
2123/// probably not for other clients.
2124template<typename Derived>
2125QualType
2126TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
2127 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002128 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002129
2130 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2131 if (Result.isNull())
2132 return QualType();
2133
2134 // Silently suppress qualifiers if the result type can't be qualified.
2135 // FIXME: this is the right thing for template instantiation, but
2136 // probably not for other clients.
2137 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002138 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002139
John McCall550e0c22009-10-21 00:40:46 +00002140 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2141
2142 TLB.push<QualifiedTypeLoc>(Result);
2143
2144 // No location information to preserve.
2145
2146 return Result;
2147}
2148
2149template <class TyLoc> static inline
2150QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2151 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2152 NewT.setNameLoc(T.getNameLoc());
2153 return T.getType();
2154}
2155
2156// Ugly metaprogramming macros because I couldn't be bothered to make
2157// the equivalent template version work.
2158#define TransformPointerLikeType(TypeClass) do { \
2159 QualType PointeeType \
2160 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2161 if (PointeeType.isNull()) \
2162 return QualType(); \
2163 \
2164 QualType Result = TL.getType(); \
2165 if (getDerived().AlwaysRebuild() || \
2166 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall70dd5f62009-10-30 00:06:24 +00002167 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2168 TL.getSigilLoc()); \
John McCall550e0c22009-10-21 00:40:46 +00002169 if (Result.isNull()) \
2170 return QualType(); \
2171 } \
2172 \
2173 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2174 NewT.setSigilLoc(TL.getSigilLoc()); \
2175 \
2176 return Result; \
2177} while(0)
2178
John McCall550e0c22009-10-21 00:40:46 +00002179template<typename Derived>
2180QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
2181 BuiltinTypeLoc T) {
2182 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002183}
Mike Stump11289f42009-09-09 15:08:12 +00002184
Douglas Gregord6ff3322009-08-04 16:50:30 +00002185template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002186QualType
John McCall550e0c22009-10-21 00:40:46 +00002187TreeTransform<Derived>::TransformFixedWidthIntType(TypeLocBuilder &TLB,
2188 FixedWidthIntTypeLoc T) {
2189 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002190}
Argyrios Kyrtzidise9189262009-08-19 01:28:17 +00002191
Douglas Gregord6ff3322009-08-04 16:50:30 +00002192template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002193QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
2194 ComplexTypeLoc T) {
2195 // FIXME: recurse?
2196 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002197}
Mike Stump11289f42009-09-09 15:08:12 +00002198
Douglas Gregord6ff3322009-08-04 16:50:30 +00002199template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002200QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
2201 PointerTypeLoc TL) {
2202 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002203}
Mike Stump11289f42009-09-09 15:08:12 +00002204
2205template<typename Derived>
2206QualType
John McCall550e0c22009-10-21 00:40:46 +00002207TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
2208 BlockPointerTypeLoc TL) {
2209 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002210}
2211
John McCall70dd5f62009-10-30 00:06:24 +00002212/// Transforms a reference type. Note that somewhat paradoxically we
2213/// don't care whether the type itself is an l-value type or an r-value
2214/// type; we only care if the type was *written* as an l-value type
2215/// or an r-value type.
2216template<typename Derived>
2217QualType
2218TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
2219 ReferenceTypeLoc TL) {
2220 const ReferenceType *T = TL.getTypePtr();
2221
2222 // Note that this works with the pointee-as-written.
2223 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2224 if (PointeeType.isNull())
2225 return QualType();
2226
2227 QualType Result = TL.getType();
2228 if (getDerived().AlwaysRebuild() ||
2229 PointeeType != T->getPointeeTypeAsWritten()) {
2230 Result = getDerived().RebuildReferenceType(PointeeType,
2231 T->isSpelledAsLValue(),
2232 TL.getSigilLoc());
2233 if (Result.isNull())
2234 return QualType();
2235 }
2236
2237 // r-value references can be rebuilt as l-value references.
2238 ReferenceTypeLoc NewTL;
2239 if (isa<LValueReferenceType>(Result))
2240 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2241 else
2242 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2243 NewTL.setSigilLoc(TL.getSigilLoc());
2244
2245 return Result;
2246}
2247
Mike Stump11289f42009-09-09 15:08:12 +00002248template<typename Derived>
2249QualType
John McCall550e0c22009-10-21 00:40:46 +00002250TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
2251 LValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002252 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002253}
2254
Mike Stump11289f42009-09-09 15:08:12 +00002255template<typename Derived>
2256QualType
John McCall550e0c22009-10-21 00:40:46 +00002257TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
2258 RValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002259 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002260}
Mike Stump11289f42009-09-09 15:08:12 +00002261
Douglas Gregord6ff3322009-08-04 16:50:30 +00002262template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002263QualType
John McCall550e0c22009-10-21 00:40:46 +00002264TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
2265 MemberPointerTypeLoc TL) {
2266 MemberPointerType *T = TL.getTypePtr();
2267
2268 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002269 if (PointeeType.isNull())
2270 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002271
John McCall550e0c22009-10-21 00:40:46 +00002272 // TODO: preserve source information for this.
2273 QualType ClassType
2274 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002275 if (ClassType.isNull())
2276 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002277
John McCall550e0c22009-10-21 00:40:46 +00002278 QualType Result = TL.getType();
2279 if (getDerived().AlwaysRebuild() ||
2280 PointeeType != T->getPointeeType() ||
2281 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002282 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2283 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002284 if (Result.isNull())
2285 return QualType();
2286 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002287
John McCall550e0c22009-10-21 00:40:46 +00002288 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2289 NewTL.setSigilLoc(TL.getSigilLoc());
2290
2291 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002292}
2293
Mike Stump11289f42009-09-09 15:08:12 +00002294template<typename Derived>
2295QualType
John McCall550e0c22009-10-21 00:40:46 +00002296TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
2297 ConstantArrayTypeLoc TL) {
2298 ConstantArrayType *T = TL.getTypePtr();
2299 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002300 if (ElementType.isNull())
2301 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002302
John McCall550e0c22009-10-21 00:40:46 +00002303 QualType Result = TL.getType();
2304 if (getDerived().AlwaysRebuild() ||
2305 ElementType != T->getElementType()) {
2306 Result = getDerived().RebuildConstantArrayType(ElementType,
2307 T->getSizeModifier(),
2308 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002309 T->getIndexTypeCVRQualifiers(),
2310 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002311 if (Result.isNull())
2312 return QualType();
2313 }
2314
2315 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2316 NewTL.setLBracketLoc(TL.getLBracketLoc());
2317 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002318
John McCall550e0c22009-10-21 00:40:46 +00002319 Expr *Size = TL.getSizeExpr();
2320 if (Size) {
2321 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2322 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2323 }
2324 NewTL.setSizeExpr(Size);
2325
2326 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002327}
Mike Stump11289f42009-09-09 15:08:12 +00002328
Douglas Gregord6ff3322009-08-04 16:50:30 +00002329template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002330QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002331 TypeLocBuilder &TLB,
2332 IncompleteArrayTypeLoc TL) {
2333 IncompleteArrayType *T = TL.getTypePtr();
2334 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002335 if (ElementType.isNull())
2336 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002337
John McCall550e0c22009-10-21 00:40:46 +00002338 QualType Result = TL.getType();
2339 if (getDerived().AlwaysRebuild() ||
2340 ElementType != T->getElementType()) {
2341 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002342 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002343 T->getIndexTypeCVRQualifiers(),
2344 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002345 if (Result.isNull())
2346 return QualType();
2347 }
2348
2349 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2350 NewTL.setLBracketLoc(TL.getLBracketLoc());
2351 NewTL.setRBracketLoc(TL.getRBracketLoc());
2352 NewTL.setSizeExpr(0);
2353
2354 return Result;
2355}
2356
2357template<typename Derived>
2358QualType
2359TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
2360 VariableArrayTypeLoc TL) {
2361 VariableArrayType *T = TL.getTypePtr();
2362 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2363 if (ElementType.isNull())
2364 return QualType();
2365
2366 // Array bounds are not potentially evaluated contexts
2367 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2368
2369 Sema::OwningExprResult SizeResult
2370 = getDerived().TransformExpr(T->getSizeExpr());
2371 if (SizeResult.isInvalid())
2372 return QualType();
2373
2374 Expr *Size = static_cast<Expr*>(SizeResult.get());
2375
2376 QualType Result = TL.getType();
2377 if (getDerived().AlwaysRebuild() ||
2378 ElementType != T->getElementType() ||
2379 Size != T->getSizeExpr()) {
2380 Result = getDerived().RebuildVariableArrayType(ElementType,
2381 T->getSizeModifier(),
2382 move(SizeResult),
2383 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002384 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002385 if (Result.isNull())
2386 return QualType();
2387 }
2388 else SizeResult.take();
2389
2390 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2391 NewTL.setLBracketLoc(TL.getLBracketLoc());
2392 NewTL.setRBracketLoc(TL.getRBracketLoc());
2393 NewTL.setSizeExpr(Size);
2394
2395 return Result;
2396}
2397
2398template<typename Derived>
2399QualType
2400TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
2401 DependentSizedArrayTypeLoc TL) {
2402 DependentSizedArrayType *T = TL.getTypePtr();
2403 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2404 if (ElementType.isNull())
2405 return QualType();
2406
2407 // Array bounds are not potentially evaluated contexts
2408 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2409
2410 Sema::OwningExprResult SizeResult
2411 = getDerived().TransformExpr(T->getSizeExpr());
2412 if (SizeResult.isInvalid())
2413 return QualType();
2414
2415 Expr *Size = static_cast<Expr*>(SizeResult.get());
2416
2417 QualType Result = TL.getType();
2418 if (getDerived().AlwaysRebuild() ||
2419 ElementType != T->getElementType() ||
2420 Size != T->getSizeExpr()) {
2421 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2422 T->getSizeModifier(),
2423 move(SizeResult),
2424 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002425 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002426 if (Result.isNull())
2427 return QualType();
2428 }
2429 else SizeResult.take();
2430
2431 // We might have any sort of array type now, but fortunately they
2432 // all have the same location layout.
2433 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2434 NewTL.setLBracketLoc(TL.getLBracketLoc());
2435 NewTL.setRBracketLoc(TL.getRBracketLoc());
2436 NewTL.setSizeExpr(Size);
2437
2438 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002439}
Mike Stump11289f42009-09-09 15:08:12 +00002440
2441template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002442QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002443 TypeLocBuilder &TLB,
2444 DependentSizedExtVectorTypeLoc TL) {
2445 DependentSizedExtVectorType *T = TL.getTypePtr();
2446
2447 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002448 QualType ElementType = getDerived().TransformType(T->getElementType());
2449 if (ElementType.isNull())
2450 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002451
Douglas Gregore922c772009-08-04 22:27:00 +00002452 // Vector sizes are not potentially evaluated contexts
2453 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2454
Douglas Gregord6ff3322009-08-04 16:50:30 +00002455 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2456 if (Size.isInvalid())
2457 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002458
John McCall550e0c22009-10-21 00:40:46 +00002459 QualType Result = TL.getType();
2460 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002461 ElementType != T->getElementType() ||
2462 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002463 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002464 move(Size),
2465 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002466 if (Result.isNull())
2467 return QualType();
2468 }
2469 else Size.take();
2470
2471 // Result might be dependent or not.
2472 if (isa<DependentSizedExtVectorType>(Result)) {
2473 DependentSizedExtVectorTypeLoc NewTL
2474 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2475 NewTL.setNameLoc(TL.getNameLoc());
2476 } else {
2477 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2478 NewTL.setNameLoc(TL.getNameLoc());
2479 }
2480
2481 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002482}
Mike Stump11289f42009-09-09 15:08:12 +00002483
2484template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002485QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
2486 VectorTypeLoc TL) {
2487 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002488 QualType ElementType = getDerived().TransformType(T->getElementType());
2489 if (ElementType.isNull())
2490 return QualType();
2491
John McCall550e0c22009-10-21 00:40:46 +00002492 QualType Result = TL.getType();
2493 if (getDerived().AlwaysRebuild() ||
2494 ElementType != T->getElementType()) {
2495 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements());
2496 if (Result.isNull())
2497 return QualType();
2498 }
2499
2500 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2501 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002502
John McCall550e0c22009-10-21 00:40:46 +00002503 return Result;
2504}
2505
2506template<typename Derived>
2507QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
2508 ExtVectorTypeLoc TL) {
2509 VectorType *T = TL.getTypePtr();
2510 QualType ElementType = getDerived().TransformType(T->getElementType());
2511 if (ElementType.isNull())
2512 return QualType();
2513
2514 QualType Result = TL.getType();
2515 if (getDerived().AlwaysRebuild() ||
2516 ElementType != T->getElementType()) {
2517 Result = getDerived().RebuildExtVectorType(ElementType,
2518 T->getNumElements(),
2519 /*FIXME*/ SourceLocation());
2520 if (Result.isNull())
2521 return QualType();
2522 }
2523
2524 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2525 NewTL.setNameLoc(TL.getNameLoc());
2526
2527 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002528}
Mike Stump11289f42009-09-09 15:08:12 +00002529
2530template<typename Derived>
2531QualType
John McCall550e0c22009-10-21 00:40:46 +00002532TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
2533 FunctionProtoTypeLoc TL) {
2534 FunctionProtoType *T = TL.getTypePtr();
2535 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002536 if (ResultType.isNull())
2537 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002538
John McCall550e0c22009-10-21 00:40:46 +00002539 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002540 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002541 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2542 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2543 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump11289f42009-09-09 15:08:12 +00002544
John McCall550e0c22009-10-21 00:40:46 +00002545 QualType NewType;
2546 ParmVarDecl *NewParm;
2547
2548 if (OldParm) {
2549 DeclaratorInfo *OldDI = OldParm->getDeclaratorInfo();
2550 assert(OldDI->getType() == T->getArgType(i));
2551
2552 DeclaratorInfo *NewDI = getDerived().TransformType(OldDI);
2553 if (!NewDI)
2554 return QualType();
2555
2556 if (NewDI == OldDI)
2557 NewParm = OldParm;
2558 else
2559 NewParm = ParmVarDecl::Create(SemaRef.Context,
2560 OldParm->getDeclContext(),
2561 OldParm->getLocation(),
2562 OldParm->getIdentifier(),
2563 NewDI->getType(),
2564 NewDI,
2565 OldParm->getStorageClass(),
2566 /* DefArg */ NULL);
2567 NewType = NewParm->getType();
2568
2569 // Deal with the possibility that we don't have a parameter
2570 // declaration for this parameter.
2571 } else {
2572 NewParm = 0;
2573
2574 QualType OldType = T->getArgType(i);
2575 NewType = getDerived().TransformType(OldType);
2576 if (NewType.isNull())
2577 return QualType();
2578 }
2579
2580 ParamTypes.push_back(NewType);
2581 ParamDecls.push_back(NewParm);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002582 }
Mike Stump11289f42009-09-09 15:08:12 +00002583
John McCall550e0c22009-10-21 00:40:46 +00002584 QualType Result = TL.getType();
2585 if (getDerived().AlwaysRebuild() ||
2586 ResultType != T->getResultType() ||
2587 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2588 Result = getDerived().RebuildFunctionProtoType(ResultType,
2589 ParamTypes.data(),
2590 ParamTypes.size(),
2591 T->isVariadic(),
2592 T->getTypeQuals());
2593 if (Result.isNull())
2594 return QualType();
2595 }
Mike Stump11289f42009-09-09 15:08:12 +00002596
John McCall550e0c22009-10-21 00:40:46 +00002597 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2598 NewTL.setLParenLoc(TL.getLParenLoc());
2599 NewTL.setRParenLoc(TL.getRParenLoc());
2600 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2601 NewTL.setArg(i, ParamDecls[i]);
2602
2603 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002604}
Mike Stump11289f42009-09-09 15:08:12 +00002605
Douglas Gregord6ff3322009-08-04 16:50:30 +00002606template<typename Derived>
2607QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002608 TypeLocBuilder &TLB,
2609 FunctionNoProtoTypeLoc TL) {
2610 FunctionNoProtoType *T = TL.getTypePtr();
2611 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2612 if (ResultType.isNull())
2613 return QualType();
2614
2615 QualType Result = TL.getType();
2616 if (getDerived().AlwaysRebuild() ||
2617 ResultType != T->getResultType())
2618 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2619
2620 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2621 NewTL.setLParenLoc(TL.getLParenLoc());
2622 NewTL.setRParenLoc(TL.getRParenLoc());
2623
2624 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002625}
Mike Stump11289f42009-09-09 15:08:12 +00002626
Douglas Gregord6ff3322009-08-04 16:50:30 +00002627template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002628QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
2629 TypedefTypeLoc TL) {
2630 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002631 TypedefDecl *Typedef
2632 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2633 if (!Typedef)
2634 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002635
John McCall550e0c22009-10-21 00:40:46 +00002636 QualType Result = TL.getType();
2637 if (getDerived().AlwaysRebuild() ||
2638 Typedef != T->getDecl()) {
2639 Result = getDerived().RebuildTypedefType(Typedef);
2640 if (Result.isNull())
2641 return QualType();
2642 }
Mike Stump11289f42009-09-09 15:08:12 +00002643
John McCall550e0c22009-10-21 00:40:46 +00002644 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2645 NewTL.setNameLoc(TL.getNameLoc());
2646
2647 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002648}
Mike Stump11289f42009-09-09 15:08:12 +00002649
Douglas Gregord6ff3322009-08-04 16:50:30 +00002650template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002651QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
2652 TypeOfExprTypeLoc TL) {
2653 TypeOfExprType *T = TL.getTypePtr();
2654
Douglas Gregore922c772009-08-04 22:27:00 +00002655 // typeof expressions are not potentially evaluated contexts
2656 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002657
Douglas Gregord6ff3322009-08-04 16:50:30 +00002658 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2659 if (E.isInvalid())
2660 return QualType();
2661
John McCall550e0c22009-10-21 00:40:46 +00002662 QualType Result = TL.getType();
2663 if (getDerived().AlwaysRebuild() ||
2664 E.get() != T->getUnderlyingExpr()) {
2665 Result = getDerived().RebuildTypeOfExprType(move(E));
2666 if (Result.isNull())
2667 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002668 }
John McCall550e0c22009-10-21 00:40:46 +00002669 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002670
John McCall550e0c22009-10-21 00:40:46 +00002671 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
2672 NewTL.setNameLoc(TL.getNameLoc());
2673
2674 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002675}
Mike Stump11289f42009-09-09 15:08:12 +00002676
2677template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002678QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
2679 TypeOfTypeLoc TL) {
2680 TypeOfType *T = TL.getTypePtr();
2681
2682 // FIXME: should be an inner type, or at least have a DeclaratorInfo.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002683 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2684 if (Underlying.isNull())
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 Underlying != T->getUnderlyingType()) {
2690 Result = getDerived().RebuildTypeOfType(Underlying);
2691 if (Result.isNull())
2692 return QualType();
2693 }
Mike Stump11289f42009-09-09 15:08:12 +00002694
John McCall550e0c22009-10-21 00:40:46 +00002695 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
2696 NewTL.setNameLoc(TL.getNameLoc());
2697
2698 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002699}
Mike Stump11289f42009-09-09 15:08:12 +00002700
2701template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002702QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
2703 DecltypeTypeLoc TL) {
2704 DecltypeType *T = TL.getTypePtr();
2705
Douglas Gregore922c772009-08-04 22:27:00 +00002706 // decltype expressions are not potentially evaluated contexts
2707 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002708
Douglas Gregord6ff3322009-08-04 16:50:30 +00002709 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2710 if (E.isInvalid())
2711 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002712
John McCall550e0c22009-10-21 00:40:46 +00002713 QualType Result = TL.getType();
2714 if (getDerived().AlwaysRebuild() ||
2715 E.get() != T->getUnderlyingExpr()) {
2716 Result = getDerived().RebuildDecltypeType(move(E));
2717 if (Result.isNull())
2718 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002719 }
John McCall550e0c22009-10-21 00:40:46 +00002720 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002721
John McCall550e0c22009-10-21 00:40:46 +00002722 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2723 NewTL.setNameLoc(TL.getNameLoc());
2724
2725 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002726}
2727
2728template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002729QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
2730 RecordTypeLoc TL) {
2731 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002732 RecordDecl *Record
John McCall550e0c22009-10-21 00:40:46 +00002733 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002734 if (!Record)
2735 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002736
John McCall550e0c22009-10-21 00:40:46 +00002737 QualType Result = TL.getType();
2738 if (getDerived().AlwaysRebuild() ||
2739 Record != T->getDecl()) {
2740 Result = getDerived().RebuildRecordType(Record);
2741 if (Result.isNull())
2742 return QualType();
2743 }
Mike Stump11289f42009-09-09 15:08:12 +00002744
John McCall550e0c22009-10-21 00:40:46 +00002745 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2746 NewTL.setNameLoc(TL.getNameLoc());
2747
2748 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002749}
Mike Stump11289f42009-09-09 15:08:12 +00002750
2751template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002752QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
2753 EnumTypeLoc TL) {
2754 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002755 EnumDecl *Enum
John McCall550e0c22009-10-21 00:40:46 +00002756 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002757 if (!Enum)
2758 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002759
John McCall550e0c22009-10-21 00:40:46 +00002760 QualType Result = TL.getType();
2761 if (getDerived().AlwaysRebuild() ||
2762 Enum != T->getDecl()) {
2763 Result = getDerived().RebuildEnumType(Enum);
2764 if (Result.isNull())
2765 return QualType();
2766 }
Mike Stump11289f42009-09-09 15:08:12 +00002767
John McCall550e0c22009-10-21 00:40:46 +00002768 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2769 NewTL.setNameLoc(TL.getNameLoc());
2770
2771 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002772}
John McCallfcc33b02009-09-05 00:15:47 +00002773
2774template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002775QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
2776 ElaboratedTypeLoc TL) {
2777 ElaboratedType *T = TL.getTypePtr();
2778
2779 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002780 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2781 if (Underlying.isNull())
2782 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002783
John McCall550e0c22009-10-21 00:40:46 +00002784 QualType Result = TL.getType();
2785 if (getDerived().AlwaysRebuild() ||
2786 Underlying != T->getUnderlyingType()) {
2787 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2788 if (Result.isNull())
2789 return QualType();
2790 }
Mike Stump11289f42009-09-09 15:08:12 +00002791
John McCall550e0c22009-10-21 00:40:46 +00002792 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2793 NewTL.setNameLoc(TL.getNameLoc());
2794
2795 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002796}
Mike Stump11289f42009-09-09 15:08:12 +00002797
2798
Douglas Gregord6ff3322009-08-04 16:50:30 +00002799template<typename Derived>
2800QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002801 TypeLocBuilder &TLB,
2802 TemplateTypeParmTypeLoc TL) {
2803 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002804}
2805
Mike Stump11289f42009-09-09 15:08:12 +00002806template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002807QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002808 TypeLocBuilder &TLB,
2809 SubstTemplateTypeParmTypeLoc TL) {
2810 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002811}
2812
2813template<typename Derived>
Douglas Gregorc59e5612009-10-19 22:04:39 +00002814inline QualType
2815TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall550e0c22009-10-21 00:40:46 +00002816 TypeLocBuilder &TLB,
2817 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00002818 return TransformTemplateSpecializationType(TLB, TL, QualType());
2819}
John McCall550e0c22009-10-21 00:40:46 +00002820
John McCall0ad16662009-10-29 08:12:44 +00002821template<typename Derived>
2822QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2823 const TemplateSpecializationType *TST,
2824 QualType ObjectType) {
2825 // FIXME: this entire method is a temporary workaround; callers
2826 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00002827
John McCall0ad16662009-10-29 08:12:44 +00002828 // Fake up a TemplateSpecializationTypeLoc.
2829 TypeLocBuilder TLB;
2830 TemplateSpecializationTypeLoc TL
2831 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2832
John McCall0d07eb32009-10-29 18:45:58 +00002833 SourceLocation BaseLoc = getDerived().getBaseLocation();
2834
2835 TL.setTemplateNameLoc(BaseLoc);
2836 TL.setLAngleLoc(BaseLoc);
2837 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00002838 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2839 const TemplateArgument &TA = TST->getArg(i);
2840 TemplateArgumentLoc TAL;
2841 getDerived().InventTemplateArgumentLoc(TA, TAL);
2842 TL.setArgLocInfo(i, TAL.getLocInfo());
2843 }
2844
2845 TypeLocBuilder IgnoredTLB;
2846 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00002847}
2848
2849template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002850QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00002851 TypeLocBuilder &TLB,
2852 TemplateSpecializationTypeLoc TL,
2853 QualType ObjectType) {
2854 const TemplateSpecializationType *T = TL.getTypePtr();
2855
Mike Stump11289f42009-09-09 15:08:12 +00002856 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002857 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002858 if (Template.isNull())
2859 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002860
John McCall6b51f282009-11-23 01:53:49 +00002861 TemplateArgumentListInfo NewTemplateArgs;
2862 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2863 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2864
2865 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2866 TemplateArgumentLoc Loc;
2867 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00002868 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00002869 NewTemplateArgs.addArgument(Loc);
2870 }
Mike Stump11289f42009-09-09 15:08:12 +00002871
John McCall0ad16662009-10-29 08:12:44 +00002872 // FIXME: maybe don't rebuild if all the template arguments are the same.
2873
2874 QualType Result =
2875 getDerived().RebuildTemplateSpecializationType(Template,
2876 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00002877 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00002878
2879 if (!Result.isNull()) {
2880 TemplateSpecializationTypeLoc NewTL
2881 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2882 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2883 NewTL.setLAngleLoc(TL.getLAngleLoc());
2884 NewTL.setRAngleLoc(TL.getRAngleLoc());
2885 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2886 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002887 }
Mike Stump11289f42009-09-09 15:08:12 +00002888
John McCall0ad16662009-10-29 08:12:44 +00002889 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002890}
Mike Stump11289f42009-09-09 15:08:12 +00002891
2892template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002893QualType
2894TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
2895 QualifiedNameTypeLoc TL) {
2896 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002897 NestedNameSpecifier *NNS
2898 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2899 SourceRange());
2900 if (!NNS)
2901 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002902
Douglas Gregord6ff3322009-08-04 16:50:30 +00002903 QualType Named = getDerived().TransformType(T->getNamedType());
2904 if (Named.isNull())
2905 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002906
John McCall550e0c22009-10-21 00:40:46 +00002907 QualType Result = TL.getType();
2908 if (getDerived().AlwaysRebuild() ||
2909 NNS != T->getQualifier() ||
2910 Named != T->getNamedType()) {
2911 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2912 if (Result.isNull())
2913 return QualType();
2914 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002915
John McCall550e0c22009-10-21 00:40:46 +00002916 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2917 NewTL.setNameLoc(TL.getNameLoc());
2918
2919 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002920}
Mike Stump11289f42009-09-09 15:08:12 +00002921
2922template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002923QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
2924 TypenameTypeLoc TL) {
2925 TypenameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00002926
2927 /* FIXME: preserve source information better than this */
2928 SourceRange SR(TL.getNameLoc());
2929
Douglas Gregord6ff3322009-08-04 16:50:30 +00002930 NestedNameSpecifier *NNS
John McCall0ad16662009-10-29 08:12:44 +00002931 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002932 if (!NNS)
2933 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002934
John McCall550e0c22009-10-21 00:40:46 +00002935 QualType Result;
2936
Douglas Gregord6ff3322009-08-04 16:50:30 +00002937 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002938 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002939 = getDerived().TransformType(QualType(TemplateId, 0));
2940 if (NewTemplateId.isNull())
2941 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002942
Douglas Gregord6ff3322009-08-04 16:50:30 +00002943 if (!getDerived().AlwaysRebuild() &&
2944 NNS == T->getQualifier() &&
2945 NewTemplateId == QualType(TemplateId, 0))
2946 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002947
John McCall550e0c22009-10-21 00:40:46 +00002948 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2949 } else {
John McCall0ad16662009-10-29 08:12:44 +00002950 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002951 }
John McCall550e0c22009-10-21 00:40:46 +00002952 if (Result.isNull())
2953 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002954
John McCall550e0c22009-10-21 00:40:46 +00002955 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2956 NewTL.setNameLoc(TL.getNameLoc());
2957
2958 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002959}
Mike Stump11289f42009-09-09 15:08:12 +00002960
Douglas Gregord6ff3322009-08-04 16:50:30 +00002961template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002962QualType
2963TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
2964 ObjCInterfaceTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002965 assert(false && "TransformObjCInterfaceType unimplemented");
2966 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002967}
Mike Stump11289f42009-09-09 15:08:12 +00002968
2969template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002970QualType
2971TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
2972 ObjCObjectPointerTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002973 assert(false && "TransformObjCObjectPointerType unimplemented");
2974 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00002975}
2976
Douglas Gregord6ff3322009-08-04 16:50:30 +00002977//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00002978// Statement transformation
2979//===----------------------------------------------------------------------===//
2980template<typename Derived>
2981Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002982TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2983 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002984}
2985
2986template<typename Derived>
2987Sema::OwningStmtResult
2988TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2989 return getDerived().TransformCompoundStmt(S, false);
2990}
2991
2992template<typename Derived>
2993Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002994TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00002995 bool IsStmtExpr) {
2996 bool SubStmtChanged = false;
2997 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
2998 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
2999 B != BEnd; ++B) {
3000 OwningStmtResult Result = getDerived().TransformStmt(*B);
3001 if (Result.isInvalid())
3002 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003003
Douglas Gregorebe10102009-08-20 07:17:43 +00003004 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3005 Statements.push_back(Result.takeAs<Stmt>());
3006 }
Mike Stump11289f42009-09-09 15:08:12 +00003007
Douglas Gregorebe10102009-08-20 07:17:43 +00003008 if (!getDerived().AlwaysRebuild() &&
3009 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003010 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003011
3012 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3013 move_arg(Statements),
3014 S->getRBracLoc(),
3015 IsStmtExpr);
3016}
Mike Stump11289f42009-09-09 15:08:12 +00003017
Douglas Gregorebe10102009-08-20 07:17:43 +00003018template<typename Derived>
3019Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003020TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003021 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3022 {
3023 // The case value expressions are not potentially evaluated.
3024 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003025
Eli Friedman06577382009-11-19 03:14:00 +00003026 // Transform the left-hand case value.
3027 LHS = getDerived().TransformExpr(S->getLHS());
3028 if (LHS.isInvalid())
3029 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003030
Eli Friedman06577382009-11-19 03:14:00 +00003031 // Transform the right-hand case value (for the GNU case-range extension).
3032 RHS = getDerived().TransformExpr(S->getRHS());
3033 if (RHS.isInvalid())
3034 return SemaRef.StmtError();
3035 }
Mike Stump11289f42009-09-09 15:08:12 +00003036
Douglas Gregorebe10102009-08-20 07:17:43 +00003037 // Build the case statement.
3038 // Case statements are always rebuilt so that they will attached to their
3039 // transformed switch statement.
3040 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3041 move(LHS),
3042 S->getEllipsisLoc(),
3043 move(RHS),
3044 S->getColonLoc());
3045 if (Case.isInvalid())
3046 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003047
Douglas Gregorebe10102009-08-20 07:17:43 +00003048 // Transform the statement following the case
3049 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3050 if (SubStmt.isInvalid())
3051 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003052
Douglas Gregorebe10102009-08-20 07:17:43 +00003053 // Attach the body to the case statement
3054 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3055}
3056
3057template<typename Derived>
3058Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003059TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003060 // Transform the statement following the default case
3061 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3062 if (SubStmt.isInvalid())
3063 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003064
Douglas Gregorebe10102009-08-20 07:17:43 +00003065 // Default statements are always rebuilt
3066 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3067 move(SubStmt));
3068}
Mike Stump11289f42009-09-09 15:08:12 +00003069
Douglas Gregorebe10102009-08-20 07:17:43 +00003070template<typename Derived>
3071Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003072TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003073 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3074 if (SubStmt.isInvalid())
3075 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003076
Douglas Gregorebe10102009-08-20 07:17:43 +00003077 // FIXME: Pass the real colon location in.
3078 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3079 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3080 move(SubStmt));
3081}
Mike Stump11289f42009-09-09 15:08:12 +00003082
Douglas Gregorebe10102009-08-20 07:17:43 +00003083template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003084Sema::OwningStmtResult
3085TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003086 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003087 OwningExprResult Cond(SemaRef);
3088 VarDecl *ConditionVar = 0;
3089 if (S->getConditionVariable()) {
3090 ConditionVar
3091 = cast_or_null<VarDecl>(
3092 getDerived().TransformDefinition(S->getConditionVariable()));
3093 if (!ConditionVar)
3094 return SemaRef.StmtError();
3095
3096 Cond = getSema().CheckConditionVariable(ConditionVar);
3097 } else
3098 Cond = getDerived().TransformExpr(S->getCond());
3099
Douglas Gregorebe10102009-08-20 07:17:43 +00003100 if (Cond.isInvalid())
3101 return SemaRef.StmtError();
Douglas Gregor633caca2009-11-23 23:44:04 +00003102
Douglas Gregorebe10102009-08-20 07:17:43 +00003103 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003104
Douglas Gregorebe10102009-08-20 07:17:43 +00003105 // Transform the "then" branch.
3106 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3107 if (Then.isInvalid())
3108 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003109
Douglas Gregorebe10102009-08-20 07:17:43 +00003110 // Transform the "else" branch.
3111 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3112 if (Else.isInvalid())
3113 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003114
Douglas Gregorebe10102009-08-20 07:17:43 +00003115 if (!getDerived().AlwaysRebuild() &&
3116 FullCond->get() == S->getCond() &&
3117 Then.get() == S->getThen() &&
3118 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003119 return SemaRef.Owned(S->Retain());
3120
Douglas Gregorebe10102009-08-20 07:17:43 +00003121 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003122 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003123}
3124
3125template<typename Derived>
3126Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003127TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003128 // Transform the condition.
3129 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3130 if (Cond.isInvalid())
3131 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003132
Douglas Gregorebe10102009-08-20 07:17:43 +00003133 // Rebuild the switch statement.
3134 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(move(Cond));
3135 if (Switch.isInvalid())
3136 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003137
Douglas Gregorebe10102009-08-20 07:17:43 +00003138 // Transform the body of the switch statement.
3139 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3140 if (Body.isInvalid())
3141 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003142
Douglas Gregorebe10102009-08-20 07:17:43 +00003143 // Complete the switch statement.
3144 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3145 move(Body));
3146}
Mike Stump11289f42009-09-09 15:08:12 +00003147
Douglas Gregorebe10102009-08-20 07:17:43 +00003148template<typename Derived>
3149Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003150TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003151 // Transform the condition
3152 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3153 if (Cond.isInvalid())
3154 return SemaRef.StmtError();
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() &&
3165 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003166 return SemaRef.Owned(S->Retain());
3167
Douglas Gregorebe10102009-08-20 07:17:43 +00003168 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, move(Body));
3169}
Mike Stump11289f42009-09-09 15:08:12 +00003170
Douglas Gregorebe10102009-08-20 07:17:43 +00003171template<typename Derived>
3172Sema::OwningStmtResult
3173TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3174 // Transform the condition
3175 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3176 if (Cond.isInvalid())
3177 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003178
Douglas Gregorebe10102009-08-20 07:17:43 +00003179 // Transform the body
3180 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3181 if (Body.isInvalid())
3182 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003183
Douglas Gregorebe10102009-08-20 07:17:43 +00003184 if (!getDerived().AlwaysRebuild() &&
3185 Cond.get() == S->getCond() &&
3186 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003187 return SemaRef.Owned(S->Retain());
3188
Douglas Gregorebe10102009-08-20 07:17:43 +00003189 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3190 /*FIXME:*/S->getWhileLoc(), move(Cond),
3191 S->getRParenLoc());
3192}
Mike Stump11289f42009-09-09 15:08:12 +00003193
Douglas Gregorebe10102009-08-20 07:17:43 +00003194template<typename Derived>
3195Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003196TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003197 // Transform the initialization statement
3198 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3199 if (Init.isInvalid())
3200 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003201
Douglas Gregorebe10102009-08-20 07:17:43 +00003202 // Transform the condition
3203 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3204 if (Cond.isInvalid())
3205 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003206
Douglas Gregorebe10102009-08-20 07:17:43 +00003207 // Transform the increment
3208 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3209 if (Inc.isInvalid())
3210 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003211
Douglas Gregorebe10102009-08-20 07:17:43 +00003212 // Transform the body
3213 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3214 if (Body.isInvalid())
3215 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003216
Douglas Gregorebe10102009-08-20 07:17:43 +00003217 if (!getDerived().AlwaysRebuild() &&
3218 Init.get() == S->getInit() &&
3219 Cond.get() == S->getCond() &&
3220 Inc.get() == S->getInc() &&
3221 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003222 return SemaRef.Owned(S->Retain());
3223
Douglas Gregorebe10102009-08-20 07:17:43 +00003224 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
3225 move(Init), move(Cond), move(Inc),
3226 S->getRParenLoc(), move(Body));
3227}
3228
3229template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003230Sema::OwningStmtResult
3231TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003232 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003233 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003234 S->getLabel());
3235}
3236
3237template<typename Derived>
3238Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003239TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003240 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3241 if (Target.isInvalid())
3242 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003243
Douglas Gregorebe10102009-08-20 07:17:43 +00003244 if (!getDerived().AlwaysRebuild() &&
3245 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003246 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003247
3248 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3249 move(Target));
3250}
3251
3252template<typename Derived>
3253Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003254TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3255 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003256}
Mike Stump11289f42009-09-09 15:08:12 +00003257
Douglas Gregorebe10102009-08-20 07:17:43 +00003258template<typename Derived>
3259Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003260TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3261 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003262}
Mike Stump11289f42009-09-09 15:08:12 +00003263
Douglas Gregorebe10102009-08-20 07:17:43 +00003264template<typename Derived>
3265Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003266TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003267 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3268 if (Result.isInvalid())
3269 return SemaRef.StmtError();
3270
Mike Stump11289f42009-09-09 15:08:12 +00003271 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003272 // to tell whether the return type of the function has changed.
3273 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3274}
Mike Stump11289f42009-09-09 15:08:12 +00003275
Douglas Gregorebe10102009-08-20 07:17:43 +00003276template<typename Derived>
3277Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003278TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003279 bool DeclChanged = false;
3280 llvm::SmallVector<Decl *, 4> Decls;
3281 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3282 D != DEnd; ++D) {
3283 Decl *Transformed = getDerived().TransformDefinition(*D);
3284 if (!Transformed)
3285 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003286
Douglas Gregorebe10102009-08-20 07:17:43 +00003287 if (Transformed != *D)
3288 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003289
Douglas Gregorebe10102009-08-20 07:17:43 +00003290 Decls.push_back(Transformed);
3291 }
Mike Stump11289f42009-09-09 15:08:12 +00003292
Douglas Gregorebe10102009-08-20 07:17:43 +00003293 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003294 return SemaRef.Owned(S->Retain());
3295
3296 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003297 S->getStartLoc(), S->getEndLoc());
3298}
Mike Stump11289f42009-09-09 15:08:12 +00003299
Douglas Gregorebe10102009-08-20 07:17:43 +00003300template<typename Derived>
3301Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003302TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003303 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003304 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003305}
3306
3307template<typename Derived>
3308Sema::OwningStmtResult
3309TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
3310 // FIXME: Implement!
3311 assert(false && "Inline assembly cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003312 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003313}
3314
3315
3316template<typename Derived>
3317Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003318TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003319 // FIXME: Implement this
3320 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003321 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003322}
Mike Stump11289f42009-09-09 15:08:12 +00003323
Douglas Gregorebe10102009-08-20 07:17:43 +00003324template<typename Derived>
3325Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003326TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003327 // FIXME: Implement this
3328 assert(false && "Cannot transform an Objective-C @catch statement");
3329 return SemaRef.Owned(S->Retain());
3330}
Mike Stump11289f42009-09-09 15:08:12 +00003331
Douglas Gregorebe10102009-08-20 07:17:43 +00003332template<typename Derived>
3333Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003334TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003335 // FIXME: Implement this
3336 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003337 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003338}
Mike Stump11289f42009-09-09 15:08:12 +00003339
Douglas Gregorebe10102009-08-20 07:17:43 +00003340template<typename Derived>
3341Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003342TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003343 // FIXME: Implement this
3344 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003345 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003346}
Mike Stump11289f42009-09-09 15:08:12 +00003347
Douglas Gregorebe10102009-08-20 07:17:43 +00003348template<typename Derived>
3349Sema::OwningStmtResult
3350TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003351 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003352 // FIXME: Implement this
3353 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003354 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003355}
3356
3357template<typename Derived>
3358Sema::OwningStmtResult
3359TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003360 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003361 // FIXME: Implement this
3362 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003363 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003364}
3365
3366
3367template<typename Derived>
3368Sema::OwningStmtResult
3369TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3370 // Transform the exception declaration, if any.
3371 VarDecl *Var = 0;
3372 if (S->getExceptionDecl()) {
3373 VarDecl *ExceptionDecl = S->getExceptionDecl();
3374 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3375 ExceptionDecl->getDeclName());
3376
3377 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3378 if (T.isNull())
3379 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003380
Douglas Gregorebe10102009-08-20 07:17:43 +00003381 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3382 T,
3383 ExceptionDecl->getDeclaratorInfo(),
3384 ExceptionDecl->getIdentifier(),
3385 ExceptionDecl->getLocation(),
3386 /*FIXME: Inaccurate*/
3387 SourceRange(ExceptionDecl->getLocation()));
3388 if (!Var || Var->isInvalidDecl()) {
3389 if (Var)
3390 Var->Destroy(SemaRef.Context);
3391 return SemaRef.StmtError();
3392 }
3393 }
Mike Stump11289f42009-09-09 15:08:12 +00003394
Douglas Gregorebe10102009-08-20 07:17:43 +00003395 // Transform the actual exception handler.
3396 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3397 if (Handler.isInvalid()) {
3398 if (Var)
3399 Var->Destroy(SemaRef.Context);
3400 return SemaRef.StmtError();
3401 }
Mike Stump11289f42009-09-09 15:08:12 +00003402
Douglas Gregorebe10102009-08-20 07:17:43 +00003403 if (!getDerived().AlwaysRebuild() &&
3404 !Var &&
3405 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003406 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003407
3408 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3409 Var,
3410 move(Handler));
3411}
Mike Stump11289f42009-09-09 15:08:12 +00003412
Douglas Gregorebe10102009-08-20 07:17:43 +00003413template<typename Derived>
3414Sema::OwningStmtResult
3415TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3416 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003417 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003418 = getDerived().TransformCompoundStmt(S->getTryBlock());
3419 if (TryBlock.isInvalid())
3420 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003421
Douglas Gregorebe10102009-08-20 07:17:43 +00003422 // Transform the handlers.
3423 bool HandlerChanged = false;
3424 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3425 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003426 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003427 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3428 if (Handler.isInvalid())
3429 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003430
Douglas Gregorebe10102009-08-20 07:17:43 +00003431 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3432 Handlers.push_back(Handler.takeAs<Stmt>());
3433 }
Mike Stump11289f42009-09-09 15:08:12 +00003434
Douglas Gregorebe10102009-08-20 07:17:43 +00003435 if (!getDerived().AlwaysRebuild() &&
3436 TryBlock.get() == S->getTryBlock() &&
3437 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003438 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003439
3440 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003441 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003442}
Mike Stump11289f42009-09-09 15:08:12 +00003443
Douglas Gregorebe10102009-08-20 07:17:43 +00003444//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003445// Expression transformation
3446//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003447template<typename Derived>
3448Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003449TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E,
3450 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003451 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003452}
Mike Stump11289f42009-09-09 15:08:12 +00003453
3454template<typename Derived>
3455Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003456TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E,
3457 bool isAddressOfOperand) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003458 NestedNameSpecifier *Qualifier = 0;
3459 if (E->getQualifier()) {
3460 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3461 E->getQualifierRange());
3462 if (!Qualifier)
3463 return SemaRef.ExprError();
3464 }
3465
Mike Stump11289f42009-09-09 15:08:12 +00003466 NamedDecl *ND
Douglas Gregora16548e2009-08-11 05:31:07 +00003467 = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl()));
3468 if (!ND)
3469 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003470
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003471 if (!getDerived().AlwaysRebuild() &&
3472 Qualifier == E->getQualifier() &&
3473 ND == E->getDecl() &&
3474 !E->hasExplicitTemplateArgumentList())
Mike Stump11289f42009-09-09 15:08:12 +00003475 return SemaRef.Owned(E->Retain());
3476
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003477 // FIXME: We're losing the explicit template arguments in this transformation.
3478
John McCall0ad16662009-10-29 08:12:44 +00003479 llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003480 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall0ad16662009-10-29 08:12:44 +00003481 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I],
3482 TransArgs[I]))
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003483 return SemaRef.ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003484 }
3485
3486 // FIXME: Pass the qualifier/qualifier range along.
3487 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003488 ND, E->getLocation(),
3489 isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00003490}
Mike Stump11289f42009-09-09 15:08:12 +00003491
Douglas Gregora16548e2009-08-11 05:31:07 +00003492template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003493Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003494TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E,
3495 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003496 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003497}
Mike Stump11289f42009-09-09 15:08:12 +00003498
Douglas Gregora16548e2009-08-11 05:31:07 +00003499template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003500Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003501TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E,
3502 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003503 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003504}
Mike Stump11289f42009-09-09 15:08:12 +00003505
Douglas Gregora16548e2009-08-11 05:31:07 +00003506template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003507Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003508TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E,
3509 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003510 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003511}
Mike Stump11289f42009-09-09 15:08:12 +00003512
Douglas Gregora16548e2009-08-11 05:31:07 +00003513template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003514Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003515TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E,
3516 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003517 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003518}
Mike Stump11289f42009-09-09 15:08:12 +00003519
Douglas Gregora16548e2009-08-11 05:31:07 +00003520template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003521Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003522TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E,
3523 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003524 return SemaRef.Owned(E->Retain());
3525}
3526
3527template<typename Derived>
3528Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003529TreeTransform<Derived>::TransformParenExpr(ParenExpr *E,
3530 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003531 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3532 if (SubExpr.isInvalid())
3533 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003534
Douglas Gregora16548e2009-08-11 05:31:07 +00003535 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003536 return SemaRef.Owned(E->Retain());
3537
3538 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003539 E->getRParen());
3540}
3541
Mike Stump11289f42009-09-09 15:08:12 +00003542template<typename Derived>
3543Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003544TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E,
3545 bool isAddressOfOperand) {
3546 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr(),
3547 E->getOpcode() == UnaryOperator::AddrOf);
Douglas Gregora16548e2009-08-11 05:31:07 +00003548 if (SubExpr.isInvalid())
3549 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003550
Douglas Gregora16548e2009-08-11 05:31:07 +00003551 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003552 return SemaRef.Owned(E->Retain());
3553
Douglas Gregora16548e2009-08-11 05:31:07 +00003554 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3555 E->getOpcode(),
3556 move(SubExpr));
3557}
Mike Stump11289f42009-09-09 15:08:12 +00003558
Douglas Gregora16548e2009-08-11 05:31:07 +00003559template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003560Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003561TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E,
3562 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003563 if (E->isArgumentType()) {
John McCall4c98fd82009-11-04 07:28:41 +00003564 DeclaratorInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003565
John McCall4c98fd82009-11-04 07:28:41 +00003566 DeclaratorInfo *NewT = getDerived().TransformType(OldT);
3567 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003568 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003569
John McCall4c98fd82009-11-04 07:28:41 +00003570 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003571 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003572
John McCall4c98fd82009-11-04 07:28:41 +00003573 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003574 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003575 E->getSourceRange());
3576 }
Mike Stump11289f42009-09-09 15:08:12 +00003577
Douglas Gregora16548e2009-08-11 05:31:07 +00003578 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003579 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003580 // C++0x [expr.sizeof]p1:
3581 // The operand is either an expression, which is an unevaluated operand
3582 // [...]
3583 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003584
Douglas Gregora16548e2009-08-11 05:31:07 +00003585 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3586 if (SubExpr.isInvalid())
3587 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003588
Douglas Gregora16548e2009-08-11 05:31:07 +00003589 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3590 return SemaRef.Owned(E->Retain());
3591 }
Mike Stump11289f42009-09-09 15:08:12 +00003592
Douglas Gregora16548e2009-08-11 05:31:07 +00003593 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3594 E->isSizeOf(),
3595 E->getSourceRange());
3596}
Mike Stump11289f42009-09-09 15:08:12 +00003597
Douglas Gregora16548e2009-08-11 05:31:07 +00003598template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003599Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003600TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E,
3601 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003602 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3603 if (LHS.isInvalid())
3604 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003605
Douglas Gregora16548e2009-08-11 05:31:07 +00003606 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3607 if (RHS.isInvalid())
3608 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003609
3610
Douglas Gregora16548e2009-08-11 05:31:07 +00003611 if (!getDerived().AlwaysRebuild() &&
3612 LHS.get() == E->getLHS() &&
3613 RHS.get() == E->getRHS())
3614 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003615
Douglas Gregora16548e2009-08-11 05:31:07 +00003616 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3617 /*FIXME:*/E->getLHS()->getLocStart(),
3618 move(RHS),
3619 E->getRBracketLoc());
3620}
Mike Stump11289f42009-09-09 15:08:12 +00003621
3622template<typename Derived>
3623Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003624TreeTransform<Derived>::TransformCallExpr(CallExpr *E,
3625 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003626 // Transform the callee.
3627 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3628 if (Callee.isInvalid())
3629 return SemaRef.ExprError();
3630
3631 // Transform arguments.
3632 bool ArgChanged = false;
3633 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3634 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3635 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3636 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3637 if (Arg.isInvalid())
3638 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003639
Douglas Gregora16548e2009-08-11 05:31:07 +00003640 // FIXME: Wrong source location information for the ','.
3641 FakeCommaLocs.push_back(
3642 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003643
3644 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003645 Args.push_back(Arg.takeAs<Expr>());
3646 }
Mike Stump11289f42009-09-09 15:08:12 +00003647
Douglas Gregora16548e2009-08-11 05:31:07 +00003648 if (!getDerived().AlwaysRebuild() &&
3649 Callee.get() == E->getCallee() &&
3650 !ArgChanged)
3651 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003652
Douglas Gregora16548e2009-08-11 05:31:07 +00003653 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003654 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003655 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3656 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3657 move_arg(Args),
3658 FakeCommaLocs.data(),
3659 E->getRParenLoc());
3660}
Mike Stump11289f42009-09-09 15:08:12 +00003661
3662template<typename Derived>
3663Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003664TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E,
3665 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003666 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3667 if (Base.isInvalid())
3668 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003669
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003670 NestedNameSpecifier *Qualifier = 0;
3671 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003672 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003673 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3674 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003675 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003676 return SemaRef.ExprError();
3677 }
Mike Stump11289f42009-09-09 15:08:12 +00003678
3679 NamedDecl *Member
Douglas Gregora16548e2009-08-11 05:31:07 +00003680 = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getMemberDecl()));
3681 if (!Member)
3682 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003683
Douglas Gregora16548e2009-08-11 05:31:07 +00003684 if (!getDerived().AlwaysRebuild() &&
3685 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003686 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003687 Member == E->getMemberDecl() &&
3688 !E->hasExplicitTemplateArgumentList())
Mike Stump11289f42009-09-09 15:08:12 +00003689 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003690
John McCall6b51f282009-11-23 01:53:49 +00003691 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003692 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003693 TransArgs.setLAngleLoc(E->getLAngleLoc());
3694 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003695 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003696 TemplateArgumentLoc Loc;
3697 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003698 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003699 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003700 }
3701 }
3702
Douglas Gregora16548e2009-08-11 05:31:07 +00003703 // FIXME: Bogus source location for the operator
3704 SourceLocation FakeOperatorLoc
3705 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3706
3707 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3708 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003709 Qualifier,
3710 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003711 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003712 Member,
John McCall6b51f282009-11-23 01:53:49 +00003713 (E->hasExplicitTemplateArgumentList()
3714 ? &TransArgs : 0),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003715 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00003716}
Mike Stump11289f42009-09-09 15:08:12 +00003717
Douglas Gregora16548e2009-08-11 05:31:07 +00003718template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003719Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003720TreeTransform<Derived>::TransformCastExpr(CastExpr *E,
3721 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003722 assert(false && "Cannot transform abstract class");
3723 return SemaRef.Owned(E->Retain());
3724}
3725
3726template<typename Derived>
3727Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003728TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E,
3729 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003730 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3731 if (LHS.isInvalid())
3732 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003733
Douglas Gregora16548e2009-08-11 05:31:07 +00003734 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3735 if (RHS.isInvalid())
3736 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003737
Douglas Gregora16548e2009-08-11 05:31:07 +00003738 if (!getDerived().AlwaysRebuild() &&
3739 LHS.get() == E->getLHS() &&
3740 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003741 return SemaRef.Owned(E->Retain());
3742
Douglas Gregora16548e2009-08-11 05:31:07 +00003743 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3744 move(LHS), move(RHS));
3745}
3746
Mike Stump11289f42009-09-09 15:08:12 +00003747template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003748Sema::OwningExprResult
3749TreeTransform<Derived>::TransformCompoundAssignOperator(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003750 CompoundAssignOperator *E,
3751 bool isAddressOfOperand) {
3752 return getDerived().TransformBinaryOperator(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00003753}
Mike Stump11289f42009-09-09 15:08:12 +00003754
Douglas Gregora16548e2009-08-11 05:31:07 +00003755template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003756Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003757TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E,
3758 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003759 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3760 if (Cond.isInvalid())
3761 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003762
Douglas Gregora16548e2009-08-11 05:31:07 +00003763 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3764 if (LHS.isInvalid())
3765 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003766
Douglas Gregora16548e2009-08-11 05:31:07 +00003767 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3768 if (RHS.isInvalid())
3769 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003770
Douglas Gregora16548e2009-08-11 05:31:07 +00003771 if (!getDerived().AlwaysRebuild() &&
3772 Cond.get() == E->getCond() &&
3773 LHS.get() == E->getLHS() &&
3774 RHS.get() == E->getRHS())
3775 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003776
3777 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003778 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003779 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003780 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003781 move(RHS));
3782}
Mike Stump11289f42009-09-09 15:08:12 +00003783
3784template<typename Derived>
3785Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003786TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E,
3787 bool isAddressOfOperand) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00003788 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3789
3790 // FIXME: Will we ever have type information here? It seems like we won't,
3791 // so do we even need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00003792 QualType T = getDerived().TransformType(E->getType());
3793 if (T.isNull())
3794 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003795
Douglas Gregora16548e2009-08-11 05:31:07 +00003796 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3797 if (SubExpr.isInvalid())
3798 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003799
Douglas Gregora16548e2009-08-11 05:31:07 +00003800 if (!getDerived().AlwaysRebuild() &&
3801 T == E->getType() &&
3802 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003803 return SemaRef.Owned(E->Retain());
3804
Douglas Gregora16548e2009-08-11 05:31:07 +00003805 return getDerived().RebuildImplicitCastExpr(T, E->getCastKind(),
Mike Stump11289f42009-09-09 15:08:12 +00003806 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00003807 E->isLvalueCast());
3808}
Mike Stump11289f42009-09-09 15:08:12 +00003809
Douglas Gregora16548e2009-08-11 05:31:07 +00003810template<typename Derived>
3811Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003812TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E,
3813 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003814 assert(false && "Cannot transform abstract class");
3815 return SemaRef.Owned(E->Retain());
3816}
3817
3818template<typename Derived>
3819Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003820TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E,
3821 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003822 QualType T;
3823 {
3824 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003825 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003826 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3827 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003828
Douglas Gregora16548e2009-08-11 05:31:07 +00003829 T = getDerived().TransformType(E->getTypeAsWritten());
3830 if (T.isNull())
3831 return SemaRef.ExprError();
3832 }
Mike Stump11289f42009-09-09 15:08:12 +00003833
Douglas Gregora16548e2009-08-11 05:31:07 +00003834 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3835 if (SubExpr.isInvalid())
3836 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003837
Douglas Gregora16548e2009-08-11 05:31:07 +00003838 if (!getDerived().AlwaysRebuild() &&
3839 T == E->getTypeAsWritten() &&
3840 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003841 return SemaRef.Owned(E->Retain());
3842
Douglas Gregora16548e2009-08-11 05:31:07 +00003843 return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T,
3844 E->getRParenLoc(),
3845 move(SubExpr));
3846}
Mike Stump11289f42009-09-09 15:08:12 +00003847
Douglas Gregora16548e2009-08-11 05:31:07 +00003848template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003849Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003850TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E,
3851 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003852 QualType T;
3853 {
3854 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003855 SourceLocation FakeTypeLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003856 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3857 TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003858
Douglas Gregora16548e2009-08-11 05:31:07 +00003859 T = getDerived().TransformType(E->getType());
3860 if (T.isNull())
3861 return SemaRef.ExprError();
3862 }
Mike Stump11289f42009-09-09 15:08:12 +00003863
Douglas Gregora16548e2009-08-11 05:31:07 +00003864 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3865 if (Init.isInvalid())
3866 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003867
Douglas Gregora16548e2009-08-11 05:31:07 +00003868 if (!getDerived().AlwaysRebuild() &&
3869 T == E->getType() &&
3870 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003871 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003872
3873 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T,
3874 /*FIXME:*/E->getInitializer()->getLocEnd(),
3875 move(Init));
3876}
Mike Stump11289f42009-09-09 15:08:12 +00003877
Douglas Gregora16548e2009-08-11 05:31:07 +00003878template<typename Derived>
3879Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003880TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E,
3881 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003882 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3883 if (Base.isInvalid())
3884 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003885
Douglas Gregora16548e2009-08-11 05:31:07 +00003886 if (!getDerived().AlwaysRebuild() &&
3887 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003888 return SemaRef.Owned(E->Retain());
3889
Douglas Gregora16548e2009-08-11 05:31:07 +00003890 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003891 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003892 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3893 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3894 E->getAccessorLoc(),
3895 E->getAccessor());
3896}
Mike Stump11289f42009-09-09 15:08:12 +00003897
Douglas Gregora16548e2009-08-11 05:31:07 +00003898template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003899Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003900TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E,
3901 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003902 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003903
Douglas Gregora16548e2009-08-11 05:31:07 +00003904 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3905 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3906 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3907 if (Init.isInvalid())
3908 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003909
Douglas Gregora16548e2009-08-11 05:31:07 +00003910 InitChanged = InitChanged || Init.get() != E->getInit(I);
3911 Inits.push_back(Init.takeAs<Expr>());
3912 }
Mike Stump11289f42009-09-09 15:08:12 +00003913
Douglas Gregora16548e2009-08-11 05:31:07 +00003914 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003915 return SemaRef.Owned(E->Retain());
3916
Douglas Gregora16548e2009-08-11 05:31:07 +00003917 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00003918 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00003919}
Mike Stump11289f42009-09-09 15:08:12 +00003920
Douglas Gregora16548e2009-08-11 05:31:07 +00003921template<typename Derived>
3922Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003923TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E,
3924 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003925 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00003926
Douglas Gregorebe10102009-08-20 07:17:43 +00003927 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00003928 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3929 if (Init.isInvalid())
3930 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003931
Douglas Gregorebe10102009-08-20 07:17:43 +00003932 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00003933 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3934 bool ExprChanged = false;
3935 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3936 DEnd = E->designators_end();
3937 D != DEnd; ++D) {
3938 if (D->isFieldDesignator()) {
3939 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3940 D->getDotLoc(),
3941 D->getFieldLoc()));
3942 continue;
3943 }
Mike Stump11289f42009-09-09 15:08:12 +00003944
Douglas Gregora16548e2009-08-11 05:31:07 +00003945 if (D->isArrayDesignator()) {
3946 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3947 if (Index.isInvalid())
3948 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003949
3950 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003951 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003952
Douglas Gregora16548e2009-08-11 05:31:07 +00003953 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3954 ArrayExprs.push_back(Index.release());
3955 continue;
3956 }
Mike Stump11289f42009-09-09 15:08:12 +00003957
Douglas Gregora16548e2009-08-11 05:31:07 +00003958 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00003959 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00003960 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3961 if (Start.isInvalid())
3962 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003963
Douglas Gregora16548e2009-08-11 05:31:07 +00003964 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3965 if (End.isInvalid())
3966 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003967
3968 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003969 End.get(),
3970 D->getLBracketLoc(),
3971 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003972
Douglas Gregora16548e2009-08-11 05:31:07 +00003973 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
3974 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00003975
Douglas Gregora16548e2009-08-11 05:31:07 +00003976 ArrayExprs.push_back(Start.release());
3977 ArrayExprs.push_back(End.release());
3978 }
Mike Stump11289f42009-09-09 15:08:12 +00003979
Douglas Gregora16548e2009-08-11 05:31:07 +00003980 if (!getDerived().AlwaysRebuild() &&
3981 Init.get() == E->getInit() &&
3982 !ExprChanged)
3983 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003984
Douglas Gregora16548e2009-08-11 05:31:07 +00003985 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
3986 E->getEqualOrColonLoc(),
3987 E->usesGNUSyntax(), move(Init));
3988}
Mike Stump11289f42009-09-09 15:08:12 +00003989
Douglas Gregora16548e2009-08-11 05:31:07 +00003990template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003991Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003992TreeTransform<Derived>::TransformImplicitValueInitExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003993 ImplicitValueInitExpr *E,
3994 bool isAddressOfOperand) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00003995 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3996
3997 // FIXME: Will we ever have proper type location here? Will we actually
3998 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00003999 QualType T = getDerived().TransformType(E->getType());
4000 if (T.isNull())
4001 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004002
Douglas Gregora16548e2009-08-11 05:31:07 +00004003 if (!getDerived().AlwaysRebuild() &&
4004 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004005 return SemaRef.Owned(E->Retain());
4006
Douglas Gregora16548e2009-08-11 05:31:07 +00004007 return getDerived().RebuildImplicitValueInitExpr(T);
4008}
Mike Stump11289f42009-09-09 15:08:12 +00004009
Douglas Gregora16548e2009-08-11 05:31:07 +00004010template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004011Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004012TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E,
4013 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004014 // FIXME: Do we want the type as written?
4015 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004016
Douglas Gregora16548e2009-08-11 05:31:07 +00004017 {
4018 // FIXME: Source location isn't quite accurate.
4019 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4020 T = getDerived().TransformType(E->getType());
4021 if (T.isNull())
4022 return SemaRef.ExprError();
4023 }
Mike Stump11289f42009-09-09 15:08:12 +00004024
Douglas Gregora16548e2009-08-11 05:31:07 +00004025 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4026 if (SubExpr.isInvalid())
4027 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004028
Douglas Gregora16548e2009-08-11 05:31:07 +00004029 if (!getDerived().AlwaysRebuild() &&
4030 T == E->getType() &&
4031 SubExpr.get() == E->getSubExpr())
4032 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004033
Douglas Gregora16548e2009-08-11 05:31:07 +00004034 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4035 T, E->getRParenLoc());
4036}
4037
4038template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004039Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004040TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E,
4041 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004042 bool ArgumentChanged = false;
4043 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4044 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4045 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4046 if (Init.isInvalid())
4047 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004048
Douglas Gregora16548e2009-08-11 05:31:07 +00004049 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4050 Inits.push_back(Init.takeAs<Expr>());
4051 }
Mike Stump11289f42009-09-09 15:08:12 +00004052
Douglas Gregora16548e2009-08-11 05:31:07 +00004053 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4054 move_arg(Inits),
4055 E->getRParenLoc());
4056}
Mike Stump11289f42009-09-09 15:08:12 +00004057
Douglas Gregora16548e2009-08-11 05:31:07 +00004058/// \brief Transform an address-of-label expression.
4059///
4060/// By default, the transformation of an address-of-label expression always
4061/// rebuilds the expression, so that the label identifier can be resolved to
4062/// the corresponding label statement by semantic analysis.
4063template<typename Derived>
4064Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004065TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E,
4066 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004067 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4068 E->getLabel());
4069}
Mike Stump11289f42009-09-09 15:08:12 +00004070
4071template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004072Sema::OwningExprResult
4073TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E,
4074 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004075 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004076 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4077 if (SubStmt.isInvalid())
4078 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004079
Douglas Gregora16548e2009-08-11 05:31:07 +00004080 if (!getDerived().AlwaysRebuild() &&
4081 SubStmt.get() == E->getSubStmt())
4082 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004083
4084 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004085 move(SubStmt),
4086 E->getRParenLoc());
4087}
Mike Stump11289f42009-09-09 15:08:12 +00004088
Douglas Gregora16548e2009-08-11 05:31:07 +00004089template<typename Derived>
4090Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004091TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E,
4092 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004093 QualType T1, T2;
4094 {
4095 // FIXME: Source location isn't quite accurate.
4096 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004097
Douglas Gregora16548e2009-08-11 05:31:07 +00004098 T1 = getDerived().TransformType(E->getArgType1());
4099 if (T1.isNull())
4100 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004101
Douglas Gregora16548e2009-08-11 05:31:07 +00004102 T2 = getDerived().TransformType(E->getArgType2());
4103 if (T2.isNull())
4104 return SemaRef.ExprError();
4105 }
4106
4107 if (!getDerived().AlwaysRebuild() &&
4108 T1 == E->getArgType1() &&
4109 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004110 return SemaRef.Owned(E->Retain());
4111
Douglas Gregora16548e2009-08-11 05:31:07 +00004112 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4113 T1, T2, E->getRParenLoc());
4114}
Mike Stump11289f42009-09-09 15:08:12 +00004115
Douglas Gregora16548e2009-08-11 05:31:07 +00004116template<typename Derived>
4117Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004118TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E,
4119 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004120 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4121 if (Cond.isInvalid())
4122 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004123
Douglas Gregora16548e2009-08-11 05:31:07 +00004124 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4125 if (LHS.isInvalid())
4126 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004127
Douglas Gregora16548e2009-08-11 05:31:07 +00004128 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4129 if (RHS.isInvalid())
4130 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004131
Douglas Gregora16548e2009-08-11 05:31:07 +00004132 if (!getDerived().AlwaysRebuild() &&
4133 Cond.get() == E->getCond() &&
4134 LHS.get() == E->getLHS() &&
4135 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004136 return SemaRef.Owned(E->Retain());
4137
Douglas Gregora16548e2009-08-11 05:31:07 +00004138 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4139 move(Cond), move(LHS), move(RHS),
4140 E->getRParenLoc());
4141}
Mike Stump11289f42009-09-09 15:08:12 +00004142
Douglas Gregora16548e2009-08-11 05:31:07 +00004143template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004144Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004145TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E,
4146 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004147 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004148}
4149
4150template<typename Derived>
4151Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004152TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E,
4153 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004154 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4155 if (Callee.isInvalid())
4156 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004157
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004158 OwningExprResult First
4159 = getDerived().TransformExpr(E->getArg(0),
4160 E->getNumArgs() == 1 && E->getOperator() == OO_Amp);
Douglas Gregora16548e2009-08-11 05:31:07 +00004161 if (First.isInvalid())
4162 return SemaRef.ExprError();
4163
4164 OwningExprResult Second(SemaRef);
4165 if (E->getNumArgs() == 2) {
4166 Second = getDerived().TransformExpr(E->getArg(1));
4167 if (Second.isInvalid())
4168 return SemaRef.ExprError();
4169 }
Mike Stump11289f42009-09-09 15:08:12 +00004170
Douglas Gregora16548e2009-08-11 05:31:07 +00004171 if (!getDerived().AlwaysRebuild() &&
4172 Callee.get() == E->getCallee() &&
4173 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004174 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4175 return SemaRef.Owned(E->Retain());
4176
Douglas Gregora16548e2009-08-11 05:31:07 +00004177 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4178 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004179 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004180 move(First),
4181 move(Second));
4182}
Mike Stump11289f42009-09-09 15:08:12 +00004183
Douglas Gregora16548e2009-08-11 05:31:07 +00004184template<typename Derived>
4185Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004186TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E,
4187 bool isAddressOfOperand) {
4188 return getDerived().TransformCallExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004189}
Mike Stump11289f42009-09-09 15:08:12 +00004190
Douglas Gregora16548e2009-08-11 05:31:07 +00004191template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004192Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004193TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E,
4194 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004195 QualType ExplicitTy;
4196 {
4197 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004198 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004199 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4200 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004201
Douglas Gregora16548e2009-08-11 05:31:07 +00004202 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4203 if (ExplicitTy.isNull())
4204 return SemaRef.ExprError();
4205 }
Mike Stump11289f42009-09-09 15:08:12 +00004206
Douglas Gregora16548e2009-08-11 05:31:07 +00004207 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4208 if (SubExpr.isInvalid())
4209 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004210
Douglas Gregora16548e2009-08-11 05:31:07 +00004211 if (!getDerived().AlwaysRebuild() &&
4212 ExplicitTy == E->getTypeAsWritten() &&
4213 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004214 return SemaRef.Owned(E->Retain());
4215
Douglas Gregora16548e2009-08-11 05:31:07 +00004216 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004217 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004218 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4219 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4220 SourceLocation FakeRParenLoc
4221 = SemaRef.PP.getLocForEndOfToken(
4222 E->getSubExpr()->getSourceRange().getEnd());
4223 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004224 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004225 FakeLAngleLoc,
4226 ExplicitTy,
4227 FakeRAngleLoc,
4228 FakeRAngleLoc,
4229 move(SubExpr),
4230 FakeRParenLoc);
4231}
Mike Stump11289f42009-09-09 15:08:12 +00004232
Douglas Gregora16548e2009-08-11 05:31:07 +00004233template<typename Derived>
4234Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004235TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E,
4236 bool isAddressOfOperand) {
4237 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004238}
Mike Stump11289f42009-09-09 15:08:12 +00004239
4240template<typename Derived>
4241Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004242TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E,
4243 bool isAddressOfOperand) {
4244 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Mike Stump11289f42009-09-09 15:08:12 +00004245}
4246
Douglas Gregora16548e2009-08-11 05:31:07 +00004247template<typename Derived>
4248Sema::OwningExprResult
4249TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004250 CXXReinterpretCastExpr *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
Douglas Gregora16548e2009-08-11 05:31:07 +00004255template<typename Derived>
4256Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004257TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E,
4258 bool isAddressOfOperand) {
4259 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004260}
Mike Stump11289f42009-09-09 15:08:12 +00004261
Douglas Gregora16548e2009-08-11 05:31:07 +00004262template<typename Derived>
4263Sema::OwningExprResult
4264TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004265 CXXFunctionalCastExpr *E,
4266 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004267 QualType ExplicitTy;
4268 {
4269 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004270
Douglas Gregora16548e2009-08-11 05:31:07 +00004271 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4272 if (ExplicitTy.isNull())
4273 return SemaRef.ExprError();
4274 }
Mike Stump11289f42009-09-09 15:08:12 +00004275
Douglas Gregora16548e2009-08-11 05:31:07 +00004276 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4277 if (SubExpr.isInvalid())
4278 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004279
Douglas Gregora16548e2009-08-11 05:31:07 +00004280 if (!getDerived().AlwaysRebuild() &&
4281 ExplicitTy == E->getTypeAsWritten() &&
4282 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004283 return SemaRef.Owned(E->Retain());
4284
Douglas Gregora16548e2009-08-11 05:31:07 +00004285 // FIXME: The end of the type's source range is wrong
4286 return getDerived().RebuildCXXFunctionalCastExpr(
4287 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
4288 ExplicitTy,
4289 /*FIXME:*/E->getSubExpr()->getLocStart(),
4290 move(SubExpr),
4291 E->getRParenLoc());
4292}
Mike Stump11289f42009-09-09 15:08:12 +00004293
Douglas Gregora16548e2009-08-11 05:31:07 +00004294template<typename Derived>
4295Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004296TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E,
4297 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004298 if (E->isTypeOperand()) {
4299 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004300
Douglas Gregora16548e2009-08-11 05:31:07 +00004301 QualType T = getDerived().TransformType(E->getTypeOperand());
4302 if (T.isNull())
4303 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004304
Douglas Gregora16548e2009-08-11 05:31:07 +00004305 if (!getDerived().AlwaysRebuild() &&
4306 T == E->getTypeOperand())
4307 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004308
Douglas Gregora16548e2009-08-11 05:31:07 +00004309 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4310 /*FIXME:*/E->getLocStart(),
4311 T,
4312 E->getLocEnd());
4313 }
Mike Stump11289f42009-09-09 15:08:12 +00004314
Douglas Gregora16548e2009-08-11 05:31:07 +00004315 // We don't know whether the expression is potentially evaluated until
4316 // after we perform semantic analysis, so the expression is potentially
4317 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004318 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004319 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004320
Douglas Gregora16548e2009-08-11 05:31:07 +00004321 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4322 if (SubExpr.isInvalid())
4323 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004324
Douglas Gregora16548e2009-08-11 05:31:07 +00004325 if (!getDerived().AlwaysRebuild() &&
4326 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004327 return SemaRef.Owned(E->Retain());
4328
Douglas Gregora16548e2009-08-11 05:31:07 +00004329 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4330 /*FIXME:*/E->getLocStart(),
4331 move(SubExpr),
4332 E->getLocEnd());
4333}
4334
4335template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004336Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004337TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E,
4338 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004339 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004340}
Mike Stump11289f42009-09-09 15:08:12 +00004341
Douglas Gregora16548e2009-08-11 05:31:07 +00004342template<typename Derived>
4343Sema::OwningExprResult
4344TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004345 CXXNullPtrLiteralExpr *E,
4346 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004347 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004348}
Mike Stump11289f42009-09-09 15:08:12 +00004349
Douglas Gregora16548e2009-08-11 05:31:07 +00004350template<typename Derived>
4351Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004352TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E,
4353 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004354 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004355
Douglas Gregora16548e2009-08-11 05:31:07 +00004356 QualType T = getDerived().TransformType(E->getType());
4357 if (T.isNull())
4358 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004359
Douglas Gregora16548e2009-08-11 05:31:07 +00004360 if (!getDerived().AlwaysRebuild() &&
4361 T == E->getType())
4362 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004363
Douglas Gregora16548e2009-08-11 05:31:07 +00004364 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T);
4365}
Mike Stump11289f42009-09-09 15:08:12 +00004366
Douglas Gregora16548e2009-08-11 05:31:07 +00004367template<typename Derived>
4368Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004369TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E,
4370 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004371 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4372 if (SubExpr.isInvalid())
4373 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004374
Douglas Gregora16548e2009-08-11 05:31:07 +00004375 if (!getDerived().AlwaysRebuild() &&
4376 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004377 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004378
4379 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
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>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E,
4385 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004386 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004387 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4388 if (!Param)
4389 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004390
Douglas Gregora16548e2009-08-11 05:31:07 +00004391 if (getDerived().AlwaysRebuild() &&
4392 Param == E->getParam())
4393 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004394
Douglas Gregora16548e2009-08-11 05:31:07 +00004395 return getDerived().RebuildCXXDefaultArgExpr(Param);
4396}
Mike Stump11289f42009-09-09 15:08:12 +00004397
Douglas Gregora16548e2009-08-11 05:31:07 +00004398template<typename Derived>
4399Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004400TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E,
4401 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004402 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4403
4404 QualType T = getDerived().TransformType(E->getType());
4405 if (T.isNull())
4406 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004407
Douglas Gregora16548e2009-08-11 05:31:07 +00004408 if (!getDerived().AlwaysRebuild() &&
4409 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004410 return SemaRef.Owned(E->Retain());
4411
4412 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004413 /*FIXME:*/E->getTypeBeginLoc(),
4414 T,
4415 E->getRParenLoc());
4416}
Mike Stump11289f42009-09-09 15:08:12 +00004417
Douglas Gregora16548e2009-08-11 05:31:07 +00004418template<typename Derived>
4419Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004420TreeTransform<Derived>::TransformCXXConditionDeclExpr(CXXConditionDeclExpr *E,
4421 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004422 VarDecl *Var
Douglas Gregorebe10102009-08-20 07:17:43 +00004423 = cast_or_null<VarDecl>(getDerived().TransformDefinition(E->getVarDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004424 if (!Var)
4425 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004426
Douglas Gregora16548e2009-08-11 05:31:07 +00004427 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004428 Var == E->getVarDecl())
Douglas Gregora16548e2009-08-11 05:31:07 +00004429 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004430
4431 return getDerived().RebuildCXXConditionDeclExpr(E->getStartLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004432 /*FIXME:*/E->getStartLoc(),
4433 Var);
4434}
Mike Stump11289f42009-09-09 15:08:12 +00004435
Douglas Gregora16548e2009-08-11 05:31:07 +00004436template<typename Derived>
4437Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004438TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E,
4439 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004440 // Transform the type that we're allocating
4441 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4442 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4443 if (AllocType.isNull())
4444 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004445
Douglas Gregora16548e2009-08-11 05:31:07 +00004446 // Transform the size of the array we're allocating (if any).
4447 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4448 if (ArraySize.isInvalid())
4449 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004450
Douglas Gregora16548e2009-08-11 05:31:07 +00004451 // Transform the placement arguments (if any).
4452 bool ArgumentChanged = false;
4453 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4454 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4455 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4456 if (Arg.isInvalid())
4457 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004458
Douglas Gregora16548e2009-08-11 05:31:07 +00004459 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4460 PlacementArgs.push_back(Arg.take());
4461 }
Mike Stump11289f42009-09-09 15:08:12 +00004462
Douglas Gregorebe10102009-08-20 07:17:43 +00004463 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004464 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4465 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4466 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4467 if (Arg.isInvalid())
4468 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004469
Douglas Gregora16548e2009-08-11 05:31:07 +00004470 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4471 ConstructorArgs.push_back(Arg.take());
4472 }
Mike Stump11289f42009-09-09 15:08:12 +00004473
Douglas Gregora16548e2009-08-11 05:31:07 +00004474 if (!getDerived().AlwaysRebuild() &&
4475 AllocType == E->getAllocatedType() &&
4476 ArraySize.get() == E->getArraySize() &&
4477 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004478 return SemaRef.Owned(E->Retain());
4479
Douglas Gregora16548e2009-08-11 05:31:07 +00004480 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4481 E->isGlobalNew(),
4482 /*FIXME:*/E->getLocStart(),
4483 move_arg(PlacementArgs),
4484 /*FIXME:*/E->getLocStart(),
4485 E->isParenTypeId(),
4486 AllocType,
4487 /*FIXME:*/E->getLocStart(),
4488 /*FIXME:*/SourceRange(),
4489 move(ArraySize),
4490 /*FIXME:*/E->getLocStart(),
4491 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004492 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004493}
Mike Stump11289f42009-09-09 15:08:12 +00004494
Douglas Gregora16548e2009-08-11 05:31:07 +00004495template<typename Derived>
4496Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004497TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E,
4498 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004499 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4500 if (Operand.isInvalid())
4501 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004502
Douglas Gregora16548e2009-08-11 05:31:07 +00004503 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004504 Operand.get() == E->getArgument())
4505 return SemaRef.Owned(E->Retain());
4506
Douglas Gregora16548e2009-08-11 05:31:07 +00004507 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4508 E->isGlobalDelete(),
4509 E->isArrayForm(),
4510 move(Operand));
4511}
Mike Stump11289f42009-09-09 15:08:12 +00004512
Douglas Gregora16548e2009-08-11 05:31:07 +00004513template<typename Derived>
4514Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004515TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004516 CXXPseudoDestructorExpr *E,
4517 bool isAddressOfOperand) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004518 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4519 if (Base.isInvalid())
4520 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004521
Douglas Gregorad8a3362009-09-04 17:36:40 +00004522 NestedNameSpecifier *Qualifier
4523 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4524 E->getQualifierRange());
4525 if (E->getQualifier() && !Qualifier)
4526 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004527
Douglas Gregorad8a3362009-09-04 17:36:40 +00004528 QualType DestroyedType;
4529 {
4530 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4531 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4532 if (DestroyedType.isNull())
4533 return SemaRef.ExprError();
4534 }
Mike Stump11289f42009-09-09 15:08:12 +00004535
Douglas Gregorad8a3362009-09-04 17:36:40 +00004536 if (!getDerived().AlwaysRebuild() &&
4537 Base.get() == E->getBase() &&
4538 Qualifier == E->getQualifier() &&
4539 DestroyedType == E->getDestroyedType())
4540 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004541
Douglas Gregorad8a3362009-09-04 17:36:40 +00004542 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4543 E->getOperatorLoc(),
4544 E->isArrow(),
4545 E->getDestroyedTypeLoc(),
4546 DestroyedType,
4547 Qualifier,
4548 E->getQualifierRange());
4549}
Mike Stump11289f42009-09-09 15:08:12 +00004550
Douglas Gregorad8a3362009-09-04 17:36:40 +00004551template<typename Derived>
4552Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004553TreeTransform<Derived>::TransformUnresolvedLookupExpr(
4554 UnresolvedLookupExpr *E,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004555 bool isAddressOfOperand) {
John McCalld14a8642009-11-21 08:51:07 +00004556 // There is no transformation we can apply to an unresolved lookup.
Mike Stump11289f42009-09-09 15:08:12 +00004557 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004558}
Mike Stump11289f42009-09-09 15:08:12 +00004559
Douglas Gregora16548e2009-08-11 05:31:07 +00004560template<typename Derived>
4561Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004562TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E,
4563 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004564 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004565
Douglas Gregora16548e2009-08-11 05:31:07 +00004566 QualType T = getDerived().TransformType(E->getQueriedType());
4567 if (T.isNull())
4568 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004569
Douglas Gregora16548e2009-08-11 05:31:07 +00004570 if (!getDerived().AlwaysRebuild() &&
4571 T == E->getQueriedType())
4572 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004573
Douglas Gregora16548e2009-08-11 05:31:07 +00004574 // FIXME: Bad location information
4575 SourceLocation FakeLParenLoc
4576 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004577
4578 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004579 E->getLocStart(),
4580 /*FIXME:*/FakeLParenLoc,
4581 T,
4582 E->getLocEnd());
4583}
Mike Stump11289f42009-09-09 15:08:12 +00004584
Douglas Gregora16548e2009-08-11 05:31:07 +00004585template<typename Derived>
4586Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004587TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
4588 DependentScopeDeclRefExpr *E,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004589 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004590 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004591 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4592 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004593 if (!NNS)
4594 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004595
4596 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004597 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4598 if (!Name)
4599 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004600
4601 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004602 NNS == E->getQualifier() &&
4603 Name == E->getDeclName())
Mike Stump11289f42009-09-09 15:08:12 +00004604 return SemaRef.Owned(E->Retain());
4605
John McCall8cd78132009-11-19 22:55:06 +00004606 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00004607 E->getQualifierRange(),
4608 Name,
4609 E->getLocation(),
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004610 isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004611}
4612
4613template<typename Derived>
4614Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004615TreeTransform<Derived>::TransformTemplateIdRefExpr(TemplateIdRefExpr *E,
4616 bool isAddressOfOperand) {
Douglas Gregorba91b892009-10-29 17:56:10 +00004617 TemporaryBase Rebase(*this, E->getTemplateNameLoc(), DeclarationName());
4618
Mike Stump11289f42009-09-09 15:08:12 +00004619 TemplateName Template
Douglas Gregora16548e2009-08-11 05:31:07 +00004620 = getDerived().TransformTemplateName(E->getTemplateName());
4621 if (Template.isNull())
4622 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004623
Douglas Gregord019ff62009-10-22 17:20:55 +00004624 NestedNameSpecifier *Qualifier = 0;
4625 if (E->getQualifier()) {
4626 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4627 E->getQualifierRange());
4628 if (!Qualifier)
4629 return SemaRef.ExprError();
4630 }
John McCall6b51f282009-11-23 01:53:49 +00004631
4632 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004633 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004634 TemplateArgumentLoc Loc;
4635 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004636 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004637 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004638 }
4639
4640 // FIXME: Would like to avoid rebuilding if nothing changed, but we can't
4641 // compare template arguments (yet).
Mike Stump11289f42009-09-09 15:08:12 +00004642
4643 // FIXME: It's possible that we'll find out now that the template name
Douglas Gregora16548e2009-08-11 05:31:07 +00004644 // actually refers to a type, in which case the caller is actually dealing
4645 // with a functional cast. Give a reasonable error message!
Douglas Gregord019ff62009-10-22 17:20:55 +00004646 return getDerived().RebuildTemplateIdExpr(Qualifier, E->getQualifierRange(),
4647 Template, E->getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004648 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004649}
4650
4651template<typename Derived>
4652Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004653TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E,
4654 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004655 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4656
4657 QualType T = getDerived().TransformType(E->getType());
4658 if (T.isNull())
4659 return SemaRef.ExprError();
4660
4661 CXXConstructorDecl *Constructor
4662 = cast_or_null<CXXConstructorDecl>(
4663 getDerived().TransformDecl(E->getConstructor()));
4664 if (!Constructor)
4665 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004666
Douglas Gregora16548e2009-08-11 05:31:07 +00004667 bool ArgumentChanged = false;
4668 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004669 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004670 ArgEnd = E->arg_end();
4671 Arg != ArgEnd; ++Arg) {
4672 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4673 if (TransArg.isInvalid())
4674 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004675
Douglas Gregora16548e2009-08-11 05:31:07 +00004676 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4677 Args.push_back(TransArg.takeAs<Expr>());
4678 }
4679
4680 if (!getDerived().AlwaysRebuild() &&
4681 T == E->getType() &&
4682 Constructor == E->getConstructor() &&
4683 !ArgumentChanged)
4684 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004685
Douglas Gregora16548e2009-08-11 05:31:07 +00004686 return getDerived().RebuildCXXConstructExpr(T, Constructor, E->isElidable(),
4687 move_arg(Args));
4688}
Mike Stump11289f42009-09-09 15:08:12 +00004689
Douglas Gregora16548e2009-08-11 05:31:07 +00004690/// \brief Transform a C++ temporary-binding expression.
4691///
Mike Stump11289f42009-09-09 15:08:12 +00004692/// The transformation of a temporary-binding expression always attempts to
4693/// bind a new temporary variable to its subexpression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004694/// subexpression itself did not change, because the temporary variable itself
4695/// must be unique.
4696template<typename Derived>
4697Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004698TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E,
4699 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004700 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4701 if (SubExpr.isInvalid())
4702 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004703
Douglas Gregora16548e2009-08-11 05:31:07 +00004704 return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>());
4705}
Mike Stump11289f42009-09-09 15:08:12 +00004706
4707/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004708/// be destroyed after the expression is evaluated.
4709///
Mike Stump11289f42009-09-09 15:08:12 +00004710/// The transformation of a full expression always attempts to build a new
4711/// CXXExprWithTemporaries expression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004712/// subexpression itself did not change, because it will need to capture the
4713/// the new temporary variables introduced in the subexpression.
4714template<typename Derived>
4715Sema::OwningExprResult
4716TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004717 CXXExprWithTemporaries *E,
4718 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004719 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4720 if (SubExpr.isInvalid())
4721 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004722
Douglas Gregora16548e2009-08-11 05:31:07 +00004723 return SemaRef.Owned(
4724 SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(),
4725 E->shouldDestroyTemporaries()));
4726}
Mike Stump11289f42009-09-09 15:08:12 +00004727
Douglas Gregora16548e2009-08-11 05:31:07 +00004728template<typename Derived>
4729Sema::OwningExprResult
4730TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004731 CXXTemporaryObjectExpr *E,
4732 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004733 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4734 QualType T = getDerived().TransformType(E->getType());
4735 if (T.isNull())
4736 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004737
Douglas Gregora16548e2009-08-11 05:31:07 +00004738 CXXConstructorDecl *Constructor
4739 = cast_or_null<CXXConstructorDecl>(
4740 getDerived().TransformDecl(E->getConstructor()));
4741 if (!Constructor)
4742 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004743
Douglas Gregora16548e2009-08-11 05:31:07 +00004744 bool ArgumentChanged = false;
4745 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4746 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004747 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004748 ArgEnd = E->arg_end();
4749 Arg != ArgEnd; ++Arg) {
4750 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4751 if (TransArg.isInvalid())
4752 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004753
Douglas Gregora16548e2009-08-11 05:31:07 +00004754 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4755 Args.push_back((Expr *)TransArg.release());
4756 }
Mike Stump11289f42009-09-09 15:08:12 +00004757
Douglas Gregora16548e2009-08-11 05:31:07 +00004758 if (!getDerived().AlwaysRebuild() &&
4759 T == E->getType() &&
4760 Constructor == E->getConstructor() &&
4761 !ArgumentChanged)
4762 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004763
Douglas Gregora16548e2009-08-11 05:31:07 +00004764 // FIXME: Bogus location information
4765 SourceLocation CommaLoc;
4766 if (Args.size() > 1) {
4767 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004768 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004769 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4770 }
4771 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4772 T,
4773 /*FIXME:*/E->getTypeBeginLoc(),
4774 move_arg(Args),
4775 &CommaLoc,
4776 E->getLocEnd());
4777}
Mike Stump11289f42009-09-09 15:08:12 +00004778
Douglas Gregora16548e2009-08-11 05:31:07 +00004779template<typename Derived>
4780Sema::OwningExprResult
4781TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004782 CXXUnresolvedConstructExpr *E,
4783 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004784 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4785 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4786 if (T.isNull())
4787 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004788
Douglas Gregora16548e2009-08-11 05:31:07 +00004789 bool ArgumentChanged = false;
4790 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4791 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4792 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4793 ArgEnd = E->arg_end();
4794 Arg != ArgEnd; ++Arg) {
4795 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4796 if (TransArg.isInvalid())
4797 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004798
Douglas Gregora16548e2009-08-11 05:31:07 +00004799 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4800 FakeCommaLocs.push_back(
4801 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4802 Args.push_back(TransArg.takeAs<Expr>());
4803 }
Mike Stump11289f42009-09-09 15:08:12 +00004804
Douglas Gregora16548e2009-08-11 05:31:07 +00004805 if (!getDerived().AlwaysRebuild() &&
4806 T == E->getTypeAsWritten() &&
4807 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004808 return SemaRef.Owned(E->Retain());
4809
Douglas Gregora16548e2009-08-11 05:31:07 +00004810 // FIXME: we're faking the locations of the commas
4811 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4812 T,
4813 E->getLParenLoc(),
4814 move_arg(Args),
4815 FakeCommaLocs.data(),
4816 E->getRParenLoc());
4817}
Mike Stump11289f42009-09-09 15:08:12 +00004818
Douglas Gregora16548e2009-08-11 05:31:07 +00004819template<typename Derived>
4820Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004821TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
4822 CXXDependentScopeMemberExpr *E,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004823 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004824 // Transform the base of the expression.
4825 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4826 if (Base.isInvalid())
4827 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004828
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004829 // Start the member reference and compute the object's type.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004830 Sema::TypeTy *ObjectType = 0;
Mike Stump11289f42009-09-09 15:08:12 +00004831 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004832 E->getOperatorLoc(),
4833 E->isArrow()? tok::arrow : tok::period,
4834 ObjectType);
4835 if (Base.isInvalid())
4836 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004837
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004838 // Transform the first part of the nested-name-specifier that qualifies
4839 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004840 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004841 = getDerived().TransformFirstQualifierInScope(
4842 E->getFirstQualifierFoundInScope(),
4843 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00004844
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004845 NestedNameSpecifier *Qualifier = 0;
4846 if (E->getQualifier()) {
4847 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4848 E->getQualifierRange(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004849 QualType::getFromOpaquePtr(ObjectType),
4850 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004851 if (!Qualifier)
4852 return SemaRef.ExprError();
4853 }
Mike Stump11289f42009-09-09 15:08:12 +00004854
4855 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00004856 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
4857 QualType::getFromOpaquePtr(ObjectType));
Douglas Gregorf816bd72009-09-03 22:13:48 +00004858 if (!Name)
4859 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004860
Douglas Gregor308047d2009-09-09 00:23:06 +00004861 if (!E->hasExplicitTemplateArgumentList()) {
4862 // This is a reference to a member without an explicitly-specified
4863 // template argument list. Optimize for this common case.
4864 if (!getDerived().AlwaysRebuild() &&
4865 Base.get() == E->getBase() &&
4866 Qualifier == E->getQualifier() &&
4867 Name == E->getMember() &&
4868 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00004869 return SemaRef.Owned(E->Retain());
4870
John McCall8cd78132009-11-19 22:55:06 +00004871 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
Douglas Gregor308047d2009-09-09 00:23:06 +00004872 E->isArrow(),
4873 E->getOperatorLoc(),
4874 Qualifier,
4875 E->getQualifierRange(),
4876 Name,
4877 E->getMemberLoc(),
4878 FirstQualifierInScope);
4879 }
4880
4881 // FIXME: This is an ugly hack, which forces the same template name to
4882 // be looked up multiple times. Yuck!
Douglas Gregor71395fa2009-11-04 00:56:37 +00004883 TemporaryBase Rebase(*this, E->getMemberLoc(), DeclarationName());
4884 TemplateName OrigTemplateName;
4885 if (const IdentifierInfo *II = Name.getAsIdentifierInfo())
4886 OrigTemplateName = SemaRef.Context.getDependentTemplateName(0, II);
4887 else
4888 OrigTemplateName
4889 = SemaRef.Context.getDependentTemplateName(0,
4890 Name.getCXXOverloadedOperator());
Mike Stump11289f42009-09-09 15:08:12 +00004891
4892 TemplateName Template
4893 = getDerived().TransformTemplateName(OrigTemplateName,
Douglas Gregor308047d2009-09-09 00:23:06 +00004894 QualType::getFromOpaquePtr(ObjectType));
4895 if (Template.isNull())
4896 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004897
John McCall6b51f282009-11-23 01:53:49 +00004898 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00004899 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004900 TemplateArgumentLoc Loc;
4901 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00004902 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004903 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00004904 }
Mike Stump11289f42009-09-09 15:08:12 +00004905
John McCall8cd78132009-11-19 22:55:06 +00004906 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
Douglas Gregora16548e2009-08-11 05:31:07 +00004907 E->isArrow(),
4908 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004909 Qualifier,
4910 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004911 Template,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004912 E->getMemberLoc(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004913 FirstQualifierInScope,
John McCall6b51f282009-11-23 01:53:49 +00004914 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004915}
4916
4917template<typename Derived>
4918Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004919TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E,
4920 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004921 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004922}
4923
Mike Stump11289f42009-09-09 15:08:12 +00004924template<typename Derived>
4925Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004926TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E,
4927 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004928 // FIXME: poor source location
4929 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
4930 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
4931 if (EncodedType.isNull())
4932 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004933
Douglas Gregora16548e2009-08-11 05:31:07 +00004934 if (!getDerived().AlwaysRebuild() &&
4935 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00004936 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004937
4938 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
4939 EncodedType,
4940 E->getRParenLoc());
4941}
Mike Stump11289f42009-09-09 15:08:12 +00004942
Douglas Gregora16548e2009-08-11 05:31:07 +00004943template<typename Derived>
4944Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004945TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E,
4946 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004947 // FIXME: Implement this!
4948 assert(false && "Cannot transform Objective-C expressions yet");
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>::TransformObjCSelectorExpr(ObjCSelectorExpr *E,
4955 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004956 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004957}
4958
Mike Stump11289f42009-09-09 15:08:12 +00004959template<typename Derived>
4960Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004961TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E,
4962 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004963 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00004964 = cast_or_null<ObjCProtocolDecl>(
4965 getDerived().TransformDecl(E->getProtocol()));
4966 if (!Protocol)
4967 return SemaRef.ExprError();
4968
4969 if (!getDerived().AlwaysRebuild() &&
4970 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00004971 return SemaRef.Owned(E->Retain());
4972
Douglas Gregora16548e2009-08-11 05:31:07 +00004973 return getDerived().RebuildObjCProtocolExpr(Protocol,
4974 E->getAtLoc(),
4975 /*FIXME:*/E->getAtLoc(),
4976 /*FIXME:*/E->getAtLoc(),
4977 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004978
Douglas Gregora16548e2009-08-11 05:31:07 +00004979}
4980
Mike Stump11289f42009-09-09 15:08:12 +00004981template<typename Derived>
4982Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004983TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E,
4984 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004985 // FIXME: Implement this!
4986 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004987 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004988}
4989
Mike Stump11289f42009-09-09 15:08:12 +00004990template<typename Derived>
4991Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004992TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E,
4993 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004994 // FIXME: Implement this!
4995 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004996 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004997}
4998
Mike Stump11289f42009-09-09 15:08:12 +00004999template<typename Derived>
5000Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005001TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005002 ObjCImplicitSetterGetterRefExpr *E,
5003 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005004 // FIXME: Implement this!
5005 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005006 return SemaRef.Owned(E->Retain());
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>::TransformObjCSuperExpr(ObjCSuperExpr *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>::TransformObjCIsaExpr(ObjCIsaExpr *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
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005029TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E,
5030 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005031 bool ArgumentChanged = false;
5032 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5033 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5034 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5035 if (SubExpr.isInvalid())
5036 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005037
Douglas Gregora16548e2009-08-11 05:31:07 +00005038 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5039 SubExprs.push_back(SubExpr.takeAs<Expr>());
5040 }
Mike Stump11289f42009-09-09 15:08:12 +00005041
Douglas Gregora16548e2009-08-11 05:31:07 +00005042 if (!getDerived().AlwaysRebuild() &&
5043 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005044 return SemaRef.Owned(E->Retain());
5045
Douglas Gregora16548e2009-08-11 05:31:07 +00005046 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5047 move_arg(SubExprs),
5048 E->getRParenLoc());
5049}
5050
Mike Stump11289f42009-09-09 15:08:12 +00005051template<typename Derived>
5052Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005053TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E,
5054 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005055 // FIXME: Implement this!
5056 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005057 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005058}
5059
Mike Stump11289f42009-09-09 15:08:12 +00005060template<typename Derived>
5061Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005062TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E,
5063 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005064 // FIXME: Implement this!
5065 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005066 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005067}
Mike Stump11289f42009-09-09 15:08:12 +00005068
Douglas Gregora16548e2009-08-11 05:31:07 +00005069//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005070// Type reconstruction
5071//===----------------------------------------------------------------------===//
5072
Mike Stump11289f42009-09-09 15:08:12 +00005073template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005074QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5075 SourceLocation Star) {
5076 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005077 getDerived().getBaseEntity());
5078}
5079
Mike Stump11289f42009-09-09 15:08:12 +00005080template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005081QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5082 SourceLocation Star) {
5083 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005084 getDerived().getBaseEntity());
5085}
5086
Mike Stump11289f42009-09-09 15:08:12 +00005087template<typename Derived>
5088QualType
John McCall70dd5f62009-10-30 00:06:24 +00005089TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5090 bool WrittenAsLValue,
5091 SourceLocation Sigil) {
5092 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5093 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005094}
5095
5096template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005097QualType
John McCall70dd5f62009-10-30 00:06:24 +00005098TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5099 QualType ClassType,
5100 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005101 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005102 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005103}
5104
5105template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005106QualType
John McCall70dd5f62009-10-30 00:06:24 +00005107TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5108 SourceLocation Sigil) {
5109 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005110 getDerived().getBaseEntity());
5111}
5112
5113template<typename Derived>
5114QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005115TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5116 ArrayType::ArraySizeModifier SizeMod,
5117 const llvm::APInt *Size,
5118 Expr *SizeExpr,
5119 unsigned IndexTypeQuals,
5120 SourceRange BracketsRange) {
5121 if (SizeExpr || !Size)
5122 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5123 IndexTypeQuals, BracketsRange,
5124 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005125
5126 QualType Types[] = {
5127 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5128 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5129 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005130 };
5131 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5132 QualType SizeType;
5133 for (unsigned I = 0; I != NumTypes; ++I)
5134 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5135 SizeType = Types[I];
5136 break;
5137 }
Mike Stump11289f42009-09-09 15:08:12 +00005138
Douglas Gregord6ff3322009-08-04 16:50:30 +00005139 if (SizeType.isNull())
5140 SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false);
Mike Stump11289f42009-09-09 15:08:12 +00005141
Douglas Gregord6ff3322009-08-04 16:50:30 +00005142 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005143 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005144 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005145 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005146}
Mike Stump11289f42009-09-09 15:08:12 +00005147
Douglas Gregord6ff3322009-08-04 16:50:30 +00005148template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005149QualType
5150TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005151 ArrayType::ArraySizeModifier SizeMod,
5152 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005153 unsigned IndexTypeQuals,
5154 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005155 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005156 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005157}
5158
5159template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005160QualType
Mike Stump11289f42009-09-09 15:08:12 +00005161TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005162 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005163 unsigned IndexTypeQuals,
5164 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005165 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005166 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005167}
Mike Stump11289f42009-09-09 15:08:12 +00005168
Douglas Gregord6ff3322009-08-04 16:50:30 +00005169template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005170QualType
5171TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005172 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005173 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005174 unsigned IndexTypeQuals,
5175 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005176 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005177 SizeExpr.takeAs<Expr>(),
5178 IndexTypeQuals, BracketsRange);
5179}
5180
5181template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005182QualType
5183TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005184 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005185 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005186 unsigned IndexTypeQuals,
5187 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005188 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005189 SizeExpr.takeAs<Expr>(),
5190 IndexTypeQuals, BracketsRange);
5191}
5192
5193template<typename Derived>
5194QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
5195 unsigned NumElements) {
5196 // FIXME: semantic checking!
5197 return SemaRef.Context.getVectorType(ElementType, NumElements);
5198}
Mike Stump11289f42009-09-09 15:08:12 +00005199
Douglas Gregord6ff3322009-08-04 16:50:30 +00005200template<typename Derived>
5201QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5202 unsigned NumElements,
5203 SourceLocation AttributeLoc) {
5204 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5205 NumElements, true);
5206 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005207 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005208 AttributeLoc);
5209 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5210 AttributeLoc);
5211}
Mike Stump11289f42009-09-09 15:08:12 +00005212
Douglas Gregord6ff3322009-08-04 16:50:30 +00005213template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005214QualType
5215TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005216 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005217 SourceLocation AttributeLoc) {
5218 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5219}
Mike Stump11289f42009-09-09 15:08:12 +00005220
Douglas Gregord6ff3322009-08-04 16:50:30 +00005221template<typename Derived>
5222QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005223 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005224 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005225 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005226 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005227 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005228 Quals,
5229 getDerived().getBaseLocation(),
5230 getDerived().getBaseEntity());
5231}
Mike Stump11289f42009-09-09 15:08:12 +00005232
Douglas Gregord6ff3322009-08-04 16:50:30 +00005233template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005234QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5235 return SemaRef.Context.getFunctionNoProtoType(T);
5236}
5237
5238template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005239QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005240 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5241}
5242
5243template<typename Derived>
5244QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5245 return SemaRef.Context.getTypeOfType(Underlying);
5246}
5247
5248template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005249QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005250 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5251}
5252
5253template<typename Derived>
5254QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005255 TemplateName Template,
5256 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005257 const TemplateArgumentListInfo &TemplateArgs) {
5258 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005259}
Mike Stump11289f42009-09-09 15:08:12 +00005260
Douglas Gregor1135c352009-08-06 05:28:30 +00005261template<typename Derived>
5262NestedNameSpecifier *
5263TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5264 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005265 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005266 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005267 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005268 CXXScopeSpec SS;
5269 // FIXME: The source location information is all wrong.
5270 SS.setRange(Range);
5271 SS.setScopeRep(Prefix);
5272 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005273 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005274 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005275 ObjectType,
5276 FirstQualifierInScope,
Douglas Gregore861bac2009-08-25 22:51:20 +00005277 false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005278}
5279
5280template<typename Derived>
5281NestedNameSpecifier *
5282TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5283 SourceRange Range,
5284 NamespaceDecl *NS) {
5285 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5286}
5287
5288template<typename Derived>
5289NestedNameSpecifier *
5290TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5291 SourceRange Range,
5292 bool TemplateKW,
5293 QualType T) {
5294 if (T->isDependentType() || T->isRecordType() ||
5295 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005296 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005297 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5298 T.getTypePtr());
5299 }
Mike Stump11289f42009-09-09 15:08:12 +00005300
Douglas Gregor1135c352009-08-06 05:28:30 +00005301 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5302 return 0;
5303}
Mike Stump11289f42009-09-09 15:08:12 +00005304
Douglas Gregor71dc5092009-08-06 06:41:21 +00005305template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005306TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005307TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5308 bool TemplateKW,
5309 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005310 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005311 Template);
5312}
5313
5314template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005315TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005316TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5317 bool TemplateKW,
5318 OverloadedFunctionDecl *Ovl) {
5319 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, Ovl);
5320}
5321
5322template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005323TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005324TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005325 const IdentifierInfo &II,
5326 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005327 CXXScopeSpec SS;
5328 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005329 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005330 UnqualifiedId Name;
5331 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005332 return getSema().ActOnDependentTemplateName(
5333 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005334 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005335 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005336 ObjectType.getAsOpaquePtr(),
5337 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005338 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005339}
Mike Stump11289f42009-09-09 15:08:12 +00005340
Douglas Gregora16548e2009-08-11 05:31:07 +00005341template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005342TemplateName
5343TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5344 OverloadedOperatorKind Operator,
5345 QualType ObjectType) {
5346 CXXScopeSpec SS;
5347 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5348 SS.setScopeRep(Qualifier);
5349 UnqualifiedId Name;
5350 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5351 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5352 Operator, SymbolLocations);
5353 return getSema().ActOnDependentTemplateName(
5354 /*FIXME:*/getDerived().getBaseLocation(),
5355 SS,
5356 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005357 ObjectType.getAsOpaquePtr(),
5358 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005359 .template getAsVal<TemplateName>();
5360}
5361
5362template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005363Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005364TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5365 SourceLocation OpLoc,
5366 ExprArg Callee,
5367 ExprArg First,
5368 ExprArg Second) {
5369 Expr *FirstExpr = (Expr *)First.get();
5370 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005371 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005372 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005373
Douglas Gregora16548e2009-08-11 05:31:07 +00005374 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005375 if (Op == OO_Subscript) {
5376 if (!FirstExpr->getType()->isOverloadableType() &&
5377 !SecondExpr->getType()->isOverloadableType())
5378 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005379 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005380 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005381 } else if (Op == OO_Arrow) {
5382 // -> is never a builtin operation.
5383 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005384 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005385 if (!FirstExpr->getType()->isOverloadableType()) {
5386 // The argument is not of overloadable type, so try to create a
5387 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005388 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005389 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005390
Douglas Gregora16548e2009-08-11 05:31:07 +00005391 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5392 }
5393 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005394 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005395 !SecondExpr->getType()->isOverloadableType()) {
5396 // Neither of the arguments is an overloadable type, so try to
5397 // create a built-in binary operation.
5398 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005399 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005400 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5401 if (Result.isInvalid())
5402 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005403
Douglas Gregora16548e2009-08-11 05:31:07 +00005404 First.release();
5405 Second.release();
5406 return move(Result);
5407 }
5408 }
Mike Stump11289f42009-09-09 15:08:12 +00005409
5410 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005411 // used during overload resolution.
5412 Sema::FunctionSet Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005413
John McCalld14a8642009-11-21 08:51:07 +00005414 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5415 assert(ULE->requiresADL());
5416
5417 // FIXME: Do we have to check
5418 // IsAcceptableNonMemberOperatorCandidate for each of these?
5419 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(),
5420 E = ULE->decls_end(); I != E; ++I)
5421 Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I));
5422 } else {
5423 Functions.insert(AnyFunctionDecl::getFromNamedDecl(
5424 cast<DeclRefExpr>(CalleeExpr)->getDecl()));
5425 }
Mike Stump11289f42009-09-09 15:08:12 +00005426
Douglas Gregora16548e2009-08-11 05:31:07 +00005427 // Add any functions found via argument-dependent lookup.
5428 Expr *Args[2] = { FirstExpr, SecondExpr };
5429 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005430 DeclarationName OpName
Douglas Gregora16548e2009-08-11 05:31:07 +00005431 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
Sebastian Redlc057f422009-10-23 19:23:15 +00005432 SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs,
5433 Functions);
Mike Stump11289f42009-09-09 15:08:12 +00005434
Douglas Gregora16548e2009-08-11 05:31:07 +00005435 // Create the overloaded operator invocation for unary operators.
5436 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005437 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005438 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5439 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5440 }
Mike Stump11289f42009-09-09 15:08:12 +00005441
Sebastian Redladba46e2009-10-29 20:17:01 +00005442 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005443 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5444 OpLoc,
5445 move(First),
5446 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005447
Douglas Gregora16548e2009-08-11 05:31:07 +00005448 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005449 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005450 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005451 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005452 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5453 if (Result.isInvalid())
5454 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005455
Douglas Gregora16548e2009-08-11 05:31:07 +00005456 First.release();
5457 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005458 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005459}
Mike Stump11289f42009-09-09 15:08:12 +00005460
Douglas Gregord6ff3322009-08-04 16:50:30 +00005461} // end namespace clang
5462
5463#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H