blob: 53aef9fdef5921de93b0518046e6f2b356f8b110 [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.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000293 TemplateArgument TransformTemplateArgument(const TemplateArgument &Arg);
Mike Stump11289f42009-09-09 15:08:12 +0000294
John McCall550e0c22009-10-21 00:40:46 +0000295#define ABSTRACT_TYPELOC(CLASS, PARENT)
296#define TYPELOC(CLASS, PARENT) \
297 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
298#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000299
Douglas Gregorc59e5612009-10-19 22:04:39 +0000300 QualType
301 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
302 QualType ObjectType);
303
Douglas Gregorebe10102009-08-20 07:17:43 +0000304 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Mike Stump11289f42009-09-09 15:08:12 +0000305
Douglas Gregorebe10102009-08-20 07:17:43 +0000306#define STMT(Node, Parent) \
307 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000308#define EXPR(Node, Parent) \
309 OwningExprResult Transform##Node(Node *E);
310#define ABSTRACT_EXPR(Node, Parent)
311#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000312
Douglas Gregord6ff3322009-08-04 16:50:30 +0000313 /// \brief Build a new pointer type given its pointee type.
314 ///
315 /// By default, performs semantic analysis when building the pointer type.
316 /// Subclasses may override this routine to provide different behavior.
317 QualType RebuildPointerType(QualType PointeeType);
318
319 /// \brief Build a new block pointer type given its pointee type.
320 ///
Mike Stump11289f42009-09-09 15:08:12 +0000321 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000322 /// type. Subclasses may override this routine to provide different behavior.
323 QualType RebuildBlockPointerType(QualType PointeeType);
324
325 /// \brief Build a new lvalue reference type given the type it references.
326 ///
327 /// By default, performs semantic analysis when building the lvalue reference
328 /// type. Subclasses may override this routine to provide different behavior.
329 QualType RebuildLValueReferenceType(QualType ReferentType);
330
331 /// \brief Build a new rvalue reference type given the type it references.
332 ///
333 /// By default, performs semantic analysis when building the rvalue reference
334 /// type. Subclasses may override this routine to provide different behavior.
335 QualType RebuildRValueReferenceType(QualType ReferentType);
Mike Stump11289f42009-09-09 15:08:12 +0000336
Douglas Gregord6ff3322009-08-04 16:50:30 +0000337 /// \brief Build a new member pointer type given the pointee type and the
338 /// class type it refers into.
339 ///
340 /// By default, performs semantic analysis when building the member pointer
341 /// type. Subclasses may override this routine to provide different behavior.
342 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType);
Mike Stump11289f42009-09-09 15:08:12 +0000343
John McCall550e0c22009-10-21 00:40:46 +0000344 /// \brief Build a new Objective C object pointer type.
345 QualType RebuildObjCObjectPointerType(QualType PointeeType);
346
Douglas Gregord6ff3322009-08-04 16:50:30 +0000347 /// \brief Build a new array type given the element type, size
348 /// modifier, size of the array (if known), size expression, and index type
349 /// qualifiers.
350 ///
351 /// By default, performs semantic analysis when building the array type.
352 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000353 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000354 QualType RebuildArrayType(QualType ElementType,
355 ArrayType::ArraySizeModifier SizeMod,
356 const llvm::APInt *Size,
357 Expr *SizeExpr,
358 unsigned IndexTypeQuals,
359 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000360
Douglas Gregord6ff3322009-08-04 16:50:30 +0000361 /// \brief Build a new constant array type given the element type, size
362 /// modifier, (known) size of the array, and index type qualifiers.
363 ///
364 /// By default, performs semantic analysis when building the array type.
365 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000366 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000367 ArrayType::ArraySizeModifier SizeMod,
368 const llvm::APInt &Size,
369 unsigned IndexTypeQuals);
370
Douglas Gregord6ff3322009-08-04 16:50:30 +0000371 /// \brief Build a new incomplete array type given the element type, size
372 /// modifier, and index type qualifiers.
373 ///
374 /// By default, performs semantic analysis when building the array type.
375 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000376 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000377 ArrayType::ArraySizeModifier SizeMod,
378 unsigned IndexTypeQuals);
379
Mike Stump11289f42009-09-09 15:08:12 +0000380 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000381 /// size modifier, size expression, and index type qualifiers.
382 ///
383 /// By default, performs semantic analysis when building the array type.
384 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000385 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000386 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000387 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000388 unsigned IndexTypeQuals,
389 SourceRange BracketsRange);
390
Mike Stump11289f42009-09-09 15:08:12 +0000391 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000392 /// size modifier, size expression, and index type qualifiers.
393 ///
394 /// By default, performs semantic analysis when building the array type.
395 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000396 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000397 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000398 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000399 unsigned IndexTypeQuals,
400 SourceRange BracketsRange);
401
402 /// \brief Build a new vector type given the element type and
403 /// number of elements.
404 ///
405 /// By default, performs semantic analysis when building the vector type.
406 /// Subclasses may override this routine to provide different behavior.
407 QualType RebuildVectorType(QualType ElementType, unsigned NumElements);
Mike Stump11289f42009-09-09 15:08:12 +0000408
Douglas Gregord6ff3322009-08-04 16:50:30 +0000409 /// \brief Build a new extended vector type given the element type and
410 /// number of elements.
411 ///
412 /// By default, performs semantic analysis when building the vector type.
413 /// Subclasses may override this routine to provide different behavior.
414 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
415 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000416
417 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000418 /// given the element type and number of elements.
419 ///
420 /// By default, performs semantic analysis when building the vector type.
421 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000422 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000423 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000424 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000425
Douglas Gregord6ff3322009-08-04 16:50:30 +0000426 /// \brief Build a new function type.
427 ///
428 /// By default, performs semantic analysis when building the function type.
429 /// Subclasses may override this routine to provide different behavior.
430 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000431 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000432 unsigned NumParamTypes,
433 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000434
John McCall550e0c22009-10-21 00:40:46 +0000435 /// \brief Build a new unprototyped function type.
436 QualType RebuildFunctionNoProtoType(QualType ResultType);
437
Douglas Gregord6ff3322009-08-04 16:50:30 +0000438 /// \brief Build a new typedef type.
439 QualType RebuildTypedefType(TypedefDecl *Typedef) {
440 return SemaRef.Context.getTypeDeclType(Typedef);
441 }
442
443 /// \brief Build a new class/struct/union type.
444 QualType RebuildRecordType(RecordDecl *Record) {
445 return SemaRef.Context.getTypeDeclType(Record);
446 }
447
448 /// \brief Build a new Enum type.
449 QualType RebuildEnumType(EnumDecl *Enum) {
450 return SemaRef.Context.getTypeDeclType(Enum);
451 }
John McCallfcc33b02009-09-05 00:15:47 +0000452
453 /// \brief Build a new elaborated type.
454 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
455 return SemaRef.Context.getElaboratedType(T, Tag);
456 }
Mike Stump11289f42009-09-09 15:08:12 +0000457
458 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000459 ///
460 /// By default, performs semantic analysis when building the typeof type.
461 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000462 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000463
Mike Stump11289f42009-09-09 15:08:12 +0000464 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000465 ///
466 /// By default, builds a new TypeOfType with the given underlying type.
467 QualType RebuildTypeOfType(QualType Underlying);
468
Mike Stump11289f42009-09-09 15:08:12 +0000469 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000470 ///
471 /// By default, performs semantic analysis when building the decltype type.
472 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000473 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000474
Douglas Gregord6ff3322009-08-04 16:50:30 +0000475 /// \brief Build a new template specialization type.
476 ///
477 /// By default, performs semantic analysis when building the template
478 /// specialization type. Subclasses may override this routine to provide
479 /// different behavior.
480 QualType RebuildTemplateSpecializationType(TemplateName Template,
481 const TemplateArgument *Args,
482 unsigned NumArgs);
Mike Stump11289f42009-09-09 15:08:12 +0000483
Douglas Gregord6ff3322009-08-04 16:50:30 +0000484 /// \brief Build a new qualified name type.
485 ///
Mike Stump11289f42009-09-09 15:08:12 +0000486 /// By default, builds a new QualifiedNameType type from the
487 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000488 /// this routine to provide different behavior.
489 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
490 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000491 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000492
493 /// \brief Build a new typename type that refers to a template-id.
494 ///
495 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000496 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000497 /// different behavior.
498 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
499 if (NNS->isDependent())
Mike Stump11289f42009-09-09 15:08:12 +0000500 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501 cast<TemplateSpecializationType>(T));
Mike Stump11289f42009-09-09 15:08:12 +0000502
Douglas Gregord6ff3322009-08-04 16:50:30 +0000503 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000504 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000505
506 /// \brief Build a new typename type that refers to an identifier.
507 ///
508 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000509 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000510 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000511 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 const IdentifierInfo *Id) {
513 return SemaRef.CheckTypenameType(NNS, *Id,
514 SourceRange(getDerived().getBaseLocation()));
Douglas Gregor1135c352009-08-06 05:28:30 +0000515 }
Mike Stump11289f42009-09-09 15:08:12 +0000516
John McCall550e0c22009-10-21 00:40:46 +0000517 /// \brief Rebuild an objective C protocol list type.
518 QualType RebuildObjCProtocolListType(QualType BaseType,
519 ObjCProtocolDecl **Protocols,
520 unsigned NumProtocols) {
521 return SemaRef.Context.getObjCProtocolListType(BaseType, Protocols,
522 NumProtocols);
523 }
524
Douglas Gregor1135c352009-08-06 05:28:30 +0000525 /// \brief Build a new nested-name-specifier given the prefix and an
526 /// identifier that names the next step in the nested-name-specifier.
527 ///
528 /// By default, performs semantic analysis when building the new
529 /// nested-name-specifier. Subclasses may override this routine to provide
530 /// different behavior.
531 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
532 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000533 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000534 QualType ObjectType,
535 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000536
537 /// \brief Build a new nested-name-specifier given the prefix and the
538 /// namespace named in the next step in the nested-name-specifier.
539 ///
540 /// By default, performs semantic analysis when building the new
541 /// nested-name-specifier. Subclasses may override this routine to provide
542 /// different behavior.
543 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
544 SourceRange Range,
545 NamespaceDecl *NS);
546
547 /// \brief Build a new nested-name-specifier given the prefix and the
548 /// type named in the next step in the nested-name-specifier.
549 ///
550 /// By default, performs semantic analysis when building the new
551 /// nested-name-specifier. Subclasses may override this routine to provide
552 /// different behavior.
553 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
554 SourceRange Range,
555 bool TemplateKW,
556 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000557
558 /// \brief Build a new template name given a nested name specifier, a flag
559 /// indicating whether the "template" keyword was provided, and the template
560 /// that the template name refers to.
561 ///
562 /// By default, builds the new template name directly. Subclasses may override
563 /// this routine to provide different behavior.
564 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
565 bool TemplateKW,
566 TemplateDecl *Template);
567
568 /// \brief Build a new template name given a nested name specifier, a flag
569 /// indicating whether the "template" keyword was provided, and a set of
570 /// overloaded function templates.
571 ///
572 /// By default, builds the new template name directly. Subclasses may override
573 /// this routine to provide different behavior.
574 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
575 bool TemplateKW,
576 OverloadedFunctionDecl *Ovl);
Mike Stump11289f42009-09-09 15:08:12 +0000577
Douglas Gregor71dc5092009-08-06 06:41:21 +0000578 /// \brief Build a new template name given a nested name specifier and the
579 /// name that is referred to as a template.
580 ///
581 /// By default, performs semantic analysis to determine whether the name can
582 /// be resolved to a specific template, then builds the appropriate kind of
583 /// template name. Subclasses may override this routine to provide different
584 /// behavior.
585 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000586 const IdentifierInfo &II,
587 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000588
589
Douglas Gregorebe10102009-08-20 07:17:43 +0000590 /// \brief Build a new compound statement.
591 ///
592 /// By default, performs semantic analysis to build the new statement.
593 /// Subclasses may override this routine to provide different behavior.
594 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
595 MultiStmtArg Statements,
596 SourceLocation RBraceLoc,
597 bool IsStmtExpr) {
598 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
599 IsStmtExpr);
600 }
601
602 /// \brief Build a new case statement.
603 ///
604 /// By default, performs semantic analysis to build the new statement.
605 /// Subclasses may override this routine to provide different behavior.
606 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
607 ExprArg LHS,
608 SourceLocation EllipsisLoc,
609 ExprArg RHS,
610 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000611 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000612 ColonLoc);
613 }
Mike Stump11289f42009-09-09 15:08:12 +0000614
Douglas Gregorebe10102009-08-20 07:17:43 +0000615 /// \brief Attach the body to a new case statement.
616 ///
617 /// By default, performs semantic analysis to build the new statement.
618 /// Subclasses may override this routine to provide different behavior.
619 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
620 getSema().ActOnCaseStmtBody(S.get(), move(Body));
621 return move(S);
622 }
Mike Stump11289f42009-09-09 15:08:12 +0000623
Douglas Gregorebe10102009-08-20 07:17:43 +0000624 /// \brief Build a new default statement.
625 ///
626 /// By default, performs semantic analysis to build the new statement.
627 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000628 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000629 SourceLocation ColonLoc,
630 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000631 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000632 /*CurScope=*/0);
633 }
Mike Stump11289f42009-09-09 15:08:12 +0000634
Douglas Gregorebe10102009-08-20 07:17:43 +0000635 /// \brief Build a new label statement.
636 ///
637 /// By default, performs semantic analysis to build the new statement.
638 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000639 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000640 IdentifierInfo *Id,
641 SourceLocation ColonLoc,
642 StmtArg SubStmt) {
643 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
644 }
Mike Stump11289f42009-09-09 15:08:12 +0000645
Douglas Gregorebe10102009-08-20 07:17:43 +0000646 /// \brief Build a new "if" statement.
647 ///
648 /// By default, performs semantic analysis to build the new statement.
649 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000650 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
651 StmtArg Then, SourceLocation ElseLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000652 StmtArg Else) {
653 return getSema().ActOnIfStmt(IfLoc, Cond, move(Then), ElseLoc, move(Else));
654 }
Mike Stump11289f42009-09-09 15:08:12 +0000655
Douglas Gregorebe10102009-08-20 07:17:43 +0000656 /// \brief Start building a new switch statement.
657 ///
658 /// By default, performs semantic analysis to build the new statement.
659 /// Subclasses may override this routine to provide different behavior.
660 OwningStmtResult RebuildSwitchStmtStart(ExprArg Cond) {
661 return getSema().ActOnStartOfSwitchStmt(move(Cond));
662 }
Mike Stump11289f42009-09-09 15:08:12 +0000663
Douglas Gregorebe10102009-08-20 07:17:43 +0000664 /// \brief Attach the body to the switch statement.
665 ///
666 /// By default, performs semantic analysis to build the new statement.
667 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000668 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000669 StmtArg Switch, StmtArg Body) {
670 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
671 move(Body));
672 }
673
674 /// \brief Build a new while statement.
675 ///
676 /// By default, performs semantic analysis to build the new statement.
677 /// Subclasses may override this routine to provide different behavior.
678 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
679 Sema::FullExprArg Cond,
680 StmtArg Body) {
681 return getSema().ActOnWhileStmt(WhileLoc, Cond, move(Body));
682 }
Mike Stump11289f42009-09-09 15:08:12 +0000683
Douglas Gregorebe10102009-08-20 07:17:43 +0000684 /// \brief Build a new do-while statement.
685 ///
686 /// By default, performs semantic analysis to build the new statement.
687 /// Subclasses may override this routine to provide different behavior.
688 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
689 SourceLocation WhileLoc,
690 SourceLocation LParenLoc,
691 ExprArg Cond,
692 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000693 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000694 move(Cond), RParenLoc);
695 }
696
697 /// \brief Build a new for statement.
698 ///
699 /// By default, performs semantic analysis to build the new statement.
700 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000701 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000702 SourceLocation LParenLoc,
703 StmtArg Init, ExprArg Cond, ExprArg Inc,
704 SourceLocation RParenLoc, StmtArg Body) {
Mike Stump11289f42009-09-09 15:08:12 +0000705 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), move(Cond),
Douglas Gregorebe10102009-08-20 07:17:43 +0000706 move(Inc), RParenLoc, move(Body));
707 }
Mike Stump11289f42009-09-09 15:08:12 +0000708
Douglas Gregorebe10102009-08-20 07:17:43 +0000709 /// \brief Build a new goto statement.
710 ///
711 /// By default, performs semantic analysis to build the new statement.
712 /// Subclasses may override this routine to provide different behavior.
713 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
714 SourceLocation LabelLoc,
715 LabelStmt *Label) {
716 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
717 }
718
719 /// \brief Build a new indirect goto statement.
720 ///
721 /// By default, performs semantic analysis to build the new statement.
722 /// Subclasses may override this routine to provide different behavior.
723 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
724 SourceLocation StarLoc,
725 ExprArg Target) {
726 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
727 }
Mike Stump11289f42009-09-09 15:08:12 +0000728
Douglas Gregorebe10102009-08-20 07:17:43 +0000729 /// \brief Build a new return statement.
730 ///
731 /// By default, performs semantic analysis to build the new statement.
732 /// Subclasses may override this routine to provide different behavior.
733 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
734 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000735
Douglas Gregorebe10102009-08-20 07:17:43 +0000736 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
737 }
Mike Stump11289f42009-09-09 15:08:12 +0000738
Douglas Gregorebe10102009-08-20 07:17:43 +0000739 /// \brief Build a new declaration statement.
740 ///
741 /// By default, performs semantic analysis to build the new statement.
742 /// Subclasses may override this routine to provide different behavior.
743 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000744 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000745 SourceLocation EndLoc) {
746 return getSema().Owned(
747 new (getSema().Context) DeclStmt(
748 DeclGroupRef::Create(getSema().Context,
749 Decls, NumDecls),
750 StartLoc, EndLoc));
751 }
Mike Stump11289f42009-09-09 15:08:12 +0000752
Douglas Gregorebe10102009-08-20 07:17:43 +0000753 /// \brief Build a new C++ exception declaration.
754 ///
755 /// By default, performs semantic analysis to build the new decaration.
756 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000757 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
Douglas Gregorebe10102009-08-20 07:17:43 +0000758 DeclaratorInfo *Declarator,
759 IdentifierInfo *Name,
760 SourceLocation Loc,
761 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000762 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000763 TypeRange);
764 }
765
766 /// \brief Build a new C++ catch statement.
767 ///
768 /// By default, performs semantic analysis to build the new statement.
769 /// Subclasses may override this routine to provide different behavior.
770 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
771 VarDecl *ExceptionDecl,
772 StmtArg Handler) {
773 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000774 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000775 Handler.takeAs<Stmt>()));
776 }
Mike Stump11289f42009-09-09 15:08:12 +0000777
Douglas Gregorebe10102009-08-20 07:17:43 +0000778 /// \brief Build a new C++ try statement.
779 ///
780 /// By default, performs semantic analysis to build the new statement.
781 /// Subclasses may override this routine to provide different behavior.
782 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
783 StmtArg TryBlock,
784 MultiStmtArg Handlers) {
785 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
786 }
Mike Stump11289f42009-09-09 15:08:12 +0000787
Douglas Gregora16548e2009-08-11 05:31:07 +0000788 /// \brief Build a new expression that references a declaration.
789 ///
790 /// By default, performs semantic analysis to build the new expression.
791 /// Subclasses may override this routine to provide different behavior.
792 OwningExprResult RebuildDeclRefExpr(NamedDecl *ND, SourceLocation Loc) {
793 return getSema().BuildDeclarationNameExpr(Loc, ND,
794 /*FIXME:*/false,
795 /*SS=*/0,
796 /*FIXME:*/false);
797 }
Mike Stump11289f42009-09-09 15:08:12 +0000798
Douglas Gregora16548e2009-08-11 05:31:07 +0000799 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000800 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000801 /// By default, performs semantic analysis to build the new expression.
802 /// Subclasses may override this routine to provide different behavior.
803 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
804 SourceLocation RParen) {
805 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
806 }
807
Douglas Gregorad8a3362009-09-04 17:36:40 +0000808 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000809 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000810 /// By default, performs semantic analysis to build the new expression.
811 /// Subclasses may override this routine to provide different behavior.
812 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
813 SourceLocation OperatorLoc,
814 bool isArrow,
815 SourceLocation DestroyedTypeLoc,
816 QualType DestroyedType,
817 NestedNameSpecifier *Qualifier,
818 SourceRange QualifierRange) {
819 CXXScopeSpec SS;
820 if (Qualifier) {
821 SS.setRange(QualifierRange);
822 SS.setScopeRep(Qualifier);
823 }
824
Mike Stump11289f42009-09-09 15:08:12 +0000825 DeclarationName Name
Douglas Gregorad8a3362009-09-04 17:36:40 +0000826 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
827 SemaRef.Context.getCanonicalType(DestroyedType));
Mike Stump11289f42009-09-09 15:08:12 +0000828
829 return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base),
Douglas Gregorad8a3362009-09-04 17:36:40 +0000830 OperatorLoc,
831 isArrow? tok::arrow : tok::period,
832 DestroyedTypeLoc,
833 Name,
834 Sema::DeclPtrTy::make((Decl *)0),
835 &SS);
Mike Stump11289f42009-09-09 15:08:12 +0000836 }
837
Douglas Gregora16548e2009-08-11 05:31:07 +0000838 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000839 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000840 /// By default, performs semantic analysis to build the new expression.
841 /// Subclasses may override this routine to provide different behavior.
842 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
843 UnaryOperator::Opcode Opc,
844 ExprArg SubExpr) {
845 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(SubExpr));
846 }
Mike Stump11289f42009-09-09 15:08:12 +0000847
Douglas Gregora16548e2009-08-11 05:31:07 +0000848 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000849 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000850 /// By default, performs semantic analysis to build the new expression.
851 /// Subclasses may override this routine to provide different behavior.
852 OwningExprResult RebuildSizeOfAlignOf(QualType T, SourceLocation OpLoc,
853 bool isSizeOf, SourceRange R) {
854 return getSema().CreateSizeOfAlignOfExpr(T, OpLoc, isSizeOf, R);
855 }
856
Mike Stump11289f42009-09-09 15:08:12 +0000857 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000858 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +0000859 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000860 /// By default, performs semantic analysis to build the new expression.
861 /// Subclasses may override this routine to provide different behavior.
862 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
863 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +0000864 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000865 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
866 OpLoc, isSizeOf, R);
867 if (Result.isInvalid())
868 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000869
Douglas Gregora16548e2009-08-11 05:31:07 +0000870 SubExpr.release();
871 return move(Result);
872 }
Mike Stump11289f42009-09-09 15:08:12 +0000873
Douglas Gregora16548e2009-08-11 05:31:07 +0000874 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +0000875 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000876 /// By default, performs semantic analysis to build the new expression.
877 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000878 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000879 SourceLocation LBracketLoc,
880 ExprArg RHS,
881 SourceLocation RBracketLoc) {
882 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000883 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000884 RBracketLoc);
885 }
886
887 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000888 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000889 /// By default, performs semantic analysis to build the new expression.
890 /// Subclasses may override this routine to provide different behavior.
891 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
892 MultiExprArg Args,
893 SourceLocation *CommaLocs,
894 SourceLocation RParenLoc) {
895 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
896 move(Args), CommaLocs, RParenLoc);
897 }
898
899 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000900 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000901 /// By default, performs semantic analysis to build the new expression.
902 /// Subclasses may override this routine to provide different behavior.
903 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000904 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000905 NestedNameSpecifier *Qualifier,
906 SourceRange QualifierRange,
907 SourceLocation MemberLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000908 NamedDecl *Member) {
Anders Carlsson5da84842009-09-01 04:26:58 +0000909 if (!Member->getDeclName()) {
910 // We have a reference to an unnamed field.
911 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +0000912
913 MemberExpr *ME =
Anders Carlsson5da84842009-09-01 04:26:58 +0000914 new (getSema().Context) MemberExpr(Base.takeAs<Expr>(), isArrow,
915 Member, MemberLoc,
916 cast<FieldDecl>(Member)->getType());
917 return getSema().Owned(ME);
918 }
Mike Stump11289f42009-09-09 15:08:12 +0000919
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000920 CXXScopeSpec SS;
921 if (Qualifier) {
922 SS.setRange(QualifierRange);
923 SS.setScopeRep(Qualifier);
924 }
925
Douglas Gregorf14b46f2009-08-31 20:00:26 +0000926 return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000927 isArrow? tok::arrow : tok::period,
928 MemberLoc,
Douglas Gregorf14b46f2009-08-31 20:00:26 +0000929 Member->getDeclName(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000930 /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0),
931 &SS);
Douglas Gregora16548e2009-08-11 05:31:07 +0000932 }
Mike Stump11289f42009-09-09 15:08:12 +0000933
Douglas Gregora16548e2009-08-11 05:31:07 +0000934 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000935 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000936 /// By default, performs semantic analysis to build the new expression.
937 /// Subclasses may override this routine to provide different behavior.
938 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
939 BinaryOperator::Opcode Opc,
940 ExprArg LHS, ExprArg RHS) {
941 OwningExprResult Result
Mike Stump11289f42009-09-09 15:08:12 +0000942 = getSema().CreateBuiltinBinOp(OpLoc, Opc, (Expr *)LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +0000943 (Expr *)RHS.get());
944 if (Result.isInvalid())
945 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000946
Douglas Gregora16548e2009-08-11 05:31:07 +0000947 LHS.release();
948 RHS.release();
949 return move(Result);
950 }
951
952 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000953 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000954 /// By default, performs semantic analysis to build the new expression.
955 /// Subclasses may override this routine to provide different behavior.
956 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
957 SourceLocation QuestionLoc,
958 ExprArg LHS,
959 SourceLocation ColonLoc,
960 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +0000961 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +0000962 move(LHS), move(RHS));
963 }
964
965 /// \brief Build a new implicit cast expression.
Mike Stump11289f42009-09-09 15:08:12 +0000966 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000967 /// By default, builds a new implicit cast without any semantic analysis.
968 /// Subclasses may override this routine to provide different behavior.
969 OwningExprResult RebuildImplicitCastExpr(QualType T, CastExpr::CastKind Kind,
970 ExprArg SubExpr, bool isLvalue) {
971 ImplicitCastExpr *ICE
Mike Stump11289f42009-09-09 15:08:12 +0000972 = new (getSema().Context) ImplicitCastExpr(T, Kind,
Douglas Gregora16548e2009-08-11 05:31:07 +0000973 (Expr *)SubExpr.release(),
974 isLvalue);
975 return getSema().Owned(ICE);
976 }
977
978 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +0000979 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000980 /// By default, performs semantic analysis to build the new expression.
981 /// Subclasses may override this routine to provide different behavior.
982 OwningExprResult RebuildCStyleCaseExpr(SourceLocation LParenLoc,
983 QualType ExplicitTy,
984 SourceLocation RParenLoc,
985 ExprArg SubExpr) {
986 return getSema().ActOnCastExpr(/*Scope=*/0,
987 LParenLoc,
988 ExplicitTy.getAsOpaquePtr(),
989 RParenLoc,
990 move(SubExpr));
991 }
Mike Stump11289f42009-09-09 15:08:12 +0000992
Douglas Gregora16548e2009-08-11 05:31:07 +0000993 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +0000994 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000995 /// By default, performs semantic analysis to build the new expression.
996 /// Subclasses may override this routine to provide different behavior.
997 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
998 QualType T,
999 SourceLocation RParenLoc,
1000 ExprArg Init) {
1001 return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(),
1002 RParenLoc, move(Init));
1003 }
Mike Stump11289f42009-09-09 15:08:12 +00001004
Douglas Gregora16548e2009-08-11 05:31:07 +00001005 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001006 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001007 /// By default, performs semantic analysis to build the new expression.
1008 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001009 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001010 SourceLocation OpLoc,
1011 SourceLocation AccessorLoc,
1012 IdentifierInfo &Accessor) {
1013 return getSema().ActOnMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc,
1014 tok::period, AccessorLoc,
1015 Accessor,
1016 /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0));
1017 }
Mike Stump11289f42009-09-09 15:08:12 +00001018
Douglas Gregora16548e2009-08-11 05:31:07 +00001019 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001020 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001021 /// By default, performs semantic analysis to build the new expression.
1022 /// Subclasses may override this routine to provide different behavior.
1023 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1024 MultiExprArg Inits,
1025 SourceLocation RBraceLoc) {
1026 return SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1027 }
Mike Stump11289f42009-09-09 15:08:12 +00001028
Douglas Gregora16548e2009-08-11 05:31:07 +00001029 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001030 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001031 /// By default, performs semantic analysis to build the new expression.
1032 /// Subclasses may override this routine to provide different behavior.
1033 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1034 MultiExprArg ArrayExprs,
1035 SourceLocation EqualOrColonLoc,
1036 bool GNUSyntax,
1037 ExprArg Init) {
1038 OwningExprResult Result
1039 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1040 move(Init));
1041 if (Result.isInvalid())
1042 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001043
Douglas Gregora16548e2009-08-11 05:31:07 +00001044 ArrayExprs.release();
1045 return move(Result);
1046 }
Mike Stump11289f42009-09-09 15:08:12 +00001047
Douglas Gregora16548e2009-08-11 05:31:07 +00001048 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001049 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001050 /// By default, builds the implicit value initialization without performing
1051 /// any semantic analysis. Subclasses may override this routine to provide
1052 /// different behavior.
1053 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1054 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1055 }
Mike Stump11289f42009-09-09 15:08:12 +00001056
Douglas Gregora16548e2009-08-11 05:31:07 +00001057 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001058 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001059 /// By default, performs semantic analysis to build the new expression.
1060 /// Subclasses may override this routine to provide different behavior.
1061 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1062 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001063 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001064 RParenLoc);
1065 }
1066
1067 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001068 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001069 /// By default, performs semantic analysis to build the new expression.
1070 /// Subclasses may override this routine to provide different behavior.
1071 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1072 MultiExprArg SubExprs,
1073 SourceLocation RParenLoc) {
1074 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
1075 }
Mike Stump11289f42009-09-09 15:08:12 +00001076
Douglas Gregora16548e2009-08-11 05:31:07 +00001077 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001078 ///
1079 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001080 /// rather than attempting to map the label statement itself.
1081 /// Subclasses may override this routine to provide different behavior.
1082 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1083 SourceLocation LabelLoc,
1084 LabelStmt *Label) {
1085 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1086 }
Mike Stump11289f42009-09-09 15:08:12 +00001087
Douglas Gregora16548e2009-08-11 05:31:07 +00001088 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001089 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001090 /// By default, performs semantic analysis to build the new expression.
1091 /// Subclasses may override this routine to provide different behavior.
1092 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1093 StmtArg SubStmt,
1094 SourceLocation RParenLoc) {
1095 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1096 }
Mike Stump11289f42009-09-09 15:08:12 +00001097
Douglas Gregora16548e2009-08-11 05:31:07 +00001098 /// \brief Build a new __builtin_types_compatible_p expression.
1099 ///
1100 /// By default, performs semantic analysis to build the new expression.
1101 /// Subclasses may override this routine to provide different behavior.
1102 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1103 QualType T1, QualType T2,
1104 SourceLocation RParenLoc) {
1105 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1106 T1.getAsOpaquePtr(),
1107 T2.getAsOpaquePtr(),
1108 RParenLoc);
1109 }
Mike Stump11289f42009-09-09 15:08:12 +00001110
Douglas Gregora16548e2009-08-11 05:31:07 +00001111 /// \brief Build a new __builtin_choose_expr expression.
1112 ///
1113 /// By default, performs semantic analysis to build the new expression.
1114 /// Subclasses may override this routine to provide different behavior.
1115 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1116 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1117 SourceLocation RParenLoc) {
1118 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1119 move(Cond), move(LHS), move(RHS),
1120 RParenLoc);
1121 }
Mike Stump11289f42009-09-09 15:08:12 +00001122
Douglas Gregora16548e2009-08-11 05:31:07 +00001123 /// \brief Build a new overloaded operator call expression.
1124 ///
1125 /// By default, performs semantic analysis to build the new expression.
1126 /// The semantic analysis provides the behavior of template instantiation,
1127 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001128 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001129 /// argument-dependent lookup, etc. Subclasses may override this routine to
1130 /// provide different behavior.
1131 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1132 SourceLocation OpLoc,
1133 ExprArg Callee,
1134 ExprArg First,
1135 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001136
1137 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001138 /// reinterpret_cast.
1139 ///
1140 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001141 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001142 /// Subclasses may override this routine to provide different behavior.
1143 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1144 Stmt::StmtClass Class,
1145 SourceLocation LAngleLoc,
1146 QualType T,
1147 SourceLocation RAngleLoc,
1148 SourceLocation LParenLoc,
1149 ExprArg SubExpr,
1150 SourceLocation RParenLoc) {
1151 switch (Class) {
1152 case Stmt::CXXStaticCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001153 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T,
1154 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001155 move(SubExpr), RParenLoc);
1156
1157 case Stmt::CXXDynamicCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001158 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T,
1159 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001160 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001161
Douglas Gregora16548e2009-08-11 05:31:07 +00001162 case Stmt::CXXReinterpretCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001163 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T,
1164 RAngleLoc, LParenLoc,
1165 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001166 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001167
Douglas Gregora16548e2009-08-11 05:31:07 +00001168 case Stmt::CXXConstCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001169 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T,
1170 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001171 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001172
Douglas Gregora16548e2009-08-11 05:31:07 +00001173 default:
1174 assert(false && "Invalid C++ named cast");
1175 break;
1176 }
Mike Stump11289f42009-09-09 15:08:12 +00001177
Douglas Gregora16548e2009-08-11 05:31:07 +00001178 return getSema().ExprError();
1179 }
Mike Stump11289f42009-09-09 15:08:12 +00001180
Douglas Gregora16548e2009-08-11 05:31:07 +00001181 /// \brief Build a new C++ static_cast expression.
1182 ///
1183 /// By default, performs semantic analysis to build the new expression.
1184 /// Subclasses may override this routine to provide different behavior.
1185 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1186 SourceLocation LAngleLoc,
1187 QualType T,
1188 SourceLocation RAngleLoc,
1189 SourceLocation LParenLoc,
1190 ExprArg SubExpr,
1191 SourceLocation RParenLoc) {
1192 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001193 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001194 LParenLoc, move(SubExpr), RParenLoc);
1195 }
1196
1197 /// \brief Build a new C++ dynamic_cast expression.
1198 ///
1199 /// By default, performs semantic analysis to build the new expression.
1200 /// Subclasses may override this routine to provide different behavior.
1201 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1202 SourceLocation LAngleLoc,
1203 QualType T,
1204 SourceLocation RAngleLoc,
1205 SourceLocation LParenLoc,
1206 ExprArg SubExpr,
1207 SourceLocation RParenLoc) {
1208 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001209 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001210 LParenLoc, move(SubExpr), RParenLoc);
1211 }
1212
1213 /// \brief Build a new C++ reinterpret_cast expression.
1214 ///
1215 /// By default, performs semantic analysis to build the new expression.
1216 /// Subclasses may override this routine to provide different behavior.
1217 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1218 SourceLocation LAngleLoc,
1219 QualType T,
1220 SourceLocation RAngleLoc,
1221 SourceLocation LParenLoc,
1222 ExprArg SubExpr,
1223 SourceLocation RParenLoc) {
1224 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1225 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
1226 LParenLoc, move(SubExpr), RParenLoc);
1227 }
1228
1229 /// \brief Build a new C++ const_cast expression.
1230 ///
1231 /// By default, performs semantic analysis to build the new expression.
1232 /// Subclasses may override this routine to provide different behavior.
1233 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1234 SourceLocation LAngleLoc,
1235 QualType T,
1236 SourceLocation RAngleLoc,
1237 SourceLocation LParenLoc,
1238 ExprArg SubExpr,
1239 SourceLocation RParenLoc) {
1240 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001241 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001242 LParenLoc, move(SubExpr), RParenLoc);
1243 }
Mike Stump11289f42009-09-09 15:08:12 +00001244
Douglas Gregora16548e2009-08-11 05:31:07 +00001245 /// \brief Build a new C++ functional-style cast expression.
1246 ///
1247 /// By default, performs semantic analysis to build the new expression.
1248 /// Subclasses may override this routine to provide different behavior.
1249 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
1250 QualType T,
1251 SourceLocation LParenLoc,
1252 ExprArg SubExpr,
1253 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001254 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001255 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
1256 T.getAsOpaquePtr(),
1257 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001258 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001259 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001260 RParenLoc);
1261 }
Mike Stump11289f42009-09-09 15:08:12 +00001262
Douglas Gregora16548e2009-08-11 05:31:07 +00001263 /// \brief Build a new C++ typeid(type) expression.
1264 ///
1265 /// By default, performs semantic analysis to build the new expression.
1266 /// Subclasses may override this routine to provide different behavior.
1267 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1268 SourceLocation LParenLoc,
1269 QualType T,
1270 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001271 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001272 T.getAsOpaquePtr(), RParenLoc);
1273 }
Mike Stump11289f42009-09-09 15:08:12 +00001274
Douglas Gregora16548e2009-08-11 05:31:07 +00001275 /// \brief Build a new C++ typeid(expr) expression.
1276 ///
1277 /// By default, performs semantic analysis to build the new expression.
1278 /// Subclasses may override this routine to provide different behavior.
1279 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1280 SourceLocation LParenLoc,
1281 ExprArg Operand,
1282 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001283 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001284 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1285 RParenLoc);
1286 if (Result.isInvalid())
1287 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001288
Douglas Gregora16548e2009-08-11 05:31:07 +00001289 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1290 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001291 }
1292
Douglas Gregora16548e2009-08-11 05:31:07 +00001293 /// \brief Build a new C++ "this" expression.
1294 ///
1295 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001296 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001297 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001298 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001299 QualType ThisType) {
1300 return getSema().Owned(
1301 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType));
1302 }
1303
1304 /// \brief Build a new C++ throw expression.
1305 ///
1306 /// By default, performs semantic analysis to build the new expression.
1307 /// Subclasses may override this routine to provide different behavior.
1308 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1309 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1310 }
1311
1312 /// \brief Build a new C++ default-argument expression.
1313 ///
1314 /// By default, builds a new default-argument expression, which does not
1315 /// require any semantic analysis. Subclasses may override this routine to
1316 /// provide different behavior.
1317 OwningExprResult RebuildCXXDefaultArgExpr(ParmVarDecl *Param) {
Anders Carlssone8271232009-08-14 18:30:22 +00001318 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 }
1320
1321 /// \brief Build a new C++ zero-initialization expression.
1322 ///
1323 /// By default, performs semantic analysis to build the new expression.
1324 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001325 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 SourceLocation LParenLoc,
1327 QualType T,
1328 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001329 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1330 T.getAsOpaquePtr(), LParenLoc,
1331 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 0, RParenLoc);
1333 }
Mike Stump11289f42009-09-09 15:08:12 +00001334
Douglas Gregora16548e2009-08-11 05:31:07 +00001335 /// \brief Build a new C++ conditional declaration expression.
1336 ///
1337 /// By default, performs semantic analysis to build the new expression.
1338 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001339 OwningExprResult RebuildCXXConditionDeclExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 SourceLocation EqLoc,
1341 VarDecl *Var) {
1342 return SemaRef.Owned(new (SemaRef.Context) CXXConditionDeclExpr(StartLoc,
1343 EqLoc,
1344 Var));
1345 }
Mike Stump11289f42009-09-09 15:08:12 +00001346
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 /// \brief Build a new C++ "new" expression.
1348 ///
1349 /// By default, performs semantic analysis to build the new expression.
1350 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001351 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001352 bool UseGlobal,
1353 SourceLocation PlacementLParen,
1354 MultiExprArg PlacementArgs,
1355 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001356 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001357 QualType AllocType,
1358 SourceLocation TypeLoc,
1359 SourceRange TypeRange,
1360 ExprArg ArraySize,
1361 SourceLocation ConstructorLParen,
1362 MultiExprArg ConstructorArgs,
1363 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001364 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 PlacementLParen,
1366 move(PlacementArgs),
1367 PlacementRParen,
1368 ParenTypeId,
1369 AllocType,
1370 TypeLoc,
1371 TypeRange,
1372 move(ArraySize),
1373 ConstructorLParen,
1374 move(ConstructorArgs),
1375 ConstructorRParen);
1376 }
Mike Stump11289f42009-09-09 15:08:12 +00001377
Douglas Gregora16548e2009-08-11 05:31:07 +00001378 /// \brief Build a new C++ "delete" expression.
1379 ///
1380 /// By default, performs semantic analysis to build the new expression.
1381 /// Subclasses may override this routine to provide different behavior.
1382 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1383 bool IsGlobalDelete,
1384 bool IsArrayForm,
1385 ExprArg Operand) {
1386 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1387 move(Operand));
1388 }
Mike Stump11289f42009-09-09 15:08:12 +00001389
Douglas Gregora16548e2009-08-11 05:31:07 +00001390 /// \brief Build a new unary type trait expression.
1391 ///
1392 /// By default, performs semantic analysis to build the new expression.
1393 /// Subclasses may override this routine to provide different behavior.
1394 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1395 SourceLocation StartLoc,
1396 SourceLocation LParenLoc,
1397 QualType T,
1398 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001399 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001400 T.getAsOpaquePtr(), RParenLoc);
1401 }
1402
1403 /// \brief Build a new qualified declaration reference expression.
1404 ///
1405 /// By default, performs semantic analysis to build the new expression.
1406 /// Subclasses may override this routine to provide different behavior.
1407 OwningExprResult RebuildQualifiedDeclRefExpr(NestedNameSpecifier *NNS,
1408 SourceRange QualifierRange,
1409 NamedDecl *ND,
1410 SourceLocation Location,
1411 bool IsAddressOfOperand) {
1412 CXXScopeSpec SS;
1413 SS.setRange(QualifierRange);
1414 SS.setScopeRep(NNS);
Mike Stump11289f42009-09-09 15:08:12 +00001415 return getSema().ActOnDeclarationNameExpr(/*Scope=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001416 Location,
1417 ND->getDeclName(),
1418 /*Trailing lparen=*/false,
1419 &SS,
1420 IsAddressOfOperand);
1421 }
1422
Mike Stump11289f42009-09-09 15:08:12 +00001423 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001424 /// expression.
1425 ///
1426 /// By default, performs semantic analysis to build the new expression.
1427 /// Subclasses may override this routine to provide different behavior.
1428 OwningExprResult RebuildUnresolvedDeclRefExpr(NestedNameSpecifier *NNS,
1429 SourceRange QualifierRange,
1430 DeclarationName Name,
1431 SourceLocation Location,
1432 bool IsAddressOfOperand) {
1433 CXXScopeSpec SS;
1434 SS.setRange(QualifierRange);
1435 SS.setScopeRep(NNS);
Mike Stump11289f42009-09-09 15:08:12 +00001436 return getSema().ActOnDeclarationNameExpr(/*Scope=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001437 Location,
1438 Name,
1439 /*Trailing lparen=*/false,
1440 &SS,
1441 IsAddressOfOperand);
1442 }
1443
1444 /// \brief Build a new template-id expression.
1445 ///
1446 /// By default, performs semantic analysis to build the new expression.
1447 /// Subclasses may override this routine to provide different behavior.
1448 OwningExprResult RebuildTemplateIdExpr(TemplateName Template,
1449 SourceLocation TemplateLoc,
1450 SourceLocation LAngleLoc,
1451 TemplateArgument *TemplateArgs,
1452 unsigned NumTemplateArgs,
1453 SourceLocation RAngleLoc) {
1454 return getSema().BuildTemplateIdExpr(Template, TemplateLoc,
1455 LAngleLoc,
1456 TemplateArgs, NumTemplateArgs,
1457 RAngleLoc);
1458 }
1459
1460 /// \brief Build a new object-construction expression.
1461 ///
1462 /// By default, performs semantic analysis to build the new expression.
1463 /// Subclasses may override this routine to provide different behavior.
1464 OwningExprResult RebuildCXXConstructExpr(QualType T,
1465 CXXConstructorDecl *Constructor,
1466 bool IsElidable,
1467 MultiExprArg Args) {
Anders Carlsson1b4ebfa2009-09-05 07:40:38 +00001468 return getSema().BuildCXXConstructExpr(/*FIXME:ConstructLoc*/
1469 SourceLocation(),
1470 T, Constructor, IsElidable,
Anders Carlsson5995a3e2009-09-07 22:23:31 +00001471 move(Args));
Douglas Gregora16548e2009-08-11 05:31:07 +00001472 }
1473
1474 /// \brief Build a new object-construction expression.
1475 ///
1476 /// By default, performs semantic analysis to build the new expression.
1477 /// Subclasses may override this routine to provide different behavior.
1478 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1479 QualType T,
1480 SourceLocation LParenLoc,
1481 MultiExprArg Args,
1482 SourceLocation *Commas,
1483 SourceLocation RParenLoc) {
1484 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1485 T.getAsOpaquePtr(),
1486 LParenLoc,
1487 move(Args),
1488 Commas,
1489 RParenLoc);
1490 }
1491
1492 /// \brief Build a new object-construction expression.
1493 ///
1494 /// By default, performs semantic analysis to build the new expression.
1495 /// Subclasses may override this routine to provide different behavior.
1496 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1497 QualType T,
1498 SourceLocation LParenLoc,
1499 MultiExprArg Args,
1500 SourceLocation *Commas,
1501 SourceLocation RParenLoc) {
1502 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1503 /*FIXME*/LParenLoc),
1504 T.getAsOpaquePtr(),
1505 LParenLoc,
1506 move(Args),
1507 Commas,
1508 RParenLoc);
1509 }
Mike Stump11289f42009-09-09 15:08:12 +00001510
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 /// \brief Build a new member reference expression.
1512 ///
1513 /// By default, performs semantic analysis to build the new expression.
1514 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2168a9f2009-08-11 15:56:57 +00001515 OwningExprResult RebuildCXXUnresolvedMemberExpr(ExprArg BaseE,
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 bool IsArrow,
1517 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001518 NestedNameSpecifier *Qualifier,
1519 SourceRange QualifierRange,
Douglas Gregora16548e2009-08-11 05:31:07 +00001520 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001521 SourceLocation MemberLoc,
1522 NamedDecl *FirstQualifierInScope) {
Douglas Gregor2168a9f2009-08-11 15:56:57 +00001523 OwningExprResult Base = move(BaseE);
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001525
Douglas Gregora16548e2009-08-11 05:31:07 +00001526 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001527 SS.setRange(QualifierRange);
1528 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001529
Douglas Gregor308047d2009-09-09 00:23:06 +00001530 return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001531 move(Base), OperatorLoc, OpKind,
Douglas Gregorf14b46f2009-08-31 20:00:26 +00001532 MemberLoc,
1533 Name,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001534 /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001535 &SS,
1536 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00001537 }
1538
Douglas Gregor308047d2009-09-09 00:23:06 +00001539 /// \brief Build a new member reference expression with explicit template
1540 /// arguments.
1541 ///
1542 /// By default, performs semantic analysis to build the new expression.
1543 /// Subclasses may override this routine to provide different behavior.
1544 OwningExprResult RebuildCXXUnresolvedMemberExpr(ExprArg BaseE,
1545 bool IsArrow,
1546 SourceLocation OperatorLoc,
1547 NestedNameSpecifier *Qualifier,
1548 SourceRange QualifierRange,
1549 TemplateName Template,
1550 SourceLocation TemplateNameLoc,
1551 NamedDecl *FirstQualifierInScope,
1552 SourceLocation LAngleLoc,
1553 const TemplateArgument *TemplateArgs,
1554 unsigned NumTemplateArgs,
1555 SourceLocation RAngleLoc) {
1556 OwningExprResult Base = move(BaseE);
1557 tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period;
Mike Stump11289f42009-09-09 15:08:12 +00001558
Douglas Gregor308047d2009-09-09 00:23:06 +00001559 CXXScopeSpec SS;
1560 SS.setRange(QualifierRange);
1561 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001562
Douglas Gregor308047d2009-09-09 00:23:06 +00001563 // FIXME: We're going to end up looking up the template based on its name,
1564 // twice! Also, duplicates part of Sema::ActOnMemberTemplateIdReferenceExpr.
1565 DeclarationName Name;
1566 if (TemplateDecl *ActualTemplate = Template.getAsTemplateDecl())
1567 Name = ActualTemplate->getDeclName();
Mike Stump11289f42009-09-09 15:08:12 +00001568 else if (OverloadedFunctionDecl *Ovl
Douglas Gregor308047d2009-09-09 00:23:06 +00001569 = Template.getAsOverloadedFunctionDecl())
1570 Name = Ovl->getDeclName();
1571 else
1572 Name = Template.getAsDependentTemplateName()->getName();
Mike Stump11289f42009-09-09 15:08:12 +00001573
1574 return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0, move(Base),
Douglas Gregor308047d2009-09-09 00:23:06 +00001575 OperatorLoc, OpKind,
1576 TemplateNameLoc, Name, true,
1577 LAngleLoc, TemplateArgs,
1578 NumTemplateArgs, RAngleLoc,
1579 Sema::DeclPtrTy(), &SS);
1580 }
Mike Stump11289f42009-09-09 15:08:12 +00001581
Douglas Gregora16548e2009-08-11 05:31:07 +00001582 /// \brief Build a new Objective-C @encode expression.
1583 ///
1584 /// By default, performs semantic analysis to build the new expression.
1585 /// Subclasses may override this routine to provide different behavior.
1586 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1587 QualType T,
1588 SourceLocation RParenLoc) {
1589 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1590 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001591 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001592
1593 /// \brief Build a new Objective-C protocol expression.
1594 ///
1595 /// By default, performs semantic analysis to build the new expression.
1596 /// Subclasses may override this routine to provide different behavior.
1597 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1598 SourceLocation AtLoc,
1599 SourceLocation ProtoLoc,
1600 SourceLocation LParenLoc,
1601 SourceLocation RParenLoc) {
1602 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1603 Protocol->getIdentifier(),
1604 AtLoc,
1605 ProtoLoc,
1606 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001607 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 }
Mike Stump11289f42009-09-09 15:08:12 +00001609
Douglas Gregora16548e2009-08-11 05:31:07 +00001610 /// \brief Build a new shuffle vector expression.
1611 ///
1612 /// By default, performs semantic analysis to build the new expression.
1613 /// Subclasses may override this routine to provide different behavior.
1614 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1615 MultiExprArg SubExprs,
1616 SourceLocation RParenLoc) {
1617 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001618 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1620 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1621 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1622 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001623
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 // Build a reference to the __builtin_shufflevector builtin
1625 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001626 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001627 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
1628 BuiltinLoc, false, false);
1629 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001630
1631 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 unsigned NumSubExprs = SubExprs.size();
1633 Expr **Subs = (Expr **)SubExprs.release();
1634 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1635 Subs, NumSubExprs,
1636 Builtin->getResultType(),
1637 RParenLoc);
1638 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001639
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 // Type-check the __builtin_shufflevector expression.
1641 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1642 if (Result.isInvalid())
1643 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001644
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001646 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001648};
Douglas Gregora16548e2009-08-11 05:31:07 +00001649
Douglas Gregorebe10102009-08-20 07:17:43 +00001650template<typename Derived>
1651Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1652 if (!S)
1653 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001654
Douglas Gregorebe10102009-08-20 07:17:43 +00001655 switch (S->getStmtClass()) {
1656 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001657
Douglas Gregorebe10102009-08-20 07:17:43 +00001658 // Transform individual statement nodes
1659#define STMT(Node, Parent) \
1660 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1661#define EXPR(Node, Parent)
1662#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001663
Douglas Gregorebe10102009-08-20 07:17:43 +00001664 // Transform expressions by calling TransformExpr.
1665#define STMT(Node, Parent)
1666#define EXPR(Node, Parent) case Stmt::Node##Class:
1667#include "clang/AST/StmtNodes.def"
1668 {
1669 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1670 if (E.isInvalid())
1671 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001672
Douglas Gregorebe10102009-08-20 07:17:43 +00001673 return getSema().Owned(E.takeAs<Stmt>());
1674 }
Mike Stump11289f42009-09-09 15:08:12 +00001675 }
1676
Douglas Gregorebe10102009-08-20 07:17:43 +00001677 return SemaRef.Owned(S->Retain());
1678}
Mike Stump11289f42009-09-09 15:08:12 +00001679
1680
Douglas Gregore922c772009-08-04 22:27:00 +00001681template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00001682Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E,
1683 bool isAddressOfOperand) {
1684 if (!E)
1685 return SemaRef.Owned(E);
1686
1687 switch (E->getStmtClass()) {
1688 case Stmt::NoStmtClass: break;
1689#define STMT(Node, Parent) case Stmt::Node##Class: break;
1690#define EXPR(Node, Parent) \
1691 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
1692#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001693 }
1694
Douglas Gregora16548e2009-08-11 05:31:07 +00001695 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001696}
1697
1698template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001699NestedNameSpecifier *
1700TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001701 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001702 QualType ObjectType,
1703 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001704 if (!NNS)
1705 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001706
Douglas Gregorebe10102009-08-20 07:17:43 +00001707 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001708 NestedNameSpecifier *Prefix = NNS->getPrefix();
1709 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001710 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001711 ObjectType,
1712 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001713 if (!Prefix)
1714 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001715
1716 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001717 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001718 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001719 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001720 }
Mike Stump11289f42009-09-09 15:08:12 +00001721
Douglas Gregor1135c352009-08-06 05:28:30 +00001722 switch (NNS->getKind()) {
1723 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001724 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001725 "Identifier nested-name-specifier with no prefix or object type");
1726 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1727 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001728 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001729
1730 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001731 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001732 ObjectType,
1733 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001734
Douglas Gregor1135c352009-08-06 05:28:30 +00001735 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001736 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001737 = cast_or_null<NamespaceDecl>(
1738 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001739 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001740 Prefix == NNS->getPrefix() &&
1741 NS == NNS->getAsNamespace())
1742 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001743
Douglas Gregor1135c352009-08-06 05:28:30 +00001744 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1745 }
Mike Stump11289f42009-09-09 15:08:12 +00001746
Douglas Gregor1135c352009-08-06 05:28:30 +00001747 case NestedNameSpecifier::Global:
1748 // There is no meaningful transformation that one could perform on the
1749 // global scope.
1750 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001751
Douglas Gregor1135c352009-08-06 05:28:30 +00001752 case NestedNameSpecifier::TypeSpecWithTemplate:
1753 case NestedNameSpecifier::TypeSpec: {
1754 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001755 if (T.isNull())
1756 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001757
Douglas Gregor1135c352009-08-06 05:28:30 +00001758 if (!getDerived().AlwaysRebuild() &&
1759 Prefix == NNS->getPrefix() &&
1760 T == QualType(NNS->getAsType(), 0))
1761 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001762
1763 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1764 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregor1135c352009-08-06 05:28:30 +00001765 T);
1766 }
1767 }
Mike Stump11289f42009-09-09 15:08:12 +00001768
Douglas Gregor1135c352009-08-06 05:28:30 +00001769 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001770 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001771}
1772
1773template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001774DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001775TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001776 SourceLocation Loc,
1777 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001778 if (!Name)
1779 return Name;
1780
1781 switch (Name.getNameKind()) {
1782 case DeclarationName::Identifier:
1783 case DeclarationName::ObjCZeroArgSelector:
1784 case DeclarationName::ObjCOneArgSelector:
1785 case DeclarationName::ObjCMultiArgSelector:
1786 case DeclarationName::CXXOperatorName:
1787 case DeclarationName::CXXUsingDirective:
1788 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001789
Douglas Gregorf816bd72009-09-03 22:13:48 +00001790 case DeclarationName::CXXConstructorName:
1791 case DeclarationName::CXXDestructorName:
1792 case DeclarationName::CXXConversionFunctionName: {
1793 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorc59e5612009-10-19 22:04:39 +00001794 QualType T;
1795 if (!ObjectType.isNull() &&
1796 isa<TemplateSpecializationType>(Name.getCXXNameType())) {
1797 TemplateSpecializationType *SpecType
1798 = cast<TemplateSpecializationType>(Name.getCXXNameType());
1799 T = TransformTemplateSpecializationType(SpecType, ObjectType);
1800 } else
1801 T = getDerived().TransformType(Name.getCXXNameType());
Douglas Gregorf816bd72009-09-03 22:13:48 +00001802 if (T.isNull())
1803 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001804
Douglas Gregorf816bd72009-09-03 22:13:48 +00001805 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001806 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001807 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001808 }
Mike Stump11289f42009-09-09 15:08:12 +00001809 }
1810
Douglas Gregorf816bd72009-09-03 22:13:48 +00001811 return DeclarationName();
1812}
1813
1814template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001815TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001816TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1817 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00001818 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001819 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001820 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1821 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1822 if (!NNS)
1823 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001824
Douglas Gregor71dc5092009-08-06 06:41:21 +00001825 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001826 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001827 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1828 if (!TransTemplate)
1829 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001830
Douglas Gregor71dc5092009-08-06 06:41:21 +00001831 if (!getDerived().AlwaysRebuild() &&
1832 NNS == QTN->getQualifier() &&
1833 TransTemplate == Template)
1834 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001835
Douglas Gregor71dc5092009-08-06 06:41:21 +00001836 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1837 TransTemplate);
1838 }
Mike Stump11289f42009-09-09 15:08:12 +00001839
Douglas Gregor71dc5092009-08-06 06:41:21 +00001840 OverloadedFunctionDecl *Ovl = QTN->getOverloadedFunctionDecl();
1841 assert(Ovl && "Not a template name or an overload set?");
Mike Stump11289f42009-09-09 15:08:12 +00001842 OverloadedFunctionDecl *TransOvl
Douglas Gregor71dc5092009-08-06 06:41:21 +00001843 = cast_or_null<OverloadedFunctionDecl>(getDerived().TransformDecl(Ovl));
1844 if (!TransOvl)
1845 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001846
Douglas Gregor71dc5092009-08-06 06:41:21 +00001847 if (!getDerived().AlwaysRebuild() &&
1848 NNS == QTN->getQualifier() &&
1849 TransOvl == Ovl)
1850 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001851
Douglas Gregor71dc5092009-08-06 06:41:21 +00001852 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1853 TransOvl);
1854 }
Mike Stump11289f42009-09-09 15:08:12 +00001855
Douglas Gregor71dc5092009-08-06 06:41:21 +00001856 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001857 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001858 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1859 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor308047d2009-09-09 00:23:06 +00001860 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001861 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001862
Douglas Gregor71dc5092009-08-06 06:41:21 +00001863 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001864 NNS == DTN->getQualifier() &&
1865 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001866 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001867
Douglas Gregor308047d2009-09-09 00:23:06 +00001868 return getDerived().RebuildTemplateName(NNS, *DTN->getName(), ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001869 }
Mike Stump11289f42009-09-09 15:08:12 +00001870
Douglas Gregor71dc5092009-08-06 06:41:21 +00001871 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001872 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001873 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1874 if (!TransTemplate)
1875 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001876
Douglas Gregor71dc5092009-08-06 06:41:21 +00001877 if (!getDerived().AlwaysRebuild() &&
1878 TransTemplate == Template)
1879 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001880
Douglas Gregor71dc5092009-08-06 06:41:21 +00001881 return TemplateName(TransTemplate);
1882 }
Mike Stump11289f42009-09-09 15:08:12 +00001883
Douglas Gregor71dc5092009-08-06 06:41:21 +00001884 OverloadedFunctionDecl *Ovl = Name.getAsOverloadedFunctionDecl();
1885 assert(Ovl && "Not a template name or an overload set?");
Mike Stump11289f42009-09-09 15:08:12 +00001886 OverloadedFunctionDecl *TransOvl
Douglas Gregor71dc5092009-08-06 06:41:21 +00001887 = cast_or_null<OverloadedFunctionDecl>(getDerived().TransformDecl(Ovl));
1888 if (!TransOvl)
1889 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001890
Douglas Gregor71dc5092009-08-06 06:41:21 +00001891 if (!getDerived().AlwaysRebuild() &&
1892 TransOvl == Ovl)
1893 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001894
Douglas Gregor71dc5092009-08-06 06:41:21 +00001895 return TemplateName(TransOvl);
1896}
1897
1898template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001899TemplateArgument
Douglas Gregore922c772009-08-04 22:27:00 +00001900TreeTransform<Derived>::TransformTemplateArgument(const TemplateArgument &Arg) {
1901 switch (Arg.getKind()) {
1902 case TemplateArgument::Null:
1903 case TemplateArgument::Integral:
1904 return Arg;
Mike Stump11289f42009-09-09 15:08:12 +00001905
Douglas Gregore922c772009-08-04 22:27:00 +00001906 case TemplateArgument::Type: {
1907 QualType T = getDerived().TransformType(Arg.getAsType());
1908 if (T.isNull())
1909 return TemplateArgument();
1910 return TemplateArgument(Arg.getLocation(), T);
1911 }
Mike Stump11289f42009-09-09 15:08:12 +00001912
Douglas Gregore922c772009-08-04 22:27:00 +00001913 case TemplateArgument::Declaration: {
1914 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
1915 if (!D)
1916 return TemplateArgument();
1917 return TemplateArgument(Arg.getLocation(), D);
1918 }
Mike Stump11289f42009-09-09 15:08:12 +00001919
Douglas Gregore922c772009-08-04 22:27:00 +00001920 case TemplateArgument::Expression: {
1921 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00001922 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00001923 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00001924
Douglas Gregore922c772009-08-04 22:27:00 +00001925 Sema::OwningExprResult E = getDerived().TransformExpr(Arg.getAsExpr());
1926 if (E.isInvalid())
1927 return TemplateArgument();
1928 return TemplateArgument(E.takeAs<Expr>());
1929 }
Mike Stump11289f42009-09-09 15:08:12 +00001930
Douglas Gregore922c772009-08-04 22:27:00 +00001931 case TemplateArgument::Pack: {
1932 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
1933 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00001934 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00001935 AEnd = Arg.pack_end();
1936 A != AEnd; ++A) {
1937 TemplateArgument TA = getDerived().TransformTemplateArgument(*A);
1938 if (TA.isNull())
1939 return TA;
Mike Stump11289f42009-09-09 15:08:12 +00001940
Douglas Gregore922c772009-08-04 22:27:00 +00001941 TransformedArgs.push_back(TA);
1942 }
1943 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00001944 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00001945 true);
1946 return Result;
1947 }
1948 }
Mike Stump11289f42009-09-09 15:08:12 +00001949
Douglas Gregore922c772009-08-04 22:27:00 +00001950 // Work around bogus GCC warning
1951 return TemplateArgument();
1952}
1953
Douglas Gregord6ff3322009-08-04 16:50:30 +00001954//===----------------------------------------------------------------------===//
1955// Type transformation
1956//===----------------------------------------------------------------------===//
1957
1958template<typename Derived>
1959QualType TreeTransform<Derived>::TransformType(QualType T) {
1960 if (getDerived().AlreadyTransformed(T))
1961 return T;
Mike Stump11289f42009-09-09 15:08:12 +00001962
John McCall550e0c22009-10-21 00:40:46 +00001963 // Temporary workaround. All of these transformations should
1964 // eventually turn into transformations on TypeLocs.
1965 DeclaratorInfo *DI = getSema().Context.CreateDeclaratorInfo(T);
John McCallde889892009-10-21 00:44:26 +00001966 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00001967
1968 DeclaratorInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00001969
John McCall550e0c22009-10-21 00:40:46 +00001970 if (!NewDI)
1971 return QualType();
1972
1973 return NewDI->getType();
1974}
1975
1976template<typename Derived>
1977DeclaratorInfo *TreeTransform<Derived>::TransformType(DeclaratorInfo *DI) {
1978 if (getDerived().AlreadyTransformed(DI->getType()))
1979 return DI;
1980
1981 TypeLocBuilder TLB;
1982
1983 TypeLoc TL = DI->getTypeLoc();
1984 TLB.reserve(TL.getFullDataSize());
1985
1986 QualType Result = getDerived().TransformType(TLB, TL);
1987 if (Result.isNull())
1988 return 0;
1989
1990 return TLB.getDeclaratorInfo(SemaRef.Context, Result);
1991}
1992
1993template<typename Derived>
1994QualType
1995TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
1996 switch (T.getTypeLocClass()) {
1997#define ABSTRACT_TYPELOC(CLASS, PARENT)
1998#define TYPELOC(CLASS, PARENT) \
1999 case TypeLoc::CLASS: \
2000 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2001#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002002 }
Mike Stump11289f42009-09-09 15:08:12 +00002003
John McCall550e0c22009-10-21 00:40:46 +00002004 llvm::llvm_unreachable("unhandled type loc!");
2005 return QualType();
2006}
2007
2008/// FIXME: By default, this routine adds type qualifiers only to types
2009/// that can have qualifiers, and silently suppresses those qualifiers
2010/// that are not permitted (e.g., qualifiers on reference or function
2011/// types). This is the right thing for template instantiation, but
2012/// probably not for other clients.
2013template<typename Derived>
2014QualType
2015TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
2016 QualifiedTypeLoc T) {
2017 Qualifiers Quals = T.getType().getQualifiers();
2018
2019 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2020 if (Result.isNull())
2021 return QualType();
2022
2023 // Silently suppress qualifiers if the result type can't be qualified.
2024 // FIXME: this is the right thing for template instantiation, but
2025 // probably not for other clients.
2026 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002027 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002028
John McCall550e0c22009-10-21 00:40:46 +00002029 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2030
2031 TLB.push<QualifiedTypeLoc>(Result);
2032
2033 // No location information to preserve.
2034
2035 return Result;
2036}
2037
2038template <class TyLoc> static inline
2039QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2040 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2041 NewT.setNameLoc(T.getNameLoc());
2042 return T.getType();
2043}
2044
2045// Ugly metaprogramming macros because I couldn't be bothered to make
2046// the equivalent template version work.
2047#define TransformPointerLikeType(TypeClass) do { \
2048 QualType PointeeType \
2049 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2050 if (PointeeType.isNull()) \
2051 return QualType(); \
2052 \
2053 QualType Result = TL.getType(); \
2054 if (getDerived().AlwaysRebuild() || \
2055 PointeeType != TL.getPointeeLoc().getType()) { \
2056 Result = getDerived().Rebuild##TypeClass(PointeeType); \
2057 if (Result.isNull()) \
2058 return QualType(); \
2059 } \
2060 \
2061 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2062 NewT.setSigilLoc(TL.getSigilLoc()); \
2063 \
2064 return Result; \
2065} while(0)
2066
2067// Reference collapsing forces us to transform reference types
2068// differently from the other pointer-like types.
2069#define TransformReferenceType(TypeClass) do { \
2070 QualType PointeeType \
2071 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2072 if (PointeeType.isNull()) \
2073 return QualType(); \
2074 \
2075 QualType Result = TL.getType(); \
2076 if (getDerived().AlwaysRebuild() || \
2077 PointeeType != TL.getPointeeLoc().getType()) { \
2078 Result = getDerived().Rebuild##TypeClass(PointeeType); \
2079 if (Result.isNull()) \
2080 return QualType(); \
2081 } \
2082 \
2083 /* Workaround: rebuild doesn't always change the type */ \
2084 /* FIXME: avoid losing this location information. */ \
2085 if (Result == PointeeType) \
2086 return Result; \
2087 ReferenceTypeLoc NewTL; \
2088 if (isa<LValueReferenceType>(Result)) \
2089 NewTL = TLB.push<LValueReferenceTypeLoc>(Result); \
2090 else \
2091 NewTL = TLB.push<RValueReferenceTypeLoc>(Result); \
2092 NewTL.setSigilLoc(TL.getSigilLoc()); \
2093 return Result; \
2094} while (0)
2095
2096template<typename Derived>
2097QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
2098 BuiltinTypeLoc T) {
2099 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002100}
Mike Stump11289f42009-09-09 15:08:12 +00002101
Douglas Gregord6ff3322009-08-04 16:50:30 +00002102template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002103QualType
John McCall550e0c22009-10-21 00:40:46 +00002104TreeTransform<Derived>::TransformFixedWidthIntType(TypeLocBuilder &TLB,
2105 FixedWidthIntTypeLoc T) {
2106 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002107}
Argyrios Kyrtzidise9189262009-08-19 01:28:17 +00002108
Douglas Gregord6ff3322009-08-04 16:50:30 +00002109template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002110QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
2111 ComplexTypeLoc T) {
2112 // FIXME: recurse?
2113 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002114}
Mike Stump11289f42009-09-09 15:08:12 +00002115
Douglas Gregord6ff3322009-08-04 16:50:30 +00002116template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002117QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
2118 PointerTypeLoc TL) {
2119 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002120}
Mike Stump11289f42009-09-09 15:08:12 +00002121
2122template<typename Derived>
2123QualType
John McCall550e0c22009-10-21 00:40:46 +00002124TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
2125 BlockPointerTypeLoc TL) {
2126 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002127}
2128
Mike Stump11289f42009-09-09 15:08:12 +00002129template<typename Derived>
2130QualType
John McCall550e0c22009-10-21 00:40:46 +00002131TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
2132 LValueReferenceTypeLoc TL) {
2133 TransformReferenceType(LValueReferenceType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002134}
2135
Mike Stump11289f42009-09-09 15:08:12 +00002136template<typename Derived>
2137QualType
John McCall550e0c22009-10-21 00:40:46 +00002138TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
2139 RValueReferenceTypeLoc TL) {
2140 TransformReferenceType(RValueReferenceType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002141}
Mike Stump11289f42009-09-09 15:08:12 +00002142
Douglas Gregord6ff3322009-08-04 16:50:30 +00002143template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002144QualType
John McCall550e0c22009-10-21 00:40:46 +00002145TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
2146 MemberPointerTypeLoc TL) {
2147 MemberPointerType *T = TL.getTypePtr();
2148
2149 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002150 if (PointeeType.isNull())
2151 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002152
John McCall550e0c22009-10-21 00:40:46 +00002153 // TODO: preserve source information for this.
2154 QualType ClassType
2155 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002156 if (ClassType.isNull())
2157 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002158
John McCall550e0c22009-10-21 00:40:46 +00002159 QualType Result = TL.getType();
2160 if (getDerived().AlwaysRebuild() ||
2161 PointeeType != T->getPointeeType() ||
2162 ClassType != QualType(T->getClass(), 0)) {
2163 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType);
2164 if (Result.isNull())
2165 return QualType();
2166 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002167
John McCall550e0c22009-10-21 00:40:46 +00002168 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2169 NewTL.setSigilLoc(TL.getSigilLoc());
2170
2171 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002172}
2173
Mike Stump11289f42009-09-09 15:08:12 +00002174template<typename Derived>
2175QualType
John McCall550e0c22009-10-21 00:40:46 +00002176TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
2177 ConstantArrayTypeLoc TL) {
2178 ConstantArrayType *T = TL.getTypePtr();
2179 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002180 if (ElementType.isNull())
2181 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002182
John McCall550e0c22009-10-21 00:40:46 +00002183 QualType Result = TL.getType();
2184 if (getDerived().AlwaysRebuild() ||
2185 ElementType != T->getElementType()) {
2186 Result = getDerived().RebuildConstantArrayType(ElementType,
2187 T->getSizeModifier(),
2188 T->getSize(),
2189 T->getIndexTypeCVRQualifiers());
2190 if (Result.isNull())
2191 return QualType();
2192 }
2193
2194 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2195 NewTL.setLBracketLoc(TL.getLBracketLoc());
2196 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002197
John McCall550e0c22009-10-21 00:40:46 +00002198 Expr *Size = TL.getSizeExpr();
2199 if (Size) {
2200 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2201 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2202 }
2203 NewTL.setSizeExpr(Size);
2204
2205 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002206}
Mike Stump11289f42009-09-09 15:08:12 +00002207
Douglas Gregord6ff3322009-08-04 16:50:30 +00002208template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002209QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002210 TypeLocBuilder &TLB,
2211 IncompleteArrayTypeLoc TL) {
2212 IncompleteArrayType *T = TL.getTypePtr();
2213 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002214 if (ElementType.isNull())
2215 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002216
John McCall550e0c22009-10-21 00:40:46 +00002217 QualType Result = TL.getType();
2218 if (getDerived().AlwaysRebuild() ||
2219 ElementType != T->getElementType()) {
2220 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002221 T->getSizeModifier(),
John McCall550e0c22009-10-21 00:40:46 +00002222 T->getIndexTypeCVRQualifiers());
2223 if (Result.isNull())
2224 return QualType();
2225 }
2226
2227 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2228 NewTL.setLBracketLoc(TL.getLBracketLoc());
2229 NewTL.setRBracketLoc(TL.getRBracketLoc());
2230 NewTL.setSizeExpr(0);
2231
2232 return Result;
2233}
2234
2235template<typename Derived>
2236QualType
2237TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
2238 VariableArrayTypeLoc TL) {
2239 VariableArrayType *T = TL.getTypePtr();
2240 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2241 if (ElementType.isNull())
2242 return QualType();
2243
2244 // Array bounds are not potentially evaluated contexts
2245 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2246
2247 Sema::OwningExprResult SizeResult
2248 = getDerived().TransformExpr(T->getSizeExpr());
2249 if (SizeResult.isInvalid())
2250 return QualType();
2251
2252 Expr *Size = static_cast<Expr*>(SizeResult.get());
2253
2254 QualType Result = TL.getType();
2255 if (getDerived().AlwaysRebuild() ||
2256 ElementType != T->getElementType() ||
2257 Size != T->getSizeExpr()) {
2258 Result = getDerived().RebuildVariableArrayType(ElementType,
2259 T->getSizeModifier(),
2260 move(SizeResult),
2261 T->getIndexTypeCVRQualifiers(),
2262 T->getBracketsRange());
2263 if (Result.isNull())
2264 return QualType();
2265 }
2266 else SizeResult.take();
2267
2268 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2269 NewTL.setLBracketLoc(TL.getLBracketLoc());
2270 NewTL.setRBracketLoc(TL.getRBracketLoc());
2271 NewTL.setSizeExpr(Size);
2272
2273 return Result;
2274}
2275
2276template<typename Derived>
2277QualType
2278TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
2279 DependentSizedArrayTypeLoc TL) {
2280 DependentSizedArrayType *T = TL.getTypePtr();
2281 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2282 if (ElementType.isNull())
2283 return QualType();
2284
2285 // Array bounds are not potentially evaluated contexts
2286 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2287
2288 Sema::OwningExprResult SizeResult
2289 = getDerived().TransformExpr(T->getSizeExpr());
2290 if (SizeResult.isInvalid())
2291 return QualType();
2292
2293 Expr *Size = static_cast<Expr*>(SizeResult.get());
2294
2295 QualType Result = TL.getType();
2296 if (getDerived().AlwaysRebuild() ||
2297 ElementType != T->getElementType() ||
2298 Size != T->getSizeExpr()) {
2299 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2300 T->getSizeModifier(),
2301 move(SizeResult),
2302 T->getIndexTypeCVRQualifiers(),
2303 T->getBracketsRange());
2304 if (Result.isNull())
2305 return QualType();
2306 }
2307 else SizeResult.take();
2308
2309 // We might have any sort of array type now, but fortunately they
2310 // all have the same location layout.
2311 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2312 NewTL.setLBracketLoc(TL.getLBracketLoc());
2313 NewTL.setRBracketLoc(TL.getRBracketLoc());
2314 NewTL.setSizeExpr(Size);
2315
2316 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002317}
Mike Stump11289f42009-09-09 15:08:12 +00002318
2319template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002320QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002321 TypeLocBuilder &TLB,
2322 DependentSizedExtVectorTypeLoc TL) {
2323 DependentSizedExtVectorType *T = TL.getTypePtr();
2324
2325 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002326 QualType ElementType = getDerived().TransformType(T->getElementType());
2327 if (ElementType.isNull())
2328 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002329
Douglas Gregore922c772009-08-04 22:27:00 +00002330 // Vector sizes are not potentially evaluated contexts
2331 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2332
Douglas Gregord6ff3322009-08-04 16:50:30 +00002333 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2334 if (Size.isInvalid())
2335 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002336
John McCall550e0c22009-10-21 00:40:46 +00002337 QualType Result = TL.getType();
2338 if (getDerived().AlwaysRebuild() ||
2339 ElementType != T->getElementType() &&
2340 Size.get() != T->getSizeExpr()) {
2341 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002342 move(Size),
2343 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002344 if (Result.isNull())
2345 return QualType();
2346 }
2347 else Size.take();
2348
2349 // Result might be dependent or not.
2350 if (isa<DependentSizedExtVectorType>(Result)) {
2351 DependentSizedExtVectorTypeLoc NewTL
2352 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2353 NewTL.setNameLoc(TL.getNameLoc());
2354 } else {
2355 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2356 NewTL.setNameLoc(TL.getNameLoc());
2357 }
2358
2359 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002360}
Mike Stump11289f42009-09-09 15:08:12 +00002361
2362template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002363QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
2364 VectorTypeLoc TL) {
2365 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002366 QualType ElementType = getDerived().TransformType(T->getElementType());
2367 if (ElementType.isNull())
2368 return QualType();
2369
John McCall550e0c22009-10-21 00:40:46 +00002370 QualType Result = TL.getType();
2371 if (getDerived().AlwaysRebuild() ||
2372 ElementType != T->getElementType()) {
2373 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements());
2374 if (Result.isNull())
2375 return QualType();
2376 }
2377
2378 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2379 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002380
John McCall550e0c22009-10-21 00:40:46 +00002381 return Result;
2382}
2383
2384template<typename Derived>
2385QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
2386 ExtVectorTypeLoc TL) {
2387 VectorType *T = TL.getTypePtr();
2388 QualType ElementType = getDerived().TransformType(T->getElementType());
2389 if (ElementType.isNull())
2390 return QualType();
2391
2392 QualType Result = TL.getType();
2393 if (getDerived().AlwaysRebuild() ||
2394 ElementType != T->getElementType()) {
2395 Result = getDerived().RebuildExtVectorType(ElementType,
2396 T->getNumElements(),
2397 /*FIXME*/ SourceLocation());
2398 if (Result.isNull())
2399 return QualType();
2400 }
2401
2402 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2403 NewTL.setNameLoc(TL.getNameLoc());
2404
2405 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002406}
Mike Stump11289f42009-09-09 15:08:12 +00002407
2408template<typename Derived>
2409QualType
John McCall550e0c22009-10-21 00:40:46 +00002410TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
2411 FunctionProtoTypeLoc TL) {
2412 FunctionProtoType *T = TL.getTypePtr();
2413 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002414 if (ResultType.isNull())
2415 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002416
John McCall550e0c22009-10-21 00:40:46 +00002417 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002418 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002419 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2420 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2421 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump11289f42009-09-09 15:08:12 +00002422
John McCall550e0c22009-10-21 00:40:46 +00002423 QualType NewType;
2424 ParmVarDecl *NewParm;
2425
2426 if (OldParm) {
2427 DeclaratorInfo *OldDI = OldParm->getDeclaratorInfo();
2428 assert(OldDI->getType() == T->getArgType(i));
2429
2430 DeclaratorInfo *NewDI = getDerived().TransformType(OldDI);
2431 if (!NewDI)
2432 return QualType();
2433
2434 if (NewDI == OldDI)
2435 NewParm = OldParm;
2436 else
2437 NewParm = ParmVarDecl::Create(SemaRef.Context,
2438 OldParm->getDeclContext(),
2439 OldParm->getLocation(),
2440 OldParm->getIdentifier(),
2441 NewDI->getType(),
2442 NewDI,
2443 OldParm->getStorageClass(),
2444 /* DefArg */ NULL);
2445 NewType = NewParm->getType();
2446
2447 // Deal with the possibility that we don't have a parameter
2448 // declaration for this parameter.
2449 } else {
2450 NewParm = 0;
2451
2452 QualType OldType = T->getArgType(i);
2453 NewType = getDerived().TransformType(OldType);
2454 if (NewType.isNull())
2455 return QualType();
2456 }
2457
2458 ParamTypes.push_back(NewType);
2459 ParamDecls.push_back(NewParm);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002460 }
Mike Stump11289f42009-09-09 15:08:12 +00002461
John McCall550e0c22009-10-21 00:40:46 +00002462 QualType Result = TL.getType();
2463 if (getDerived().AlwaysRebuild() ||
2464 ResultType != T->getResultType() ||
2465 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2466 Result = getDerived().RebuildFunctionProtoType(ResultType,
2467 ParamTypes.data(),
2468 ParamTypes.size(),
2469 T->isVariadic(),
2470 T->getTypeQuals());
2471 if (Result.isNull())
2472 return QualType();
2473 }
Mike Stump11289f42009-09-09 15:08:12 +00002474
John McCall550e0c22009-10-21 00:40:46 +00002475 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2476 NewTL.setLParenLoc(TL.getLParenLoc());
2477 NewTL.setRParenLoc(TL.getRParenLoc());
2478 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2479 NewTL.setArg(i, ParamDecls[i]);
2480
2481 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002482}
Mike Stump11289f42009-09-09 15:08:12 +00002483
Douglas Gregord6ff3322009-08-04 16:50:30 +00002484template<typename Derived>
2485QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002486 TypeLocBuilder &TLB,
2487 FunctionNoProtoTypeLoc TL) {
2488 FunctionNoProtoType *T = TL.getTypePtr();
2489 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2490 if (ResultType.isNull())
2491 return QualType();
2492
2493 QualType Result = TL.getType();
2494 if (getDerived().AlwaysRebuild() ||
2495 ResultType != T->getResultType())
2496 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2497
2498 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2499 NewTL.setLParenLoc(TL.getLParenLoc());
2500 NewTL.setRParenLoc(TL.getRParenLoc());
2501
2502 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002503}
Mike Stump11289f42009-09-09 15:08:12 +00002504
Douglas Gregord6ff3322009-08-04 16:50:30 +00002505template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002506QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
2507 TypedefTypeLoc TL) {
2508 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002509 TypedefDecl *Typedef
2510 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2511 if (!Typedef)
2512 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002513
John McCall550e0c22009-10-21 00:40:46 +00002514 QualType Result = TL.getType();
2515 if (getDerived().AlwaysRebuild() ||
2516 Typedef != T->getDecl()) {
2517 Result = getDerived().RebuildTypedefType(Typedef);
2518 if (Result.isNull())
2519 return QualType();
2520 }
Mike Stump11289f42009-09-09 15:08:12 +00002521
John McCall550e0c22009-10-21 00:40:46 +00002522 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2523 NewTL.setNameLoc(TL.getNameLoc());
2524
2525 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002526}
Mike Stump11289f42009-09-09 15:08:12 +00002527
Douglas Gregord6ff3322009-08-04 16:50:30 +00002528template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002529QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
2530 TypeOfExprTypeLoc TL) {
2531 TypeOfExprType *T = TL.getTypePtr();
2532
Douglas Gregore922c772009-08-04 22:27:00 +00002533 // typeof expressions are not potentially evaluated contexts
2534 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002535
Douglas Gregord6ff3322009-08-04 16:50:30 +00002536 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2537 if (E.isInvalid())
2538 return QualType();
2539
John McCall550e0c22009-10-21 00:40:46 +00002540 QualType Result = TL.getType();
2541 if (getDerived().AlwaysRebuild() ||
2542 E.get() != T->getUnderlyingExpr()) {
2543 Result = getDerived().RebuildTypeOfExprType(move(E));
2544 if (Result.isNull())
2545 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002546 }
John McCall550e0c22009-10-21 00:40:46 +00002547 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002548
John McCall550e0c22009-10-21 00:40:46 +00002549 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
2550 NewTL.setNameLoc(TL.getNameLoc());
2551
2552 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002553}
Mike Stump11289f42009-09-09 15:08:12 +00002554
2555template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002556QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
2557 TypeOfTypeLoc TL) {
2558 TypeOfType *T = TL.getTypePtr();
2559
2560 // FIXME: should be an inner type, or at least have a DeclaratorInfo.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002561 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2562 if (Underlying.isNull())
2563 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002564
John McCall550e0c22009-10-21 00:40:46 +00002565 QualType Result = TL.getType();
2566 if (getDerived().AlwaysRebuild() ||
2567 Underlying != T->getUnderlyingType()) {
2568 Result = getDerived().RebuildTypeOfType(Underlying);
2569 if (Result.isNull())
2570 return QualType();
2571 }
Mike Stump11289f42009-09-09 15:08:12 +00002572
John McCall550e0c22009-10-21 00:40:46 +00002573 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
2574 NewTL.setNameLoc(TL.getNameLoc());
2575
2576 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002577}
Mike Stump11289f42009-09-09 15:08:12 +00002578
2579template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002580QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
2581 DecltypeTypeLoc TL) {
2582 DecltypeType *T = TL.getTypePtr();
2583
Douglas Gregore922c772009-08-04 22:27:00 +00002584 // decltype expressions are not potentially evaluated contexts
2585 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002586
Douglas Gregord6ff3322009-08-04 16:50:30 +00002587 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2588 if (E.isInvalid())
2589 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002590
John McCall550e0c22009-10-21 00:40:46 +00002591 QualType Result = TL.getType();
2592 if (getDerived().AlwaysRebuild() ||
2593 E.get() != T->getUnderlyingExpr()) {
2594 Result = getDerived().RebuildDecltypeType(move(E));
2595 if (Result.isNull())
2596 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002597 }
John McCall550e0c22009-10-21 00:40:46 +00002598 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002599
John McCall550e0c22009-10-21 00:40:46 +00002600 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2601 NewTL.setNameLoc(TL.getNameLoc());
2602
2603 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002604}
2605
2606template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002607QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
2608 RecordTypeLoc TL) {
2609 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002610 RecordDecl *Record
John McCall550e0c22009-10-21 00:40:46 +00002611 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002612 if (!Record)
2613 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002614
John McCall550e0c22009-10-21 00:40:46 +00002615 QualType Result = TL.getType();
2616 if (getDerived().AlwaysRebuild() ||
2617 Record != T->getDecl()) {
2618 Result = getDerived().RebuildRecordType(Record);
2619 if (Result.isNull())
2620 return QualType();
2621 }
Mike Stump11289f42009-09-09 15:08:12 +00002622
John McCall550e0c22009-10-21 00:40:46 +00002623 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2624 NewTL.setNameLoc(TL.getNameLoc());
2625
2626 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002627}
Mike Stump11289f42009-09-09 15:08:12 +00002628
2629template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002630QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
2631 EnumTypeLoc TL) {
2632 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002633 EnumDecl *Enum
John McCall550e0c22009-10-21 00:40:46 +00002634 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002635 if (!Enum)
2636 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002637
John McCall550e0c22009-10-21 00:40:46 +00002638 QualType Result = TL.getType();
2639 if (getDerived().AlwaysRebuild() ||
2640 Enum != T->getDecl()) {
2641 Result = getDerived().RebuildEnumType(Enum);
2642 if (Result.isNull())
2643 return QualType();
2644 }
Mike Stump11289f42009-09-09 15:08:12 +00002645
John McCall550e0c22009-10-21 00:40:46 +00002646 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2647 NewTL.setNameLoc(TL.getNameLoc());
2648
2649 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002650}
John McCallfcc33b02009-09-05 00:15:47 +00002651
2652template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002653QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
2654 ElaboratedTypeLoc TL) {
2655 ElaboratedType *T = TL.getTypePtr();
2656
2657 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002658 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2659 if (Underlying.isNull())
2660 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002661
John McCall550e0c22009-10-21 00:40:46 +00002662 QualType Result = TL.getType();
2663 if (getDerived().AlwaysRebuild() ||
2664 Underlying != T->getUnderlyingType()) {
2665 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2666 if (Result.isNull())
2667 return QualType();
2668 }
Mike Stump11289f42009-09-09 15:08:12 +00002669
John McCall550e0c22009-10-21 00:40:46 +00002670 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2671 NewTL.setNameLoc(TL.getNameLoc());
2672
2673 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002674}
Mike Stump11289f42009-09-09 15:08:12 +00002675
2676
Douglas Gregord6ff3322009-08-04 16:50:30 +00002677template<typename Derived>
2678QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002679 TypeLocBuilder &TLB,
2680 TemplateTypeParmTypeLoc TL) {
2681 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002682}
2683
Mike Stump11289f42009-09-09 15:08:12 +00002684template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002685QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002686 TypeLocBuilder &TLB,
2687 SubstTemplateTypeParmTypeLoc TL) {
2688 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002689}
2690
2691template<typename Derived>
Douglas Gregorc59e5612009-10-19 22:04:39 +00002692inline QualType
2693TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall550e0c22009-10-21 00:40:46 +00002694 TypeLocBuilder &TLB,
2695 TemplateSpecializationTypeLoc TL) {
2696 // TODO: figure out how make this work with an ObjectType.
2697 QualType Result
2698 = TransformTemplateSpecializationType(TL.getTypePtr(), QualType());
2699 if (Result.isNull())
2700 return QualType();
2701
2702 TemplateSpecializationTypeLoc NewTL
2703 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2704 NewTL.setNameLoc(TL.getNameLoc());
2705
2706 return Result;
Douglas Gregorc59e5612009-10-19 22:04:39 +00002707}
2708
2709template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002710QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
Douglas Gregorc59e5612009-10-19 22:04:39 +00002711 const TemplateSpecializationType *T,
2712 QualType ObjectType) {
Mike Stump11289f42009-09-09 15:08:12 +00002713 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002714 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002715 if (Template.isNull())
2716 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002717
Douglas Gregord6ff3322009-08-04 16:50:30 +00002718 llvm::SmallVector<TemplateArgument, 4> NewTemplateArgs;
2719 NewTemplateArgs.reserve(T->getNumArgs());
2720 for (TemplateSpecializationType::iterator Arg = T->begin(), ArgEnd = T->end();
2721 Arg != ArgEnd; ++Arg) {
2722 TemplateArgument NewArg = getDerived().TransformTemplateArgument(*Arg);
2723 if (NewArg.isNull())
2724 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002725
Douglas Gregord6ff3322009-08-04 16:50:30 +00002726 NewTemplateArgs.push_back(NewArg);
2727 }
Mike Stump11289f42009-09-09 15:08:12 +00002728
Douglas Gregord6ff3322009-08-04 16:50:30 +00002729 // FIXME: early abort if all of the template arguments and such are the
2730 // same.
Mike Stump11289f42009-09-09 15:08:12 +00002731
Douglas Gregord6ff3322009-08-04 16:50:30 +00002732 // FIXME: We're missing the locations of the template name, '<', and '>'.
2733 return getDerived().RebuildTemplateSpecializationType(Template,
2734 NewTemplateArgs.data(),
2735 NewTemplateArgs.size());
2736}
Mike Stump11289f42009-09-09 15:08:12 +00002737
2738template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002739QualType
2740TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
2741 QualifiedNameTypeLoc TL) {
2742 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002743 NestedNameSpecifier *NNS
2744 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2745 SourceRange());
2746 if (!NNS)
2747 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002748
Douglas Gregord6ff3322009-08-04 16:50:30 +00002749 QualType Named = getDerived().TransformType(T->getNamedType());
2750 if (Named.isNull())
2751 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002752
John McCall550e0c22009-10-21 00:40:46 +00002753 QualType Result = TL.getType();
2754 if (getDerived().AlwaysRebuild() ||
2755 NNS != T->getQualifier() ||
2756 Named != T->getNamedType()) {
2757 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2758 if (Result.isNull())
2759 return QualType();
2760 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002761
John McCall550e0c22009-10-21 00:40:46 +00002762 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2763 NewTL.setNameLoc(TL.getNameLoc());
2764
2765 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002766}
Mike Stump11289f42009-09-09 15:08:12 +00002767
2768template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002769QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
2770 TypenameTypeLoc TL) {
2771 TypenameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002772 NestedNameSpecifier *NNS
2773 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregor15acfb92009-08-06 16:20:37 +00002774 SourceRange(/*FIXME:*/getDerived().getBaseLocation()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002775 if (!NNS)
2776 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002777
John McCall550e0c22009-10-21 00:40:46 +00002778 QualType Result;
2779
Douglas Gregord6ff3322009-08-04 16:50:30 +00002780 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002781 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002782 = getDerived().TransformType(QualType(TemplateId, 0));
2783 if (NewTemplateId.isNull())
2784 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002785
Douglas Gregord6ff3322009-08-04 16:50:30 +00002786 if (!getDerived().AlwaysRebuild() &&
2787 NNS == T->getQualifier() &&
2788 NewTemplateId == QualType(TemplateId, 0))
2789 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002790
John McCall550e0c22009-10-21 00:40:46 +00002791 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2792 } else {
2793 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002794 }
John McCall550e0c22009-10-21 00:40:46 +00002795 if (Result.isNull())
2796 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002797
John McCall550e0c22009-10-21 00:40:46 +00002798 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2799 NewTL.setNameLoc(TL.getNameLoc());
2800
2801 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002802}
Mike Stump11289f42009-09-09 15:08:12 +00002803
Douglas Gregord6ff3322009-08-04 16:50:30 +00002804template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002805QualType
2806TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
2807 ObjCInterfaceTypeLoc TL) {
2808 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002809}
Mike Stump11289f42009-09-09 15:08:12 +00002810
2811template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002812QualType
2813TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
2814 ObjCObjectPointerTypeLoc TL) {
2815 TransformPointerLikeType(ObjCObjectPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002816}
2817
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00002818template<typename Derived>
2819QualType TreeTransform<Derived>::TransformObjCProtocolListType(
John McCall550e0c22009-10-21 00:40:46 +00002820 TypeLocBuilder &TLB,
2821 ObjCProtocolListTypeLoc TL) {
2822 ObjCProtocolListType *T = TL.getTypePtr();
2823 QualType BaseType = T->getBaseType();
2824 if (!BaseType.isNull()) {
2825 BaseType = getDerived().TransformType(TLB, TL.getBaseTypeLoc());
2826 if (BaseType.isNull())
2827 return QualType();
2828 }
2829
2830 QualType Result = TL.getType();
2831 if (getDerived().AlwaysRebuild() ||
2832 BaseType != T->getBaseType()) {
2833 // TODO: transform these?
2834 llvm::SmallVector<ObjCProtocolDecl*,4> Protocols(T->getNumProtocols());
2835 std::copy(T->qual_begin(), T->qual_end(), Protocols.begin());
2836 Result = getDerived().RebuildObjCProtocolListType(BaseType,
2837 &Protocols[0],
2838 T->getNumProtocols());
2839 if (Result.isNull())
2840 return QualType();
2841 }
2842
2843 ObjCProtocolListTypeLoc NewTL = TLB.push<ObjCProtocolListTypeLoc>(Result);
2844 NewTL.setLAngleLoc(TL.getLAngleLoc());
2845 NewTL.setRAngleLoc(TL.getRAngleLoc());
2846
2847 assert(NewTL.getNumProtocols() == TL.getNumProtocols());
2848 for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i)
2849 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
2850
2851 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00002852}
2853
Douglas Gregord6ff3322009-08-04 16:50:30 +00002854//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00002855// Statement transformation
2856//===----------------------------------------------------------------------===//
2857template<typename Derived>
2858Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002859TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2860 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002861}
2862
2863template<typename Derived>
2864Sema::OwningStmtResult
2865TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2866 return getDerived().TransformCompoundStmt(S, false);
2867}
2868
2869template<typename Derived>
2870Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002871TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00002872 bool IsStmtExpr) {
2873 bool SubStmtChanged = false;
2874 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
2875 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
2876 B != BEnd; ++B) {
2877 OwningStmtResult Result = getDerived().TransformStmt(*B);
2878 if (Result.isInvalid())
2879 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002880
Douglas Gregorebe10102009-08-20 07:17:43 +00002881 SubStmtChanged = SubStmtChanged || Result.get() != *B;
2882 Statements.push_back(Result.takeAs<Stmt>());
2883 }
Mike Stump11289f42009-09-09 15:08:12 +00002884
Douglas Gregorebe10102009-08-20 07:17:43 +00002885 if (!getDerived().AlwaysRebuild() &&
2886 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00002887 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002888
2889 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
2890 move_arg(Statements),
2891 S->getRBracLoc(),
2892 IsStmtExpr);
2893}
Mike Stump11289f42009-09-09 15:08:12 +00002894
Douglas Gregorebe10102009-08-20 07:17:43 +00002895template<typename Derived>
2896Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002897TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002898 // The case value expressions are not potentially evaluated.
2899 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002900
Douglas Gregorebe10102009-08-20 07:17:43 +00002901 // Transform the left-hand case value.
2902 OwningExprResult LHS = getDerived().TransformExpr(S->getLHS());
2903 if (LHS.isInvalid())
2904 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002905
Douglas Gregorebe10102009-08-20 07:17:43 +00002906 // Transform the right-hand case value (for the GNU case-range extension).
2907 OwningExprResult RHS = getDerived().TransformExpr(S->getRHS());
2908 if (RHS.isInvalid())
2909 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002910
Douglas Gregorebe10102009-08-20 07:17:43 +00002911 // Build the case statement.
2912 // Case statements are always rebuilt so that they will attached to their
2913 // transformed switch statement.
2914 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
2915 move(LHS),
2916 S->getEllipsisLoc(),
2917 move(RHS),
2918 S->getColonLoc());
2919 if (Case.isInvalid())
2920 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002921
Douglas Gregorebe10102009-08-20 07:17:43 +00002922 // Transform the statement following the case
2923 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
2924 if (SubStmt.isInvalid())
2925 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002926
Douglas Gregorebe10102009-08-20 07:17:43 +00002927 // Attach the body to the case statement
2928 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
2929}
2930
2931template<typename Derived>
2932Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002933TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002934 // Transform the statement following the default case
2935 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
2936 if (SubStmt.isInvalid())
2937 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002938
Douglas Gregorebe10102009-08-20 07:17:43 +00002939 // Default statements are always rebuilt
2940 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
2941 move(SubStmt));
2942}
Mike Stump11289f42009-09-09 15:08:12 +00002943
Douglas Gregorebe10102009-08-20 07:17:43 +00002944template<typename Derived>
2945Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002946TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002947 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
2948 if (SubStmt.isInvalid())
2949 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002950
Douglas Gregorebe10102009-08-20 07:17:43 +00002951 // FIXME: Pass the real colon location in.
2952 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
2953 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
2954 move(SubStmt));
2955}
Mike Stump11289f42009-09-09 15:08:12 +00002956
Douglas Gregorebe10102009-08-20 07:17:43 +00002957template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002958Sema::OwningStmtResult
2959TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002960 // Transform the condition
2961 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
2962 if (Cond.isInvalid())
2963 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002964
Douglas Gregorebe10102009-08-20 07:17:43 +00002965 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00002966
Douglas Gregorebe10102009-08-20 07:17:43 +00002967 // Transform the "then" branch.
2968 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
2969 if (Then.isInvalid())
2970 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002971
Douglas Gregorebe10102009-08-20 07:17:43 +00002972 // Transform the "else" branch.
2973 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
2974 if (Else.isInvalid())
2975 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002976
Douglas Gregorebe10102009-08-20 07:17:43 +00002977 if (!getDerived().AlwaysRebuild() &&
2978 FullCond->get() == S->getCond() &&
2979 Then.get() == S->getThen() &&
2980 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00002981 return SemaRef.Owned(S->Retain());
2982
Douglas Gregorebe10102009-08-20 07:17:43 +00002983 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00002984 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00002985}
2986
2987template<typename Derived>
2988Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002989TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002990 // Transform the condition.
2991 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
2992 if (Cond.isInvalid())
2993 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002994
Douglas Gregorebe10102009-08-20 07:17:43 +00002995 // Rebuild the switch statement.
2996 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(move(Cond));
2997 if (Switch.isInvalid())
2998 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002999
Douglas Gregorebe10102009-08-20 07:17:43 +00003000 // Transform the body of the switch statement.
3001 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3002 if (Body.isInvalid())
3003 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003004
Douglas Gregorebe10102009-08-20 07:17:43 +00003005 // Complete the switch statement.
3006 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3007 move(Body));
3008}
Mike Stump11289f42009-09-09 15:08:12 +00003009
Douglas Gregorebe10102009-08-20 07:17:43 +00003010template<typename Derived>
3011Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003012TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003013 // Transform the condition
3014 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3015 if (Cond.isInvalid())
3016 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003017
Douglas Gregorebe10102009-08-20 07:17:43 +00003018 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003019
Douglas Gregorebe10102009-08-20 07:17:43 +00003020 // Transform the body
3021 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3022 if (Body.isInvalid())
3023 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003024
Douglas Gregorebe10102009-08-20 07:17:43 +00003025 if (!getDerived().AlwaysRebuild() &&
3026 FullCond->get() == S->getCond() &&
3027 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003028 return SemaRef.Owned(S->Retain());
3029
Douglas Gregorebe10102009-08-20 07:17:43 +00003030 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, move(Body));
3031}
Mike Stump11289f42009-09-09 15:08:12 +00003032
Douglas Gregorebe10102009-08-20 07:17:43 +00003033template<typename Derived>
3034Sema::OwningStmtResult
3035TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3036 // Transform the condition
3037 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3038 if (Cond.isInvalid())
3039 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003040
Douglas Gregorebe10102009-08-20 07:17:43 +00003041 // Transform the body
3042 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3043 if (Body.isInvalid())
3044 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003045
Douglas Gregorebe10102009-08-20 07:17:43 +00003046 if (!getDerived().AlwaysRebuild() &&
3047 Cond.get() == S->getCond() &&
3048 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003049 return SemaRef.Owned(S->Retain());
3050
Douglas Gregorebe10102009-08-20 07:17:43 +00003051 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3052 /*FIXME:*/S->getWhileLoc(), move(Cond),
3053 S->getRParenLoc());
3054}
Mike Stump11289f42009-09-09 15:08:12 +00003055
Douglas Gregorebe10102009-08-20 07:17:43 +00003056template<typename Derived>
3057Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003058TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003059 // Transform the initialization statement
3060 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3061 if (Init.isInvalid())
3062 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003063
Douglas Gregorebe10102009-08-20 07:17:43 +00003064 // Transform the condition
3065 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3066 if (Cond.isInvalid())
3067 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003068
Douglas Gregorebe10102009-08-20 07:17:43 +00003069 // Transform the increment
3070 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3071 if (Inc.isInvalid())
3072 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003073
Douglas Gregorebe10102009-08-20 07:17:43 +00003074 // Transform the body
3075 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3076 if (Body.isInvalid())
3077 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003078
Douglas Gregorebe10102009-08-20 07:17:43 +00003079 if (!getDerived().AlwaysRebuild() &&
3080 Init.get() == S->getInit() &&
3081 Cond.get() == S->getCond() &&
3082 Inc.get() == S->getInc() &&
3083 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003084 return SemaRef.Owned(S->Retain());
3085
Douglas Gregorebe10102009-08-20 07:17:43 +00003086 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
3087 move(Init), move(Cond), move(Inc),
3088 S->getRParenLoc(), move(Body));
3089}
3090
3091template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003092Sema::OwningStmtResult
3093TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003094 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003095 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003096 S->getLabel());
3097}
3098
3099template<typename Derived>
3100Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003101TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003102 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3103 if (Target.isInvalid())
3104 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003105
Douglas Gregorebe10102009-08-20 07:17:43 +00003106 if (!getDerived().AlwaysRebuild() &&
3107 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003108 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003109
3110 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3111 move(Target));
3112}
3113
3114template<typename Derived>
3115Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003116TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3117 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003118}
Mike Stump11289f42009-09-09 15:08:12 +00003119
Douglas Gregorebe10102009-08-20 07:17:43 +00003120template<typename Derived>
3121Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003122TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3123 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003124}
Mike Stump11289f42009-09-09 15:08:12 +00003125
Douglas Gregorebe10102009-08-20 07:17:43 +00003126template<typename Derived>
3127Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003128TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003129 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3130 if (Result.isInvalid())
3131 return SemaRef.StmtError();
3132
Mike Stump11289f42009-09-09 15:08:12 +00003133 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003134 // to tell whether the return type of the function has changed.
3135 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3136}
Mike Stump11289f42009-09-09 15:08:12 +00003137
Douglas Gregorebe10102009-08-20 07:17:43 +00003138template<typename Derived>
3139Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003140TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003141 bool DeclChanged = false;
3142 llvm::SmallVector<Decl *, 4> Decls;
3143 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3144 D != DEnd; ++D) {
3145 Decl *Transformed = getDerived().TransformDefinition(*D);
3146 if (!Transformed)
3147 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003148
Douglas Gregorebe10102009-08-20 07:17:43 +00003149 if (Transformed != *D)
3150 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003151
Douglas Gregorebe10102009-08-20 07:17:43 +00003152 Decls.push_back(Transformed);
3153 }
Mike Stump11289f42009-09-09 15:08:12 +00003154
Douglas Gregorebe10102009-08-20 07:17:43 +00003155 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003156 return SemaRef.Owned(S->Retain());
3157
3158 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003159 S->getStartLoc(), S->getEndLoc());
3160}
Mike Stump11289f42009-09-09 15:08:12 +00003161
Douglas Gregorebe10102009-08-20 07:17:43 +00003162template<typename Derived>
3163Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003164TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003165 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003166 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003167}
3168
3169template<typename Derived>
3170Sema::OwningStmtResult
3171TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
3172 // FIXME: Implement!
3173 assert(false && "Inline assembly cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003174 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003175}
3176
3177
3178template<typename Derived>
3179Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003180TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003181 // FIXME: Implement this
3182 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003183 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003184}
Mike Stump11289f42009-09-09 15:08:12 +00003185
Douglas Gregorebe10102009-08-20 07:17:43 +00003186template<typename Derived>
3187Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003188TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003189 // FIXME: Implement this
3190 assert(false && "Cannot transform an Objective-C @catch statement");
3191 return SemaRef.Owned(S->Retain());
3192}
Mike Stump11289f42009-09-09 15:08:12 +00003193
Douglas Gregorebe10102009-08-20 07:17:43 +00003194template<typename Derived>
3195Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003196TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003197 // FIXME: Implement this
3198 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003199 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003200}
Mike Stump11289f42009-09-09 15:08:12 +00003201
Douglas Gregorebe10102009-08-20 07:17:43 +00003202template<typename Derived>
3203Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003204TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003205 // FIXME: Implement this
3206 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003207 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003208}
Mike Stump11289f42009-09-09 15:08:12 +00003209
Douglas Gregorebe10102009-08-20 07:17:43 +00003210template<typename Derived>
3211Sema::OwningStmtResult
3212TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003213 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003214 // FIXME: Implement this
3215 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003216 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003217}
3218
3219template<typename Derived>
3220Sema::OwningStmtResult
3221TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003222 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003223 // FIXME: Implement this
3224 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003225 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003226}
3227
3228
3229template<typename Derived>
3230Sema::OwningStmtResult
3231TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3232 // Transform the exception declaration, if any.
3233 VarDecl *Var = 0;
3234 if (S->getExceptionDecl()) {
3235 VarDecl *ExceptionDecl = S->getExceptionDecl();
3236 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3237 ExceptionDecl->getDeclName());
3238
3239 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3240 if (T.isNull())
3241 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003242
Douglas Gregorebe10102009-08-20 07:17:43 +00003243 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3244 T,
3245 ExceptionDecl->getDeclaratorInfo(),
3246 ExceptionDecl->getIdentifier(),
3247 ExceptionDecl->getLocation(),
3248 /*FIXME: Inaccurate*/
3249 SourceRange(ExceptionDecl->getLocation()));
3250 if (!Var || Var->isInvalidDecl()) {
3251 if (Var)
3252 Var->Destroy(SemaRef.Context);
3253 return SemaRef.StmtError();
3254 }
3255 }
Mike Stump11289f42009-09-09 15:08:12 +00003256
Douglas Gregorebe10102009-08-20 07:17:43 +00003257 // Transform the actual exception handler.
3258 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3259 if (Handler.isInvalid()) {
3260 if (Var)
3261 Var->Destroy(SemaRef.Context);
3262 return SemaRef.StmtError();
3263 }
Mike Stump11289f42009-09-09 15:08:12 +00003264
Douglas Gregorebe10102009-08-20 07:17:43 +00003265 if (!getDerived().AlwaysRebuild() &&
3266 !Var &&
3267 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003268 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003269
3270 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3271 Var,
3272 move(Handler));
3273}
Mike Stump11289f42009-09-09 15:08:12 +00003274
Douglas Gregorebe10102009-08-20 07:17:43 +00003275template<typename Derived>
3276Sema::OwningStmtResult
3277TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3278 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003279 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003280 = getDerived().TransformCompoundStmt(S->getTryBlock());
3281 if (TryBlock.isInvalid())
3282 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003283
Douglas Gregorebe10102009-08-20 07:17:43 +00003284 // Transform the handlers.
3285 bool HandlerChanged = false;
3286 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3287 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003288 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003289 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3290 if (Handler.isInvalid())
3291 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003292
Douglas Gregorebe10102009-08-20 07:17:43 +00003293 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3294 Handlers.push_back(Handler.takeAs<Stmt>());
3295 }
Mike Stump11289f42009-09-09 15:08:12 +00003296
Douglas Gregorebe10102009-08-20 07:17:43 +00003297 if (!getDerived().AlwaysRebuild() &&
3298 TryBlock.get() == S->getTryBlock() &&
3299 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003300 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003301
3302 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003303 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003304}
Mike Stump11289f42009-09-09 15:08:12 +00003305
Douglas Gregorebe10102009-08-20 07:17:43 +00003306//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003307// Expression transformation
3308//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003309template<typename Derived>
3310Sema::OwningExprResult
3311TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
3312 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003313}
Mike Stump11289f42009-09-09 15:08:12 +00003314
3315template<typename Derived>
3316Sema::OwningExprResult
3317TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
3318 NamedDecl *ND
Douglas Gregora16548e2009-08-11 05:31:07 +00003319 = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl()));
3320 if (!ND)
3321 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003322
Douglas Gregora16548e2009-08-11 05:31:07 +00003323 if (!getDerived().AlwaysRebuild() && ND == E->getDecl())
Mike Stump11289f42009-09-09 15:08:12 +00003324 return SemaRef.Owned(E->Retain());
3325
Douglas Gregora16548e2009-08-11 05:31:07 +00003326 return getDerived().RebuildDeclRefExpr(ND, E->getLocation());
3327}
Mike Stump11289f42009-09-09 15:08:12 +00003328
Douglas Gregora16548e2009-08-11 05:31:07 +00003329template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003330Sema::OwningExprResult
3331TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
3332 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003333}
Mike Stump11289f42009-09-09 15:08:12 +00003334
Douglas Gregora16548e2009-08-11 05:31:07 +00003335template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003336Sema::OwningExprResult
3337TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
3338 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003339}
Mike Stump11289f42009-09-09 15:08:12 +00003340
Douglas Gregora16548e2009-08-11 05:31:07 +00003341template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003342Sema::OwningExprResult
3343TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
3344 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003345}
Mike Stump11289f42009-09-09 15:08:12 +00003346
Douglas Gregora16548e2009-08-11 05:31:07 +00003347template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003348Sema::OwningExprResult
3349TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
3350 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003351}
Mike Stump11289f42009-09-09 15:08:12 +00003352
Douglas Gregora16548e2009-08-11 05:31:07 +00003353template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003354Sema::OwningExprResult
3355TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
3356 return SemaRef.Owned(E->Retain());
3357}
3358
3359template<typename Derived>
3360Sema::OwningExprResult
3361TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003362 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3363 if (SubExpr.isInvalid())
3364 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003365
Douglas Gregora16548e2009-08-11 05:31:07 +00003366 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003367 return SemaRef.Owned(E->Retain());
3368
3369 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003370 E->getRParen());
3371}
3372
Mike Stump11289f42009-09-09 15:08:12 +00003373template<typename Derived>
3374Sema::OwningExprResult
3375TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003376 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3377 if (SubExpr.isInvalid())
3378 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003379
Douglas Gregora16548e2009-08-11 05:31:07 +00003380 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003381 return SemaRef.Owned(E->Retain());
3382
Douglas Gregora16548e2009-08-11 05:31:07 +00003383 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3384 E->getOpcode(),
3385 move(SubExpr));
3386}
Mike Stump11289f42009-09-09 15:08:12 +00003387
Douglas Gregora16548e2009-08-11 05:31:07 +00003388template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003389Sema::OwningExprResult
3390TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003391 if (E->isArgumentType()) {
3392 QualType T = getDerived().TransformType(E->getArgumentType());
3393 if (T.isNull())
3394 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003395
Douglas Gregora16548e2009-08-11 05:31:07 +00003396 if (!getDerived().AlwaysRebuild() && T == E->getArgumentType())
3397 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003398
3399 return getDerived().RebuildSizeOfAlignOf(T, E->getOperatorLoc(),
3400 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003401 E->getSourceRange());
3402 }
Mike Stump11289f42009-09-09 15:08:12 +00003403
Douglas Gregora16548e2009-08-11 05:31:07 +00003404 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003405 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003406 // C++0x [expr.sizeof]p1:
3407 // The operand is either an expression, which is an unevaluated operand
3408 // [...]
3409 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003410
Douglas Gregora16548e2009-08-11 05:31:07 +00003411 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3412 if (SubExpr.isInvalid())
3413 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003414
Douglas Gregora16548e2009-08-11 05:31:07 +00003415 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3416 return SemaRef.Owned(E->Retain());
3417 }
Mike Stump11289f42009-09-09 15:08:12 +00003418
Douglas Gregora16548e2009-08-11 05:31:07 +00003419 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3420 E->isSizeOf(),
3421 E->getSourceRange());
3422}
Mike Stump11289f42009-09-09 15:08:12 +00003423
Douglas Gregora16548e2009-08-11 05:31:07 +00003424template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003425Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003426TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
3427 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3428 if (LHS.isInvalid())
3429 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003430
Douglas Gregora16548e2009-08-11 05:31:07 +00003431 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3432 if (RHS.isInvalid())
3433 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003434
3435
Douglas Gregora16548e2009-08-11 05:31:07 +00003436 if (!getDerived().AlwaysRebuild() &&
3437 LHS.get() == E->getLHS() &&
3438 RHS.get() == E->getRHS())
3439 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003440
Douglas Gregora16548e2009-08-11 05:31:07 +00003441 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3442 /*FIXME:*/E->getLHS()->getLocStart(),
3443 move(RHS),
3444 E->getRBracketLoc());
3445}
Mike Stump11289f42009-09-09 15:08:12 +00003446
3447template<typename Derived>
3448Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003449TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
3450 // Transform the callee.
3451 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3452 if (Callee.isInvalid())
3453 return SemaRef.ExprError();
3454
3455 // Transform arguments.
3456 bool ArgChanged = false;
3457 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3458 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3459 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3460 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3461 if (Arg.isInvalid())
3462 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003463
Douglas Gregora16548e2009-08-11 05:31:07 +00003464 // FIXME: Wrong source location information for the ','.
3465 FakeCommaLocs.push_back(
3466 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003467
3468 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003469 Args.push_back(Arg.takeAs<Expr>());
3470 }
Mike Stump11289f42009-09-09 15:08:12 +00003471
Douglas Gregora16548e2009-08-11 05:31:07 +00003472 if (!getDerived().AlwaysRebuild() &&
3473 Callee.get() == E->getCallee() &&
3474 !ArgChanged)
3475 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003476
Douglas Gregora16548e2009-08-11 05:31:07 +00003477 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003478 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003479 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3480 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3481 move_arg(Args),
3482 FakeCommaLocs.data(),
3483 E->getRParenLoc());
3484}
Mike Stump11289f42009-09-09 15:08:12 +00003485
3486template<typename Derived>
3487Sema::OwningExprResult
3488TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003489 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3490 if (Base.isInvalid())
3491 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003492
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003493 NestedNameSpecifier *Qualifier = 0;
3494 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003495 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003496 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3497 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003498 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003499 return SemaRef.ExprError();
3500 }
Mike Stump11289f42009-09-09 15:08:12 +00003501
3502 NamedDecl *Member
Douglas Gregora16548e2009-08-11 05:31:07 +00003503 = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getMemberDecl()));
3504 if (!Member)
3505 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003506
Douglas Gregora16548e2009-08-11 05:31:07 +00003507 if (!getDerived().AlwaysRebuild() &&
3508 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003509 Qualifier == E->getQualifier() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003510 Member == E->getMemberDecl())
Mike Stump11289f42009-09-09 15:08:12 +00003511 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003512
3513 // FIXME: Bogus source location for the operator
3514 SourceLocation FakeOperatorLoc
3515 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3516
3517 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3518 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003519 Qualifier,
3520 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003521 E->getMemberLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003522 Member);
Douglas Gregora16548e2009-08-11 05:31:07 +00003523}
Mike Stump11289f42009-09-09 15:08:12 +00003524
Douglas Gregora16548e2009-08-11 05:31:07 +00003525template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003526Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003527TreeTransform<Derived>::TransformCastExpr(CastExpr *E) {
3528 assert(false && "Cannot transform abstract class");
3529 return SemaRef.Owned(E->Retain());
3530}
3531
3532template<typename Derived>
3533Sema::OwningExprResult
3534TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003535 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3536 if (LHS.isInvalid())
3537 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003538
Douglas Gregora16548e2009-08-11 05:31:07 +00003539 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3540 if (RHS.isInvalid())
3541 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003542
Douglas Gregora16548e2009-08-11 05:31:07 +00003543 if (!getDerived().AlwaysRebuild() &&
3544 LHS.get() == E->getLHS() &&
3545 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003546 return SemaRef.Owned(E->Retain());
3547
Douglas Gregora16548e2009-08-11 05:31:07 +00003548 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3549 move(LHS), move(RHS));
3550}
3551
Mike Stump11289f42009-09-09 15:08:12 +00003552template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003553Sema::OwningExprResult
3554TreeTransform<Derived>::TransformCompoundAssignOperator(
3555 CompoundAssignOperator *E) {
3556 return getDerived().TransformBinaryOperator(E);
3557}
Mike Stump11289f42009-09-09 15:08:12 +00003558
Douglas Gregora16548e2009-08-11 05:31:07 +00003559template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003560Sema::OwningExprResult
3561TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003562 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3563 if (Cond.isInvalid())
3564 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003565
Douglas Gregora16548e2009-08-11 05:31:07 +00003566 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3567 if (LHS.isInvalid())
3568 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003569
Douglas Gregora16548e2009-08-11 05:31:07 +00003570 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3571 if (RHS.isInvalid())
3572 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003573
Douglas Gregora16548e2009-08-11 05:31:07 +00003574 if (!getDerived().AlwaysRebuild() &&
3575 Cond.get() == E->getCond() &&
3576 LHS.get() == E->getLHS() &&
3577 RHS.get() == E->getRHS())
3578 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003579
3580 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003581 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003582 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003583 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003584 move(RHS));
3585}
Mike Stump11289f42009-09-09 15:08:12 +00003586
3587template<typename Derived>
3588Sema::OwningExprResult
3589TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003590 QualType T = getDerived().TransformType(E->getType());
3591 if (T.isNull())
3592 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003593
Douglas Gregora16548e2009-08-11 05:31:07 +00003594 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3595 if (SubExpr.isInvalid())
3596 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003597
Douglas Gregora16548e2009-08-11 05:31:07 +00003598 if (!getDerived().AlwaysRebuild() &&
3599 T == E->getType() &&
3600 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003601 return SemaRef.Owned(E->Retain());
3602
Douglas Gregora16548e2009-08-11 05:31:07 +00003603 return getDerived().RebuildImplicitCastExpr(T, E->getCastKind(),
Mike Stump11289f42009-09-09 15:08:12 +00003604 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00003605 E->isLvalueCast());
3606}
Mike Stump11289f42009-09-09 15:08:12 +00003607
Douglas Gregora16548e2009-08-11 05:31:07 +00003608template<typename Derived>
3609Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003610TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) {
3611 assert(false && "Cannot transform abstract class");
3612 return SemaRef.Owned(E->Retain());
3613}
3614
3615template<typename Derived>
3616Sema::OwningExprResult
3617TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003618 QualType T;
3619 {
3620 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003621 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003622 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3623 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003624
Douglas Gregora16548e2009-08-11 05:31:07 +00003625 T = getDerived().TransformType(E->getTypeAsWritten());
3626 if (T.isNull())
3627 return SemaRef.ExprError();
3628 }
Mike Stump11289f42009-09-09 15:08:12 +00003629
Douglas Gregora16548e2009-08-11 05:31:07 +00003630 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3631 if (SubExpr.isInvalid())
3632 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003633
Douglas Gregora16548e2009-08-11 05:31:07 +00003634 if (!getDerived().AlwaysRebuild() &&
3635 T == E->getTypeAsWritten() &&
3636 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003637 return SemaRef.Owned(E->Retain());
3638
Douglas Gregora16548e2009-08-11 05:31:07 +00003639 return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T,
3640 E->getRParenLoc(),
3641 move(SubExpr));
3642}
Mike Stump11289f42009-09-09 15:08:12 +00003643
Douglas Gregora16548e2009-08-11 05:31:07 +00003644template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003645Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003646TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
3647 QualType T;
3648 {
3649 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003650 SourceLocation FakeTypeLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003651 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3652 TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003653
Douglas Gregora16548e2009-08-11 05:31:07 +00003654 T = getDerived().TransformType(E->getType());
3655 if (T.isNull())
3656 return SemaRef.ExprError();
3657 }
Mike Stump11289f42009-09-09 15:08:12 +00003658
Douglas Gregora16548e2009-08-11 05:31:07 +00003659 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3660 if (Init.isInvalid())
3661 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003662
Douglas Gregora16548e2009-08-11 05:31:07 +00003663 if (!getDerived().AlwaysRebuild() &&
3664 T == E->getType() &&
3665 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003666 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003667
3668 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T,
3669 /*FIXME:*/E->getInitializer()->getLocEnd(),
3670 move(Init));
3671}
Mike Stump11289f42009-09-09 15:08:12 +00003672
Douglas Gregora16548e2009-08-11 05:31:07 +00003673template<typename Derived>
3674Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003675TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003676 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3677 if (Base.isInvalid())
3678 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003679
Douglas Gregora16548e2009-08-11 05:31:07 +00003680 if (!getDerived().AlwaysRebuild() &&
3681 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003682 return SemaRef.Owned(E->Retain());
3683
Douglas Gregora16548e2009-08-11 05:31:07 +00003684 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003685 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003686 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3687 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3688 E->getAccessorLoc(),
3689 E->getAccessor());
3690}
Mike Stump11289f42009-09-09 15:08:12 +00003691
Douglas Gregora16548e2009-08-11 05:31:07 +00003692template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003693Sema::OwningExprResult
3694TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003695 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003696
Douglas Gregora16548e2009-08-11 05:31:07 +00003697 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3698 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3699 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3700 if (Init.isInvalid())
3701 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003702
Douglas Gregora16548e2009-08-11 05:31:07 +00003703 InitChanged = InitChanged || Init.get() != E->getInit(I);
3704 Inits.push_back(Init.takeAs<Expr>());
3705 }
Mike Stump11289f42009-09-09 15:08:12 +00003706
Douglas Gregora16548e2009-08-11 05:31:07 +00003707 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003708 return SemaRef.Owned(E->Retain());
3709
Douglas Gregora16548e2009-08-11 05:31:07 +00003710 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
3711 E->getRBraceLoc());
3712}
Mike Stump11289f42009-09-09 15:08:12 +00003713
Douglas Gregora16548e2009-08-11 05:31:07 +00003714template<typename Derived>
3715Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003716TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003717 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00003718
Douglas Gregorebe10102009-08-20 07:17:43 +00003719 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00003720 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3721 if (Init.isInvalid())
3722 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003723
Douglas Gregorebe10102009-08-20 07:17:43 +00003724 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00003725 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3726 bool ExprChanged = false;
3727 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3728 DEnd = E->designators_end();
3729 D != DEnd; ++D) {
3730 if (D->isFieldDesignator()) {
3731 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3732 D->getDotLoc(),
3733 D->getFieldLoc()));
3734 continue;
3735 }
Mike Stump11289f42009-09-09 15:08:12 +00003736
Douglas Gregora16548e2009-08-11 05:31:07 +00003737 if (D->isArrayDesignator()) {
3738 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3739 if (Index.isInvalid())
3740 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003741
3742 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003743 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003744
Douglas Gregora16548e2009-08-11 05:31:07 +00003745 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3746 ArrayExprs.push_back(Index.release());
3747 continue;
3748 }
Mike Stump11289f42009-09-09 15:08:12 +00003749
Douglas Gregora16548e2009-08-11 05:31:07 +00003750 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00003751 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00003752 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3753 if (Start.isInvalid())
3754 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003755
Douglas Gregora16548e2009-08-11 05:31:07 +00003756 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3757 if (End.isInvalid())
3758 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003759
3760 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003761 End.get(),
3762 D->getLBracketLoc(),
3763 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003764
Douglas Gregora16548e2009-08-11 05:31:07 +00003765 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
3766 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00003767
Douglas Gregora16548e2009-08-11 05:31:07 +00003768 ArrayExprs.push_back(Start.release());
3769 ArrayExprs.push_back(End.release());
3770 }
Mike Stump11289f42009-09-09 15:08:12 +00003771
Douglas Gregora16548e2009-08-11 05:31:07 +00003772 if (!getDerived().AlwaysRebuild() &&
3773 Init.get() == E->getInit() &&
3774 !ExprChanged)
3775 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003776
Douglas Gregora16548e2009-08-11 05:31:07 +00003777 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
3778 E->getEqualOrColonLoc(),
3779 E->usesGNUSyntax(), move(Init));
3780}
Mike Stump11289f42009-09-09 15:08:12 +00003781
Douglas Gregora16548e2009-08-11 05:31:07 +00003782template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003783Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003784TreeTransform<Derived>::TransformImplicitValueInitExpr(
Mike Stump11289f42009-09-09 15:08:12 +00003785 ImplicitValueInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003786 QualType T = getDerived().TransformType(E->getType());
3787 if (T.isNull())
3788 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003789
Douglas Gregora16548e2009-08-11 05:31:07 +00003790 if (!getDerived().AlwaysRebuild() &&
3791 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00003792 return SemaRef.Owned(E->Retain());
3793
Douglas Gregora16548e2009-08-11 05:31:07 +00003794 return getDerived().RebuildImplicitValueInitExpr(T);
3795}
Mike Stump11289f42009-09-09 15:08:12 +00003796
Douglas Gregora16548e2009-08-11 05:31:07 +00003797template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003798Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003799TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
3800 // FIXME: Do we want the type as written?
3801 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00003802
Douglas Gregora16548e2009-08-11 05:31:07 +00003803 {
3804 // FIXME: Source location isn't quite accurate.
3805 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
3806 T = getDerived().TransformType(E->getType());
3807 if (T.isNull())
3808 return SemaRef.ExprError();
3809 }
Mike Stump11289f42009-09-09 15:08:12 +00003810
Douglas Gregora16548e2009-08-11 05:31:07 +00003811 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3812 if (SubExpr.isInvalid())
3813 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003814
Douglas Gregora16548e2009-08-11 05:31:07 +00003815 if (!getDerived().AlwaysRebuild() &&
3816 T == E->getType() &&
3817 SubExpr.get() == E->getSubExpr())
3818 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003819
Douglas Gregora16548e2009-08-11 05:31:07 +00003820 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
3821 T, E->getRParenLoc());
3822}
3823
3824template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003825Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003826TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
3827 bool ArgumentChanged = false;
3828 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3829 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
3830 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
3831 if (Init.isInvalid())
3832 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003833
Douglas Gregora16548e2009-08-11 05:31:07 +00003834 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
3835 Inits.push_back(Init.takeAs<Expr>());
3836 }
Mike Stump11289f42009-09-09 15:08:12 +00003837
Douglas Gregora16548e2009-08-11 05:31:07 +00003838 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
3839 move_arg(Inits),
3840 E->getRParenLoc());
3841}
Mike Stump11289f42009-09-09 15:08:12 +00003842
Douglas Gregora16548e2009-08-11 05:31:07 +00003843/// \brief Transform an address-of-label expression.
3844///
3845/// By default, the transformation of an address-of-label expression always
3846/// rebuilds the expression, so that the label identifier can be resolved to
3847/// the corresponding label statement by semantic analysis.
3848template<typename Derived>
3849Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003850TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003851 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
3852 E->getLabel());
3853}
Mike Stump11289f42009-09-09 15:08:12 +00003854
3855template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003856Sema::OwningExprResult TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003857 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00003858 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
3859 if (SubStmt.isInvalid())
3860 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003861
Douglas Gregora16548e2009-08-11 05:31:07 +00003862 if (!getDerived().AlwaysRebuild() &&
3863 SubStmt.get() == E->getSubStmt())
3864 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003865
3866 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003867 move(SubStmt),
3868 E->getRParenLoc());
3869}
Mike Stump11289f42009-09-09 15:08:12 +00003870
Douglas Gregora16548e2009-08-11 05:31:07 +00003871template<typename Derived>
3872Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003873TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003874 QualType T1, T2;
3875 {
3876 // FIXME: Source location isn't quite accurate.
3877 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003878
Douglas Gregora16548e2009-08-11 05:31:07 +00003879 T1 = getDerived().TransformType(E->getArgType1());
3880 if (T1.isNull())
3881 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003882
Douglas Gregora16548e2009-08-11 05:31:07 +00003883 T2 = getDerived().TransformType(E->getArgType2());
3884 if (T2.isNull())
3885 return SemaRef.ExprError();
3886 }
3887
3888 if (!getDerived().AlwaysRebuild() &&
3889 T1 == E->getArgType1() &&
3890 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00003891 return SemaRef.Owned(E->Retain());
3892
Douglas Gregora16548e2009-08-11 05:31:07 +00003893 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
3894 T1, T2, E->getRParenLoc());
3895}
Mike Stump11289f42009-09-09 15:08:12 +00003896
Douglas Gregora16548e2009-08-11 05:31:07 +00003897template<typename Derived>
3898Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003899TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003900 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3901 if (Cond.isInvalid())
3902 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003903
Douglas Gregora16548e2009-08-11 05:31:07 +00003904 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3905 if (LHS.isInvalid())
3906 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003907
Douglas Gregora16548e2009-08-11 05:31:07 +00003908 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3909 if (RHS.isInvalid())
3910 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003911
Douglas Gregora16548e2009-08-11 05:31:07 +00003912 if (!getDerived().AlwaysRebuild() &&
3913 Cond.get() == E->getCond() &&
3914 LHS.get() == E->getLHS() &&
3915 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003916 return SemaRef.Owned(E->Retain());
3917
Douglas Gregora16548e2009-08-11 05:31:07 +00003918 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
3919 move(Cond), move(LHS), move(RHS),
3920 E->getRParenLoc());
3921}
Mike Stump11289f42009-09-09 15:08:12 +00003922
Douglas Gregora16548e2009-08-11 05:31:07 +00003923template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003924Sema::OwningExprResult
3925TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
3926 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003927}
3928
3929template<typename Derived>
3930Sema::OwningExprResult
3931TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
3932 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3933 if (Callee.isInvalid())
3934 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003935
Douglas Gregora16548e2009-08-11 05:31:07 +00003936 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
3937 if (First.isInvalid())
3938 return SemaRef.ExprError();
3939
3940 OwningExprResult Second(SemaRef);
3941 if (E->getNumArgs() == 2) {
3942 Second = getDerived().TransformExpr(E->getArg(1));
3943 if (Second.isInvalid())
3944 return SemaRef.ExprError();
3945 }
Mike Stump11289f42009-09-09 15:08:12 +00003946
Douglas Gregora16548e2009-08-11 05:31:07 +00003947 if (!getDerived().AlwaysRebuild() &&
3948 Callee.get() == E->getCallee() &&
3949 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00003950 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
3951 return SemaRef.Owned(E->Retain());
3952
Douglas Gregora16548e2009-08-11 05:31:07 +00003953 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
3954 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003955 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00003956 move(First),
3957 move(Second));
3958}
Mike Stump11289f42009-09-09 15:08:12 +00003959
Douglas Gregora16548e2009-08-11 05:31:07 +00003960template<typename Derived>
3961Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003962TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003963 return getDerived().TransformCallExpr(E);
3964}
Mike Stump11289f42009-09-09 15:08:12 +00003965
Douglas Gregora16548e2009-08-11 05:31:07 +00003966template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003967Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003968TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
3969 QualType ExplicitTy;
3970 {
3971 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003972 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003973 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
3974 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003975
Douglas Gregora16548e2009-08-11 05:31:07 +00003976 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
3977 if (ExplicitTy.isNull())
3978 return SemaRef.ExprError();
3979 }
Mike Stump11289f42009-09-09 15:08:12 +00003980
Douglas Gregora16548e2009-08-11 05:31:07 +00003981 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3982 if (SubExpr.isInvalid())
3983 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003984
Douglas Gregora16548e2009-08-11 05:31:07 +00003985 if (!getDerived().AlwaysRebuild() &&
3986 ExplicitTy == E->getTypeAsWritten() &&
3987 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003988 return SemaRef.Owned(E->Retain());
3989
Douglas Gregora16548e2009-08-11 05:31:07 +00003990 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00003991 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003992 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
3993 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
3994 SourceLocation FakeRParenLoc
3995 = SemaRef.PP.getLocForEndOfToken(
3996 E->getSubExpr()->getSourceRange().getEnd());
3997 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003998 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003999 FakeLAngleLoc,
4000 ExplicitTy,
4001 FakeRAngleLoc,
4002 FakeRAngleLoc,
4003 move(SubExpr),
4004 FakeRParenLoc);
4005}
Mike Stump11289f42009-09-09 15:08:12 +00004006
Douglas Gregora16548e2009-08-11 05:31:07 +00004007template<typename Derived>
4008Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004009TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004010 return getDerived().TransformCXXNamedCastExpr(E);
4011}
Mike Stump11289f42009-09-09 15:08:12 +00004012
4013template<typename Derived>
4014Sema::OwningExprResult
4015TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4016 return getDerived().TransformCXXNamedCastExpr(E);
4017}
4018
Douglas Gregora16548e2009-08-11 05:31:07 +00004019template<typename Derived>
4020Sema::OwningExprResult
4021TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004022 CXXReinterpretCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004023 return getDerived().TransformCXXNamedCastExpr(E);
4024}
Mike Stump11289f42009-09-09 15:08:12 +00004025
Douglas Gregora16548e2009-08-11 05:31:07 +00004026template<typename Derived>
4027Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004028TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004029 return getDerived().TransformCXXNamedCastExpr(E);
4030}
Mike Stump11289f42009-09-09 15:08:12 +00004031
Douglas Gregora16548e2009-08-11 05:31:07 +00004032template<typename Derived>
4033Sema::OwningExprResult
4034TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004035 CXXFunctionalCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004036 QualType ExplicitTy;
4037 {
4038 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004039
Douglas Gregora16548e2009-08-11 05:31:07 +00004040 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4041 if (ExplicitTy.isNull())
4042 return SemaRef.ExprError();
4043 }
Mike Stump11289f42009-09-09 15:08:12 +00004044
Douglas Gregora16548e2009-08-11 05:31:07 +00004045 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4046 if (SubExpr.isInvalid())
4047 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004048
Douglas Gregora16548e2009-08-11 05:31:07 +00004049 if (!getDerived().AlwaysRebuild() &&
4050 ExplicitTy == E->getTypeAsWritten() &&
4051 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004052 return SemaRef.Owned(E->Retain());
4053
Douglas Gregora16548e2009-08-11 05:31:07 +00004054 // FIXME: The end of the type's source range is wrong
4055 return getDerived().RebuildCXXFunctionalCastExpr(
4056 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
4057 ExplicitTy,
4058 /*FIXME:*/E->getSubExpr()->getLocStart(),
4059 move(SubExpr),
4060 E->getRParenLoc());
4061}
Mike Stump11289f42009-09-09 15:08:12 +00004062
Douglas Gregora16548e2009-08-11 05:31:07 +00004063template<typename Derived>
4064Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004065TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004066 if (E->isTypeOperand()) {
4067 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004068
Douglas Gregora16548e2009-08-11 05:31:07 +00004069 QualType T = getDerived().TransformType(E->getTypeOperand());
4070 if (T.isNull())
4071 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004072
Douglas Gregora16548e2009-08-11 05:31:07 +00004073 if (!getDerived().AlwaysRebuild() &&
4074 T == E->getTypeOperand())
4075 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004076
Douglas Gregora16548e2009-08-11 05:31:07 +00004077 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4078 /*FIXME:*/E->getLocStart(),
4079 T,
4080 E->getLocEnd());
4081 }
Mike Stump11289f42009-09-09 15:08:12 +00004082
Douglas Gregora16548e2009-08-11 05:31:07 +00004083 // We don't know whether the expression is potentially evaluated until
4084 // after we perform semantic analysis, so the expression is potentially
4085 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004086 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004087 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004088
Douglas Gregora16548e2009-08-11 05:31:07 +00004089 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4090 if (SubExpr.isInvalid())
4091 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004092
Douglas Gregora16548e2009-08-11 05:31:07 +00004093 if (!getDerived().AlwaysRebuild() &&
4094 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004095 return SemaRef.Owned(E->Retain());
4096
Douglas Gregora16548e2009-08-11 05:31:07 +00004097 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4098 /*FIXME:*/E->getLocStart(),
4099 move(SubExpr),
4100 E->getLocEnd());
4101}
4102
4103template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004104Sema::OwningExprResult
4105TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
4106 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004107}
Mike Stump11289f42009-09-09 15:08:12 +00004108
Douglas Gregora16548e2009-08-11 05:31:07 +00004109template<typename Derived>
4110Sema::OwningExprResult
4111TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004112 CXXNullPtrLiteralExpr *E) {
4113 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004114}
Mike Stump11289f42009-09-09 15:08:12 +00004115
Douglas Gregora16548e2009-08-11 05:31:07 +00004116template<typename Derived>
4117Sema::OwningExprResult
4118TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
4119 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004120
Douglas Gregora16548e2009-08-11 05:31:07 +00004121 QualType T = getDerived().TransformType(E->getType());
4122 if (T.isNull())
4123 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004124
Douglas Gregora16548e2009-08-11 05:31:07 +00004125 if (!getDerived().AlwaysRebuild() &&
4126 T == E->getType())
4127 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004128
Douglas Gregora16548e2009-08-11 05:31:07 +00004129 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T);
4130}
Mike Stump11289f42009-09-09 15:08:12 +00004131
Douglas Gregora16548e2009-08-11 05:31:07 +00004132template<typename Derived>
4133Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004134TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004135 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4136 if (SubExpr.isInvalid())
4137 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004138
Douglas Gregora16548e2009-08-11 05:31:07 +00004139 if (!getDerived().AlwaysRebuild() &&
4140 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004141 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004142
4143 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4144}
Mike Stump11289f42009-09-09 15:08:12 +00004145
Douglas Gregora16548e2009-08-11 05:31:07 +00004146template<typename Derived>
4147Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004148TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
4149 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004150 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4151 if (!Param)
4152 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004153
Douglas Gregora16548e2009-08-11 05:31:07 +00004154 if (getDerived().AlwaysRebuild() &&
4155 Param == E->getParam())
4156 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004157
Douglas Gregora16548e2009-08-11 05:31:07 +00004158 return getDerived().RebuildCXXDefaultArgExpr(Param);
4159}
Mike Stump11289f42009-09-09 15:08:12 +00004160
Douglas Gregora16548e2009-08-11 05:31:07 +00004161template<typename Derived>
4162Sema::OwningExprResult
4163TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
4164 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4165
4166 QualType T = getDerived().TransformType(E->getType());
4167 if (T.isNull())
4168 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004169
Douglas Gregora16548e2009-08-11 05:31:07 +00004170 if (!getDerived().AlwaysRebuild() &&
4171 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004172 return SemaRef.Owned(E->Retain());
4173
4174 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004175 /*FIXME:*/E->getTypeBeginLoc(),
4176 T,
4177 E->getRParenLoc());
4178}
Mike Stump11289f42009-09-09 15:08:12 +00004179
Douglas Gregora16548e2009-08-11 05:31:07 +00004180template<typename Derived>
4181Sema::OwningExprResult
4182TreeTransform<Derived>::TransformCXXConditionDeclExpr(CXXConditionDeclExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004183 VarDecl *Var
Douglas Gregorebe10102009-08-20 07:17:43 +00004184 = cast_or_null<VarDecl>(getDerived().TransformDefinition(E->getVarDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004185 if (!Var)
4186 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004187
Douglas Gregora16548e2009-08-11 05:31:07 +00004188 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004189 Var == E->getVarDecl())
Douglas Gregora16548e2009-08-11 05:31:07 +00004190 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004191
4192 return getDerived().RebuildCXXConditionDeclExpr(E->getStartLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004193 /*FIXME:*/E->getStartLoc(),
4194 Var);
4195}
Mike Stump11289f42009-09-09 15:08:12 +00004196
Douglas Gregora16548e2009-08-11 05:31:07 +00004197template<typename Derived>
4198Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004199TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004200 // Transform the type that we're allocating
4201 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4202 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4203 if (AllocType.isNull())
4204 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004205
Douglas Gregora16548e2009-08-11 05:31:07 +00004206 // Transform the size of the array we're allocating (if any).
4207 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4208 if (ArraySize.isInvalid())
4209 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004210
Douglas Gregora16548e2009-08-11 05:31:07 +00004211 // Transform the placement arguments (if any).
4212 bool ArgumentChanged = false;
4213 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4214 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4215 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4216 if (Arg.isInvalid())
4217 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004218
Douglas Gregora16548e2009-08-11 05:31:07 +00004219 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4220 PlacementArgs.push_back(Arg.take());
4221 }
Mike Stump11289f42009-09-09 15:08:12 +00004222
Douglas Gregorebe10102009-08-20 07:17:43 +00004223 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004224 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4225 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4226 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4227 if (Arg.isInvalid())
4228 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004229
Douglas Gregora16548e2009-08-11 05:31:07 +00004230 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4231 ConstructorArgs.push_back(Arg.take());
4232 }
Mike Stump11289f42009-09-09 15:08:12 +00004233
Douglas Gregora16548e2009-08-11 05:31:07 +00004234 if (!getDerived().AlwaysRebuild() &&
4235 AllocType == E->getAllocatedType() &&
4236 ArraySize.get() == E->getArraySize() &&
4237 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004238 return SemaRef.Owned(E->Retain());
4239
Douglas Gregora16548e2009-08-11 05:31:07 +00004240 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4241 E->isGlobalNew(),
4242 /*FIXME:*/E->getLocStart(),
4243 move_arg(PlacementArgs),
4244 /*FIXME:*/E->getLocStart(),
4245 E->isParenTypeId(),
4246 AllocType,
4247 /*FIXME:*/E->getLocStart(),
4248 /*FIXME:*/SourceRange(),
4249 move(ArraySize),
4250 /*FIXME:*/E->getLocStart(),
4251 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004252 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004253}
Mike Stump11289f42009-09-09 15:08:12 +00004254
Douglas Gregora16548e2009-08-11 05:31:07 +00004255template<typename Derived>
4256Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004257TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004258 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4259 if (Operand.isInvalid())
4260 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004261
Douglas Gregora16548e2009-08-11 05:31:07 +00004262 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004263 Operand.get() == E->getArgument())
4264 return SemaRef.Owned(E->Retain());
4265
Douglas Gregora16548e2009-08-11 05:31:07 +00004266 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4267 E->isGlobalDelete(),
4268 E->isArrayForm(),
4269 move(Operand));
4270}
Mike Stump11289f42009-09-09 15:08:12 +00004271
Douglas Gregora16548e2009-08-11 05:31:07 +00004272template<typename Derived>
4273Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004274TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
4275 CXXPseudoDestructorExpr *E) {
4276 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4277 if (Base.isInvalid())
4278 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004279
Douglas Gregorad8a3362009-09-04 17:36:40 +00004280 NestedNameSpecifier *Qualifier
4281 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4282 E->getQualifierRange());
4283 if (E->getQualifier() && !Qualifier)
4284 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004285
Douglas Gregorad8a3362009-09-04 17:36:40 +00004286 QualType DestroyedType;
4287 {
4288 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4289 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4290 if (DestroyedType.isNull())
4291 return SemaRef.ExprError();
4292 }
Mike Stump11289f42009-09-09 15:08:12 +00004293
Douglas Gregorad8a3362009-09-04 17:36:40 +00004294 if (!getDerived().AlwaysRebuild() &&
4295 Base.get() == E->getBase() &&
4296 Qualifier == E->getQualifier() &&
4297 DestroyedType == E->getDestroyedType())
4298 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004299
Douglas Gregorad8a3362009-09-04 17:36:40 +00004300 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4301 E->getOperatorLoc(),
4302 E->isArrow(),
4303 E->getDestroyedTypeLoc(),
4304 DestroyedType,
4305 Qualifier,
4306 E->getQualifierRange());
4307}
Mike Stump11289f42009-09-09 15:08:12 +00004308
Douglas Gregorad8a3362009-09-04 17:36:40 +00004309template<typename Derived>
4310Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004311TreeTransform<Derived>::TransformUnresolvedFunctionNameExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004312 UnresolvedFunctionNameExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004313 // There is no transformation we can apply to an unresolved function name.
Mike Stump11289f42009-09-09 15:08:12 +00004314 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004315}
Mike Stump11289f42009-09-09 15:08:12 +00004316
Douglas Gregora16548e2009-08-11 05:31:07 +00004317template<typename Derived>
4318Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004319TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004320 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004321
Douglas Gregora16548e2009-08-11 05:31:07 +00004322 QualType T = getDerived().TransformType(E->getQueriedType());
4323 if (T.isNull())
4324 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004325
Douglas Gregora16548e2009-08-11 05:31:07 +00004326 if (!getDerived().AlwaysRebuild() &&
4327 T == E->getQueriedType())
4328 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004329
Douglas Gregora16548e2009-08-11 05:31:07 +00004330 // FIXME: Bad location information
4331 SourceLocation FakeLParenLoc
4332 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004333
4334 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004335 E->getLocStart(),
4336 /*FIXME:*/FakeLParenLoc,
4337 T,
4338 E->getLocEnd());
4339}
Mike Stump11289f42009-09-09 15:08:12 +00004340
Douglas Gregora16548e2009-08-11 05:31:07 +00004341template<typename Derived>
4342Sema::OwningExprResult
4343TreeTransform<Derived>::TransformQualifiedDeclRefExpr(QualifiedDeclRefExpr *E) {
4344 NestedNameSpecifier *NNS
4345 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4346 E->getQualifierRange());
4347 if (!NNS)
4348 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004349
4350 NamedDecl *ND
Douglas Gregora16548e2009-08-11 05:31:07 +00004351 = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl()));
4352 if (!ND)
4353 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004354
4355 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004356 NNS == E->getQualifier() &&
4357 ND == E->getDecl())
Mike Stump11289f42009-09-09 15:08:12 +00004358 return SemaRef.Owned(E->Retain());
4359
4360 return getDerived().RebuildQualifiedDeclRefExpr(NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00004361 E->getQualifierRange(),
4362 ND,
4363 E->getLocation(),
4364 /*FIXME:*/false);
4365}
Mike Stump11289f42009-09-09 15:08:12 +00004366
Douglas Gregora16548e2009-08-11 05:31:07 +00004367template<typename Derived>
4368Sema::OwningExprResult
4369TreeTransform<Derived>::TransformUnresolvedDeclRefExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004370 UnresolvedDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004371 NestedNameSpecifier *NNS
4372 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4373 E->getQualifierRange());
4374 if (!NNS)
4375 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004376
4377 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004378 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4379 if (!Name)
4380 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004381
4382 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004383 NNS == E->getQualifier() &&
4384 Name == E->getDeclName())
Mike Stump11289f42009-09-09 15:08:12 +00004385 return SemaRef.Owned(E->Retain());
4386
4387 return getDerived().RebuildUnresolvedDeclRefExpr(NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00004388 E->getQualifierRange(),
4389 Name,
4390 E->getLocation(),
4391 /*FIXME:*/false);
4392}
4393
4394template<typename Derived>
4395Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004396TreeTransform<Derived>::TransformTemplateIdRefExpr(TemplateIdRefExpr *E) {
4397 TemplateName Template
Douglas Gregora16548e2009-08-11 05:31:07 +00004398 = getDerived().TransformTemplateName(E->getTemplateName());
4399 if (Template.isNull())
4400 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004401
Douglas Gregora16548e2009-08-11 05:31:07 +00004402 llvm::SmallVector<TemplateArgument, 4> TransArgs;
4403 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004404 TemplateArgument TransArg
Douglas Gregora16548e2009-08-11 05:31:07 +00004405 = getDerived().TransformTemplateArgument(E->getTemplateArgs()[I]);
4406 if (TransArg.isNull())
4407 return SemaRef.ExprError();
4408
4409 TransArgs.push_back(TransArg);
4410 }
4411
4412 // FIXME: Would like to avoid rebuilding if nothing changed, but we can't
4413 // compare template arguments (yet).
Mike Stump11289f42009-09-09 15:08:12 +00004414
4415 // FIXME: It's possible that we'll find out now that the template name
Douglas Gregora16548e2009-08-11 05:31:07 +00004416 // actually refers to a type, in which case the caller is actually dealing
4417 // with a functional cast. Give a reasonable error message!
4418 return getDerived().RebuildTemplateIdExpr(Template, E->getTemplateNameLoc(),
4419 E->getLAngleLoc(),
4420 TransArgs.data(),
4421 TransArgs.size(),
4422 E->getRAngleLoc());
4423}
4424
4425template<typename Derived>
4426Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004427TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004428 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4429
4430 QualType T = getDerived().TransformType(E->getType());
4431 if (T.isNull())
4432 return SemaRef.ExprError();
4433
4434 CXXConstructorDecl *Constructor
4435 = cast_or_null<CXXConstructorDecl>(
4436 getDerived().TransformDecl(E->getConstructor()));
4437 if (!Constructor)
4438 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004439
Douglas Gregora16548e2009-08-11 05:31:07 +00004440 bool ArgumentChanged = false;
4441 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004442 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004443 ArgEnd = E->arg_end();
4444 Arg != ArgEnd; ++Arg) {
4445 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4446 if (TransArg.isInvalid())
4447 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004448
Douglas Gregora16548e2009-08-11 05:31:07 +00004449 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4450 Args.push_back(TransArg.takeAs<Expr>());
4451 }
4452
4453 if (!getDerived().AlwaysRebuild() &&
4454 T == E->getType() &&
4455 Constructor == E->getConstructor() &&
4456 !ArgumentChanged)
4457 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004458
Douglas Gregora16548e2009-08-11 05:31:07 +00004459 return getDerived().RebuildCXXConstructExpr(T, Constructor, E->isElidable(),
4460 move_arg(Args));
4461}
Mike Stump11289f42009-09-09 15:08:12 +00004462
Douglas Gregora16548e2009-08-11 05:31:07 +00004463/// \brief Transform a C++ temporary-binding expression.
4464///
Mike Stump11289f42009-09-09 15:08:12 +00004465/// The transformation of a temporary-binding expression always attempts to
4466/// bind a new temporary variable to its subexpression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004467/// subexpression itself did not change, because the temporary variable itself
4468/// must be unique.
4469template<typename Derived>
4470Sema::OwningExprResult
4471TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
4472 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4473 if (SubExpr.isInvalid())
4474 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004475
Douglas Gregora16548e2009-08-11 05:31:07 +00004476 return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>());
4477}
Mike Stump11289f42009-09-09 15:08:12 +00004478
4479/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004480/// be destroyed after the expression is evaluated.
4481///
Mike Stump11289f42009-09-09 15:08:12 +00004482/// The transformation of a full expression always attempts to build a new
4483/// CXXExprWithTemporaries expression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004484/// subexpression itself did not change, because it will need to capture the
4485/// the new temporary variables introduced in the subexpression.
4486template<typename Derived>
4487Sema::OwningExprResult
4488TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Mike Stump11289f42009-09-09 15:08:12 +00004489 CXXExprWithTemporaries *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004490 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4491 if (SubExpr.isInvalid())
4492 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004493
Douglas Gregora16548e2009-08-11 05:31:07 +00004494 return SemaRef.Owned(
4495 SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(),
4496 E->shouldDestroyTemporaries()));
4497}
Mike Stump11289f42009-09-09 15:08:12 +00004498
Douglas Gregora16548e2009-08-11 05:31:07 +00004499template<typename Derived>
4500Sema::OwningExprResult
4501TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004502 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004503 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4504 QualType T = getDerived().TransformType(E->getType());
4505 if (T.isNull())
4506 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004507
Douglas Gregora16548e2009-08-11 05:31:07 +00004508 CXXConstructorDecl *Constructor
4509 = cast_or_null<CXXConstructorDecl>(
4510 getDerived().TransformDecl(E->getConstructor()));
4511 if (!Constructor)
4512 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004513
Douglas Gregora16548e2009-08-11 05:31:07 +00004514 bool ArgumentChanged = false;
4515 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4516 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004517 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004518 ArgEnd = E->arg_end();
4519 Arg != ArgEnd; ++Arg) {
4520 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4521 if (TransArg.isInvalid())
4522 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004523
Douglas Gregora16548e2009-08-11 05:31:07 +00004524 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4525 Args.push_back((Expr *)TransArg.release());
4526 }
Mike Stump11289f42009-09-09 15:08:12 +00004527
Douglas Gregora16548e2009-08-11 05:31:07 +00004528 if (!getDerived().AlwaysRebuild() &&
4529 T == E->getType() &&
4530 Constructor == E->getConstructor() &&
4531 !ArgumentChanged)
4532 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004533
Douglas Gregora16548e2009-08-11 05:31:07 +00004534 // FIXME: Bogus location information
4535 SourceLocation CommaLoc;
4536 if (Args.size() > 1) {
4537 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004538 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004539 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4540 }
4541 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4542 T,
4543 /*FIXME:*/E->getTypeBeginLoc(),
4544 move_arg(Args),
4545 &CommaLoc,
4546 E->getLocEnd());
4547}
Mike Stump11289f42009-09-09 15:08:12 +00004548
Douglas Gregora16548e2009-08-11 05:31:07 +00004549template<typename Derived>
4550Sema::OwningExprResult
4551TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004552 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004553 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4554 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4555 if (T.isNull())
4556 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004557
Douglas Gregora16548e2009-08-11 05:31:07 +00004558 bool ArgumentChanged = false;
4559 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4560 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4561 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4562 ArgEnd = E->arg_end();
4563 Arg != ArgEnd; ++Arg) {
4564 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4565 if (TransArg.isInvalid())
4566 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004567
Douglas Gregora16548e2009-08-11 05:31:07 +00004568 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4569 FakeCommaLocs.push_back(
4570 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4571 Args.push_back(TransArg.takeAs<Expr>());
4572 }
Mike Stump11289f42009-09-09 15:08:12 +00004573
Douglas Gregora16548e2009-08-11 05:31:07 +00004574 if (!getDerived().AlwaysRebuild() &&
4575 T == E->getTypeAsWritten() &&
4576 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004577 return SemaRef.Owned(E->Retain());
4578
Douglas Gregora16548e2009-08-11 05:31:07 +00004579 // FIXME: we're faking the locations of the commas
4580 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4581 T,
4582 E->getLParenLoc(),
4583 move_arg(Args),
4584 FakeCommaLocs.data(),
4585 E->getRParenLoc());
4586}
Mike Stump11289f42009-09-09 15:08:12 +00004587
Douglas Gregora16548e2009-08-11 05:31:07 +00004588template<typename Derived>
4589Sema::OwningExprResult
4590TreeTransform<Derived>::TransformCXXUnresolvedMemberExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004591 CXXUnresolvedMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004592 // Transform the base of the expression.
4593 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4594 if (Base.isInvalid())
4595 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004596
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004597 // Start the member reference and compute the object's type.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004598 Sema::TypeTy *ObjectType = 0;
Mike Stump11289f42009-09-09 15:08:12 +00004599 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004600 E->getOperatorLoc(),
4601 E->isArrow()? tok::arrow : tok::period,
4602 ObjectType);
4603 if (Base.isInvalid())
4604 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004605
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004606 // Transform the first part of the nested-name-specifier that qualifies
4607 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004608 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004609 = getDerived().TransformFirstQualifierInScope(
4610 E->getFirstQualifierFoundInScope(),
4611 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00004612
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004613 NestedNameSpecifier *Qualifier = 0;
4614 if (E->getQualifier()) {
4615 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4616 E->getQualifierRange(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004617 QualType::getFromOpaquePtr(ObjectType),
4618 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004619 if (!Qualifier)
4620 return SemaRef.ExprError();
4621 }
Mike Stump11289f42009-09-09 15:08:12 +00004622
4623 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00004624 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
4625 QualType::getFromOpaquePtr(ObjectType));
Douglas Gregorf816bd72009-09-03 22:13:48 +00004626 if (!Name)
4627 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004628
Douglas Gregor308047d2009-09-09 00:23:06 +00004629 if (!E->hasExplicitTemplateArgumentList()) {
4630 // This is a reference to a member without an explicitly-specified
4631 // template argument list. Optimize for this common case.
4632 if (!getDerived().AlwaysRebuild() &&
4633 Base.get() == E->getBase() &&
4634 Qualifier == E->getQualifier() &&
4635 Name == E->getMember() &&
4636 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00004637 return SemaRef.Owned(E->Retain());
4638
Douglas Gregor308047d2009-09-09 00:23:06 +00004639 return getDerived().RebuildCXXUnresolvedMemberExpr(move(Base),
4640 E->isArrow(),
4641 E->getOperatorLoc(),
4642 Qualifier,
4643 E->getQualifierRange(),
4644 Name,
4645 E->getMemberLoc(),
4646 FirstQualifierInScope);
4647 }
4648
4649 // FIXME: This is an ugly hack, which forces the same template name to
4650 // be looked up multiple times. Yuck!
4651 // FIXME: This also won't work for, e.g., x->template operator+<int>
4652 TemplateName OrigTemplateName
4653 = SemaRef.Context.getDependentTemplateName(0, Name.getAsIdentifierInfo());
Mike Stump11289f42009-09-09 15:08:12 +00004654
4655 TemplateName Template
4656 = getDerived().TransformTemplateName(OrigTemplateName,
Douglas Gregor308047d2009-09-09 00:23:06 +00004657 QualType::getFromOpaquePtr(ObjectType));
4658 if (Template.isNull())
4659 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004660
Douglas Gregor308047d2009-09-09 00:23:06 +00004661 llvm::SmallVector<TemplateArgument, 4> TransArgs;
4662 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004663 TemplateArgument TransArg
Douglas Gregor308047d2009-09-09 00:23:06 +00004664 = getDerived().TransformTemplateArgument(E->getTemplateArgs()[I]);
4665 if (TransArg.isNull())
4666 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004667
Douglas Gregor308047d2009-09-09 00:23:06 +00004668 TransArgs.push_back(TransArg);
4669 }
Mike Stump11289f42009-09-09 15:08:12 +00004670
Douglas Gregora16548e2009-08-11 05:31:07 +00004671 return getDerived().RebuildCXXUnresolvedMemberExpr(move(Base),
4672 E->isArrow(),
4673 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004674 Qualifier,
4675 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004676 Template,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004677 E->getMemberLoc(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004678 FirstQualifierInScope,
4679 E->getLAngleLoc(),
4680 TransArgs.data(),
4681 TransArgs.size(),
4682 E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004683}
4684
4685template<typename Derived>
4686Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004687TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
4688 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004689}
4690
Mike Stump11289f42009-09-09 15:08:12 +00004691template<typename Derived>
4692Sema::OwningExprResult
4693TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004694 // FIXME: poor source location
4695 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
4696 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
4697 if (EncodedType.isNull())
4698 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004699
Douglas Gregora16548e2009-08-11 05:31:07 +00004700 if (!getDerived().AlwaysRebuild() &&
4701 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00004702 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004703
4704 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
4705 EncodedType,
4706 E->getRParenLoc());
4707}
Mike Stump11289f42009-09-09 15:08:12 +00004708
Douglas Gregora16548e2009-08-11 05:31:07 +00004709template<typename Derived>
4710Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004711TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004712 // FIXME: Implement this!
4713 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004714 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004715}
4716
Mike Stump11289f42009-09-09 15:08:12 +00004717template<typename Derived>
4718Sema::OwningExprResult
4719TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
4720 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004721}
4722
Mike Stump11289f42009-09-09 15:08:12 +00004723template<typename Derived>
4724Sema::OwningExprResult
4725TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
4726 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00004727 = cast_or_null<ObjCProtocolDecl>(
4728 getDerived().TransformDecl(E->getProtocol()));
4729 if (!Protocol)
4730 return SemaRef.ExprError();
4731
4732 if (!getDerived().AlwaysRebuild() &&
4733 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00004734 return SemaRef.Owned(E->Retain());
4735
Douglas Gregora16548e2009-08-11 05:31:07 +00004736 return getDerived().RebuildObjCProtocolExpr(Protocol,
4737 E->getAtLoc(),
4738 /*FIXME:*/E->getAtLoc(),
4739 /*FIXME:*/E->getAtLoc(),
4740 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004741
Douglas Gregora16548e2009-08-11 05:31:07 +00004742}
4743
Mike Stump11289f42009-09-09 15:08:12 +00004744template<typename Derived>
4745Sema::OwningExprResult
4746TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004747 // FIXME: Implement this!
4748 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004749 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004750}
4751
Mike Stump11289f42009-09-09 15:08:12 +00004752template<typename Derived>
4753Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004754TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
4755 // FIXME: Implement this!
4756 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004757 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004758}
4759
Mike Stump11289f42009-09-09 15:08:12 +00004760template<typename Derived>
4761Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00004762TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004763 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004764 // FIXME: Implement this!
4765 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004766 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004767}
4768
Mike Stump11289f42009-09-09 15:08:12 +00004769template<typename Derived>
4770Sema::OwningExprResult
4771TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004772 // FIXME: Implement this!
4773 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004774 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004775}
4776
Mike Stump11289f42009-09-09 15:08:12 +00004777template<typename Derived>
4778Sema::OwningExprResult
4779TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004780 // FIXME: Implement this!
4781 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004782 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004783}
4784
Mike Stump11289f42009-09-09 15:08:12 +00004785template<typename Derived>
4786Sema::OwningExprResult
4787TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004788 bool ArgumentChanged = false;
4789 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
4790 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
4791 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
4792 if (SubExpr.isInvalid())
4793 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004794
Douglas Gregora16548e2009-08-11 05:31:07 +00004795 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
4796 SubExprs.push_back(SubExpr.takeAs<Expr>());
4797 }
Mike Stump11289f42009-09-09 15:08:12 +00004798
Douglas Gregora16548e2009-08-11 05:31:07 +00004799 if (!getDerived().AlwaysRebuild() &&
4800 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004801 return SemaRef.Owned(E->Retain());
4802
Douglas Gregora16548e2009-08-11 05:31:07 +00004803 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
4804 move_arg(SubExprs),
4805 E->getRParenLoc());
4806}
4807
Mike Stump11289f42009-09-09 15:08:12 +00004808template<typename Derived>
4809Sema::OwningExprResult
4810TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004811 // FIXME: Implement this!
4812 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004813 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004814}
4815
Mike Stump11289f42009-09-09 15:08:12 +00004816template<typename Derived>
4817Sema::OwningExprResult
4818TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004819 // FIXME: Implement this!
4820 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004821 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004822}
Mike Stump11289f42009-09-09 15:08:12 +00004823
Douglas Gregora16548e2009-08-11 05:31:07 +00004824//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00004825// Type reconstruction
4826//===----------------------------------------------------------------------===//
4827
Mike Stump11289f42009-09-09 15:08:12 +00004828template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004829QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004830 return SemaRef.BuildPointerType(PointeeType, Qualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004831 getDerived().getBaseLocation(),
4832 getDerived().getBaseEntity());
4833}
4834
Mike Stump11289f42009-09-09 15:08:12 +00004835template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004836QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004837 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004838 getDerived().getBaseLocation(),
4839 getDerived().getBaseEntity());
4840}
4841
Mike Stump11289f42009-09-09 15:08:12 +00004842template<typename Derived>
4843QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00004844TreeTransform<Derived>::RebuildLValueReferenceType(QualType ReferentType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004845 return SemaRef.BuildReferenceType(ReferentType, true, Qualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004846 getDerived().getBaseLocation(),
4847 getDerived().getBaseEntity());
4848}
4849
4850template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004851QualType
4852TreeTransform<Derived>::RebuildRValueReferenceType(QualType ReferentType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004853 return SemaRef.BuildReferenceType(ReferentType, false, Qualifiers(),
Mike Stump11289f42009-09-09 15:08:12 +00004854 getDerived().getBaseLocation(),
4855 getDerived().getBaseEntity());
4856}
4857
4858template<typename Derived>
4859QualType TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004860 QualType ClassType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004861 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004862 getDerived().getBaseLocation(),
4863 getDerived().getBaseEntity());
4864}
4865
4866template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004867QualType
John McCall550e0c22009-10-21 00:40:46 +00004868TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType) {
4869 return SemaRef.BuildPointerType(PointeeType, Qualifiers(),
4870 getDerived().getBaseLocation(),
4871 getDerived().getBaseEntity());
4872}
4873
4874template<typename Derived>
4875QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00004876TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
4877 ArrayType::ArraySizeModifier SizeMod,
4878 const llvm::APInt *Size,
4879 Expr *SizeExpr,
4880 unsigned IndexTypeQuals,
4881 SourceRange BracketsRange) {
4882 if (SizeExpr || !Size)
4883 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
4884 IndexTypeQuals, BracketsRange,
4885 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00004886
4887 QualType Types[] = {
4888 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
4889 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
4890 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00004891 };
4892 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
4893 QualType SizeType;
4894 for (unsigned I = 0; I != NumTypes; ++I)
4895 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
4896 SizeType = Types[I];
4897 break;
4898 }
Mike Stump11289f42009-09-09 15:08:12 +00004899
Douglas Gregord6ff3322009-08-04 16:50:30 +00004900 if (SizeType.isNull())
4901 SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false);
Mike Stump11289f42009-09-09 15:08:12 +00004902
Douglas Gregord6ff3322009-08-04 16:50:30 +00004903 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00004904 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004905 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00004906 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004907}
Mike Stump11289f42009-09-09 15:08:12 +00004908
Douglas Gregord6ff3322009-08-04 16:50:30 +00004909template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004910QualType
4911TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004912 ArrayType::ArraySizeModifier SizeMod,
4913 const llvm::APInt &Size,
4914 unsigned IndexTypeQuals) {
Mike Stump11289f42009-09-09 15:08:12 +00004915 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004916 IndexTypeQuals, SourceRange());
4917}
4918
4919template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004920QualType
Mike Stump11289f42009-09-09 15:08:12 +00004921TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004922 ArrayType::ArraySizeModifier SizeMod,
4923 unsigned IndexTypeQuals) {
Mike Stump11289f42009-09-09 15:08:12 +00004924 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004925 IndexTypeQuals, SourceRange());
4926}
Mike Stump11289f42009-09-09 15:08:12 +00004927
Douglas Gregord6ff3322009-08-04 16:50:30 +00004928template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004929QualType
4930TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004931 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00004932 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004933 unsigned IndexTypeQuals,
4934 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00004935 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004936 SizeExpr.takeAs<Expr>(),
4937 IndexTypeQuals, BracketsRange);
4938}
4939
4940template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004941QualType
4942TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004943 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00004944 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004945 unsigned IndexTypeQuals,
4946 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00004947 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004948 SizeExpr.takeAs<Expr>(),
4949 IndexTypeQuals, BracketsRange);
4950}
4951
4952template<typename Derived>
4953QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
4954 unsigned NumElements) {
4955 // FIXME: semantic checking!
4956 return SemaRef.Context.getVectorType(ElementType, NumElements);
4957}
Mike Stump11289f42009-09-09 15:08:12 +00004958
Douglas Gregord6ff3322009-08-04 16:50:30 +00004959template<typename Derived>
4960QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
4961 unsigned NumElements,
4962 SourceLocation AttributeLoc) {
4963 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
4964 NumElements, true);
4965 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00004966 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004967 AttributeLoc);
4968 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
4969 AttributeLoc);
4970}
Mike Stump11289f42009-09-09 15:08:12 +00004971
Douglas Gregord6ff3322009-08-04 16:50:30 +00004972template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004973QualType
4974TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00004975 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004976 SourceLocation AttributeLoc) {
4977 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
4978}
Mike Stump11289f42009-09-09 15:08:12 +00004979
Douglas Gregord6ff3322009-08-04 16:50:30 +00004980template<typename Derived>
4981QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00004982 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004983 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00004984 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004985 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00004986 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004987 Quals,
4988 getDerived().getBaseLocation(),
4989 getDerived().getBaseEntity());
4990}
Mike Stump11289f42009-09-09 15:08:12 +00004991
Douglas Gregord6ff3322009-08-04 16:50:30 +00004992template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004993QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
4994 return SemaRef.Context.getFunctionNoProtoType(T);
4995}
4996
4997template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004998QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004999 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5000}
5001
5002template<typename Derived>
5003QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5004 return SemaRef.Context.getTypeOfType(Underlying);
5005}
5006
5007template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005008QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005009 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5010}
5011
5012template<typename Derived>
5013QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
5014 TemplateName Template,
5015 const TemplateArgument *Args,
5016 unsigned NumArgs) {
5017 // FIXME: Missing source locations for the template name, <, >.
5018 return SemaRef.CheckTemplateIdType(Template, getDerived().getBaseLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00005019 SourceLocation(), Args, NumArgs,
5020 SourceLocation());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005021}
Mike Stump11289f42009-09-09 15:08:12 +00005022
Douglas Gregor1135c352009-08-06 05:28:30 +00005023template<typename Derived>
5024NestedNameSpecifier *
5025TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5026 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005027 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005028 QualType ObjectType,
5029 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005030 CXXScopeSpec SS;
5031 // FIXME: The source location information is all wrong.
5032 SS.setRange(Range);
5033 SS.setScopeRep(Prefix);
5034 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005035 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005036 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005037 ObjectType,
5038 FirstQualifierInScope,
Douglas Gregore861bac2009-08-25 22:51:20 +00005039 false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005040}
5041
5042template<typename Derived>
5043NestedNameSpecifier *
5044TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5045 SourceRange Range,
5046 NamespaceDecl *NS) {
5047 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5048}
5049
5050template<typename Derived>
5051NestedNameSpecifier *
5052TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5053 SourceRange Range,
5054 bool TemplateKW,
5055 QualType T) {
5056 if (T->isDependentType() || T->isRecordType() ||
5057 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
John McCall8ccfcb52009-09-24 19:53:00 +00005058 assert(!T.hasQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005059 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5060 T.getTypePtr());
5061 }
Mike Stump11289f42009-09-09 15:08:12 +00005062
Douglas Gregor1135c352009-08-06 05:28:30 +00005063 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5064 return 0;
5065}
Mike Stump11289f42009-09-09 15:08:12 +00005066
Douglas Gregor71dc5092009-08-06 06:41:21 +00005067template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005068TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005069TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5070 bool TemplateKW,
5071 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005072 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005073 Template);
5074}
5075
5076template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005077TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005078TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5079 bool TemplateKW,
5080 OverloadedFunctionDecl *Ovl) {
5081 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, Ovl);
5082}
5083
5084template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005085TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005086TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005087 const IdentifierInfo &II,
5088 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005089 CXXScopeSpec SS;
5090 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005091 SS.setScopeRep(Qualifier);
Douglas Gregor308047d2009-09-09 00:23:06 +00005092 return getSema().ActOnDependentTemplateName(
5093 /*FIXME:*/getDerived().getBaseLocation(),
5094 II,
5095 /*FIXME:*/getDerived().getBaseLocation(),
5096 SS,
5097 ObjectType.getAsOpaquePtr())
5098 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005099}
Mike Stump11289f42009-09-09 15:08:12 +00005100
Douglas Gregora16548e2009-08-11 05:31:07 +00005101template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005102Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005103TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5104 SourceLocation OpLoc,
5105 ExprArg Callee,
5106 ExprArg First,
5107 ExprArg Second) {
5108 Expr *FirstExpr = (Expr *)First.get();
5109 Expr *SecondExpr = (Expr *)Second.get();
5110 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005111
Douglas Gregora16548e2009-08-11 05:31:07 +00005112 // Determine whether this should be a builtin operation.
5113 if (SecondExpr == 0 || isPostIncDec) {
5114 if (!FirstExpr->getType()->isOverloadableType()) {
5115 // The argument is not of overloadable type, so try to create a
5116 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005117 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005118 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005119
Douglas Gregora16548e2009-08-11 05:31:07 +00005120 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5121 }
5122 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005123 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005124 !SecondExpr->getType()->isOverloadableType()) {
5125 // Neither of the arguments is an overloadable type, so try to
5126 // create a built-in binary operation.
5127 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005128 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005129 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5130 if (Result.isInvalid())
5131 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005132
Douglas Gregora16548e2009-08-11 05:31:07 +00005133 First.release();
5134 Second.release();
5135 return move(Result);
5136 }
5137 }
Mike Stump11289f42009-09-09 15:08:12 +00005138
5139 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005140 // used during overload resolution.
5141 Sema::FunctionSet Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005142
5143 DeclRefExpr *DRE
Douglas Gregor32e2c842009-09-01 16:58:52 +00005144 = cast<DeclRefExpr>(((Expr *)Callee.get())->IgnoreParenCasts());
Mike Stump11289f42009-09-09 15:08:12 +00005145
Douglas Gregora16548e2009-08-11 05:31:07 +00005146 // FIXME: Do we have to check
5147 // IsAcceptableNonMemberOperatorCandidate for each of these?
Douglas Gregor32e2c842009-09-01 16:58:52 +00005148 for (OverloadIterator F(DRE->getDecl()), FEnd; F != FEnd; ++F)
Douglas Gregora16548e2009-08-11 05:31:07 +00005149 Functions.insert(*F);
Mike Stump11289f42009-09-09 15:08:12 +00005150
Douglas Gregora16548e2009-08-11 05:31:07 +00005151 // Add any functions found via argument-dependent lookup.
5152 Expr *Args[2] = { FirstExpr, SecondExpr };
5153 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005154 DeclarationName OpName
Douglas Gregora16548e2009-08-11 05:31:07 +00005155 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
5156 SemaRef.ArgumentDependentLookup(OpName, Args, NumArgs, Functions);
Mike Stump11289f42009-09-09 15:08:12 +00005157
Douglas Gregora16548e2009-08-11 05:31:07 +00005158 // Create the overloaded operator invocation for unary operators.
5159 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005160 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005161 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5162 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5163 }
Mike Stump11289f42009-09-09 15:08:12 +00005164
Douglas Gregora16548e2009-08-11 05:31:07 +00005165 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005166 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005167 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005168 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005169 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5170 if (Result.isInvalid())
5171 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005172
Douglas Gregora16548e2009-08-11 05:31:07 +00005173 First.release();
5174 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005175 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005176}
Mike Stump11289f42009-09-09 15:08:12 +00005177
Douglas Gregord6ff3322009-08-04 16:50:30 +00005178} // end namespace clang
5179
5180#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H