blob: ffbf69b51aaf88a930cbc8f06e329cad028d1551 [file] [log] [blame]
Douglas Gregord6ff3322009-08-04 16:50:30 +00001//===------- TreeTransform.h - Semantic Tree Transformation ---------------===/
2//
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"
Douglas Gregora16548e2009-08-11 05:31:07 +000025#include "clang/Parse/Ownership.h"
26#include "clang/Parse/Designator.h"
27#include "clang/Lex/Preprocessor.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000028#include <algorithm>
29
30namespace clang {
Mike Stump11289f42009-09-09 15:08:12 +000031
Douglas Gregord6ff3322009-08-04 16:50:30 +000032/// \brief A semantic tree transformation that allows one to transform one
33/// abstract syntax tree into another.
34///
Mike Stump11289f42009-09-09 15:08:12 +000035/// A new tree transformation is defined by creating a new subclass \c X of
36/// \c TreeTransform<X> and then overriding certain operations to provide
37/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000038/// instantiation is implemented as a tree transformation where the
39/// transformation of TemplateTypeParmType nodes involves substituting the
40/// template arguments for their corresponding template parameters; a similar
41/// transformation is performed for non-type template parameters and
42/// template template parameters.
43///
44/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000045/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000046/// override any of the transformation or rebuild operators by providing an
47/// operation with the same signature as the default implementation. The
48/// overridding function should not be virtual.
49///
50/// Semantic tree transformations are split into two stages, either of which
51/// can be replaced by a subclass. The "transform" step transforms an AST node
52/// or the parts of an AST node using the various transformation functions,
53/// then passes the pieces on to the "rebuild" step, which constructs a new AST
54/// node of the appropriate kind from the pieces. The default transformation
55/// routines recursively transform the operands to composite AST nodes (e.g.,
56/// the pointee type of a PointerType node) and, if any of those operand nodes
57/// were changed by the transformation, invokes the rebuild operation to create
58/// a new AST node.
59///
Mike Stump11289f42009-09-09 15:08:12 +000060/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000061/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000062/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
63/// TransformTemplateName(), or TransformTemplateArgument() with entirely
64/// new implementations.
65///
66/// For more fine-grained transformations, subclasses can replace any of the
67/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000068/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000069/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000070/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000071/// parameters. Additionally, subclasses can override the \c RebuildXXX
72/// functions to control how AST nodes are rebuilt when their operands change.
73/// By default, \c TreeTransform will invoke semantic analysis to rebuild
74/// AST nodes. However, certain other tree transformations (e.g, cloning) may
75/// be able to use more efficient rebuild steps.
76///
77/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000078/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
80/// operands have not changed (\c AlwaysRebuild()), and customize the
81/// default locations and entity names used for type-checking
82/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000083template<typename Derived>
84class TreeTransform {
85protected:
86 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000087
88public:
Douglas Gregora16548e2009-08-11 05:31:07 +000089 typedef Sema::OwningStmtResult OwningStmtResult;
90 typedef Sema::OwningExprResult OwningExprResult;
91 typedef Sema::StmtArg StmtArg;
92 typedef Sema::ExprArg ExprArg;
93 typedef Sema::MultiExprArg MultiExprArg;
Douglas Gregorebe10102009-08-20 07:17:43 +000094 typedef Sema::MultiStmtArg MultiStmtArg;
Mike Stump11289f42009-09-09 15:08:12 +000095
Douglas Gregord6ff3322009-08-04 16:50:30 +000096 /// \brief Initializes a new tree transformer.
97 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +000098
Douglas Gregord6ff3322009-08-04 16:50:30 +000099 /// \brief Retrieves a reference to the derived class.
100 Derived &getDerived() { return static_cast<Derived&>(*this); }
101
102 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000103 const Derived &getDerived() const {
104 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000105 }
106
107 /// \brief Retrieves a reference to the semantic analysis object used for
108 /// this tree transform.
109 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000110
Douglas Gregord6ff3322009-08-04 16:50:30 +0000111 /// \brief Whether the transformation should always rebuild AST nodes, even
112 /// if none of the children have changed.
113 ///
114 /// Subclasses may override this function to specify when the transformation
115 /// should rebuild all AST nodes.
116 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000117
Douglas Gregord6ff3322009-08-04 16:50:30 +0000118 /// \brief Returns the location of the entity being transformed, if that
119 /// information was not available elsewhere in the AST.
120 ///
Mike Stump11289f42009-09-09 15:08:12 +0000121 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// provide an alternative implementation that provides better location
123 /// information.
124 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000125
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 /// \brief Returns the name of the entity being transformed, if that
127 /// information was not available elsewhere in the AST.
128 ///
129 /// By default, returns an empty name. Subclasses can provide an alternative
130 /// implementation with a more precise name.
131 DeclarationName getBaseEntity() { return DeclarationName(); }
132
Douglas Gregora16548e2009-08-11 05:31:07 +0000133 /// \brief Sets the "base" location and entity when that
134 /// information is known based on another transformation.
135 ///
136 /// By default, the source location and entity are ignored. Subclasses can
137 /// override this function to provide a customized implementation.
138 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Douglas Gregora16548e2009-08-11 05:31:07 +0000140 /// \brief RAII object that temporarily sets the base location and entity
141 /// used for reporting diagnostics in types.
142 class TemporaryBase {
143 TreeTransform &Self;
144 SourceLocation OldLocation;
145 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000146
Douglas Gregora16548e2009-08-11 05:31:07 +0000147 public:
148 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000149 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000150 OldLocation = Self.getDerived().getBaseLocation();
151 OldEntity = Self.getDerived().getBaseEntity();
152 Self.getDerived().setBase(Location, Entity);
153 }
Mike Stump11289f42009-09-09 15:08:12 +0000154
Douglas Gregora16548e2009-08-11 05:31:07 +0000155 ~TemporaryBase() {
156 Self.getDerived().setBase(OldLocation, OldEntity);
157 }
158 };
Mike Stump11289f42009-09-09 15:08:12 +0000159
160 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000161 /// transformed.
162 ///
163 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000164 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000165 /// not change. For example, template instantiation need not traverse
166 /// non-dependent types.
167 bool AlreadyTransformed(QualType T) {
168 return T.isNull();
169 }
170
171 /// \brief Transforms the given type into another type.
172 ///
173 /// By default, this routine transforms a type by delegating to the
Mike Stump11289f42009-09-09 15:08:12 +0000174 /// appropriate TransformXXXType to build a new type, then applying
175 /// the qualifiers on \p T to the resulting type with AddTypeQualifiers.
176 /// Subclasses may override this function (to take over all type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000177 /// transformations), some set of the TransformXXXType functions, or
178 /// the AddTypeQualifiers function to alter the transformation.
179 ///
180 /// \returns the transformed type.
181 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000182
Douglas Gregord6ff3322009-08-04 16:50:30 +0000183 /// \brief Transform the given type by adding the given set of qualifiers
184 /// and returning the result.
185 ///
186 /// FIXME: By default, this routine adds type qualifiers only to types that
187 /// can have qualifiers, and silently suppresses those qualifiers that are
188 /// not permitted (e.g., qualifiers on reference or function types). This
189 /// is the right thing for template instantiation, but probably not for
190 /// other clients.
John McCall8ccfcb52009-09-24 19:53:00 +0000191 QualType AddTypeQualifiers(QualType T, Qualifiers Qs);
Mike Stump11289f42009-09-09 15:08:12 +0000192
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000193 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000194 ///
Mike Stump11289f42009-09-09 15:08:12 +0000195 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000196 /// appropriate TransformXXXStmt function to transform a specific kind of
197 /// statement or the TransformExpr() function to transform an expression.
198 /// Subclasses may override this function to transform statements using some
199 /// other mechanism.
200 ///
201 /// \returns the transformed statement.
Douglas Gregora16548e2009-08-11 05:31:07 +0000202 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000203
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000204 /// \brief Transform the given expression.
205 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000206 /// By default, this routine transforms an expression by delegating to the
207 /// appropriate TransformXXXExpr function to build a new expression.
208 /// Subclasses may override this function to transform expressions using some
209 /// other mechanism.
210 ///
211 /// \returns the transformed expression.
212 OwningExprResult TransformExpr(Expr *E) {
213 return getDerived().TransformExpr(E, /*isAddressOfOperand=*/false);
214 }
215
216 /// \brief Transform the given expression.
217 ///
218 /// By default, this routine transforms an expression by delegating to the
219 /// appropriate TransformXXXExpr function to build a new expression.
220 /// Subclasses may override this function to transform expressions using some
221 /// other mechanism.
222 ///
223 /// \returns the transformed expression.
224 OwningExprResult TransformExpr(Expr *E, bool isAddressOfOperand);
Mike Stump11289f42009-09-09 15:08:12 +0000225
Douglas Gregord6ff3322009-08-04 16:50:30 +0000226 /// \brief Transform the given declaration, which is referenced from a type
227 /// or expression.
228 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000229 /// By default, acts as the identity function on declarations. Subclasses
230 /// may override this function to provide alternate behavior.
231 Decl *TransformDecl(Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000232
233 /// \brief Transform the definition of the given declaration.
234 ///
Mike Stump11289f42009-09-09 15:08:12 +0000235 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000236 /// Subclasses may override this function to provide alternate behavior.
237 Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); }
Mike Stump11289f42009-09-09 15:08:12 +0000238
Douglas Gregord6ff3322009-08-04 16:50:30 +0000239 /// \brief Transform the given nested-name-specifier.
240 ///
Mike Stump11289f42009-09-09 15:08:12 +0000241 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000242 /// nested-name-specifier. Subclasses may override this function to provide
243 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000244 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000245 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000246 QualType ObjectType = QualType(),
247 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000248
Douglas Gregorf816bd72009-09-03 22:13:48 +0000249 /// \brief Transform the given declaration name.
250 ///
251 /// By default, transforms the types of conversion function, constructor,
252 /// and destructor names and then (if needed) rebuilds the declaration name.
253 /// Identifiers and selectors are returned unmodified. Sublcasses may
254 /// override this function to provide alternate behavior.
255 DeclarationName TransformDeclarationName(DeclarationName Name,
256 SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000257
Douglas Gregord6ff3322009-08-04 16:50:30 +0000258 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000259 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000260 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000261 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000262 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000263 TemplateName TransformTemplateName(TemplateName Name,
264 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000265
Douglas Gregord6ff3322009-08-04 16:50:30 +0000266 /// \brief Transform the given template argument.
267 ///
Mike Stump11289f42009-09-09 15:08:12 +0000268 /// By default, this operation transforms the type, expression, or
269 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000270 /// new template argument from the transformed result. Subclasses may
271 /// override this function to provide alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000272 TemplateArgument TransformTemplateArgument(const TemplateArgument &Arg);
Mike Stump11289f42009-09-09 15:08:12 +0000273
Douglas Gregord6ff3322009-08-04 16:50:30 +0000274#define ABSTRACT_TYPE(CLASS, PARENT)
275#define TYPE(CLASS, PARENT) \
276 QualType Transform##CLASS##Type(const CLASS##Type *T);
Mike Stump11289f42009-09-09 15:08:12 +0000277#include "clang/AST/TypeNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000278
Douglas Gregorebe10102009-08-20 07:17:43 +0000279 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Mike Stump11289f42009-09-09 15:08:12 +0000280
Douglas Gregorebe10102009-08-20 07:17:43 +0000281#define STMT(Node, Parent) \
282 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000283#define EXPR(Node, Parent) \
284 OwningExprResult Transform##Node(Node *E);
285#define ABSTRACT_EXPR(Node, Parent)
286#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000287
Douglas Gregord6ff3322009-08-04 16:50:30 +0000288 /// \brief Build a new pointer type given its pointee type.
289 ///
290 /// By default, performs semantic analysis when building the pointer type.
291 /// Subclasses may override this routine to provide different behavior.
292 QualType RebuildPointerType(QualType PointeeType);
293
294 /// \brief Build a new block pointer type given its pointee type.
295 ///
Mike Stump11289f42009-09-09 15:08:12 +0000296 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000297 /// type. Subclasses may override this routine to provide different behavior.
298 QualType RebuildBlockPointerType(QualType PointeeType);
299
300 /// \brief Build a new lvalue reference type given the type it references.
301 ///
302 /// By default, performs semantic analysis when building the lvalue reference
303 /// type. Subclasses may override this routine to provide different behavior.
304 QualType RebuildLValueReferenceType(QualType ReferentType);
305
306 /// \brief Build a new rvalue reference type given the type it references.
307 ///
308 /// By default, performs semantic analysis when building the rvalue reference
309 /// type. Subclasses may override this routine to provide different behavior.
310 QualType RebuildRValueReferenceType(QualType ReferentType);
Mike Stump11289f42009-09-09 15:08:12 +0000311
Douglas Gregord6ff3322009-08-04 16:50:30 +0000312 /// \brief Build a new member pointer type given the pointee type and the
313 /// class type it refers into.
314 ///
315 /// By default, performs semantic analysis when building the member pointer
316 /// type. Subclasses may override this routine to provide different behavior.
317 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType);
Mike Stump11289f42009-09-09 15:08:12 +0000318
Douglas Gregord6ff3322009-08-04 16:50:30 +0000319 /// \brief Build a new array type given the element type, size
320 /// modifier, size of the array (if known), size expression, and index type
321 /// qualifiers.
322 ///
323 /// By default, performs semantic analysis when building the array type.
324 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000325 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000326 QualType RebuildArrayType(QualType ElementType,
327 ArrayType::ArraySizeModifier SizeMod,
328 const llvm::APInt *Size,
329 Expr *SizeExpr,
330 unsigned IndexTypeQuals,
331 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000332
Douglas Gregord6ff3322009-08-04 16:50:30 +0000333 /// \brief Build a new constant array type given the element type, size
334 /// modifier, (known) size of the array, and index type qualifiers.
335 ///
336 /// By default, performs semantic analysis when building the array type.
337 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000338 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000339 ArrayType::ArraySizeModifier SizeMod,
340 const llvm::APInt &Size,
341 unsigned IndexTypeQuals);
342
343 /// \brief Build a new constant array type given the element type, size
Mike Stump11289f42009-09-09 15:08:12 +0000344 /// modifier, (known) size of the array, size expression, and index type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000345 /// qualifiers.
346 ///
347 /// By default, performs semantic analysis when building the array type.
348 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000349 QualType RebuildConstantArrayWithExprType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 ArrayType::ArraySizeModifier SizeMod,
351 const llvm::APInt &Size,
352 Expr *SizeExpr,
353 unsigned IndexTypeQuals,
354 SourceRange BracketsRange);
355
356 /// \brief Build a new constant array type given the element type, size
357 /// modifier, (known) size of the array, and index type qualifiers.
358 ///
359 /// By default, performs semantic analysis when building the array type.
360 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000361 QualType RebuildConstantArrayWithoutExprType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000362 ArrayType::ArraySizeModifier SizeMod,
363 const llvm::APInt &Size,
364 unsigned IndexTypeQuals);
365
366 /// \brief Build a new incomplete array type given the element type, size
367 /// modifier, and index type qualifiers.
368 ///
369 /// By default, performs semantic analysis when building the array type.
370 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000371 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000372 ArrayType::ArraySizeModifier SizeMod,
373 unsigned IndexTypeQuals);
374
Mike Stump11289f42009-09-09 15:08:12 +0000375 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000376 /// size modifier, size expression, and index type qualifiers.
377 ///
378 /// By default, performs semantic analysis when building the array type.
379 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000380 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000381 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000382 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000383 unsigned IndexTypeQuals,
384 SourceRange BracketsRange);
385
Mike Stump11289f42009-09-09 15:08:12 +0000386 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000387 /// size modifier, size expression, and index type qualifiers.
388 ///
389 /// By default, performs semantic analysis when building the array type.
390 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000391 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000392 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000393 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000394 unsigned IndexTypeQuals,
395 SourceRange BracketsRange);
396
397 /// \brief Build a new vector type given the element type and
398 /// number of elements.
399 ///
400 /// By default, performs semantic analysis when building the vector type.
401 /// Subclasses may override this routine to provide different behavior.
402 QualType RebuildVectorType(QualType ElementType, unsigned NumElements);
Mike Stump11289f42009-09-09 15:08:12 +0000403
Douglas Gregord6ff3322009-08-04 16:50:30 +0000404 /// \brief Build a new extended vector type given the element type and
405 /// number of elements.
406 ///
407 /// By default, performs semantic analysis when building the vector type.
408 /// Subclasses may override this routine to provide different behavior.
409 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
410 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000411
412 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000413 /// given the element type and number of elements.
414 ///
415 /// By default, performs semantic analysis when building the vector type.
416 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000417 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000418 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000419 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000420
Douglas Gregord6ff3322009-08-04 16:50:30 +0000421 /// \brief Build a new function type.
422 ///
423 /// By default, performs semantic analysis when building the function type.
424 /// Subclasses may override this routine to provide different behavior.
425 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000426 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000427 unsigned NumParamTypes,
428 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000429
Douglas Gregord6ff3322009-08-04 16:50:30 +0000430 /// \brief Build a new typedef type.
431 QualType RebuildTypedefType(TypedefDecl *Typedef) {
432 return SemaRef.Context.getTypeDeclType(Typedef);
433 }
434
435 /// \brief Build a new class/struct/union type.
436 QualType RebuildRecordType(RecordDecl *Record) {
437 return SemaRef.Context.getTypeDeclType(Record);
438 }
439
440 /// \brief Build a new Enum type.
441 QualType RebuildEnumType(EnumDecl *Enum) {
442 return SemaRef.Context.getTypeDeclType(Enum);
443 }
John McCallfcc33b02009-09-05 00:15:47 +0000444
445 /// \brief Build a new elaborated type.
446 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
447 return SemaRef.Context.getElaboratedType(T, Tag);
448 }
Mike Stump11289f42009-09-09 15:08:12 +0000449
450 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000451 ///
452 /// By default, performs semantic analysis when building the typeof type.
453 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000454 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000455
Mike Stump11289f42009-09-09 15:08:12 +0000456 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000457 ///
458 /// By default, builds a new TypeOfType with the given underlying type.
459 QualType RebuildTypeOfType(QualType Underlying);
460
Mike Stump11289f42009-09-09 15:08:12 +0000461 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 ///
463 /// By default, performs semantic analysis when building the decltype type.
464 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000465 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000466
Douglas Gregord6ff3322009-08-04 16:50:30 +0000467 /// \brief Build a new template specialization type.
468 ///
469 /// By default, performs semantic analysis when building the template
470 /// specialization type. Subclasses may override this routine to provide
471 /// different behavior.
472 QualType RebuildTemplateSpecializationType(TemplateName Template,
473 const TemplateArgument *Args,
474 unsigned NumArgs);
Mike Stump11289f42009-09-09 15:08:12 +0000475
Douglas Gregord6ff3322009-08-04 16:50:30 +0000476 /// \brief Build a new qualified name type.
477 ///
Mike Stump11289f42009-09-09 15:08:12 +0000478 /// By default, builds a new QualifiedNameType type from the
479 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000480 /// this routine to provide different behavior.
481 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
482 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000483 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000484
485 /// \brief Build a new typename type that refers to a template-id.
486 ///
487 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000488 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000489 /// different behavior.
490 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
491 if (NNS->isDependent())
Mike Stump11289f42009-09-09 15:08:12 +0000492 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000493 cast<TemplateSpecializationType>(T));
Mike Stump11289f42009-09-09 15:08:12 +0000494
Douglas Gregord6ff3322009-08-04 16:50:30 +0000495 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000496 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000497
498 /// \brief Build a new typename type that refers to an identifier.
499 ///
500 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000501 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000502 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000503 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000504 const IdentifierInfo *Id) {
505 return SemaRef.CheckTypenameType(NNS, *Id,
506 SourceRange(getDerived().getBaseLocation()));
Douglas Gregor1135c352009-08-06 05:28:30 +0000507 }
Mike Stump11289f42009-09-09 15:08:12 +0000508
Douglas Gregor1135c352009-08-06 05:28:30 +0000509 /// \brief Build a new nested-name-specifier given the prefix and an
510 /// identifier that names the next step in the nested-name-specifier.
511 ///
512 /// By default, performs semantic analysis when building the new
513 /// nested-name-specifier. Subclasses may override this routine to provide
514 /// different behavior.
515 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
516 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000517 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000518 QualType ObjectType,
519 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000520
521 /// \brief Build a new nested-name-specifier given the prefix and the
522 /// namespace named in the next step in the nested-name-specifier.
523 ///
524 /// By default, performs semantic analysis when building the new
525 /// nested-name-specifier. Subclasses may override this routine to provide
526 /// different behavior.
527 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
528 SourceRange Range,
529 NamespaceDecl *NS);
530
531 /// \brief Build a new nested-name-specifier given the prefix and the
532 /// type named in the next step in the nested-name-specifier.
533 ///
534 /// By default, performs semantic analysis when building the new
535 /// nested-name-specifier. Subclasses may override this routine to provide
536 /// different behavior.
537 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
538 SourceRange Range,
539 bool TemplateKW,
540 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000541
542 /// \brief Build a new template name given a nested name specifier, a flag
543 /// indicating whether the "template" keyword was provided, and the template
544 /// that the template name refers to.
545 ///
546 /// By default, builds the new template name directly. Subclasses may override
547 /// this routine to provide different behavior.
548 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
549 bool TemplateKW,
550 TemplateDecl *Template);
551
552 /// \brief Build a new template name given a nested name specifier, a flag
553 /// indicating whether the "template" keyword was provided, and a set of
554 /// overloaded function templates.
555 ///
556 /// By default, builds the new template name directly. Subclasses may override
557 /// this routine to provide different behavior.
558 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
559 bool TemplateKW,
560 OverloadedFunctionDecl *Ovl);
Mike Stump11289f42009-09-09 15:08:12 +0000561
Douglas Gregor71dc5092009-08-06 06:41:21 +0000562 /// \brief Build a new template name given a nested name specifier and the
563 /// name that is referred to as a template.
564 ///
565 /// By default, performs semantic analysis to determine whether the name can
566 /// be resolved to a specific template, then builds the appropriate kind of
567 /// template name. Subclasses may override this routine to provide different
568 /// behavior.
569 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000570 const IdentifierInfo &II,
571 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000572
573
Douglas Gregorebe10102009-08-20 07:17:43 +0000574 /// \brief Build a new compound statement.
575 ///
576 /// By default, performs semantic analysis to build the new statement.
577 /// Subclasses may override this routine to provide different behavior.
578 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
579 MultiStmtArg Statements,
580 SourceLocation RBraceLoc,
581 bool IsStmtExpr) {
582 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
583 IsStmtExpr);
584 }
585
586 /// \brief Build a new case statement.
587 ///
588 /// By default, performs semantic analysis to build the new statement.
589 /// Subclasses may override this routine to provide different behavior.
590 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
591 ExprArg LHS,
592 SourceLocation EllipsisLoc,
593 ExprArg RHS,
594 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000595 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000596 ColonLoc);
597 }
Mike Stump11289f42009-09-09 15:08:12 +0000598
Douglas Gregorebe10102009-08-20 07:17:43 +0000599 /// \brief Attach the body to a new case statement.
600 ///
601 /// By default, performs semantic analysis to build the new statement.
602 /// Subclasses may override this routine to provide different behavior.
603 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
604 getSema().ActOnCaseStmtBody(S.get(), move(Body));
605 return move(S);
606 }
Mike Stump11289f42009-09-09 15:08:12 +0000607
Douglas Gregorebe10102009-08-20 07:17:43 +0000608 /// \brief Build a new default statement.
609 ///
610 /// By default, performs semantic analysis to build the new statement.
611 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000612 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000613 SourceLocation ColonLoc,
614 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000615 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000616 /*CurScope=*/0);
617 }
Mike Stump11289f42009-09-09 15:08:12 +0000618
Douglas Gregorebe10102009-08-20 07:17:43 +0000619 /// \brief Build a new label statement.
620 ///
621 /// By default, performs semantic analysis to build the new statement.
622 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000623 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000624 IdentifierInfo *Id,
625 SourceLocation ColonLoc,
626 StmtArg SubStmt) {
627 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
628 }
Mike Stump11289f42009-09-09 15:08:12 +0000629
Douglas Gregorebe10102009-08-20 07:17:43 +0000630 /// \brief Build a new "if" statement.
631 ///
632 /// By default, performs semantic analysis to build the new statement.
633 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000634 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
635 StmtArg Then, SourceLocation ElseLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000636 StmtArg Else) {
637 return getSema().ActOnIfStmt(IfLoc, Cond, move(Then), ElseLoc, move(Else));
638 }
Mike Stump11289f42009-09-09 15:08:12 +0000639
Douglas Gregorebe10102009-08-20 07:17:43 +0000640 /// \brief Start building a new switch statement.
641 ///
642 /// By default, performs semantic analysis to build the new statement.
643 /// Subclasses may override this routine to provide different behavior.
644 OwningStmtResult RebuildSwitchStmtStart(ExprArg Cond) {
645 return getSema().ActOnStartOfSwitchStmt(move(Cond));
646 }
Mike Stump11289f42009-09-09 15:08:12 +0000647
Douglas Gregorebe10102009-08-20 07:17:43 +0000648 /// \brief Attach the body to the switch statement.
649 ///
650 /// By default, performs semantic analysis to build the new statement.
651 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000652 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000653 StmtArg Switch, StmtArg Body) {
654 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
655 move(Body));
656 }
657
658 /// \brief Build a new while statement.
659 ///
660 /// By default, performs semantic analysis to build the new statement.
661 /// Subclasses may override this routine to provide different behavior.
662 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
663 Sema::FullExprArg Cond,
664 StmtArg Body) {
665 return getSema().ActOnWhileStmt(WhileLoc, Cond, move(Body));
666 }
Mike Stump11289f42009-09-09 15:08:12 +0000667
Douglas Gregorebe10102009-08-20 07:17:43 +0000668 /// \brief Build a new do-while statement.
669 ///
670 /// By default, performs semantic analysis to build the new statement.
671 /// Subclasses may override this routine to provide different behavior.
672 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
673 SourceLocation WhileLoc,
674 SourceLocation LParenLoc,
675 ExprArg Cond,
676 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000677 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000678 move(Cond), RParenLoc);
679 }
680
681 /// \brief Build a new for statement.
682 ///
683 /// By default, performs semantic analysis to build the new statement.
684 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000685 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000686 SourceLocation LParenLoc,
687 StmtArg Init, ExprArg Cond, ExprArg Inc,
688 SourceLocation RParenLoc, StmtArg Body) {
Mike Stump11289f42009-09-09 15:08:12 +0000689 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), move(Cond),
Douglas Gregorebe10102009-08-20 07:17:43 +0000690 move(Inc), RParenLoc, move(Body));
691 }
Mike Stump11289f42009-09-09 15:08:12 +0000692
Douglas Gregorebe10102009-08-20 07:17:43 +0000693 /// \brief Build a new goto statement.
694 ///
695 /// By default, performs semantic analysis to build the new statement.
696 /// Subclasses may override this routine to provide different behavior.
697 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
698 SourceLocation LabelLoc,
699 LabelStmt *Label) {
700 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
701 }
702
703 /// \brief Build a new indirect goto statement.
704 ///
705 /// By default, performs semantic analysis to build the new statement.
706 /// Subclasses may override this routine to provide different behavior.
707 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
708 SourceLocation StarLoc,
709 ExprArg Target) {
710 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
711 }
Mike Stump11289f42009-09-09 15:08:12 +0000712
Douglas Gregorebe10102009-08-20 07:17:43 +0000713 /// \brief Build a new return statement.
714 ///
715 /// By default, performs semantic analysis to build the new statement.
716 /// Subclasses may override this routine to provide different behavior.
717 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
718 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000719
Douglas Gregorebe10102009-08-20 07:17:43 +0000720 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
721 }
Mike Stump11289f42009-09-09 15:08:12 +0000722
Douglas Gregorebe10102009-08-20 07:17:43 +0000723 /// \brief Build a new declaration statement.
724 ///
725 /// By default, performs semantic analysis to build the new statement.
726 /// Subclasses may override this routine to provide different behavior.
727 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000728 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000729 SourceLocation EndLoc) {
730 return getSema().Owned(
731 new (getSema().Context) DeclStmt(
732 DeclGroupRef::Create(getSema().Context,
733 Decls, NumDecls),
734 StartLoc, EndLoc));
735 }
Mike Stump11289f42009-09-09 15:08:12 +0000736
Douglas Gregorebe10102009-08-20 07:17:43 +0000737 /// \brief Build a new C++ exception declaration.
738 ///
739 /// By default, performs semantic analysis to build the new decaration.
740 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000741 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
Douglas Gregorebe10102009-08-20 07:17:43 +0000742 DeclaratorInfo *Declarator,
743 IdentifierInfo *Name,
744 SourceLocation Loc,
745 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000746 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000747 TypeRange);
748 }
749
750 /// \brief Build a new C++ catch statement.
751 ///
752 /// By default, performs semantic analysis to build the new statement.
753 /// Subclasses may override this routine to provide different behavior.
754 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
755 VarDecl *ExceptionDecl,
756 StmtArg Handler) {
757 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000758 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000759 Handler.takeAs<Stmt>()));
760 }
Mike Stump11289f42009-09-09 15:08:12 +0000761
Douglas Gregorebe10102009-08-20 07:17:43 +0000762 /// \brief Build a new C++ try statement.
763 ///
764 /// By default, performs semantic analysis to build the new statement.
765 /// Subclasses may override this routine to provide different behavior.
766 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
767 StmtArg TryBlock,
768 MultiStmtArg Handlers) {
769 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
770 }
Mike Stump11289f42009-09-09 15:08:12 +0000771
Douglas Gregora16548e2009-08-11 05:31:07 +0000772 /// \brief Build a new expression that references a declaration.
773 ///
774 /// By default, performs semantic analysis to build the new expression.
775 /// Subclasses may override this routine to provide different behavior.
776 OwningExprResult RebuildDeclRefExpr(NamedDecl *ND, SourceLocation Loc) {
777 return getSema().BuildDeclarationNameExpr(Loc, ND,
778 /*FIXME:*/false,
779 /*SS=*/0,
780 /*FIXME:*/false);
781 }
Mike Stump11289f42009-09-09 15:08:12 +0000782
Douglas Gregora16548e2009-08-11 05:31:07 +0000783 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000784 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000785 /// By default, performs semantic analysis to build the new expression.
786 /// Subclasses may override this routine to provide different behavior.
787 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
788 SourceLocation RParen) {
789 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
790 }
791
Douglas Gregorad8a3362009-09-04 17:36:40 +0000792 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000793 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000794 /// By default, performs semantic analysis to build the new expression.
795 /// Subclasses may override this routine to provide different behavior.
796 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
797 SourceLocation OperatorLoc,
798 bool isArrow,
799 SourceLocation DestroyedTypeLoc,
800 QualType DestroyedType,
801 NestedNameSpecifier *Qualifier,
802 SourceRange QualifierRange) {
803 CXXScopeSpec SS;
804 if (Qualifier) {
805 SS.setRange(QualifierRange);
806 SS.setScopeRep(Qualifier);
807 }
808
Mike Stump11289f42009-09-09 15:08:12 +0000809 DeclarationName Name
Douglas Gregorad8a3362009-09-04 17:36:40 +0000810 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
811 SemaRef.Context.getCanonicalType(DestroyedType));
Mike Stump11289f42009-09-09 15:08:12 +0000812
813 return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base),
Douglas Gregorad8a3362009-09-04 17:36:40 +0000814 OperatorLoc,
815 isArrow? tok::arrow : tok::period,
816 DestroyedTypeLoc,
817 Name,
818 Sema::DeclPtrTy::make((Decl *)0),
819 &SS);
Mike Stump11289f42009-09-09 15:08:12 +0000820 }
821
Douglas Gregora16548e2009-08-11 05:31:07 +0000822 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000823 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000824 /// By default, performs semantic analysis to build the new expression.
825 /// Subclasses may override this routine to provide different behavior.
826 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
827 UnaryOperator::Opcode Opc,
828 ExprArg SubExpr) {
829 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(SubExpr));
830 }
Mike Stump11289f42009-09-09 15:08:12 +0000831
Douglas Gregora16548e2009-08-11 05:31:07 +0000832 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000833 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000834 /// By default, performs semantic analysis to build the new expression.
835 /// Subclasses may override this routine to provide different behavior.
836 OwningExprResult RebuildSizeOfAlignOf(QualType T, SourceLocation OpLoc,
837 bool isSizeOf, SourceRange R) {
838 return getSema().CreateSizeOfAlignOfExpr(T, OpLoc, isSizeOf, R);
839 }
840
Mike Stump11289f42009-09-09 15:08:12 +0000841 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000842 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +0000843 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000844 /// By default, performs semantic analysis to build the new expression.
845 /// Subclasses may override this routine to provide different behavior.
846 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
847 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +0000848 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000849 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
850 OpLoc, isSizeOf, R);
851 if (Result.isInvalid())
852 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000853
Douglas Gregora16548e2009-08-11 05:31:07 +0000854 SubExpr.release();
855 return move(Result);
856 }
Mike Stump11289f42009-09-09 15:08:12 +0000857
Douglas Gregora16548e2009-08-11 05:31:07 +0000858 /// \brief Build a new array subscript expression.
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.
Mike Stump11289f42009-09-09 15:08:12 +0000862 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000863 SourceLocation LBracketLoc,
864 ExprArg RHS,
865 SourceLocation RBracketLoc) {
866 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000867 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000868 RBracketLoc);
869 }
870
871 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000872 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000873 /// By default, performs semantic analysis to build the new expression.
874 /// Subclasses may override this routine to provide different behavior.
875 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
876 MultiExprArg Args,
877 SourceLocation *CommaLocs,
878 SourceLocation RParenLoc) {
879 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
880 move(Args), CommaLocs, RParenLoc);
881 }
882
883 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000884 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000885 /// By default, performs semantic analysis to build the new expression.
886 /// Subclasses may override this routine to provide different behavior.
887 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000888 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000889 NestedNameSpecifier *Qualifier,
890 SourceRange QualifierRange,
891 SourceLocation MemberLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000892 NamedDecl *Member) {
Anders Carlsson5da84842009-09-01 04:26:58 +0000893 if (!Member->getDeclName()) {
894 // We have a reference to an unnamed field.
895 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +0000896
897 MemberExpr *ME =
Anders Carlsson5da84842009-09-01 04:26:58 +0000898 new (getSema().Context) MemberExpr(Base.takeAs<Expr>(), isArrow,
899 Member, MemberLoc,
900 cast<FieldDecl>(Member)->getType());
901 return getSema().Owned(ME);
902 }
Mike Stump11289f42009-09-09 15:08:12 +0000903
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000904 CXXScopeSpec SS;
905 if (Qualifier) {
906 SS.setRange(QualifierRange);
907 SS.setScopeRep(Qualifier);
908 }
909
Douglas Gregorf14b46f2009-08-31 20:00:26 +0000910 return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000911 isArrow? tok::arrow : tok::period,
912 MemberLoc,
Douglas Gregorf14b46f2009-08-31 20:00:26 +0000913 Member->getDeclName(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000914 /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0),
915 &SS);
Douglas Gregora16548e2009-08-11 05:31:07 +0000916 }
Mike Stump11289f42009-09-09 15:08:12 +0000917
Douglas Gregora16548e2009-08-11 05:31:07 +0000918 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000919 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000920 /// By default, performs semantic analysis to build the new expression.
921 /// Subclasses may override this routine to provide different behavior.
922 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
923 BinaryOperator::Opcode Opc,
924 ExprArg LHS, ExprArg RHS) {
925 OwningExprResult Result
Mike Stump11289f42009-09-09 15:08:12 +0000926 = getSema().CreateBuiltinBinOp(OpLoc, Opc, (Expr *)LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +0000927 (Expr *)RHS.get());
928 if (Result.isInvalid())
929 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000930
Douglas Gregora16548e2009-08-11 05:31:07 +0000931 LHS.release();
932 RHS.release();
933 return move(Result);
934 }
935
936 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000937 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000938 /// By default, performs semantic analysis to build the new expression.
939 /// Subclasses may override this routine to provide different behavior.
940 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
941 SourceLocation QuestionLoc,
942 ExprArg LHS,
943 SourceLocation ColonLoc,
944 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +0000945 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +0000946 move(LHS), move(RHS));
947 }
948
949 /// \brief Build a new implicit cast expression.
Mike Stump11289f42009-09-09 15:08:12 +0000950 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000951 /// By default, builds a new implicit cast without any semantic analysis.
952 /// Subclasses may override this routine to provide different behavior.
953 OwningExprResult RebuildImplicitCastExpr(QualType T, CastExpr::CastKind Kind,
954 ExprArg SubExpr, bool isLvalue) {
955 ImplicitCastExpr *ICE
Mike Stump11289f42009-09-09 15:08:12 +0000956 = new (getSema().Context) ImplicitCastExpr(T, Kind,
Douglas Gregora16548e2009-08-11 05:31:07 +0000957 (Expr *)SubExpr.release(),
958 isLvalue);
959 return getSema().Owned(ICE);
960 }
961
962 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +0000963 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000964 /// By default, performs semantic analysis to build the new expression.
965 /// Subclasses may override this routine to provide different behavior.
966 OwningExprResult RebuildCStyleCaseExpr(SourceLocation LParenLoc,
967 QualType ExplicitTy,
968 SourceLocation RParenLoc,
969 ExprArg SubExpr) {
970 return getSema().ActOnCastExpr(/*Scope=*/0,
971 LParenLoc,
972 ExplicitTy.getAsOpaquePtr(),
973 RParenLoc,
974 move(SubExpr));
975 }
Mike Stump11289f42009-09-09 15:08:12 +0000976
Douglas Gregora16548e2009-08-11 05:31:07 +0000977 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +0000978 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000979 /// By default, performs semantic analysis to build the new expression.
980 /// Subclasses may override this routine to provide different behavior.
981 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
982 QualType T,
983 SourceLocation RParenLoc,
984 ExprArg Init) {
985 return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(),
986 RParenLoc, move(Init));
987 }
Mike Stump11289f42009-09-09 15:08:12 +0000988
Douglas Gregora16548e2009-08-11 05:31:07 +0000989 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000990 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000991 /// By default, performs semantic analysis to build the new expression.
992 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000993 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +0000994 SourceLocation OpLoc,
995 SourceLocation AccessorLoc,
996 IdentifierInfo &Accessor) {
997 return getSema().ActOnMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc,
998 tok::period, AccessorLoc,
999 Accessor,
1000 /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0));
1001 }
Mike Stump11289f42009-09-09 15:08:12 +00001002
Douglas Gregora16548e2009-08-11 05:31:07 +00001003 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001004 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001005 /// By default, performs semantic analysis to build the new expression.
1006 /// Subclasses may override this routine to provide different behavior.
1007 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1008 MultiExprArg Inits,
1009 SourceLocation RBraceLoc) {
1010 return SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1011 }
Mike Stump11289f42009-09-09 15:08:12 +00001012
Douglas Gregora16548e2009-08-11 05:31:07 +00001013 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001014 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001015 /// By default, performs semantic analysis to build the new expression.
1016 /// Subclasses may override this routine to provide different behavior.
1017 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1018 MultiExprArg ArrayExprs,
1019 SourceLocation EqualOrColonLoc,
1020 bool GNUSyntax,
1021 ExprArg Init) {
1022 OwningExprResult Result
1023 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1024 move(Init));
1025 if (Result.isInvalid())
1026 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001027
Douglas Gregora16548e2009-08-11 05:31:07 +00001028 ArrayExprs.release();
1029 return move(Result);
1030 }
Mike Stump11289f42009-09-09 15:08:12 +00001031
Douglas Gregora16548e2009-08-11 05:31:07 +00001032 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001033 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001034 /// By default, builds the implicit value initialization without performing
1035 /// any semantic analysis. Subclasses may override this routine to provide
1036 /// different behavior.
1037 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1038 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1039 }
Mike Stump11289f42009-09-09 15:08:12 +00001040
Douglas Gregora16548e2009-08-11 05:31:07 +00001041 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001042 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001043 /// By default, performs semantic analysis to build the new expression.
1044 /// Subclasses may override this routine to provide different behavior.
1045 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1046 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001047 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001048 RParenLoc);
1049 }
1050
1051 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001052 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001053 /// By default, performs semantic analysis to build the new expression.
1054 /// Subclasses may override this routine to provide different behavior.
1055 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1056 MultiExprArg SubExprs,
1057 SourceLocation RParenLoc) {
1058 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
1059 }
Mike Stump11289f42009-09-09 15:08:12 +00001060
Douglas Gregora16548e2009-08-11 05:31:07 +00001061 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001062 ///
1063 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001064 /// rather than attempting to map the label statement itself.
1065 /// Subclasses may override this routine to provide different behavior.
1066 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1067 SourceLocation LabelLoc,
1068 LabelStmt *Label) {
1069 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1070 }
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregora16548e2009-08-11 05:31:07 +00001072 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001073 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001074 /// By default, performs semantic analysis to build the new expression.
1075 /// Subclasses may override this routine to provide different behavior.
1076 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1077 StmtArg SubStmt,
1078 SourceLocation RParenLoc) {
1079 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1080 }
Mike Stump11289f42009-09-09 15:08:12 +00001081
Douglas Gregora16548e2009-08-11 05:31:07 +00001082 /// \brief Build a new __builtin_types_compatible_p expression.
1083 ///
1084 /// By default, performs semantic analysis to build the new expression.
1085 /// Subclasses may override this routine to provide different behavior.
1086 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1087 QualType T1, QualType T2,
1088 SourceLocation RParenLoc) {
1089 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1090 T1.getAsOpaquePtr(),
1091 T2.getAsOpaquePtr(),
1092 RParenLoc);
1093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Douglas Gregora16548e2009-08-11 05:31:07 +00001095 /// \brief Build a new __builtin_choose_expr expression.
1096 ///
1097 /// By default, performs semantic analysis to build the new expression.
1098 /// Subclasses may override this routine to provide different behavior.
1099 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1100 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1101 SourceLocation RParenLoc) {
1102 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1103 move(Cond), move(LHS), move(RHS),
1104 RParenLoc);
1105 }
Mike Stump11289f42009-09-09 15:08:12 +00001106
Douglas Gregora16548e2009-08-11 05:31:07 +00001107 /// \brief Build a new overloaded operator call expression.
1108 ///
1109 /// By default, performs semantic analysis to build the new expression.
1110 /// The semantic analysis provides the behavior of template instantiation,
1111 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001112 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001113 /// argument-dependent lookup, etc. Subclasses may override this routine to
1114 /// provide different behavior.
1115 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1116 SourceLocation OpLoc,
1117 ExprArg Callee,
1118 ExprArg First,
1119 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001120
1121 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001122 /// reinterpret_cast.
1123 ///
1124 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001125 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001126 /// Subclasses may override this routine to provide different behavior.
1127 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1128 Stmt::StmtClass Class,
1129 SourceLocation LAngleLoc,
1130 QualType T,
1131 SourceLocation RAngleLoc,
1132 SourceLocation LParenLoc,
1133 ExprArg SubExpr,
1134 SourceLocation RParenLoc) {
1135 switch (Class) {
1136 case Stmt::CXXStaticCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001137 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T,
1138 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001139 move(SubExpr), RParenLoc);
1140
1141 case Stmt::CXXDynamicCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001142 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T,
1143 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001144 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001145
Douglas Gregora16548e2009-08-11 05:31:07 +00001146 case Stmt::CXXReinterpretCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001147 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T,
1148 RAngleLoc, LParenLoc,
1149 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001150 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001151
Douglas Gregora16548e2009-08-11 05:31:07 +00001152 case Stmt::CXXConstCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001153 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T,
1154 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001155 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001156
Douglas Gregora16548e2009-08-11 05:31:07 +00001157 default:
1158 assert(false && "Invalid C++ named cast");
1159 break;
1160 }
Mike Stump11289f42009-09-09 15:08:12 +00001161
Douglas Gregora16548e2009-08-11 05:31:07 +00001162 return getSema().ExprError();
1163 }
Mike Stump11289f42009-09-09 15:08:12 +00001164
Douglas Gregora16548e2009-08-11 05:31:07 +00001165 /// \brief Build a new C++ static_cast expression.
1166 ///
1167 /// By default, performs semantic analysis to build the new expression.
1168 /// Subclasses may override this routine to provide different behavior.
1169 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1170 SourceLocation LAngleLoc,
1171 QualType T,
1172 SourceLocation RAngleLoc,
1173 SourceLocation LParenLoc,
1174 ExprArg SubExpr,
1175 SourceLocation RParenLoc) {
1176 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001177 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001178 LParenLoc, move(SubExpr), RParenLoc);
1179 }
1180
1181 /// \brief Build a new C++ dynamic_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 RebuildCXXDynamicCastExpr(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_dynamic_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++ reinterpret_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 RebuildCXXReinterpretCastExpr(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_reinterpret_cast,
1209 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
1210 LParenLoc, move(SubExpr), RParenLoc);
1211 }
1212
1213 /// \brief Build a new C++ const_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 RebuildCXXConstCastExpr(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_const_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001225 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001226 LParenLoc, move(SubExpr), RParenLoc);
1227 }
Mike Stump11289f42009-09-09 15:08:12 +00001228
Douglas Gregora16548e2009-08-11 05:31:07 +00001229 /// \brief Build a new C++ functional-style 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 RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
1234 QualType T,
1235 SourceLocation LParenLoc,
1236 ExprArg SubExpr,
1237 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001238 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001239 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
1240 T.getAsOpaquePtr(),
1241 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001242 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001243 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001244 RParenLoc);
1245 }
Mike Stump11289f42009-09-09 15:08:12 +00001246
Douglas Gregora16548e2009-08-11 05:31:07 +00001247 /// \brief Build a new C++ typeid(type) expression.
1248 ///
1249 /// By default, performs semantic analysis to build the new expression.
1250 /// Subclasses may override this routine to provide different behavior.
1251 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1252 SourceLocation LParenLoc,
1253 QualType T,
1254 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001255 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001256 T.getAsOpaquePtr(), RParenLoc);
1257 }
Mike Stump11289f42009-09-09 15:08:12 +00001258
Douglas Gregora16548e2009-08-11 05:31:07 +00001259 /// \brief Build a new C++ typeid(expr) expression.
1260 ///
1261 /// By default, performs semantic analysis to build the new expression.
1262 /// Subclasses may override this routine to provide different behavior.
1263 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1264 SourceLocation LParenLoc,
1265 ExprArg Operand,
1266 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001267 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001268 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1269 RParenLoc);
1270 if (Result.isInvalid())
1271 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001272
Douglas Gregora16548e2009-08-11 05:31:07 +00001273 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1274 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001275 }
1276
Douglas Gregora16548e2009-08-11 05:31:07 +00001277 /// \brief Build a new C++ "this" expression.
1278 ///
1279 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001280 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001281 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001282 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001283 QualType ThisType) {
1284 return getSema().Owned(
1285 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType));
1286 }
1287
1288 /// \brief Build a new C++ throw expression.
1289 ///
1290 /// By default, performs semantic analysis to build the new expression.
1291 /// Subclasses may override this routine to provide different behavior.
1292 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1293 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1294 }
1295
1296 /// \brief Build a new C++ default-argument expression.
1297 ///
1298 /// By default, builds a new default-argument expression, which does not
1299 /// require any semantic analysis. Subclasses may override this routine to
1300 /// provide different behavior.
1301 OwningExprResult RebuildCXXDefaultArgExpr(ParmVarDecl *Param) {
Anders Carlssone8271232009-08-14 18:30:22 +00001302 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001303 }
1304
1305 /// \brief Build a new C++ zero-initialization expression.
1306 ///
1307 /// By default, performs semantic analysis to build the new expression.
1308 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001309 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001310 SourceLocation LParenLoc,
1311 QualType T,
1312 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001313 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1314 T.getAsOpaquePtr(), LParenLoc,
1315 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001316 0, RParenLoc);
1317 }
Mike Stump11289f42009-09-09 15:08:12 +00001318
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 /// \brief Build a new C++ conditional declaration expression.
1320 ///
1321 /// By default, performs semantic analysis to build the new expression.
1322 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001323 OwningExprResult RebuildCXXConditionDeclExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 SourceLocation EqLoc,
1325 VarDecl *Var) {
1326 return SemaRef.Owned(new (SemaRef.Context) CXXConditionDeclExpr(StartLoc,
1327 EqLoc,
1328 Var));
1329 }
Mike Stump11289f42009-09-09 15:08:12 +00001330
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 /// \brief Build a new C++ "new" expression.
1332 ///
1333 /// By default, performs semantic analysis to build the new expression.
1334 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001335 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 bool UseGlobal,
1337 SourceLocation PlacementLParen,
1338 MultiExprArg PlacementArgs,
1339 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001340 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 QualType AllocType,
1342 SourceLocation TypeLoc,
1343 SourceRange TypeRange,
1344 ExprArg ArraySize,
1345 SourceLocation ConstructorLParen,
1346 MultiExprArg ConstructorArgs,
1347 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001348 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 PlacementLParen,
1350 move(PlacementArgs),
1351 PlacementRParen,
1352 ParenTypeId,
1353 AllocType,
1354 TypeLoc,
1355 TypeRange,
1356 move(ArraySize),
1357 ConstructorLParen,
1358 move(ConstructorArgs),
1359 ConstructorRParen);
1360 }
Mike Stump11289f42009-09-09 15:08:12 +00001361
Douglas Gregora16548e2009-08-11 05:31:07 +00001362 /// \brief Build a new C++ "delete" expression.
1363 ///
1364 /// By default, performs semantic analysis to build the new expression.
1365 /// Subclasses may override this routine to provide different behavior.
1366 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1367 bool IsGlobalDelete,
1368 bool IsArrayForm,
1369 ExprArg Operand) {
1370 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1371 move(Operand));
1372 }
Mike Stump11289f42009-09-09 15:08:12 +00001373
Douglas Gregora16548e2009-08-11 05:31:07 +00001374 /// \brief Build a new unary type trait expression.
1375 ///
1376 /// By default, performs semantic analysis to build the new expression.
1377 /// Subclasses may override this routine to provide different behavior.
1378 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1379 SourceLocation StartLoc,
1380 SourceLocation LParenLoc,
1381 QualType T,
1382 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001383 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001384 T.getAsOpaquePtr(), RParenLoc);
1385 }
1386
1387 /// \brief Build a new qualified declaration reference expression.
1388 ///
1389 /// By default, performs semantic analysis to build the new expression.
1390 /// Subclasses may override this routine to provide different behavior.
1391 OwningExprResult RebuildQualifiedDeclRefExpr(NestedNameSpecifier *NNS,
1392 SourceRange QualifierRange,
1393 NamedDecl *ND,
1394 SourceLocation Location,
1395 bool IsAddressOfOperand) {
1396 CXXScopeSpec SS;
1397 SS.setRange(QualifierRange);
1398 SS.setScopeRep(NNS);
Mike Stump11289f42009-09-09 15:08:12 +00001399 return getSema().ActOnDeclarationNameExpr(/*Scope=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001400 Location,
1401 ND->getDeclName(),
1402 /*Trailing lparen=*/false,
1403 &SS,
1404 IsAddressOfOperand);
1405 }
1406
Mike Stump11289f42009-09-09 15:08:12 +00001407 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 /// expression.
1409 ///
1410 /// By default, performs semantic analysis to build the new expression.
1411 /// Subclasses may override this routine to provide different behavior.
1412 OwningExprResult RebuildUnresolvedDeclRefExpr(NestedNameSpecifier *NNS,
1413 SourceRange QualifierRange,
1414 DeclarationName Name,
1415 SourceLocation Location,
1416 bool IsAddressOfOperand) {
1417 CXXScopeSpec SS;
1418 SS.setRange(QualifierRange);
1419 SS.setScopeRep(NNS);
Mike Stump11289f42009-09-09 15:08:12 +00001420 return getSema().ActOnDeclarationNameExpr(/*Scope=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 Location,
1422 Name,
1423 /*Trailing lparen=*/false,
1424 &SS,
1425 IsAddressOfOperand);
1426 }
1427
1428 /// \brief Build a new template-id expression.
1429 ///
1430 /// By default, performs semantic analysis to build the new expression.
1431 /// Subclasses may override this routine to provide different behavior.
1432 OwningExprResult RebuildTemplateIdExpr(TemplateName Template,
1433 SourceLocation TemplateLoc,
1434 SourceLocation LAngleLoc,
1435 TemplateArgument *TemplateArgs,
1436 unsigned NumTemplateArgs,
1437 SourceLocation RAngleLoc) {
1438 return getSema().BuildTemplateIdExpr(Template, TemplateLoc,
1439 LAngleLoc,
1440 TemplateArgs, NumTemplateArgs,
1441 RAngleLoc);
1442 }
1443
1444 /// \brief Build a new object-construction 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 RebuildCXXConstructExpr(QualType T,
1449 CXXConstructorDecl *Constructor,
1450 bool IsElidable,
1451 MultiExprArg Args) {
Anders Carlsson1b4ebfa2009-09-05 07:40:38 +00001452 return getSema().BuildCXXConstructExpr(/*FIXME:ConstructLoc*/
1453 SourceLocation(),
1454 T, Constructor, IsElidable,
Anders Carlsson5995a3e2009-09-07 22:23:31 +00001455 move(Args));
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 }
1457
1458 /// \brief Build a new object-construction expression.
1459 ///
1460 /// By default, performs semantic analysis to build the new expression.
1461 /// Subclasses may override this routine to provide different behavior.
1462 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1463 QualType T,
1464 SourceLocation LParenLoc,
1465 MultiExprArg Args,
1466 SourceLocation *Commas,
1467 SourceLocation RParenLoc) {
1468 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1469 T.getAsOpaquePtr(),
1470 LParenLoc,
1471 move(Args),
1472 Commas,
1473 RParenLoc);
1474 }
1475
1476 /// \brief Build a new object-construction expression.
1477 ///
1478 /// By default, performs semantic analysis to build the new expression.
1479 /// Subclasses may override this routine to provide different behavior.
1480 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1481 QualType T,
1482 SourceLocation LParenLoc,
1483 MultiExprArg Args,
1484 SourceLocation *Commas,
1485 SourceLocation RParenLoc) {
1486 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1487 /*FIXME*/LParenLoc),
1488 T.getAsOpaquePtr(),
1489 LParenLoc,
1490 move(Args),
1491 Commas,
1492 RParenLoc);
1493 }
Mike Stump11289f42009-09-09 15:08:12 +00001494
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 /// \brief Build a new member reference expression.
1496 ///
1497 /// By default, performs semantic analysis to build the new expression.
1498 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2168a9f2009-08-11 15:56:57 +00001499 OwningExprResult RebuildCXXUnresolvedMemberExpr(ExprArg BaseE,
Douglas Gregora16548e2009-08-11 05:31:07 +00001500 bool IsArrow,
1501 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001502 NestedNameSpecifier *Qualifier,
1503 SourceRange QualifierRange,
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001505 SourceLocation MemberLoc,
1506 NamedDecl *FirstQualifierInScope) {
Douglas Gregor2168a9f2009-08-11 15:56:57 +00001507 OwningExprResult Base = move(BaseE);
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001509
Douglas Gregora16548e2009-08-11 05:31:07 +00001510 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001511 SS.setRange(QualifierRange);
1512 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001513
Douglas Gregor308047d2009-09-09 00:23:06 +00001514 return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 move(Base), OperatorLoc, OpKind,
Douglas Gregorf14b46f2009-08-31 20:00:26 +00001516 MemberLoc,
1517 Name,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001518 /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001519 &SS,
1520 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00001521 }
1522
Douglas Gregor308047d2009-09-09 00:23:06 +00001523 /// \brief Build a new member reference expression with explicit template
1524 /// arguments.
1525 ///
1526 /// By default, performs semantic analysis to build the new expression.
1527 /// Subclasses may override this routine to provide different behavior.
1528 OwningExprResult RebuildCXXUnresolvedMemberExpr(ExprArg BaseE,
1529 bool IsArrow,
1530 SourceLocation OperatorLoc,
1531 NestedNameSpecifier *Qualifier,
1532 SourceRange QualifierRange,
1533 TemplateName Template,
1534 SourceLocation TemplateNameLoc,
1535 NamedDecl *FirstQualifierInScope,
1536 SourceLocation LAngleLoc,
1537 const TemplateArgument *TemplateArgs,
1538 unsigned NumTemplateArgs,
1539 SourceLocation RAngleLoc) {
1540 OwningExprResult Base = move(BaseE);
1541 tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period;
Mike Stump11289f42009-09-09 15:08:12 +00001542
Douglas Gregor308047d2009-09-09 00:23:06 +00001543 CXXScopeSpec SS;
1544 SS.setRange(QualifierRange);
1545 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001546
Douglas Gregor308047d2009-09-09 00:23:06 +00001547 // FIXME: We're going to end up looking up the template based on its name,
1548 // twice! Also, duplicates part of Sema::ActOnMemberTemplateIdReferenceExpr.
1549 DeclarationName Name;
1550 if (TemplateDecl *ActualTemplate = Template.getAsTemplateDecl())
1551 Name = ActualTemplate->getDeclName();
Mike Stump11289f42009-09-09 15:08:12 +00001552 else if (OverloadedFunctionDecl *Ovl
Douglas Gregor308047d2009-09-09 00:23:06 +00001553 = Template.getAsOverloadedFunctionDecl())
1554 Name = Ovl->getDeclName();
1555 else
1556 Name = Template.getAsDependentTemplateName()->getName();
Mike Stump11289f42009-09-09 15:08:12 +00001557
1558 return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0, move(Base),
Douglas Gregor308047d2009-09-09 00:23:06 +00001559 OperatorLoc, OpKind,
1560 TemplateNameLoc, Name, true,
1561 LAngleLoc, TemplateArgs,
1562 NumTemplateArgs, RAngleLoc,
1563 Sema::DeclPtrTy(), &SS);
1564 }
Mike Stump11289f42009-09-09 15:08:12 +00001565
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 /// \brief Build a new Objective-C @encode expression.
1567 ///
1568 /// By default, performs semantic analysis to build the new expression.
1569 /// Subclasses may override this routine to provide different behavior.
1570 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1571 QualType T,
1572 SourceLocation RParenLoc) {
1573 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1574 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001575 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001576
1577 /// \brief Build a new Objective-C protocol expression.
1578 ///
1579 /// By default, performs semantic analysis to build the new expression.
1580 /// Subclasses may override this routine to provide different behavior.
1581 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1582 SourceLocation AtLoc,
1583 SourceLocation ProtoLoc,
1584 SourceLocation LParenLoc,
1585 SourceLocation RParenLoc) {
1586 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1587 Protocol->getIdentifier(),
1588 AtLoc,
1589 ProtoLoc,
1590 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001591 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001592 }
Mike Stump11289f42009-09-09 15:08:12 +00001593
Douglas Gregora16548e2009-08-11 05:31:07 +00001594 /// \brief Build a new shuffle vector expression.
1595 ///
1596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
1598 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1599 MultiExprArg SubExprs,
1600 SourceLocation RParenLoc) {
1601 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001602 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1604 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1605 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1606 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001607
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 // Build a reference to the __builtin_shufflevector builtin
1609 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001610 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
1612 BuiltinLoc, false, false);
1613 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001614
1615 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 unsigned NumSubExprs = SubExprs.size();
1617 Expr **Subs = (Expr **)SubExprs.release();
1618 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1619 Subs, NumSubExprs,
1620 Builtin->getResultType(),
1621 RParenLoc);
1622 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001623
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 // Type-check the __builtin_shufflevector expression.
1625 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1626 if (Result.isInvalid())
1627 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001628
Douglas Gregora16548e2009-08-11 05:31:07 +00001629 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001630 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001632};
Douglas Gregora16548e2009-08-11 05:31:07 +00001633
Douglas Gregorebe10102009-08-20 07:17:43 +00001634template<typename Derived>
1635Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1636 if (!S)
1637 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001638
Douglas Gregorebe10102009-08-20 07:17:43 +00001639 switch (S->getStmtClass()) {
1640 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001641
Douglas Gregorebe10102009-08-20 07:17:43 +00001642 // Transform individual statement nodes
1643#define STMT(Node, Parent) \
1644 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1645#define EXPR(Node, Parent)
1646#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001647
Douglas Gregorebe10102009-08-20 07:17:43 +00001648 // Transform expressions by calling TransformExpr.
1649#define STMT(Node, Parent)
1650#define EXPR(Node, Parent) case Stmt::Node##Class:
1651#include "clang/AST/StmtNodes.def"
1652 {
1653 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1654 if (E.isInvalid())
1655 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001656
Douglas Gregorebe10102009-08-20 07:17:43 +00001657 return getSema().Owned(E.takeAs<Stmt>());
1658 }
Mike Stump11289f42009-09-09 15:08:12 +00001659 }
1660
Douglas Gregorebe10102009-08-20 07:17:43 +00001661 return SemaRef.Owned(S->Retain());
1662}
Mike Stump11289f42009-09-09 15:08:12 +00001663
1664
Douglas Gregore922c772009-08-04 22:27:00 +00001665template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00001666Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E,
1667 bool isAddressOfOperand) {
1668 if (!E)
1669 return SemaRef.Owned(E);
1670
1671 switch (E->getStmtClass()) {
1672 case Stmt::NoStmtClass: break;
1673#define STMT(Node, Parent) case Stmt::Node##Class: break;
1674#define EXPR(Node, Parent) \
1675 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
1676#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001677 }
1678
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001680}
1681
1682template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001683NestedNameSpecifier *
1684TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001685 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001686 QualType ObjectType,
1687 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001688 if (!NNS)
1689 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001690
Douglas Gregorebe10102009-08-20 07:17:43 +00001691 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001692 NestedNameSpecifier *Prefix = NNS->getPrefix();
1693 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001694 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001695 ObjectType,
1696 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001697 if (!Prefix)
1698 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001699
1700 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001701 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001702 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001703 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001704 }
Mike Stump11289f42009-09-09 15:08:12 +00001705
Douglas Gregor1135c352009-08-06 05:28:30 +00001706 switch (NNS->getKind()) {
1707 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001708 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001709 "Identifier nested-name-specifier with no prefix or object type");
1710 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1711 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001712 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001713
1714 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001715 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001716 ObjectType,
1717 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001718
Douglas Gregor1135c352009-08-06 05:28:30 +00001719 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001720 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001721 = cast_or_null<NamespaceDecl>(
1722 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001723 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001724 Prefix == NNS->getPrefix() &&
1725 NS == NNS->getAsNamespace())
1726 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001727
Douglas Gregor1135c352009-08-06 05:28:30 +00001728 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1729 }
Mike Stump11289f42009-09-09 15:08:12 +00001730
Douglas Gregor1135c352009-08-06 05:28:30 +00001731 case NestedNameSpecifier::Global:
1732 // There is no meaningful transformation that one could perform on the
1733 // global scope.
1734 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001735
Douglas Gregor1135c352009-08-06 05:28:30 +00001736 case NestedNameSpecifier::TypeSpecWithTemplate:
1737 case NestedNameSpecifier::TypeSpec: {
1738 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001739 if (T.isNull())
1740 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001741
Douglas Gregor1135c352009-08-06 05:28:30 +00001742 if (!getDerived().AlwaysRebuild() &&
1743 Prefix == NNS->getPrefix() &&
1744 T == QualType(NNS->getAsType(), 0))
1745 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001746
1747 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1748 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregor1135c352009-08-06 05:28:30 +00001749 T);
1750 }
1751 }
Mike Stump11289f42009-09-09 15:08:12 +00001752
Douglas Gregor1135c352009-08-06 05:28:30 +00001753 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001754 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001755}
1756
1757template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001758DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001759TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
1760 SourceLocation Loc) {
1761 if (!Name)
1762 return Name;
1763
1764 switch (Name.getNameKind()) {
1765 case DeclarationName::Identifier:
1766 case DeclarationName::ObjCZeroArgSelector:
1767 case DeclarationName::ObjCOneArgSelector:
1768 case DeclarationName::ObjCMultiArgSelector:
1769 case DeclarationName::CXXOperatorName:
1770 case DeclarationName::CXXUsingDirective:
1771 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001772
Douglas Gregorf816bd72009-09-03 22:13:48 +00001773 case DeclarationName::CXXConstructorName:
1774 case DeclarationName::CXXDestructorName:
1775 case DeclarationName::CXXConversionFunctionName: {
1776 TemporaryBase Rebase(*this, Loc, Name);
1777 QualType T = getDerived().TransformType(Name.getCXXNameType());
1778 if (T.isNull())
1779 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001780
Douglas Gregorf816bd72009-09-03 22:13:48 +00001781 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001782 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001783 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001784 }
Mike Stump11289f42009-09-09 15:08:12 +00001785 }
1786
Douglas Gregorf816bd72009-09-03 22:13:48 +00001787 return DeclarationName();
1788}
1789
1790template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001791TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001792TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1793 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00001794 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001795 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001796 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1797 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1798 if (!NNS)
1799 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001800
Douglas Gregor71dc5092009-08-06 06:41:21 +00001801 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001802 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001803 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1804 if (!TransTemplate)
1805 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001806
Douglas Gregor71dc5092009-08-06 06:41:21 +00001807 if (!getDerived().AlwaysRebuild() &&
1808 NNS == QTN->getQualifier() &&
1809 TransTemplate == Template)
1810 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001811
Douglas Gregor71dc5092009-08-06 06:41:21 +00001812 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1813 TransTemplate);
1814 }
Mike Stump11289f42009-09-09 15:08:12 +00001815
Douglas Gregor71dc5092009-08-06 06:41:21 +00001816 OverloadedFunctionDecl *Ovl = QTN->getOverloadedFunctionDecl();
1817 assert(Ovl && "Not a template name or an overload set?");
Mike Stump11289f42009-09-09 15:08:12 +00001818 OverloadedFunctionDecl *TransOvl
Douglas Gregor71dc5092009-08-06 06:41:21 +00001819 = cast_or_null<OverloadedFunctionDecl>(getDerived().TransformDecl(Ovl));
1820 if (!TransOvl)
1821 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001822
Douglas Gregor71dc5092009-08-06 06:41:21 +00001823 if (!getDerived().AlwaysRebuild() &&
1824 NNS == QTN->getQualifier() &&
1825 TransOvl == Ovl)
1826 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001827
Douglas Gregor71dc5092009-08-06 06:41:21 +00001828 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1829 TransOvl);
1830 }
Mike Stump11289f42009-09-09 15:08:12 +00001831
Douglas Gregor71dc5092009-08-06 06:41:21 +00001832 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001833 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001834 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1835 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor308047d2009-09-09 00:23:06 +00001836 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001837 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001838
Douglas Gregor71dc5092009-08-06 06:41:21 +00001839 if (!getDerived().AlwaysRebuild() &&
1840 NNS == DTN->getQualifier())
1841 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001842
Douglas Gregor308047d2009-09-09 00:23:06 +00001843 return getDerived().RebuildTemplateName(NNS, *DTN->getName(), ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001844 }
Mike Stump11289f42009-09-09 15:08:12 +00001845
Douglas Gregor71dc5092009-08-06 06:41:21 +00001846 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001847 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001848 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1849 if (!TransTemplate)
1850 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001851
Douglas Gregor71dc5092009-08-06 06:41:21 +00001852 if (!getDerived().AlwaysRebuild() &&
1853 TransTemplate == Template)
1854 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001855
Douglas Gregor71dc5092009-08-06 06:41:21 +00001856 return TemplateName(TransTemplate);
1857 }
Mike Stump11289f42009-09-09 15:08:12 +00001858
Douglas Gregor71dc5092009-08-06 06:41:21 +00001859 OverloadedFunctionDecl *Ovl = Name.getAsOverloadedFunctionDecl();
1860 assert(Ovl && "Not a template name or an overload set?");
Mike Stump11289f42009-09-09 15:08:12 +00001861 OverloadedFunctionDecl *TransOvl
Douglas Gregor71dc5092009-08-06 06:41:21 +00001862 = cast_or_null<OverloadedFunctionDecl>(getDerived().TransformDecl(Ovl));
1863 if (!TransOvl)
1864 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001865
Douglas Gregor71dc5092009-08-06 06:41:21 +00001866 if (!getDerived().AlwaysRebuild() &&
1867 TransOvl == Ovl)
1868 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001869
Douglas Gregor71dc5092009-08-06 06:41:21 +00001870 return TemplateName(TransOvl);
1871}
1872
1873template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001874TemplateArgument
Douglas Gregore922c772009-08-04 22:27:00 +00001875TreeTransform<Derived>::TransformTemplateArgument(const TemplateArgument &Arg) {
1876 switch (Arg.getKind()) {
1877 case TemplateArgument::Null:
1878 case TemplateArgument::Integral:
1879 return Arg;
Mike Stump11289f42009-09-09 15:08:12 +00001880
Douglas Gregore922c772009-08-04 22:27:00 +00001881 case TemplateArgument::Type: {
1882 QualType T = getDerived().TransformType(Arg.getAsType());
1883 if (T.isNull())
1884 return TemplateArgument();
1885 return TemplateArgument(Arg.getLocation(), T);
1886 }
Mike Stump11289f42009-09-09 15:08:12 +00001887
Douglas Gregore922c772009-08-04 22:27:00 +00001888 case TemplateArgument::Declaration: {
1889 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
1890 if (!D)
1891 return TemplateArgument();
1892 return TemplateArgument(Arg.getLocation(), D);
1893 }
Mike Stump11289f42009-09-09 15:08:12 +00001894
Douglas Gregore922c772009-08-04 22:27:00 +00001895 case TemplateArgument::Expression: {
1896 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00001897 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00001898 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00001899
Douglas Gregore922c772009-08-04 22:27:00 +00001900 Sema::OwningExprResult E = getDerived().TransformExpr(Arg.getAsExpr());
1901 if (E.isInvalid())
1902 return TemplateArgument();
1903 return TemplateArgument(E.takeAs<Expr>());
1904 }
Mike Stump11289f42009-09-09 15:08:12 +00001905
Douglas Gregore922c772009-08-04 22:27:00 +00001906 case TemplateArgument::Pack: {
1907 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
1908 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00001909 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00001910 AEnd = Arg.pack_end();
1911 A != AEnd; ++A) {
1912 TemplateArgument TA = getDerived().TransformTemplateArgument(*A);
1913 if (TA.isNull())
1914 return TA;
Mike Stump11289f42009-09-09 15:08:12 +00001915
Douglas Gregore922c772009-08-04 22:27:00 +00001916 TransformedArgs.push_back(TA);
1917 }
1918 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00001919 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00001920 true);
1921 return Result;
1922 }
1923 }
Mike Stump11289f42009-09-09 15:08:12 +00001924
Douglas Gregore922c772009-08-04 22:27:00 +00001925 // Work around bogus GCC warning
1926 return TemplateArgument();
1927}
1928
Douglas Gregord6ff3322009-08-04 16:50:30 +00001929//===----------------------------------------------------------------------===//
1930// Type transformation
1931//===----------------------------------------------------------------------===//
1932
1933template<typename Derived>
1934QualType TreeTransform<Derived>::TransformType(QualType T) {
1935 if (getDerived().AlreadyTransformed(T))
1936 return T;
Mike Stump11289f42009-09-09 15:08:12 +00001937
John McCall8ccfcb52009-09-24 19:53:00 +00001938 QualifierCollector Qs;
1939 const Type *Ty = Qs.strip(T);
1940
Douglas Gregord6ff3322009-08-04 16:50:30 +00001941 QualType Result;
John McCall8ccfcb52009-09-24 19:53:00 +00001942 switch (Ty->getTypeClass()) {
Mike Stump11289f42009-09-09 15:08:12 +00001943#define ABSTRACT_TYPE(CLASS, PARENT)
Douglas Gregord6ff3322009-08-04 16:50:30 +00001944#define TYPE(CLASS, PARENT) \
1945 case Type::CLASS: \
1946 Result = getDerived().Transform##CLASS##Type( \
John McCall8ccfcb52009-09-24 19:53:00 +00001947 static_cast<const CLASS##Type*>(Ty)); \
Douglas Gregord6ff3322009-08-04 16:50:30 +00001948 break;
Mike Stump11289f42009-09-09 15:08:12 +00001949#include "clang/AST/TypeNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00001950 }
Mike Stump11289f42009-09-09 15:08:12 +00001951
Douglas Gregord6ff3322009-08-04 16:50:30 +00001952 if (Result.isNull() || T == Result)
1953 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00001954
John McCall8ccfcb52009-09-24 19:53:00 +00001955 return getDerived().AddTypeQualifiers(Result, Qs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00001956}
Mike Stump11289f42009-09-09 15:08:12 +00001957
Douglas Gregord6ff3322009-08-04 16:50:30 +00001958template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001959QualType
John McCall8ccfcb52009-09-24 19:53:00 +00001960TreeTransform<Derived>::AddTypeQualifiers(QualType T, Qualifiers Quals) {
1961 if (!Quals.empty() && !T->isFunctionType() && !T->isReferenceType())
1962 return SemaRef.Context.getQualifiedType(T, Quals);
Mike Stump11289f42009-09-09 15:08:12 +00001963
Douglas Gregord6ff3322009-08-04 16:50:30 +00001964 return T;
1965}
Argyrios Kyrtzidise9189262009-08-19 01:28:17 +00001966
Douglas Gregord6ff3322009-08-04 16:50:30 +00001967template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001968QualType TreeTransform<Derived>::TransformBuiltinType(const BuiltinType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00001969 // Nothing to do
Mike Stump11289f42009-09-09 15:08:12 +00001970 return QualType(T, 0);
Douglas Gregord6ff3322009-08-04 16:50:30 +00001971}
Mike Stump11289f42009-09-09 15:08:12 +00001972
Douglas Gregord6ff3322009-08-04 16:50:30 +00001973template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001974QualType TreeTransform<Derived>::TransformFixedWidthIntType(
1975 const FixedWidthIntType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00001976 // FIXME: Implement
Mike Stump11289f42009-09-09 15:08:12 +00001977 return QualType(T, 0);
Douglas Gregord6ff3322009-08-04 16:50:30 +00001978}
Mike Stump11289f42009-09-09 15:08:12 +00001979
1980template<typename Derived>
1981QualType TreeTransform<Derived>::TransformComplexType(const ComplexType *T) {
1982 // FIXME: Implement
1983 return QualType(T, 0);
1984}
1985
1986template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00001987QualType TreeTransform<Derived>::TransformPointerType(const PointerType *T) {
1988 QualType PointeeType = getDerived().TransformType(T->getPointeeType());
1989 if (PointeeType.isNull())
1990 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00001991
Douglas Gregord6ff3322009-08-04 16:50:30 +00001992 if (!getDerived().AlwaysRebuild() &&
1993 PointeeType == T->getPointeeType())
1994 return QualType(T, 0);
1995
1996 return getDerived().RebuildPointerType(PointeeType);
1997}
Mike Stump11289f42009-09-09 15:08:12 +00001998
1999template<typename Derived>
2000QualType
2001TreeTransform<Derived>::TransformBlockPointerType(const BlockPointerType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002002 QualType PointeeType = getDerived().TransformType(T->getPointeeType());
2003 if (PointeeType.isNull())
2004 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002005
Douglas Gregord6ff3322009-08-04 16:50:30 +00002006 if (!getDerived().AlwaysRebuild() &&
2007 PointeeType == T->getPointeeType())
2008 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002009
Douglas Gregord6ff3322009-08-04 16:50:30 +00002010 return getDerived().RebuildBlockPointerType(PointeeType);
2011}
2012
Mike Stump11289f42009-09-09 15:08:12 +00002013template<typename Derived>
2014QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00002015TreeTransform<Derived>::TransformLValueReferenceType(
Mike Stump11289f42009-09-09 15:08:12 +00002016 const LValueReferenceType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002017 QualType PointeeType = getDerived().TransformType(T->getPointeeType());
2018 if (PointeeType.isNull())
2019 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002020
Douglas Gregord6ff3322009-08-04 16:50:30 +00002021 if (!getDerived().AlwaysRebuild() &&
2022 PointeeType == T->getPointeeType())
2023 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002024
Douglas Gregord6ff3322009-08-04 16:50:30 +00002025 return getDerived().RebuildLValueReferenceType(PointeeType);
2026}
2027
Mike Stump11289f42009-09-09 15:08:12 +00002028template<typename Derived>
2029QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00002030TreeTransform<Derived>::TransformRValueReferenceType(
Mike Stump11289f42009-09-09 15:08:12 +00002031 const RValueReferenceType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002032 QualType PointeeType = getDerived().TransformType(T->getPointeeType());
2033 if (PointeeType.isNull())
2034 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002035
Douglas Gregord6ff3322009-08-04 16:50:30 +00002036 if (!getDerived().AlwaysRebuild() &&
2037 PointeeType == T->getPointeeType())
2038 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002039
Douglas Gregord6ff3322009-08-04 16:50:30 +00002040 return getDerived().RebuildRValueReferenceType(PointeeType);
2041}
Mike Stump11289f42009-09-09 15:08:12 +00002042
Douglas Gregord6ff3322009-08-04 16:50:30 +00002043template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002044QualType
2045TreeTransform<Derived>::TransformMemberPointerType(const MemberPointerType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002046 QualType PointeeType = getDerived().TransformType(T->getPointeeType());
2047 if (PointeeType.isNull())
2048 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002049
Douglas Gregord6ff3322009-08-04 16:50:30 +00002050 QualType ClassType = getDerived().TransformType(QualType(T->getClass(), 0));
2051 if (ClassType.isNull())
2052 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002053
Douglas Gregord6ff3322009-08-04 16:50:30 +00002054 if (!getDerived().AlwaysRebuild() &&
2055 PointeeType == T->getPointeeType() &&
2056 ClassType == QualType(T->getClass(), 0))
2057 return QualType(T, 0);
2058
2059 return getDerived().RebuildMemberPointerType(PointeeType, ClassType);
2060}
2061
Mike Stump11289f42009-09-09 15:08:12 +00002062template<typename Derived>
2063QualType
2064TreeTransform<Derived>::TransformConstantArrayType(const ConstantArrayType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002065 QualType ElementType = getDerived().TransformType(T->getElementType());
2066 if (ElementType.isNull())
2067 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002068
Douglas Gregord6ff3322009-08-04 16:50:30 +00002069 if (!getDerived().AlwaysRebuild() &&
2070 ElementType == T->getElementType())
2071 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002072
2073 return getDerived().RebuildConstantArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002074 T->getSizeModifier(),
2075 T->getSize(),
John McCall8ccfcb52009-09-24 19:53:00 +00002076 T->getIndexTypeCVRQualifiers());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002077}
Mike Stump11289f42009-09-09 15:08:12 +00002078
Douglas Gregord6ff3322009-08-04 16:50:30 +00002079template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002080QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00002081TreeTransform<Derived>::TransformConstantArrayWithExprType(
Mike Stump11289f42009-09-09 15:08:12 +00002082 const ConstantArrayWithExprType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002083 QualType ElementType = getDerived().TransformType(T->getElementType());
2084 if (ElementType.isNull())
2085 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002086
Douglas Gregore922c772009-08-04 22:27:00 +00002087 // Array bounds are not potentially evaluated contexts
2088 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002089
Douglas Gregore922c772009-08-04 22:27:00 +00002090 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2091 if (Size.isInvalid())
2092 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002093
Douglas Gregord6ff3322009-08-04 16:50:30 +00002094 if (!getDerived().AlwaysRebuild() &&
Douglas Gregore922c772009-08-04 22:27:00 +00002095 ElementType == T->getElementType() &&
2096 Size.get() == T->getSizeExpr())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002097 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002098
2099 return getDerived().RebuildConstantArrayWithExprType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002100 T->getSizeModifier(),
2101 T->getSize(),
Douglas Gregore922c772009-08-04 22:27:00 +00002102 Size.takeAs<Expr>(),
John McCall8ccfcb52009-09-24 19:53:00 +00002103 T->getIndexTypeCVRQualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002104 T->getBracketsRange());
2105}
Mike Stump11289f42009-09-09 15:08:12 +00002106
2107template<typename Derived>
2108QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00002109TreeTransform<Derived>::TransformConstantArrayWithoutExprType(
Mike Stump11289f42009-09-09 15:08:12 +00002110 const ConstantArrayWithoutExprType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002111 QualType ElementType = getDerived().TransformType(T->getElementType());
2112 if (ElementType.isNull())
2113 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002114
Douglas Gregord6ff3322009-08-04 16:50:30 +00002115 if (!getDerived().AlwaysRebuild() &&
2116 ElementType == T->getElementType())
2117 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002118
2119 return getDerived().RebuildConstantArrayWithoutExprType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002120 T->getSizeModifier(),
2121 T->getSize(),
John McCall8ccfcb52009-09-24 19:53:00 +00002122 T->getIndexTypeCVRQualifiers());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002123}
2124
Mike Stump11289f42009-09-09 15:08:12 +00002125template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002126QualType TreeTransform<Derived>::TransformIncompleteArrayType(
Mike Stump11289f42009-09-09 15:08:12 +00002127 const IncompleteArrayType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002128 QualType ElementType = getDerived().TransformType(T->getElementType());
2129 if (ElementType.isNull())
2130 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002131
Douglas Gregord6ff3322009-08-04 16:50:30 +00002132 if (!getDerived().AlwaysRebuild() &&
2133 ElementType == T->getElementType())
2134 return QualType(T, 0);
2135
2136 return getDerived().RebuildIncompleteArrayType(ElementType,
2137 T->getSizeModifier(),
John McCall8ccfcb52009-09-24 19:53:00 +00002138 T->getIndexTypeCVRQualifiers());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002139}
Mike Stump11289f42009-09-09 15:08:12 +00002140
Douglas Gregord6ff3322009-08-04 16:50:30 +00002141template<typename Derived>
2142QualType TreeTransform<Derived>::TransformVariableArrayType(
Mike Stump11289f42009-09-09 15:08:12 +00002143 const VariableArrayType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002144 QualType ElementType = getDerived().TransformType(T->getElementType());
2145 if (ElementType.isNull())
2146 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002147
Douglas Gregore922c772009-08-04 22:27:00 +00002148 // Array bounds are not potentially evaluated contexts
2149 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2150
Douglas Gregord6ff3322009-08-04 16:50:30 +00002151 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2152 if (Size.isInvalid())
2153 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002154
Douglas Gregord6ff3322009-08-04 16:50:30 +00002155 if (!getDerived().AlwaysRebuild() &&
2156 ElementType == T->getElementType() &&
2157 Size.get() == T->getSizeExpr()) {
2158 Size.take();
2159 return QualType(T, 0);
2160 }
Mike Stump11289f42009-09-09 15:08:12 +00002161
2162 return getDerived().RebuildVariableArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002163 T->getSizeModifier(),
2164 move(Size),
John McCall8ccfcb52009-09-24 19:53:00 +00002165 T->getIndexTypeCVRQualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002166 T->getBracketsRange());
2167}
Mike Stump11289f42009-09-09 15:08:12 +00002168
2169template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002170QualType TreeTransform<Derived>::TransformDependentSizedArrayType(
Mike Stump11289f42009-09-09 15:08:12 +00002171 const DependentSizedArrayType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002172 QualType ElementType = getDerived().TransformType(T->getElementType());
2173 if (ElementType.isNull())
2174 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002175
Douglas Gregore922c772009-08-04 22:27:00 +00002176 // Array bounds are not potentially evaluated contexts
2177 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002178
Douglas Gregord6ff3322009-08-04 16:50:30 +00002179 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2180 if (Size.isInvalid())
2181 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002182
Douglas Gregord6ff3322009-08-04 16:50:30 +00002183 if (!getDerived().AlwaysRebuild() &&
2184 ElementType == T->getElementType() &&
2185 Size.get() == T->getSizeExpr()) {
2186 Size.take();
2187 return QualType(T, 0);
2188 }
Mike Stump11289f42009-09-09 15:08:12 +00002189
2190 return getDerived().RebuildDependentSizedArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002191 T->getSizeModifier(),
2192 move(Size),
John McCall8ccfcb52009-09-24 19:53:00 +00002193 T->getIndexTypeCVRQualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002194 T->getBracketsRange());
2195}
Mike Stump11289f42009-09-09 15:08:12 +00002196
2197template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002198QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
Mike Stump11289f42009-09-09 15:08:12 +00002199 const DependentSizedExtVectorType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002200 QualType ElementType = getDerived().TransformType(T->getElementType());
2201 if (ElementType.isNull())
2202 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002203
Douglas Gregore922c772009-08-04 22:27:00 +00002204 // Vector sizes are not potentially evaluated contexts
2205 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2206
Douglas Gregord6ff3322009-08-04 16:50:30 +00002207 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2208 if (Size.isInvalid())
2209 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002210
Douglas Gregord6ff3322009-08-04 16:50:30 +00002211 if (!getDerived().AlwaysRebuild() &&
2212 ElementType == T->getElementType() &&
2213 Size.get() == T->getSizeExpr()) {
2214 Size.take();
2215 return QualType(T, 0);
2216 }
Mike Stump11289f42009-09-09 15:08:12 +00002217
2218 return getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002219 move(Size),
2220 T->getAttributeLoc());
2221}
Mike Stump11289f42009-09-09 15:08:12 +00002222
2223template<typename Derived>
2224QualType TreeTransform<Derived>::TransformVectorType(const VectorType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002225 QualType ElementType = getDerived().TransformType(T->getElementType());
2226 if (ElementType.isNull())
2227 return QualType();
2228
2229 if (!getDerived().AlwaysRebuild() &&
2230 ElementType == T->getElementType())
2231 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002232
Douglas Gregord6ff3322009-08-04 16:50:30 +00002233 return getDerived().RebuildVectorType(ElementType, T->getNumElements());
2234}
Mike Stump11289f42009-09-09 15:08:12 +00002235
2236template<typename Derived>
2237QualType
2238TreeTransform<Derived>::TransformExtVectorType(const ExtVectorType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002239 QualType ElementType = getDerived().TransformType(T->getElementType());
2240 if (ElementType.isNull())
2241 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002242
Douglas Gregord6ff3322009-08-04 16:50:30 +00002243 if (!getDerived().AlwaysRebuild() &&
2244 ElementType == T->getElementType())
2245 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002246
Douglas Gregord6ff3322009-08-04 16:50:30 +00002247 return getDerived().RebuildExtVectorType(ElementType, T->getNumElements(),
2248 /*FIXME*/SourceLocation());
2249}
2250
Mike Stump11289f42009-09-09 15:08:12 +00002251template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002252QualType TreeTransform<Derived>::TransformFunctionProtoType(
Mike Stump11289f42009-09-09 15:08:12 +00002253 const FunctionProtoType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002254 QualType ResultType = getDerived().TransformType(T->getResultType());
2255 if (ResultType.isNull())
2256 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002257
Douglas Gregord6ff3322009-08-04 16:50:30 +00002258 llvm::SmallVector<QualType, 4> ParamTypes;
2259 for (FunctionProtoType::arg_type_iterator Param = T->arg_type_begin(),
Mike Stump11289f42009-09-09 15:08:12 +00002260 ParamEnd = T->arg_type_end();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002261 Param != ParamEnd; ++Param) {
2262 QualType P = getDerived().TransformType(*Param);
2263 if (P.isNull())
2264 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002265
Douglas Gregord6ff3322009-08-04 16:50:30 +00002266 ParamTypes.push_back(P);
2267 }
Mike Stump11289f42009-09-09 15:08:12 +00002268
Douglas Gregord6ff3322009-08-04 16:50:30 +00002269 if (!getDerived().AlwaysRebuild() &&
2270 ResultType == T->getResultType() &&
2271 std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin()))
2272 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002273
2274 return getDerived().RebuildFunctionProtoType(ResultType, ParamTypes.data(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002275 ParamTypes.size(), T->isVariadic(),
2276 T->getTypeQuals());
2277}
Mike Stump11289f42009-09-09 15:08:12 +00002278
Douglas Gregord6ff3322009-08-04 16:50:30 +00002279template<typename Derived>
2280QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
Mike Stump11289f42009-09-09 15:08:12 +00002281 const FunctionNoProtoType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002282 // FIXME: Implement
Mike Stump11289f42009-09-09 15:08:12 +00002283 return QualType(T, 0);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002284}
Mike Stump11289f42009-09-09 15:08:12 +00002285
Douglas Gregord6ff3322009-08-04 16:50:30 +00002286template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002287QualType TreeTransform<Derived>::TransformTypedefType(const TypedefType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002288 TypedefDecl *Typedef
2289 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2290 if (!Typedef)
2291 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002292
Douglas Gregord6ff3322009-08-04 16:50:30 +00002293 if (!getDerived().AlwaysRebuild() &&
2294 Typedef == T->getDecl())
2295 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002296
Douglas Gregord6ff3322009-08-04 16:50:30 +00002297 return getDerived().RebuildTypedefType(Typedef);
2298}
Mike Stump11289f42009-09-09 15:08:12 +00002299
Douglas Gregord6ff3322009-08-04 16:50:30 +00002300template<typename Derived>
2301QualType TreeTransform<Derived>::TransformTypeOfExprType(
Mike Stump11289f42009-09-09 15:08:12 +00002302 const TypeOfExprType *T) {
Douglas Gregore922c772009-08-04 22:27:00 +00002303 // typeof expressions are not potentially evaluated contexts
2304 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002305
Douglas Gregord6ff3322009-08-04 16:50:30 +00002306 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2307 if (E.isInvalid())
2308 return QualType();
2309
2310 if (!getDerived().AlwaysRebuild() &&
2311 E.get() == T->getUnderlyingExpr()) {
2312 E.take();
2313 return QualType(T, 0);
2314 }
Mike Stump11289f42009-09-09 15:08:12 +00002315
Douglas Gregord6ff3322009-08-04 16:50:30 +00002316 return getDerived().RebuildTypeOfExprType(move(E));
2317}
Mike Stump11289f42009-09-09 15:08:12 +00002318
2319template<typename Derived>
2320QualType TreeTransform<Derived>::TransformTypeOfType(const TypeOfType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002321 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2322 if (Underlying.isNull())
2323 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002324
Douglas Gregord6ff3322009-08-04 16:50:30 +00002325 if (!getDerived().AlwaysRebuild() &&
2326 Underlying == T->getUnderlyingType())
2327 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002328
Douglas Gregord6ff3322009-08-04 16:50:30 +00002329 return getDerived().RebuildTypeOfType(Underlying);
2330}
Mike Stump11289f42009-09-09 15:08:12 +00002331
2332template<typename Derived>
2333QualType TreeTransform<Derived>::TransformDecltypeType(const DecltypeType *T) {
Douglas Gregore922c772009-08-04 22:27:00 +00002334 // decltype expressions are not potentially evaluated contexts
2335 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002336
Douglas Gregord6ff3322009-08-04 16:50:30 +00002337 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2338 if (E.isInvalid())
2339 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002340
Douglas Gregord6ff3322009-08-04 16:50:30 +00002341 if (!getDerived().AlwaysRebuild() &&
2342 E.get() == T->getUnderlyingExpr()) {
2343 E.take();
2344 return QualType(T, 0);
2345 }
Mike Stump11289f42009-09-09 15:08:12 +00002346
Douglas Gregord6ff3322009-08-04 16:50:30 +00002347 return getDerived().RebuildDecltypeType(move(E));
2348}
2349
2350template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002351QualType TreeTransform<Derived>::TransformRecordType(const RecordType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002352 RecordDecl *Record
2353 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
2354 if (!Record)
2355 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002356
Douglas Gregord6ff3322009-08-04 16:50:30 +00002357 if (!getDerived().AlwaysRebuild() &&
2358 Record == T->getDecl())
2359 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002360
Douglas Gregord6ff3322009-08-04 16:50:30 +00002361 return getDerived().RebuildRecordType(Record);
2362}
Mike Stump11289f42009-09-09 15:08:12 +00002363
2364template<typename Derived>
2365QualType TreeTransform<Derived>::TransformEnumType(const EnumType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002366 EnumDecl *Enum
2367 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
2368 if (!Enum)
2369 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002370
Douglas Gregord6ff3322009-08-04 16:50:30 +00002371 if (!getDerived().AlwaysRebuild() &&
2372 Enum == T->getDecl())
2373 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002374
Douglas Gregord6ff3322009-08-04 16:50:30 +00002375 return getDerived().RebuildEnumType(Enum);
2376}
John McCallfcc33b02009-09-05 00:15:47 +00002377
2378template <typename Derived>
2379QualType TreeTransform<Derived>::TransformElaboratedType(
2380 const ElaboratedType *T) {
2381 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2382 if (Underlying.isNull())
2383 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002384
John McCallfcc33b02009-09-05 00:15:47 +00002385 if (!getDerived().AlwaysRebuild() &&
2386 Underlying == T->getUnderlyingType())
2387 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002388
John McCallfcc33b02009-09-05 00:15:47 +00002389 return getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2390}
Mike Stump11289f42009-09-09 15:08:12 +00002391
2392
Douglas Gregord6ff3322009-08-04 16:50:30 +00002393template<typename Derived>
2394QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
Mike Stump11289f42009-09-09 15:08:12 +00002395 const TemplateTypeParmType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002396 // Nothing to do
Mike Stump11289f42009-09-09 15:08:12 +00002397 return QualType(T, 0);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002398}
2399
Mike Stump11289f42009-09-09 15:08:12 +00002400template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002401QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
Mike Stump11289f42009-09-09 15:08:12 +00002402 const TemplateSpecializationType *T) {
2403 TemplateName Template
Douglas Gregord6ff3322009-08-04 16:50:30 +00002404 = getDerived().TransformTemplateName(T->getTemplateName());
2405 if (Template.isNull())
2406 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002407
Douglas Gregord6ff3322009-08-04 16:50:30 +00002408 llvm::SmallVector<TemplateArgument, 4> NewTemplateArgs;
2409 NewTemplateArgs.reserve(T->getNumArgs());
2410 for (TemplateSpecializationType::iterator Arg = T->begin(), ArgEnd = T->end();
2411 Arg != ArgEnd; ++Arg) {
2412 TemplateArgument NewArg = getDerived().TransformTemplateArgument(*Arg);
2413 if (NewArg.isNull())
2414 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002415
Douglas Gregord6ff3322009-08-04 16:50:30 +00002416 NewTemplateArgs.push_back(NewArg);
2417 }
Mike Stump11289f42009-09-09 15:08:12 +00002418
Douglas Gregord6ff3322009-08-04 16:50:30 +00002419 // FIXME: early abort if all of the template arguments and such are the
2420 // same.
Mike Stump11289f42009-09-09 15:08:12 +00002421
Douglas Gregord6ff3322009-08-04 16:50:30 +00002422 // FIXME: We're missing the locations of the template name, '<', and '>'.
2423 return getDerived().RebuildTemplateSpecializationType(Template,
2424 NewTemplateArgs.data(),
2425 NewTemplateArgs.size());
2426}
Mike Stump11289f42009-09-09 15:08:12 +00002427
2428template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002429QualType TreeTransform<Derived>::TransformQualifiedNameType(
2430 const QualifiedNameType *T) {
2431 NestedNameSpecifier *NNS
2432 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2433 SourceRange());
2434 if (!NNS)
2435 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002436
Douglas Gregord6ff3322009-08-04 16:50:30 +00002437 QualType Named = getDerived().TransformType(T->getNamedType());
2438 if (Named.isNull())
2439 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002440
Douglas Gregord6ff3322009-08-04 16:50:30 +00002441 if (!getDerived().AlwaysRebuild() &&
2442 NNS == T->getQualifier() &&
2443 Named == T->getNamedType())
2444 return QualType(T, 0);
2445
2446 return getDerived().RebuildQualifiedNameType(NNS, Named);
2447}
Mike Stump11289f42009-09-09 15:08:12 +00002448
2449template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002450QualType TreeTransform<Derived>::TransformTypenameType(const TypenameType *T) {
2451 NestedNameSpecifier *NNS
2452 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregor15acfb92009-08-06 16:20:37 +00002453 SourceRange(/*FIXME:*/getDerived().getBaseLocation()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002454 if (!NNS)
2455 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002456
Douglas Gregord6ff3322009-08-04 16:50:30 +00002457 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002458 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002459 = getDerived().TransformType(QualType(TemplateId, 0));
2460 if (NewTemplateId.isNull())
2461 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002462
Douglas Gregord6ff3322009-08-04 16:50:30 +00002463 if (!getDerived().AlwaysRebuild() &&
2464 NNS == T->getQualifier() &&
2465 NewTemplateId == QualType(TemplateId, 0))
2466 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002467
Douglas Gregord6ff3322009-08-04 16:50:30 +00002468 return getDerived().RebuildTypenameType(NNS, NewTemplateId);
2469 }
2470
2471 return getDerived().RebuildTypenameType(NNS, T->getIdentifier());
2472}
Mike Stump11289f42009-09-09 15:08:12 +00002473
Douglas Gregord6ff3322009-08-04 16:50:30 +00002474template<typename Derived>
2475QualType TreeTransform<Derived>::TransformObjCInterfaceType(
Mike Stump11289f42009-09-09 15:08:12 +00002476 const ObjCInterfaceType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002477 // FIXME: Implement
Mike Stump11289f42009-09-09 15:08:12 +00002478 return QualType(T, 0);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002479}
Mike Stump11289f42009-09-09 15:08:12 +00002480
2481template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002482QualType TreeTransform<Derived>::TransformObjCObjectPointerType(
Mike Stump11289f42009-09-09 15:08:12 +00002483 const ObjCObjectPointerType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002484 // FIXME: Implement
Mike Stump11289f42009-09-09 15:08:12 +00002485 return QualType(T, 0);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002486}
2487
2488//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00002489// Statement transformation
2490//===----------------------------------------------------------------------===//
2491template<typename Derived>
2492Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002493TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2494 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002495}
2496
2497template<typename Derived>
2498Sema::OwningStmtResult
2499TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2500 return getDerived().TransformCompoundStmt(S, false);
2501}
2502
2503template<typename Derived>
2504Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002505TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00002506 bool IsStmtExpr) {
2507 bool SubStmtChanged = false;
2508 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
2509 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
2510 B != BEnd; ++B) {
2511 OwningStmtResult Result = getDerived().TransformStmt(*B);
2512 if (Result.isInvalid())
2513 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002514
Douglas Gregorebe10102009-08-20 07:17:43 +00002515 SubStmtChanged = SubStmtChanged || Result.get() != *B;
2516 Statements.push_back(Result.takeAs<Stmt>());
2517 }
Mike Stump11289f42009-09-09 15:08:12 +00002518
Douglas Gregorebe10102009-08-20 07:17:43 +00002519 if (!getDerived().AlwaysRebuild() &&
2520 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00002521 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002522
2523 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
2524 move_arg(Statements),
2525 S->getRBracLoc(),
2526 IsStmtExpr);
2527}
Mike Stump11289f42009-09-09 15:08:12 +00002528
Douglas Gregorebe10102009-08-20 07:17:43 +00002529template<typename Derived>
2530Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002531TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002532 // The case value expressions are not potentially evaluated.
2533 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002534
Douglas Gregorebe10102009-08-20 07:17:43 +00002535 // Transform the left-hand case value.
2536 OwningExprResult LHS = getDerived().TransformExpr(S->getLHS());
2537 if (LHS.isInvalid())
2538 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002539
Douglas Gregorebe10102009-08-20 07:17:43 +00002540 // Transform the right-hand case value (for the GNU case-range extension).
2541 OwningExprResult RHS = getDerived().TransformExpr(S->getRHS());
2542 if (RHS.isInvalid())
2543 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002544
Douglas Gregorebe10102009-08-20 07:17:43 +00002545 // Build the case statement.
2546 // Case statements are always rebuilt so that they will attached to their
2547 // transformed switch statement.
2548 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
2549 move(LHS),
2550 S->getEllipsisLoc(),
2551 move(RHS),
2552 S->getColonLoc());
2553 if (Case.isInvalid())
2554 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002555
Douglas Gregorebe10102009-08-20 07:17:43 +00002556 // Transform the statement following the case
2557 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
2558 if (SubStmt.isInvalid())
2559 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002560
Douglas Gregorebe10102009-08-20 07:17:43 +00002561 // Attach the body to the case statement
2562 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
2563}
2564
2565template<typename Derived>
2566Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002567TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002568 // Transform the statement following the default case
2569 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
2570 if (SubStmt.isInvalid())
2571 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002572
Douglas Gregorebe10102009-08-20 07:17:43 +00002573 // Default statements are always rebuilt
2574 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
2575 move(SubStmt));
2576}
Mike Stump11289f42009-09-09 15:08:12 +00002577
Douglas Gregorebe10102009-08-20 07:17:43 +00002578template<typename Derived>
2579Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002580TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002581 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
2582 if (SubStmt.isInvalid())
2583 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002584
Douglas Gregorebe10102009-08-20 07:17:43 +00002585 // FIXME: Pass the real colon location in.
2586 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
2587 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
2588 move(SubStmt));
2589}
Mike Stump11289f42009-09-09 15:08:12 +00002590
Douglas Gregorebe10102009-08-20 07:17:43 +00002591template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002592Sema::OwningStmtResult
2593TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002594 // Transform the condition
2595 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
2596 if (Cond.isInvalid())
2597 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002598
Douglas Gregorebe10102009-08-20 07:17:43 +00002599 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00002600
Douglas Gregorebe10102009-08-20 07:17:43 +00002601 // Transform the "then" branch.
2602 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
2603 if (Then.isInvalid())
2604 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002605
Douglas Gregorebe10102009-08-20 07:17:43 +00002606 // Transform the "else" branch.
2607 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
2608 if (Else.isInvalid())
2609 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002610
Douglas Gregorebe10102009-08-20 07:17:43 +00002611 if (!getDerived().AlwaysRebuild() &&
2612 FullCond->get() == S->getCond() &&
2613 Then.get() == S->getThen() &&
2614 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00002615 return SemaRef.Owned(S->Retain());
2616
Douglas Gregorebe10102009-08-20 07:17:43 +00002617 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00002618 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00002619}
2620
2621template<typename Derived>
2622Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002623TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002624 // Transform the condition.
2625 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
2626 if (Cond.isInvalid())
2627 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002628
Douglas Gregorebe10102009-08-20 07:17:43 +00002629 // Rebuild the switch statement.
2630 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(move(Cond));
2631 if (Switch.isInvalid())
2632 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002633
Douglas Gregorebe10102009-08-20 07:17:43 +00002634 // Transform the body of the switch statement.
2635 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
2636 if (Body.isInvalid())
2637 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002638
Douglas Gregorebe10102009-08-20 07:17:43 +00002639 // Complete the switch statement.
2640 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
2641 move(Body));
2642}
Mike Stump11289f42009-09-09 15:08:12 +00002643
Douglas Gregorebe10102009-08-20 07:17:43 +00002644template<typename Derived>
2645Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002646TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002647 // Transform the condition
2648 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
2649 if (Cond.isInvalid())
2650 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002651
Douglas Gregorebe10102009-08-20 07:17:43 +00002652 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00002653
Douglas Gregorebe10102009-08-20 07:17:43 +00002654 // Transform the body
2655 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
2656 if (Body.isInvalid())
2657 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002658
Douglas Gregorebe10102009-08-20 07:17:43 +00002659 if (!getDerived().AlwaysRebuild() &&
2660 FullCond->get() == S->getCond() &&
2661 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00002662 return SemaRef.Owned(S->Retain());
2663
Douglas Gregorebe10102009-08-20 07:17:43 +00002664 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, move(Body));
2665}
Mike Stump11289f42009-09-09 15:08:12 +00002666
Douglas Gregorebe10102009-08-20 07:17:43 +00002667template<typename Derived>
2668Sema::OwningStmtResult
2669TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
2670 // Transform the condition
2671 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
2672 if (Cond.isInvalid())
2673 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002674
Douglas Gregorebe10102009-08-20 07:17:43 +00002675 // Transform the body
2676 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
2677 if (Body.isInvalid())
2678 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002679
Douglas Gregorebe10102009-08-20 07:17:43 +00002680 if (!getDerived().AlwaysRebuild() &&
2681 Cond.get() == S->getCond() &&
2682 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00002683 return SemaRef.Owned(S->Retain());
2684
Douglas Gregorebe10102009-08-20 07:17:43 +00002685 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
2686 /*FIXME:*/S->getWhileLoc(), move(Cond),
2687 S->getRParenLoc());
2688}
Mike Stump11289f42009-09-09 15:08:12 +00002689
Douglas Gregorebe10102009-08-20 07:17:43 +00002690template<typename Derived>
2691Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002692TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002693 // Transform the initialization statement
2694 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
2695 if (Init.isInvalid())
2696 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002697
Douglas Gregorebe10102009-08-20 07:17:43 +00002698 // Transform the condition
2699 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
2700 if (Cond.isInvalid())
2701 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002702
Douglas Gregorebe10102009-08-20 07:17:43 +00002703 // Transform the increment
2704 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
2705 if (Inc.isInvalid())
2706 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002707
Douglas Gregorebe10102009-08-20 07:17:43 +00002708 // Transform the body
2709 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
2710 if (Body.isInvalid())
2711 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002712
Douglas Gregorebe10102009-08-20 07:17:43 +00002713 if (!getDerived().AlwaysRebuild() &&
2714 Init.get() == S->getInit() &&
2715 Cond.get() == S->getCond() &&
2716 Inc.get() == S->getInc() &&
2717 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00002718 return SemaRef.Owned(S->Retain());
2719
Douglas Gregorebe10102009-08-20 07:17:43 +00002720 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
2721 move(Init), move(Cond), move(Inc),
2722 S->getRParenLoc(), move(Body));
2723}
2724
2725template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002726Sema::OwningStmtResult
2727TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002728 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00002729 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00002730 S->getLabel());
2731}
2732
2733template<typename Derived>
2734Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002735TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002736 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
2737 if (Target.isInvalid())
2738 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002739
Douglas Gregorebe10102009-08-20 07:17:43 +00002740 if (!getDerived().AlwaysRebuild() &&
2741 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00002742 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002743
2744 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
2745 move(Target));
2746}
2747
2748template<typename Derived>
2749Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002750TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
2751 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002752}
Mike Stump11289f42009-09-09 15:08:12 +00002753
Douglas Gregorebe10102009-08-20 07:17:43 +00002754template<typename Derived>
2755Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002756TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
2757 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002758}
Mike Stump11289f42009-09-09 15:08:12 +00002759
Douglas Gregorebe10102009-08-20 07:17:43 +00002760template<typename Derived>
2761Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002762TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002763 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
2764 if (Result.isInvalid())
2765 return SemaRef.StmtError();
2766
Mike Stump11289f42009-09-09 15:08:12 +00002767 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00002768 // to tell whether the return type of the function has changed.
2769 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
2770}
Mike Stump11289f42009-09-09 15:08:12 +00002771
Douglas Gregorebe10102009-08-20 07:17:43 +00002772template<typename Derived>
2773Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002774TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002775 bool DeclChanged = false;
2776 llvm::SmallVector<Decl *, 4> Decls;
2777 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
2778 D != DEnd; ++D) {
2779 Decl *Transformed = getDerived().TransformDefinition(*D);
2780 if (!Transformed)
2781 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002782
Douglas Gregorebe10102009-08-20 07:17:43 +00002783 if (Transformed != *D)
2784 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00002785
Douglas Gregorebe10102009-08-20 07:17:43 +00002786 Decls.push_back(Transformed);
2787 }
Mike Stump11289f42009-09-09 15:08:12 +00002788
Douglas Gregorebe10102009-08-20 07:17:43 +00002789 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00002790 return SemaRef.Owned(S->Retain());
2791
2792 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00002793 S->getStartLoc(), S->getEndLoc());
2794}
Mike Stump11289f42009-09-09 15:08:12 +00002795
Douglas Gregorebe10102009-08-20 07:17:43 +00002796template<typename Derived>
2797Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002798TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002799 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00002800 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002801}
2802
2803template<typename Derived>
2804Sema::OwningStmtResult
2805TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
2806 // FIXME: Implement!
2807 assert(false && "Inline assembly cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00002808 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002809}
2810
2811
2812template<typename Derived>
2813Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002814TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002815 // FIXME: Implement this
2816 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00002817 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002818}
Mike Stump11289f42009-09-09 15:08:12 +00002819
Douglas Gregorebe10102009-08-20 07:17:43 +00002820template<typename Derived>
2821Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002822TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002823 // FIXME: Implement this
2824 assert(false && "Cannot transform an Objective-C @catch statement");
2825 return SemaRef.Owned(S->Retain());
2826}
Mike Stump11289f42009-09-09 15:08:12 +00002827
Douglas Gregorebe10102009-08-20 07:17:43 +00002828template<typename Derived>
2829Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002830TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002831 // FIXME: Implement this
2832 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00002833 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002834}
Mike Stump11289f42009-09-09 15:08:12 +00002835
Douglas Gregorebe10102009-08-20 07:17:43 +00002836template<typename Derived>
2837Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002838TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002839 // FIXME: Implement this
2840 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00002841 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002842}
Mike Stump11289f42009-09-09 15:08:12 +00002843
Douglas Gregorebe10102009-08-20 07:17:43 +00002844template<typename Derived>
2845Sema::OwningStmtResult
2846TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00002847 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002848 // FIXME: Implement this
2849 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00002850 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002851}
2852
2853template<typename Derived>
2854Sema::OwningStmtResult
2855TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00002856 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002857 // FIXME: Implement this
2858 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00002859 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002860}
2861
2862
2863template<typename Derived>
2864Sema::OwningStmtResult
2865TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
2866 // Transform the exception declaration, if any.
2867 VarDecl *Var = 0;
2868 if (S->getExceptionDecl()) {
2869 VarDecl *ExceptionDecl = S->getExceptionDecl();
2870 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
2871 ExceptionDecl->getDeclName());
2872
2873 QualType T = getDerived().TransformType(ExceptionDecl->getType());
2874 if (T.isNull())
2875 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002876
Douglas Gregorebe10102009-08-20 07:17:43 +00002877 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
2878 T,
2879 ExceptionDecl->getDeclaratorInfo(),
2880 ExceptionDecl->getIdentifier(),
2881 ExceptionDecl->getLocation(),
2882 /*FIXME: Inaccurate*/
2883 SourceRange(ExceptionDecl->getLocation()));
2884 if (!Var || Var->isInvalidDecl()) {
2885 if (Var)
2886 Var->Destroy(SemaRef.Context);
2887 return SemaRef.StmtError();
2888 }
2889 }
Mike Stump11289f42009-09-09 15:08:12 +00002890
Douglas Gregorebe10102009-08-20 07:17:43 +00002891 // Transform the actual exception handler.
2892 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
2893 if (Handler.isInvalid()) {
2894 if (Var)
2895 Var->Destroy(SemaRef.Context);
2896 return SemaRef.StmtError();
2897 }
Mike Stump11289f42009-09-09 15:08:12 +00002898
Douglas Gregorebe10102009-08-20 07:17:43 +00002899 if (!getDerived().AlwaysRebuild() &&
2900 !Var &&
2901 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00002902 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002903
2904 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
2905 Var,
2906 move(Handler));
2907}
Mike Stump11289f42009-09-09 15:08:12 +00002908
Douglas Gregorebe10102009-08-20 07:17:43 +00002909template<typename Derived>
2910Sema::OwningStmtResult
2911TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
2912 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00002913 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00002914 = getDerived().TransformCompoundStmt(S->getTryBlock());
2915 if (TryBlock.isInvalid())
2916 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002917
Douglas Gregorebe10102009-08-20 07:17:43 +00002918 // Transform the handlers.
2919 bool HandlerChanged = false;
2920 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
2921 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00002922 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00002923 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
2924 if (Handler.isInvalid())
2925 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002926
Douglas Gregorebe10102009-08-20 07:17:43 +00002927 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
2928 Handlers.push_back(Handler.takeAs<Stmt>());
2929 }
Mike Stump11289f42009-09-09 15:08:12 +00002930
Douglas Gregorebe10102009-08-20 07:17:43 +00002931 if (!getDerived().AlwaysRebuild() &&
2932 TryBlock.get() == S->getTryBlock() &&
2933 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00002934 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002935
2936 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00002937 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00002938}
Mike Stump11289f42009-09-09 15:08:12 +00002939
Douglas Gregorebe10102009-08-20 07:17:43 +00002940//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00002941// Expression transformation
2942//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00002943template<typename Derived>
2944Sema::OwningExprResult
2945TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
2946 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00002947}
Mike Stump11289f42009-09-09 15:08:12 +00002948
2949template<typename Derived>
2950Sema::OwningExprResult
2951TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
2952 NamedDecl *ND
Douglas Gregora16548e2009-08-11 05:31:07 +00002953 = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl()));
2954 if (!ND)
2955 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002956
Douglas Gregora16548e2009-08-11 05:31:07 +00002957 if (!getDerived().AlwaysRebuild() && ND == E->getDecl())
Mike Stump11289f42009-09-09 15:08:12 +00002958 return SemaRef.Owned(E->Retain());
2959
Douglas Gregora16548e2009-08-11 05:31:07 +00002960 return getDerived().RebuildDeclRefExpr(ND, E->getLocation());
2961}
Mike Stump11289f42009-09-09 15:08:12 +00002962
Douglas Gregora16548e2009-08-11 05:31:07 +00002963template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002964Sema::OwningExprResult
2965TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
2966 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00002967}
Mike Stump11289f42009-09-09 15:08:12 +00002968
Douglas Gregora16548e2009-08-11 05:31:07 +00002969template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002970Sema::OwningExprResult
2971TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
2972 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00002973}
Mike Stump11289f42009-09-09 15:08:12 +00002974
Douglas Gregora16548e2009-08-11 05:31:07 +00002975template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002976Sema::OwningExprResult
2977TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
2978 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00002979}
Mike Stump11289f42009-09-09 15:08:12 +00002980
Douglas Gregora16548e2009-08-11 05:31:07 +00002981template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002982Sema::OwningExprResult
2983TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
2984 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00002985}
Mike Stump11289f42009-09-09 15:08:12 +00002986
Douglas Gregora16548e2009-08-11 05:31:07 +00002987template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002988Sema::OwningExprResult
2989TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
2990 return SemaRef.Owned(E->Retain());
2991}
2992
2993template<typename Derived>
2994Sema::OwningExprResult
2995TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002996 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
2997 if (SubExpr.isInvalid())
2998 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002999
Douglas Gregora16548e2009-08-11 05:31:07 +00003000 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003001 return SemaRef.Owned(E->Retain());
3002
3003 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003004 E->getRParen());
3005}
3006
Mike Stump11289f42009-09-09 15:08:12 +00003007template<typename Derived>
3008Sema::OwningExprResult
3009TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003010 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3011 if (SubExpr.isInvalid())
3012 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003013
Douglas Gregora16548e2009-08-11 05:31:07 +00003014 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003015 return SemaRef.Owned(E->Retain());
3016
Douglas Gregora16548e2009-08-11 05:31:07 +00003017 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3018 E->getOpcode(),
3019 move(SubExpr));
3020}
Mike Stump11289f42009-09-09 15:08:12 +00003021
Douglas Gregora16548e2009-08-11 05:31:07 +00003022template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003023Sema::OwningExprResult
3024TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003025 if (E->isArgumentType()) {
3026 QualType T = getDerived().TransformType(E->getArgumentType());
3027 if (T.isNull())
3028 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003029
Douglas Gregora16548e2009-08-11 05:31:07 +00003030 if (!getDerived().AlwaysRebuild() && T == E->getArgumentType())
3031 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003032
3033 return getDerived().RebuildSizeOfAlignOf(T, E->getOperatorLoc(),
3034 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003035 E->getSourceRange());
3036 }
Mike Stump11289f42009-09-09 15:08:12 +00003037
Douglas Gregora16548e2009-08-11 05:31:07 +00003038 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003039 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003040 // C++0x [expr.sizeof]p1:
3041 // The operand is either an expression, which is an unevaluated operand
3042 // [...]
3043 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003044
Douglas Gregora16548e2009-08-11 05:31:07 +00003045 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3046 if (SubExpr.isInvalid())
3047 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003048
Douglas Gregora16548e2009-08-11 05:31:07 +00003049 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3050 return SemaRef.Owned(E->Retain());
3051 }
Mike Stump11289f42009-09-09 15:08:12 +00003052
Douglas Gregora16548e2009-08-11 05:31:07 +00003053 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3054 E->isSizeOf(),
3055 E->getSourceRange());
3056}
Mike Stump11289f42009-09-09 15:08:12 +00003057
Douglas Gregora16548e2009-08-11 05:31:07 +00003058template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003059Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003060TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
3061 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3062 if (LHS.isInvalid())
3063 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003064
Douglas Gregora16548e2009-08-11 05:31:07 +00003065 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3066 if (RHS.isInvalid())
3067 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003068
3069
Douglas Gregora16548e2009-08-11 05:31:07 +00003070 if (!getDerived().AlwaysRebuild() &&
3071 LHS.get() == E->getLHS() &&
3072 RHS.get() == E->getRHS())
3073 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003074
Douglas Gregora16548e2009-08-11 05:31:07 +00003075 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3076 /*FIXME:*/E->getLHS()->getLocStart(),
3077 move(RHS),
3078 E->getRBracketLoc());
3079}
Mike Stump11289f42009-09-09 15:08:12 +00003080
3081template<typename Derived>
3082Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003083TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
3084 // Transform the callee.
3085 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3086 if (Callee.isInvalid())
3087 return SemaRef.ExprError();
3088
3089 // Transform arguments.
3090 bool ArgChanged = false;
3091 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3092 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3093 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3094 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3095 if (Arg.isInvalid())
3096 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003097
Douglas Gregora16548e2009-08-11 05:31:07 +00003098 // FIXME: Wrong source location information for the ','.
3099 FakeCommaLocs.push_back(
3100 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003101
3102 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003103 Args.push_back(Arg.takeAs<Expr>());
3104 }
Mike Stump11289f42009-09-09 15:08:12 +00003105
Douglas Gregora16548e2009-08-11 05:31:07 +00003106 if (!getDerived().AlwaysRebuild() &&
3107 Callee.get() == E->getCallee() &&
3108 !ArgChanged)
3109 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003110
Douglas Gregora16548e2009-08-11 05:31:07 +00003111 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003112 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003113 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3114 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3115 move_arg(Args),
3116 FakeCommaLocs.data(),
3117 E->getRParenLoc());
3118}
Mike Stump11289f42009-09-09 15:08:12 +00003119
3120template<typename Derived>
3121Sema::OwningExprResult
3122TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003123 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3124 if (Base.isInvalid())
3125 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003126
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003127 NestedNameSpecifier *Qualifier = 0;
3128 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003129 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003130 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3131 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003132 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003133 return SemaRef.ExprError();
3134 }
Mike Stump11289f42009-09-09 15:08:12 +00003135
3136 NamedDecl *Member
Douglas Gregora16548e2009-08-11 05:31:07 +00003137 = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getMemberDecl()));
3138 if (!Member)
3139 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003140
Douglas Gregora16548e2009-08-11 05:31:07 +00003141 if (!getDerived().AlwaysRebuild() &&
3142 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003143 Qualifier == E->getQualifier() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003144 Member == E->getMemberDecl())
Mike Stump11289f42009-09-09 15:08:12 +00003145 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003146
3147 // FIXME: Bogus source location for the operator
3148 SourceLocation FakeOperatorLoc
3149 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3150
3151 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3152 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003153 Qualifier,
3154 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003155 E->getMemberLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003156 Member);
Douglas Gregora16548e2009-08-11 05:31:07 +00003157}
Mike Stump11289f42009-09-09 15:08:12 +00003158
Douglas Gregora16548e2009-08-11 05:31:07 +00003159template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003160Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003161TreeTransform<Derived>::TransformCastExpr(CastExpr *E) {
3162 assert(false && "Cannot transform abstract class");
3163 return SemaRef.Owned(E->Retain());
3164}
3165
3166template<typename Derived>
3167Sema::OwningExprResult
3168TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003169 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3170 if (LHS.isInvalid())
3171 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003172
Douglas Gregora16548e2009-08-11 05:31:07 +00003173 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3174 if (RHS.isInvalid())
3175 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003176
Douglas Gregora16548e2009-08-11 05:31:07 +00003177 if (!getDerived().AlwaysRebuild() &&
3178 LHS.get() == E->getLHS() &&
3179 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003180 return SemaRef.Owned(E->Retain());
3181
Douglas Gregora16548e2009-08-11 05:31:07 +00003182 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3183 move(LHS), move(RHS));
3184}
3185
Mike Stump11289f42009-09-09 15:08:12 +00003186template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003187Sema::OwningExprResult
3188TreeTransform<Derived>::TransformCompoundAssignOperator(
3189 CompoundAssignOperator *E) {
3190 return getDerived().TransformBinaryOperator(E);
3191}
Mike Stump11289f42009-09-09 15:08:12 +00003192
Douglas Gregora16548e2009-08-11 05:31:07 +00003193template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003194Sema::OwningExprResult
3195TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003196 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3197 if (Cond.isInvalid())
3198 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003199
Douglas Gregora16548e2009-08-11 05:31:07 +00003200 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3201 if (LHS.isInvalid())
3202 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003203
Douglas Gregora16548e2009-08-11 05:31:07 +00003204 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3205 if (RHS.isInvalid())
3206 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003207
Douglas Gregora16548e2009-08-11 05:31:07 +00003208 if (!getDerived().AlwaysRebuild() &&
3209 Cond.get() == E->getCond() &&
3210 LHS.get() == E->getLHS() &&
3211 RHS.get() == E->getRHS())
3212 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003213
3214 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003215 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003216 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003217 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003218 move(RHS));
3219}
Mike Stump11289f42009-09-09 15:08:12 +00003220
3221template<typename Derived>
3222Sema::OwningExprResult
3223TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003224 QualType T = getDerived().TransformType(E->getType());
3225 if (T.isNull())
3226 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003227
Douglas Gregora16548e2009-08-11 05:31:07 +00003228 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3229 if (SubExpr.isInvalid())
3230 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003231
Douglas Gregora16548e2009-08-11 05:31:07 +00003232 if (!getDerived().AlwaysRebuild() &&
3233 T == E->getType() &&
3234 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003235 return SemaRef.Owned(E->Retain());
3236
Douglas Gregora16548e2009-08-11 05:31:07 +00003237 return getDerived().RebuildImplicitCastExpr(T, E->getCastKind(),
Mike Stump11289f42009-09-09 15:08:12 +00003238 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00003239 E->isLvalueCast());
3240}
Mike Stump11289f42009-09-09 15:08:12 +00003241
Douglas Gregora16548e2009-08-11 05:31:07 +00003242template<typename Derived>
3243Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003244TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) {
3245 assert(false && "Cannot transform abstract class");
3246 return SemaRef.Owned(E->Retain());
3247}
3248
3249template<typename Derived>
3250Sema::OwningExprResult
3251TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003252 QualType T;
3253 {
3254 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003255 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003256 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3257 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003258
Douglas Gregora16548e2009-08-11 05:31:07 +00003259 T = getDerived().TransformType(E->getTypeAsWritten());
3260 if (T.isNull())
3261 return SemaRef.ExprError();
3262 }
Mike Stump11289f42009-09-09 15:08:12 +00003263
Douglas Gregora16548e2009-08-11 05:31:07 +00003264 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3265 if (SubExpr.isInvalid())
3266 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003267
Douglas Gregora16548e2009-08-11 05:31:07 +00003268 if (!getDerived().AlwaysRebuild() &&
3269 T == E->getTypeAsWritten() &&
3270 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003271 return SemaRef.Owned(E->Retain());
3272
Douglas Gregora16548e2009-08-11 05:31:07 +00003273 return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T,
3274 E->getRParenLoc(),
3275 move(SubExpr));
3276}
Mike Stump11289f42009-09-09 15:08:12 +00003277
Douglas Gregora16548e2009-08-11 05:31:07 +00003278template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003279Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003280TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
3281 QualType T;
3282 {
3283 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003284 SourceLocation FakeTypeLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003285 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3286 TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003287
Douglas Gregora16548e2009-08-11 05:31:07 +00003288 T = getDerived().TransformType(E->getType());
3289 if (T.isNull())
3290 return SemaRef.ExprError();
3291 }
Mike Stump11289f42009-09-09 15:08:12 +00003292
Douglas Gregora16548e2009-08-11 05:31:07 +00003293 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3294 if (Init.isInvalid())
3295 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003296
Douglas Gregora16548e2009-08-11 05:31:07 +00003297 if (!getDerived().AlwaysRebuild() &&
3298 T == E->getType() &&
3299 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003300 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003301
3302 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T,
3303 /*FIXME:*/E->getInitializer()->getLocEnd(),
3304 move(Init));
3305}
Mike Stump11289f42009-09-09 15:08:12 +00003306
Douglas Gregora16548e2009-08-11 05:31:07 +00003307template<typename Derived>
3308Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003309TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003310 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3311 if (Base.isInvalid())
3312 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003313
Douglas Gregora16548e2009-08-11 05:31:07 +00003314 if (!getDerived().AlwaysRebuild() &&
3315 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003316 return SemaRef.Owned(E->Retain());
3317
Douglas Gregora16548e2009-08-11 05:31:07 +00003318 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003319 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003320 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3321 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3322 E->getAccessorLoc(),
3323 E->getAccessor());
3324}
Mike Stump11289f42009-09-09 15:08:12 +00003325
Douglas Gregora16548e2009-08-11 05:31:07 +00003326template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003327Sema::OwningExprResult
3328TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003329 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003330
Douglas Gregora16548e2009-08-11 05:31:07 +00003331 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3332 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3333 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3334 if (Init.isInvalid())
3335 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003336
Douglas Gregora16548e2009-08-11 05:31:07 +00003337 InitChanged = InitChanged || Init.get() != E->getInit(I);
3338 Inits.push_back(Init.takeAs<Expr>());
3339 }
Mike Stump11289f42009-09-09 15:08:12 +00003340
Douglas Gregora16548e2009-08-11 05:31:07 +00003341 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003342 return SemaRef.Owned(E->Retain());
3343
Douglas Gregora16548e2009-08-11 05:31:07 +00003344 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
3345 E->getRBraceLoc());
3346}
Mike Stump11289f42009-09-09 15:08:12 +00003347
Douglas Gregora16548e2009-08-11 05:31:07 +00003348template<typename Derived>
3349Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003350TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003351 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00003352
Douglas Gregorebe10102009-08-20 07:17:43 +00003353 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00003354 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3355 if (Init.isInvalid())
3356 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003357
Douglas Gregorebe10102009-08-20 07:17:43 +00003358 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00003359 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3360 bool ExprChanged = false;
3361 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3362 DEnd = E->designators_end();
3363 D != DEnd; ++D) {
3364 if (D->isFieldDesignator()) {
3365 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3366 D->getDotLoc(),
3367 D->getFieldLoc()));
3368 continue;
3369 }
Mike Stump11289f42009-09-09 15:08:12 +00003370
Douglas Gregora16548e2009-08-11 05:31:07 +00003371 if (D->isArrayDesignator()) {
3372 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3373 if (Index.isInvalid())
3374 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003375
3376 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003377 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003378
Douglas Gregora16548e2009-08-11 05:31:07 +00003379 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3380 ArrayExprs.push_back(Index.release());
3381 continue;
3382 }
Mike Stump11289f42009-09-09 15:08:12 +00003383
Douglas Gregora16548e2009-08-11 05:31:07 +00003384 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00003385 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00003386 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3387 if (Start.isInvalid())
3388 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003389
Douglas Gregora16548e2009-08-11 05:31:07 +00003390 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3391 if (End.isInvalid())
3392 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003393
3394 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003395 End.get(),
3396 D->getLBracketLoc(),
3397 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003398
Douglas Gregora16548e2009-08-11 05:31:07 +00003399 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
3400 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00003401
Douglas Gregora16548e2009-08-11 05:31:07 +00003402 ArrayExprs.push_back(Start.release());
3403 ArrayExprs.push_back(End.release());
3404 }
Mike Stump11289f42009-09-09 15:08:12 +00003405
Douglas Gregora16548e2009-08-11 05:31:07 +00003406 if (!getDerived().AlwaysRebuild() &&
3407 Init.get() == E->getInit() &&
3408 !ExprChanged)
3409 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003410
Douglas Gregora16548e2009-08-11 05:31:07 +00003411 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
3412 E->getEqualOrColonLoc(),
3413 E->usesGNUSyntax(), move(Init));
3414}
Mike Stump11289f42009-09-09 15:08:12 +00003415
Douglas Gregora16548e2009-08-11 05:31:07 +00003416template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003417Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003418TreeTransform<Derived>::TransformImplicitValueInitExpr(
Mike Stump11289f42009-09-09 15:08:12 +00003419 ImplicitValueInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003420 QualType T = getDerived().TransformType(E->getType());
3421 if (T.isNull())
3422 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003423
Douglas Gregora16548e2009-08-11 05:31:07 +00003424 if (!getDerived().AlwaysRebuild() &&
3425 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00003426 return SemaRef.Owned(E->Retain());
3427
Douglas Gregora16548e2009-08-11 05:31:07 +00003428 return getDerived().RebuildImplicitValueInitExpr(T);
3429}
Mike Stump11289f42009-09-09 15:08:12 +00003430
Douglas Gregora16548e2009-08-11 05:31:07 +00003431template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003432Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003433TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
3434 // FIXME: Do we want the type as written?
3435 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00003436
Douglas Gregora16548e2009-08-11 05:31:07 +00003437 {
3438 // FIXME: Source location isn't quite accurate.
3439 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
3440 T = getDerived().TransformType(E->getType());
3441 if (T.isNull())
3442 return SemaRef.ExprError();
3443 }
Mike Stump11289f42009-09-09 15:08:12 +00003444
Douglas Gregora16548e2009-08-11 05:31:07 +00003445 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3446 if (SubExpr.isInvalid())
3447 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003448
Douglas Gregora16548e2009-08-11 05:31:07 +00003449 if (!getDerived().AlwaysRebuild() &&
3450 T == E->getType() &&
3451 SubExpr.get() == E->getSubExpr())
3452 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003453
Douglas Gregora16548e2009-08-11 05:31:07 +00003454 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
3455 T, E->getRParenLoc());
3456}
3457
3458template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003459Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003460TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
3461 bool ArgumentChanged = false;
3462 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3463 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
3464 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
3465 if (Init.isInvalid())
3466 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003467
Douglas Gregora16548e2009-08-11 05:31:07 +00003468 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
3469 Inits.push_back(Init.takeAs<Expr>());
3470 }
Mike Stump11289f42009-09-09 15:08:12 +00003471
Douglas Gregora16548e2009-08-11 05:31:07 +00003472 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
3473 move_arg(Inits),
3474 E->getRParenLoc());
3475}
Mike Stump11289f42009-09-09 15:08:12 +00003476
Douglas Gregora16548e2009-08-11 05:31:07 +00003477/// \brief Transform an address-of-label expression.
3478///
3479/// By default, the transformation of an address-of-label expression always
3480/// rebuilds the expression, so that the label identifier can be resolved to
3481/// the corresponding label statement by semantic analysis.
3482template<typename Derived>
3483Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003484TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003485 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
3486 E->getLabel());
3487}
Mike Stump11289f42009-09-09 15:08:12 +00003488
3489template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003490Sema::OwningExprResult TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003491 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00003492 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
3493 if (SubStmt.isInvalid())
3494 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003495
Douglas Gregora16548e2009-08-11 05:31:07 +00003496 if (!getDerived().AlwaysRebuild() &&
3497 SubStmt.get() == E->getSubStmt())
3498 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003499
3500 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003501 move(SubStmt),
3502 E->getRParenLoc());
3503}
Mike Stump11289f42009-09-09 15:08:12 +00003504
Douglas Gregora16548e2009-08-11 05:31:07 +00003505template<typename Derived>
3506Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003507TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003508 QualType T1, T2;
3509 {
3510 // FIXME: Source location isn't quite accurate.
3511 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003512
Douglas Gregora16548e2009-08-11 05:31:07 +00003513 T1 = getDerived().TransformType(E->getArgType1());
3514 if (T1.isNull())
3515 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003516
Douglas Gregora16548e2009-08-11 05:31:07 +00003517 T2 = getDerived().TransformType(E->getArgType2());
3518 if (T2.isNull())
3519 return SemaRef.ExprError();
3520 }
3521
3522 if (!getDerived().AlwaysRebuild() &&
3523 T1 == E->getArgType1() &&
3524 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00003525 return SemaRef.Owned(E->Retain());
3526
Douglas Gregora16548e2009-08-11 05:31:07 +00003527 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
3528 T1, T2, E->getRParenLoc());
3529}
Mike Stump11289f42009-09-09 15:08:12 +00003530
Douglas Gregora16548e2009-08-11 05:31:07 +00003531template<typename Derived>
3532Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003533TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003534 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3535 if (Cond.isInvalid())
3536 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003537
Douglas Gregora16548e2009-08-11 05:31:07 +00003538 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3539 if (LHS.isInvalid())
3540 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003541
Douglas Gregora16548e2009-08-11 05:31:07 +00003542 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3543 if (RHS.isInvalid())
3544 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003545
Douglas Gregora16548e2009-08-11 05:31:07 +00003546 if (!getDerived().AlwaysRebuild() &&
3547 Cond.get() == E->getCond() &&
3548 LHS.get() == E->getLHS() &&
3549 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003550 return SemaRef.Owned(E->Retain());
3551
Douglas Gregora16548e2009-08-11 05:31:07 +00003552 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
3553 move(Cond), move(LHS), move(RHS),
3554 E->getRParenLoc());
3555}
Mike Stump11289f42009-09-09 15:08:12 +00003556
Douglas Gregora16548e2009-08-11 05:31:07 +00003557template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003558Sema::OwningExprResult
3559TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
3560 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003561}
3562
3563template<typename Derived>
3564Sema::OwningExprResult
3565TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
3566 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3567 if (Callee.isInvalid())
3568 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003569
Douglas Gregora16548e2009-08-11 05:31:07 +00003570 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
3571 if (First.isInvalid())
3572 return SemaRef.ExprError();
3573
3574 OwningExprResult Second(SemaRef);
3575 if (E->getNumArgs() == 2) {
3576 Second = getDerived().TransformExpr(E->getArg(1));
3577 if (Second.isInvalid())
3578 return SemaRef.ExprError();
3579 }
Mike Stump11289f42009-09-09 15:08:12 +00003580
Douglas Gregora16548e2009-08-11 05:31:07 +00003581 if (!getDerived().AlwaysRebuild() &&
3582 Callee.get() == E->getCallee() &&
3583 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00003584 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
3585 return SemaRef.Owned(E->Retain());
3586
Douglas Gregora16548e2009-08-11 05:31:07 +00003587 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
3588 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003589 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00003590 move(First),
3591 move(Second));
3592}
Mike Stump11289f42009-09-09 15:08:12 +00003593
Douglas Gregora16548e2009-08-11 05:31:07 +00003594template<typename Derived>
3595Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003596TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003597 return getDerived().TransformCallExpr(E);
3598}
Mike Stump11289f42009-09-09 15:08:12 +00003599
Douglas Gregora16548e2009-08-11 05:31:07 +00003600template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003601Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003602TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
3603 QualType ExplicitTy;
3604 {
3605 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003606 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003607 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
3608 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003609
Douglas Gregora16548e2009-08-11 05:31:07 +00003610 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
3611 if (ExplicitTy.isNull())
3612 return SemaRef.ExprError();
3613 }
Mike Stump11289f42009-09-09 15:08:12 +00003614
Douglas Gregora16548e2009-08-11 05:31:07 +00003615 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3616 if (SubExpr.isInvalid())
3617 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003618
Douglas Gregora16548e2009-08-11 05:31:07 +00003619 if (!getDerived().AlwaysRebuild() &&
3620 ExplicitTy == E->getTypeAsWritten() &&
3621 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003622 return SemaRef.Owned(E->Retain());
3623
Douglas Gregora16548e2009-08-11 05:31:07 +00003624 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00003625 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003626 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
3627 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
3628 SourceLocation FakeRParenLoc
3629 = SemaRef.PP.getLocForEndOfToken(
3630 E->getSubExpr()->getSourceRange().getEnd());
3631 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003632 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003633 FakeLAngleLoc,
3634 ExplicitTy,
3635 FakeRAngleLoc,
3636 FakeRAngleLoc,
3637 move(SubExpr),
3638 FakeRParenLoc);
3639}
Mike Stump11289f42009-09-09 15:08:12 +00003640
Douglas Gregora16548e2009-08-11 05:31:07 +00003641template<typename Derived>
3642Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003643TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003644 return getDerived().TransformCXXNamedCastExpr(E);
3645}
Mike Stump11289f42009-09-09 15:08:12 +00003646
3647template<typename Derived>
3648Sema::OwningExprResult
3649TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
3650 return getDerived().TransformCXXNamedCastExpr(E);
3651}
3652
Douglas Gregora16548e2009-08-11 05:31:07 +00003653template<typename Derived>
3654Sema::OwningExprResult
3655TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
Mike Stump11289f42009-09-09 15:08:12 +00003656 CXXReinterpretCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003657 return getDerived().TransformCXXNamedCastExpr(E);
3658}
Mike Stump11289f42009-09-09 15:08:12 +00003659
Douglas Gregora16548e2009-08-11 05:31:07 +00003660template<typename Derived>
3661Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003662TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003663 return getDerived().TransformCXXNamedCastExpr(E);
3664}
Mike Stump11289f42009-09-09 15:08:12 +00003665
Douglas Gregora16548e2009-08-11 05:31:07 +00003666template<typename Derived>
3667Sema::OwningExprResult
3668TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
Mike Stump11289f42009-09-09 15:08:12 +00003669 CXXFunctionalCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003670 QualType ExplicitTy;
3671 {
3672 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003673
Douglas Gregora16548e2009-08-11 05:31:07 +00003674 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
3675 if (ExplicitTy.isNull())
3676 return SemaRef.ExprError();
3677 }
Mike Stump11289f42009-09-09 15:08:12 +00003678
Douglas Gregora16548e2009-08-11 05:31:07 +00003679 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3680 if (SubExpr.isInvalid())
3681 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003682
Douglas Gregora16548e2009-08-11 05:31:07 +00003683 if (!getDerived().AlwaysRebuild() &&
3684 ExplicitTy == E->getTypeAsWritten() &&
3685 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003686 return SemaRef.Owned(E->Retain());
3687
Douglas Gregora16548e2009-08-11 05:31:07 +00003688 // FIXME: The end of the type's source range is wrong
3689 return getDerived().RebuildCXXFunctionalCastExpr(
3690 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
3691 ExplicitTy,
3692 /*FIXME:*/E->getSubExpr()->getLocStart(),
3693 move(SubExpr),
3694 E->getRParenLoc());
3695}
Mike Stump11289f42009-09-09 15:08:12 +00003696
Douglas Gregora16548e2009-08-11 05:31:07 +00003697template<typename Derived>
3698Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003699TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003700 if (E->isTypeOperand()) {
3701 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003702
Douglas Gregora16548e2009-08-11 05:31:07 +00003703 QualType T = getDerived().TransformType(E->getTypeOperand());
3704 if (T.isNull())
3705 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003706
Douglas Gregora16548e2009-08-11 05:31:07 +00003707 if (!getDerived().AlwaysRebuild() &&
3708 T == E->getTypeOperand())
3709 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003710
Douglas Gregora16548e2009-08-11 05:31:07 +00003711 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
3712 /*FIXME:*/E->getLocStart(),
3713 T,
3714 E->getLocEnd());
3715 }
Mike Stump11289f42009-09-09 15:08:12 +00003716
Douglas Gregora16548e2009-08-11 05:31:07 +00003717 // We don't know whether the expression is potentially evaluated until
3718 // after we perform semantic analysis, so the expression is potentially
3719 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00003720 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00003721 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003722
Douglas Gregora16548e2009-08-11 05:31:07 +00003723 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
3724 if (SubExpr.isInvalid())
3725 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003726
Douglas Gregora16548e2009-08-11 05:31:07 +00003727 if (!getDerived().AlwaysRebuild() &&
3728 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00003729 return SemaRef.Owned(E->Retain());
3730
Douglas Gregora16548e2009-08-11 05:31:07 +00003731 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
3732 /*FIXME:*/E->getLocStart(),
3733 move(SubExpr),
3734 E->getLocEnd());
3735}
3736
3737template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003738Sema::OwningExprResult
3739TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
3740 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003741}
Mike Stump11289f42009-09-09 15:08:12 +00003742
Douglas Gregora16548e2009-08-11 05:31:07 +00003743template<typename Derived>
3744Sema::OwningExprResult
3745TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
Mike Stump11289f42009-09-09 15:08:12 +00003746 CXXNullPtrLiteralExpr *E) {
3747 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003748}
Mike Stump11289f42009-09-09 15:08:12 +00003749
Douglas Gregora16548e2009-08-11 05:31:07 +00003750template<typename Derived>
3751Sema::OwningExprResult
3752TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
3753 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003754
Douglas Gregora16548e2009-08-11 05:31:07 +00003755 QualType T = getDerived().TransformType(E->getType());
3756 if (T.isNull())
3757 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003758
Douglas Gregora16548e2009-08-11 05:31:07 +00003759 if (!getDerived().AlwaysRebuild() &&
3760 T == E->getType())
3761 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003762
Douglas Gregora16548e2009-08-11 05:31:07 +00003763 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T);
3764}
Mike Stump11289f42009-09-09 15:08:12 +00003765
Douglas Gregora16548e2009-08-11 05:31:07 +00003766template<typename Derived>
3767Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003768TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003769 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3770 if (SubExpr.isInvalid())
3771 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003772
Douglas Gregora16548e2009-08-11 05:31:07 +00003773 if (!getDerived().AlwaysRebuild() &&
3774 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003775 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003776
3777 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
3778}
Mike Stump11289f42009-09-09 15:08:12 +00003779
Douglas Gregora16548e2009-08-11 05:31:07 +00003780template<typename Derived>
3781Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003782TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
3783 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00003784 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
3785 if (!Param)
3786 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003787
Douglas Gregora16548e2009-08-11 05:31:07 +00003788 if (getDerived().AlwaysRebuild() &&
3789 Param == E->getParam())
3790 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003791
Douglas Gregora16548e2009-08-11 05:31:07 +00003792 return getDerived().RebuildCXXDefaultArgExpr(Param);
3793}
Mike Stump11289f42009-09-09 15:08:12 +00003794
Douglas Gregora16548e2009-08-11 05:31:07 +00003795template<typename Derived>
3796Sema::OwningExprResult
3797TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
3798 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
3799
3800 QualType T = getDerived().TransformType(E->getType());
3801 if (T.isNull())
3802 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003803
Douglas Gregora16548e2009-08-11 05:31:07 +00003804 if (!getDerived().AlwaysRebuild() &&
3805 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00003806 return SemaRef.Owned(E->Retain());
3807
3808 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003809 /*FIXME:*/E->getTypeBeginLoc(),
3810 T,
3811 E->getRParenLoc());
3812}
Mike Stump11289f42009-09-09 15:08:12 +00003813
Douglas Gregora16548e2009-08-11 05:31:07 +00003814template<typename Derived>
3815Sema::OwningExprResult
3816TreeTransform<Derived>::TransformCXXConditionDeclExpr(CXXConditionDeclExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003817 VarDecl *Var
Douglas Gregorebe10102009-08-20 07:17:43 +00003818 = cast_or_null<VarDecl>(getDerived().TransformDefinition(E->getVarDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003819 if (!Var)
3820 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003821
Douglas Gregora16548e2009-08-11 05:31:07 +00003822 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00003823 Var == E->getVarDecl())
Douglas Gregora16548e2009-08-11 05:31:07 +00003824 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003825
3826 return getDerived().RebuildCXXConditionDeclExpr(E->getStartLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003827 /*FIXME:*/E->getStartLoc(),
3828 Var);
3829}
Mike Stump11289f42009-09-09 15:08:12 +00003830
Douglas Gregora16548e2009-08-11 05:31:07 +00003831template<typename Derived>
3832Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003833TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003834 // Transform the type that we're allocating
3835 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3836 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
3837 if (AllocType.isNull())
3838 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003839
Douglas Gregora16548e2009-08-11 05:31:07 +00003840 // Transform the size of the array we're allocating (if any).
3841 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
3842 if (ArraySize.isInvalid())
3843 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003844
Douglas Gregora16548e2009-08-11 05:31:07 +00003845 // Transform the placement arguments (if any).
3846 bool ArgumentChanged = false;
3847 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
3848 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
3849 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
3850 if (Arg.isInvalid())
3851 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003852
Douglas Gregora16548e2009-08-11 05:31:07 +00003853 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
3854 PlacementArgs.push_back(Arg.take());
3855 }
Mike Stump11289f42009-09-09 15:08:12 +00003856
Douglas Gregorebe10102009-08-20 07:17:43 +00003857 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00003858 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
3859 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
3860 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
3861 if (Arg.isInvalid())
3862 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003863
Douglas Gregora16548e2009-08-11 05:31:07 +00003864 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
3865 ConstructorArgs.push_back(Arg.take());
3866 }
Mike Stump11289f42009-09-09 15:08:12 +00003867
Douglas Gregora16548e2009-08-11 05:31:07 +00003868 if (!getDerived().AlwaysRebuild() &&
3869 AllocType == E->getAllocatedType() &&
3870 ArraySize.get() == E->getArraySize() &&
3871 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003872 return SemaRef.Owned(E->Retain());
3873
Douglas Gregora16548e2009-08-11 05:31:07 +00003874 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
3875 E->isGlobalNew(),
3876 /*FIXME:*/E->getLocStart(),
3877 move_arg(PlacementArgs),
3878 /*FIXME:*/E->getLocStart(),
3879 E->isParenTypeId(),
3880 AllocType,
3881 /*FIXME:*/E->getLocStart(),
3882 /*FIXME:*/SourceRange(),
3883 move(ArraySize),
3884 /*FIXME:*/E->getLocStart(),
3885 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00003886 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00003887}
Mike Stump11289f42009-09-09 15:08:12 +00003888
Douglas Gregora16548e2009-08-11 05:31:07 +00003889template<typename Derived>
3890Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003891TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003892 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
3893 if (Operand.isInvalid())
3894 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003895
Douglas Gregora16548e2009-08-11 05:31:07 +00003896 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00003897 Operand.get() == E->getArgument())
3898 return SemaRef.Owned(E->Retain());
3899
Douglas Gregora16548e2009-08-11 05:31:07 +00003900 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
3901 E->isGlobalDelete(),
3902 E->isArrayForm(),
3903 move(Operand));
3904}
Mike Stump11289f42009-09-09 15:08:12 +00003905
Douglas Gregora16548e2009-08-11 05:31:07 +00003906template<typename Derived>
3907Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00003908TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
3909 CXXPseudoDestructorExpr *E) {
3910 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3911 if (Base.isInvalid())
3912 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003913
Douglas Gregorad8a3362009-09-04 17:36:40 +00003914 NestedNameSpecifier *Qualifier
3915 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3916 E->getQualifierRange());
3917 if (E->getQualifier() && !Qualifier)
3918 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003919
Douglas Gregorad8a3362009-09-04 17:36:40 +00003920 QualType DestroyedType;
3921 {
3922 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
3923 DestroyedType = getDerived().TransformType(E->getDestroyedType());
3924 if (DestroyedType.isNull())
3925 return SemaRef.ExprError();
3926 }
Mike Stump11289f42009-09-09 15:08:12 +00003927
Douglas Gregorad8a3362009-09-04 17:36:40 +00003928 if (!getDerived().AlwaysRebuild() &&
3929 Base.get() == E->getBase() &&
3930 Qualifier == E->getQualifier() &&
3931 DestroyedType == E->getDestroyedType())
3932 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003933
Douglas Gregorad8a3362009-09-04 17:36:40 +00003934 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
3935 E->getOperatorLoc(),
3936 E->isArrow(),
3937 E->getDestroyedTypeLoc(),
3938 DestroyedType,
3939 Qualifier,
3940 E->getQualifierRange());
3941}
Mike Stump11289f42009-09-09 15:08:12 +00003942
Douglas Gregorad8a3362009-09-04 17:36:40 +00003943template<typename Derived>
3944Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003945TreeTransform<Derived>::TransformUnresolvedFunctionNameExpr(
Mike Stump11289f42009-09-09 15:08:12 +00003946 UnresolvedFunctionNameExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003947 // There is no transformation we can apply to an unresolved function name.
Mike Stump11289f42009-09-09 15:08:12 +00003948 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003949}
Mike Stump11289f42009-09-09 15:08:12 +00003950
Douglas Gregora16548e2009-08-11 05:31:07 +00003951template<typename Derived>
3952Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003953TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003954 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003955
Douglas Gregora16548e2009-08-11 05:31:07 +00003956 QualType T = getDerived().TransformType(E->getQueriedType());
3957 if (T.isNull())
3958 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003959
Douglas Gregora16548e2009-08-11 05:31:07 +00003960 if (!getDerived().AlwaysRebuild() &&
3961 T == E->getQueriedType())
3962 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003963
Douglas Gregora16548e2009-08-11 05:31:07 +00003964 // FIXME: Bad location information
3965 SourceLocation FakeLParenLoc
3966 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00003967
3968 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003969 E->getLocStart(),
3970 /*FIXME:*/FakeLParenLoc,
3971 T,
3972 E->getLocEnd());
3973}
Mike Stump11289f42009-09-09 15:08:12 +00003974
Douglas Gregora16548e2009-08-11 05:31:07 +00003975template<typename Derived>
3976Sema::OwningExprResult
3977TreeTransform<Derived>::TransformQualifiedDeclRefExpr(QualifiedDeclRefExpr *E) {
3978 NestedNameSpecifier *NNS
3979 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3980 E->getQualifierRange());
3981 if (!NNS)
3982 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003983
3984 NamedDecl *ND
Douglas Gregora16548e2009-08-11 05:31:07 +00003985 = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl()));
3986 if (!ND)
3987 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003988
3989 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003990 NNS == E->getQualifier() &&
3991 ND == E->getDecl())
Mike Stump11289f42009-09-09 15:08:12 +00003992 return SemaRef.Owned(E->Retain());
3993
3994 return getDerived().RebuildQualifiedDeclRefExpr(NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00003995 E->getQualifierRange(),
3996 ND,
3997 E->getLocation(),
3998 /*FIXME:*/false);
3999}
Mike Stump11289f42009-09-09 15:08:12 +00004000
Douglas Gregora16548e2009-08-11 05:31:07 +00004001template<typename Derived>
4002Sema::OwningExprResult
4003TreeTransform<Derived>::TransformUnresolvedDeclRefExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004004 UnresolvedDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004005 NestedNameSpecifier *NNS
4006 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4007 E->getQualifierRange());
4008 if (!NNS)
4009 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004010
4011 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004012 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4013 if (!Name)
4014 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004015
4016 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004017 NNS == E->getQualifier() &&
4018 Name == E->getDeclName())
Mike Stump11289f42009-09-09 15:08:12 +00004019 return SemaRef.Owned(E->Retain());
4020
4021 return getDerived().RebuildUnresolvedDeclRefExpr(NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00004022 E->getQualifierRange(),
4023 Name,
4024 E->getLocation(),
4025 /*FIXME:*/false);
4026}
4027
4028template<typename Derived>
4029Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004030TreeTransform<Derived>::TransformTemplateIdRefExpr(TemplateIdRefExpr *E) {
4031 TemplateName Template
Douglas Gregora16548e2009-08-11 05:31:07 +00004032 = getDerived().TransformTemplateName(E->getTemplateName());
4033 if (Template.isNull())
4034 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004035
Douglas Gregora16548e2009-08-11 05:31:07 +00004036 llvm::SmallVector<TemplateArgument, 4> TransArgs;
4037 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004038 TemplateArgument TransArg
Douglas Gregora16548e2009-08-11 05:31:07 +00004039 = getDerived().TransformTemplateArgument(E->getTemplateArgs()[I]);
4040 if (TransArg.isNull())
4041 return SemaRef.ExprError();
4042
4043 TransArgs.push_back(TransArg);
4044 }
4045
4046 // FIXME: Would like to avoid rebuilding if nothing changed, but we can't
4047 // compare template arguments (yet).
Mike Stump11289f42009-09-09 15:08:12 +00004048
4049 // FIXME: It's possible that we'll find out now that the template name
Douglas Gregora16548e2009-08-11 05:31:07 +00004050 // actually refers to a type, in which case the caller is actually dealing
4051 // with a functional cast. Give a reasonable error message!
4052 return getDerived().RebuildTemplateIdExpr(Template, E->getTemplateNameLoc(),
4053 E->getLAngleLoc(),
4054 TransArgs.data(),
4055 TransArgs.size(),
4056 E->getRAngleLoc());
4057}
4058
4059template<typename Derived>
4060Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004061TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004062 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4063
4064 QualType T = getDerived().TransformType(E->getType());
4065 if (T.isNull())
4066 return SemaRef.ExprError();
4067
4068 CXXConstructorDecl *Constructor
4069 = cast_or_null<CXXConstructorDecl>(
4070 getDerived().TransformDecl(E->getConstructor()));
4071 if (!Constructor)
4072 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004073
Douglas Gregora16548e2009-08-11 05:31:07 +00004074 bool ArgumentChanged = false;
4075 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004076 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004077 ArgEnd = E->arg_end();
4078 Arg != ArgEnd; ++Arg) {
4079 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4080 if (TransArg.isInvalid())
4081 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004082
Douglas Gregora16548e2009-08-11 05:31:07 +00004083 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4084 Args.push_back(TransArg.takeAs<Expr>());
4085 }
4086
4087 if (!getDerived().AlwaysRebuild() &&
4088 T == E->getType() &&
4089 Constructor == E->getConstructor() &&
4090 !ArgumentChanged)
4091 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004092
Douglas Gregora16548e2009-08-11 05:31:07 +00004093 return getDerived().RebuildCXXConstructExpr(T, Constructor, E->isElidable(),
4094 move_arg(Args));
4095}
Mike Stump11289f42009-09-09 15:08:12 +00004096
Douglas Gregora16548e2009-08-11 05:31:07 +00004097/// \brief Transform a C++ temporary-binding expression.
4098///
Mike Stump11289f42009-09-09 15:08:12 +00004099/// The transformation of a temporary-binding expression always attempts to
4100/// bind a new temporary variable to its subexpression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004101/// subexpression itself did not change, because the temporary variable itself
4102/// must be unique.
4103template<typename Derived>
4104Sema::OwningExprResult
4105TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
4106 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4107 if (SubExpr.isInvalid())
4108 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004109
Douglas Gregora16548e2009-08-11 05:31:07 +00004110 return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>());
4111}
Mike Stump11289f42009-09-09 15:08:12 +00004112
4113/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004114/// be destroyed after the expression is evaluated.
4115///
Mike Stump11289f42009-09-09 15:08:12 +00004116/// The transformation of a full expression always attempts to build a new
4117/// CXXExprWithTemporaries expression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004118/// subexpression itself did not change, because it will need to capture the
4119/// the new temporary variables introduced in the subexpression.
4120template<typename Derived>
4121Sema::OwningExprResult
4122TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Mike Stump11289f42009-09-09 15:08:12 +00004123 CXXExprWithTemporaries *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004124 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4125 if (SubExpr.isInvalid())
4126 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004127
Douglas Gregora16548e2009-08-11 05:31:07 +00004128 return SemaRef.Owned(
4129 SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(),
4130 E->shouldDestroyTemporaries()));
4131}
Mike Stump11289f42009-09-09 15:08:12 +00004132
Douglas Gregora16548e2009-08-11 05:31:07 +00004133template<typename Derived>
4134Sema::OwningExprResult
4135TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004136 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004137 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4138 QualType T = getDerived().TransformType(E->getType());
4139 if (T.isNull())
4140 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004141
Douglas Gregora16548e2009-08-11 05:31:07 +00004142 CXXConstructorDecl *Constructor
4143 = cast_or_null<CXXConstructorDecl>(
4144 getDerived().TransformDecl(E->getConstructor()));
4145 if (!Constructor)
4146 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004147
Douglas Gregora16548e2009-08-11 05:31:07 +00004148 bool ArgumentChanged = false;
4149 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4150 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004151 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004152 ArgEnd = E->arg_end();
4153 Arg != ArgEnd; ++Arg) {
4154 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4155 if (TransArg.isInvalid())
4156 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004157
Douglas Gregora16548e2009-08-11 05:31:07 +00004158 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4159 Args.push_back((Expr *)TransArg.release());
4160 }
Mike Stump11289f42009-09-09 15:08:12 +00004161
Douglas Gregora16548e2009-08-11 05:31:07 +00004162 if (!getDerived().AlwaysRebuild() &&
4163 T == E->getType() &&
4164 Constructor == E->getConstructor() &&
4165 !ArgumentChanged)
4166 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004167
Douglas Gregora16548e2009-08-11 05:31:07 +00004168 // FIXME: Bogus location information
4169 SourceLocation CommaLoc;
4170 if (Args.size() > 1) {
4171 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004172 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004173 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4174 }
4175 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4176 T,
4177 /*FIXME:*/E->getTypeBeginLoc(),
4178 move_arg(Args),
4179 &CommaLoc,
4180 E->getLocEnd());
4181}
Mike Stump11289f42009-09-09 15:08:12 +00004182
Douglas Gregora16548e2009-08-11 05:31:07 +00004183template<typename Derived>
4184Sema::OwningExprResult
4185TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004186 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004187 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4188 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4189 if (T.isNull())
4190 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004191
Douglas Gregora16548e2009-08-11 05:31:07 +00004192 bool ArgumentChanged = false;
4193 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4194 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4195 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4196 ArgEnd = E->arg_end();
4197 Arg != ArgEnd; ++Arg) {
4198 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4199 if (TransArg.isInvalid())
4200 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004201
Douglas Gregora16548e2009-08-11 05:31:07 +00004202 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4203 FakeCommaLocs.push_back(
4204 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4205 Args.push_back(TransArg.takeAs<Expr>());
4206 }
Mike Stump11289f42009-09-09 15:08:12 +00004207
Douglas Gregora16548e2009-08-11 05:31:07 +00004208 if (!getDerived().AlwaysRebuild() &&
4209 T == E->getTypeAsWritten() &&
4210 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004211 return SemaRef.Owned(E->Retain());
4212
Douglas Gregora16548e2009-08-11 05:31:07 +00004213 // FIXME: we're faking the locations of the commas
4214 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4215 T,
4216 E->getLParenLoc(),
4217 move_arg(Args),
4218 FakeCommaLocs.data(),
4219 E->getRParenLoc());
4220}
Mike Stump11289f42009-09-09 15:08:12 +00004221
Douglas Gregora16548e2009-08-11 05:31:07 +00004222template<typename Derived>
4223Sema::OwningExprResult
4224TreeTransform<Derived>::TransformCXXUnresolvedMemberExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004225 CXXUnresolvedMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004226 // Transform the base of the expression.
4227 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4228 if (Base.isInvalid())
4229 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004230
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004231 Sema::TypeTy *ObjectType = 0;
Mike Stump11289f42009-09-09 15:08:12 +00004232 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004233 E->getOperatorLoc(),
4234 E->isArrow()? tok::arrow : tok::period,
4235 ObjectType);
4236 if (Base.isInvalid())
4237 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004238
Douglas Gregor308047d2009-09-09 00:23:06 +00004239 // FIXME: The first qualifier found might be a template type parameter,
4240 // in which case there is no transformed declaration to refer to (it might
4241 // refer to a built-in type!).
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004242 NamedDecl *FirstQualifierInScope
4243 = cast_or_null<NamedDecl>(
4244 getDerived().TransformDecl(E->getFirstQualifierFoundInScope()));
Mike Stump11289f42009-09-09 15:08:12 +00004245
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004246 NestedNameSpecifier *Qualifier = 0;
4247 if (E->getQualifier()) {
4248 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4249 E->getQualifierRange(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004250 QualType::getFromOpaquePtr(ObjectType),
4251 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004252 if (!Qualifier)
4253 return SemaRef.ExprError();
4254 }
Mike Stump11289f42009-09-09 15:08:12 +00004255
4256 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004257 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc());
4258 if (!Name)
4259 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004260
Douglas Gregor308047d2009-09-09 00:23:06 +00004261 if (!E->hasExplicitTemplateArgumentList()) {
4262 // This is a reference to a member without an explicitly-specified
4263 // template argument list. Optimize for this common case.
4264 if (!getDerived().AlwaysRebuild() &&
4265 Base.get() == E->getBase() &&
4266 Qualifier == E->getQualifier() &&
4267 Name == E->getMember() &&
4268 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00004269 return SemaRef.Owned(E->Retain());
4270
Douglas Gregor308047d2009-09-09 00:23:06 +00004271 return getDerived().RebuildCXXUnresolvedMemberExpr(move(Base),
4272 E->isArrow(),
4273 E->getOperatorLoc(),
4274 Qualifier,
4275 E->getQualifierRange(),
4276 Name,
4277 E->getMemberLoc(),
4278 FirstQualifierInScope);
4279 }
4280
4281 // FIXME: This is an ugly hack, which forces the same template name to
4282 // be looked up multiple times. Yuck!
4283 // FIXME: This also won't work for, e.g., x->template operator+<int>
4284 TemplateName OrigTemplateName
4285 = SemaRef.Context.getDependentTemplateName(0, Name.getAsIdentifierInfo());
Mike Stump11289f42009-09-09 15:08:12 +00004286
4287 TemplateName Template
4288 = getDerived().TransformTemplateName(OrigTemplateName,
Douglas Gregor308047d2009-09-09 00:23:06 +00004289 QualType::getFromOpaquePtr(ObjectType));
4290 if (Template.isNull())
4291 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004292
Douglas Gregor308047d2009-09-09 00:23:06 +00004293 llvm::SmallVector<TemplateArgument, 4> TransArgs;
4294 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004295 TemplateArgument TransArg
Douglas Gregor308047d2009-09-09 00:23:06 +00004296 = getDerived().TransformTemplateArgument(E->getTemplateArgs()[I]);
4297 if (TransArg.isNull())
4298 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004299
Douglas Gregor308047d2009-09-09 00:23:06 +00004300 TransArgs.push_back(TransArg);
4301 }
Mike Stump11289f42009-09-09 15:08:12 +00004302
Douglas Gregora16548e2009-08-11 05:31:07 +00004303 return getDerived().RebuildCXXUnresolvedMemberExpr(move(Base),
4304 E->isArrow(),
4305 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004306 Qualifier,
4307 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004308 Template,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004309 E->getMemberLoc(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004310 FirstQualifierInScope,
4311 E->getLAngleLoc(),
4312 TransArgs.data(),
4313 TransArgs.size(),
4314 E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004315}
4316
4317template<typename Derived>
4318Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004319TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
4320 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004321}
4322
Mike Stump11289f42009-09-09 15:08:12 +00004323template<typename Derived>
4324Sema::OwningExprResult
4325TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004326 // FIXME: poor source location
4327 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
4328 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
4329 if (EncodedType.isNull())
4330 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004331
Douglas Gregora16548e2009-08-11 05:31:07 +00004332 if (!getDerived().AlwaysRebuild() &&
4333 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00004334 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004335
4336 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
4337 EncodedType,
4338 E->getRParenLoc());
4339}
Mike Stump11289f42009-09-09 15:08:12 +00004340
Douglas Gregora16548e2009-08-11 05:31:07 +00004341template<typename Derived>
4342Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004343TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004344 // FIXME: Implement this!
4345 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004346 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004347}
4348
Mike Stump11289f42009-09-09 15:08:12 +00004349template<typename Derived>
4350Sema::OwningExprResult
4351TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
4352 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004353}
4354
Mike Stump11289f42009-09-09 15:08:12 +00004355template<typename Derived>
4356Sema::OwningExprResult
4357TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
4358 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00004359 = cast_or_null<ObjCProtocolDecl>(
4360 getDerived().TransformDecl(E->getProtocol()));
4361 if (!Protocol)
4362 return SemaRef.ExprError();
4363
4364 if (!getDerived().AlwaysRebuild() &&
4365 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00004366 return SemaRef.Owned(E->Retain());
4367
Douglas Gregora16548e2009-08-11 05:31:07 +00004368 return getDerived().RebuildObjCProtocolExpr(Protocol,
4369 E->getAtLoc(),
4370 /*FIXME:*/E->getAtLoc(),
4371 /*FIXME:*/E->getAtLoc(),
4372 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004373
Douglas Gregora16548e2009-08-11 05:31:07 +00004374}
4375
Mike Stump11289f42009-09-09 15:08:12 +00004376template<typename Derived>
4377Sema::OwningExprResult
4378TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004379 // FIXME: Implement this!
4380 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004381 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004382}
4383
Mike Stump11289f42009-09-09 15:08:12 +00004384template<typename Derived>
4385Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004386TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
4387 // FIXME: Implement this!
4388 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004389 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004390}
4391
Mike Stump11289f42009-09-09 15:08:12 +00004392template<typename Derived>
4393Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00004394TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004395 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004396 // FIXME: Implement this!
4397 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004398 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004399}
4400
Mike Stump11289f42009-09-09 15:08:12 +00004401template<typename Derived>
4402Sema::OwningExprResult
4403TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004404 // FIXME: Implement this!
4405 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004406 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004407}
4408
Mike Stump11289f42009-09-09 15:08:12 +00004409template<typename Derived>
4410Sema::OwningExprResult
4411TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004412 // FIXME: Implement this!
4413 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004414 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004415}
4416
Mike Stump11289f42009-09-09 15:08:12 +00004417template<typename Derived>
4418Sema::OwningExprResult
4419TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004420 bool ArgumentChanged = false;
4421 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
4422 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
4423 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
4424 if (SubExpr.isInvalid())
4425 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004426
Douglas Gregora16548e2009-08-11 05:31:07 +00004427 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
4428 SubExprs.push_back(SubExpr.takeAs<Expr>());
4429 }
Mike Stump11289f42009-09-09 15:08:12 +00004430
Douglas Gregora16548e2009-08-11 05:31:07 +00004431 if (!getDerived().AlwaysRebuild() &&
4432 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004433 return SemaRef.Owned(E->Retain());
4434
Douglas Gregora16548e2009-08-11 05:31:07 +00004435 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
4436 move_arg(SubExprs),
4437 E->getRParenLoc());
4438}
4439
Mike Stump11289f42009-09-09 15:08:12 +00004440template<typename Derived>
4441Sema::OwningExprResult
4442TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004443 // FIXME: Implement this!
4444 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004445 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004446}
4447
Mike Stump11289f42009-09-09 15:08:12 +00004448template<typename Derived>
4449Sema::OwningExprResult
4450TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004451 // FIXME: Implement this!
4452 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004453 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004454}
Mike Stump11289f42009-09-09 15:08:12 +00004455
Douglas Gregora16548e2009-08-11 05:31:07 +00004456//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00004457// Type reconstruction
4458//===----------------------------------------------------------------------===//
4459
Mike Stump11289f42009-09-09 15:08:12 +00004460template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004461QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004462 return SemaRef.BuildPointerType(PointeeType, Qualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004463 getDerived().getBaseLocation(),
4464 getDerived().getBaseEntity());
4465}
4466
Mike Stump11289f42009-09-09 15:08:12 +00004467template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004468QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004469 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004470 getDerived().getBaseLocation(),
4471 getDerived().getBaseEntity());
4472}
4473
Mike Stump11289f42009-09-09 15:08:12 +00004474template<typename Derived>
4475QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00004476TreeTransform<Derived>::RebuildLValueReferenceType(QualType ReferentType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004477 return SemaRef.BuildReferenceType(ReferentType, true, Qualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004478 getDerived().getBaseLocation(),
4479 getDerived().getBaseEntity());
4480}
4481
4482template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004483QualType
4484TreeTransform<Derived>::RebuildRValueReferenceType(QualType ReferentType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004485 return SemaRef.BuildReferenceType(ReferentType, false, Qualifiers(),
Mike Stump11289f42009-09-09 15:08:12 +00004486 getDerived().getBaseLocation(),
4487 getDerived().getBaseEntity());
4488}
4489
4490template<typename Derived>
4491QualType TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004492 QualType ClassType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004493 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004494 getDerived().getBaseLocation(),
4495 getDerived().getBaseEntity());
4496}
4497
4498template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004499QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00004500TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
4501 ArrayType::ArraySizeModifier SizeMod,
4502 const llvm::APInt *Size,
4503 Expr *SizeExpr,
4504 unsigned IndexTypeQuals,
4505 SourceRange BracketsRange) {
4506 if (SizeExpr || !Size)
4507 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
4508 IndexTypeQuals, BracketsRange,
4509 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00004510
4511 QualType Types[] = {
4512 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
4513 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
4514 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00004515 };
4516 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
4517 QualType SizeType;
4518 for (unsigned I = 0; I != NumTypes; ++I)
4519 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
4520 SizeType = Types[I];
4521 break;
4522 }
Mike Stump11289f42009-09-09 15:08:12 +00004523
Douglas Gregord6ff3322009-08-04 16:50:30 +00004524 if (SizeType.isNull())
4525 SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false);
Mike Stump11289f42009-09-09 15:08:12 +00004526
Douglas Gregord6ff3322009-08-04 16:50:30 +00004527 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00004528 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004529 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00004530 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004531}
Mike Stump11289f42009-09-09 15:08:12 +00004532
Douglas Gregord6ff3322009-08-04 16:50:30 +00004533template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004534QualType
4535TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004536 ArrayType::ArraySizeModifier SizeMod,
4537 const llvm::APInt &Size,
4538 unsigned IndexTypeQuals) {
Mike Stump11289f42009-09-09 15:08:12 +00004539 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004540 IndexTypeQuals, SourceRange());
4541}
4542
4543template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004544QualType
4545TreeTransform<Derived>::RebuildConstantArrayWithExprType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004546 ArrayType::ArraySizeModifier SizeMod,
4547 const llvm::APInt &Size,
4548 Expr *SizeExpr,
4549 unsigned IndexTypeQuals,
4550 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00004551 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004552 IndexTypeQuals, BracketsRange);
4553}
4554
4555template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004556QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00004557TreeTransform<Derived>::RebuildConstantArrayWithoutExprType(
Mike Stump11289f42009-09-09 15:08:12 +00004558 QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004559 ArrayType::ArraySizeModifier SizeMod,
4560 const llvm::APInt &Size,
4561 unsigned IndexTypeQuals) {
Mike Stump11289f42009-09-09 15:08:12 +00004562 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004563 IndexTypeQuals, SourceRange());
4564}
4565
4566template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004567QualType
4568TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004569 ArrayType::ArraySizeModifier SizeMod,
4570 unsigned IndexTypeQuals) {
Mike Stump11289f42009-09-09 15:08:12 +00004571 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004572 IndexTypeQuals, SourceRange());
4573}
Mike Stump11289f42009-09-09 15:08:12 +00004574
Douglas Gregord6ff3322009-08-04 16:50:30 +00004575template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004576QualType
4577TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004578 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00004579 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004580 unsigned IndexTypeQuals,
4581 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00004582 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004583 SizeExpr.takeAs<Expr>(),
4584 IndexTypeQuals, BracketsRange);
4585}
4586
4587template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004588QualType
4589TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004590 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00004591 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004592 unsigned IndexTypeQuals,
4593 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00004594 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004595 SizeExpr.takeAs<Expr>(),
4596 IndexTypeQuals, BracketsRange);
4597}
4598
4599template<typename Derived>
4600QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
4601 unsigned NumElements) {
4602 // FIXME: semantic checking!
4603 return SemaRef.Context.getVectorType(ElementType, NumElements);
4604}
Mike Stump11289f42009-09-09 15:08:12 +00004605
Douglas Gregord6ff3322009-08-04 16:50:30 +00004606template<typename Derived>
4607QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
4608 unsigned NumElements,
4609 SourceLocation AttributeLoc) {
4610 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
4611 NumElements, true);
4612 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00004613 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004614 AttributeLoc);
4615 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
4616 AttributeLoc);
4617}
Mike Stump11289f42009-09-09 15:08:12 +00004618
Douglas Gregord6ff3322009-08-04 16:50:30 +00004619template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004620QualType
4621TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00004622 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004623 SourceLocation AttributeLoc) {
4624 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
4625}
Mike Stump11289f42009-09-09 15:08:12 +00004626
Douglas Gregord6ff3322009-08-04 16:50:30 +00004627template<typename Derived>
4628QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00004629 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004630 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00004631 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004632 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00004633 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004634 Quals,
4635 getDerived().getBaseLocation(),
4636 getDerived().getBaseEntity());
4637}
Mike Stump11289f42009-09-09 15:08:12 +00004638
Douglas Gregord6ff3322009-08-04 16:50:30 +00004639template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004640QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004641 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
4642}
4643
4644template<typename Derived>
4645QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
4646 return SemaRef.Context.getTypeOfType(Underlying);
4647}
4648
4649template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004650QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004651 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
4652}
4653
4654template<typename Derived>
4655QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
4656 TemplateName Template,
4657 const TemplateArgument *Args,
4658 unsigned NumArgs) {
4659 // FIXME: Missing source locations for the template name, <, >.
4660 return SemaRef.CheckTemplateIdType(Template, getDerived().getBaseLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00004661 SourceLocation(), Args, NumArgs,
4662 SourceLocation());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004663}
Mike Stump11289f42009-09-09 15:08:12 +00004664
Douglas Gregor1135c352009-08-06 05:28:30 +00004665template<typename Derived>
4666NestedNameSpecifier *
4667TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
4668 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004669 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004670 QualType ObjectType,
4671 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00004672 CXXScopeSpec SS;
4673 // FIXME: The source location information is all wrong.
4674 SS.setRange(Range);
4675 SS.setScopeRep(Prefix);
4676 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00004677 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00004678 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004679 ObjectType,
4680 FirstQualifierInScope,
Douglas Gregore861bac2009-08-25 22:51:20 +00004681 false));
Douglas Gregor1135c352009-08-06 05:28:30 +00004682}
4683
4684template<typename Derived>
4685NestedNameSpecifier *
4686TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
4687 SourceRange Range,
4688 NamespaceDecl *NS) {
4689 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
4690}
4691
4692template<typename Derived>
4693NestedNameSpecifier *
4694TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
4695 SourceRange Range,
4696 bool TemplateKW,
4697 QualType T) {
4698 if (T->isDependentType() || T->isRecordType() ||
4699 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
John McCall8ccfcb52009-09-24 19:53:00 +00004700 assert(!T.hasQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00004701 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
4702 T.getTypePtr());
4703 }
Mike Stump11289f42009-09-09 15:08:12 +00004704
Douglas Gregor1135c352009-08-06 05:28:30 +00004705 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
4706 return 0;
4707}
Mike Stump11289f42009-09-09 15:08:12 +00004708
Douglas Gregor71dc5092009-08-06 06:41:21 +00004709template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004710TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00004711TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
4712 bool TemplateKW,
4713 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00004714 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00004715 Template);
4716}
4717
4718template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004719TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00004720TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
4721 bool TemplateKW,
4722 OverloadedFunctionDecl *Ovl) {
4723 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, Ovl);
4724}
4725
4726template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004727TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00004728TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00004729 const IdentifierInfo &II,
4730 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00004731 CXXScopeSpec SS;
4732 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00004733 SS.setScopeRep(Qualifier);
Douglas Gregor308047d2009-09-09 00:23:06 +00004734 return getSema().ActOnDependentTemplateName(
4735 /*FIXME:*/getDerived().getBaseLocation(),
4736 II,
4737 /*FIXME:*/getDerived().getBaseLocation(),
4738 SS,
4739 ObjectType.getAsOpaquePtr())
4740 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00004741}
Mike Stump11289f42009-09-09 15:08:12 +00004742
Douglas Gregora16548e2009-08-11 05:31:07 +00004743template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004744Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004745TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
4746 SourceLocation OpLoc,
4747 ExprArg Callee,
4748 ExprArg First,
4749 ExprArg Second) {
4750 Expr *FirstExpr = (Expr *)First.get();
4751 Expr *SecondExpr = (Expr *)Second.get();
4752 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00004753
Douglas Gregora16548e2009-08-11 05:31:07 +00004754 // Determine whether this should be a builtin operation.
4755 if (SecondExpr == 0 || isPostIncDec) {
4756 if (!FirstExpr->getType()->isOverloadableType()) {
4757 // The argument is not of overloadable type, so try to create a
4758 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00004759 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00004760 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00004761
Douglas Gregora16548e2009-08-11 05:31:07 +00004762 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
4763 }
4764 } else {
Mike Stump11289f42009-09-09 15:08:12 +00004765 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004766 !SecondExpr->getType()->isOverloadableType()) {
4767 // Neither of the arguments is an overloadable type, so try to
4768 // create a built-in binary operation.
4769 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00004770 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00004771 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
4772 if (Result.isInvalid())
4773 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004774
Douglas Gregora16548e2009-08-11 05:31:07 +00004775 First.release();
4776 Second.release();
4777 return move(Result);
4778 }
4779 }
Mike Stump11289f42009-09-09 15:08:12 +00004780
4781 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00004782 // used during overload resolution.
4783 Sema::FunctionSet Functions;
Mike Stump11289f42009-09-09 15:08:12 +00004784
4785 DeclRefExpr *DRE
Douglas Gregor32e2c842009-09-01 16:58:52 +00004786 = cast<DeclRefExpr>(((Expr *)Callee.get())->IgnoreParenCasts());
Mike Stump11289f42009-09-09 15:08:12 +00004787
Douglas Gregora16548e2009-08-11 05:31:07 +00004788 // FIXME: Do we have to check
4789 // IsAcceptableNonMemberOperatorCandidate for each of these?
Douglas Gregor32e2c842009-09-01 16:58:52 +00004790 for (OverloadIterator F(DRE->getDecl()), FEnd; F != FEnd; ++F)
Douglas Gregora16548e2009-08-11 05:31:07 +00004791 Functions.insert(*F);
Mike Stump11289f42009-09-09 15:08:12 +00004792
Douglas Gregora16548e2009-08-11 05:31:07 +00004793 // Add any functions found via argument-dependent lookup.
4794 Expr *Args[2] = { FirstExpr, SecondExpr };
4795 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00004796 DeclarationName OpName
Douglas Gregora16548e2009-08-11 05:31:07 +00004797 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
4798 SemaRef.ArgumentDependentLookup(OpName, Args, NumArgs, Functions);
Mike Stump11289f42009-09-09 15:08:12 +00004799
Douglas Gregora16548e2009-08-11 05:31:07 +00004800 // Create the overloaded operator invocation for unary operators.
4801 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00004802 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00004803 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
4804 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
4805 }
Mike Stump11289f42009-09-09 15:08:12 +00004806
Douglas Gregora16548e2009-08-11 05:31:07 +00004807 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00004808 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00004809 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00004810 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00004811 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
4812 if (Result.isInvalid())
4813 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004814
Douglas Gregora16548e2009-08-11 05:31:07 +00004815 First.release();
4816 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00004817 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00004818}
Mike Stump11289f42009-09-09 15:08:12 +00004819
Douglas Gregord6ff3322009-08-04 16:50:30 +00004820} // end namespace clang
4821
4822#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H