blob: ecac31a3e7acab520d3748d9fe07494877673f46 [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
3087 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3088 if (Cond.isInvalid())
3089 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003090
Douglas Gregorebe10102009-08-20 07:17:43 +00003091 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003092
Douglas Gregorebe10102009-08-20 07:17:43 +00003093 // Transform the "then" branch.
3094 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3095 if (Then.isInvalid())
3096 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003097
Douglas Gregorebe10102009-08-20 07:17:43 +00003098 // Transform the "else" branch.
3099 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3100 if (Else.isInvalid())
3101 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003102
Douglas Gregorebe10102009-08-20 07:17:43 +00003103 if (!getDerived().AlwaysRebuild() &&
3104 FullCond->get() == S->getCond() &&
3105 Then.get() == S->getThen() &&
3106 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003107 return SemaRef.Owned(S->Retain());
3108
Douglas Gregorebe10102009-08-20 07:17:43 +00003109 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003110 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003111}
3112
3113template<typename Derived>
3114Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003115TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003116 // Transform the condition.
3117 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3118 if (Cond.isInvalid())
3119 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003120
Douglas Gregorebe10102009-08-20 07:17:43 +00003121 // Rebuild the switch statement.
3122 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(move(Cond));
3123 if (Switch.isInvalid())
3124 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003125
Douglas Gregorebe10102009-08-20 07:17:43 +00003126 // Transform the body of the switch statement.
3127 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3128 if (Body.isInvalid())
3129 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003130
Douglas Gregorebe10102009-08-20 07:17:43 +00003131 // Complete the switch statement.
3132 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3133 move(Body));
3134}
Mike Stump11289f42009-09-09 15:08:12 +00003135
Douglas Gregorebe10102009-08-20 07:17:43 +00003136template<typename Derived>
3137Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003138TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003139 // Transform the condition
3140 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3141 if (Cond.isInvalid())
3142 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003143
Douglas Gregorebe10102009-08-20 07:17:43 +00003144 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003145
Douglas Gregorebe10102009-08-20 07:17:43 +00003146 // Transform the body
3147 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3148 if (Body.isInvalid())
3149 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003150
Douglas Gregorebe10102009-08-20 07:17:43 +00003151 if (!getDerived().AlwaysRebuild() &&
3152 FullCond->get() == S->getCond() &&
3153 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003154 return SemaRef.Owned(S->Retain());
3155
Douglas Gregorebe10102009-08-20 07:17:43 +00003156 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, move(Body));
3157}
Mike Stump11289f42009-09-09 15:08:12 +00003158
Douglas Gregorebe10102009-08-20 07:17:43 +00003159template<typename Derived>
3160Sema::OwningStmtResult
3161TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3162 // Transform the condition
3163 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3164 if (Cond.isInvalid())
3165 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003166
Douglas Gregorebe10102009-08-20 07:17:43 +00003167 // Transform the body
3168 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3169 if (Body.isInvalid())
3170 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003171
Douglas Gregorebe10102009-08-20 07:17:43 +00003172 if (!getDerived().AlwaysRebuild() &&
3173 Cond.get() == S->getCond() &&
3174 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003175 return SemaRef.Owned(S->Retain());
3176
Douglas Gregorebe10102009-08-20 07:17:43 +00003177 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3178 /*FIXME:*/S->getWhileLoc(), move(Cond),
3179 S->getRParenLoc());
3180}
Mike Stump11289f42009-09-09 15:08:12 +00003181
Douglas Gregorebe10102009-08-20 07:17:43 +00003182template<typename Derived>
3183Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003184TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003185 // Transform the initialization statement
3186 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3187 if (Init.isInvalid())
3188 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003189
Douglas Gregorebe10102009-08-20 07:17:43 +00003190 // Transform the condition
3191 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3192 if (Cond.isInvalid())
3193 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003194
Douglas Gregorebe10102009-08-20 07:17:43 +00003195 // Transform the increment
3196 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3197 if (Inc.isInvalid())
3198 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003199
Douglas Gregorebe10102009-08-20 07:17:43 +00003200 // Transform the body
3201 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3202 if (Body.isInvalid())
3203 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003204
Douglas Gregorebe10102009-08-20 07:17:43 +00003205 if (!getDerived().AlwaysRebuild() &&
3206 Init.get() == S->getInit() &&
3207 Cond.get() == S->getCond() &&
3208 Inc.get() == S->getInc() &&
3209 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003210 return SemaRef.Owned(S->Retain());
3211
Douglas Gregorebe10102009-08-20 07:17:43 +00003212 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
3213 move(Init), move(Cond), move(Inc),
3214 S->getRParenLoc(), move(Body));
3215}
3216
3217template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003218Sema::OwningStmtResult
3219TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003220 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003221 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003222 S->getLabel());
3223}
3224
3225template<typename Derived>
3226Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003227TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003228 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3229 if (Target.isInvalid())
3230 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003231
Douglas Gregorebe10102009-08-20 07:17:43 +00003232 if (!getDerived().AlwaysRebuild() &&
3233 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003234 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003235
3236 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3237 move(Target));
3238}
3239
3240template<typename Derived>
3241Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003242TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3243 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003244}
Mike Stump11289f42009-09-09 15:08:12 +00003245
Douglas Gregorebe10102009-08-20 07:17:43 +00003246template<typename Derived>
3247Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003248TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3249 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003250}
Mike Stump11289f42009-09-09 15:08:12 +00003251
Douglas Gregorebe10102009-08-20 07:17:43 +00003252template<typename Derived>
3253Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003254TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003255 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3256 if (Result.isInvalid())
3257 return SemaRef.StmtError();
3258
Mike Stump11289f42009-09-09 15:08:12 +00003259 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003260 // to tell whether the return type of the function has changed.
3261 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3262}
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>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003267 bool DeclChanged = false;
3268 llvm::SmallVector<Decl *, 4> Decls;
3269 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3270 D != DEnd; ++D) {
3271 Decl *Transformed = getDerived().TransformDefinition(*D);
3272 if (!Transformed)
3273 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003274
Douglas Gregorebe10102009-08-20 07:17:43 +00003275 if (Transformed != *D)
3276 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003277
Douglas Gregorebe10102009-08-20 07:17:43 +00003278 Decls.push_back(Transformed);
3279 }
Mike Stump11289f42009-09-09 15:08:12 +00003280
Douglas Gregorebe10102009-08-20 07:17:43 +00003281 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003282 return SemaRef.Owned(S->Retain());
3283
3284 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003285 S->getStartLoc(), S->getEndLoc());
3286}
Mike Stump11289f42009-09-09 15:08:12 +00003287
Douglas Gregorebe10102009-08-20 07:17:43 +00003288template<typename Derived>
3289Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003290TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003291 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003292 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003293}
3294
3295template<typename Derived>
3296Sema::OwningStmtResult
3297TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
3298 // FIXME: Implement!
3299 assert(false && "Inline assembly cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003300 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003301}
3302
3303
3304template<typename Derived>
3305Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003306TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003307 // FIXME: Implement this
3308 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003309 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003310}
Mike Stump11289f42009-09-09 15:08:12 +00003311
Douglas Gregorebe10102009-08-20 07:17:43 +00003312template<typename Derived>
3313Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003314TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003315 // FIXME: Implement this
3316 assert(false && "Cannot transform an Objective-C @catch statement");
3317 return SemaRef.Owned(S->Retain());
3318}
Mike Stump11289f42009-09-09 15:08:12 +00003319
Douglas Gregorebe10102009-08-20 07:17:43 +00003320template<typename Derived>
3321Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003322TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003323 // FIXME: Implement this
3324 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003325 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003326}
Mike Stump11289f42009-09-09 15:08:12 +00003327
Douglas Gregorebe10102009-08-20 07:17:43 +00003328template<typename Derived>
3329Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003330TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003331 // FIXME: Implement this
3332 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003333 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003334}
Mike Stump11289f42009-09-09 15:08:12 +00003335
Douglas Gregorebe10102009-08-20 07:17:43 +00003336template<typename Derived>
3337Sema::OwningStmtResult
3338TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003339 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003340 // FIXME: Implement this
3341 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003342 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003343}
3344
3345template<typename Derived>
3346Sema::OwningStmtResult
3347TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003348 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003349 // FIXME: Implement this
3350 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003351 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003352}
3353
3354
3355template<typename Derived>
3356Sema::OwningStmtResult
3357TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3358 // Transform the exception declaration, if any.
3359 VarDecl *Var = 0;
3360 if (S->getExceptionDecl()) {
3361 VarDecl *ExceptionDecl = S->getExceptionDecl();
3362 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3363 ExceptionDecl->getDeclName());
3364
3365 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3366 if (T.isNull())
3367 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003368
Douglas Gregorebe10102009-08-20 07:17:43 +00003369 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3370 T,
3371 ExceptionDecl->getDeclaratorInfo(),
3372 ExceptionDecl->getIdentifier(),
3373 ExceptionDecl->getLocation(),
3374 /*FIXME: Inaccurate*/
3375 SourceRange(ExceptionDecl->getLocation()));
3376 if (!Var || Var->isInvalidDecl()) {
3377 if (Var)
3378 Var->Destroy(SemaRef.Context);
3379 return SemaRef.StmtError();
3380 }
3381 }
Mike Stump11289f42009-09-09 15:08:12 +00003382
Douglas Gregorebe10102009-08-20 07:17:43 +00003383 // Transform the actual exception handler.
3384 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3385 if (Handler.isInvalid()) {
3386 if (Var)
3387 Var->Destroy(SemaRef.Context);
3388 return SemaRef.StmtError();
3389 }
Mike Stump11289f42009-09-09 15:08:12 +00003390
Douglas Gregorebe10102009-08-20 07:17:43 +00003391 if (!getDerived().AlwaysRebuild() &&
3392 !Var &&
3393 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003394 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003395
3396 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3397 Var,
3398 move(Handler));
3399}
Mike Stump11289f42009-09-09 15:08:12 +00003400
Douglas Gregorebe10102009-08-20 07:17:43 +00003401template<typename Derived>
3402Sema::OwningStmtResult
3403TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3404 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003405 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003406 = getDerived().TransformCompoundStmt(S->getTryBlock());
3407 if (TryBlock.isInvalid())
3408 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003409
Douglas Gregorebe10102009-08-20 07:17:43 +00003410 // Transform the handlers.
3411 bool HandlerChanged = false;
3412 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3413 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003414 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003415 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3416 if (Handler.isInvalid())
3417 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003418
Douglas Gregorebe10102009-08-20 07:17:43 +00003419 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3420 Handlers.push_back(Handler.takeAs<Stmt>());
3421 }
Mike Stump11289f42009-09-09 15:08:12 +00003422
Douglas Gregorebe10102009-08-20 07:17:43 +00003423 if (!getDerived().AlwaysRebuild() &&
3424 TryBlock.get() == S->getTryBlock() &&
3425 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003426 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003427
3428 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003429 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003430}
Mike Stump11289f42009-09-09 15:08:12 +00003431
Douglas Gregorebe10102009-08-20 07:17:43 +00003432//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003433// Expression transformation
3434//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003435template<typename Derived>
3436Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003437TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E,
3438 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003439 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003440}
Mike Stump11289f42009-09-09 15:08:12 +00003441
3442template<typename Derived>
3443Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003444TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E,
3445 bool isAddressOfOperand) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003446 NestedNameSpecifier *Qualifier = 0;
3447 if (E->getQualifier()) {
3448 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3449 E->getQualifierRange());
3450 if (!Qualifier)
3451 return SemaRef.ExprError();
3452 }
3453
Mike Stump11289f42009-09-09 15:08:12 +00003454 NamedDecl *ND
Douglas Gregora16548e2009-08-11 05:31:07 +00003455 = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl()));
3456 if (!ND)
3457 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003458
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003459 if (!getDerived().AlwaysRebuild() &&
3460 Qualifier == E->getQualifier() &&
3461 ND == E->getDecl() &&
3462 !E->hasExplicitTemplateArgumentList())
Mike Stump11289f42009-09-09 15:08:12 +00003463 return SemaRef.Owned(E->Retain());
3464
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003465 // FIXME: We're losing the explicit template arguments in this transformation.
3466
John McCall0ad16662009-10-29 08:12:44 +00003467 llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003468 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall0ad16662009-10-29 08:12:44 +00003469 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I],
3470 TransArgs[I]))
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003471 return SemaRef.ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003472 }
3473
3474 // FIXME: Pass the qualifier/qualifier range along.
3475 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003476 ND, E->getLocation(),
3477 isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00003478}
Mike Stump11289f42009-09-09 15:08:12 +00003479
Douglas Gregora16548e2009-08-11 05:31:07 +00003480template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003481Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003482TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E,
3483 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003484 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003485}
Mike Stump11289f42009-09-09 15:08:12 +00003486
Douglas Gregora16548e2009-08-11 05:31:07 +00003487template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003488Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003489TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E,
3490 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003491 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003492}
Mike Stump11289f42009-09-09 15:08:12 +00003493
Douglas Gregora16548e2009-08-11 05:31:07 +00003494template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003495Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003496TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E,
3497 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003498 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003499}
Mike Stump11289f42009-09-09 15:08:12 +00003500
Douglas Gregora16548e2009-08-11 05:31:07 +00003501template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003502Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003503TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E,
3504 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003505 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003506}
Mike Stump11289f42009-09-09 15:08:12 +00003507
Douglas Gregora16548e2009-08-11 05:31:07 +00003508template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003509Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003510TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E,
3511 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003512 return SemaRef.Owned(E->Retain());
3513}
3514
3515template<typename Derived>
3516Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003517TreeTransform<Derived>::TransformParenExpr(ParenExpr *E,
3518 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003519 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3520 if (SubExpr.isInvalid())
3521 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003522
Douglas Gregora16548e2009-08-11 05:31:07 +00003523 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003524 return SemaRef.Owned(E->Retain());
3525
3526 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003527 E->getRParen());
3528}
3529
Mike Stump11289f42009-09-09 15:08:12 +00003530template<typename Derived>
3531Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003532TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E,
3533 bool isAddressOfOperand) {
3534 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr(),
3535 E->getOpcode() == UnaryOperator::AddrOf);
Douglas Gregora16548e2009-08-11 05:31:07 +00003536 if (SubExpr.isInvalid())
3537 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003538
Douglas Gregora16548e2009-08-11 05:31:07 +00003539 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003540 return SemaRef.Owned(E->Retain());
3541
Douglas Gregora16548e2009-08-11 05:31:07 +00003542 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3543 E->getOpcode(),
3544 move(SubExpr));
3545}
Mike Stump11289f42009-09-09 15:08:12 +00003546
Douglas Gregora16548e2009-08-11 05:31:07 +00003547template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003548Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003549TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E,
3550 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003551 if (E->isArgumentType()) {
John McCall4c98fd82009-11-04 07:28:41 +00003552 DeclaratorInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003553
John McCall4c98fd82009-11-04 07:28:41 +00003554 DeclaratorInfo *NewT = getDerived().TransformType(OldT);
3555 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003556 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003557
John McCall4c98fd82009-11-04 07:28:41 +00003558 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003559 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003560
John McCall4c98fd82009-11-04 07:28:41 +00003561 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003562 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003563 E->getSourceRange());
3564 }
Mike Stump11289f42009-09-09 15:08:12 +00003565
Douglas Gregora16548e2009-08-11 05:31:07 +00003566 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003567 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003568 // C++0x [expr.sizeof]p1:
3569 // The operand is either an expression, which is an unevaluated operand
3570 // [...]
3571 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003572
Douglas Gregora16548e2009-08-11 05:31:07 +00003573 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3574 if (SubExpr.isInvalid())
3575 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003576
Douglas Gregora16548e2009-08-11 05:31:07 +00003577 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3578 return SemaRef.Owned(E->Retain());
3579 }
Mike Stump11289f42009-09-09 15:08:12 +00003580
Douglas Gregora16548e2009-08-11 05:31:07 +00003581 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3582 E->isSizeOf(),
3583 E->getSourceRange());
3584}
Mike Stump11289f42009-09-09 15:08:12 +00003585
Douglas Gregora16548e2009-08-11 05:31:07 +00003586template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003587Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003588TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E,
3589 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003590 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3591 if (LHS.isInvalid())
3592 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003593
Douglas Gregora16548e2009-08-11 05:31:07 +00003594 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3595 if (RHS.isInvalid())
3596 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003597
3598
Douglas Gregora16548e2009-08-11 05:31:07 +00003599 if (!getDerived().AlwaysRebuild() &&
3600 LHS.get() == E->getLHS() &&
3601 RHS.get() == E->getRHS())
3602 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003603
Douglas Gregora16548e2009-08-11 05:31:07 +00003604 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3605 /*FIXME:*/E->getLHS()->getLocStart(),
3606 move(RHS),
3607 E->getRBracketLoc());
3608}
Mike Stump11289f42009-09-09 15:08:12 +00003609
3610template<typename Derived>
3611Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003612TreeTransform<Derived>::TransformCallExpr(CallExpr *E,
3613 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003614 // Transform the callee.
3615 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3616 if (Callee.isInvalid())
3617 return SemaRef.ExprError();
3618
3619 // Transform arguments.
3620 bool ArgChanged = false;
3621 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3622 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3623 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3624 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3625 if (Arg.isInvalid())
3626 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003627
Douglas Gregora16548e2009-08-11 05:31:07 +00003628 // FIXME: Wrong source location information for the ','.
3629 FakeCommaLocs.push_back(
3630 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003631
3632 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003633 Args.push_back(Arg.takeAs<Expr>());
3634 }
Mike Stump11289f42009-09-09 15:08:12 +00003635
Douglas Gregora16548e2009-08-11 05:31:07 +00003636 if (!getDerived().AlwaysRebuild() &&
3637 Callee.get() == E->getCallee() &&
3638 !ArgChanged)
3639 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003640
Douglas Gregora16548e2009-08-11 05:31:07 +00003641 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003642 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003643 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3644 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3645 move_arg(Args),
3646 FakeCommaLocs.data(),
3647 E->getRParenLoc());
3648}
Mike Stump11289f42009-09-09 15:08:12 +00003649
3650template<typename Derived>
3651Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003652TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E,
3653 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003654 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3655 if (Base.isInvalid())
3656 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003657
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003658 NestedNameSpecifier *Qualifier = 0;
3659 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003660 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003661 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3662 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003663 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003664 return SemaRef.ExprError();
3665 }
Mike Stump11289f42009-09-09 15:08:12 +00003666
3667 NamedDecl *Member
Douglas Gregora16548e2009-08-11 05:31:07 +00003668 = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getMemberDecl()));
3669 if (!Member)
3670 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003671
Douglas Gregora16548e2009-08-11 05:31:07 +00003672 if (!getDerived().AlwaysRebuild() &&
3673 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003674 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003675 Member == E->getMemberDecl() &&
3676 !E->hasExplicitTemplateArgumentList())
Mike Stump11289f42009-09-09 15:08:12 +00003677 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003678
John McCall6b51f282009-11-23 01:53:49 +00003679 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003680 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003681 TransArgs.setLAngleLoc(E->getLAngleLoc());
3682 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003683 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003684 TemplateArgumentLoc Loc;
3685 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003686 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003687 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003688 }
3689 }
3690
Douglas Gregora16548e2009-08-11 05:31:07 +00003691 // FIXME: Bogus source location for the operator
3692 SourceLocation FakeOperatorLoc
3693 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3694
3695 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3696 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003697 Qualifier,
3698 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003699 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003700 Member,
John McCall6b51f282009-11-23 01:53:49 +00003701 (E->hasExplicitTemplateArgumentList()
3702 ? &TransArgs : 0),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003703 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00003704}
Mike Stump11289f42009-09-09 15:08:12 +00003705
Douglas Gregora16548e2009-08-11 05:31:07 +00003706template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003707Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003708TreeTransform<Derived>::TransformCastExpr(CastExpr *E,
3709 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003710 assert(false && "Cannot transform abstract class");
3711 return SemaRef.Owned(E->Retain());
3712}
3713
3714template<typename Derived>
3715Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003716TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E,
3717 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003718 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3719 if (LHS.isInvalid())
3720 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003721
Douglas Gregora16548e2009-08-11 05:31:07 +00003722 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3723 if (RHS.isInvalid())
3724 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003725
Douglas Gregora16548e2009-08-11 05:31:07 +00003726 if (!getDerived().AlwaysRebuild() &&
3727 LHS.get() == E->getLHS() &&
3728 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003729 return SemaRef.Owned(E->Retain());
3730
Douglas Gregora16548e2009-08-11 05:31:07 +00003731 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3732 move(LHS), move(RHS));
3733}
3734
Mike Stump11289f42009-09-09 15:08:12 +00003735template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003736Sema::OwningExprResult
3737TreeTransform<Derived>::TransformCompoundAssignOperator(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003738 CompoundAssignOperator *E,
3739 bool isAddressOfOperand) {
3740 return getDerived().TransformBinaryOperator(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00003741}
Mike Stump11289f42009-09-09 15:08:12 +00003742
Douglas Gregora16548e2009-08-11 05:31:07 +00003743template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003744Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003745TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E,
3746 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003747 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3748 if (Cond.isInvalid())
3749 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003750
Douglas Gregora16548e2009-08-11 05:31:07 +00003751 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3752 if (LHS.isInvalid())
3753 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003754
Douglas Gregora16548e2009-08-11 05:31:07 +00003755 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3756 if (RHS.isInvalid())
3757 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003758
Douglas Gregora16548e2009-08-11 05:31:07 +00003759 if (!getDerived().AlwaysRebuild() &&
3760 Cond.get() == E->getCond() &&
3761 LHS.get() == E->getLHS() &&
3762 RHS.get() == E->getRHS())
3763 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003764
3765 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003766 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003767 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003768 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003769 move(RHS));
3770}
Mike Stump11289f42009-09-09 15:08:12 +00003771
3772template<typename Derived>
3773Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003774TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E,
3775 bool isAddressOfOperand) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00003776 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3777
3778 // FIXME: Will we ever have type information here? It seems like we won't,
3779 // so do we even need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00003780 QualType T = getDerived().TransformType(E->getType());
3781 if (T.isNull())
3782 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003783
Douglas Gregora16548e2009-08-11 05:31:07 +00003784 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3785 if (SubExpr.isInvalid())
3786 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003787
Douglas Gregora16548e2009-08-11 05:31:07 +00003788 if (!getDerived().AlwaysRebuild() &&
3789 T == E->getType() &&
3790 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003791 return SemaRef.Owned(E->Retain());
3792
Douglas Gregora16548e2009-08-11 05:31:07 +00003793 return getDerived().RebuildImplicitCastExpr(T, E->getCastKind(),
Mike Stump11289f42009-09-09 15:08:12 +00003794 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00003795 E->isLvalueCast());
3796}
Mike Stump11289f42009-09-09 15:08:12 +00003797
Douglas Gregora16548e2009-08-11 05:31:07 +00003798template<typename Derived>
3799Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003800TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E,
3801 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003802 assert(false && "Cannot transform abstract class");
3803 return SemaRef.Owned(E->Retain());
3804}
3805
3806template<typename Derived>
3807Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003808TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E,
3809 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003810 QualType T;
3811 {
3812 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003813 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003814 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3815 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003816
Douglas Gregora16548e2009-08-11 05:31:07 +00003817 T = getDerived().TransformType(E->getTypeAsWritten());
3818 if (T.isNull())
3819 return SemaRef.ExprError();
3820 }
Mike Stump11289f42009-09-09 15:08:12 +00003821
Douglas Gregora16548e2009-08-11 05:31:07 +00003822 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3823 if (SubExpr.isInvalid())
3824 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003825
Douglas Gregora16548e2009-08-11 05:31:07 +00003826 if (!getDerived().AlwaysRebuild() &&
3827 T == E->getTypeAsWritten() &&
3828 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003829 return SemaRef.Owned(E->Retain());
3830
Douglas Gregora16548e2009-08-11 05:31:07 +00003831 return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T,
3832 E->getRParenLoc(),
3833 move(SubExpr));
3834}
Mike Stump11289f42009-09-09 15:08:12 +00003835
Douglas Gregora16548e2009-08-11 05:31:07 +00003836template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003837Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003838TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E,
3839 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003840 QualType T;
3841 {
3842 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003843 SourceLocation FakeTypeLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003844 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3845 TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003846
Douglas Gregora16548e2009-08-11 05:31:07 +00003847 T = getDerived().TransformType(E->getType());
3848 if (T.isNull())
3849 return SemaRef.ExprError();
3850 }
Mike Stump11289f42009-09-09 15:08:12 +00003851
Douglas Gregora16548e2009-08-11 05:31:07 +00003852 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3853 if (Init.isInvalid())
3854 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003855
Douglas Gregora16548e2009-08-11 05:31:07 +00003856 if (!getDerived().AlwaysRebuild() &&
3857 T == E->getType() &&
3858 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003859 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003860
3861 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T,
3862 /*FIXME:*/E->getInitializer()->getLocEnd(),
3863 move(Init));
3864}
Mike Stump11289f42009-09-09 15:08:12 +00003865
Douglas Gregora16548e2009-08-11 05:31:07 +00003866template<typename Derived>
3867Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003868TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E,
3869 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003870 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3871 if (Base.isInvalid())
3872 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003873
Douglas Gregora16548e2009-08-11 05:31:07 +00003874 if (!getDerived().AlwaysRebuild() &&
3875 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003876 return SemaRef.Owned(E->Retain());
3877
Douglas Gregora16548e2009-08-11 05:31:07 +00003878 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003879 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003880 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3881 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3882 E->getAccessorLoc(),
3883 E->getAccessor());
3884}
Mike Stump11289f42009-09-09 15:08:12 +00003885
Douglas Gregora16548e2009-08-11 05:31:07 +00003886template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003887Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003888TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E,
3889 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003890 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003891
Douglas Gregora16548e2009-08-11 05:31:07 +00003892 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3893 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3894 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3895 if (Init.isInvalid())
3896 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003897
Douglas Gregora16548e2009-08-11 05:31:07 +00003898 InitChanged = InitChanged || Init.get() != E->getInit(I);
3899 Inits.push_back(Init.takeAs<Expr>());
3900 }
Mike Stump11289f42009-09-09 15:08:12 +00003901
Douglas Gregora16548e2009-08-11 05:31:07 +00003902 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003903 return SemaRef.Owned(E->Retain());
3904
Douglas Gregora16548e2009-08-11 05:31:07 +00003905 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00003906 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00003907}
Mike Stump11289f42009-09-09 15:08:12 +00003908
Douglas Gregora16548e2009-08-11 05:31:07 +00003909template<typename Derived>
3910Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003911TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E,
3912 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003913 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00003914
Douglas Gregorebe10102009-08-20 07:17:43 +00003915 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00003916 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3917 if (Init.isInvalid())
3918 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003919
Douglas Gregorebe10102009-08-20 07:17:43 +00003920 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00003921 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3922 bool ExprChanged = false;
3923 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3924 DEnd = E->designators_end();
3925 D != DEnd; ++D) {
3926 if (D->isFieldDesignator()) {
3927 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3928 D->getDotLoc(),
3929 D->getFieldLoc()));
3930 continue;
3931 }
Mike Stump11289f42009-09-09 15:08:12 +00003932
Douglas Gregora16548e2009-08-11 05:31:07 +00003933 if (D->isArrayDesignator()) {
3934 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3935 if (Index.isInvalid())
3936 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003937
3938 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003939 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003940
Douglas Gregora16548e2009-08-11 05:31:07 +00003941 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3942 ArrayExprs.push_back(Index.release());
3943 continue;
3944 }
Mike Stump11289f42009-09-09 15:08:12 +00003945
Douglas Gregora16548e2009-08-11 05:31:07 +00003946 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00003947 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00003948 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3949 if (Start.isInvalid())
3950 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003951
Douglas Gregora16548e2009-08-11 05:31:07 +00003952 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3953 if (End.isInvalid())
3954 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003955
3956 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003957 End.get(),
3958 D->getLBracketLoc(),
3959 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003960
Douglas Gregora16548e2009-08-11 05:31:07 +00003961 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
3962 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00003963
Douglas Gregora16548e2009-08-11 05:31:07 +00003964 ArrayExprs.push_back(Start.release());
3965 ArrayExprs.push_back(End.release());
3966 }
Mike Stump11289f42009-09-09 15:08:12 +00003967
Douglas Gregora16548e2009-08-11 05:31:07 +00003968 if (!getDerived().AlwaysRebuild() &&
3969 Init.get() == E->getInit() &&
3970 !ExprChanged)
3971 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003972
Douglas Gregora16548e2009-08-11 05:31:07 +00003973 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
3974 E->getEqualOrColonLoc(),
3975 E->usesGNUSyntax(), move(Init));
3976}
Mike Stump11289f42009-09-09 15:08:12 +00003977
Douglas Gregora16548e2009-08-11 05:31:07 +00003978template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003979Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003980TreeTransform<Derived>::TransformImplicitValueInitExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003981 ImplicitValueInitExpr *E,
3982 bool isAddressOfOperand) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00003983 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3984
3985 // FIXME: Will we ever have proper type location here? Will we actually
3986 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00003987 QualType T = getDerived().TransformType(E->getType());
3988 if (T.isNull())
3989 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003990
Douglas Gregora16548e2009-08-11 05:31:07 +00003991 if (!getDerived().AlwaysRebuild() &&
3992 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00003993 return SemaRef.Owned(E->Retain());
3994
Douglas Gregora16548e2009-08-11 05:31:07 +00003995 return getDerived().RebuildImplicitValueInitExpr(T);
3996}
Mike Stump11289f42009-09-09 15:08:12 +00003997
Douglas Gregora16548e2009-08-11 05:31:07 +00003998template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003999Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004000TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E,
4001 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004002 // FIXME: Do we want the type as written?
4003 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004004
Douglas Gregora16548e2009-08-11 05:31:07 +00004005 {
4006 // FIXME: Source location isn't quite accurate.
4007 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4008 T = getDerived().TransformType(E->getType());
4009 if (T.isNull())
4010 return SemaRef.ExprError();
4011 }
Mike Stump11289f42009-09-09 15:08:12 +00004012
Douglas Gregora16548e2009-08-11 05:31:07 +00004013 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4014 if (SubExpr.isInvalid())
4015 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004016
Douglas Gregora16548e2009-08-11 05:31:07 +00004017 if (!getDerived().AlwaysRebuild() &&
4018 T == E->getType() &&
4019 SubExpr.get() == E->getSubExpr())
4020 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004021
Douglas Gregora16548e2009-08-11 05:31:07 +00004022 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4023 T, E->getRParenLoc());
4024}
4025
4026template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004027Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004028TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E,
4029 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004030 bool ArgumentChanged = false;
4031 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4032 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4033 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4034 if (Init.isInvalid())
4035 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004036
Douglas Gregora16548e2009-08-11 05:31:07 +00004037 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4038 Inits.push_back(Init.takeAs<Expr>());
4039 }
Mike Stump11289f42009-09-09 15:08:12 +00004040
Douglas Gregora16548e2009-08-11 05:31:07 +00004041 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4042 move_arg(Inits),
4043 E->getRParenLoc());
4044}
Mike Stump11289f42009-09-09 15:08:12 +00004045
Douglas Gregora16548e2009-08-11 05:31:07 +00004046/// \brief Transform an address-of-label expression.
4047///
4048/// By default, the transformation of an address-of-label expression always
4049/// rebuilds the expression, so that the label identifier can be resolved to
4050/// the corresponding label statement by semantic analysis.
4051template<typename Derived>
4052Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004053TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E,
4054 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004055 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4056 E->getLabel());
4057}
Mike Stump11289f42009-09-09 15:08:12 +00004058
4059template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004060Sema::OwningExprResult
4061TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E,
4062 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004063 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004064 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4065 if (SubStmt.isInvalid())
4066 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004067
Douglas Gregora16548e2009-08-11 05:31:07 +00004068 if (!getDerived().AlwaysRebuild() &&
4069 SubStmt.get() == E->getSubStmt())
4070 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004071
4072 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004073 move(SubStmt),
4074 E->getRParenLoc());
4075}
Mike Stump11289f42009-09-09 15:08:12 +00004076
Douglas Gregora16548e2009-08-11 05:31:07 +00004077template<typename Derived>
4078Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004079TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E,
4080 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004081 QualType T1, T2;
4082 {
4083 // FIXME: Source location isn't quite accurate.
4084 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004085
Douglas Gregora16548e2009-08-11 05:31:07 +00004086 T1 = getDerived().TransformType(E->getArgType1());
4087 if (T1.isNull())
4088 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004089
Douglas Gregora16548e2009-08-11 05:31:07 +00004090 T2 = getDerived().TransformType(E->getArgType2());
4091 if (T2.isNull())
4092 return SemaRef.ExprError();
4093 }
4094
4095 if (!getDerived().AlwaysRebuild() &&
4096 T1 == E->getArgType1() &&
4097 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004098 return SemaRef.Owned(E->Retain());
4099
Douglas Gregora16548e2009-08-11 05:31:07 +00004100 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4101 T1, T2, E->getRParenLoc());
4102}
Mike Stump11289f42009-09-09 15:08:12 +00004103
Douglas Gregora16548e2009-08-11 05:31:07 +00004104template<typename Derived>
4105Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004106TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E,
4107 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004108 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4109 if (Cond.isInvalid())
4110 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004111
Douglas Gregora16548e2009-08-11 05:31:07 +00004112 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4113 if (LHS.isInvalid())
4114 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004115
Douglas Gregora16548e2009-08-11 05:31:07 +00004116 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4117 if (RHS.isInvalid())
4118 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004119
Douglas Gregora16548e2009-08-11 05:31:07 +00004120 if (!getDerived().AlwaysRebuild() &&
4121 Cond.get() == E->getCond() &&
4122 LHS.get() == E->getLHS() &&
4123 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004124 return SemaRef.Owned(E->Retain());
4125
Douglas Gregora16548e2009-08-11 05:31:07 +00004126 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4127 move(Cond), move(LHS), move(RHS),
4128 E->getRParenLoc());
4129}
Mike Stump11289f42009-09-09 15:08:12 +00004130
Douglas Gregora16548e2009-08-11 05:31:07 +00004131template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004132Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004133TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E,
4134 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004135 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004136}
4137
4138template<typename Derived>
4139Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004140TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E,
4141 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004142 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4143 if (Callee.isInvalid())
4144 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004145
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004146 OwningExprResult First
4147 = getDerived().TransformExpr(E->getArg(0),
4148 E->getNumArgs() == 1 && E->getOperator() == OO_Amp);
Douglas Gregora16548e2009-08-11 05:31:07 +00004149 if (First.isInvalid())
4150 return SemaRef.ExprError();
4151
4152 OwningExprResult Second(SemaRef);
4153 if (E->getNumArgs() == 2) {
4154 Second = getDerived().TransformExpr(E->getArg(1));
4155 if (Second.isInvalid())
4156 return SemaRef.ExprError();
4157 }
Mike Stump11289f42009-09-09 15:08:12 +00004158
Douglas Gregora16548e2009-08-11 05:31:07 +00004159 if (!getDerived().AlwaysRebuild() &&
4160 Callee.get() == E->getCallee() &&
4161 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004162 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4163 return SemaRef.Owned(E->Retain());
4164
Douglas Gregora16548e2009-08-11 05:31:07 +00004165 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4166 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004167 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004168 move(First),
4169 move(Second));
4170}
Mike Stump11289f42009-09-09 15:08:12 +00004171
Douglas Gregora16548e2009-08-11 05:31:07 +00004172template<typename Derived>
4173Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004174TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E,
4175 bool isAddressOfOperand) {
4176 return getDerived().TransformCallExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004177}
Mike Stump11289f42009-09-09 15:08:12 +00004178
Douglas Gregora16548e2009-08-11 05:31:07 +00004179template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004180Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004181TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E,
4182 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004183 QualType ExplicitTy;
4184 {
4185 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004186 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004187 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4188 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004189
Douglas Gregora16548e2009-08-11 05:31:07 +00004190 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4191 if (ExplicitTy.isNull())
4192 return SemaRef.ExprError();
4193 }
Mike Stump11289f42009-09-09 15:08:12 +00004194
Douglas Gregora16548e2009-08-11 05:31:07 +00004195 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4196 if (SubExpr.isInvalid())
4197 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004198
Douglas Gregora16548e2009-08-11 05:31:07 +00004199 if (!getDerived().AlwaysRebuild() &&
4200 ExplicitTy == E->getTypeAsWritten() &&
4201 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004202 return SemaRef.Owned(E->Retain());
4203
Douglas Gregora16548e2009-08-11 05:31:07 +00004204 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004205 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004206 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4207 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4208 SourceLocation FakeRParenLoc
4209 = SemaRef.PP.getLocForEndOfToken(
4210 E->getSubExpr()->getSourceRange().getEnd());
4211 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004212 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004213 FakeLAngleLoc,
4214 ExplicitTy,
4215 FakeRAngleLoc,
4216 FakeRAngleLoc,
4217 move(SubExpr),
4218 FakeRParenLoc);
4219}
Mike Stump11289f42009-09-09 15:08:12 +00004220
Douglas Gregora16548e2009-08-11 05:31:07 +00004221template<typename Derived>
4222Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004223TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E,
4224 bool isAddressOfOperand) {
4225 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004226}
Mike Stump11289f42009-09-09 15:08:12 +00004227
4228template<typename Derived>
4229Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004230TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E,
4231 bool isAddressOfOperand) {
4232 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Mike Stump11289f42009-09-09 15:08:12 +00004233}
4234
Douglas Gregora16548e2009-08-11 05:31:07 +00004235template<typename Derived>
4236Sema::OwningExprResult
4237TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004238 CXXReinterpretCastExpr *E,
4239 bool isAddressOfOperand) {
4240 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004241}
Mike Stump11289f42009-09-09 15:08:12 +00004242
Douglas Gregora16548e2009-08-11 05:31:07 +00004243template<typename Derived>
4244Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004245TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E,
4246 bool isAddressOfOperand) {
4247 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004248}
Mike Stump11289f42009-09-09 15:08:12 +00004249
Douglas Gregora16548e2009-08-11 05:31:07 +00004250template<typename Derived>
4251Sema::OwningExprResult
4252TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004253 CXXFunctionalCastExpr *E,
4254 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004255 QualType ExplicitTy;
4256 {
4257 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004258
Douglas Gregora16548e2009-08-11 05:31:07 +00004259 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4260 if (ExplicitTy.isNull())
4261 return SemaRef.ExprError();
4262 }
Mike Stump11289f42009-09-09 15:08:12 +00004263
Douglas Gregora16548e2009-08-11 05:31:07 +00004264 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4265 if (SubExpr.isInvalid())
4266 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004267
Douglas Gregora16548e2009-08-11 05:31:07 +00004268 if (!getDerived().AlwaysRebuild() &&
4269 ExplicitTy == E->getTypeAsWritten() &&
4270 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004271 return SemaRef.Owned(E->Retain());
4272
Douglas Gregora16548e2009-08-11 05:31:07 +00004273 // FIXME: The end of the type's source range is wrong
4274 return getDerived().RebuildCXXFunctionalCastExpr(
4275 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
4276 ExplicitTy,
4277 /*FIXME:*/E->getSubExpr()->getLocStart(),
4278 move(SubExpr),
4279 E->getRParenLoc());
4280}
Mike Stump11289f42009-09-09 15:08:12 +00004281
Douglas Gregora16548e2009-08-11 05:31:07 +00004282template<typename Derived>
4283Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004284TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E,
4285 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004286 if (E->isTypeOperand()) {
4287 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004288
Douglas Gregora16548e2009-08-11 05:31:07 +00004289 QualType T = getDerived().TransformType(E->getTypeOperand());
4290 if (T.isNull())
4291 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004292
Douglas Gregora16548e2009-08-11 05:31:07 +00004293 if (!getDerived().AlwaysRebuild() &&
4294 T == E->getTypeOperand())
4295 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004296
Douglas Gregora16548e2009-08-11 05:31:07 +00004297 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4298 /*FIXME:*/E->getLocStart(),
4299 T,
4300 E->getLocEnd());
4301 }
Mike Stump11289f42009-09-09 15:08:12 +00004302
Douglas Gregora16548e2009-08-11 05:31:07 +00004303 // We don't know whether the expression is potentially evaluated until
4304 // after we perform semantic analysis, so the expression is potentially
4305 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004306 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004307 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004308
Douglas Gregora16548e2009-08-11 05:31:07 +00004309 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4310 if (SubExpr.isInvalid())
4311 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004312
Douglas Gregora16548e2009-08-11 05:31:07 +00004313 if (!getDerived().AlwaysRebuild() &&
4314 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004315 return SemaRef.Owned(E->Retain());
4316
Douglas Gregora16548e2009-08-11 05:31:07 +00004317 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4318 /*FIXME:*/E->getLocStart(),
4319 move(SubExpr),
4320 E->getLocEnd());
4321}
4322
4323template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004324Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004325TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E,
4326 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004327 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004328}
Mike Stump11289f42009-09-09 15:08:12 +00004329
Douglas Gregora16548e2009-08-11 05:31:07 +00004330template<typename Derived>
4331Sema::OwningExprResult
4332TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004333 CXXNullPtrLiteralExpr *E,
4334 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004335 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004336}
Mike Stump11289f42009-09-09 15:08:12 +00004337
Douglas Gregora16548e2009-08-11 05:31:07 +00004338template<typename Derived>
4339Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004340TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E,
4341 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004342 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004343
Douglas Gregora16548e2009-08-11 05:31:07 +00004344 QualType T = getDerived().TransformType(E->getType());
4345 if (T.isNull())
4346 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004347
Douglas Gregora16548e2009-08-11 05:31:07 +00004348 if (!getDerived().AlwaysRebuild() &&
4349 T == E->getType())
4350 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004351
Douglas Gregora16548e2009-08-11 05:31:07 +00004352 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T);
4353}
Mike Stump11289f42009-09-09 15:08:12 +00004354
Douglas Gregora16548e2009-08-11 05:31:07 +00004355template<typename Derived>
4356Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004357TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E,
4358 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004359 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4360 if (SubExpr.isInvalid())
4361 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004362
Douglas Gregora16548e2009-08-11 05:31:07 +00004363 if (!getDerived().AlwaysRebuild() &&
4364 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004365 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004366
4367 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4368}
Mike Stump11289f42009-09-09 15:08:12 +00004369
Douglas Gregora16548e2009-08-11 05:31:07 +00004370template<typename Derived>
4371Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004372TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E,
4373 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004374 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004375 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4376 if (!Param)
4377 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004378
Douglas Gregora16548e2009-08-11 05:31:07 +00004379 if (getDerived().AlwaysRebuild() &&
4380 Param == E->getParam())
4381 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004382
Douglas Gregora16548e2009-08-11 05:31:07 +00004383 return getDerived().RebuildCXXDefaultArgExpr(Param);
4384}
Mike Stump11289f42009-09-09 15:08:12 +00004385
Douglas Gregora16548e2009-08-11 05:31:07 +00004386template<typename Derived>
4387Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004388TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E,
4389 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004390 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4391
4392 QualType T = getDerived().TransformType(E->getType());
4393 if (T.isNull())
4394 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004395
Douglas Gregora16548e2009-08-11 05:31:07 +00004396 if (!getDerived().AlwaysRebuild() &&
4397 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004398 return SemaRef.Owned(E->Retain());
4399
4400 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004401 /*FIXME:*/E->getTypeBeginLoc(),
4402 T,
4403 E->getRParenLoc());
4404}
Mike Stump11289f42009-09-09 15:08:12 +00004405
Douglas Gregora16548e2009-08-11 05:31:07 +00004406template<typename Derived>
4407Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004408TreeTransform<Derived>::TransformCXXConditionDeclExpr(CXXConditionDeclExpr *E,
4409 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004410 VarDecl *Var
Douglas Gregorebe10102009-08-20 07:17:43 +00004411 = cast_or_null<VarDecl>(getDerived().TransformDefinition(E->getVarDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004412 if (!Var)
4413 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004414
Douglas Gregora16548e2009-08-11 05:31:07 +00004415 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004416 Var == E->getVarDecl())
Douglas Gregora16548e2009-08-11 05:31:07 +00004417 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004418
4419 return getDerived().RebuildCXXConditionDeclExpr(E->getStartLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004420 /*FIXME:*/E->getStartLoc(),
4421 Var);
4422}
Mike Stump11289f42009-09-09 15:08:12 +00004423
Douglas Gregora16548e2009-08-11 05:31:07 +00004424template<typename Derived>
4425Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004426TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E,
4427 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004428 // Transform the type that we're allocating
4429 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4430 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4431 if (AllocType.isNull())
4432 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004433
Douglas Gregora16548e2009-08-11 05:31:07 +00004434 // Transform the size of the array we're allocating (if any).
4435 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4436 if (ArraySize.isInvalid())
4437 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004438
Douglas Gregora16548e2009-08-11 05:31:07 +00004439 // Transform the placement arguments (if any).
4440 bool ArgumentChanged = false;
4441 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4442 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4443 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4444 if (Arg.isInvalid())
4445 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004446
Douglas Gregora16548e2009-08-11 05:31:07 +00004447 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4448 PlacementArgs.push_back(Arg.take());
4449 }
Mike Stump11289f42009-09-09 15:08:12 +00004450
Douglas Gregorebe10102009-08-20 07:17:43 +00004451 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004452 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4453 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4454 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4455 if (Arg.isInvalid())
4456 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004457
Douglas Gregora16548e2009-08-11 05:31:07 +00004458 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4459 ConstructorArgs.push_back(Arg.take());
4460 }
Mike Stump11289f42009-09-09 15:08:12 +00004461
Douglas Gregora16548e2009-08-11 05:31:07 +00004462 if (!getDerived().AlwaysRebuild() &&
4463 AllocType == E->getAllocatedType() &&
4464 ArraySize.get() == E->getArraySize() &&
4465 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004466 return SemaRef.Owned(E->Retain());
4467
Douglas Gregora16548e2009-08-11 05:31:07 +00004468 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4469 E->isGlobalNew(),
4470 /*FIXME:*/E->getLocStart(),
4471 move_arg(PlacementArgs),
4472 /*FIXME:*/E->getLocStart(),
4473 E->isParenTypeId(),
4474 AllocType,
4475 /*FIXME:*/E->getLocStart(),
4476 /*FIXME:*/SourceRange(),
4477 move(ArraySize),
4478 /*FIXME:*/E->getLocStart(),
4479 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004480 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004481}
Mike Stump11289f42009-09-09 15:08:12 +00004482
Douglas Gregora16548e2009-08-11 05:31:07 +00004483template<typename Derived>
4484Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004485TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E,
4486 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004487 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4488 if (Operand.isInvalid())
4489 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004490
Douglas Gregora16548e2009-08-11 05:31:07 +00004491 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004492 Operand.get() == E->getArgument())
4493 return SemaRef.Owned(E->Retain());
4494
Douglas Gregora16548e2009-08-11 05:31:07 +00004495 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4496 E->isGlobalDelete(),
4497 E->isArrayForm(),
4498 move(Operand));
4499}
Mike Stump11289f42009-09-09 15:08:12 +00004500
Douglas Gregora16548e2009-08-11 05:31:07 +00004501template<typename Derived>
4502Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004503TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004504 CXXPseudoDestructorExpr *E,
4505 bool isAddressOfOperand) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004506 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4507 if (Base.isInvalid())
4508 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004509
Douglas Gregorad8a3362009-09-04 17:36:40 +00004510 NestedNameSpecifier *Qualifier
4511 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4512 E->getQualifierRange());
4513 if (E->getQualifier() && !Qualifier)
4514 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004515
Douglas Gregorad8a3362009-09-04 17:36:40 +00004516 QualType DestroyedType;
4517 {
4518 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4519 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4520 if (DestroyedType.isNull())
4521 return SemaRef.ExprError();
4522 }
Mike Stump11289f42009-09-09 15:08:12 +00004523
Douglas Gregorad8a3362009-09-04 17:36:40 +00004524 if (!getDerived().AlwaysRebuild() &&
4525 Base.get() == E->getBase() &&
4526 Qualifier == E->getQualifier() &&
4527 DestroyedType == E->getDestroyedType())
4528 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004529
Douglas Gregorad8a3362009-09-04 17:36:40 +00004530 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4531 E->getOperatorLoc(),
4532 E->isArrow(),
4533 E->getDestroyedTypeLoc(),
4534 DestroyedType,
4535 Qualifier,
4536 E->getQualifierRange());
4537}
Mike Stump11289f42009-09-09 15:08:12 +00004538
Douglas Gregorad8a3362009-09-04 17:36:40 +00004539template<typename Derived>
4540Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004541TreeTransform<Derived>::TransformUnresolvedLookupExpr(
4542 UnresolvedLookupExpr *E,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004543 bool isAddressOfOperand) {
John McCalld14a8642009-11-21 08:51:07 +00004544 // There is no transformation we can apply to an unresolved lookup.
Mike Stump11289f42009-09-09 15:08:12 +00004545 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004546}
Mike Stump11289f42009-09-09 15:08:12 +00004547
Douglas Gregora16548e2009-08-11 05:31:07 +00004548template<typename Derived>
4549Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004550TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E,
4551 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004552 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004553
Douglas Gregora16548e2009-08-11 05:31:07 +00004554 QualType T = getDerived().TransformType(E->getQueriedType());
4555 if (T.isNull())
4556 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004557
Douglas Gregora16548e2009-08-11 05:31:07 +00004558 if (!getDerived().AlwaysRebuild() &&
4559 T == E->getQueriedType())
4560 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004561
Douglas Gregora16548e2009-08-11 05:31:07 +00004562 // FIXME: Bad location information
4563 SourceLocation FakeLParenLoc
4564 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004565
4566 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004567 E->getLocStart(),
4568 /*FIXME:*/FakeLParenLoc,
4569 T,
4570 E->getLocEnd());
4571}
Mike Stump11289f42009-09-09 15:08:12 +00004572
Douglas Gregora16548e2009-08-11 05:31:07 +00004573template<typename Derived>
4574Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004575TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
4576 DependentScopeDeclRefExpr *E,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004577 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004578 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004579 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4580 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004581 if (!NNS)
4582 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004583
4584 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004585 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4586 if (!Name)
4587 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004588
4589 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004590 NNS == E->getQualifier() &&
4591 Name == E->getDeclName())
Mike Stump11289f42009-09-09 15:08:12 +00004592 return SemaRef.Owned(E->Retain());
4593
John McCall8cd78132009-11-19 22:55:06 +00004594 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00004595 E->getQualifierRange(),
4596 Name,
4597 E->getLocation(),
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004598 isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004599}
4600
4601template<typename Derived>
4602Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004603TreeTransform<Derived>::TransformTemplateIdRefExpr(TemplateIdRefExpr *E,
4604 bool isAddressOfOperand) {
Douglas Gregorba91b892009-10-29 17:56:10 +00004605 TemporaryBase Rebase(*this, E->getTemplateNameLoc(), DeclarationName());
4606
Mike Stump11289f42009-09-09 15:08:12 +00004607 TemplateName Template
Douglas Gregora16548e2009-08-11 05:31:07 +00004608 = getDerived().TransformTemplateName(E->getTemplateName());
4609 if (Template.isNull())
4610 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004611
Douglas Gregord019ff62009-10-22 17:20:55 +00004612 NestedNameSpecifier *Qualifier = 0;
4613 if (E->getQualifier()) {
4614 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4615 E->getQualifierRange());
4616 if (!Qualifier)
4617 return SemaRef.ExprError();
4618 }
John McCall6b51f282009-11-23 01:53:49 +00004619
4620 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004621 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004622 TemplateArgumentLoc Loc;
4623 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004624 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004625 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004626 }
4627
4628 // FIXME: Would like to avoid rebuilding if nothing changed, but we can't
4629 // compare template arguments (yet).
Mike Stump11289f42009-09-09 15:08:12 +00004630
4631 // FIXME: It's possible that we'll find out now that the template name
Douglas Gregora16548e2009-08-11 05:31:07 +00004632 // actually refers to a type, in which case the caller is actually dealing
4633 // with a functional cast. Give a reasonable error message!
Douglas Gregord019ff62009-10-22 17:20:55 +00004634 return getDerived().RebuildTemplateIdExpr(Qualifier, E->getQualifierRange(),
4635 Template, E->getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004636 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004637}
4638
4639template<typename Derived>
4640Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004641TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E,
4642 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004643 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4644
4645 QualType T = getDerived().TransformType(E->getType());
4646 if (T.isNull())
4647 return SemaRef.ExprError();
4648
4649 CXXConstructorDecl *Constructor
4650 = cast_or_null<CXXConstructorDecl>(
4651 getDerived().TransformDecl(E->getConstructor()));
4652 if (!Constructor)
4653 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004654
Douglas Gregora16548e2009-08-11 05:31:07 +00004655 bool ArgumentChanged = false;
4656 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004657 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004658 ArgEnd = E->arg_end();
4659 Arg != ArgEnd; ++Arg) {
4660 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4661 if (TransArg.isInvalid())
4662 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004663
Douglas Gregora16548e2009-08-11 05:31:07 +00004664 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4665 Args.push_back(TransArg.takeAs<Expr>());
4666 }
4667
4668 if (!getDerived().AlwaysRebuild() &&
4669 T == E->getType() &&
4670 Constructor == E->getConstructor() &&
4671 !ArgumentChanged)
4672 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004673
Douglas Gregora16548e2009-08-11 05:31:07 +00004674 return getDerived().RebuildCXXConstructExpr(T, Constructor, E->isElidable(),
4675 move_arg(Args));
4676}
Mike Stump11289f42009-09-09 15:08:12 +00004677
Douglas Gregora16548e2009-08-11 05:31:07 +00004678/// \brief Transform a C++ temporary-binding expression.
4679///
Mike Stump11289f42009-09-09 15:08:12 +00004680/// The transformation of a temporary-binding expression always attempts to
4681/// bind a new temporary variable to its subexpression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004682/// subexpression itself did not change, because the temporary variable itself
4683/// must be unique.
4684template<typename Derived>
4685Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004686TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E,
4687 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004688 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4689 if (SubExpr.isInvalid())
4690 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004691
Douglas Gregora16548e2009-08-11 05:31:07 +00004692 return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>());
4693}
Mike Stump11289f42009-09-09 15:08:12 +00004694
4695/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004696/// be destroyed after the expression is evaluated.
4697///
Mike Stump11289f42009-09-09 15:08:12 +00004698/// The transformation of a full expression always attempts to build a new
4699/// CXXExprWithTemporaries expression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004700/// subexpression itself did not change, because it will need to capture the
4701/// the new temporary variables introduced in the subexpression.
4702template<typename Derived>
4703Sema::OwningExprResult
4704TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004705 CXXExprWithTemporaries *E,
4706 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004707 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4708 if (SubExpr.isInvalid())
4709 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004710
Douglas Gregora16548e2009-08-11 05:31:07 +00004711 return SemaRef.Owned(
4712 SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(),
4713 E->shouldDestroyTemporaries()));
4714}
Mike Stump11289f42009-09-09 15:08:12 +00004715
Douglas Gregora16548e2009-08-11 05:31:07 +00004716template<typename Derived>
4717Sema::OwningExprResult
4718TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004719 CXXTemporaryObjectExpr *E,
4720 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004721 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4722 QualType T = getDerived().TransformType(E->getType());
4723 if (T.isNull())
4724 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004725
Douglas Gregora16548e2009-08-11 05:31:07 +00004726 CXXConstructorDecl *Constructor
4727 = cast_or_null<CXXConstructorDecl>(
4728 getDerived().TransformDecl(E->getConstructor()));
4729 if (!Constructor)
4730 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004731
Douglas Gregora16548e2009-08-11 05:31:07 +00004732 bool ArgumentChanged = false;
4733 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4734 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004735 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004736 ArgEnd = E->arg_end();
4737 Arg != ArgEnd; ++Arg) {
4738 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4739 if (TransArg.isInvalid())
4740 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004741
Douglas Gregora16548e2009-08-11 05:31:07 +00004742 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4743 Args.push_back((Expr *)TransArg.release());
4744 }
Mike Stump11289f42009-09-09 15:08:12 +00004745
Douglas Gregora16548e2009-08-11 05:31:07 +00004746 if (!getDerived().AlwaysRebuild() &&
4747 T == E->getType() &&
4748 Constructor == E->getConstructor() &&
4749 !ArgumentChanged)
4750 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004751
Douglas Gregora16548e2009-08-11 05:31:07 +00004752 // FIXME: Bogus location information
4753 SourceLocation CommaLoc;
4754 if (Args.size() > 1) {
4755 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004756 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004757 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4758 }
4759 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4760 T,
4761 /*FIXME:*/E->getTypeBeginLoc(),
4762 move_arg(Args),
4763 &CommaLoc,
4764 E->getLocEnd());
4765}
Mike Stump11289f42009-09-09 15:08:12 +00004766
Douglas Gregora16548e2009-08-11 05:31:07 +00004767template<typename Derived>
4768Sema::OwningExprResult
4769TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004770 CXXUnresolvedConstructExpr *E,
4771 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004772 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4773 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4774 if (T.isNull())
4775 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004776
Douglas Gregora16548e2009-08-11 05:31:07 +00004777 bool ArgumentChanged = false;
4778 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4779 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4780 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4781 ArgEnd = E->arg_end();
4782 Arg != ArgEnd; ++Arg) {
4783 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4784 if (TransArg.isInvalid())
4785 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004786
Douglas Gregora16548e2009-08-11 05:31:07 +00004787 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4788 FakeCommaLocs.push_back(
4789 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4790 Args.push_back(TransArg.takeAs<Expr>());
4791 }
Mike Stump11289f42009-09-09 15:08:12 +00004792
Douglas Gregora16548e2009-08-11 05:31:07 +00004793 if (!getDerived().AlwaysRebuild() &&
4794 T == E->getTypeAsWritten() &&
4795 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004796 return SemaRef.Owned(E->Retain());
4797
Douglas Gregora16548e2009-08-11 05:31:07 +00004798 // FIXME: we're faking the locations of the commas
4799 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4800 T,
4801 E->getLParenLoc(),
4802 move_arg(Args),
4803 FakeCommaLocs.data(),
4804 E->getRParenLoc());
4805}
Mike Stump11289f42009-09-09 15:08:12 +00004806
Douglas Gregora16548e2009-08-11 05:31:07 +00004807template<typename Derived>
4808Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004809TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
4810 CXXDependentScopeMemberExpr *E,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004811 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004812 // Transform the base of the expression.
4813 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4814 if (Base.isInvalid())
4815 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004816
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004817 // Start the member reference and compute the object's type.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004818 Sema::TypeTy *ObjectType = 0;
Mike Stump11289f42009-09-09 15:08:12 +00004819 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004820 E->getOperatorLoc(),
4821 E->isArrow()? tok::arrow : tok::period,
4822 ObjectType);
4823 if (Base.isInvalid())
4824 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004825
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004826 // Transform the first part of the nested-name-specifier that qualifies
4827 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004828 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004829 = getDerived().TransformFirstQualifierInScope(
4830 E->getFirstQualifierFoundInScope(),
4831 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00004832
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004833 NestedNameSpecifier *Qualifier = 0;
4834 if (E->getQualifier()) {
4835 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4836 E->getQualifierRange(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004837 QualType::getFromOpaquePtr(ObjectType),
4838 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004839 if (!Qualifier)
4840 return SemaRef.ExprError();
4841 }
Mike Stump11289f42009-09-09 15:08:12 +00004842
4843 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00004844 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
4845 QualType::getFromOpaquePtr(ObjectType));
Douglas Gregorf816bd72009-09-03 22:13:48 +00004846 if (!Name)
4847 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004848
Douglas Gregor308047d2009-09-09 00:23:06 +00004849 if (!E->hasExplicitTemplateArgumentList()) {
4850 // This is a reference to a member without an explicitly-specified
4851 // template argument list. Optimize for this common case.
4852 if (!getDerived().AlwaysRebuild() &&
4853 Base.get() == E->getBase() &&
4854 Qualifier == E->getQualifier() &&
4855 Name == E->getMember() &&
4856 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00004857 return SemaRef.Owned(E->Retain());
4858
John McCall8cd78132009-11-19 22:55:06 +00004859 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
Douglas Gregor308047d2009-09-09 00:23:06 +00004860 E->isArrow(),
4861 E->getOperatorLoc(),
4862 Qualifier,
4863 E->getQualifierRange(),
4864 Name,
4865 E->getMemberLoc(),
4866 FirstQualifierInScope);
4867 }
4868
4869 // FIXME: This is an ugly hack, which forces the same template name to
4870 // be looked up multiple times. Yuck!
Douglas Gregor71395fa2009-11-04 00:56:37 +00004871 TemporaryBase Rebase(*this, E->getMemberLoc(), DeclarationName());
4872 TemplateName OrigTemplateName;
4873 if (const IdentifierInfo *II = Name.getAsIdentifierInfo())
4874 OrigTemplateName = SemaRef.Context.getDependentTemplateName(0, II);
4875 else
4876 OrigTemplateName
4877 = SemaRef.Context.getDependentTemplateName(0,
4878 Name.getCXXOverloadedOperator());
Mike Stump11289f42009-09-09 15:08:12 +00004879
4880 TemplateName Template
4881 = getDerived().TransformTemplateName(OrigTemplateName,
Douglas Gregor308047d2009-09-09 00:23:06 +00004882 QualType::getFromOpaquePtr(ObjectType));
4883 if (Template.isNull())
4884 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004885
John McCall6b51f282009-11-23 01:53:49 +00004886 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00004887 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004888 TemplateArgumentLoc Loc;
4889 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00004890 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004891 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00004892 }
Mike Stump11289f42009-09-09 15:08:12 +00004893
John McCall8cd78132009-11-19 22:55:06 +00004894 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
Douglas Gregora16548e2009-08-11 05:31:07 +00004895 E->isArrow(),
4896 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004897 Qualifier,
4898 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004899 Template,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004900 E->getMemberLoc(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004901 FirstQualifierInScope,
John McCall6b51f282009-11-23 01:53:49 +00004902 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004903}
4904
4905template<typename Derived>
4906Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004907TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E,
4908 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004909 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004910}
4911
Mike Stump11289f42009-09-09 15:08:12 +00004912template<typename Derived>
4913Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004914TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E,
4915 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004916 // FIXME: poor source location
4917 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
4918 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
4919 if (EncodedType.isNull())
4920 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004921
Douglas Gregora16548e2009-08-11 05:31:07 +00004922 if (!getDerived().AlwaysRebuild() &&
4923 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00004924 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004925
4926 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
4927 EncodedType,
4928 E->getRParenLoc());
4929}
Mike Stump11289f42009-09-09 15:08:12 +00004930
Douglas Gregora16548e2009-08-11 05:31:07 +00004931template<typename Derived>
4932Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004933TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E,
4934 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004935 // FIXME: Implement this!
4936 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004937 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004938}
4939
Mike Stump11289f42009-09-09 15:08:12 +00004940template<typename Derived>
4941Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004942TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E,
4943 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004944 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004945}
4946
Mike Stump11289f42009-09-09 15:08:12 +00004947template<typename Derived>
4948Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004949TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E,
4950 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004951 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00004952 = cast_or_null<ObjCProtocolDecl>(
4953 getDerived().TransformDecl(E->getProtocol()));
4954 if (!Protocol)
4955 return SemaRef.ExprError();
4956
4957 if (!getDerived().AlwaysRebuild() &&
4958 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00004959 return SemaRef.Owned(E->Retain());
4960
Douglas Gregora16548e2009-08-11 05:31:07 +00004961 return getDerived().RebuildObjCProtocolExpr(Protocol,
4962 E->getAtLoc(),
4963 /*FIXME:*/E->getAtLoc(),
4964 /*FIXME:*/E->getAtLoc(),
4965 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004966
Douglas Gregora16548e2009-08-11 05:31:07 +00004967}
4968
Mike Stump11289f42009-09-09 15:08:12 +00004969template<typename Derived>
4970Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004971TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E,
4972 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004973 // FIXME: Implement this!
4974 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004975 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004976}
4977
Mike Stump11289f42009-09-09 15:08:12 +00004978template<typename Derived>
4979Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004980TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E,
4981 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004982 // FIXME: Implement this!
4983 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004984 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004985}
4986
Mike Stump11289f42009-09-09 15:08:12 +00004987template<typename Derived>
4988Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00004989TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004990 ObjCImplicitSetterGetterRefExpr *E,
4991 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004992 // FIXME: Implement this!
4993 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004994 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004995}
4996
Mike Stump11289f42009-09-09 15:08:12 +00004997template<typename Derived>
4998Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004999TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E,
5000 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005001 // FIXME: Implement this!
5002 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005003 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005004}
5005
Mike Stump11289f42009-09-09 15:08:12 +00005006template<typename Derived>
5007Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005008TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E,
5009 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005010 // FIXME: Implement this!
5011 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005012 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005013}
5014
Mike Stump11289f42009-09-09 15:08:12 +00005015template<typename Derived>
5016Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005017TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E,
5018 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005019 bool ArgumentChanged = false;
5020 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5021 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5022 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5023 if (SubExpr.isInvalid())
5024 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005025
Douglas Gregora16548e2009-08-11 05:31:07 +00005026 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5027 SubExprs.push_back(SubExpr.takeAs<Expr>());
5028 }
Mike Stump11289f42009-09-09 15:08:12 +00005029
Douglas Gregora16548e2009-08-11 05:31:07 +00005030 if (!getDerived().AlwaysRebuild() &&
5031 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005032 return SemaRef.Owned(E->Retain());
5033
Douglas Gregora16548e2009-08-11 05:31:07 +00005034 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5035 move_arg(SubExprs),
5036 E->getRParenLoc());
5037}
5038
Mike Stump11289f42009-09-09 15:08:12 +00005039template<typename Derived>
5040Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005041TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E,
5042 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005043 // FIXME: Implement this!
5044 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005045 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005046}
5047
Mike Stump11289f42009-09-09 15:08:12 +00005048template<typename Derived>
5049Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005050TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E,
5051 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005052 // FIXME: Implement this!
5053 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005054 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005055}
Mike Stump11289f42009-09-09 15:08:12 +00005056
Douglas Gregora16548e2009-08-11 05:31:07 +00005057//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005058// Type reconstruction
5059//===----------------------------------------------------------------------===//
5060
Mike Stump11289f42009-09-09 15:08:12 +00005061template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005062QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5063 SourceLocation Star) {
5064 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005065 getDerived().getBaseEntity());
5066}
5067
Mike Stump11289f42009-09-09 15:08:12 +00005068template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005069QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5070 SourceLocation Star) {
5071 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005072 getDerived().getBaseEntity());
5073}
5074
Mike Stump11289f42009-09-09 15:08:12 +00005075template<typename Derived>
5076QualType
John McCall70dd5f62009-10-30 00:06:24 +00005077TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5078 bool WrittenAsLValue,
5079 SourceLocation Sigil) {
5080 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5081 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005082}
5083
5084template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005085QualType
John McCall70dd5f62009-10-30 00:06:24 +00005086TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5087 QualType ClassType,
5088 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005089 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005090 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005091}
5092
5093template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005094QualType
John McCall70dd5f62009-10-30 00:06:24 +00005095TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5096 SourceLocation Sigil) {
5097 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005098 getDerived().getBaseEntity());
5099}
5100
5101template<typename Derived>
5102QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005103TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5104 ArrayType::ArraySizeModifier SizeMod,
5105 const llvm::APInt *Size,
5106 Expr *SizeExpr,
5107 unsigned IndexTypeQuals,
5108 SourceRange BracketsRange) {
5109 if (SizeExpr || !Size)
5110 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5111 IndexTypeQuals, BracketsRange,
5112 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005113
5114 QualType Types[] = {
5115 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5116 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5117 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005118 };
5119 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5120 QualType SizeType;
5121 for (unsigned I = 0; I != NumTypes; ++I)
5122 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5123 SizeType = Types[I];
5124 break;
5125 }
Mike Stump11289f42009-09-09 15:08:12 +00005126
Douglas Gregord6ff3322009-08-04 16:50:30 +00005127 if (SizeType.isNull())
5128 SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false);
Mike Stump11289f42009-09-09 15:08:12 +00005129
Douglas Gregord6ff3322009-08-04 16:50:30 +00005130 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005131 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005132 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005133 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005134}
Mike Stump11289f42009-09-09 15:08:12 +00005135
Douglas Gregord6ff3322009-08-04 16:50:30 +00005136template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005137QualType
5138TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005139 ArrayType::ArraySizeModifier SizeMod,
5140 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005141 unsigned IndexTypeQuals,
5142 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005143 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005144 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005145}
5146
5147template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005148QualType
Mike Stump11289f42009-09-09 15:08:12 +00005149TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005150 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005151 unsigned IndexTypeQuals,
5152 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005153 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005154 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005155}
Mike Stump11289f42009-09-09 15:08:12 +00005156
Douglas Gregord6ff3322009-08-04 16:50:30 +00005157template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005158QualType
5159TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005160 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005161 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005162 unsigned IndexTypeQuals,
5163 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005164 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005165 SizeExpr.takeAs<Expr>(),
5166 IndexTypeQuals, BracketsRange);
5167}
5168
5169template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005170QualType
5171TreeTransform<Derived>::RebuildDependentSizedArrayType(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>
5182QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
5183 unsigned NumElements) {
5184 // FIXME: semantic checking!
5185 return SemaRef.Context.getVectorType(ElementType, NumElements);
5186}
Mike Stump11289f42009-09-09 15:08:12 +00005187
Douglas Gregord6ff3322009-08-04 16:50:30 +00005188template<typename Derived>
5189QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5190 unsigned NumElements,
5191 SourceLocation AttributeLoc) {
5192 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5193 NumElements, true);
5194 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005195 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005196 AttributeLoc);
5197 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5198 AttributeLoc);
5199}
Mike Stump11289f42009-09-09 15:08:12 +00005200
Douglas Gregord6ff3322009-08-04 16:50:30 +00005201template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005202QualType
5203TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005204 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005205 SourceLocation AttributeLoc) {
5206 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5207}
Mike Stump11289f42009-09-09 15:08:12 +00005208
Douglas Gregord6ff3322009-08-04 16:50:30 +00005209template<typename Derived>
5210QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005211 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005212 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005213 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005214 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005215 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005216 Quals,
5217 getDerived().getBaseLocation(),
5218 getDerived().getBaseEntity());
5219}
Mike Stump11289f42009-09-09 15:08:12 +00005220
Douglas Gregord6ff3322009-08-04 16:50:30 +00005221template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005222QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5223 return SemaRef.Context.getFunctionNoProtoType(T);
5224}
5225
5226template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005227QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005228 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5229}
5230
5231template<typename Derived>
5232QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5233 return SemaRef.Context.getTypeOfType(Underlying);
5234}
5235
5236template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005237QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005238 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5239}
5240
5241template<typename Derived>
5242QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005243 TemplateName Template,
5244 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005245 const TemplateArgumentListInfo &TemplateArgs) {
5246 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005247}
Mike Stump11289f42009-09-09 15:08:12 +00005248
Douglas Gregor1135c352009-08-06 05:28:30 +00005249template<typename Derived>
5250NestedNameSpecifier *
5251TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5252 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005253 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005254 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005255 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005256 CXXScopeSpec SS;
5257 // FIXME: The source location information is all wrong.
5258 SS.setRange(Range);
5259 SS.setScopeRep(Prefix);
5260 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005261 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005262 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005263 ObjectType,
5264 FirstQualifierInScope,
Douglas Gregore861bac2009-08-25 22:51:20 +00005265 false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005266}
5267
5268template<typename Derived>
5269NestedNameSpecifier *
5270TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5271 SourceRange Range,
5272 NamespaceDecl *NS) {
5273 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5274}
5275
5276template<typename Derived>
5277NestedNameSpecifier *
5278TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5279 SourceRange Range,
5280 bool TemplateKW,
5281 QualType T) {
5282 if (T->isDependentType() || T->isRecordType() ||
5283 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005284 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005285 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5286 T.getTypePtr());
5287 }
Mike Stump11289f42009-09-09 15:08:12 +00005288
Douglas Gregor1135c352009-08-06 05:28:30 +00005289 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5290 return 0;
5291}
Mike Stump11289f42009-09-09 15:08:12 +00005292
Douglas Gregor71dc5092009-08-06 06:41:21 +00005293template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005294TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005295TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5296 bool TemplateKW,
5297 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005298 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005299 Template);
5300}
5301
5302template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005303TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005304TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5305 bool TemplateKW,
5306 OverloadedFunctionDecl *Ovl) {
5307 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, Ovl);
5308}
5309
5310template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005311TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005312TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005313 const IdentifierInfo &II,
5314 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005315 CXXScopeSpec SS;
5316 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005317 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005318 UnqualifiedId Name;
5319 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005320 return getSema().ActOnDependentTemplateName(
5321 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005322 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005323 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005324 ObjectType.getAsOpaquePtr(),
5325 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005326 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005327}
Mike Stump11289f42009-09-09 15:08:12 +00005328
Douglas Gregora16548e2009-08-11 05:31:07 +00005329template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005330TemplateName
5331TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5332 OverloadedOperatorKind Operator,
5333 QualType ObjectType) {
5334 CXXScopeSpec SS;
5335 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5336 SS.setScopeRep(Qualifier);
5337 UnqualifiedId Name;
5338 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5339 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5340 Operator, SymbolLocations);
5341 return getSema().ActOnDependentTemplateName(
5342 /*FIXME:*/getDerived().getBaseLocation(),
5343 SS,
5344 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005345 ObjectType.getAsOpaquePtr(),
5346 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005347 .template getAsVal<TemplateName>();
5348}
5349
5350template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005351Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005352TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5353 SourceLocation OpLoc,
5354 ExprArg Callee,
5355 ExprArg First,
5356 ExprArg Second) {
5357 Expr *FirstExpr = (Expr *)First.get();
5358 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005359 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005360 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005361
Douglas Gregora16548e2009-08-11 05:31:07 +00005362 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005363 if (Op == OO_Subscript) {
5364 if (!FirstExpr->getType()->isOverloadableType() &&
5365 !SecondExpr->getType()->isOverloadableType())
5366 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005367 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005368 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005369 } else if (Op == OO_Arrow) {
5370 // -> is never a builtin operation.
5371 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005372 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005373 if (!FirstExpr->getType()->isOverloadableType()) {
5374 // The argument is not of overloadable type, so try to create a
5375 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005376 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005377 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005378
Douglas Gregora16548e2009-08-11 05:31:07 +00005379 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5380 }
5381 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005382 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005383 !SecondExpr->getType()->isOverloadableType()) {
5384 // Neither of the arguments is an overloadable type, so try to
5385 // create a built-in binary operation.
5386 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005387 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005388 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5389 if (Result.isInvalid())
5390 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005391
Douglas Gregora16548e2009-08-11 05:31:07 +00005392 First.release();
5393 Second.release();
5394 return move(Result);
5395 }
5396 }
Mike Stump11289f42009-09-09 15:08:12 +00005397
5398 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005399 // used during overload resolution.
5400 Sema::FunctionSet Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005401
John McCalld14a8642009-11-21 08:51:07 +00005402 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5403 assert(ULE->requiresADL());
5404
5405 // FIXME: Do we have to check
5406 // IsAcceptableNonMemberOperatorCandidate for each of these?
5407 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(),
5408 E = ULE->decls_end(); I != E; ++I)
5409 Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I));
5410 } else {
5411 Functions.insert(AnyFunctionDecl::getFromNamedDecl(
5412 cast<DeclRefExpr>(CalleeExpr)->getDecl()));
5413 }
Mike Stump11289f42009-09-09 15:08:12 +00005414
Douglas Gregora16548e2009-08-11 05:31:07 +00005415 // Add any functions found via argument-dependent lookup.
5416 Expr *Args[2] = { FirstExpr, SecondExpr };
5417 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005418 DeclarationName OpName
Douglas Gregora16548e2009-08-11 05:31:07 +00005419 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
Sebastian Redlc057f422009-10-23 19:23:15 +00005420 SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs,
5421 Functions);
Mike Stump11289f42009-09-09 15:08:12 +00005422
Douglas Gregora16548e2009-08-11 05:31:07 +00005423 // Create the overloaded operator invocation for unary operators.
5424 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005425 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005426 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5427 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5428 }
Mike Stump11289f42009-09-09 15:08:12 +00005429
Sebastian Redladba46e2009-10-29 20:17:01 +00005430 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005431 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5432 OpLoc,
5433 move(First),
5434 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005435
Douglas Gregora16548e2009-08-11 05:31:07 +00005436 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005437 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005438 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005439 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005440 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5441 if (Result.isInvalid())
5442 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005443
Douglas Gregora16548e2009-08-11 05:31:07 +00005444 First.release();
5445 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005446 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005447}
Mike Stump11289f42009-09-09 15:08:12 +00005448
Douglas Gregord6ff3322009-08-04 16:50:30 +00005449} // end namespace clang
5450
5451#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H