blob: 00af8c1ca0e50bbcb0987602abf77a96b9364d82 [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
Douglas Gregord6ff3322009-08-04 16:50:30 +0000343 /// \brief Build a new incomplete array type given the element type, size
344 /// modifier, and index type qualifiers.
345 ///
346 /// By default, performs semantic analysis when building the array type.
347 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000348 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000349 ArrayType::ArraySizeModifier SizeMod,
350 unsigned IndexTypeQuals);
351
Mike Stump11289f42009-09-09 15:08:12 +0000352 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000353 /// size modifier, size expression, and index type qualifiers.
354 ///
355 /// By default, performs semantic analysis when building the array type.
356 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000357 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000358 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000359 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000360 unsigned IndexTypeQuals,
361 SourceRange BracketsRange);
362
Mike Stump11289f42009-09-09 15:08:12 +0000363 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000364 /// size modifier, size expression, and index type qualifiers.
365 ///
366 /// By default, performs semantic analysis when building the array type.
367 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000368 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000369 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000370 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000371 unsigned IndexTypeQuals,
372 SourceRange BracketsRange);
373
374 /// \brief Build a new vector type given the element type and
375 /// number of elements.
376 ///
377 /// By default, performs semantic analysis when building the vector type.
378 /// Subclasses may override this routine to provide different behavior.
379 QualType RebuildVectorType(QualType ElementType, unsigned NumElements);
Mike Stump11289f42009-09-09 15:08:12 +0000380
Douglas Gregord6ff3322009-08-04 16:50:30 +0000381 /// \brief Build a new extended vector type given the element type and
382 /// number of elements.
383 ///
384 /// By default, performs semantic analysis when building the vector type.
385 /// Subclasses may override this routine to provide different behavior.
386 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
387 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000388
389 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000390 /// given the element type and number of elements.
391 ///
392 /// By default, performs semantic analysis when building the vector type.
393 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000394 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000395 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000396 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000397
Douglas Gregord6ff3322009-08-04 16:50:30 +0000398 /// \brief Build a new function type.
399 ///
400 /// By default, performs semantic analysis when building the function type.
401 /// Subclasses may override this routine to provide different behavior.
402 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000403 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000404 unsigned NumParamTypes,
405 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000406
Douglas Gregord6ff3322009-08-04 16:50:30 +0000407 /// \brief Build a new typedef type.
408 QualType RebuildTypedefType(TypedefDecl *Typedef) {
409 return SemaRef.Context.getTypeDeclType(Typedef);
410 }
411
412 /// \brief Build a new class/struct/union type.
413 QualType RebuildRecordType(RecordDecl *Record) {
414 return SemaRef.Context.getTypeDeclType(Record);
415 }
416
417 /// \brief Build a new Enum type.
418 QualType RebuildEnumType(EnumDecl *Enum) {
419 return SemaRef.Context.getTypeDeclType(Enum);
420 }
John McCallfcc33b02009-09-05 00:15:47 +0000421
422 /// \brief Build a new elaborated type.
423 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
424 return SemaRef.Context.getElaboratedType(T, Tag);
425 }
Mike Stump11289f42009-09-09 15:08:12 +0000426
427 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000428 ///
429 /// By default, performs semantic analysis when building the typeof type.
430 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000431 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000432
Mike Stump11289f42009-09-09 15:08:12 +0000433 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000434 ///
435 /// By default, builds a new TypeOfType with the given underlying type.
436 QualType RebuildTypeOfType(QualType Underlying);
437
Mike Stump11289f42009-09-09 15:08:12 +0000438 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000439 ///
440 /// By default, performs semantic analysis when building the decltype type.
441 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000442 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000443
Douglas Gregord6ff3322009-08-04 16:50:30 +0000444 /// \brief Build a new template specialization type.
445 ///
446 /// By default, performs semantic analysis when building the template
447 /// specialization type. Subclasses may override this routine to provide
448 /// different behavior.
449 QualType RebuildTemplateSpecializationType(TemplateName Template,
450 const TemplateArgument *Args,
451 unsigned NumArgs);
Mike Stump11289f42009-09-09 15:08:12 +0000452
Douglas Gregord6ff3322009-08-04 16:50:30 +0000453 /// \brief Build a new qualified name type.
454 ///
Mike Stump11289f42009-09-09 15:08:12 +0000455 /// By default, builds a new QualifiedNameType type from the
456 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000457 /// this routine to provide different behavior.
458 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
459 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000460 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000461
462 /// \brief Build a new typename type that refers to a template-id.
463 ///
464 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000465 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000466 /// different behavior.
467 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
468 if (NNS->isDependent())
Mike Stump11289f42009-09-09 15:08:12 +0000469 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000470 cast<TemplateSpecializationType>(T));
Mike Stump11289f42009-09-09 15:08:12 +0000471
Douglas Gregord6ff3322009-08-04 16:50:30 +0000472 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000473 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000474
475 /// \brief Build a new typename type that refers to an identifier.
476 ///
477 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000478 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000479 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000480 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000481 const IdentifierInfo *Id) {
482 return SemaRef.CheckTypenameType(NNS, *Id,
483 SourceRange(getDerived().getBaseLocation()));
Douglas Gregor1135c352009-08-06 05:28:30 +0000484 }
Mike Stump11289f42009-09-09 15:08:12 +0000485
Douglas Gregor1135c352009-08-06 05:28:30 +0000486 /// \brief Build a new nested-name-specifier given the prefix and an
487 /// identifier that names the next step in the nested-name-specifier.
488 ///
489 /// By default, performs semantic analysis when building the new
490 /// nested-name-specifier. Subclasses may override this routine to provide
491 /// different behavior.
492 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
493 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000494 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000495 QualType ObjectType,
496 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000497
498 /// \brief Build a new nested-name-specifier given the prefix and the
499 /// namespace named in the next step in the nested-name-specifier.
500 ///
501 /// By default, performs semantic analysis when building the new
502 /// nested-name-specifier. Subclasses may override this routine to provide
503 /// different behavior.
504 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
505 SourceRange Range,
506 NamespaceDecl *NS);
507
508 /// \brief Build a new nested-name-specifier given the prefix and the
509 /// type named in the next step in the nested-name-specifier.
510 ///
511 /// By default, performs semantic analysis when building the new
512 /// nested-name-specifier. Subclasses may override this routine to provide
513 /// different behavior.
514 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
515 SourceRange Range,
516 bool TemplateKW,
517 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000518
519 /// \brief Build a new template name given a nested name specifier, a flag
520 /// indicating whether the "template" keyword was provided, and the template
521 /// that the template name refers to.
522 ///
523 /// By default, builds the new template name directly. Subclasses may override
524 /// this routine to provide different behavior.
525 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
526 bool TemplateKW,
527 TemplateDecl *Template);
528
529 /// \brief Build a new template name given a nested name specifier, a flag
530 /// indicating whether the "template" keyword was provided, and a set of
531 /// overloaded function templates.
532 ///
533 /// By default, builds the new template name directly. Subclasses may override
534 /// this routine to provide different behavior.
535 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
536 bool TemplateKW,
537 OverloadedFunctionDecl *Ovl);
Mike Stump11289f42009-09-09 15:08:12 +0000538
Douglas Gregor71dc5092009-08-06 06:41:21 +0000539 /// \brief Build a new template name given a nested name specifier and the
540 /// name that is referred to as a template.
541 ///
542 /// By default, performs semantic analysis to determine whether the name can
543 /// be resolved to a specific template, then builds the appropriate kind of
544 /// template name. Subclasses may override this routine to provide different
545 /// behavior.
546 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000547 const IdentifierInfo &II,
548 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000549
550
Douglas Gregorebe10102009-08-20 07:17:43 +0000551 /// \brief Build a new compound statement.
552 ///
553 /// By default, performs semantic analysis to build the new statement.
554 /// Subclasses may override this routine to provide different behavior.
555 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
556 MultiStmtArg Statements,
557 SourceLocation RBraceLoc,
558 bool IsStmtExpr) {
559 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
560 IsStmtExpr);
561 }
562
563 /// \brief Build a new case statement.
564 ///
565 /// By default, performs semantic analysis to build the new statement.
566 /// Subclasses may override this routine to provide different behavior.
567 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
568 ExprArg LHS,
569 SourceLocation EllipsisLoc,
570 ExprArg RHS,
571 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000572 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000573 ColonLoc);
574 }
Mike Stump11289f42009-09-09 15:08:12 +0000575
Douglas Gregorebe10102009-08-20 07:17:43 +0000576 /// \brief Attach the body to a new case statement.
577 ///
578 /// By default, performs semantic analysis to build the new statement.
579 /// Subclasses may override this routine to provide different behavior.
580 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
581 getSema().ActOnCaseStmtBody(S.get(), move(Body));
582 return move(S);
583 }
Mike Stump11289f42009-09-09 15:08:12 +0000584
Douglas Gregorebe10102009-08-20 07:17:43 +0000585 /// \brief Build a new default statement.
586 ///
587 /// By default, performs semantic analysis to build the new statement.
588 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000589 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000590 SourceLocation ColonLoc,
591 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000592 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000593 /*CurScope=*/0);
594 }
Mike Stump11289f42009-09-09 15:08:12 +0000595
Douglas Gregorebe10102009-08-20 07:17:43 +0000596 /// \brief Build a new label statement.
597 ///
598 /// By default, performs semantic analysis to build the new statement.
599 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000600 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000601 IdentifierInfo *Id,
602 SourceLocation ColonLoc,
603 StmtArg SubStmt) {
604 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
605 }
Mike Stump11289f42009-09-09 15:08:12 +0000606
Douglas Gregorebe10102009-08-20 07:17:43 +0000607 /// \brief Build a new "if" statement.
608 ///
609 /// By default, performs semantic analysis to build the new statement.
610 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000611 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
612 StmtArg Then, SourceLocation ElseLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000613 StmtArg Else) {
614 return getSema().ActOnIfStmt(IfLoc, Cond, move(Then), ElseLoc, move(Else));
615 }
Mike Stump11289f42009-09-09 15:08:12 +0000616
Douglas Gregorebe10102009-08-20 07:17:43 +0000617 /// \brief Start building a new switch statement.
618 ///
619 /// By default, performs semantic analysis to build the new statement.
620 /// Subclasses may override this routine to provide different behavior.
621 OwningStmtResult RebuildSwitchStmtStart(ExprArg Cond) {
622 return getSema().ActOnStartOfSwitchStmt(move(Cond));
623 }
Mike Stump11289f42009-09-09 15:08:12 +0000624
Douglas Gregorebe10102009-08-20 07:17:43 +0000625 /// \brief Attach the body to the switch statement.
626 ///
627 /// By default, performs semantic analysis to build the new statement.
628 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000629 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000630 StmtArg Switch, StmtArg Body) {
631 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
632 move(Body));
633 }
634
635 /// \brief Build a new while statement.
636 ///
637 /// By default, performs semantic analysis to build the new statement.
638 /// Subclasses may override this routine to provide different behavior.
639 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
640 Sema::FullExprArg Cond,
641 StmtArg Body) {
642 return getSema().ActOnWhileStmt(WhileLoc, Cond, move(Body));
643 }
Mike Stump11289f42009-09-09 15:08:12 +0000644
Douglas Gregorebe10102009-08-20 07:17:43 +0000645 /// \brief Build a new do-while statement.
646 ///
647 /// By default, performs semantic analysis to build the new statement.
648 /// Subclasses may override this routine to provide different behavior.
649 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
650 SourceLocation WhileLoc,
651 SourceLocation LParenLoc,
652 ExprArg Cond,
653 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000654 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000655 move(Cond), RParenLoc);
656 }
657
658 /// \brief Build a new for statement.
659 ///
660 /// By default, performs semantic analysis to build the new statement.
661 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000662 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000663 SourceLocation LParenLoc,
664 StmtArg Init, ExprArg Cond, ExprArg Inc,
665 SourceLocation RParenLoc, StmtArg Body) {
Mike Stump11289f42009-09-09 15:08:12 +0000666 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), move(Cond),
Douglas Gregorebe10102009-08-20 07:17:43 +0000667 move(Inc), RParenLoc, move(Body));
668 }
Mike Stump11289f42009-09-09 15:08:12 +0000669
Douglas Gregorebe10102009-08-20 07:17:43 +0000670 /// \brief Build a new goto statement.
671 ///
672 /// By default, performs semantic analysis to build the new statement.
673 /// Subclasses may override this routine to provide different behavior.
674 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
675 SourceLocation LabelLoc,
676 LabelStmt *Label) {
677 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
678 }
679
680 /// \brief Build a new indirect goto statement.
681 ///
682 /// By default, performs semantic analysis to build the new statement.
683 /// Subclasses may override this routine to provide different behavior.
684 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
685 SourceLocation StarLoc,
686 ExprArg Target) {
687 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
688 }
Mike Stump11289f42009-09-09 15:08:12 +0000689
Douglas Gregorebe10102009-08-20 07:17:43 +0000690 /// \brief Build a new return statement.
691 ///
692 /// By default, performs semantic analysis to build the new statement.
693 /// Subclasses may override this routine to provide different behavior.
694 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
695 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000696
Douglas Gregorebe10102009-08-20 07:17:43 +0000697 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
698 }
Mike Stump11289f42009-09-09 15:08:12 +0000699
Douglas Gregorebe10102009-08-20 07:17:43 +0000700 /// \brief Build a new declaration statement.
701 ///
702 /// By default, performs semantic analysis to build the new statement.
703 /// Subclasses may override this routine to provide different behavior.
704 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000705 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000706 SourceLocation EndLoc) {
707 return getSema().Owned(
708 new (getSema().Context) DeclStmt(
709 DeclGroupRef::Create(getSema().Context,
710 Decls, NumDecls),
711 StartLoc, EndLoc));
712 }
Mike Stump11289f42009-09-09 15:08:12 +0000713
Douglas Gregorebe10102009-08-20 07:17:43 +0000714 /// \brief Build a new C++ exception declaration.
715 ///
716 /// By default, performs semantic analysis to build the new decaration.
717 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000718 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
Douglas Gregorebe10102009-08-20 07:17:43 +0000719 DeclaratorInfo *Declarator,
720 IdentifierInfo *Name,
721 SourceLocation Loc,
722 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000723 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000724 TypeRange);
725 }
726
727 /// \brief Build a new C++ catch statement.
728 ///
729 /// By default, performs semantic analysis to build the new statement.
730 /// Subclasses may override this routine to provide different behavior.
731 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
732 VarDecl *ExceptionDecl,
733 StmtArg Handler) {
734 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000735 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000736 Handler.takeAs<Stmt>()));
737 }
Mike Stump11289f42009-09-09 15:08:12 +0000738
Douglas Gregorebe10102009-08-20 07:17:43 +0000739 /// \brief Build a new C++ try statement.
740 ///
741 /// By default, performs semantic analysis to build the new statement.
742 /// Subclasses may override this routine to provide different behavior.
743 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
744 StmtArg TryBlock,
745 MultiStmtArg Handlers) {
746 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
747 }
Mike Stump11289f42009-09-09 15:08:12 +0000748
Douglas Gregora16548e2009-08-11 05:31:07 +0000749 /// \brief Build a new expression that references a declaration.
750 ///
751 /// By default, performs semantic analysis to build the new expression.
752 /// Subclasses may override this routine to provide different behavior.
753 OwningExprResult RebuildDeclRefExpr(NamedDecl *ND, SourceLocation Loc) {
754 return getSema().BuildDeclarationNameExpr(Loc, ND,
755 /*FIXME:*/false,
756 /*SS=*/0,
757 /*FIXME:*/false);
758 }
Mike Stump11289f42009-09-09 15:08:12 +0000759
Douglas Gregora16548e2009-08-11 05:31:07 +0000760 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000761 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000762 /// By default, performs semantic analysis to build the new expression.
763 /// Subclasses may override this routine to provide different behavior.
764 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
765 SourceLocation RParen) {
766 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
767 }
768
Douglas Gregorad8a3362009-09-04 17:36:40 +0000769 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000770 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000771 /// By default, performs semantic analysis to build the new expression.
772 /// Subclasses may override this routine to provide different behavior.
773 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
774 SourceLocation OperatorLoc,
775 bool isArrow,
776 SourceLocation DestroyedTypeLoc,
777 QualType DestroyedType,
778 NestedNameSpecifier *Qualifier,
779 SourceRange QualifierRange) {
780 CXXScopeSpec SS;
781 if (Qualifier) {
782 SS.setRange(QualifierRange);
783 SS.setScopeRep(Qualifier);
784 }
785
Mike Stump11289f42009-09-09 15:08:12 +0000786 DeclarationName Name
Douglas Gregorad8a3362009-09-04 17:36:40 +0000787 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
788 SemaRef.Context.getCanonicalType(DestroyedType));
Mike Stump11289f42009-09-09 15:08:12 +0000789
790 return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base),
Douglas Gregorad8a3362009-09-04 17:36:40 +0000791 OperatorLoc,
792 isArrow? tok::arrow : tok::period,
793 DestroyedTypeLoc,
794 Name,
795 Sema::DeclPtrTy::make((Decl *)0),
796 &SS);
Mike Stump11289f42009-09-09 15:08:12 +0000797 }
798
Douglas Gregora16548e2009-08-11 05:31:07 +0000799 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000800 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000801 /// By default, performs semantic analysis to build the new expression.
802 /// Subclasses may override this routine to provide different behavior.
803 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
804 UnaryOperator::Opcode Opc,
805 ExprArg SubExpr) {
806 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(SubExpr));
807 }
Mike Stump11289f42009-09-09 15:08:12 +0000808
Douglas Gregora16548e2009-08-11 05:31:07 +0000809 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000810 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000811 /// By default, performs semantic analysis to build the new expression.
812 /// Subclasses may override this routine to provide different behavior.
813 OwningExprResult RebuildSizeOfAlignOf(QualType T, SourceLocation OpLoc,
814 bool isSizeOf, SourceRange R) {
815 return getSema().CreateSizeOfAlignOfExpr(T, OpLoc, isSizeOf, R);
816 }
817
Mike Stump11289f42009-09-09 15:08:12 +0000818 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000819 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +0000820 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000821 /// By default, performs semantic analysis to build the new expression.
822 /// Subclasses may override this routine to provide different behavior.
823 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
824 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +0000825 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000826 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
827 OpLoc, isSizeOf, R);
828 if (Result.isInvalid())
829 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000830
Douglas Gregora16548e2009-08-11 05:31:07 +0000831 SubExpr.release();
832 return move(Result);
833 }
Mike Stump11289f42009-09-09 15:08:12 +0000834
Douglas Gregora16548e2009-08-11 05:31:07 +0000835 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +0000836 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000837 /// By default, performs semantic analysis to build the new expression.
838 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000839 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000840 SourceLocation LBracketLoc,
841 ExprArg RHS,
842 SourceLocation RBracketLoc) {
843 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000844 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000845 RBracketLoc);
846 }
847
848 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000849 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000850 /// By default, performs semantic analysis to build the new expression.
851 /// Subclasses may override this routine to provide different behavior.
852 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
853 MultiExprArg Args,
854 SourceLocation *CommaLocs,
855 SourceLocation RParenLoc) {
856 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
857 move(Args), CommaLocs, RParenLoc);
858 }
859
860 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000861 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000862 /// By default, performs semantic analysis to build the new expression.
863 /// Subclasses may override this routine to provide different behavior.
864 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000865 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000866 NestedNameSpecifier *Qualifier,
867 SourceRange QualifierRange,
868 SourceLocation MemberLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000869 NamedDecl *Member) {
Anders Carlsson5da84842009-09-01 04:26:58 +0000870 if (!Member->getDeclName()) {
871 // We have a reference to an unnamed field.
872 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +0000873
874 MemberExpr *ME =
Anders Carlsson5da84842009-09-01 04:26:58 +0000875 new (getSema().Context) MemberExpr(Base.takeAs<Expr>(), isArrow,
876 Member, MemberLoc,
877 cast<FieldDecl>(Member)->getType());
878 return getSema().Owned(ME);
879 }
Mike Stump11289f42009-09-09 15:08:12 +0000880
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000881 CXXScopeSpec SS;
882 if (Qualifier) {
883 SS.setRange(QualifierRange);
884 SS.setScopeRep(Qualifier);
885 }
886
Douglas Gregorf14b46f2009-08-31 20:00:26 +0000887 return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000888 isArrow? tok::arrow : tok::period,
889 MemberLoc,
Douglas Gregorf14b46f2009-08-31 20:00:26 +0000890 Member->getDeclName(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000891 /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0),
892 &SS);
Douglas Gregora16548e2009-08-11 05:31:07 +0000893 }
Mike Stump11289f42009-09-09 15:08:12 +0000894
Douglas Gregora16548e2009-08-11 05:31:07 +0000895 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000896 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000897 /// By default, performs semantic analysis to build the new expression.
898 /// Subclasses may override this routine to provide different behavior.
899 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
900 BinaryOperator::Opcode Opc,
901 ExprArg LHS, ExprArg RHS) {
902 OwningExprResult Result
Mike Stump11289f42009-09-09 15:08:12 +0000903 = getSema().CreateBuiltinBinOp(OpLoc, Opc, (Expr *)LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +0000904 (Expr *)RHS.get());
905 if (Result.isInvalid())
906 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000907
Douglas Gregora16548e2009-08-11 05:31:07 +0000908 LHS.release();
909 RHS.release();
910 return move(Result);
911 }
912
913 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000914 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000915 /// By default, performs semantic analysis to build the new expression.
916 /// Subclasses may override this routine to provide different behavior.
917 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
918 SourceLocation QuestionLoc,
919 ExprArg LHS,
920 SourceLocation ColonLoc,
921 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +0000922 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +0000923 move(LHS), move(RHS));
924 }
925
926 /// \brief Build a new implicit cast expression.
Mike Stump11289f42009-09-09 15:08:12 +0000927 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000928 /// By default, builds a new implicit cast without any semantic analysis.
929 /// Subclasses may override this routine to provide different behavior.
930 OwningExprResult RebuildImplicitCastExpr(QualType T, CastExpr::CastKind Kind,
931 ExprArg SubExpr, bool isLvalue) {
932 ImplicitCastExpr *ICE
Mike Stump11289f42009-09-09 15:08:12 +0000933 = new (getSema().Context) ImplicitCastExpr(T, Kind,
Douglas Gregora16548e2009-08-11 05:31:07 +0000934 (Expr *)SubExpr.release(),
935 isLvalue);
936 return getSema().Owned(ICE);
937 }
938
939 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +0000940 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000941 /// By default, performs semantic analysis to build the new expression.
942 /// Subclasses may override this routine to provide different behavior.
943 OwningExprResult RebuildCStyleCaseExpr(SourceLocation LParenLoc,
944 QualType ExplicitTy,
945 SourceLocation RParenLoc,
946 ExprArg SubExpr) {
947 return getSema().ActOnCastExpr(/*Scope=*/0,
948 LParenLoc,
949 ExplicitTy.getAsOpaquePtr(),
950 RParenLoc,
951 move(SubExpr));
952 }
Mike Stump11289f42009-09-09 15:08:12 +0000953
Douglas Gregora16548e2009-08-11 05:31:07 +0000954 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +0000955 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000956 /// By default, performs semantic analysis to build the new expression.
957 /// Subclasses may override this routine to provide different behavior.
958 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
959 QualType T,
960 SourceLocation RParenLoc,
961 ExprArg Init) {
962 return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(),
963 RParenLoc, move(Init));
964 }
Mike Stump11289f42009-09-09 15:08:12 +0000965
Douglas Gregora16548e2009-08-11 05:31:07 +0000966 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000967 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000968 /// By default, performs semantic analysis to build the new expression.
969 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000970 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +0000971 SourceLocation OpLoc,
972 SourceLocation AccessorLoc,
973 IdentifierInfo &Accessor) {
974 return getSema().ActOnMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc,
975 tok::period, AccessorLoc,
976 Accessor,
977 /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0));
978 }
Mike Stump11289f42009-09-09 15:08:12 +0000979
Douglas Gregora16548e2009-08-11 05:31:07 +0000980 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +0000981 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000982 /// By default, performs semantic analysis to build the new expression.
983 /// Subclasses may override this routine to provide different behavior.
984 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
985 MultiExprArg Inits,
986 SourceLocation RBraceLoc) {
987 return SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
988 }
Mike Stump11289f42009-09-09 15:08:12 +0000989
Douglas Gregora16548e2009-08-11 05:31:07 +0000990 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +0000991 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000992 /// By default, performs semantic analysis to build the new expression.
993 /// Subclasses may override this routine to provide different behavior.
994 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
995 MultiExprArg ArrayExprs,
996 SourceLocation EqualOrColonLoc,
997 bool GNUSyntax,
998 ExprArg Init) {
999 OwningExprResult Result
1000 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1001 move(Init));
1002 if (Result.isInvalid())
1003 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001004
Douglas Gregora16548e2009-08-11 05:31:07 +00001005 ArrayExprs.release();
1006 return move(Result);
1007 }
Mike Stump11289f42009-09-09 15:08:12 +00001008
Douglas Gregora16548e2009-08-11 05:31:07 +00001009 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001010 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001011 /// By default, builds the implicit value initialization without performing
1012 /// any semantic analysis. Subclasses may override this routine to provide
1013 /// different behavior.
1014 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1015 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1016 }
Mike Stump11289f42009-09-09 15:08:12 +00001017
Douglas Gregora16548e2009-08-11 05:31:07 +00001018 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001019 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001020 /// By default, performs semantic analysis to build the new expression.
1021 /// Subclasses may override this routine to provide different behavior.
1022 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1023 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001024 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001025 RParenLoc);
1026 }
1027
1028 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001029 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001030 /// By default, performs semantic analysis to build the new expression.
1031 /// Subclasses may override this routine to provide different behavior.
1032 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1033 MultiExprArg SubExprs,
1034 SourceLocation RParenLoc) {
1035 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
1036 }
Mike Stump11289f42009-09-09 15:08:12 +00001037
Douglas Gregora16548e2009-08-11 05:31:07 +00001038 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001039 ///
1040 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001041 /// rather than attempting to map the label statement itself.
1042 /// Subclasses may override this routine to provide different behavior.
1043 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1044 SourceLocation LabelLoc,
1045 LabelStmt *Label) {
1046 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1047 }
Mike Stump11289f42009-09-09 15:08:12 +00001048
Douglas Gregora16548e2009-08-11 05:31:07 +00001049 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001050 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001051 /// By default, performs semantic analysis to build the new expression.
1052 /// Subclasses may override this routine to provide different behavior.
1053 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1054 StmtArg SubStmt,
1055 SourceLocation RParenLoc) {
1056 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1057 }
Mike Stump11289f42009-09-09 15:08:12 +00001058
Douglas Gregora16548e2009-08-11 05:31:07 +00001059 /// \brief Build a new __builtin_types_compatible_p expression.
1060 ///
1061 /// By default, performs semantic analysis to build the new expression.
1062 /// Subclasses may override this routine to provide different behavior.
1063 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1064 QualType T1, QualType T2,
1065 SourceLocation RParenLoc) {
1066 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1067 T1.getAsOpaquePtr(),
1068 T2.getAsOpaquePtr(),
1069 RParenLoc);
1070 }
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregora16548e2009-08-11 05:31:07 +00001072 /// \brief Build a new __builtin_choose_expr expression.
1073 ///
1074 /// By default, performs semantic analysis to build the new expression.
1075 /// Subclasses may override this routine to provide different behavior.
1076 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1077 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1078 SourceLocation RParenLoc) {
1079 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1080 move(Cond), move(LHS), move(RHS),
1081 RParenLoc);
1082 }
Mike Stump11289f42009-09-09 15:08:12 +00001083
Douglas Gregora16548e2009-08-11 05:31:07 +00001084 /// \brief Build a new overloaded operator call expression.
1085 ///
1086 /// By default, performs semantic analysis to build the new expression.
1087 /// The semantic analysis provides the behavior of template instantiation,
1088 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001089 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001090 /// argument-dependent lookup, etc. Subclasses may override this routine to
1091 /// provide different behavior.
1092 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1093 SourceLocation OpLoc,
1094 ExprArg Callee,
1095 ExprArg First,
1096 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001097
1098 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001099 /// reinterpret_cast.
1100 ///
1101 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001102 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001103 /// Subclasses may override this routine to provide different behavior.
1104 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1105 Stmt::StmtClass Class,
1106 SourceLocation LAngleLoc,
1107 QualType T,
1108 SourceLocation RAngleLoc,
1109 SourceLocation LParenLoc,
1110 ExprArg SubExpr,
1111 SourceLocation RParenLoc) {
1112 switch (Class) {
1113 case Stmt::CXXStaticCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001114 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T,
1115 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001116 move(SubExpr), RParenLoc);
1117
1118 case Stmt::CXXDynamicCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001119 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T,
1120 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001121 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001122
Douglas Gregora16548e2009-08-11 05:31:07 +00001123 case Stmt::CXXReinterpretCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001124 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T,
1125 RAngleLoc, LParenLoc,
1126 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001127 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001128
Douglas Gregora16548e2009-08-11 05:31:07 +00001129 case Stmt::CXXConstCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001130 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T,
1131 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001132 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001133
Douglas Gregora16548e2009-08-11 05:31:07 +00001134 default:
1135 assert(false && "Invalid C++ named cast");
1136 break;
1137 }
Mike Stump11289f42009-09-09 15:08:12 +00001138
Douglas Gregora16548e2009-08-11 05:31:07 +00001139 return getSema().ExprError();
1140 }
Mike Stump11289f42009-09-09 15:08:12 +00001141
Douglas Gregora16548e2009-08-11 05:31:07 +00001142 /// \brief Build a new C++ static_cast expression.
1143 ///
1144 /// By default, performs semantic analysis to build the new expression.
1145 /// Subclasses may override this routine to provide different behavior.
1146 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1147 SourceLocation LAngleLoc,
1148 QualType T,
1149 SourceLocation RAngleLoc,
1150 SourceLocation LParenLoc,
1151 ExprArg SubExpr,
1152 SourceLocation RParenLoc) {
1153 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001154 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001155 LParenLoc, move(SubExpr), RParenLoc);
1156 }
1157
1158 /// \brief Build a new C++ dynamic_cast expression.
1159 ///
1160 /// By default, performs semantic analysis to build the new expression.
1161 /// Subclasses may override this routine to provide different behavior.
1162 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1163 SourceLocation LAngleLoc,
1164 QualType T,
1165 SourceLocation RAngleLoc,
1166 SourceLocation LParenLoc,
1167 ExprArg SubExpr,
1168 SourceLocation RParenLoc) {
1169 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001170 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001171 LParenLoc, move(SubExpr), RParenLoc);
1172 }
1173
1174 /// \brief Build a new C++ reinterpret_cast expression.
1175 ///
1176 /// By default, performs semantic analysis to build the new expression.
1177 /// Subclasses may override this routine to provide different behavior.
1178 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1179 SourceLocation LAngleLoc,
1180 QualType T,
1181 SourceLocation RAngleLoc,
1182 SourceLocation LParenLoc,
1183 ExprArg SubExpr,
1184 SourceLocation RParenLoc) {
1185 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1186 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
1187 LParenLoc, move(SubExpr), RParenLoc);
1188 }
1189
1190 /// \brief Build a new C++ const_cast expression.
1191 ///
1192 /// By default, performs semantic analysis to build the new expression.
1193 /// Subclasses may override this routine to provide different behavior.
1194 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1195 SourceLocation LAngleLoc,
1196 QualType T,
1197 SourceLocation RAngleLoc,
1198 SourceLocation LParenLoc,
1199 ExprArg SubExpr,
1200 SourceLocation RParenLoc) {
1201 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001202 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001203 LParenLoc, move(SubExpr), RParenLoc);
1204 }
Mike Stump11289f42009-09-09 15:08:12 +00001205
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 /// \brief Build a new C++ functional-style cast expression.
1207 ///
1208 /// By default, performs semantic analysis to build the new expression.
1209 /// Subclasses may override this routine to provide different behavior.
1210 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
1211 QualType T,
1212 SourceLocation LParenLoc,
1213 ExprArg SubExpr,
1214 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001215 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001216 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
1217 T.getAsOpaquePtr(),
1218 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001219 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001220 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001221 RParenLoc);
1222 }
Mike Stump11289f42009-09-09 15:08:12 +00001223
Douglas Gregora16548e2009-08-11 05:31:07 +00001224 /// \brief Build a new C++ typeid(type) expression.
1225 ///
1226 /// By default, performs semantic analysis to build the new expression.
1227 /// Subclasses may override this routine to provide different behavior.
1228 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1229 SourceLocation LParenLoc,
1230 QualType T,
1231 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001232 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001233 T.getAsOpaquePtr(), RParenLoc);
1234 }
Mike Stump11289f42009-09-09 15:08:12 +00001235
Douglas Gregora16548e2009-08-11 05:31:07 +00001236 /// \brief Build a new C++ typeid(expr) expression.
1237 ///
1238 /// By default, performs semantic analysis to build the new expression.
1239 /// Subclasses may override this routine to provide different behavior.
1240 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1241 SourceLocation LParenLoc,
1242 ExprArg Operand,
1243 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001244 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001245 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1246 RParenLoc);
1247 if (Result.isInvalid())
1248 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001249
Douglas Gregora16548e2009-08-11 05:31:07 +00001250 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1251 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001252 }
1253
Douglas Gregora16548e2009-08-11 05:31:07 +00001254 /// \brief Build a new C++ "this" expression.
1255 ///
1256 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001257 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001258 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001259 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001260 QualType ThisType) {
1261 return getSema().Owned(
1262 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType));
1263 }
1264
1265 /// \brief Build a new C++ throw expression.
1266 ///
1267 /// By default, performs semantic analysis to build the new expression.
1268 /// Subclasses may override this routine to provide different behavior.
1269 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1270 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1271 }
1272
1273 /// \brief Build a new C++ default-argument expression.
1274 ///
1275 /// By default, builds a new default-argument expression, which does not
1276 /// require any semantic analysis. Subclasses may override this routine to
1277 /// provide different behavior.
1278 OwningExprResult RebuildCXXDefaultArgExpr(ParmVarDecl *Param) {
Anders Carlssone8271232009-08-14 18:30:22 +00001279 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 }
1281
1282 /// \brief Build a new C++ zero-initialization expression.
1283 ///
1284 /// By default, performs semantic analysis to build the new expression.
1285 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001286 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001287 SourceLocation LParenLoc,
1288 QualType T,
1289 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001290 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1291 T.getAsOpaquePtr(), LParenLoc,
1292 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001293 0, RParenLoc);
1294 }
Mike Stump11289f42009-09-09 15:08:12 +00001295
Douglas Gregora16548e2009-08-11 05:31:07 +00001296 /// \brief Build a new C++ conditional declaration expression.
1297 ///
1298 /// By default, performs semantic analysis to build the new expression.
1299 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001300 OwningExprResult RebuildCXXConditionDeclExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001301 SourceLocation EqLoc,
1302 VarDecl *Var) {
1303 return SemaRef.Owned(new (SemaRef.Context) CXXConditionDeclExpr(StartLoc,
1304 EqLoc,
1305 Var));
1306 }
Mike Stump11289f42009-09-09 15:08:12 +00001307
Douglas Gregora16548e2009-08-11 05:31:07 +00001308 /// \brief Build a new C++ "new" expression.
1309 ///
1310 /// By default, performs semantic analysis to build the new expression.
1311 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001312 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 bool UseGlobal,
1314 SourceLocation PlacementLParen,
1315 MultiExprArg PlacementArgs,
1316 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001317 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001318 QualType AllocType,
1319 SourceLocation TypeLoc,
1320 SourceRange TypeRange,
1321 ExprArg ArraySize,
1322 SourceLocation ConstructorLParen,
1323 MultiExprArg ConstructorArgs,
1324 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001325 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 PlacementLParen,
1327 move(PlacementArgs),
1328 PlacementRParen,
1329 ParenTypeId,
1330 AllocType,
1331 TypeLoc,
1332 TypeRange,
1333 move(ArraySize),
1334 ConstructorLParen,
1335 move(ConstructorArgs),
1336 ConstructorRParen);
1337 }
Mike Stump11289f42009-09-09 15:08:12 +00001338
Douglas Gregora16548e2009-08-11 05:31:07 +00001339 /// \brief Build a new C++ "delete" expression.
1340 ///
1341 /// By default, performs semantic analysis to build the new expression.
1342 /// Subclasses may override this routine to provide different behavior.
1343 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1344 bool IsGlobalDelete,
1345 bool IsArrayForm,
1346 ExprArg Operand) {
1347 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1348 move(Operand));
1349 }
Mike Stump11289f42009-09-09 15:08:12 +00001350
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 /// \brief Build a new unary type trait expression.
1352 ///
1353 /// By default, performs semantic analysis to build the new expression.
1354 /// Subclasses may override this routine to provide different behavior.
1355 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1356 SourceLocation StartLoc,
1357 SourceLocation LParenLoc,
1358 QualType T,
1359 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001360 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001361 T.getAsOpaquePtr(), RParenLoc);
1362 }
1363
1364 /// \brief Build a new qualified declaration reference expression.
1365 ///
1366 /// By default, performs semantic analysis to build the new expression.
1367 /// Subclasses may override this routine to provide different behavior.
1368 OwningExprResult RebuildQualifiedDeclRefExpr(NestedNameSpecifier *NNS,
1369 SourceRange QualifierRange,
1370 NamedDecl *ND,
1371 SourceLocation Location,
1372 bool IsAddressOfOperand) {
1373 CXXScopeSpec SS;
1374 SS.setRange(QualifierRange);
1375 SS.setScopeRep(NNS);
Mike Stump11289f42009-09-09 15:08:12 +00001376 return getSema().ActOnDeclarationNameExpr(/*Scope=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001377 Location,
1378 ND->getDeclName(),
1379 /*Trailing lparen=*/false,
1380 &SS,
1381 IsAddressOfOperand);
1382 }
1383
Mike Stump11289f42009-09-09 15:08:12 +00001384 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001385 /// expression.
1386 ///
1387 /// By default, performs semantic analysis to build the new expression.
1388 /// Subclasses may override this routine to provide different behavior.
1389 OwningExprResult RebuildUnresolvedDeclRefExpr(NestedNameSpecifier *NNS,
1390 SourceRange QualifierRange,
1391 DeclarationName Name,
1392 SourceLocation Location,
1393 bool IsAddressOfOperand) {
1394 CXXScopeSpec SS;
1395 SS.setRange(QualifierRange);
1396 SS.setScopeRep(NNS);
Mike Stump11289f42009-09-09 15:08:12 +00001397 return getSema().ActOnDeclarationNameExpr(/*Scope=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001398 Location,
1399 Name,
1400 /*Trailing lparen=*/false,
1401 &SS,
1402 IsAddressOfOperand);
1403 }
1404
1405 /// \brief Build a new template-id expression.
1406 ///
1407 /// By default, performs semantic analysis to build the new expression.
1408 /// Subclasses may override this routine to provide different behavior.
1409 OwningExprResult RebuildTemplateIdExpr(TemplateName Template,
1410 SourceLocation TemplateLoc,
1411 SourceLocation LAngleLoc,
1412 TemplateArgument *TemplateArgs,
1413 unsigned NumTemplateArgs,
1414 SourceLocation RAngleLoc) {
1415 return getSema().BuildTemplateIdExpr(Template, TemplateLoc,
1416 LAngleLoc,
1417 TemplateArgs, NumTemplateArgs,
1418 RAngleLoc);
1419 }
1420
1421 /// \brief Build a new object-construction expression.
1422 ///
1423 /// By default, performs semantic analysis to build the new expression.
1424 /// Subclasses may override this routine to provide different behavior.
1425 OwningExprResult RebuildCXXConstructExpr(QualType T,
1426 CXXConstructorDecl *Constructor,
1427 bool IsElidable,
1428 MultiExprArg Args) {
Anders Carlsson1b4ebfa2009-09-05 07:40:38 +00001429 return getSema().BuildCXXConstructExpr(/*FIXME:ConstructLoc*/
1430 SourceLocation(),
1431 T, Constructor, IsElidable,
Anders Carlsson5995a3e2009-09-07 22:23:31 +00001432 move(Args));
Douglas Gregora16548e2009-08-11 05:31:07 +00001433 }
1434
1435 /// \brief Build a new object-construction expression.
1436 ///
1437 /// By default, performs semantic analysis to build the new expression.
1438 /// Subclasses may override this routine to provide different behavior.
1439 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1440 QualType T,
1441 SourceLocation LParenLoc,
1442 MultiExprArg Args,
1443 SourceLocation *Commas,
1444 SourceLocation RParenLoc) {
1445 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1446 T.getAsOpaquePtr(),
1447 LParenLoc,
1448 move(Args),
1449 Commas,
1450 RParenLoc);
1451 }
1452
1453 /// \brief Build a new object-construction expression.
1454 ///
1455 /// By default, performs semantic analysis to build the new expression.
1456 /// Subclasses may override this routine to provide different behavior.
1457 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1458 QualType T,
1459 SourceLocation LParenLoc,
1460 MultiExprArg Args,
1461 SourceLocation *Commas,
1462 SourceLocation RParenLoc) {
1463 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1464 /*FIXME*/LParenLoc),
1465 T.getAsOpaquePtr(),
1466 LParenLoc,
1467 move(Args),
1468 Commas,
1469 RParenLoc);
1470 }
Mike Stump11289f42009-09-09 15:08:12 +00001471
Douglas Gregora16548e2009-08-11 05:31:07 +00001472 /// \brief Build a new member reference expression.
1473 ///
1474 /// By default, performs semantic analysis to build the new expression.
1475 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2168a9f2009-08-11 15:56:57 +00001476 OwningExprResult RebuildCXXUnresolvedMemberExpr(ExprArg BaseE,
Douglas Gregora16548e2009-08-11 05:31:07 +00001477 bool IsArrow,
1478 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001479 NestedNameSpecifier *Qualifier,
1480 SourceRange QualifierRange,
Douglas Gregora16548e2009-08-11 05:31:07 +00001481 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001482 SourceLocation MemberLoc,
1483 NamedDecl *FirstQualifierInScope) {
Douglas Gregor2168a9f2009-08-11 15:56:57 +00001484 OwningExprResult Base = move(BaseE);
Douglas Gregora16548e2009-08-11 05:31:07 +00001485 tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001486
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001488 SS.setRange(QualifierRange);
1489 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001490
Douglas Gregor308047d2009-09-09 00:23:06 +00001491 return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 move(Base), OperatorLoc, OpKind,
Douglas Gregorf14b46f2009-08-31 20:00:26 +00001493 MemberLoc,
1494 Name,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001495 /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001496 &SS,
1497 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00001498 }
1499
Douglas Gregor308047d2009-09-09 00:23:06 +00001500 /// \brief Build a new member reference expression with explicit template
1501 /// arguments.
1502 ///
1503 /// By default, performs semantic analysis to build the new expression.
1504 /// Subclasses may override this routine to provide different behavior.
1505 OwningExprResult RebuildCXXUnresolvedMemberExpr(ExprArg BaseE,
1506 bool IsArrow,
1507 SourceLocation OperatorLoc,
1508 NestedNameSpecifier *Qualifier,
1509 SourceRange QualifierRange,
1510 TemplateName Template,
1511 SourceLocation TemplateNameLoc,
1512 NamedDecl *FirstQualifierInScope,
1513 SourceLocation LAngleLoc,
1514 const TemplateArgument *TemplateArgs,
1515 unsigned NumTemplateArgs,
1516 SourceLocation RAngleLoc) {
1517 OwningExprResult Base = move(BaseE);
1518 tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period;
Mike Stump11289f42009-09-09 15:08:12 +00001519
Douglas Gregor308047d2009-09-09 00:23:06 +00001520 CXXScopeSpec SS;
1521 SS.setRange(QualifierRange);
1522 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001523
Douglas Gregor308047d2009-09-09 00:23:06 +00001524 // FIXME: We're going to end up looking up the template based on its name,
1525 // twice! Also, duplicates part of Sema::ActOnMemberTemplateIdReferenceExpr.
1526 DeclarationName Name;
1527 if (TemplateDecl *ActualTemplate = Template.getAsTemplateDecl())
1528 Name = ActualTemplate->getDeclName();
Mike Stump11289f42009-09-09 15:08:12 +00001529 else if (OverloadedFunctionDecl *Ovl
Douglas Gregor308047d2009-09-09 00:23:06 +00001530 = Template.getAsOverloadedFunctionDecl())
1531 Name = Ovl->getDeclName();
1532 else
1533 Name = Template.getAsDependentTemplateName()->getName();
Mike Stump11289f42009-09-09 15:08:12 +00001534
1535 return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0, move(Base),
Douglas Gregor308047d2009-09-09 00:23:06 +00001536 OperatorLoc, OpKind,
1537 TemplateNameLoc, Name, true,
1538 LAngleLoc, TemplateArgs,
1539 NumTemplateArgs, RAngleLoc,
1540 Sema::DeclPtrTy(), &SS);
1541 }
Mike Stump11289f42009-09-09 15:08:12 +00001542
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 /// \brief Build a new Objective-C @encode expression.
1544 ///
1545 /// By default, performs semantic analysis to build the new expression.
1546 /// Subclasses may override this routine to provide different behavior.
1547 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1548 QualType T,
1549 SourceLocation RParenLoc) {
1550 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1551 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001552 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001553
1554 /// \brief Build a new Objective-C protocol expression.
1555 ///
1556 /// By default, performs semantic analysis to build the new expression.
1557 /// Subclasses may override this routine to provide different behavior.
1558 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1559 SourceLocation AtLoc,
1560 SourceLocation ProtoLoc,
1561 SourceLocation LParenLoc,
1562 SourceLocation RParenLoc) {
1563 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1564 Protocol->getIdentifier(),
1565 AtLoc,
1566 ProtoLoc,
1567 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001568 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 }
Mike Stump11289f42009-09-09 15:08:12 +00001570
Douglas Gregora16548e2009-08-11 05:31:07 +00001571 /// \brief Build a new shuffle vector expression.
1572 ///
1573 /// By default, performs semantic analysis to build the new expression.
1574 /// Subclasses may override this routine to provide different behavior.
1575 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1576 MultiExprArg SubExprs,
1577 SourceLocation RParenLoc) {
1578 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001579 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001580 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1581 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1582 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1583 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001584
Douglas Gregora16548e2009-08-11 05:31:07 +00001585 // Build a reference to the __builtin_shufflevector builtin
1586 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001587 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001588 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
1589 BuiltinLoc, false, false);
1590 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001591
1592 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 unsigned NumSubExprs = SubExprs.size();
1594 Expr **Subs = (Expr **)SubExprs.release();
1595 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1596 Subs, NumSubExprs,
1597 Builtin->getResultType(),
1598 RParenLoc);
1599 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001600
Douglas Gregora16548e2009-08-11 05:31:07 +00001601 // Type-check the __builtin_shufflevector expression.
1602 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1603 if (Result.isInvalid())
1604 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001605
Douglas Gregora16548e2009-08-11 05:31:07 +00001606 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001607 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001609};
Douglas Gregora16548e2009-08-11 05:31:07 +00001610
Douglas Gregorebe10102009-08-20 07:17:43 +00001611template<typename Derived>
1612Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1613 if (!S)
1614 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001615
Douglas Gregorebe10102009-08-20 07:17:43 +00001616 switch (S->getStmtClass()) {
1617 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001618
Douglas Gregorebe10102009-08-20 07:17:43 +00001619 // Transform individual statement nodes
1620#define STMT(Node, Parent) \
1621 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1622#define EXPR(Node, Parent)
1623#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001624
Douglas Gregorebe10102009-08-20 07:17:43 +00001625 // Transform expressions by calling TransformExpr.
1626#define STMT(Node, Parent)
1627#define EXPR(Node, Parent) case Stmt::Node##Class:
1628#include "clang/AST/StmtNodes.def"
1629 {
1630 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1631 if (E.isInvalid())
1632 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001633
Douglas Gregorebe10102009-08-20 07:17:43 +00001634 return getSema().Owned(E.takeAs<Stmt>());
1635 }
Mike Stump11289f42009-09-09 15:08:12 +00001636 }
1637
Douglas Gregorebe10102009-08-20 07:17:43 +00001638 return SemaRef.Owned(S->Retain());
1639}
Mike Stump11289f42009-09-09 15:08:12 +00001640
1641
Douglas Gregore922c772009-08-04 22:27:00 +00001642template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00001643Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E,
1644 bool isAddressOfOperand) {
1645 if (!E)
1646 return SemaRef.Owned(E);
1647
1648 switch (E->getStmtClass()) {
1649 case Stmt::NoStmtClass: break;
1650#define STMT(Node, Parent) case Stmt::Node##Class: break;
1651#define EXPR(Node, Parent) \
1652 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
1653#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001654 }
1655
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001657}
1658
1659template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001660NestedNameSpecifier *
1661TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001662 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001663 QualType ObjectType,
1664 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001665 if (!NNS)
1666 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001667
Douglas Gregorebe10102009-08-20 07:17:43 +00001668 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001669 NestedNameSpecifier *Prefix = NNS->getPrefix();
1670 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001671 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001672 ObjectType,
1673 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001674 if (!Prefix)
1675 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001676
1677 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001678 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001679 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001680 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001681 }
Mike Stump11289f42009-09-09 15:08:12 +00001682
Douglas Gregor1135c352009-08-06 05:28:30 +00001683 switch (NNS->getKind()) {
1684 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001685 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001686 "Identifier nested-name-specifier with no prefix or object type");
1687 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1688 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001689 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001690
1691 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001692 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001693 ObjectType,
1694 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001695
Douglas Gregor1135c352009-08-06 05:28:30 +00001696 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001697 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001698 = cast_or_null<NamespaceDecl>(
1699 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001700 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001701 Prefix == NNS->getPrefix() &&
1702 NS == NNS->getAsNamespace())
1703 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001704
Douglas Gregor1135c352009-08-06 05:28:30 +00001705 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1706 }
Mike Stump11289f42009-09-09 15:08:12 +00001707
Douglas Gregor1135c352009-08-06 05:28:30 +00001708 case NestedNameSpecifier::Global:
1709 // There is no meaningful transformation that one could perform on the
1710 // global scope.
1711 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001712
Douglas Gregor1135c352009-08-06 05:28:30 +00001713 case NestedNameSpecifier::TypeSpecWithTemplate:
1714 case NestedNameSpecifier::TypeSpec: {
1715 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001716 if (T.isNull())
1717 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001718
Douglas Gregor1135c352009-08-06 05:28:30 +00001719 if (!getDerived().AlwaysRebuild() &&
1720 Prefix == NNS->getPrefix() &&
1721 T == QualType(NNS->getAsType(), 0))
1722 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001723
1724 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1725 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregor1135c352009-08-06 05:28:30 +00001726 T);
1727 }
1728 }
Mike Stump11289f42009-09-09 15:08:12 +00001729
Douglas Gregor1135c352009-08-06 05:28:30 +00001730 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001731 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001732}
1733
1734template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001735DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001736TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
1737 SourceLocation Loc) {
1738 if (!Name)
1739 return Name;
1740
1741 switch (Name.getNameKind()) {
1742 case DeclarationName::Identifier:
1743 case DeclarationName::ObjCZeroArgSelector:
1744 case DeclarationName::ObjCOneArgSelector:
1745 case DeclarationName::ObjCMultiArgSelector:
1746 case DeclarationName::CXXOperatorName:
1747 case DeclarationName::CXXUsingDirective:
1748 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001749
Douglas Gregorf816bd72009-09-03 22:13:48 +00001750 case DeclarationName::CXXConstructorName:
1751 case DeclarationName::CXXDestructorName:
1752 case DeclarationName::CXXConversionFunctionName: {
1753 TemporaryBase Rebase(*this, Loc, Name);
1754 QualType T = getDerived().TransformType(Name.getCXXNameType());
1755 if (T.isNull())
1756 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001757
Douglas Gregorf816bd72009-09-03 22:13:48 +00001758 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001759 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001760 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001761 }
Mike Stump11289f42009-09-09 15:08:12 +00001762 }
1763
Douglas Gregorf816bd72009-09-03 22:13:48 +00001764 return DeclarationName();
1765}
1766
1767template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001768TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001769TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1770 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00001771 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001772 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001773 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1774 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1775 if (!NNS)
1776 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001777
Douglas Gregor71dc5092009-08-06 06:41:21 +00001778 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001779 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001780 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1781 if (!TransTemplate)
1782 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001783
Douglas Gregor71dc5092009-08-06 06:41:21 +00001784 if (!getDerived().AlwaysRebuild() &&
1785 NNS == QTN->getQualifier() &&
1786 TransTemplate == Template)
1787 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001788
Douglas Gregor71dc5092009-08-06 06:41:21 +00001789 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1790 TransTemplate);
1791 }
Mike Stump11289f42009-09-09 15:08:12 +00001792
Douglas Gregor71dc5092009-08-06 06:41:21 +00001793 OverloadedFunctionDecl *Ovl = QTN->getOverloadedFunctionDecl();
1794 assert(Ovl && "Not a template name or an overload set?");
Mike Stump11289f42009-09-09 15:08:12 +00001795 OverloadedFunctionDecl *TransOvl
Douglas Gregor71dc5092009-08-06 06:41:21 +00001796 = cast_or_null<OverloadedFunctionDecl>(getDerived().TransformDecl(Ovl));
1797 if (!TransOvl)
1798 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001799
Douglas Gregor71dc5092009-08-06 06:41:21 +00001800 if (!getDerived().AlwaysRebuild() &&
1801 NNS == QTN->getQualifier() &&
1802 TransOvl == Ovl)
1803 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001804
Douglas Gregor71dc5092009-08-06 06:41:21 +00001805 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1806 TransOvl);
1807 }
Mike Stump11289f42009-09-09 15:08:12 +00001808
Douglas Gregor71dc5092009-08-06 06:41:21 +00001809 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001810 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001811 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1812 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor308047d2009-09-09 00:23:06 +00001813 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001814 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001815
Douglas Gregor71dc5092009-08-06 06:41:21 +00001816 if (!getDerived().AlwaysRebuild() &&
1817 NNS == DTN->getQualifier())
1818 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001819
Douglas Gregor308047d2009-09-09 00:23:06 +00001820 return getDerived().RebuildTemplateName(NNS, *DTN->getName(), ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001821 }
Mike Stump11289f42009-09-09 15:08:12 +00001822
Douglas Gregor71dc5092009-08-06 06:41:21 +00001823 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001824 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001825 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1826 if (!TransTemplate)
1827 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001828
Douglas Gregor71dc5092009-08-06 06:41:21 +00001829 if (!getDerived().AlwaysRebuild() &&
1830 TransTemplate == Template)
1831 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001832
Douglas Gregor71dc5092009-08-06 06:41:21 +00001833 return TemplateName(TransTemplate);
1834 }
Mike Stump11289f42009-09-09 15:08:12 +00001835
Douglas Gregor71dc5092009-08-06 06:41:21 +00001836 OverloadedFunctionDecl *Ovl = Name.getAsOverloadedFunctionDecl();
1837 assert(Ovl && "Not a template name or an overload set?");
Mike Stump11289f42009-09-09 15:08:12 +00001838 OverloadedFunctionDecl *TransOvl
Douglas Gregor71dc5092009-08-06 06:41:21 +00001839 = cast_or_null<OverloadedFunctionDecl>(getDerived().TransformDecl(Ovl));
1840 if (!TransOvl)
1841 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001842
Douglas Gregor71dc5092009-08-06 06:41:21 +00001843 if (!getDerived().AlwaysRebuild() &&
1844 TransOvl == Ovl)
1845 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001846
Douglas Gregor71dc5092009-08-06 06:41:21 +00001847 return TemplateName(TransOvl);
1848}
1849
1850template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001851TemplateArgument
Douglas Gregore922c772009-08-04 22:27:00 +00001852TreeTransform<Derived>::TransformTemplateArgument(const TemplateArgument &Arg) {
1853 switch (Arg.getKind()) {
1854 case TemplateArgument::Null:
1855 case TemplateArgument::Integral:
1856 return Arg;
Mike Stump11289f42009-09-09 15:08:12 +00001857
Douglas Gregore922c772009-08-04 22:27:00 +00001858 case TemplateArgument::Type: {
1859 QualType T = getDerived().TransformType(Arg.getAsType());
1860 if (T.isNull())
1861 return TemplateArgument();
1862 return TemplateArgument(Arg.getLocation(), T);
1863 }
Mike Stump11289f42009-09-09 15:08:12 +00001864
Douglas Gregore922c772009-08-04 22:27:00 +00001865 case TemplateArgument::Declaration: {
1866 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
1867 if (!D)
1868 return TemplateArgument();
1869 return TemplateArgument(Arg.getLocation(), D);
1870 }
Mike Stump11289f42009-09-09 15:08:12 +00001871
Douglas Gregore922c772009-08-04 22:27:00 +00001872 case TemplateArgument::Expression: {
1873 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00001874 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00001875 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00001876
Douglas Gregore922c772009-08-04 22:27:00 +00001877 Sema::OwningExprResult E = getDerived().TransformExpr(Arg.getAsExpr());
1878 if (E.isInvalid())
1879 return TemplateArgument();
1880 return TemplateArgument(E.takeAs<Expr>());
1881 }
Mike Stump11289f42009-09-09 15:08:12 +00001882
Douglas Gregore922c772009-08-04 22:27:00 +00001883 case TemplateArgument::Pack: {
1884 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
1885 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00001886 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00001887 AEnd = Arg.pack_end();
1888 A != AEnd; ++A) {
1889 TemplateArgument TA = getDerived().TransformTemplateArgument(*A);
1890 if (TA.isNull())
1891 return TA;
Mike Stump11289f42009-09-09 15:08:12 +00001892
Douglas Gregore922c772009-08-04 22:27:00 +00001893 TransformedArgs.push_back(TA);
1894 }
1895 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00001896 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00001897 true);
1898 return Result;
1899 }
1900 }
Mike Stump11289f42009-09-09 15:08:12 +00001901
Douglas Gregore922c772009-08-04 22:27:00 +00001902 // Work around bogus GCC warning
1903 return TemplateArgument();
1904}
1905
Douglas Gregord6ff3322009-08-04 16:50:30 +00001906//===----------------------------------------------------------------------===//
1907// Type transformation
1908//===----------------------------------------------------------------------===//
1909
1910template<typename Derived>
1911QualType TreeTransform<Derived>::TransformType(QualType T) {
1912 if (getDerived().AlreadyTransformed(T))
1913 return T;
Mike Stump11289f42009-09-09 15:08:12 +00001914
John McCall8ccfcb52009-09-24 19:53:00 +00001915 QualifierCollector Qs;
1916 const Type *Ty = Qs.strip(T);
1917
Douglas Gregord6ff3322009-08-04 16:50:30 +00001918 QualType Result;
John McCall8ccfcb52009-09-24 19:53:00 +00001919 switch (Ty->getTypeClass()) {
Mike Stump11289f42009-09-09 15:08:12 +00001920#define ABSTRACT_TYPE(CLASS, PARENT)
Douglas Gregord6ff3322009-08-04 16:50:30 +00001921#define TYPE(CLASS, PARENT) \
1922 case Type::CLASS: \
1923 Result = getDerived().Transform##CLASS##Type( \
John McCall8ccfcb52009-09-24 19:53:00 +00001924 static_cast<const CLASS##Type*>(Ty)); \
Douglas Gregord6ff3322009-08-04 16:50:30 +00001925 break;
Mike Stump11289f42009-09-09 15:08:12 +00001926#include "clang/AST/TypeNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00001927 }
Mike Stump11289f42009-09-09 15:08:12 +00001928
Douglas Gregord6ff3322009-08-04 16:50:30 +00001929 if (Result.isNull() || T == Result)
1930 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00001931
John McCall8ccfcb52009-09-24 19:53:00 +00001932 return getDerived().AddTypeQualifiers(Result, Qs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00001933}
Mike Stump11289f42009-09-09 15:08:12 +00001934
Douglas Gregord6ff3322009-08-04 16:50:30 +00001935template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001936QualType
John McCall8ccfcb52009-09-24 19:53:00 +00001937TreeTransform<Derived>::AddTypeQualifiers(QualType T, Qualifiers Quals) {
1938 if (!Quals.empty() && !T->isFunctionType() && !T->isReferenceType())
1939 return SemaRef.Context.getQualifiedType(T, Quals);
Mike Stump11289f42009-09-09 15:08:12 +00001940
Douglas Gregord6ff3322009-08-04 16:50:30 +00001941 return T;
1942}
Argyrios Kyrtzidise9189262009-08-19 01:28:17 +00001943
Douglas Gregord6ff3322009-08-04 16:50:30 +00001944template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001945QualType TreeTransform<Derived>::TransformBuiltinType(const BuiltinType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00001946 // Nothing to do
Mike Stump11289f42009-09-09 15:08:12 +00001947 return QualType(T, 0);
Douglas Gregord6ff3322009-08-04 16:50:30 +00001948}
Mike Stump11289f42009-09-09 15:08:12 +00001949
Douglas Gregord6ff3322009-08-04 16:50:30 +00001950template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001951QualType TreeTransform<Derived>::TransformFixedWidthIntType(
1952 const FixedWidthIntType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00001953 // FIXME: Implement
Mike Stump11289f42009-09-09 15:08:12 +00001954 return QualType(T, 0);
Douglas Gregord6ff3322009-08-04 16:50:30 +00001955}
Mike Stump11289f42009-09-09 15:08:12 +00001956
1957template<typename Derived>
1958QualType TreeTransform<Derived>::TransformComplexType(const ComplexType *T) {
1959 // FIXME: Implement
1960 return QualType(T, 0);
1961}
1962
1963template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00001964QualType TreeTransform<Derived>::TransformPointerType(const PointerType *T) {
1965 QualType PointeeType = getDerived().TransformType(T->getPointeeType());
1966 if (PointeeType.isNull())
1967 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00001968
Douglas Gregord6ff3322009-08-04 16:50:30 +00001969 if (!getDerived().AlwaysRebuild() &&
1970 PointeeType == T->getPointeeType())
1971 return QualType(T, 0);
1972
1973 return getDerived().RebuildPointerType(PointeeType);
1974}
Mike Stump11289f42009-09-09 15:08:12 +00001975
1976template<typename Derived>
1977QualType
1978TreeTransform<Derived>::TransformBlockPointerType(const BlockPointerType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00001979 QualType PointeeType = getDerived().TransformType(T->getPointeeType());
1980 if (PointeeType.isNull())
1981 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00001982
Douglas Gregord6ff3322009-08-04 16:50:30 +00001983 if (!getDerived().AlwaysRebuild() &&
1984 PointeeType == T->getPointeeType())
1985 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00001986
Douglas Gregord6ff3322009-08-04 16:50:30 +00001987 return getDerived().RebuildBlockPointerType(PointeeType);
1988}
1989
Mike Stump11289f42009-09-09 15:08:12 +00001990template<typename Derived>
1991QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00001992TreeTransform<Derived>::TransformLValueReferenceType(
Mike Stump11289f42009-09-09 15:08:12 +00001993 const LValueReferenceType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00001994 QualType PointeeType = getDerived().TransformType(T->getPointeeType());
1995 if (PointeeType.isNull())
1996 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00001997
Douglas Gregord6ff3322009-08-04 16:50:30 +00001998 if (!getDerived().AlwaysRebuild() &&
1999 PointeeType == T->getPointeeType())
2000 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002001
Douglas Gregord6ff3322009-08-04 16:50:30 +00002002 return getDerived().RebuildLValueReferenceType(PointeeType);
2003}
2004
Mike Stump11289f42009-09-09 15:08:12 +00002005template<typename Derived>
2006QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00002007TreeTransform<Derived>::TransformRValueReferenceType(
Mike Stump11289f42009-09-09 15:08:12 +00002008 const RValueReferenceType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002009 QualType PointeeType = getDerived().TransformType(T->getPointeeType());
2010 if (PointeeType.isNull())
2011 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002012
Douglas Gregord6ff3322009-08-04 16:50:30 +00002013 if (!getDerived().AlwaysRebuild() &&
2014 PointeeType == T->getPointeeType())
2015 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002016
Douglas Gregord6ff3322009-08-04 16:50:30 +00002017 return getDerived().RebuildRValueReferenceType(PointeeType);
2018}
Mike Stump11289f42009-09-09 15:08:12 +00002019
Douglas Gregord6ff3322009-08-04 16:50:30 +00002020template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002021QualType
2022TreeTransform<Derived>::TransformMemberPointerType(const MemberPointerType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002023 QualType PointeeType = getDerived().TransformType(T->getPointeeType());
2024 if (PointeeType.isNull())
2025 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002026
Douglas Gregord6ff3322009-08-04 16:50:30 +00002027 QualType ClassType = getDerived().TransformType(QualType(T->getClass(), 0));
2028 if (ClassType.isNull())
2029 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002030
Douglas Gregord6ff3322009-08-04 16:50:30 +00002031 if (!getDerived().AlwaysRebuild() &&
2032 PointeeType == T->getPointeeType() &&
2033 ClassType == QualType(T->getClass(), 0))
2034 return QualType(T, 0);
2035
2036 return getDerived().RebuildMemberPointerType(PointeeType, ClassType);
2037}
2038
Mike Stump11289f42009-09-09 15:08:12 +00002039template<typename Derived>
2040QualType
2041TreeTransform<Derived>::TransformConstantArrayType(const ConstantArrayType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002042 QualType ElementType = getDerived().TransformType(T->getElementType());
2043 if (ElementType.isNull())
2044 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002045
Douglas Gregord6ff3322009-08-04 16:50:30 +00002046 if (!getDerived().AlwaysRebuild() &&
2047 ElementType == T->getElementType())
2048 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002049
2050 return getDerived().RebuildConstantArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002051 T->getSizeModifier(),
2052 T->getSize(),
John McCall8ccfcb52009-09-24 19:53:00 +00002053 T->getIndexTypeCVRQualifiers());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002054}
Mike Stump11289f42009-09-09 15:08:12 +00002055
Douglas Gregord6ff3322009-08-04 16:50:30 +00002056template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002057QualType TreeTransform<Derived>::TransformIncompleteArrayType(
Mike Stump11289f42009-09-09 15:08:12 +00002058 const IncompleteArrayType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002059 QualType ElementType = getDerived().TransformType(T->getElementType());
2060 if (ElementType.isNull())
2061 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002062
Douglas Gregord6ff3322009-08-04 16:50:30 +00002063 if (!getDerived().AlwaysRebuild() &&
2064 ElementType == T->getElementType())
2065 return QualType(T, 0);
2066
2067 return getDerived().RebuildIncompleteArrayType(ElementType,
2068 T->getSizeModifier(),
John McCall8ccfcb52009-09-24 19:53:00 +00002069 T->getIndexTypeCVRQualifiers());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002070}
Mike Stump11289f42009-09-09 15:08:12 +00002071
Douglas Gregord6ff3322009-08-04 16:50:30 +00002072template<typename Derived>
2073QualType TreeTransform<Derived>::TransformVariableArrayType(
Mike Stump11289f42009-09-09 15:08:12 +00002074 const VariableArrayType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002075 QualType ElementType = getDerived().TransformType(T->getElementType());
2076 if (ElementType.isNull())
2077 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002078
Douglas Gregore922c772009-08-04 22:27:00 +00002079 // Array bounds are not potentially evaluated contexts
2080 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2081
Douglas Gregord6ff3322009-08-04 16:50:30 +00002082 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2083 if (Size.isInvalid())
2084 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002085
Douglas Gregord6ff3322009-08-04 16:50:30 +00002086 if (!getDerived().AlwaysRebuild() &&
2087 ElementType == T->getElementType() &&
2088 Size.get() == T->getSizeExpr()) {
2089 Size.take();
2090 return QualType(T, 0);
2091 }
Mike Stump11289f42009-09-09 15:08:12 +00002092
2093 return getDerived().RebuildVariableArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002094 T->getSizeModifier(),
2095 move(Size),
John McCall8ccfcb52009-09-24 19:53:00 +00002096 T->getIndexTypeCVRQualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002097 T->getBracketsRange());
2098}
Mike Stump11289f42009-09-09 15:08:12 +00002099
2100template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002101QualType TreeTransform<Derived>::TransformDependentSizedArrayType(
Mike Stump11289f42009-09-09 15:08:12 +00002102 const DependentSizedArrayType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002103 QualType ElementType = getDerived().TransformType(T->getElementType());
2104 if (ElementType.isNull())
2105 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002106
Douglas Gregore922c772009-08-04 22:27:00 +00002107 // Array bounds are not potentially evaluated contexts
2108 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002109
Douglas Gregord6ff3322009-08-04 16:50:30 +00002110 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2111 if (Size.isInvalid())
2112 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002113
Douglas Gregord6ff3322009-08-04 16:50:30 +00002114 if (!getDerived().AlwaysRebuild() &&
2115 ElementType == T->getElementType() &&
2116 Size.get() == T->getSizeExpr()) {
2117 Size.take();
2118 return QualType(T, 0);
2119 }
Mike Stump11289f42009-09-09 15:08:12 +00002120
2121 return getDerived().RebuildDependentSizedArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002122 T->getSizeModifier(),
2123 move(Size),
John McCall8ccfcb52009-09-24 19:53:00 +00002124 T->getIndexTypeCVRQualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002125 T->getBracketsRange());
2126}
Mike Stump11289f42009-09-09 15:08:12 +00002127
2128template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002129QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
Mike Stump11289f42009-09-09 15:08:12 +00002130 const DependentSizedExtVectorType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002131 QualType ElementType = getDerived().TransformType(T->getElementType());
2132 if (ElementType.isNull())
2133 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002134
Douglas Gregore922c772009-08-04 22:27:00 +00002135 // Vector sizes are not potentially evaluated contexts
2136 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2137
Douglas Gregord6ff3322009-08-04 16:50:30 +00002138 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2139 if (Size.isInvalid())
2140 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002141
Douglas Gregord6ff3322009-08-04 16:50:30 +00002142 if (!getDerived().AlwaysRebuild() &&
2143 ElementType == T->getElementType() &&
2144 Size.get() == T->getSizeExpr()) {
2145 Size.take();
2146 return QualType(T, 0);
2147 }
Mike Stump11289f42009-09-09 15:08:12 +00002148
2149 return getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002150 move(Size),
2151 T->getAttributeLoc());
2152}
Mike Stump11289f42009-09-09 15:08:12 +00002153
2154template<typename Derived>
2155QualType TreeTransform<Derived>::TransformVectorType(const VectorType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002156 QualType ElementType = getDerived().TransformType(T->getElementType());
2157 if (ElementType.isNull())
2158 return QualType();
2159
2160 if (!getDerived().AlwaysRebuild() &&
2161 ElementType == T->getElementType())
2162 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002163
Douglas Gregord6ff3322009-08-04 16:50:30 +00002164 return getDerived().RebuildVectorType(ElementType, T->getNumElements());
2165}
Mike Stump11289f42009-09-09 15:08:12 +00002166
2167template<typename Derived>
2168QualType
2169TreeTransform<Derived>::TransformExtVectorType(const ExtVectorType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002170 QualType ElementType = getDerived().TransformType(T->getElementType());
2171 if (ElementType.isNull())
2172 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002173
Douglas Gregord6ff3322009-08-04 16:50:30 +00002174 if (!getDerived().AlwaysRebuild() &&
2175 ElementType == T->getElementType())
2176 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002177
Douglas Gregord6ff3322009-08-04 16:50:30 +00002178 return getDerived().RebuildExtVectorType(ElementType, T->getNumElements(),
2179 /*FIXME*/SourceLocation());
2180}
2181
Mike Stump11289f42009-09-09 15:08:12 +00002182template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002183QualType TreeTransform<Derived>::TransformFunctionProtoType(
Mike Stump11289f42009-09-09 15:08:12 +00002184 const FunctionProtoType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002185 QualType ResultType = getDerived().TransformType(T->getResultType());
2186 if (ResultType.isNull())
2187 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002188
Douglas Gregord6ff3322009-08-04 16:50:30 +00002189 llvm::SmallVector<QualType, 4> ParamTypes;
2190 for (FunctionProtoType::arg_type_iterator Param = T->arg_type_begin(),
Mike Stump11289f42009-09-09 15:08:12 +00002191 ParamEnd = T->arg_type_end();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002192 Param != ParamEnd; ++Param) {
2193 QualType P = getDerived().TransformType(*Param);
2194 if (P.isNull())
2195 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002196
Douglas Gregord6ff3322009-08-04 16:50:30 +00002197 ParamTypes.push_back(P);
2198 }
Mike Stump11289f42009-09-09 15:08:12 +00002199
Douglas Gregord6ff3322009-08-04 16:50:30 +00002200 if (!getDerived().AlwaysRebuild() &&
2201 ResultType == T->getResultType() &&
2202 std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin()))
2203 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002204
2205 return getDerived().RebuildFunctionProtoType(ResultType, ParamTypes.data(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002206 ParamTypes.size(), T->isVariadic(),
2207 T->getTypeQuals());
2208}
Mike Stump11289f42009-09-09 15:08:12 +00002209
Douglas Gregord6ff3322009-08-04 16:50:30 +00002210template<typename Derived>
2211QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
Mike Stump11289f42009-09-09 15:08:12 +00002212 const FunctionNoProtoType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002213 // FIXME: Implement
Mike Stump11289f42009-09-09 15:08:12 +00002214 return QualType(T, 0);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002215}
Mike Stump11289f42009-09-09 15:08:12 +00002216
Douglas Gregord6ff3322009-08-04 16:50:30 +00002217template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002218QualType TreeTransform<Derived>::TransformTypedefType(const TypedefType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002219 TypedefDecl *Typedef
2220 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2221 if (!Typedef)
2222 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002223
Douglas Gregord6ff3322009-08-04 16:50:30 +00002224 if (!getDerived().AlwaysRebuild() &&
2225 Typedef == T->getDecl())
2226 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002227
Douglas Gregord6ff3322009-08-04 16:50:30 +00002228 return getDerived().RebuildTypedefType(Typedef);
2229}
Mike Stump11289f42009-09-09 15:08:12 +00002230
Douglas Gregord6ff3322009-08-04 16:50:30 +00002231template<typename Derived>
2232QualType TreeTransform<Derived>::TransformTypeOfExprType(
Mike Stump11289f42009-09-09 15:08:12 +00002233 const TypeOfExprType *T) {
Douglas Gregore922c772009-08-04 22:27:00 +00002234 // typeof expressions are not potentially evaluated contexts
2235 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002236
Douglas Gregord6ff3322009-08-04 16:50:30 +00002237 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2238 if (E.isInvalid())
2239 return QualType();
2240
2241 if (!getDerived().AlwaysRebuild() &&
2242 E.get() == T->getUnderlyingExpr()) {
2243 E.take();
2244 return QualType(T, 0);
2245 }
Mike Stump11289f42009-09-09 15:08:12 +00002246
Douglas Gregord6ff3322009-08-04 16:50:30 +00002247 return getDerived().RebuildTypeOfExprType(move(E));
2248}
Mike Stump11289f42009-09-09 15:08:12 +00002249
2250template<typename Derived>
2251QualType TreeTransform<Derived>::TransformTypeOfType(const TypeOfType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002252 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2253 if (Underlying.isNull())
2254 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002255
Douglas Gregord6ff3322009-08-04 16:50:30 +00002256 if (!getDerived().AlwaysRebuild() &&
2257 Underlying == T->getUnderlyingType())
2258 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002259
Douglas Gregord6ff3322009-08-04 16:50:30 +00002260 return getDerived().RebuildTypeOfType(Underlying);
2261}
Mike Stump11289f42009-09-09 15:08:12 +00002262
2263template<typename Derived>
2264QualType TreeTransform<Derived>::TransformDecltypeType(const DecltypeType *T) {
Douglas Gregore922c772009-08-04 22:27:00 +00002265 // decltype expressions are not potentially evaluated contexts
2266 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002267
Douglas Gregord6ff3322009-08-04 16:50:30 +00002268 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2269 if (E.isInvalid())
2270 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002271
Douglas Gregord6ff3322009-08-04 16:50:30 +00002272 if (!getDerived().AlwaysRebuild() &&
2273 E.get() == T->getUnderlyingExpr()) {
2274 E.take();
2275 return QualType(T, 0);
2276 }
Mike Stump11289f42009-09-09 15:08:12 +00002277
Douglas Gregord6ff3322009-08-04 16:50:30 +00002278 return getDerived().RebuildDecltypeType(move(E));
2279}
2280
2281template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002282QualType TreeTransform<Derived>::TransformRecordType(const RecordType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002283 RecordDecl *Record
2284 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
2285 if (!Record)
2286 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002287
Douglas Gregord6ff3322009-08-04 16:50:30 +00002288 if (!getDerived().AlwaysRebuild() &&
2289 Record == T->getDecl())
2290 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002291
Douglas Gregord6ff3322009-08-04 16:50:30 +00002292 return getDerived().RebuildRecordType(Record);
2293}
Mike Stump11289f42009-09-09 15:08:12 +00002294
2295template<typename Derived>
2296QualType TreeTransform<Derived>::TransformEnumType(const EnumType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002297 EnumDecl *Enum
2298 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
2299 if (!Enum)
2300 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002301
Douglas Gregord6ff3322009-08-04 16:50:30 +00002302 if (!getDerived().AlwaysRebuild() &&
2303 Enum == T->getDecl())
2304 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002305
Douglas Gregord6ff3322009-08-04 16:50:30 +00002306 return getDerived().RebuildEnumType(Enum);
2307}
John McCallfcc33b02009-09-05 00:15:47 +00002308
2309template <typename Derived>
2310QualType TreeTransform<Derived>::TransformElaboratedType(
2311 const ElaboratedType *T) {
2312 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2313 if (Underlying.isNull())
2314 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002315
John McCallfcc33b02009-09-05 00:15:47 +00002316 if (!getDerived().AlwaysRebuild() &&
2317 Underlying == T->getUnderlyingType())
2318 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002319
John McCallfcc33b02009-09-05 00:15:47 +00002320 return getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2321}
Mike Stump11289f42009-09-09 15:08:12 +00002322
2323
Douglas Gregord6ff3322009-08-04 16:50:30 +00002324template<typename Derived>
2325QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
Mike Stump11289f42009-09-09 15:08:12 +00002326 const TemplateTypeParmType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002327 // Nothing to do
Mike Stump11289f42009-09-09 15:08:12 +00002328 return QualType(T, 0);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002329}
2330
Mike Stump11289f42009-09-09 15:08:12 +00002331template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002332QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
2333 const SubstTemplateTypeParmType *T) {
2334 // Nothing to do
2335 return QualType(T, 0);
2336}
2337
2338template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002339QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
Mike Stump11289f42009-09-09 15:08:12 +00002340 const TemplateSpecializationType *T) {
2341 TemplateName Template
Douglas Gregord6ff3322009-08-04 16:50:30 +00002342 = getDerived().TransformTemplateName(T->getTemplateName());
2343 if (Template.isNull())
2344 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002345
Douglas Gregord6ff3322009-08-04 16:50:30 +00002346 llvm::SmallVector<TemplateArgument, 4> NewTemplateArgs;
2347 NewTemplateArgs.reserve(T->getNumArgs());
2348 for (TemplateSpecializationType::iterator Arg = T->begin(), ArgEnd = T->end();
2349 Arg != ArgEnd; ++Arg) {
2350 TemplateArgument NewArg = getDerived().TransformTemplateArgument(*Arg);
2351 if (NewArg.isNull())
2352 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002353
Douglas Gregord6ff3322009-08-04 16:50:30 +00002354 NewTemplateArgs.push_back(NewArg);
2355 }
Mike Stump11289f42009-09-09 15:08:12 +00002356
Douglas Gregord6ff3322009-08-04 16:50:30 +00002357 // FIXME: early abort if all of the template arguments and such are the
2358 // same.
Mike Stump11289f42009-09-09 15:08:12 +00002359
Douglas Gregord6ff3322009-08-04 16:50:30 +00002360 // FIXME: We're missing the locations of the template name, '<', and '>'.
2361 return getDerived().RebuildTemplateSpecializationType(Template,
2362 NewTemplateArgs.data(),
2363 NewTemplateArgs.size());
2364}
Mike Stump11289f42009-09-09 15:08:12 +00002365
2366template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002367QualType TreeTransform<Derived>::TransformQualifiedNameType(
2368 const QualifiedNameType *T) {
2369 NestedNameSpecifier *NNS
2370 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2371 SourceRange());
2372 if (!NNS)
2373 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002374
Douglas Gregord6ff3322009-08-04 16:50:30 +00002375 QualType Named = getDerived().TransformType(T->getNamedType());
2376 if (Named.isNull())
2377 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002378
Douglas Gregord6ff3322009-08-04 16:50:30 +00002379 if (!getDerived().AlwaysRebuild() &&
2380 NNS == T->getQualifier() &&
2381 Named == T->getNamedType())
2382 return QualType(T, 0);
2383
2384 return getDerived().RebuildQualifiedNameType(NNS, Named);
2385}
Mike Stump11289f42009-09-09 15:08:12 +00002386
2387template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002388QualType TreeTransform<Derived>::TransformTypenameType(const TypenameType *T) {
2389 NestedNameSpecifier *NNS
2390 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregor15acfb92009-08-06 16:20:37 +00002391 SourceRange(/*FIXME:*/getDerived().getBaseLocation()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002392 if (!NNS)
2393 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002394
Douglas Gregord6ff3322009-08-04 16:50:30 +00002395 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002396 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002397 = getDerived().TransformType(QualType(TemplateId, 0));
2398 if (NewTemplateId.isNull())
2399 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002400
Douglas Gregord6ff3322009-08-04 16:50:30 +00002401 if (!getDerived().AlwaysRebuild() &&
2402 NNS == T->getQualifier() &&
2403 NewTemplateId == QualType(TemplateId, 0))
2404 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002405
Douglas Gregord6ff3322009-08-04 16:50:30 +00002406 return getDerived().RebuildTypenameType(NNS, NewTemplateId);
2407 }
2408
2409 return getDerived().RebuildTypenameType(NNS, T->getIdentifier());
2410}
Mike Stump11289f42009-09-09 15:08:12 +00002411
Douglas Gregord6ff3322009-08-04 16:50:30 +00002412template<typename Derived>
2413QualType TreeTransform<Derived>::TransformObjCInterfaceType(
Mike Stump11289f42009-09-09 15:08:12 +00002414 const ObjCInterfaceType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002415 // FIXME: Implement
Mike Stump11289f42009-09-09 15:08:12 +00002416 return QualType(T, 0);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002417}
Mike Stump11289f42009-09-09 15:08:12 +00002418
2419template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002420QualType TreeTransform<Derived>::TransformObjCObjectPointerType(
Mike Stump11289f42009-09-09 15:08:12 +00002421 const ObjCObjectPointerType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002422 // FIXME: Implement
Mike Stump11289f42009-09-09 15:08:12 +00002423 return QualType(T, 0);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002424}
2425
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00002426template<typename Derived>
2427QualType TreeTransform<Derived>::TransformObjCProtocolListType(
2428 const ObjCProtocolListType *T) {
2429 assert(false && "Should not see ObjCProtocolList types");
2430 return QualType(T, 0);
2431}
2432
Douglas Gregord6ff3322009-08-04 16:50:30 +00002433//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00002434// Statement transformation
2435//===----------------------------------------------------------------------===//
2436template<typename Derived>
2437Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002438TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2439 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002440}
2441
2442template<typename Derived>
2443Sema::OwningStmtResult
2444TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2445 return getDerived().TransformCompoundStmt(S, false);
2446}
2447
2448template<typename Derived>
2449Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002450TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00002451 bool IsStmtExpr) {
2452 bool SubStmtChanged = false;
2453 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
2454 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
2455 B != BEnd; ++B) {
2456 OwningStmtResult Result = getDerived().TransformStmt(*B);
2457 if (Result.isInvalid())
2458 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002459
Douglas Gregorebe10102009-08-20 07:17:43 +00002460 SubStmtChanged = SubStmtChanged || Result.get() != *B;
2461 Statements.push_back(Result.takeAs<Stmt>());
2462 }
Mike Stump11289f42009-09-09 15:08:12 +00002463
Douglas Gregorebe10102009-08-20 07:17:43 +00002464 if (!getDerived().AlwaysRebuild() &&
2465 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00002466 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002467
2468 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
2469 move_arg(Statements),
2470 S->getRBracLoc(),
2471 IsStmtExpr);
2472}
Mike Stump11289f42009-09-09 15:08:12 +00002473
Douglas Gregorebe10102009-08-20 07:17:43 +00002474template<typename Derived>
2475Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002476TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002477 // The case value expressions are not potentially evaluated.
2478 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002479
Douglas Gregorebe10102009-08-20 07:17:43 +00002480 // Transform the left-hand case value.
2481 OwningExprResult LHS = getDerived().TransformExpr(S->getLHS());
2482 if (LHS.isInvalid())
2483 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002484
Douglas Gregorebe10102009-08-20 07:17:43 +00002485 // Transform the right-hand case value (for the GNU case-range extension).
2486 OwningExprResult RHS = getDerived().TransformExpr(S->getRHS());
2487 if (RHS.isInvalid())
2488 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002489
Douglas Gregorebe10102009-08-20 07:17:43 +00002490 // Build the case statement.
2491 // Case statements are always rebuilt so that they will attached to their
2492 // transformed switch statement.
2493 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
2494 move(LHS),
2495 S->getEllipsisLoc(),
2496 move(RHS),
2497 S->getColonLoc());
2498 if (Case.isInvalid())
2499 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002500
Douglas Gregorebe10102009-08-20 07:17:43 +00002501 // Transform the statement following the case
2502 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
2503 if (SubStmt.isInvalid())
2504 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002505
Douglas Gregorebe10102009-08-20 07:17:43 +00002506 // Attach the body to the case statement
2507 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
2508}
2509
2510template<typename Derived>
2511Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002512TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002513 // Transform the statement following the default case
2514 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
2515 if (SubStmt.isInvalid())
2516 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002517
Douglas Gregorebe10102009-08-20 07:17:43 +00002518 // Default statements are always rebuilt
2519 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
2520 move(SubStmt));
2521}
Mike Stump11289f42009-09-09 15:08:12 +00002522
Douglas Gregorebe10102009-08-20 07:17:43 +00002523template<typename Derived>
2524Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002525TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002526 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
2527 if (SubStmt.isInvalid())
2528 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002529
Douglas Gregorebe10102009-08-20 07:17:43 +00002530 // FIXME: Pass the real colon location in.
2531 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
2532 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
2533 move(SubStmt));
2534}
Mike Stump11289f42009-09-09 15:08:12 +00002535
Douglas Gregorebe10102009-08-20 07:17:43 +00002536template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002537Sema::OwningStmtResult
2538TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002539 // Transform the condition
2540 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
2541 if (Cond.isInvalid())
2542 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002543
Douglas Gregorebe10102009-08-20 07:17:43 +00002544 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00002545
Douglas Gregorebe10102009-08-20 07:17:43 +00002546 // Transform the "then" branch.
2547 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
2548 if (Then.isInvalid())
2549 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002550
Douglas Gregorebe10102009-08-20 07:17:43 +00002551 // Transform the "else" branch.
2552 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
2553 if (Else.isInvalid())
2554 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002555
Douglas Gregorebe10102009-08-20 07:17:43 +00002556 if (!getDerived().AlwaysRebuild() &&
2557 FullCond->get() == S->getCond() &&
2558 Then.get() == S->getThen() &&
2559 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00002560 return SemaRef.Owned(S->Retain());
2561
Douglas Gregorebe10102009-08-20 07:17:43 +00002562 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00002563 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00002564}
2565
2566template<typename Derived>
2567Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002568TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002569 // Transform the condition.
2570 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
2571 if (Cond.isInvalid())
2572 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002573
Douglas Gregorebe10102009-08-20 07:17:43 +00002574 // Rebuild the switch statement.
2575 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(move(Cond));
2576 if (Switch.isInvalid())
2577 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002578
Douglas Gregorebe10102009-08-20 07:17:43 +00002579 // Transform the body of the switch statement.
2580 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
2581 if (Body.isInvalid())
2582 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002583
Douglas Gregorebe10102009-08-20 07:17:43 +00002584 // Complete the switch statement.
2585 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
2586 move(Body));
2587}
Mike Stump11289f42009-09-09 15:08:12 +00002588
Douglas Gregorebe10102009-08-20 07:17:43 +00002589template<typename Derived>
2590Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002591TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002592 // Transform the condition
2593 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
2594 if (Cond.isInvalid())
2595 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002596
Douglas Gregorebe10102009-08-20 07:17:43 +00002597 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00002598
Douglas Gregorebe10102009-08-20 07:17:43 +00002599 // Transform the body
2600 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
2601 if (Body.isInvalid())
2602 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002603
Douglas Gregorebe10102009-08-20 07:17:43 +00002604 if (!getDerived().AlwaysRebuild() &&
2605 FullCond->get() == S->getCond() &&
2606 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00002607 return SemaRef.Owned(S->Retain());
2608
Douglas Gregorebe10102009-08-20 07:17:43 +00002609 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, move(Body));
2610}
Mike Stump11289f42009-09-09 15:08:12 +00002611
Douglas Gregorebe10102009-08-20 07:17:43 +00002612template<typename Derived>
2613Sema::OwningStmtResult
2614TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
2615 // Transform the condition
2616 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
2617 if (Cond.isInvalid())
2618 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002619
Douglas Gregorebe10102009-08-20 07:17:43 +00002620 // Transform the body
2621 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
2622 if (Body.isInvalid())
2623 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002624
Douglas Gregorebe10102009-08-20 07:17:43 +00002625 if (!getDerived().AlwaysRebuild() &&
2626 Cond.get() == S->getCond() &&
2627 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00002628 return SemaRef.Owned(S->Retain());
2629
Douglas Gregorebe10102009-08-20 07:17:43 +00002630 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
2631 /*FIXME:*/S->getWhileLoc(), move(Cond),
2632 S->getRParenLoc());
2633}
Mike Stump11289f42009-09-09 15:08:12 +00002634
Douglas Gregorebe10102009-08-20 07:17:43 +00002635template<typename Derived>
2636Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002637TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002638 // Transform the initialization statement
2639 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
2640 if (Init.isInvalid())
2641 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002642
Douglas Gregorebe10102009-08-20 07:17:43 +00002643 // Transform the condition
2644 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
2645 if (Cond.isInvalid())
2646 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002647
Douglas Gregorebe10102009-08-20 07:17:43 +00002648 // Transform the increment
2649 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
2650 if (Inc.isInvalid())
2651 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002652
Douglas Gregorebe10102009-08-20 07:17:43 +00002653 // Transform the body
2654 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
2655 if (Body.isInvalid())
2656 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002657
Douglas Gregorebe10102009-08-20 07:17:43 +00002658 if (!getDerived().AlwaysRebuild() &&
2659 Init.get() == S->getInit() &&
2660 Cond.get() == S->getCond() &&
2661 Inc.get() == S->getInc() &&
2662 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00002663 return SemaRef.Owned(S->Retain());
2664
Douglas Gregorebe10102009-08-20 07:17:43 +00002665 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
2666 move(Init), move(Cond), move(Inc),
2667 S->getRParenLoc(), move(Body));
2668}
2669
2670template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002671Sema::OwningStmtResult
2672TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002673 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00002674 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00002675 S->getLabel());
2676}
2677
2678template<typename Derived>
2679Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002680TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002681 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
2682 if (Target.isInvalid())
2683 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002684
Douglas Gregorebe10102009-08-20 07:17:43 +00002685 if (!getDerived().AlwaysRebuild() &&
2686 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00002687 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002688
2689 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
2690 move(Target));
2691}
2692
2693template<typename Derived>
2694Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002695TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
2696 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002697}
Mike Stump11289f42009-09-09 15:08:12 +00002698
Douglas Gregorebe10102009-08-20 07:17:43 +00002699template<typename Derived>
2700Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002701TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
2702 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002703}
Mike Stump11289f42009-09-09 15:08:12 +00002704
Douglas Gregorebe10102009-08-20 07:17:43 +00002705template<typename Derived>
2706Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002707TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002708 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
2709 if (Result.isInvalid())
2710 return SemaRef.StmtError();
2711
Mike Stump11289f42009-09-09 15:08:12 +00002712 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00002713 // to tell whether the return type of the function has changed.
2714 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
2715}
Mike Stump11289f42009-09-09 15:08:12 +00002716
Douglas Gregorebe10102009-08-20 07:17:43 +00002717template<typename Derived>
2718Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002719TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002720 bool DeclChanged = false;
2721 llvm::SmallVector<Decl *, 4> Decls;
2722 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
2723 D != DEnd; ++D) {
2724 Decl *Transformed = getDerived().TransformDefinition(*D);
2725 if (!Transformed)
2726 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002727
Douglas Gregorebe10102009-08-20 07:17:43 +00002728 if (Transformed != *D)
2729 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00002730
Douglas Gregorebe10102009-08-20 07:17:43 +00002731 Decls.push_back(Transformed);
2732 }
Mike Stump11289f42009-09-09 15:08:12 +00002733
Douglas Gregorebe10102009-08-20 07:17:43 +00002734 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00002735 return SemaRef.Owned(S->Retain());
2736
2737 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00002738 S->getStartLoc(), S->getEndLoc());
2739}
Mike Stump11289f42009-09-09 15:08:12 +00002740
Douglas Gregorebe10102009-08-20 07:17:43 +00002741template<typename Derived>
2742Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002743TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002744 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00002745 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002746}
2747
2748template<typename Derived>
2749Sema::OwningStmtResult
2750TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
2751 // FIXME: Implement!
2752 assert(false && "Inline assembly cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00002753 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002754}
2755
2756
2757template<typename Derived>
2758Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002759TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002760 // FIXME: Implement this
2761 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00002762 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002763}
Mike Stump11289f42009-09-09 15:08:12 +00002764
Douglas Gregorebe10102009-08-20 07:17:43 +00002765template<typename Derived>
2766Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002767TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002768 // FIXME: Implement this
2769 assert(false && "Cannot transform an Objective-C @catch statement");
2770 return SemaRef.Owned(S->Retain());
2771}
Mike Stump11289f42009-09-09 15:08:12 +00002772
Douglas Gregorebe10102009-08-20 07:17:43 +00002773template<typename Derived>
2774Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002775TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002776 // FIXME: Implement this
2777 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00002778 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002779}
Mike Stump11289f42009-09-09 15:08:12 +00002780
Douglas Gregorebe10102009-08-20 07:17:43 +00002781template<typename Derived>
2782Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002783TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002784 // FIXME: Implement this
2785 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00002786 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002787}
Mike Stump11289f42009-09-09 15:08:12 +00002788
Douglas Gregorebe10102009-08-20 07:17:43 +00002789template<typename Derived>
2790Sema::OwningStmtResult
2791TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00002792 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002793 // FIXME: Implement this
2794 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00002795 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002796}
2797
2798template<typename Derived>
2799Sema::OwningStmtResult
2800TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00002801 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002802 // FIXME: Implement this
2803 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00002804 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002805}
2806
2807
2808template<typename Derived>
2809Sema::OwningStmtResult
2810TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
2811 // Transform the exception declaration, if any.
2812 VarDecl *Var = 0;
2813 if (S->getExceptionDecl()) {
2814 VarDecl *ExceptionDecl = S->getExceptionDecl();
2815 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
2816 ExceptionDecl->getDeclName());
2817
2818 QualType T = getDerived().TransformType(ExceptionDecl->getType());
2819 if (T.isNull())
2820 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002821
Douglas Gregorebe10102009-08-20 07:17:43 +00002822 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
2823 T,
2824 ExceptionDecl->getDeclaratorInfo(),
2825 ExceptionDecl->getIdentifier(),
2826 ExceptionDecl->getLocation(),
2827 /*FIXME: Inaccurate*/
2828 SourceRange(ExceptionDecl->getLocation()));
2829 if (!Var || Var->isInvalidDecl()) {
2830 if (Var)
2831 Var->Destroy(SemaRef.Context);
2832 return SemaRef.StmtError();
2833 }
2834 }
Mike Stump11289f42009-09-09 15:08:12 +00002835
Douglas Gregorebe10102009-08-20 07:17:43 +00002836 // Transform the actual exception handler.
2837 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
2838 if (Handler.isInvalid()) {
2839 if (Var)
2840 Var->Destroy(SemaRef.Context);
2841 return SemaRef.StmtError();
2842 }
Mike Stump11289f42009-09-09 15:08:12 +00002843
Douglas Gregorebe10102009-08-20 07:17:43 +00002844 if (!getDerived().AlwaysRebuild() &&
2845 !Var &&
2846 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00002847 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002848
2849 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
2850 Var,
2851 move(Handler));
2852}
Mike Stump11289f42009-09-09 15:08:12 +00002853
Douglas Gregorebe10102009-08-20 07:17:43 +00002854template<typename Derived>
2855Sema::OwningStmtResult
2856TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
2857 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00002858 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00002859 = getDerived().TransformCompoundStmt(S->getTryBlock());
2860 if (TryBlock.isInvalid())
2861 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002862
Douglas Gregorebe10102009-08-20 07:17:43 +00002863 // Transform the handlers.
2864 bool HandlerChanged = false;
2865 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
2866 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00002867 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00002868 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
2869 if (Handler.isInvalid())
2870 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002871
Douglas Gregorebe10102009-08-20 07:17:43 +00002872 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
2873 Handlers.push_back(Handler.takeAs<Stmt>());
2874 }
Mike Stump11289f42009-09-09 15:08:12 +00002875
Douglas Gregorebe10102009-08-20 07:17:43 +00002876 if (!getDerived().AlwaysRebuild() &&
2877 TryBlock.get() == S->getTryBlock() &&
2878 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00002879 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002880
2881 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00002882 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00002883}
Mike Stump11289f42009-09-09 15:08:12 +00002884
Douglas Gregorebe10102009-08-20 07:17:43 +00002885//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00002886// Expression transformation
2887//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00002888template<typename Derived>
2889Sema::OwningExprResult
2890TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
2891 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00002892}
Mike Stump11289f42009-09-09 15:08:12 +00002893
2894template<typename Derived>
2895Sema::OwningExprResult
2896TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
2897 NamedDecl *ND
Douglas Gregora16548e2009-08-11 05:31:07 +00002898 = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl()));
2899 if (!ND)
2900 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002901
Douglas Gregora16548e2009-08-11 05:31:07 +00002902 if (!getDerived().AlwaysRebuild() && ND == E->getDecl())
Mike Stump11289f42009-09-09 15:08:12 +00002903 return SemaRef.Owned(E->Retain());
2904
Douglas Gregora16548e2009-08-11 05:31:07 +00002905 return getDerived().RebuildDeclRefExpr(ND, E->getLocation());
2906}
Mike Stump11289f42009-09-09 15:08:12 +00002907
Douglas Gregora16548e2009-08-11 05:31:07 +00002908template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002909Sema::OwningExprResult
2910TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
2911 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00002912}
Mike Stump11289f42009-09-09 15:08:12 +00002913
Douglas Gregora16548e2009-08-11 05:31:07 +00002914template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002915Sema::OwningExprResult
2916TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
2917 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00002918}
Mike Stump11289f42009-09-09 15:08:12 +00002919
Douglas Gregora16548e2009-08-11 05:31:07 +00002920template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002921Sema::OwningExprResult
2922TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
2923 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00002924}
Mike Stump11289f42009-09-09 15:08:12 +00002925
Douglas Gregora16548e2009-08-11 05:31:07 +00002926template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002927Sema::OwningExprResult
2928TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
2929 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00002930}
Mike Stump11289f42009-09-09 15:08:12 +00002931
Douglas Gregora16548e2009-08-11 05:31:07 +00002932template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002933Sema::OwningExprResult
2934TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
2935 return SemaRef.Owned(E->Retain());
2936}
2937
2938template<typename Derived>
2939Sema::OwningExprResult
2940TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002941 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
2942 if (SubExpr.isInvalid())
2943 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002944
Douglas Gregora16548e2009-08-11 05:31:07 +00002945 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00002946 return SemaRef.Owned(E->Retain());
2947
2948 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002949 E->getRParen());
2950}
2951
Mike Stump11289f42009-09-09 15:08:12 +00002952template<typename Derived>
2953Sema::OwningExprResult
2954TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002955 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
2956 if (SubExpr.isInvalid())
2957 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002958
Douglas Gregora16548e2009-08-11 05:31:07 +00002959 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00002960 return SemaRef.Owned(E->Retain());
2961
Douglas Gregora16548e2009-08-11 05:31:07 +00002962 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
2963 E->getOpcode(),
2964 move(SubExpr));
2965}
Mike Stump11289f42009-09-09 15:08:12 +00002966
Douglas Gregora16548e2009-08-11 05:31:07 +00002967template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002968Sema::OwningExprResult
2969TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002970 if (E->isArgumentType()) {
2971 QualType T = getDerived().TransformType(E->getArgumentType());
2972 if (T.isNull())
2973 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002974
Douglas Gregora16548e2009-08-11 05:31:07 +00002975 if (!getDerived().AlwaysRebuild() && T == E->getArgumentType())
2976 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00002977
2978 return getDerived().RebuildSizeOfAlignOf(T, E->getOperatorLoc(),
2979 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002980 E->getSourceRange());
2981 }
Mike Stump11289f42009-09-09 15:08:12 +00002982
Douglas Gregora16548e2009-08-11 05:31:07 +00002983 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00002984 {
Douglas Gregora16548e2009-08-11 05:31:07 +00002985 // C++0x [expr.sizeof]p1:
2986 // The operand is either an expression, which is an unevaluated operand
2987 // [...]
2988 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002989
Douglas Gregora16548e2009-08-11 05:31:07 +00002990 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
2991 if (SubExpr.isInvalid())
2992 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002993
Douglas Gregora16548e2009-08-11 05:31:07 +00002994 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
2995 return SemaRef.Owned(E->Retain());
2996 }
Mike Stump11289f42009-09-09 15:08:12 +00002997
Douglas Gregora16548e2009-08-11 05:31:07 +00002998 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
2999 E->isSizeOf(),
3000 E->getSourceRange());
3001}
Mike Stump11289f42009-09-09 15:08:12 +00003002
Douglas Gregora16548e2009-08-11 05:31:07 +00003003template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003004Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003005TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
3006 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3007 if (LHS.isInvalid())
3008 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003009
Douglas Gregora16548e2009-08-11 05:31:07 +00003010 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3011 if (RHS.isInvalid())
3012 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003013
3014
Douglas Gregora16548e2009-08-11 05:31:07 +00003015 if (!getDerived().AlwaysRebuild() &&
3016 LHS.get() == E->getLHS() &&
3017 RHS.get() == E->getRHS())
3018 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003019
Douglas Gregora16548e2009-08-11 05:31:07 +00003020 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3021 /*FIXME:*/E->getLHS()->getLocStart(),
3022 move(RHS),
3023 E->getRBracketLoc());
3024}
Mike Stump11289f42009-09-09 15:08:12 +00003025
3026template<typename Derived>
3027Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003028TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
3029 // Transform the callee.
3030 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3031 if (Callee.isInvalid())
3032 return SemaRef.ExprError();
3033
3034 // Transform arguments.
3035 bool ArgChanged = false;
3036 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3037 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3038 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3039 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3040 if (Arg.isInvalid())
3041 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003042
Douglas Gregora16548e2009-08-11 05:31:07 +00003043 // FIXME: Wrong source location information for the ','.
3044 FakeCommaLocs.push_back(
3045 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003046
3047 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003048 Args.push_back(Arg.takeAs<Expr>());
3049 }
Mike Stump11289f42009-09-09 15:08:12 +00003050
Douglas Gregora16548e2009-08-11 05:31:07 +00003051 if (!getDerived().AlwaysRebuild() &&
3052 Callee.get() == E->getCallee() &&
3053 !ArgChanged)
3054 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003055
Douglas Gregora16548e2009-08-11 05:31:07 +00003056 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003057 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003058 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3059 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3060 move_arg(Args),
3061 FakeCommaLocs.data(),
3062 E->getRParenLoc());
3063}
Mike Stump11289f42009-09-09 15:08:12 +00003064
3065template<typename Derived>
3066Sema::OwningExprResult
3067TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003068 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3069 if (Base.isInvalid())
3070 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003071
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003072 NestedNameSpecifier *Qualifier = 0;
3073 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003074 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003075 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3076 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003077 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003078 return SemaRef.ExprError();
3079 }
Mike Stump11289f42009-09-09 15:08:12 +00003080
3081 NamedDecl *Member
Douglas Gregora16548e2009-08-11 05:31:07 +00003082 = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getMemberDecl()));
3083 if (!Member)
3084 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003085
Douglas Gregora16548e2009-08-11 05:31:07 +00003086 if (!getDerived().AlwaysRebuild() &&
3087 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003088 Qualifier == E->getQualifier() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003089 Member == E->getMemberDecl())
Mike Stump11289f42009-09-09 15:08:12 +00003090 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003091
3092 // FIXME: Bogus source location for the operator
3093 SourceLocation FakeOperatorLoc
3094 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3095
3096 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3097 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003098 Qualifier,
3099 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003100 E->getMemberLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003101 Member);
Douglas Gregora16548e2009-08-11 05:31:07 +00003102}
Mike Stump11289f42009-09-09 15:08:12 +00003103
Douglas Gregora16548e2009-08-11 05:31:07 +00003104template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003105Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003106TreeTransform<Derived>::TransformCastExpr(CastExpr *E) {
3107 assert(false && "Cannot transform abstract class");
3108 return SemaRef.Owned(E->Retain());
3109}
3110
3111template<typename Derived>
3112Sema::OwningExprResult
3113TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003114 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3115 if (LHS.isInvalid())
3116 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003117
Douglas Gregora16548e2009-08-11 05:31:07 +00003118 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3119 if (RHS.isInvalid())
3120 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003121
Douglas Gregora16548e2009-08-11 05:31:07 +00003122 if (!getDerived().AlwaysRebuild() &&
3123 LHS.get() == E->getLHS() &&
3124 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003125 return SemaRef.Owned(E->Retain());
3126
Douglas Gregora16548e2009-08-11 05:31:07 +00003127 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3128 move(LHS), move(RHS));
3129}
3130
Mike Stump11289f42009-09-09 15:08:12 +00003131template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003132Sema::OwningExprResult
3133TreeTransform<Derived>::TransformCompoundAssignOperator(
3134 CompoundAssignOperator *E) {
3135 return getDerived().TransformBinaryOperator(E);
3136}
Mike Stump11289f42009-09-09 15:08:12 +00003137
Douglas Gregora16548e2009-08-11 05:31:07 +00003138template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003139Sema::OwningExprResult
3140TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003141 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3142 if (Cond.isInvalid())
3143 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003144
Douglas Gregora16548e2009-08-11 05:31:07 +00003145 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3146 if (LHS.isInvalid())
3147 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003148
Douglas Gregora16548e2009-08-11 05:31:07 +00003149 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3150 if (RHS.isInvalid())
3151 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003152
Douglas Gregora16548e2009-08-11 05:31:07 +00003153 if (!getDerived().AlwaysRebuild() &&
3154 Cond.get() == E->getCond() &&
3155 LHS.get() == E->getLHS() &&
3156 RHS.get() == E->getRHS())
3157 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003158
3159 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003160 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003161 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003162 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003163 move(RHS));
3164}
Mike Stump11289f42009-09-09 15:08:12 +00003165
3166template<typename Derived>
3167Sema::OwningExprResult
3168TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003169 QualType T = getDerived().TransformType(E->getType());
3170 if (T.isNull())
3171 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003172
Douglas Gregora16548e2009-08-11 05:31:07 +00003173 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3174 if (SubExpr.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 T == E->getType() &&
3179 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003180 return SemaRef.Owned(E->Retain());
3181
Douglas Gregora16548e2009-08-11 05:31:07 +00003182 return getDerived().RebuildImplicitCastExpr(T, E->getCastKind(),
Mike Stump11289f42009-09-09 15:08:12 +00003183 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00003184 E->isLvalueCast());
3185}
Mike Stump11289f42009-09-09 15:08:12 +00003186
Douglas Gregora16548e2009-08-11 05:31:07 +00003187template<typename Derived>
3188Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003189TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) {
3190 assert(false && "Cannot transform abstract class");
3191 return SemaRef.Owned(E->Retain());
3192}
3193
3194template<typename Derived>
3195Sema::OwningExprResult
3196TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003197 QualType T;
3198 {
3199 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003200 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003201 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3202 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003203
Douglas Gregora16548e2009-08-11 05:31:07 +00003204 T = getDerived().TransformType(E->getTypeAsWritten());
3205 if (T.isNull())
3206 return SemaRef.ExprError();
3207 }
Mike Stump11289f42009-09-09 15:08:12 +00003208
Douglas Gregora16548e2009-08-11 05:31:07 +00003209 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3210 if (SubExpr.isInvalid())
3211 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003212
Douglas Gregora16548e2009-08-11 05:31:07 +00003213 if (!getDerived().AlwaysRebuild() &&
3214 T == E->getTypeAsWritten() &&
3215 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003216 return SemaRef.Owned(E->Retain());
3217
Douglas Gregora16548e2009-08-11 05:31:07 +00003218 return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T,
3219 E->getRParenLoc(),
3220 move(SubExpr));
3221}
Mike Stump11289f42009-09-09 15:08:12 +00003222
Douglas Gregora16548e2009-08-11 05:31:07 +00003223template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003224Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003225TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
3226 QualType T;
3227 {
3228 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003229 SourceLocation FakeTypeLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003230 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3231 TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003232
Douglas Gregora16548e2009-08-11 05:31:07 +00003233 T = getDerived().TransformType(E->getType());
3234 if (T.isNull())
3235 return SemaRef.ExprError();
3236 }
Mike Stump11289f42009-09-09 15:08:12 +00003237
Douglas Gregora16548e2009-08-11 05:31:07 +00003238 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3239 if (Init.isInvalid())
3240 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003241
Douglas Gregora16548e2009-08-11 05:31:07 +00003242 if (!getDerived().AlwaysRebuild() &&
3243 T == E->getType() &&
3244 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003245 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003246
3247 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T,
3248 /*FIXME:*/E->getInitializer()->getLocEnd(),
3249 move(Init));
3250}
Mike Stump11289f42009-09-09 15:08:12 +00003251
Douglas Gregora16548e2009-08-11 05:31:07 +00003252template<typename Derived>
3253Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003254TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003255 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3256 if (Base.isInvalid())
3257 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003258
Douglas Gregora16548e2009-08-11 05:31:07 +00003259 if (!getDerived().AlwaysRebuild() &&
3260 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003261 return SemaRef.Owned(E->Retain());
3262
Douglas Gregora16548e2009-08-11 05:31:07 +00003263 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003264 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003265 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3266 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3267 E->getAccessorLoc(),
3268 E->getAccessor());
3269}
Mike Stump11289f42009-09-09 15:08:12 +00003270
Douglas Gregora16548e2009-08-11 05:31:07 +00003271template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003272Sema::OwningExprResult
3273TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003274 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003275
Douglas Gregora16548e2009-08-11 05:31:07 +00003276 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3277 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3278 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3279 if (Init.isInvalid())
3280 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003281
Douglas Gregora16548e2009-08-11 05:31:07 +00003282 InitChanged = InitChanged || Init.get() != E->getInit(I);
3283 Inits.push_back(Init.takeAs<Expr>());
3284 }
Mike Stump11289f42009-09-09 15:08:12 +00003285
Douglas Gregora16548e2009-08-11 05:31:07 +00003286 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003287 return SemaRef.Owned(E->Retain());
3288
Douglas Gregora16548e2009-08-11 05:31:07 +00003289 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
3290 E->getRBraceLoc());
3291}
Mike Stump11289f42009-09-09 15:08:12 +00003292
Douglas Gregora16548e2009-08-11 05:31:07 +00003293template<typename Derived>
3294Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003295TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003296 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00003297
Douglas Gregorebe10102009-08-20 07:17:43 +00003298 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00003299 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3300 if (Init.isInvalid())
3301 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003302
Douglas Gregorebe10102009-08-20 07:17:43 +00003303 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00003304 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3305 bool ExprChanged = false;
3306 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3307 DEnd = E->designators_end();
3308 D != DEnd; ++D) {
3309 if (D->isFieldDesignator()) {
3310 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3311 D->getDotLoc(),
3312 D->getFieldLoc()));
3313 continue;
3314 }
Mike Stump11289f42009-09-09 15:08:12 +00003315
Douglas Gregora16548e2009-08-11 05:31:07 +00003316 if (D->isArrayDesignator()) {
3317 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3318 if (Index.isInvalid())
3319 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003320
3321 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003322 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003323
Douglas Gregora16548e2009-08-11 05:31:07 +00003324 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3325 ArrayExprs.push_back(Index.release());
3326 continue;
3327 }
Mike Stump11289f42009-09-09 15:08:12 +00003328
Douglas Gregora16548e2009-08-11 05:31:07 +00003329 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00003330 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00003331 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3332 if (Start.isInvalid())
3333 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003334
Douglas Gregora16548e2009-08-11 05:31:07 +00003335 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3336 if (End.isInvalid())
3337 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003338
3339 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003340 End.get(),
3341 D->getLBracketLoc(),
3342 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003343
Douglas Gregora16548e2009-08-11 05:31:07 +00003344 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
3345 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00003346
Douglas Gregora16548e2009-08-11 05:31:07 +00003347 ArrayExprs.push_back(Start.release());
3348 ArrayExprs.push_back(End.release());
3349 }
Mike Stump11289f42009-09-09 15:08:12 +00003350
Douglas Gregora16548e2009-08-11 05:31:07 +00003351 if (!getDerived().AlwaysRebuild() &&
3352 Init.get() == E->getInit() &&
3353 !ExprChanged)
3354 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003355
Douglas Gregora16548e2009-08-11 05:31:07 +00003356 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
3357 E->getEqualOrColonLoc(),
3358 E->usesGNUSyntax(), move(Init));
3359}
Mike Stump11289f42009-09-09 15:08:12 +00003360
Douglas Gregora16548e2009-08-11 05:31:07 +00003361template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003362Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003363TreeTransform<Derived>::TransformImplicitValueInitExpr(
Mike Stump11289f42009-09-09 15:08:12 +00003364 ImplicitValueInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003365 QualType T = getDerived().TransformType(E->getType());
3366 if (T.isNull())
3367 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003368
Douglas Gregora16548e2009-08-11 05:31:07 +00003369 if (!getDerived().AlwaysRebuild() &&
3370 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00003371 return SemaRef.Owned(E->Retain());
3372
Douglas Gregora16548e2009-08-11 05:31:07 +00003373 return getDerived().RebuildImplicitValueInitExpr(T);
3374}
Mike Stump11289f42009-09-09 15:08:12 +00003375
Douglas Gregora16548e2009-08-11 05:31:07 +00003376template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003377Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003378TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
3379 // FIXME: Do we want the type as written?
3380 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00003381
Douglas Gregora16548e2009-08-11 05:31:07 +00003382 {
3383 // FIXME: Source location isn't quite accurate.
3384 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
3385 T = getDerived().TransformType(E->getType());
3386 if (T.isNull())
3387 return SemaRef.ExprError();
3388 }
Mike Stump11289f42009-09-09 15:08:12 +00003389
Douglas Gregora16548e2009-08-11 05:31:07 +00003390 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3391 if (SubExpr.isInvalid())
3392 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003393
Douglas Gregora16548e2009-08-11 05:31:07 +00003394 if (!getDerived().AlwaysRebuild() &&
3395 T == E->getType() &&
3396 SubExpr.get() == E->getSubExpr())
3397 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003398
Douglas Gregora16548e2009-08-11 05:31:07 +00003399 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
3400 T, E->getRParenLoc());
3401}
3402
3403template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003404Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003405TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
3406 bool ArgumentChanged = false;
3407 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3408 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
3409 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
3410 if (Init.isInvalid())
3411 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003412
Douglas Gregora16548e2009-08-11 05:31:07 +00003413 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
3414 Inits.push_back(Init.takeAs<Expr>());
3415 }
Mike Stump11289f42009-09-09 15:08:12 +00003416
Douglas Gregora16548e2009-08-11 05:31:07 +00003417 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
3418 move_arg(Inits),
3419 E->getRParenLoc());
3420}
Mike Stump11289f42009-09-09 15:08:12 +00003421
Douglas Gregora16548e2009-08-11 05:31:07 +00003422/// \brief Transform an address-of-label expression.
3423///
3424/// By default, the transformation of an address-of-label expression always
3425/// rebuilds the expression, so that the label identifier can be resolved to
3426/// the corresponding label statement by semantic analysis.
3427template<typename Derived>
3428Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003429TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003430 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
3431 E->getLabel());
3432}
Mike Stump11289f42009-09-09 15:08:12 +00003433
3434template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003435Sema::OwningExprResult TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003436 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00003437 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
3438 if (SubStmt.isInvalid())
3439 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003440
Douglas Gregora16548e2009-08-11 05:31:07 +00003441 if (!getDerived().AlwaysRebuild() &&
3442 SubStmt.get() == E->getSubStmt())
3443 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003444
3445 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003446 move(SubStmt),
3447 E->getRParenLoc());
3448}
Mike Stump11289f42009-09-09 15:08:12 +00003449
Douglas Gregora16548e2009-08-11 05:31:07 +00003450template<typename Derived>
3451Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003452TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003453 QualType T1, T2;
3454 {
3455 // FIXME: Source location isn't quite accurate.
3456 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003457
Douglas Gregora16548e2009-08-11 05:31:07 +00003458 T1 = getDerived().TransformType(E->getArgType1());
3459 if (T1.isNull())
3460 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003461
Douglas Gregora16548e2009-08-11 05:31:07 +00003462 T2 = getDerived().TransformType(E->getArgType2());
3463 if (T2.isNull())
3464 return SemaRef.ExprError();
3465 }
3466
3467 if (!getDerived().AlwaysRebuild() &&
3468 T1 == E->getArgType1() &&
3469 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00003470 return SemaRef.Owned(E->Retain());
3471
Douglas Gregora16548e2009-08-11 05:31:07 +00003472 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
3473 T1, T2, E->getRParenLoc());
3474}
Mike Stump11289f42009-09-09 15:08:12 +00003475
Douglas Gregora16548e2009-08-11 05:31:07 +00003476template<typename Derived>
3477Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003478TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003479 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3480 if (Cond.isInvalid())
3481 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003482
Douglas Gregora16548e2009-08-11 05:31:07 +00003483 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3484 if (LHS.isInvalid())
3485 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003486
Douglas Gregora16548e2009-08-11 05:31:07 +00003487 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3488 if (RHS.isInvalid())
3489 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003490
Douglas Gregora16548e2009-08-11 05:31:07 +00003491 if (!getDerived().AlwaysRebuild() &&
3492 Cond.get() == E->getCond() &&
3493 LHS.get() == E->getLHS() &&
3494 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003495 return SemaRef.Owned(E->Retain());
3496
Douglas Gregora16548e2009-08-11 05:31:07 +00003497 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
3498 move(Cond), move(LHS), move(RHS),
3499 E->getRParenLoc());
3500}
Mike Stump11289f42009-09-09 15:08:12 +00003501
Douglas Gregora16548e2009-08-11 05:31:07 +00003502template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003503Sema::OwningExprResult
3504TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
3505 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003506}
3507
3508template<typename Derived>
3509Sema::OwningExprResult
3510TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
3511 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3512 if (Callee.isInvalid())
3513 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003514
Douglas Gregora16548e2009-08-11 05:31:07 +00003515 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
3516 if (First.isInvalid())
3517 return SemaRef.ExprError();
3518
3519 OwningExprResult Second(SemaRef);
3520 if (E->getNumArgs() == 2) {
3521 Second = getDerived().TransformExpr(E->getArg(1));
3522 if (Second.isInvalid())
3523 return SemaRef.ExprError();
3524 }
Mike Stump11289f42009-09-09 15:08:12 +00003525
Douglas Gregora16548e2009-08-11 05:31:07 +00003526 if (!getDerived().AlwaysRebuild() &&
3527 Callee.get() == E->getCallee() &&
3528 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00003529 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
3530 return SemaRef.Owned(E->Retain());
3531
Douglas Gregora16548e2009-08-11 05:31:07 +00003532 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
3533 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003534 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00003535 move(First),
3536 move(Second));
3537}
Mike Stump11289f42009-09-09 15:08:12 +00003538
Douglas Gregora16548e2009-08-11 05:31:07 +00003539template<typename Derived>
3540Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003541TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003542 return getDerived().TransformCallExpr(E);
3543}
Mike Stump11289f42009-09-09 15:08:12 +00003544
Douglas Gregora16548e2009-08-11 05:31:07 +00003545template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003546Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003547TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
3548 QualType ExplicitTy;
3549 {
3550 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003551 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003552 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
3553 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003554
Douglas Gregora16548e2009-08-11 05:31:07 +00003555 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
3556 if (ExplicitTy.isNull())
3557 return SemaRef.ExprError();
3558 }
Mike Stump11289f42009-09-09 15:08:12 +00003559
Douglas Gregora16548e2009-08-11 05:31:07 +00003560 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3561 if (SubExpr.isInvalid())
3562 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003563
Douglas Gregora16548e2009-08-11 05:31:07 +00003564 if (!getDerived().AlwaysRebuild() &&
3565 ExplicitTy == E->getTypeAsWritten() &&
3566 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003567 return SemaRef.Owned(E->Retain());
3568
Douglas Gregora16548e2009-08-11 05:31:07 +00003569 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00003570 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003571 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
3572 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
3573 SourceLocation FakeRParenLoc
3574 = SemaRef.PP.getLocForEndOfToken(
3575 E->getSubExpr()->getSourceRange().getEnd());
3576 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003577 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003578 FakeLAngleLoc,
3579 ExplicitTy,
3580 FakeRAngleLoc,
3581 FakeRAngleLoc,
3582 move(SubExpr),
3583 FakeRParenLoc);
3584}
Mike Stump11289f42009-09-09 15:08:12 +00003585
Douglas Gregora16548e2009-08-11 05:31:07 +00003586template<typename Derived>
3587Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003588TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003589 return getDerived().TransformCXXNamedCastExpr(E);
3590}
Mike Stump11289f42009-09-09 15:08:12 +00003591
3592template<typename Derived>
3593Sema::OwningExprResult
3594TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
3595 return getDerived().TransformCXXNamedCastExpr(E);
3596}
3597
Douglas Gregora16548e2009-08-11 05:31:07 +00003598template<typename Derived>
3599Sema::OwningExprResult
3600TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
Mike Stump11289f42009-09-09 15:08:12 +00003601 CXXReinterpretCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003602 return getDerived().TransformCXXNamedCastExpr(E);
3603}
Mike Stump11289f42009-09-09 15:08:12 +00003604
Douglas Gregora16548e2009-08-11 05:31:07 +00003605template<typename Derived>
3606Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003607TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003608 return getDerived().TransformCXXNamedCastExpr(E);
3609}
Mike Stump11289f42009-09-09 15:08:12 +00003610
Douglas Gregora16548e2009-08-11 05:31:07 +00003611template<typename Derived>
3612Sema::OwningExprResult
3613TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
Mike Stump11289f42009-09-09 15:08:12 +00003614 CXXFunctionalCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003615 QualType ExplicitTy;
3616 {
3617 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003618
Douglas Gregora16548e2009-08-11 05:31:07 +00003619 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
3620 if (ExplicitTy.isNull())
3621 return SemaRef.ExprError();
3622 }
Mike Stump11289f42009-09-09 15:08:12 +00003623
Douglas Gregora16548e2009-08-11 05:31:07 +00003624 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3625 if (SubExpr.isInvalid())
3626 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003627
Douglas Gregora16548e2009-08-11 05:31:07 +00003628 if (!getDerived().AlwaysRebuild() &&
3629 ExplicitTy == E->getTypeAsWritten() &&
3630 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003631 return SemaRef.Owned(E->Retain());
3632
Douglas Gregora16548e2009-08-11 05:31:07 +00003633 // FIXME: The end of the type's source range is wrong
3634 return getDerived().RebuildCXXFunctionalCastExpr(
3635 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
3636 ExplicitTy,
3637 /*FIXME:*/E->getSubExpr()->getLocStart(),
3638 move(SubExpr),
3639 E->getRParenLoc());
3640}
Mike Stump11289f42009-09-09 15:08:12 +00003641
Douglas Gregora16548e2009-08-11 05:31:07 +00003642template<typename Derived>
3643Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003644TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003645 if (E->isTypeOperand()) {
3646 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003647
Douglas Gregora16548e2009-08-11 05:31:07 +00003648 QualType T = getDerived().TransformType(E->getTypeOperand());
3649 if (T.isNull())
3650 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003651
Douglas Gregora16548e2009-08-11 05:31:07 +00003652 if (!getDerived().AlwaysRebuild() &&
3653 T == E->getTypeOperand())
3654 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003655
Douglas Gregora16548e2009-08-11 05:31:07 +00003656 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
3657 /*FIXME:*/E->getLocStart(),
3658 T,
3659 E->getLocEnd());
3660 }
Mike Stump11289f42009-09-09 15:08:12 +00003661
Douglas Gregora16548e2009-08-11 05:31:07 +00003662 // We don't know whether the expression is potentially evaluated until
3663 // after we perform semantic analysis, so the expression is potentially
3664 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00003665 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00003666 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003667
Douglas Gregora16548e2009-08-11 05:31:07 +00003668 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
3669 if (SubExpr.isInvalid())
3670 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003671
Douglas Gregora16548e2009-08-11 05:31:07 +00003672 if (!getDerived().AlwaysRebuild() &&
3673 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00003674 return SemaRef.Owned(E->Retain());
3675
Douglas Gregora16548e2009-08-11 05:31:07 +00003676 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
3677 /*FIXME:*/E->getLocStart(),
3678 move(SubExpr),
3679 E->getLocEnd());
3680}
3681
3682template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003683Sema::OwningExprResult
3684TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
3685 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003686}
Mike Stump11289f42009-09-09 15:08:12 +00003687
Douglas Gregora16548e2009-08-11 05:31:07 +00003688template<typename Derived>
3689Sema::OwningExprResult
3690TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
Mike Stump11289f42009-09-09 15:08:12 +00003691 CXXNullPtrLiteralExpr *E) {
3692 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003693}
Mike Stump11289f42009-09-09 15:08:12 +00003694
Douglas Gregora16548e2009-08-11 05:31:07 +00003695template<typename Derived>
3696Sema::OwningExprResult
3697TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
3698 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003699
Douglas Gregora16548e2009-08-11 05:31:07 +00003700 QualType T = getDerived().TransformType(E->getType());
3701 if (T.isNull())
3702 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003703
Douglas Gregora16548e2009-08-11 05:31:07 +00003704 if (!getDerived().AlwaysRebuild() &&
3705 T == E->getType())
3706 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003707
Douglas Gregora16548e2009-08-11 05:31:07 +00003708 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T);
3709}
Mike Stump11289f42009-09-09 15:08:12 +00003710
Douglas Gregora16548e2009-08-11 05:31:07 +00003711template<typename Derived>
3712Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003713TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003714 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3715 if (SubExpr.isInvalid())
3716 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003717
Douglas Gregora16548e2009-08-11 05:31:07 +00003718 if (!getDerived().AlwaysRebuild() &&
3719 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003720 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003721
3722 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
3723}
Mike Stump11289f42009-09-09 15:08:12 +00003724
Douglas Gregora16548e2009-08-11 05:31:07 +00003725template<typename Derived>
3726Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003727TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
3728 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00003729 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
3730 if (!Param)
3731 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003732
Douglas Gregora16548e2009-08-11 05:31:07 +00003733 if (getDerived().AlwaysRebuild() &&
3734 Param == E->getParam())
3735 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003736
Douglas Gregora16548e2009-08-11 05:31:07 +00003737 return getDerived().RebuildCXXDefaultArgExpr(Param);
3738}
Mike Stump11289f42009-09-09 15:08:12 +00003739
Douglas Gregora16548e2009-08-11 05:31:07 +00003740template<typename Derived>
3741Sema::OwningExprResult
3742TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
3743 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
3744
3745 QualType T = getDerived().TransformType(E->getType());
3746 if (T.isNull())
3747 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003748
Douglas Gregora16548e2009-08-11 05:31:07 +00003749 if (!getDerived().AlwaysRebuild() &&
3750 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00003751 return SemaRef.Owned(E->Retain());
3752
3753 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003754 /*FIXME:*/E->getTypeBeginLoc(),
3755 T,
3756 E->getRParenLoc());
3757}
Mike Stump11289f42009-09-09 15:08:12 +00003758
Douglas Gregora16548e2009-08-11 05:31:07 +00003759template<typename Derived>
3760Sema::OwningExprResult
3761TreeTransform<Derived>::TransformCXXConditionDeclExpr(CXXConditionDeclExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003762 VarDecl *Var
Douglas Gregorebe10102009-08-20 07:17:43 +00003763 = cast_or_null<VarDecl>(getDerived().TransformDefinition(E->getVarDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003764 if (!Var)
3765 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003766
Douglas Gregora16548e2009-08-11 05:31:07 +00003767 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00003768 Var == E->getVarDecl())
Douglas Gregora16548e2009-08-11 05:31:07 +00003769 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003770
3771 return getDerived().RebuildCXXConditionDeclExpr(E->getStartLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003772 /*FIXME:*/E->getStartLoc(),
3773 Var);
3774}
Mike Stump11289f42009-09-09 15:08:12 +00003775
Douglas Gregora16548e2009-08-11 05:31:07 +00003776template<typename Derived>
3777Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003778TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003779 // Transform the type that we're allocating
3780 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3781 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
3782 if (AllocType.isNull())
3783 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003784
Douglas Gregora16548e2009-08-11 05:31:07 +00003785 // Transform the size of the array we're allocating (if any).
3786 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
3787 if (ArraySize.isInvalid())
3788 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003789
Douglas Gregora16548e2009-08-11 05:31:07 +00003790 // Transform the placement arguments (if any).
3791 bool ArgumentChanged = false;
3792 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
3793 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
3794 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
3795 if (Arg.isInvalid())
3796 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003797
Douglas Gregora16548e2009-08-11 05:31:07 +00003798 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
3799 PlacementArgs.push_back(Arg.take());
3800 }
Mike Stump11289f42009-09-09 15:08:12 +00003801
Douglas Gregorebe10102009-08-20 07:17:43 +00003802 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00003803 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
3804 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
3805 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
3806 if (Arg.isInvalid())
3807 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003808
Douglas Gregora16548e2009-08-11 05:31:07 +00003809 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
3810 ConstructorArgs.push_back(Arg.take());
3811 }
Mike Stump11289f42009-09-09 15:08:12 +00003812
Douglas Gregora16548e2009-08-11 05:31:07 +00003813 if (!getDerived().AlwaysRebuild() &&
3814 AllocType == E->getAllocatedType() &&
3815 ArraySize.get() == E->getArraySize() &&
3816 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003817 return SemaRef.Owned(E->Retain());
3818
Douglas Gregora16548e2009-08-11 05:31:07 +00003819 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
3820 E->isGlobalNew(),
3821 /*FIXME:*/E->getLocStart(),
3822 move_arg(PlacementArgs),
3823 /*FIXME:*/E->getLocStart(),
3824 E->isParenTypeId(),
3825 AllocType,
3826 /*FIXME:*/E->getLocStart(),
3827 /*FIXME:*/SourceRange(),
3828 move(ArraySize),
3829 /*FIXME:*/E->getLocStart(),
3830 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00003831 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00003832}
Mike Stump11289f42009-09-09 15:08:12 +00003833
Douglas Gregora16548e2009-08-11 05:31:07 +00003834template<typename Derived>
3835Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003836TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003837 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
3838 if (Operand.isInvalid())
3839 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003840
Douglas Gregora16548e2009-08-11 05:31:07 +00003841 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00003842 Operand.get() == E->getArgument())
3843 return SemaRef.Owned(E->Retain());
3844
Douglas Gregora16548e2009-08-11 05:31:07 +00003845 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
3846 E->isGlobalDelete(),
3847 E->isArrayForm(),
3848 move(Operand));
3849}
Mike Stump11289f42009-09-09 15:08:12 +00003850
Douglas Gregora16548e2009-08-11 05:31:07 +00003851template<typename Derived>
3852Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00003853TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
3854 CXXPseudoDestructorExpr *E) {
3855 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3856 if (Base.isInvalid())
3857 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003858
Douglas Gregorad8a3362009-09-04 17:36:40 +00003859 NestedNameSpecifier *Qualifier
3860 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3861 E->getQualifierRange());
3862 if (E->getQualifier() && !Qualifier)
3863 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003864
Douglas Gregorad8a3362009-09-04 17:36:40 +00003865 QualType DestroyedType;
3866 {
3867 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
3868 DestroyedType = getDerived().TransformType(E->getDestroyedType());
3869 if (DestroyedType.isNull())
3870 return SemaRef.ExprError();
3871 }
Mike Stump11289f42009-09-09 15:08:12 +00003872
Douglas Gregorad8a3362009-09-04 17:36:40 +00003873 if (!getDerived().AlwaysRebuild() &&
3874 Base.get() == E->getBase() &&
3875 Qualifier == E->getQualifier() &&
3876 DestroyedType == E->getDestroyedType())
3877 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003878
Douglas Gregorad8a3362009-09-04 17:36:40 +00003879 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
3880 E->getOperatorLoc(),
3881 E->isArrow(),
3882 E->getDestroyedTypeLoc(),
3883 DestroyedType,
3884 Qualifier,
3885 E->getQualifierRange());
3886}
Mike Stump11289f42009-09-09 15:08:12 +00003887
Douglas Gregorad8a3362009-09-04 17:36:40 +00003888template<typename Derived>
3889Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003890TreeTransform<Derived>::TransformUnresolvedFunctionNameExpr(
Mike Stump11289f42009-09-09 15:08:12 +00003891 UnresolvedFunctionNameExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003892 // There is no transformation we can apply to an unresolved function name.
Mike Stump11289f42009-09-09 15:08:12 +00003893 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003894}
Mike Stump11289f42009-09-09 15:08:12 +00003895
Douglas Gregora16548e2009-08-11 05:31:07 +00003896template<typename Derived>
3897Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003898TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003899 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003900
Douglas Gregora16548e2009-08-11 05:31:07 +00003901 QualType T = getDerived().TransformType(E->getQueriedType());
3902 if (T.isNull())
3903 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003904
Douglas Gregora16548e2009-08-11 05:31:07 +00003905 if (!getDerived().AlwaysRebuild() &&
3906 T == E->getQueriedType())
3907 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003908
Douglas Gregora16548e2009-08-11 05:31:07 +00003909 // FIXME: Bad location information
3910 SourceLocation FakeLParenLoc
3911 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00003912
3913 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003914 E->getLocStart(),
3915 /*FIXME:*/FakeLParenLoc,
3916 T,
3917 E->getLocEnd());
3918}
Mike Stump11289f42009-09-09 15:08:12 +00003919
Douglas Gregora16548e2009-08-11 05:31:07 +00003920template<typename Derived>
3921Sema::OwningExprResult
3922TreeTransform<Derived>::TransformQualifiedDeclRefExpr(QualifiedDeclRefExpr *E) {
3923 NestedNameSpecifier *NNS
3924 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3925 E->getQualifierRange());
3926 if (!NNS)
3927 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003928
3929 NamedDecl *ND
Douglas Gregora16548e2009-08-11 05:31:07 +00003930 = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl()));
3931 if (!ND)
3932 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003933
3934 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003935 NNS == E->getQualifier() &&
3936 ND == E->getDecl())
Mike Stump11289f42009-09-09 15:08:12 +00003937 return SemaRef.Owned(E->Retain());
3938
3939 return getDerived().RebuildQualifiedDeclRefExpr(NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00003940 E->getQualifierRange(),
3941 ND,
3942 E->getLocation(),
3943 /*FIXME:*/false);
3944}
Mike Stump11289f42009-09-09 15:08:12 +00003945
Douglas Gregora16548e2009-08-11 05:31:07 +00003946template<typename Derived>
3947Sema::OwningExprResult
3948TreeTransform<Derived>::TransformUnresolvedDeclRefExpr(
Mike Stump11289f42009-09-09 15:08:12 +00003949 UnresolvedDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003950 NestedNameSpecifier *NNS
3951 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3952 E->getQualifierRange());
3953 if (!NNS)
3954 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003955
3956 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00003957 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
3958 if (!Name)
3959 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003960
3961 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003962 NNS == E->getQualifier() &&
3963 Name == E->getDeclName())
Mike Stump11289f42009-09-09 15:08:12 +00003964 return SemaRef.Owned(E->Retain());
3965
3966 return getDerived().RebuildUnresolvedDeclRefExpr(NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00003967 E->getQualifierRange(),
3968 Name,
3969 E->getLocation(),
3970 /*FIXME:*/false);
3971}
3972
3973template<typename Derived>
3974Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003975TreeTransform<Derived>::TransformTemplateIdRefExpr(TemplateIdRefExpr *E) {
3976 TemplateName Template
Douglas Gregora16548e2009-08-11 05:31:07 +00003977 = getDerived().TransformTemplateName(E->getTemplateName());
3978 if (Template.isNull())
3979 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003980
Douglas Gregora16548e2009-08-11 05:31:07 +00003981 llvm::SmallVector<TemplateArgument, 4> TransArgs;
3982 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003983 TemplateArgument TransArg
Douglas Gregora16548e2009-08-11 05:31:07 +00003984 = getDerived().TransformTemplateArgument(E->getTemplateArgs()[I]);
3985 if (TransArg.isNull())
3986 return SemaRef.ExprError();
3987
3988 TransArgs.push_back(TransArg);
3989 }
3990
3991 // FIXME: Would like to avoid rebuilding if nothing changed, but we can't
3992 // compare template arguments (yet).
Mike Stump11289f42009-09-09 15:08:12 +00003993
3994 // FIXME: It's possible that we'll find out now that the template name
Douglas Gregora16548e2009-08-11 05:31:07 +00003995 // actually refers to a type, in which case the caller is actually dealing
3996 // with a functional cast. Give a reasonable error message!
3997 return getDerived().RebuildTemplateIdExpr(Template, E->getTemplateNameLoc(),
3998 E->getLAngleLoc(),
3999 TransArgs.data(),
4000 TransArgs.size(),
4001 E->getRAngleLoc());
4002}
4003
4004template<typename Derived>
4005Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004006TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004007 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4008
4009 QualType T = getDerived().TransformType(E->getType());
4010 if (T.isNull())
4011 return SemaRef.ExprError();
4012
4013 CXXConstructorDecl *Constructor
4014 = cast_or_null<CXXConstructorDecl>(
4015 getDerived().TransformDecl(E->getConstructor()));
4016 if (!Constructor)
4017 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004018
Douglas Gregora16548e2009-08-11 05:31:07 +00004019 bool ArgumentChanged = false;
4020 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004021 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004022 ArgEnd = E->arg_end();
4023 Arg != ArgEnd; ++Arg) {
4024 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4025 if (TransArg.isInvalid())
4026 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004027
Douglas Gregora16548e2009-08-11 05:31:07 +00004028 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4029 Args.push_back(TransArg.takeAs<Expr>());
4030 }
4031
4032 if (!getDerived().AlwaysRebuild() &&
4033 T == E->getType() &&
4034 Constructor == E->getConstructor() &&
4035 !ArgumentChanged)
4036 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004037
Douglas Gregora16548e2009-08-11 05:31:07 +00004038 return getDerived().RebuildCXXConstructExpr(T, Constructor, E->isElidable(),
4039 move_arg(Args));
4040}
Mike Stump11289f42009-09-09 15:08:12 +00004041
Douglas Gregora16548e2009-08-11 05:31:07 +00004042/// \brief Transform a C++ temporary-binding expression.
4043///
Mike Stump11289f42009-09-09 15:08:12 +00004044/// The transformation of a temporary-binding expression always attempts to
4045/// bind a new temporary variable to its subexpression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004046/// subexpression itself did not change, because the temporary variable itself
4047/// must be unique.
4048template<typename Derived>
4049Sema::OwningExprResult
4050TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
4051 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4052 if (SubExpr.isInvalid())
4053 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004054
Douglas Gregora16548e2009-08-11 05:31:07 +00004055 return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>());
4056}
Mike Stump11289f42009-09-09 15:08:12 +00004057
4058/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004059/// be destroyed after the expression is evaluated.
4060///
Mike Stump11289f42009-09-09 15:08:12 +00004061/// The transformation of a full expression always attempts to build a new
4062/// CXXExprWithTemporaries expression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004063/// subexpression itself did not change, because it will need to capture the
4064/// the new temporary variables introduced in the subexpression.
4065template<typename Derived>
4066Sema::OwningExprResult
4067TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Mike Stump11289f42009-09-09 15:08:12 +00004068 CXXExprWithTemporaries *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004069 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4070 if (SubExpr.isInvalid())
4071 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004072
Douglas Gregora16548e2009-08-11 05:31:07 +00004073 return SemaRef.Owned(
4074 SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(),
4075 E->shouldDestroyTemporaries()));
4076}
Mike Stump11289f42009-09-09 15:08:12 +00004077
Douglas Gregora16548e2009-08-11 05:31:07 +00004078template<typename Derived>
4079Sema::OwningExprResult
4080TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004081 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004082 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4083 QualType T = getDerived().TransformType(E->getType());
4084 if (T.isNull())
4085 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004086
Douglas Gregora16548e2009-08-11 05:31:07 +00004087 CXXConstructorDecl *Constructor
4088 = cast_or_null<CXXConstructorDecl>(
4089 getDerived().TransformDecl(E->getConstructor()));
4090 if (!Constructor)
4091 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004092
Douglas Gregora16548e2009-08-11 05:31:07 +00004093 bool ArgumentChanged = false;
4094 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4095 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004096 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004097 ArgEnd = E->arg_end();
4098 Arg != ArgEnd; ++Arg) {
4099 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4100 if (TransArg.isInvalid())
4101 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004102
Douglas Gregora16548e2009-08-11 05:31:07 +00004103 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4104 Args.push_back((Expr *)TransArg.release());
4105 }
Mike Stump11289f42009-09-09 15:08:12 +00004106
Douglas Gregora16548e2009-08-11 05:31:07 +00004107 if (!getDerived().AlwaysRebuild() &&
4108 T == E->getType() &&
4109 Constructor == E->getConstructor() &&
4110 !ArgumentChanged)
4111 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004112
Douglas Gregora16548e2009-08-11 05:31:07 +00004113 // FIXME: Bogus location information
4114 SourceLocation CommaLoc;
4115 if (Args.size() > 1) {
4116 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004117 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004118 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4119 }
4120 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4121 T,
4122 /*FIXME:*/E->getTypeBeginLoc(),
4123 move_arg(Args),
4124 &CommaLoc,
4125 E->getLocEnd());
4126}
Mike Stump11289f42009-09-09 15:08:12 +00004127
Douglas Gregora16548e2009-08-11 05:31:07 +00004128template<typename Derived>
4129Sema::OwningExprResult
4130TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004131 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004132 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4133 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4134 if (T.isNull())
4135 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004136
Douglas Gregora16548e2009-08-11 05:31:07 +00004137 bool ArgumentChanged = false;
4138 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4139 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4140 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4141 ArgEnd = E->arg_end();
4142 Arg != ArgEnd; ++Arg) {
4143 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4144 if (TransArg.isInvalid())
4145 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004146
Douglas Gregora16548e2009-08-11 05:31:07 +00004147 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4148 FakeCommaLocs.push_back(
4149 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4150 Args.push_back(TransArg.takeAs<Expr>());
4151 }
Mike Stump11289f42009-09-09 15:08:12 +00004152
Douglas Gregora16548e2009-08-11 05:31:07 +00004153 if (!getDerived().AlwaysRebuild() &&
4154 T == E->getTypeAsWritten() &&
4155 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004156 return SemaRef.Owned(E->Retain());
4157
Douglas Gregora16548e2009-08-11 05:31:07 +00004158 // FIXME: we're faking the locations of the commas
4159 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4160 T,
4161 E->getLParenLoc(),
4162 move_arg(Args),
4163 FakeCommaLocs.data(),
4164 E->getRParenLoc());
4165}
Mike Stump11289f42009-09-09 15:08:12 +00004166
Douglas Gregora16548e2009-08-11 05:31:07 +00004167template<typename Derived>
4168Sema::OwningExprResult
4169TreeTransform<Derived>::TransformCXXUnresolvedMemberExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004170 CXXUnresolvedMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004171 // Transform the base of the expression.
4172 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4173 if (Base.isInvalid())
4174 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004175
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004176 Sema::TypeTy *ObjectType = 0;
Mike Stump11289f42009-09-09 15:08:12 +00004177 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004178 E->getOperatorLoc(),
4179 E->isArrow()? tok::arrow : tok::period,
4180 ObjectType);
4181 if (Base.isInvalid())
4182 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004183
Douglas Gregor308047d2009-09-09 00:23:06 +00004184 // FIXME: The first qualifier found might be a template type parameter,
4185 // in which case there is no transformed declaration to refer to (it might
4186 // refer to a built-in type!).
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004187 NamedDecl *FirstQualifierInScope
4188 = cast_or_null<NamedDecl>(
4189 getDerived().TransformDecl(E->getFirstQualifierFoundInScope()));
Mike Stump11289f42009-09-09 15:08:12 +00004190
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004191 NestedNameSpecifier *Qualifier = 0;
4192 if (E->getQualifier()) {
4193 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4194 E->getQualifierRange(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004195 QualType::getFromOpaquePtr(ObjectType),
4196 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004197 if (!Qualifier)
4198 return SemaRef.ExprError();
4199 }
Mike Stump11289f42009-09-09 15:08:12 +00004200
4201 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004202 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc());
4203 if (!Name)
4204 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004205
Douglas Gregor308047d2009-09-09 00:23:06 +00004206 if (!E->hasExplicitTemplateArgumentList()) {
4207 // This is a reference to a member without an explicitly-specified
4208 // template argument list. Optimize for this common case.
4209 if (!getDerived().AlwaysRebuild() &&
4210 Base.get() == E->getBase() &&
4211 Qualifier == E->getQualifier() &&
4212 Name == E->getMember() &&
4213 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00004214 return SemaRef.Owned(E->Retain());
4215
Douglas Gregor308047d2009-09-09 00:23:06 +00004216 return getDerived().RebuildCXXUnresolvedMemberExpr(move(Base),
4217 E->isArrow(),
4218 E->getOperatorLoc(),
4219 Qualifier,
4220 E->getQualifierRange(),
4221 Name,
4222 E->getMemberLoc(),
4223 FirstQualifierInScope);
4224 }
4225
4226 // FIXME: This is an ugly hack, which forces the same template name to
4227 // be looked up multiple times. Yuck!
4228 // FIXME: This also won't work for, e.g., x->template operator+<int>
4229 TemplateName OrigTemplateName
4230 = SemaRef.Context.getDependentTemplateName(0, Name.getAsIdentifierInfo());
Mike Stump11289f42009-09-09 15:08:12 +00004231
4232 TemplateName Template
4233 = getDerived().TransformTemplateName(OrigTemplateName,
Douglas Gregor308047d2009-09-09 00:23:06 +00004234 QualType::getFromOpaquePtr(ObjectType));
4235 if (Template.isNull())
4236 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004237
Douglas Gregor308047d2009-09-09 00:23:06 +00004238 llvm::SmallVector<TemplateArgument, 4> TransArgs;
4239 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004240 TemplateArgument TransArg
Douglas Gregor308047d2009-09-09 00:23:06 +00004241 = getDerived().TransformTemplateArgument(E->getTemplateArgs()[I]);
4242 if (TransArg.isNull())
4243 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004244
Douglas Gregor308047d2009-09-09 00:23:06 +00004245 TransArgs.push_back(TransArg);
4246 }
Mike Stump11289f42009-09-09 15:08:12 +00004247
Douglas Gregora16548e2009-08-11 05:31:07 +00004248 return getDerived().RebuildCXXUnresolvedMemberExpr(move(Base),
4249 E->isArrow(),
4250 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004251 Qualifier,
4252 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004253 Template,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004254 E->getMemberLoc(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004255 FirstQualifierInScope,
4256 E->getLAngleLoc(),
4257 TransArgs.data(),
4258 TransArgs.size(),
4259 E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004260}
4261
4262template<typename Derived>
4263Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004264TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
4265 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004266}
4267
Mike Stump11289f42009-09-09 15:08:12 +00004268template<typename Derived>
4269Sema::OwningExprResult
4270TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004271 // FIXME: poor source location
4272 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
4273 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
4274 if (EncodedType.isNull())
4275 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004276
Douglas Gregora16548e2009-08-11 05:31:07 +00004277 if (!getDerived().AlwaysRebuild() &&
4278 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00004279 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004280
4281 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
4282 EncodedType,
4283 E->getRParenLoc());
4284}
Mike Stump11289f42009-09-09 15:08:12 +00004285
Douglas Gregora16548e2009-08-11 05:31:07 +00004286template<typename Derived>
4287Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004288TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004289 // FIXME: Implement this!
4290 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004291 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004292}
4293
Mike Stump11289f42009-09-09 15:08:12 +00004294template<typename Derived>
4295Sema::OwningExprResult
4296TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
4297 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004298}
4299
Mike Stump11289f42009-09-09 15:08:12 +00004300template<typename Derived>
4301Sema::OwningExprResult
4302TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
4303 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00004304 = cast_or_null<ObjCProtocolDecl>(
4305 getDerived().TransformDecl(E->getProtocol()));
4306 if (!Protocol)
4307 return SemaRef.ExprError();
4308
4309 if (!getDerived().AlwaysRebuild() &&
4310 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00004311 return SemaRef.Owned(E->Retain());
4312
Douglas Gregora16548e2009-08-11 05:31:07 +00004313 return getDerived().RebuildObjCProtocolExpr(Protocol,
4314 E->getAtLoc(),
4315 /*FIXME:*/E->getAtLoc(),
4316 /*FIXME:*/E->getAtLoc(),
4317 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004318
Douglas Gregora16548e2009-08-11 05:31:07 +00004319}
4320
Mike Stump11289f42009-09-09 15:08:12 +00004321template<typename Derived>
4322Sema::OwningExprResult
4323TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004324 // FIXME: Implement this!
4325 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004326 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004327}
4328
Mike Stump11289f42009-09-09 15:08:12 +00004329template<typename Derived>
4330Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004331TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
4332 // FIXME: Implement this!
4333 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004334 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004335}
4336
Mike Stump11289f42009-09-09 15:08:12 +00004337template<typename Derived>
4338Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00004339TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004340 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004341 // FIXME: Implement this!
4342 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004343 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004344}
4345
Mike Stump11289f42009-09-09 15:08:12 +00004346template<typename Derived>
4347Sema::OwningExprResult
4348TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004349 // FIXME: Implement this!
4350 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004351 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004352}
4353
Mike Stump11289f42009-09-09 15:08:12 +00004354template<typename Derived>
4355Sema::OwningExprResult
4356TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004357 // FIXME: Implement this!
4358 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004359 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004360}
4361
Mike Stump11289f42009-09-09 15:08:12 +00004362template<typename Derived>
4363Sema::OwningExprResult
4364TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004365 bool ArgumentChanged = false;
4366 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
4367 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
4368 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
4369 if (SubExpr.isInvalid())
4370 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004371
Douglas Gregora16548e2009-08-11 05:31:07 +00004372 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
4373 SubExprs.push_back(SubExpr.takeAs<Expr>());
4374 }
Mike Stump11289f42009-09-09 15:08:12 +00004375
Douglas Gregora16548e2009-08-11 05:31:07 +00004376 if (!getDerived().AlwaysRebuild() &&
4377 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004378 return SemaRef.Owned(E->Retain());
4379
Douglas Gregora16548e2009-08-11 05:31:07 +00004380 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
4381 move_arg(SubExprs),
4382 E->getRParenLoc());
4383}
4384
Mike Stump11289f42009-09-09 15:08:12 +00004385template<typename Derived>
4386Sema::OwningExprResult
4387TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004388 // FIXME: Implement this!
4389 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004390 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004391}
4392
Mike Stump11289f42009-09-09 15:08:12 +00004393template<typename Derived>
4394Sema::OwningExprResult
4395TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004396 // FIXME: Implement this!
4397 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004398 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004399}
Mike Stump11289f42009-09-09 15:08:12 +00004400
Douglas Gregora16548e2009-08-11 05:31:07 +00004401//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00004402// Type reconstruction
4403//===----------------------------------------------------------------------===//
4404
Mike Stump11289f42009-09-09 15:08:12 +00004405template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004406QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004407 return SemaRef.BuildPointerType(PointeeType, Qualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004408 getDerived().getBaseLocation(),
4409 getDerived().getBaseEntity());
4410}
4411
Mike Stump11289f42009-09-09 15:08:12 +00004412template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004413QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004414 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004415 getDerived().getBaseLocation(),
4416 getDerived().getBaseEntity());
4417}
4418
Mike Stump11289f42009-09-09 15:08:12 +00004419template<typename Derived>
4420QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00004421TreeTransform<Derived>::RebuildLValueReferenceType(QualType ReferentType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004422 return SemaRef.BuildReferenceType(ReferentType, true, Qualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004423 getDerived().getBaseLocation(),
4424 getDerived().getBaseEntity());
4425}
4426
4427template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004428QualType
4429TreeTransform<Derived>::RebuildRValueReferenceType(QualType ReferentType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004430 return SemaRef.BuildReferenceType(ReferentType, false, Qualifiers(),
Mike Stump11289f42009-09-09 15:08:12 +00004431 getDerived().getBaseLocation(),
4432 getDerived().getBaseEntity());
4433}
4434
4435template<typename Derived>
4436QualType TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004437 QualType ClassType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004438 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004439 getDerived().getBaseLocation(),
4440 getDerived().getBaseEntity());
4441}
4442
4443template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004444QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00004445TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
4446 ArrayType::ArraySizeModifier SizeMod,
4447 const llvm::APInt *Size,
4448 Expr *SizeExpr,
4449 unsigned IndexTypeQuals,
4450 SourceRange BracketsRange) {
4451 if (SizeExpr || !Size)
4452 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
4453 IndexTypeQuals, BracketsRange,
4454 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00004455
4456 QualType Types[] = {
4457 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
4458 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
4459 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00004460 };
4461 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
4462 QualType SizeType;
4463 for (unsigned I = 0; I != NumTypes; ++I)
4464 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
4465 SizeType = Types[I];
4466 break;
4467 }
Mike Stump11289f42009-09-09 15:08:12 +00004468
Douglas Gregord6ff3322009-08-04 16:50:30 +00004469 if (SizeType.isNull())
4470 SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false);
Mike Stump11289f42009-09-09 15:08:12 +00004471
Douglas Gregord6ff3322009-08-04 16:50:30 +00004472 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00004473 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004474 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00004475 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004476}
Mike Stump11289f42009-09-09 15:08:12 +00004477
Douglas Gregord6ff3322009-08-04 16:50:30 +00004478template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004479QualType
4480TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004481 ArrayType::ArraySizeModifier SizeMod,
4482 const llvm::APInt &Size,
4483 unsigned IndexTypeQuals) {
Mike Stump11289f42009-09-09 15:08:12 +00004484 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004485 IndexTypeQuals, SourceRange());
4486}
4487
4488template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004489QualType
Mike Stump11289f42009-09-09 15:08:12 +00004490TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004491 ArrayType::ArraySizeModifier SizeMod,
4492 unsigned IndexTypeQuals) {
Mike Stump11289f42009-09-09 15:08:12 +00004493 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004494 IndexTypeQuals, SourceRange());
4495}
Mike Stump11289f42009-09-09 15:08:12 +00004496
Douglas Gregord6ff3322009-08-04 16:50:30 +00004497template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004498QualType
4499TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004500 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00004501 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004502 unsigned IndexTypeQuals,
4503 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00004504 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004505 SizeExpr.takeAs<Expr>(),
4506 IndexTypeQuals, BracketsRange);
4507}
4508
4509template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004510QualType
4511TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004512 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00004513 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004514 unsigned IndexTypeQuals,
4515 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00004516 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004517 SizeExpr.takeAs<Expr>(),
4518 IndexTypeQuals, BracketsRange);
4519}
4520
4521template<typename Derived>
4522QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
4523 unsigned NumElements) {
4524 // FIXME: semantic checking!
4525 return SemaRef.Context.getVectorType(ElementType, NumElements);
4526}
Mike Stump11289f42009-09-09 15:08:12 +00004527
Douglas Gregord6ff3322009-08-04 16:50:30 +00004528template<typename Derived>
4529QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
4530 unsigned NumElements,
4531 SourceLocation AttributeLoc) {
4532 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
4533 NumElements, true);
4534 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00004535 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004536 AttributeLoc);
4537 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
4538 AttributeLoc);
4539}
Mike Stump11289f42009-09-09 15:08:12 +00004540
Douglas Gregord6ff3322009-08-04 16:50:30 +00004541template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004542QualType
4543TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00004544 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004545 SourceLocation AttributeLoc) {
4546 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
4547}
Mike Stump11289f42009-09-09 15:08:12 +00004548
Douglas Gregord6ff3322009-08-04 16:50:30 +00004549template<typename Derived>
4550QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00004551 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004552 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00004553 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004554 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00004555 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004556 Quals,
4557 getDerived().getBaseLocation(),
4558 getDerived().getBaseEntity());
4559}
Mike Stump11289f42009-09-09 15:08:12 +00004560
Douglas Gregord6ff3322009-08-04 16:50:30 +00004561template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004562QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004563 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
4564}
4565
4566template<typename Derived>
4567QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
4568 return SemaRef.Context.getTypeOfType(Underlying);
4569}
4570
4571template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004572QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004573 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
4574}
4575
4576template<typename Derived>
4577QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
4578 TemplateName Template,
4579 const TemplateArgument *Args,
4580 unsigned NumArgs) {
4581 // FIXME: Missing source locations for the template name, <, >.
4582 return SemaRef.CheckTemplateIdType(Template, getDerived().getBaseLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00004583 SourceLocation(), Args, NumArgs,
4584 SourceLocation());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004585}
Mike Stump11289f42009-09-09 15:08:12 +00004586
Douglas Gregor1135c352009-08-06 05:28:30 +00004587template<typename Derived>
4588NestedNameSpecifier *
4589TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
4590 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004591 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004592 QualType ObjectType,
4593 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00004594 CXXScopeSpec SS;
4595 // FIXME: The source location information is all wrong.
4596 SS.setRange(Range);
4597 SS.setScopeRep(Prefix);
4598 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00004599 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00004600 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004601 ObjectType,
4602 FirstQualifierInScope,
Douglas Gregore861bac2009-08-25 22:51:20 +00004603 false));
Douglas Gregor1135c352009-08-06 05:28:30 +00004604}
4605
4606template<typename Derived>
4607NestedNameSpecifier *
4608TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
4609 SourceRange Range,
4610 NamespaceDecl *NS) {
4611 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
4612}
4613
4614template<typename Derived>
4615NestedNameSpecifier *
4616TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
4617 SourceRange Range,
4618 bool TemplateKW,
4619 QualType T) {
4620 if (T->isDependentType() || T->isRecordType() ||
4621 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
John McCall8ccfcb52009-09-24 19:53:00 +00004622 assert(!T.hasQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00004623 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
4624 T.getTypePtr());
4625 }
Mike Stump11289f42009-09-09 15:08:12 +00004626
Douglas Gregor1135c352009-08-06 05:28:30 +00004627 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
4628 return 0;
4629}
Mike Stump11289f42009-09-09 15:08:12 +00004630
Douglas Gregor71dc5092009-08-06 06:41:21 +00004631template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004632TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00004633TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
4634 bool TemplateKW,
4635 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00004636 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00004637 Template);
4638}
4639
4640template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004641TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00004642TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
4643 bool TemplateKW,
4644 OverloadedFunctionDecl *Ovl) {
4645 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, Ovl);
4646}
4647
4648template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004649TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00004650TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00004651 const IdentifierInfo &II,
4652 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00004653 CXXScopeSpec SS;
4654 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00004655 SS.setScopeRep(Qualifier);
Douglas Gregor308047d2009-09-09 00:23:06 +00004656 return getSema().ActOnDependentTemplateName(
4657 /*FIXME:*/getDerived().getBaseLocation(),
4658 II,
4659 /*FIXME:*/getDerived().getBaseLocation(),
4660 SS,
4661 ObjectType.getAsOpaquePtr())
4662 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00004663}
Mike Stump11289f42009-09-09 15:08:12 +00004664
Douglas Gregora16548e2009-08-11 05:31:07 +00004665template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004666Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004667TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
4668 SourceLocation OpLoc,
4669 ExprArg Callee,
4670 ExprArg First,
4671 ExprArg Second) {
4672 Expr *FirstExpr = (Expr *)First.get();
4673 Expr *SecondExpr = (Expr *)Second.get();
4674 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00004675
Douglas Gregora16548e2009-08-11 05:31:07 +00004676 // Determine whether this should be a builtin operation.
4677 if (SecondExpr == 0 || isPostIncDec) {
4678 if (!FirstExpr->getType()->isOverloadableType()) {
4679 // The argument is not of overloadable type, so try to create a
4680 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00004681 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00004682 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00004683
Douglas Gregora16548e2009-08-11 05:31:07 +00004684 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
4685 }
4686 } else {
Mike Stump11289f42009-09-09 15:08:12 +00004687 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004688 !SecondExpr->getType()->isOverloadableType()) {
4689 // Neither of the arguments is an overloadable type, so try to
4690 // create a built-in binary operation.
4691 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00004692 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00004693 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
4694 if (Result.isInvalid())
4695 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004696
Douglas Gregora16548e2009-08-11 05:31:07 +00004697 First.release();
4698 Second.release();
4699 return move(Result);
4700 }
4701 }
Mike Stump11289f42009-09-09 15:08:12 +00004702
4703 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00004704 // used during overload resolution.
4705 Sema::FunctionSet Functions;
Mike Stump11289f42009-09-09 15:08:12 +00004706
4707 DeclRefExpr *DRE
Douglas Gregor32e2c842009-09-01 16:58:52 +00004708 = cast<DeclRefExpr>(((Expr *)Callee.get())->IgnoreParenCasts());
Mike Stump11289f42009-09-09 15:08:12 +00004709
Douglas Gregora16548e2009-08-11 05:31:07 +00004710 // FIXME: Do we have to check
4711 // IsAcceptableNonMemberOperatorCandidate for each of these?
Douglas Gregor32e2c842009-09-01 16:58:52 +00004712 for (OverloadIterator F(DRE->getDecl()), FEnd; F != FEnd; ++F)
Douglas Gregora16548e2009-08-11 05:31:07 +00004713 Functions.insert(*F);
Mike Stump11289f42009-09-09 15:08:12 +00004714
Douglas Gregora16548e2009-08-11 05:31:07 +00004715 // Add any functions found via argument-dependent lookup.
4716 Expr *Args[2] = { FirstExpr, SecondExpr };
4717 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00004718 DeclarationName OpName
Douglas Gregora16548e2009-08-11 05:31:07 +00004719 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
4720 SemaRef.ArgumentDependentLookup(OpName, Args, NumArgs, Functions);
Mike Stump11289f42009-09-09 15:08:12 +00004721
Douglas Gregora16548e2009-08-11 05:31:07 +00004722 // Create the overloaded operator invocation for unary operators.
4723 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00004724 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00004725 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
4726 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
4727 }
Mike Stump11289f42009-09-09 15:08:12 +00004728
Douglas Gregora16548e2009-08-11 05:31:07 +00004729 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00004730 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00004731 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00004732 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00004733 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
4734 if (Result.isInvalid())
4735 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004736
Douglas Gregora16548e2009-08-11 05:31:07 +00004737 First.release();
4738 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00004739 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00004740}
Mike Stump11289f42009-09-09 15:08:12 +00004741
Douglas Gregord6ff3322009-08-04 16:50:30 +00004742} // end namespace clang
4743
4744#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H