blob: a3c9fa5628af09e2744de62911d702b44d81d0c6 [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>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002332QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
Mike Stump11289f42009-09-09 15:08:12 +00002333 const TemplateSpecializationType *T) {
2334 TemplateName Template
Douglas Gregord6ff3322009-08-04 16:50:30 +00002335 = getDerived().TransformTemplateName(T->getTemplateName());
2336 if (Template.isNull())
2337 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002338
Douglas Gregord6ff3322009-08-04 16:50:30 +00002339 llvm::SmallVector<TemplateArgument, 4> NewTemplateArgs;
2340 NewTemplateArgs.reserve(T->getNumArgs());
2341 for (TemplateSpecializationType::iterator Arg = T->begin(), ArgEnd = T->end();
2342 Arg != ArgEnd; ++Arg) {
2343 TemplateArgument NewArg = getDerived().TransformTemplateArgument(*Arg);
2344 if (NewArg.isNull())
2345 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002346
Douglas Gregord6ff3322009-08-04 16:50:30 +00002347 NewTemplateArgs.push_back(NewArg);
2348 }
Mike Stump11289f42009-09-09 15:08:12 +00002349
Douglas Gregord6ff3322009-08-04 16:50:30 +00002350 // FIXME: early abort if all of the template arguments and such are the
2351 // same.
Mike Stump11289f42009-09-09 15:08:12 +00002352
Douglas Gregord6ff3322009-08-04 16:50:30 +00002353 // FIXME: We're missing the locations of the template name, '<', and '>'.
2354 return getDerived().RebuildTemplateSpecializationType(Template,
2355 NewTemplateArgs.data(),
2356 NewTemplateArgs.size());
2357}
Mike Stump11289f42009-09-09 15:08:12 +00002358
2359template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002360QualType TreeTransform<Derived>::TransformQualifiedNameType(
2361 const QualifiedNameType *T) {
2362 NestedNameSpecifier *NNS
2363 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2364 SourceRange());
2365 if (!NNS)
2366 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002367
Douglas Gregord6ff3322009-08-04 16:50:30 +00002368 QualType Named = getDerived().TransformType(T->getNamedType());
2369 if (Named.isNull())
2370 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002371
Douglas Gregord6ff3322009-08-04 16:50:30 +00002372 if (!getDerived().AlwaysRebuild() &&
2373 NNS == T->getQualifier() &&
2374 Named == T->getNamedType())
2375 return QualType(T, 0);
2376
2377 return getDerived().RebuildQualifiedNameType(NNS, Named);
2378}
Mike Stump11289f42009-09-09 15:08:12 +00002379
2380template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002381QualType TreeTransform<Derived>::TransformTypenameType(const TypenameType *T) {
2382 NestedNameSpecifier *NNS
2383 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregor15acfb92009-08-06 16:20:37 +00002384 SourceRange(/*FIXME:*/getDerived().getBaseLocation()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002385 if (!NNS)
2386 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002387
Douglas Gregord6ff3322009-08-04 16:50:30 +00002388 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002389 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002390 = getDerived().TransformType(QualType(TemplateId, 0));
2391 if (NewTemplateId.isNull())
2392 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002393
Douglas Gregord6ff3322009-08-04 16:50:30 +00002394 if (!getDerived().AlwaysRebuild() &&
2395 NNS == T->getQualifier() &&
2396 NewTemplateId == QualType(TemplateId, 0))
2397 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002398
Douglas Gregord6ff3322009-08-04 16:50:30 +00002399 return getDerived().RebuildTypenameType(NNS, NewTemplateId);
2400 }
2401
2402 return getDerived().RebuildTypenameType(NNS, T->getIdentifier());
2403}
Mike Stump11289f42009-09-09 15:08:12 +00002404
Douglas Gregord6ff3322009-08-04 16:50:30 +00002405template<typename Derived>
2406QualType TreeTransform<Derived>::TransformObjCInterfaceType(
Mike Stump11289f42009-09-09 15:08:12 +00002407 const ObjCInterfaceType *T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002408 // FIXME: Implement
Mike Stump11289f42009-09-09 15:08:12 +00002409 return QualType(T, 0);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002410}
Mike Stump11289f42009-09-09 15:08:12 +00002411
2412template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002413QualType TreeTransform<Derived>::TransformObjCObjectPointerType(
Mike Stump11289f42009-09-09 15:08:12 +00002414 const ObjCObjectPointerType *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}
2418
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00002419template<typename Derived>
2420QualType TreeTransform<Derived>::TransformObjCProtocolListType(
2421 const ObjCProtocolListType *T) {
2422 assert(false && "Should not see ObjCProtocolList types");
2423 return QualType(T, 0);
2424}
2425
Douglas Gregord6ff3322009-08-04 16:50:30 +00002426//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00002427// Statement transformation
2428//===----------------------------------------------------------------------===//
2429template<typename Derived>
2430Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002431TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2432 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002433}
2434
2435template<typename Derived>
2436Sema::OwningStmtResult
2437TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2438 return getDerived().TransformCompoundStmt(S, false);
2439}
2440
2441template<typename Derived>
2442Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002443TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00002444 bool IsStmtExpr) {
2445 bool SubStmtChanged = false;
2446 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
2447 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
2448 B != BEnd; ++B) {
2449 OwningStmtResult Result = getDerived().TransformStmt(*B);
2450 if (Result.isInvalid())
2451 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002452
Douglas Gregorebe10102009-08-20 07:17:43 +00002453 SubStmtChanged = SubStmtChanged || Result.get() != *B;
2454 Statements.push_back(Result.takeAs<Stmt>());
2455 }
Mike Stump11289f42009-09-09 15:08:12 +00002456
Douglas Gregorebe10102009-08-20 07:17:43 +00002457 if (!getDerived().AlwaysRebuild() &&
2458 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00002459 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002460
2461 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
2462 move_arg(Statements),
2463 S->getRBracLoc(),
2464 IsStmtExpr);
2465}
Mike Stump11289f42009-09-09 15:08:12 +00002466
Douglas Gregorebe10102009-08-20 07:17:43 +00002467template<typename Derived>
2468Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002469TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002470 // The case value expressions are not potentially evaluated.
2471 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002472
Douglas Gregorebe10102009-08-20 07:17:43 +00002473 // Transform the left-hand case value.
2474 OwningExprResult LHS = getDerived().TransformExpr(S->getLHS());
2475 if (LHS.isInvalid())
2476 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002477
Douglas Gregorebe10102009-08-20 07:17:43 +00002478 // Transform the right-hand case value (for the GNU case-range extension).
2479 OwningExprResult RHS = getDerived().TransformExpr(S->getRHS());
2480 if (RHS.isInvalid())
2481 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002482
Douglas Gregorebe10102009-08-20 07:17:43 +00002483 // Build the case statement.
2484 // Case statements are always rebuilt so that they will attached to their
2485 // transformed switch statement.
2486 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
2487 move(LHS),
2488 S->getEllipsisLoc(),
2489 move(RHS),
2490 S->getColonLoc());
2491 if (Case.isInvalid())
2492 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002493
Douglas Gregorebe10102009-08-20 07:17:43 +00002494 // Transform the statement following the case
2495 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
2496 if (SubStmt.isInvalid())
2497 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002498
Douglas Gregorebe10102009-08-20 07:17:43 +00002499 // Attach the body to the case statement
2500 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
2501}
2502
2503template<typename Derived>
2504Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002505TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002506 // Transform the statement following the default case
2507 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
2508 if (SubStmt.isInvalid())
2509 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002510
Douglas Gregorebe10102009-08-20 07:17:43 +00002511 // Default statements are always rebuilt
2512 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
2513 move(SubStmt));
2514}
Mike Stump11289f42009-09-09 15:08:12 +00002515
Douglas Gregorebe10102009-08-20 07:17:43 +00002516template<typename Derived>
2517Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002518TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002519 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
2520 if (SubStmt.isInvalid())
2521 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002522
Douglas Gregorebe10102009-08-20 07:17:43 +00002523 // FIXME: Pass the real colon location in.
2524 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
2525 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
2526 move(SubStmt));
2527}
Mike Stump11289f42009-09-09 15:08:12 +00002528
Douglas Gregorebe10102009-08-20 07:17:43 +00002529template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002530Sema::OwningStmtResult
2531TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002532 // Transform the condition
2533 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
2534 if (Cond.isInvalid())
2535 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002536
Douglas Gregorebe10102009-08-20 07:17:43 +00002537 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00002538
Douglas Gregorebe10102009-08-20 07:17:43 +00002539 // Transform the "then" branch.
2540 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
2541 if (Then.isInvalid())
2542 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002543
Douglas Gregorebe10102009-08-20 07:17:43 +00002544 // Transform the "else" branch.
2545 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
2546 if (Else.isInvalid())
2547 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002548
Douglas Gregorebe10102009-08-20 07:17:43 +00002549 if (!getDerived().AlwaysRebuild() &&
2550 FullCond->get() == S->getCond() &&
2551 Then.get() == S->getThen() &&
2552 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00002553 return SemaRef.Owned(S->Retain());
2554
Douglas Gregorebe10102009-08-20 07:17:43 +00002555 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00002556 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00002557}
2558
2559template<typename Derived>
2560Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002561TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002562 // Transform the condition.
2563 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
2564 if (Cond.isInvalid())
2565 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002566
Douglas Gregorebe10102009-08-20 07:17:43 +00002567 // Rebuild the switch statement.
2568 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(move(Cond));
2569 if (Switch.isInvalid())
2570 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002571
Douglas Gregorebe10102009-08-20 07:17:43 +00002572 // Transform the body of the switch statement.
2573 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
2574 if (Body.isInvalid())
2575 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002576
Douglas Gregorebe10102009-08-20 07:17:43 +00002577 // Complete the switch statement.
2578 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
2579 move(Body));
2580}
Mike Stump11289f42009-09-09 15:08:12 +00002581
Douglas Gregorebe10102009-08-20 07:17:43 +00002582template<typename Derived>
2583Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002584TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002585 // Transform the condition
2586 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
2587 if (Cond.isInvalid())
2588 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002589
Douglas Gregorebe10102009-08-20 07:17:43 +00002590 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00002591
Douglas Gregorebe10102009-08-20 07:17:43 +00002592 // Transform the body
2593 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
2594 if (Body.isInvalid())
2595 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002596
Douglas Gregorebe10102009-08-20 07:17:43 +00002597 if (!getDerived().AlwaysRebuild() &&
2598 FullCond->get() == S->getCond() &&
2599 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00002600 return SemaRef.Owned(S->Retain());
2601
Douglas Gregorebe10102009-08-20 07:17:43 +00002602 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, move(Body));
2603}
Mike Stump11289f42009-09-09 15:08:12 +00002604
Douglas Gregorebe10102009-08-20 07:17:43 +00002605template<typename Derived>
2606Sema::OwningStmtResult
2607TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
2608 // Transform the condition
2609 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
2610 if (Cond.isInvalid())
2611 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002612
Douglas Gregorebe10102009-08-20 07:17:43 +00002613 // Transform the body
2614 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
2615 if (Body.isInvalid())
2616 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002617
Douglas Gregorebe10102009-08-20 07:17:43 +00002618 if (!getDerived().AlwaysRebuild() &&
2619 Cond.get() == S->getCond() &&
2620 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00002621 return SemaRef.Owned(S->Retain());
2622
Douglas Gregorebe10102009-08-20 07:17:43 +00002623 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
2624 /*FIXME:*/S->getWhileLoc(), move(Cond),
2625 S->getRParenLoc());
2626}
Mike Stump11289f42009-09-09 15:08:12 +00002627
Douglas Gregorebe10102009-08-20 07:17:43 +00002628template<typename Derived>
2629Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002630TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002631 // Transform the initialization statement
2632 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
2633 if (Init.isInvalid())
2634 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002635
Douglas Gregorebe10102009-08-20 07:17:43 +00002636 // Transform the condition
2637 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
2638 if (Cond.isInvalid())
2639 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002640
Douglas Gregorebe10102009-08-20 07:17:43 +00002641 // Transform the increment
2642 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
2643 if (Inc.isInvalid())
2644 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002645
Douglas Gregorebe10102009-08-20 07:17:43 +00002646 // Transform the body
2647 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
2648 if (Body.isInvalid())
2649 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002650
Douglas Gregorebe10102009-08-20 07:17:43 +00002651 if (!getDerived().AlwaysRebuild() &&
2652 Init.get() == S->getInit() &&
2653 Cond.get() == S->getCond() &&
2654 Inc.get() == S->getInc() &&
2655 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00002656 return SemaRef.Owned(S->Retain());
2657
Douglas Gregorebe10102009-08-20 07:17:43 +00002658 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
2659 move(Init), move(Cond), move(Inc),
2660 S->getRParenLoc(), move(Body));
2661}
2662
2663template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002664Sema::OwningStmtResult
2665TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002666 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00002667 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00002668 S->getLabel());
2669}
2670
2671template<typename Derived>
2672Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002673TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002674 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
2675 if (Target.isInvalid())
2676 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002677
Douglas Gregorebe10102009-08-20 07:17:43 +00002678 if (!getDerived().AlwaysRebuild() &&
2679 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00002680 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002681
2682 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
2683 move(Target));
2684}
2685
2686template<typename Derived>
2687Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002688TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
2689 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002690}
Mike Stump11289f42009-09-09 15:08:12 +00002691
Douglas Gregorebe10102009-08-20 07:17:43 +00002692template<typename Derived>
2693Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002694TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
2695 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002696}
Mike Stump11289f42009-09-09 15:08:12 +00002697
Douglas Gregorebe10102009-08-20 07:17:43 +00002698template<typename Derived>
2699Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002700TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002701 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
2702 if (Result.isInvalid())
2703 return SemaRef.StmtError();
2704
Mike Stump11289f42009-09-09 15:08:12 +00002705 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00002706 // to tell whether the return type of the function has changed.
2707 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
2708}
Mike Stump11289f42009-09-09 15:08:12 +00002709
Douglas Gregorebe10102009-08-20 07:17:43 +00002710template<typename Derived>
2711Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002712TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002713 bool DeclChanged = false;
2714 llvm::SmallVector<Decl *, 4> Decls;
2715 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
2716 D != DEnd; ++D) {
2717 Decl *Transformed = getDerived().TransformDefinition(*D);
2718 if (!Transformed)
2719 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002720
Douglas Gregorebe10102009-08-20 07:17:43 +00002721 if (Transformed != *D)
2722 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00002723
Douglas Gregorebe10102009-08-20 07:17:43 +00002724 Decls.push_back(Transformed);
2725 }
Mike Stump11289f42009-09-09 15:08:12 +00002726
Douglas Gregorebe10102009-08-20 07:17:43 +00002727 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00002728 return SemaRef.Owned(S->Retain());
2729
2730 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00002731 S->getStartLoc(), S->getEndLoc());
2732}
Mike Stump11289f42009-09-09 15:08:12 +00002733
Douglas Gregorebe10102009-08-20 07:17:43 +00002734template<typename Derived>
2735Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002736TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002737 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00002738 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002739}
2740
2741template<typename Derived>
2742Sema::OwningStmtResult
2743TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
2744 // FIXME: Implement!
2745 assert(false && "Inline assembly cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00002746 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002747}
2748
2749
2750template<typename Derived>
2751Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002752TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002753 // FIXME: Implement this
2754 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00002755 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002756}
Mike Stump11289f42009-09-09 15:08:12 +00002757
Douglas Gregorebe10102009-08-20 07:17:43 +00002758template<typename Derived>
2759Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002760TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002761 // FIXME: Implement this
2762 assert(false && "Cannot transform an Objective-C @catch statement");
2763 return SemaRef.Owned(S->Retain());
2764}
Mike Stump11289f42009-09-09 15:08:12 +00002765
Douglas Gregorebe10102009-08-20 07:17:43 +00002766template<typename Derived>
2767Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002768TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002769 // FIXME: Implement this
2770 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00002771 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002772}
Mike Stump11289f42009-09-09 15:08:12 +00002773
Douglas Gregorebe10102009-08-20 07:17:43 +00002774template<typename Derived>
2775Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002776TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002777 // FIXME: Implement this
2778 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00002779 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002780}
Mike Stump11289f42009-09-09 15:08:12 +00002781
Douglas Gregorebe10102009-08-20 07:17:43 +00002782template<typename Derived>
2783Sema::OwningStmtResult
2784TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00002785 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002786 // FIXME: Implement this
2787 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00002788 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002789}
2790
2791template<typename Derived>
2792Sema::OwningStmtResult
2793TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00002794 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002795 // FIXME: Implement this
2796 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00002797 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002798}
2799
2800
2801template<typename Derived>
2802Sema::OwningStmtResult
2803TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
2804 // Transform the exception declaration, if any.
2805 VarDecl *Var = 0;
2806 if (S->getExceptionDecl()) {
2807 VarDecl *ExceptionDecl = S->getExceptionDecl();
2808 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
2809 ExceptionDecl->getDeclName());
2810
2811 QualType T = getDerived().TransformType(ExceptionDecl->getType());
2812 if (T.isNull())
2813 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002814
Douglas Gregorebe10102009-08-20 07:17:43 +00002815 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
2816 T,
2817 ExceptionDecl->getDeclaratorInfo(),
2818 ExceptionDecl->getIdentifier(),
2819 ExceptionDecl->getLocation(),
2820 /*FIXME: Inaccurate*/
2821 SourceRange(ExceptionDecl->getLocation()));
2822 if (!Var || Var->isInvalidDecl()) {
2823 if (Var)
2824 Var->Destroy(SemaRef.Context);
2825 return SemaRef.StmtError();
2826 }
2827 }
Mike Stump11289f42009-09-09 15:08:12 +00002828
Douglas Gregorebe10102009-08-20 07:17:43 +00002829 // Transform the actual exception handler.
2830 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
2831 if (Handler.isInvalid()) {
2832 if (Var)
2833 Var->Destroy(SemaRef.Context);
2834 return SemaRef.StmtError();
2835 }
Mike Stump11289f42009-09-09 15:08:12 +00002836
Douglas Gregorebe10102009-08-20 07:17:43 +00002837 if (!getDerived().AlwaysRebuild() &&
2838 !Var &&
2839 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00002840 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002841
2842 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
2843 Var,
2844 move(Handler));
2845}
Mike Stump11289f42009-09-09 15:08:12 +00002846
Douglas Gregorebe10102009-08-20 07:17:43 +00002847template<typename Derived>
2848Sema::OwningStmtResult
2849TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
2850 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00002851 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00002852 = getDerived().TransformCompoundStmt(S->getTryBlock());
2853 if (TryBlock.isInvalid())
2854 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002855
Douglas Gregorebe10102009-08-20 07:17:43 +00002856 // Transform the handlers.
2857 bool HandlerChanged = false;
2858 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
2859 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00002860 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00002861 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
2862 if (Handler.isInvalid())
2863 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002864
Douglas Gregorebe10102009-08-20 07:17:43 +00002865 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
2866 Handlers.push_back(Handler.takeAs<Stmt>());
2867 }
Mike Stump11289f42009-09-09 15:08:12 +00002868
Douglas Gregorebe10102009-08-20 07:17:43 +00002869 if (!getDerived().AlwaysRebuild() &&
2870 TryBlock.get() == S->getTryBlock() &&
2871 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00002872 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002873
2874 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00002875 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00002876}
Mike Stump11289f42009-09-09 15:08:12 +00002877
Douglas Gregorebe10102009-08-20 07:17:43 +00002878//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00002879// Expression transformation
2880//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00002881template<typename Derived>
2882Sema::OwningExprResult
2883TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
2884 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00002885}
Mike Stump11289f42009-09-09 15:08:12 +00002886
2887template<typename Derived>
2888Sema::OwningExprResult
2889TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
2890 NamedDecl *ND
Douglas Gregora16548e2009-08-11 05:31:07 +00002891 = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl()));
2892 if (!ND)
2893 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002894
Douglas Gregora16548e2009-08-11 05:31:07 +00002895 if (!getDerived().AlwaysRebuild() && ND == E->getDecl())
Mike Stump11289f42009-09-09 15:08:12 +00002896 return SemaRef.Owned(E->Retain());
2897
Douglas Gregora16548e2009-08-11 05:31:07 +00002898 return getDerived().RebuildDeclRefExpr(ND, E->getLocation());
2899}
Mike Stump11289f42009-09-09 15:08:12 +00002900
Douglas Gregora16548e2009-08-11 05:31:07 +00002901template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002902Sema::OwningExprResult
2903TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
2904 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00002905}
Mike Stump11289f42009-09-09 15:08:12 +00002906
Douglas Gregora16548e2009-08-11 05:31:07 +00002907template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002908Sema::OwningExprResult
2909TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
2910 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00002911}
Mike Stump11289f42009-09-09 15:08:12 +00002912
Douglas Gregora16548e2009-08-11 05:31:07 +00002913template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002914Sema::OwningExprResult
2915TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
2916 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00002917}
Mike Stump11289f42009-09-09 15:08:12 +00002918
Douglas Gregora16548e2009-08-11 05:31:07 +00002919template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002920Sema::OwningExprResult
2921TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
2922 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00002923}
Mike Stump11289f42009-09-09 15:08:12 +00002924
Douglas Gregora16548e2009-08-11 05:31:07 +00002925template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002926Sema::OwningExprResult
2927TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
2928 return SemaRef.Owned(E->Retain());
2929}
2930
2931template<typename Derived>
2932Sema::OwningExprResult
2933TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002934 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
2935 if (SubExpr.isInvalid())
2936 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002937
Douglas Gregora16548e2009-08-11 05:31:07 +00002938 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00002939 return SemaRef.Owned(E->Retain());
2940
2941 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002942 E->getRParen());
2943}
2944
Mike Stump11289f42009-09-09 15:08:12 +00002945template<typename Derived>
2946Sema::OwningExprResult
2947TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002948 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
2949 if (SubExpr.isInvalid())
2950 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002951
Douglas Gregora16548e2009-08-11 05:31:07 +00002952 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00002953 return SemaRef.Owned(E->Retain());
2954
Douglas Gregora16548e2009-08-11 05:31:07 +00002955 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
2956 E->getOpcode(),
2957 move(SubExpr));
2958}
Mike Stump11289f42009-09-09 15:08:12 +00002959
Douglas Gregora16548e2009-08-11 05:31:07 +00002960template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002961Sema::OwningExprResult
2962TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002963 if (E->isArgumentType()) {
2964 QualType T = getDerived().TransformType(E->getArgumentType());
2965 if (T.isNull())
2966 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002967
Douglas Gregora16548e2009-08-11 05:31:07 +00002968 if (!getDerived().AlwaysRebuild() && T == E->getArgumentType())
2969 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00002970
2971 return getDerived().RebuildSizeOfAlignOf(T, E->getOperatorLoc(),
2972 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002973 E->getSourceRange());
2974 }
Mike Stump11289f42009-09-09 15:08:12 +00002975
Douglas Gregora16548e2009-08-11 05:31:07 +00002976 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00002977 {
Douglas Gregora16548e2009-08-11 05:31:07 +00002978 // C++0x [expr.sizeof]p1:
2979 // The operand is either an expression, which is an unevaluated operand
2980 // [...]
2981 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002982
Douglas Gregora16548e2009-08-11 05:31:07 +00002983 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
2984 if (SubExpr.isInvalid())
2985 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002986
Douglas Gregora16548e2009-08-11 05:31:07 +00002987 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
2988 return SemaRef.Owned(E->Retain());
2989 }
Mike Stump11289f42009-09-09 15:08:12 +00002990
Douglas Gregora16548e2009-08-11 05:31:07 +00002991 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
2992 E->isSizeOf(),
2993 E->getSourceRange());
2994}
Mike Stump11289f42009-09-09 15:08:12 +00002995
Douglas Gregora16548e2009-08-11 05:31:07 +00002996template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002997Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00002998TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
2999 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3000 if (LHS.isInvalid())
3001 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003002
Douglas Gregora16548e2009-08-11 05:31:07 +00003003 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3004 if (RHS.isInvalid())
3005 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003006
3007
Douglas Gregora16548e2009-08-11 05:31:07 +00003008 if (!getDerived().AlwaysRebuild() &&
3009 LHS.get() == E->getLHS() &&
3010 RHS.get() == E->getRHS())
3011 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003012
Douglas Gregora16548e2009-08-11 05:31:07 +00003013 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3014 /*FIXME:*/E->getLHS()->getLocStart(),
3015 move(RHS),
3016 E->getRBracketLoc());
3017}
Mike Stump11289f42009-09-09 15:08:12 +00003018
3019template<typename Derived>
3020Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003021TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
3022 // Transform the callee.
3023 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3024 if (Callee.isInvalid())
3025 return SemaRef.ExprError();
3026
3027 // Transform arguments.
3028 bool ArgChanged = false;
3029 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3030 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3031 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3032 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3033 if (Arg.isInvalid())
3034 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003035
Douglas Gregora16548e2009-08-11 05:31:07 +00003036 // FIXME: Wrong source location information for the ','.
3037 FakeCommaLocs.push_back(
3038 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003039
3040 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003041 Args.push_back(Arg.takeAs<Expr>());
3042 }
Mike Stump11289f42009-09-09 15:08:12 +00003043
Douglas Gregora16548e2009-08-11 05:31:07 +00003044 if (!getDerived().AlwaysRebuild() &&
3045 Callee.get() == E->getCallee() &&
3046 !ArgChanged)
3047 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003048
Douglas Gregora16548e2009-08-11 05:31:07 +00003049 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003050 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003051 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3052 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3053 move_arg(Args),
3054 FakeCommaLocs.data(),
3055 E->getRParenLoc());
3056}
Mike Stump11289f42009-09-09 15:08:12 +00003057
3058template<typename Derived>
3059Sema::OwningExprResult
3060TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003061 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3062 if (Base.isInvalid())
3063 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003064
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003065 NestedNameSpecifier *Qualifier = 0;
3066 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003067 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003068 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3069 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003070 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003071 return SemaRef.ExprError();
3072 }
Mike Stump11289f42009-09-09 15:08:12 +00003073
3074 NamedDecl *Member
Douglas Gregora16548e2009-08-11 05:31:07 +00003075 = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getMemberDecl()));
3076 if (!Member)
3077 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003078
Douglas Gregora16548e2009-08-11 05:31:07 +00003079 if (!getDerived().AlwaysRebuild() &&
3080 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003081 Qualifier == E->getQualifier() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003082 Member == E->getMemberDecl())
Mike Stump11289f42009-09-09 15:08:12 +00003083 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003084
3085 // FIXME: Bogus source location for the operator
3086 SourceLocation FakeOperatorLoc
3087 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3088
3089 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3090 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003091 Qualifier,
3092 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003093 E->getMemberLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003094 Member);
Douglas Gregora16548e2009-08-11 05:31:07 +00003095}
Mike Stump11289f42009-09-09 15:08:12 +00003096
Douglas Gregora16548e2009-08-11 05:31:07 +00003097template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003098Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003099TreeTransform<Derived>::TransformCastExpr(CastExpr *E) {
3100 assert(false && "Cannot transform abstract class");
3101 return SemaRef.Owned(E->Retain());
3102}
3103
3104template<typename Derived>
3105Sema::OwningExprResult
3106TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003107 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3108 if (LHS.isInvalid())
3109 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003110
Douglas Gregora16548e2009-08-11 05:31:07 +00003111 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3112 if (RHS.isInvalid())
3113 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003114
Douglas Gregora16548e2009-08-11 05:31:07 +00003115 if (!getDerived().AlwaysRebuild() &&
3116 LHS.get() == E->getLHS() &&
3117 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003118 return SemaRef.Owned(E->Retain());
3119
Douglas Gregora16548e2009-08-11 05:31:07 +00003120 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3121 move(LHS), move(RHS));
3122}
3123
Mike Stump11289f42009-09-09 15:08:12 +00003124template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003125Sema::OwningExprResult
3126TreeTransform<Derived>::TransformCompoundAssignOperator(
3127 CompoundAssignOperator *E) {
3128 return getDerived().TransformBinaryOperator(E);
3129}
Mike Stump11289f42009-09-09 15:08:12 +00003130
Douglas Gregora16548e2009-08-11 05:31:07 +00003131template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003132Sema::OwningExprResult
3133TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003134 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3135 if (Cond.isInvalid())
3136 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003137
Douglas Gregora16548e2009-08-11 05:31:07 +00003138 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3139 if (LHS.isInvalid())
3140 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003141
Douglas Gregora16548e2009-08-11 05:31:07 +00003142 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3143 if (RHS.isInvalid())
3144 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003145
Douglas Gregora16548e2009-08-11 05:31:07 +00003146 if (!getDerived().AlwaysRebuild() &&
3147 Cond.get() == E->getCond() &&
3148 LHS.get() == E->getLHS() &&
3149 RHS.get() == E->getRHS())
3150 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003151
3152 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003153 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003154 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003155 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003156 move(RHS));
3157}
Mike Stump11289f42009-09-09 15:08:12 +00003158
3159template<typename Derived>
3160Sema::OwningExprResult
3161TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003162 QualType T = getDerived().TransformType(E->getType());
3163 if (T.isNull())
3164 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003165
Douglas Gregora16548e2009-08-11 05:31:07 +00003166 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3167 if (SubExpr.isInvalid())
3168 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003169
Douglas Gregora16548e2009-08-11 05:31:07 +00003170 if (!getDerived().AlwaysRebuild() &&
3171 T == E->getType() &&
3172 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003173 return SemaRef.Owned(E->Retain());
3174
Douglas Gregora16548e2009-08-11 05:31:07 +00003175 return getDerived().RebuildImplicitCastExpr(T, E->getCastKind(),
Mike Stump11289f42009-09-09 15:08:12 +00003176 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00003177 E->isLvalueCast());
3178}
Mike Stump11289f42009-09-09 15:08:12 +00003179
Douglas Gregora16548e2009-08-11 05:31:07 +00003180template<typename Derived>
3181Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003182TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) {
3183 assert(false && "Cannot transform abstract class");
3184 return SemaRef.Owned(E->Retain());
3185}
3186
3187template<typename Derived>
3188Sema::OwningExprResult
3189TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003190 QualType T;
3191 {
3192 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003193 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003194 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3195 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003196
Douglas Gregora16548e2009-08-11 05:31:07 +00003197 T = getDerived().TransformType(E->getTypeAsWritten());
3198 if (T.isNull())
3199 return SemaRef.ExprError();
3200 }
Mike Stump11289f42009-09-09 15:08:12 +00003201
Douglas Gregora16548e2009-08-11 05:31:07 +00003202 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3203 if (SubExpr.isInvalid())
3204 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003205
Douglas Gregora16548e2009-08-11 05:31:07 +00003206 if (!getDerived().AlwaysRebuild() &&
3207 T == E->getTypeAsWritten() &&
3208 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003209 return SemaRef.Owned(E->Retain());
3210
Douglas Gregora16548e2009-08-11 05:31:07 +00003211 return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T,
3212 E->getRParenLoc(),
3213 move(SubExpr));
3214}
Mike Stump11289f42009-09-09 15:08:12 +00003215
Douglas Gregora16548e2009-08-11 05:31:07 +00003216template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003217Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003218TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
3219 QualType T;
3220 {
3221 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003222 SourceLocation FakeTypeLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003223 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3224 TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003225
Douglas Gregora16548e2009-08-11 05:31:07 +00003226 T = getDerived().TransformType(E->getType());
3227 if (T.isNull())
3228 return SemaRef.ExprError();
3229 }
Mike Stump11289f42009-09-09 15:08:12 +00003230
Douglas Gregora16548e2009-08-11 05:31:07 +00003231 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3232 if (Init.isInvalid())
3233 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003234
Douglas Gregora16548e2009-08-11 05:31:07 +00003235 if (!getDerived().AlwaysRebuild() &&
3236 T == E->getType() &&
3237 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003238 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003239
3240 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T,
3241 /*FIXME:*/E->getInitializer()->getLocEnd(),
3242 move(Init));
3243}
Mike Stump11289f42009-09-09 15:08:12 +00003244
Douglas Gregora16548e2009-08-11 05:31:07 +00003245template<typename Derived>
3246Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003247TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003248 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3249 if (Base.isInvalid())
3250 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003251
Douglas Gregora16548e2009-08-11 05:31:07 +00003252 if (!getDerived().AlwaysRebuild() &&
3253 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003254 return SemaRef.Owned(E->Retain());
3255
Douglas Gregora16548e2009-08-11 05:31:07 +00003256 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003257 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003258 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3259 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3260 E->getAccessorLoc(),
3261 E->getAccessor());
3262}
Mike Stump11289f42009-09-09 15:08:12 +00003263
Douglas Gregora16548e2009-08-11 05:31:07 +00003264template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003265Sema::OwningExprResult
3266TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003267 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003268
Douglas Gregora16548e2009-08-11 05:31:07 +00003269 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3270 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3271 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3272 if (Init.isInvalid())
3273 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003274
Douglas Gregora16548e2009-08-11 05:31:07 +00003275 InitChanged = InitChanged || Init.get() != E->getInit(I);
3276 Inits.push_back(Init.takeAs<Expr>());
3277 }
Mike Stump11289f42009-09-09 15:08:12 +00003278
Douglas Gregora16548e2009-08-11 05:31:07 +00003279 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003280 return SemaRef.Owned(E->Retain());
3281
Douglas Gregora16548e2009-08-11 05:31:07 +00003282 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
3283 E->getRBraceLoc());
3284}
Mike Stump11289f42009-09-09 15:08:12 +00003285
Douglas Gregora16548e2009-08-11 05:31:07 +00003286template<typename Derived>
3287Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003288TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003289 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00003290
Douglas Gregorebe10102009-08-20 07:17:43 +00003291 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00003292 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3293 if (Init.isInvalid())
3294 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003295
Douglas Gregorebe10102009-08-20 07:17:43 +00003296 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00003297 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3298 bool ExprChanged = false;
3299 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3300 DEnd = E->designators_end();
3301 D != DEnd; ++D) {
3302 if (D->isFieldDesignator()) {
3303 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3304 D->getDotLoc(),
3305 D->getFieldLoc()));
3306 continue;
3307 }
Mike Stump11289f42009-09-09 15:08:12 +00003308
Douglas Gregora16548e2009-08-11 05:31:07 +00003309 if (D->isArrayDesignator()) {
3310 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3311 if (Index.isInvalid())
3312 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003313
3314 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003315 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003316
Douglas Gregora16548e2009-08-11 05:31:07 +00003317 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3318 ArrayExprs.push_back(Index.release());
3319 continue;
3320 }
Mike Stump11289f42009-09-09 15:08:12 +00003321
Douglas Gregora16548e2009-08-11 05:31:07 +00003322 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00003323 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00003324 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3325 if (Start.isInvalid())
3326 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003327
Douglas Gregora16548e2009-08-11 05:31:07 +00003328 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3329 if (End.isInvalid())
3330 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003331
3332 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003333 End.get(),
3334 D->getLBracketLoc(),
3335 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003336
Douglas Gregora16548e2009-08-11 05:31:07 +00003337 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
3338 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00003339
Douglas Gregora16548e2009-08-11 05:31:07 +00003340 ArrayExprs.push_back(Start.release());
3341 ArrayExprs.push_back(End.release());
3342 }
Mike Stump11289f42009-09-09 15:08:12 +00003343
Douglas Gregora16548e2009-08-11 05:31:07 +00003344 if (!getDerived().AlwaysRebuild() &&
3345 Init.get() == E->getInit() &&
3346 !ExprChanged)
3347 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003348
Douglas Gregora16548e2009-08-11 05:31:07 +00003349 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
3350 E->getEqualOrColonLoc(),
3351 E->usesGNUSyntax(), move(Init));
3352}
Mike Stump11289f42009-09-09 15:08:12 +00003353
Douglas Gregora16548e2009-08-11 05:31:07 +00003354template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003355Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003356TreeTransform<Derived>::TransformImplicitValueInitExpr(
Mike Stump11289f42009-09-09 15:08:12 +00003357 ImplicitValueInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003358 QualType T = getDerived().TransformType(E->getType());
3359 if (T.isNull())
3360 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003361
Douglas Gregora16548e2009-08-11 05:31:07 +00003362 if (!getDerived().AlwaysRebuild() &&
3363 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00003364 return SemaRef.Owned(E->Retain());
3365
Douglas Gregora16548e2009-08-11 05:31:07 +00003366 return getDerived().RebuildImplicitValueInitExpr(T);
3367}
Mike Stump11289f42009-09-09 15:08:12 +00003368
Douglas Gregora16548e2009-08-11 05:31:07 +00003369template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003370Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003371TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
3372 // FIXME: Do we want the type as written?
3373 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00003374
Douglas Gregora16548e2009-08-11 05:31:07 +00003375 {
3376 // FIXME: Source location isn't quite accurate.
3377 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
3378 T = getDerived().TransformType(E->getType());
3379 if (T.isNull())
3380 return SemaRef.ExprError();
3381 }
Mike Stump11289f42009-09-09 15:08:12 +00003382
Douglas Gregora16548e2009-08-11 05:31:07 +00003383 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3384 if (SubExpr.isInvalid())
3385 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003386
Douglas Gregora16548e2009-08-11 05:31:07 +00003387 if (!getDerived().AlwaysRebuild() &&
3388 T == E->getType() &&
3389 SubExpr.get() == E->getSubExpr())
3390 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003391
Douglas Gregora16548e2009-08-11 05:31:07 +00003392 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
3393 T, E->getRParenLoc());
3394}
3395
3396template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003397Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003398TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
3399 bool ArgumentChanged = false;
3400 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3401 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
3402 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
3403 if (Init.isInvalid())
3404 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003405
Douglas Gregora16548e2009-08-11 05:31:07 +00003406 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
3407 Inits.push_back(Init.takeAs<Expr>());
3408 }
Mike Stump11289f42009-09-09 15:08:12 +00003409
Douglas Gregora16548e2009-08-11 05:31:07 +00003410 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
3411 move_arg(Inits),
3412 E->getRParenLoc());
3413}
Mike Stump11289f42009-09-09 15:08:12 +00003414
Douglas Gregora16548e2009-08-11 05:31:07 +00003415/// \brief Transform an address-of-label expression.
3416///
3417/// By default, the transformation of an address-of-label expression always
3418/// rebuilds the expression, so that the label identifier can be resolved to
3419/// the corresponding label statement by semantic analysis.
3420template<typename Derived>
3421Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003422TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003423 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
3424 E->getLabel());
3425}
Mike Stump11289f42009-09-09 15:08:12 +00003426
3427template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003428Sema::OwningExprResult TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003429 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00003430 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
3431 if (SubStmt.isInvalid())
3432 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003433
Douglas Gregora16548e2009-08-11 05:31:07 +00003434 if (!getDerived().AlwaysRebuild() &&
3435 SubStmt.get() == E->getSubStmt())
3436 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003437
3438 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003439 move(SubStmt),
3440 E->getRParenLoc());
3441}
Mike Stump11289f42009-09-09 15:08:12 +00003442
Douglas Gregora16548e2009-08-11 05:31:07 +00003443template<typename Derived>
3444Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003445TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003446 QualType T1, T2;
3447 {
3448 // FIXME: Source location isn't quite accurate.
3449 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003450
Douglas Gregora16548e2009-08-11 05:31:07 +00003451 T1 = getDerived().TransformType(E->getArgType1());
3452 if (T1.isNull())
3453 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003454
Douglas Gregora16548e2009-08-11 05:31:07 +00003455 T2 = getDerived().TransformType(E->getArgType2());
3456 if (T2.isNull())
3457 return SemaRef.ExprError();
3458 }
3459
3460 if (!getDerived().AlwaysRebuild() &&
3461 T1 == E->getArgType1() &&
3462 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00003463 return SemaRef.Owned(E->Retain());
3464
Douglas Gregora16548e2009-08-11 05:31:07 +00003465 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
3466 T1, T2, E->getRParenLoc());
3467}
Mike Stump11289f42009-09-09 15:08:12 +00003468
Douglas Gregora16548e2009-08-11 05:31:07 +00003469template<typename Derived>
3470Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003471TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003472 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3473 if (Cond.isInvalid())
3474 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003475
Douglas Gregora16548e2009-08-11 05:31:07 +00003476 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3477 if (LHS.isInvalid())
3478 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003479
Douglas Gregora16548e2009-08-11 05:31:07 +00003480 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3481 if (RHS.isInvalid())
3482 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003483
Douglas Gregora16548e2009-08-11 05:31:07 +00003484 if (!getDerived().AlwaysRebuild() &&
3485 Cond.get() == E->getCond() &&
3486 LHS.get() == E->getLHS() &&
3487 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003488 return SemaRef.Owned(E->Retain());
3489
Douglas Gregora16548e2009-08-11 05:31:07 +00003490 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
3491 move(Cond), move(LHS), move(RHS),
3492 E->getRParenLoc());
3493}
Mike Stump11289f42009-09-09 15:08:12 +00003494
Douglas Gregora16548e2009-08-11 05:31:07 +00003495template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003496Sema::OwningExprResult
3497TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
3498 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003499}
3500
3501template<typename Derived>
3502Sema::OwningExprResult
3503TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
3504 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3505 if (Callee.isInvalid())
3506 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003507
Douglas Gregora16548e2009-08-11 05:31:07 +00003508 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
3509 if (First.isInvalid())
3510 return SemaRef.ExprError();
3511
3512 OwningExprResult Second(SemaRef);
3513 if (E->getNumArgs() == 2) {
3514 Second = getDerived().TransformExpr(E->getArg(1));
3515 if (Second.isInvalid())
3516 return SemaRef.ExprError();
3517 }
Mike Stump11289f42009-09-09 15:08:12 +00003518
Douglas Gregora16548e2009-08-11 05:31:07 +00003519 if (!getDerived().AlwaysRebuild() &&
3520 Callee.get() == E->getCallee() &&
3521 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00003522 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
3523 return SemaRef.Owned(E->Retain());
3524
Douglas Gregora16548e2009-08-11 05:31:07 +00003525 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
3526 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003527 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00003528 move(First),
3529 move(Second));
3530}
Mike Stump11289f42009-09-09 15:08:12 +00003531
Douglas Gregora16548e2009-08-11 05:31:07 +00003532template<typename Derived>
3533Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003534TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003535 return getDerived().TransformCallExpr(E);
3536}
Mike Stump11289f42009-09-09 15:08:12 +00003537
Douglas Gregora16548e2009-08-11 05:31:07 +00003538template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003539Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003540TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
3541 QualType ExplicitTy;
3542 {
3543 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003544 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003545 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
3546 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003547
Douglas Gregora16548e2009-08-11 05:31:07 +00003548 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
3549 if (ExplicitTy.isNull())
3550 return SemaRef.ExprError();
3551 }
Mike Stump11289f42009-09-09 15:08:12 +00003552
Douglas Gregora16548e2009-08-11 05:31:07 +00003553 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3554 if (SubExpr.isInvalid())
3555 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003556
Douglas Gregora16548e2009-08-11 05:31:07 +00003557 if (!getDerived().AlwaysRebuild() &&
3558 ExplicitTy == E->getTypeAsWritten() &&
3559 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003560 return SemaRef.Owned(E->Retain());
3561
Douglas Gregora16548e2009-08-11 05:31:07 +00003562 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00003563 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003564 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
3565 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
3566 SourceLocation FakeRParenLoc
3567 = SemaRef.PP.getLocForEndOfToken(
3568 E->getSubExpr()->getSourceRange().getEnd());
3569 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003570 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003571 FakeLAngleLoc,
3572 ExplicitTy,
3573 FakeRAngleLoc,
3574 FakeRAngleLoc,
3575 move(SubExpr),
3576 FakeRParenLoc);
3577}
Mike Stump11289f42009-09-09 15:08:12 +00003578
Douglas Gregora16548e2009-08-11 05:31:07 +00003579template<typename Derived>
3580Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003581TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003582 return getDerived().TransformCXXNamedCastExpr(E);
3583}
Mike Stump11289f42009-09-09 15:08:12 +00003584
3585template<typename Derived>
3586Sema::OwningExprResult
3587TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
3588 return getDerived().TransformCXXNamedCastExpr(E);
3589}
3590
Douglas Gregora16548e2009-08-11 05:31:07 +00003591template<typename Derived>
3592Sema::OwningExprResult
3593TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
Mike Stump11289f42009-09-09 15:08:12 +00003594 CXXReinterpretCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003595 return getDerived().TransformCXXNamedCastExpr(E);
3596}
Mike Stump11289f42009-09-09 15:08:12 +00003597
Douglas Gregora16548e2009-08-11 05:31:07 +00003598template<typename Derived>
3599Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003600TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003601 return getDerived().TransformCXXNamedCastExpr(E);
3602}
Mike Stump11289f42009-09-09 15:08:12 +00003603
Douglas Gregora16548e2009-08-11 05:31:07 +00003604template<typename Derived>
3605Sema::OwningExprResult
3606TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
Mike Stump11289f42009-09-09 15:08:12 +00003607 CXXFunctionalCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003608 QualType ExplicitTy;
3609 {
3610 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003611
Douglas Gregora16548e2009-08-11 05:31:07 +00003612 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
3613 if (ExplicitTy.isNull())
3614 return SemaRef.ExprError();
3615 }
Mike Stump11289f42009-09-09 15:08:12 +00003616
Douglas Gregora16548e2009-08-11 05:31:07 +00003617 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3618 if (SubExpr.isInvalid())
3619 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003620
Douglas Gregora16548e2009-08-11 05:31:07 +00003621 if (!getDerived().AlwaysRebuild() &&
3622 ExplicitTy == E->getTypeAsWritten() &&
3623 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003624 return SemaRef.Owned(E->Retain());
3625
Douglas Gregora16548e2009-08-11 05:31:07 +00003626 // FIXME: The end of the type's source range is wrong
3627 return getDerived().RebuildCXXFunctionalCastExpr(
3628 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
3629 ExplicitTy,
3630 /*FIXME:*/E->getSubExpr()->getLocStart(),
3631 move(SubExpr),
3632 E->getRParenLoc());
3633}
Mike Stump11289f42009-09-09 15:08:12 +00003634
Douglas Gregora16548e2009-08-11 05:31:07 +00003635template<typename Derived>
3636Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003637TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003638 if (E->isTypeOperand()) {
3639 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003640
Douglas Gregora16548e2009-08-11 05:31:07 +00003641 QualType T = getDerived().TransformType(E->getTypeOperand());
3642 if (T.isNull())
3643 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003644
Douglas Gregora16548e2009-08-11 05:31:07 +00003645 if (!getDerived().AlwaysRebuild() &&
3646 T == E->getTypeOperand())
3647 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003648
Douglas Gregora16548e2009-08-11 05:31:07 +00003649 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
3650 /*FIXME:*/E->getLocStart(),
3651 T,
3652 E->getLocEnd());
3653 }
Mike Stump11289f42009-09-09 15:08:12 +00003654
Douglas Gregora16548e2009-08-11 05:31:07 +00003655 // We don't know whether the expression is potentially evaluated until
3656 // after we perform semantic analysis, so the expression is potentially
3657 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00003658 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00003659 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003660
Douglas Gregora16548e2009-08-11 05:31:07 +00003661 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
3662 if (SubExpr.isInvalid())
3663 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003664
Douglas Gregora16548e2009-08-11 05:31:07 +00003665 if (!getDerived().AlwaysRebuild() &&
3666 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00003667 return SemaRef.Owned(E->Retain());
3668
Douglas Gregora16548e2009-08-11 05:31:07 +00003669 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
3670 /*FIXME:*/E->getLocStart(),
3671 move(SubExpr),
3672 E->getLocEnd());
3673}
3674
3675template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003676Sema::OwningExprResult
3677TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
3678 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003679}
Mike Stump11289f42009-09-09 15:08:12 +00003680
Douglas Gregora16548e2009-08-11 05:31:07 +00003681template<typename Derived>
3682Sema::OwningExprResult
3683TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
Mike Stump11289f42009-09-09 15:08:12 +00003684 CXXNullPtrLiteralExpr *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>::TransformCXXThisExpr(CXXThisExpr *E) {
3691 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003692
Douglas Gregora16548e2009-08-11 05:31:07 +00003693 QualType T = getDerived().TransformType(E->getType());
3694 if (T.isNull())
3695 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003696
Douglas Gregora16548e2009-08-11 05:31:07 +00003697 if (!getDerived().AlwaysRebuild() &&
3698 T == E->getType())
3699 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003700
Douglas Gregora16548e2009-08-11 05:31:07 +00003701 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T);
3702}
Mike Stump11289f42009-09-09 15:08:12 +00003703
Douglas Gregora16548e2009-08-11 05:31:07 +00003704template<typename Derived>
3705Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003706TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003707 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3708 if (SubExpr.isInvalid())
3709 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003710
Douglas Gregora16548e2009-08-11 05:31:07 +00003711 if (!getDerived().AlwaysRebuild() &&
3712 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003713 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003714
3715 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
3716}
Mike Stump11289f42009-09-09 15:08:12 +00003717
Douglas Gregora16548e2009-08-11 05:31:07 +00003718template<typename Derived>
3719Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003720TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
3721 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00003722 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
3723 if (!Param)
3724 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003725
Douglas Gregora16548e2009-08-11 05:31:07 +00003726 if (getDerived().AlwaysRebuild() &&
3727 Param == E->getParam())
3728 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003729
Douglas Gregora16548e2009-08-11 05:31:07 +00003730 return getDerived().RebuildCXXDefaultArgExpr(Param);
3731}
Mike Stump11289f42009-09-09 15:08:12 +00003732
Douglas Gregora16548e2009-08-11 05:31:07 +00003733template<typename Derived>
3734Sema::OwningExprResult
3735TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
3736 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
3737
3738 QualType T = getDerived().TransformType(E->getType());
3739 if (T.isNull())
3740 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003741
Douglas Gregora16548e2009-08-11 05:31:07 +00003742 if (!getDerived().AlwaysRebuild() &&
3743 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00003744 return SemaRef.Owned(E->Retain());
3745
3746 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003747 /*FIXME:*/E->getTypeBeginLoc(),
3748 T,
3749 E->getRParenLoc());
3750}
Mike Stump11289f42009-09-09 15:08:12 +00003751
Douglas Gregora16548e2009-08-11 05:31:07 +00003752template<typename Derived>
3753Sema::OwningExprResult
3754TreeTransform<Derived>::TransformCXXConditionDeclExpr(CXXConditionDeclExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003755 VarDecl *Var
Douglas Gregorebe10102009-08-20 07:17:43 +00003756 = cast_or_null<VarDecl>(getDerived().TransformDefinition(E->getVarDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003757 if (!Var)
3758 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003759
Douglas Gregora16548e2009-08-11 05:31:07 +00003760 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00003761 Var == E->getVarDecl())
Douglas Gregora16548e2009-08-11 05:31:07 +00003762 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003763
3764 return getDerived().RebuildCXXConditionDeclExpr(E->getStartLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003765 /*FIXME:*/E->getStartLoc(),
3766 Var);
3767}
Mike Stump11289f42009-09-09 15:08:12 +00003768
Douglas Gregora16548e2009-08-11 05:31:07 +00003769template<typename Derived>
3770Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003771TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003772 // Transform the type that we're allocating
3773 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3774 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
3775 if (AllocType.isNull())
3776 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003777
Douglas Gregora16548e2009-08-11 05:31:07 +00003778 // Transform the size of the array we're allocating (if any).
3779 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
3780 if (ArraySize.isInvalid())
3781 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003782
Douglas Gregora16548e2009-08-11 05:31:07 +00003783 // Transform the placement arguments (if any).
3784 bool ArgumentChanged = false;
3785 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
3786 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
3787 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
3788 if (Arg.isInvalid())
3789 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003790
Douglas Gregora16548e2009-08-11 05:31:07 +00003791 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
3792 PlacementArgs.push_back(Arg.take());
3793 }
Mike Stump11289f42009-09-09 15:08:12 +00003794
Douglas Gregorebe10102009-08-20 07:17:43 +00003795 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00003796 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
3797 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
3798 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
3799 if (Arg.isInvalid())
3800 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003801
Douglas Gregora16548e2009-08-11 05:31:07 +00003802 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
3803 ConstructorArgs.push_back(Arg.take());
3804 }
Mike Stump11289f42009-09-09 15:08:12 +00003805
Douglas Gregora16548e2009-08-11 05:31:07 +00003806 if (!getDerived().AlwaysRebuild() &&
3807 AllocType == E->getAllocatedType() &&
3808 ArraySize.get() == E->getArraySize() &&
3809 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003810 return SemaRef.Owned(E->Retain());
3811
Douglas Gregora16548e2009-08-11 05:31:07 +00003812 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
3813 E->isGlobalNew(),
3814 /*FIXME:*/E->getLocStart(),
3815 move_arg(PlacementArgs),
3816 /*FIXME:*/E->getLocStart(),
3817 E->isParenTypeId(),
3818 AllocType,
3819 /*FIXME:*/E->getLocStart(),
3820 /*FIXME:*/SourceRange(),
3821 move(ArraySize),
3822 /*FIXME:*/E->getLocStart(),
3823 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00003824 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00003825}
Mike Stump11289f42009-09-09 15:08:12 +00003826
Douglas Gregora16548e2009-08-11 05:31:07 +00003827template<typename Derived>
3828Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003829TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003830 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
3831 if (Operand.isInvalid())
3832 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003833
Douglas Gregora16548e2009-08-11 05:31:07 +00003834 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00003835 Operand.get() == E->getArgument())
3836 return SemaRef.Owned(E->Retain());
3837
Douglas Gregora16548e2009-08-11 05:31:07 +00003838 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
3839 E->isGlobalDelete(),
3840 E->isArrayForm(),
3841 move(Operand));
3842}
Mike Stump11289f42009-09-09 15:08:12 +00003843
Douglas Gregora16548e2009-08-11 05:31:07 +00003844template<typename Derived>
3845Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00003846TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
3847 CXXPseudoDestructorExpr *E) {
3848 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3849 if (Base.isInvalid())
3850 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003851
Douglas Gregorad8a3362009-09-04 17:36:40 +00003852 NestedNameSpecifier *Qualifier
3853 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3854 E->getQualifierRange());
3855 if (E->getQualifier() && !Qualifier)
3856 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003857
Douglas Gregorad8a3362009-09-04 17:36:40 +00003858 QualType DestroyedType;
3859 {
3860 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
3861 DestroyedType = getDerived().TransformType(E->getDestroyedType());
3862 if (DestroyedType.isNull())
3863 return SemaRef.ExprError();
3864 }
Mike Stump11289f42009-09-09 15:08:12 +00003865
Douglas Gregorad8a3362009-09-04 17:36:40 +00003866 if (!getDerived().AlwaysRebuild() &&
3867 Base.get() == E->getBase() &&
3868 Qualifier == E->getQualifier() &&
3869 DestroyedType == E->getDestroyedType())
3870 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003871
Douglas Gregorad8a3362009-09-04 17:36:40 +00003872 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
3873 E->getOperatorLoc(),
3874 E->isArrow(),
3875 E->getDestroyedTypeLoc(),
3876 DestroyedType,
3877 Qualifier,
3878 E->getQualifierRange());
3879}
Mike Stump11289f42009-09-09 15:08:12 +00003880
Douglas Gregorad8a3362009-09-04 17:36:40 +00003881template<typename Derived>
3882Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003883TreeTransform<Derived>::TransformUnresolvedFunctionNameExpr(
Mike Stump11289f42009-09-09 15:08:12 +00003884 UnresolvedFunctionNameExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003885 // There is no transformation we can apply to an unresolved function name.
Mike Stump11289f42009-09-09 15:08:12 +00003886 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003887}
Mike Stump11289f42009-09-09 15:08:12 +00003888
Douglas Gregora16548e2009-08-11 05:31:07 +00003889template<typename Derived>
3890Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003891TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003892 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003893
Douglas Gregora16548e2009-08-11 05:31:07 +00003894 QualType T = getDerived().TransformType(E->getQueriedType());
3895 if (T.isNull())
3896 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003897
Douglas Gregora16548e2009-08-11 05:31:07 +00003898 if (!getDerived().AlwaysRebuild() &&
3899 T == E->getQueriedType())
3900 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003901
Douglas Gregora16548e2009-08-11 05:31:07 +00003902 // FIXME: Bad location information
3903 SourceLocation FakeLParenLoc
3904 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00003905
3906 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003907 E->getLocStart(),
3908 /*FIXME:*/FakeLParenLoc,
3909 T,
3910 E->getLocEnd());
3911}
Mike Stump11289f42009-09-09 15:08:12 +00003912
Douglas Gregora16548e2009-08-11 05:31:07 +00003913template<typename Derived>
3914Sema::OwningExprResult
3915TreeTransform<Derived>::TransformQualifiedDeclRefExpr(QualifiedDeclRefExpr *E) {
3916 NestedNameSpecifier *NNS
3917 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3918 E->getQualifierRange());
3919 if (!NNS)
3920 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003921
3922 NamedDecl *ND
Douglas Gregora16548e2009-08-11 05:31:07 +00003923 = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl()));
3924 if (!ND)
3925 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003926
3927 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003928 NNS == E->getQualifier() &&
3929 ND == E->getDecl())
Mike Stump11289f42009-09-09 15:08:12 +00003930 return SemaRef.Owned(E->Retain());
3931
3932 return getDerived().RebuildQualifiedDeclRefExpr(NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00003933 E->getQualifierRange(),
3934 ND,
3935 E->getLocation(),
3936 /*FIXME:*/false);
3937}
Mike Stump11289f42009-09-09 15:08:12 +00003938
Douglas Gregora16548e2009-08-11 05:31:07 +00003939template<typename Derived>
3940Sema::OwningExprResult
3941TreeTransform<Derived>::TransformUnresolvedDeclRefExpr(
Mike Stump11289f42009-09-09 15:08:12 +00003942 UnresolvedDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003943 NestedNameSpecifier *NNS
3944 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3945 E->getQualifierRange());
3946 if (!NNS)
3947 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003948
3949 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00003950 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
3951 if (!Name)
3952 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003953
3954 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003955 NNS == E->getQualifier() &&
3956 Name == E->getDeclName())
Mike Stump11289f42009-09-09 15:08:12 +00003957 return SemaRef.Owned(E->Retain());
3958
3959 return getDerived().RebuildUnresolvedDeclRefExpr(NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00003960 E->getQualifierRange(),
3961 Name,
3962 E->getLocation(),
3963 /*FIXME:*/false);
3964}
3965
3966template<typename Derived>
3967Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003968TreeTransform<Derived>::TransformTemplateIdRefExpr(TemplateIdRefExpr *E) {
3969 TemplateName Template
Douglas Gregora16548e2009-08-11 05:31:07 +00003970 = getDerived().TransformTemplateName(E->getTemplateName());
3971 if (Template.isNull())
3972 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003973
Douglas Gregora16548e2009-08-11 05:31:07 +00003974 llvm::SmallVector<TemplateArgument, 4> TransArgs;
3975 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003976 TemplateArgument TransArg
Douglas Gregora16548e2009-08-11 05:31:07 +00003977 = getDerived().TransformTemplateArgument(E->getTemplateArgs()[I]);
3978 if (TransArg.isNull())
3979 return SemaRef.ExprError();
3980
3981 TransArgs.push_back(TransArg);
3982 }
3983
3984 // FIXME: Would like to avoid rebuilding if nothing changed, but we can't
3985 // compare template arguments (yet).
Mike Stump11289f42009-09-09 15:08:12 +00003986
3987 // FIXME: It's possible that we'll find out now that the template name
Douglas Gregora16548e2009-08-11 05:31:07 +00003988 // actually refers to a type, in which case the caller is actually dealing
3989 // with a functional cast. Give a reasonable error message!
3990 return getDerived().RebuildTemplateIdExpr(Template, E->getTemplateNameLoc(),
3991 E->getLAngleLoc(),
3992 TransArgs.data(),
3993 TransArgs.size(),
3994 E->getRAngleLoc());
3995}
3996
3997template<typename Derived>
3998Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00003999TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004000 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4001
4002 QualType T = getDerived().TransformType(E->getType());
4003 if (T.isNull())
4004 return SemaRef.ExprError();
4005
4006 CXXConstructorDecl *Constructor
4007 = cast_or_null<CXXConstructorDecl>(
4008 getDerived().TransformDecl(E->getConstructor()));
4009 if (!Constructor)
4010 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004011
Douglas Gregora16548e2009-08-11 05:31:07 +00004012 bool ArgumentChanged = false;
4013 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004014 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004015 ArgEnd = E->arg_end();
4016 Arg != ArgEnd; ++Arg) {
4017 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4018 if (TransArg.isInvalid())
4019 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004020
Douglas Gregora16548e2009-08-11 05:31:07 +00004021 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4022 Args.push_back(TransArg.takeAs<Expr>());
4023 }
4024
4025 if (!getDerived().AlwaysRebuild() &&
4026 T == E->getType() &&
4027 Constructor == E->getConstructor() &&
4028 !ArgumentChanged)
4029 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004030
Douglas Gregora16548e2009-08-11 05:31:07 +00004031 return getDerived().RebuildCXXConstructExpr(T, Constructor, E->isElidable(),
4032 move_arg(Args));
4033}
Mike Stump11289f42009-09-09 15:08:12 +00004034
Douglas Gregora16548e2009-08-11 05:31:07 +00004035/// \brief Transform a C++ temporary-binding expression.
4036///
Mike Stump11289f42009-09-09 15:08:12 +00004037/// The transformation of a temporary-binding expression always attempts to
4038/// bind a new temporary variable to its subexpression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004039/// subexpression itself did not change, because the temporary variable itself
4040/// must be unique.
4041template<typename Derived>
4042Sema::OwningExprResult
4043TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
4044 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4045 if (SubExpr.isInvalid())
4046 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004047
Douglas Gregora16548e2009-08-11 05:31:07 +00004048 return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>());
4049}
Mike Stump11289f42009-09-09 15:08:12 +00004050
4051/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004052/// be destroyed after the expression is evaluated.
4053///
Mike Stump11289f42009-09-09 15:08:12 +00004054/// The transformation of a full expression always attempts to build a new
4055/// CXXExprWithTemporaries expression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004056/// subexpression itself did not change, because it will need to capture the
4057/// the new temporary variables introduced in the subexpression.
4058template<typename Derived>
4059Sema::OwningExprResult
4060TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Mike Stump11289f42009-09-09 15:08:12 +00004061 CXXExprWithTemporaries *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004062 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4063 if (SubExpr.isInvalid())
4064 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004065
Douglas Gregora16548e2009-08-11 05:31:07 +00004066 return SemaRef.Owned(
4067 SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(),
4068 E->shouldDestroyTemporaries()));
4069}
Mike Stump11289f42009-09-09 15:08:12 +00004070
Douglas Gregora16548e2009-08-11 05:31:07 +00004071template<typename Derived>
4072Sema::OwningExprResult
4073TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004074 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004075 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4076 QualType T = getDerived().TransformType(E->getType());
4077 if (T.isNull())
4078 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004079
Douglas Gregora16548e2009-08-11 05:31:07 +00004080 CXXConstructorDecl *Constructor
4081 = cast_or_null<CXXConstructorDecl>(
4082 getDerived().TransformDecl(E->getConstructor()));
4083 if (!Constructor)
4084 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004085
Douglas Gregora16548e2009-08-11 05:31:07 +00004086 bool ArgumentChanged = false;
4087 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4088 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004089 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004090 ArgEnd = E->arg_end();
4091 Arg != ArgEnd; ++Arg) {
4092 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4093 if (TransArg.isInvalid())
4094 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004095
Douglas Gregora16548e2009-08-11 05:31:07 +00004096 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4097 Args.push_back((Expr *)TransArg.release());
4098 }
Mike Stump11289f42009-09-09 15:08:12 +00004099
Douglas Gregora16548e2009-08-11 05:31:07 +00004100 if (!getDerived().AlwaysRebuild() &&
4101 T == E->getType() &&
4102 Constructor == E->getConstructor() &&
4103 !ArgumentChanged)
4104 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004105
Douglas Gregora16548e2009-08-11 05:31:07 +00004106 // FIXME: Bogus location information
4107 SourceLocation CommaLoc;
4108 if (Args.size() > 1) {
4109 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004110 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004111 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4112 }
4113 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4114 T,
4115 /*FIXME:*/E->getTypeBeginLoc(),
4116 move_arg(Args),
4117 &CommaLoc,
4118 E->getLocEnd());
4119}
Mike Stump11289f42009-09-09 15:08:12 +00004120
Douglas Gregora16548e2009-08-11 05:31:07 +00004121template<typename Derived>
4122Sema::OwningExprResult
4123TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004124 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004125 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4126 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4127 if (T.isNull())
4128 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004129
Douglas Gregora16548e2009-08-11 05:31:07 +00004130 bool ArgumentChanged = false;
4131 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4132 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4133 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4134 ArgEnd = E->arg_end();
4135 Arg != ArgEnd; ++Arg) {
4136 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4137 if (TransArg.isInvalid())
4138 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004139
Douglas Gregora16548e2009-08-11 05:31:07 +00004140 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4141 FakeCommaLocs.push_back(
4142 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4143 Args.push_back(TransArg.takeAs<Expr>());
4144 }
Mike Stump11289f42009-09-09 15:08:12 +00004145
Douglas Gregora16548e2009-08-11 05:31:07 +00004146 if (!getDerived().AlwaysRebuild() &&
4147 T == E->getTypeAsWritten() &&
4148 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004149 return SemaRef.Owned(E->Retain());
4150
Douglas Gregora16548e2009-08-11 05:31:07 +00004151 // FIXME: we're faking the locations of the commas
4152 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4153 T,
4154 E->getLParenLoc(),
4155 move_arg(Args),
4156 FakeCommaLocs.data(),
4157 E->getRParenLoc());
4158}
Mike Stump11289f42009-09-09 15:08:12 +00004159
Douglas Gregora16548e2009-08-11 05:31:07 +00004160template<typename Derived>
4161Sema::OwningExprResult
4162TreeTransform<Derived>::TransformCXXUnresolvedMemberExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004163 CXXUnresolvedMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004164 // Transform the base of the expression.
4165 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4166 if (Base.isInvalid())
4167 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004168
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004169 Sema::TypeTy *ObjectType = 0;
Mike Stump11289f42009-09-09 15:08:12 +00004170 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004171 E->getOperatorLoc(),
4172 E->isArrow()? tok::arrow : tok::period,
4173 ObjectType);
4174 if (Base.isInvalid())
4175 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004176
Douglas Gregor308047d2009-09-09 00:23:06 +00004177 // FIXME: The first qualifier found might be a template type parameter,
4178 // in which case there is no transformed declaration to refer to (it might
4179 // refer to a built-in type!).
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004180 NamedDecl *FirstQualifierInScope
4181 = cast_or_null<NamedDecl>(
4182 getDerived().TransformDecl(E->getFirstQualifierFoundInScope()));
Mike Stump11289f42009-09-09 15:08:12 +00004183
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004184 NestedNameSpecifier *Qualifier = 0;
4185 if (E->getQualifier()) {
4186 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4187 E->getQualifierRange(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004188 QualType::getFromOpaquePtr(ObjectType),
4189 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004190 if (!Qualifier)
4191 return SemaRef.ExprError();
4192 }
Mike Stump11289f42009-09-09 15:08:12 +00004193
4194 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004195 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc());
4196 if (!Name)
4197 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004198
Douglas Gregor308047d2009-09-09 00:23:06 +00004199 if (!E->hasExplicitTemplateArgumentList()) {
4200 // This is a reference to a member without an explicitly-specified
4201 // template argument list. Optimize for this common case.
4202 if (!getDerived().AlwaysRebuild() &&
4203 Base.get() == E->getBase() &&
4204 Qualifier == E->getQualifier() &&
4205 Name == E->getMember() &&
4206 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00004207 return SemaRef.Owned(E->Retain());
4208
Douglas Gregor308047d2009-09-09 00:23:06 +00004209 return getDerived().RebuildCXXUnresolvedMemberExpr(move(Base),
4210 E->isArrow(),
4211 E->getOperatorLoc(),
4212 Qualifier,
4213 E->getQualifierRange(),
4214 Name,
4215 E->getMemberLoc(),
4216 FirstQualifierInScope);
4217 }
4218
4219 // FIXME: This is an ugly hack, which forces the same template name to
4220 // be looked up multiple times. Yuck!
4221 // FIXME: This also won't work for, e.g., x->template operator+<int>
4222 TemplateName OrigTemplateName
4223 = SemaRef.Context.getDependentTemplateName(0, Name.getAsIdentifierInfo());
Mike Stump11289f42009-09-09 15:08:12 +00004224
4225 TemplateName Template
4226 = getDerived().TransformTemplateName(OrigTemplateName,
Douglas Gregor308047d2009-09-09 00:23:06 +00004227 QualType::getFromOpaquePtr(ObjectType));
4228 if (Template.isNull())
4229 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004230
Douglas Gregor308047d2009-09-09 00:23:06 +00004231 llvm::SmallVector<TemplateArgument, 4> TransArgs;
4232 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004233 TemplateArgument TransArg
Douglas Gregor308047d2009-09-09 00:23:06 +00004234 = getDerived().TransformTemplateArgument(E->getTemplateArgs()[I]);
4235 if (TransArg.isNull())
4236 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004237
Douglas Gregor308047d2009-09-09 00:23:06 +00004238 TransArgs.push_back(TransArg);
4239 }
Mike Stump11289f42009-09-09 15:08:12 +00004240
Douglas Gregora16548e2009-08-11 05:31:07 +00004241 return getDerived().RebuildCXXUnresolvedMemberExpr(move(Base),
4242 E->isArrow(),
4243 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004244 Qualifier,
4245 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004246 Template,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004247 E->getMemberLoc(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004248 FirstQualifierInScope,
4249 E->getLAngleLoc(),
4250 TransArgs.data(),
4251 TransArgs.size(),
4252 E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004253}
4254
4255template<typename Derived>
4256Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004257TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
4258 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004259}
4260
Mike Stump11289f42009-09-09 15:08:12 +00004261template<typename Derived>
4262Sema::OwningExprResult
4263TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004264 // FIXME: poor source location
4265 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
4266 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
4267 if (EncodedType.isNull())
4268 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004269
Douglas Gregora16548e2009-08-11 05:31:07 +00004270 if (!getDerived().AlwaysRebuild() &&
4271 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00004272 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004273
4274 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
4275 EncodedType,
4276 E->getRParenLoc());
4277}
Mike Stump11289f42009-09-09 15:08:12 +00004278
Douglas Gregora16548e2009-08-11 05:31:07 +00004279template<typename Derived>
4280Sema::OwningExprResult
Mike Stump11289f42009-09-09 15:08:12 +00004281TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004282 // FIXME: Implement this!
4283 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004284 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004285}
4286
Mike Stump11289f42009-09-09 15:08:12 +00004287template<typename Derived>
4288Sema::OwningExprResult
4289TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
4290 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004291}
4292
Mike Stump11289f42009-09-09 15:08:12 +00004293template<typename Derived>
4294Sema::OwningExprResult
4295TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
4296 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00004297 = cast_or_null<ObjCProtocolDecl>(
4298 getDerived().TransformDecl(E->getProtocol()));
4299 if (!Protocol)
4300 return SemaRef.ExprError();
4301
4302 if (!getDerived().AlwaysRebuild() &&
4303 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00004304 return SemaRef.Owned(E->Retain());
4305
Douglas Gregora16548e2009-08-11 05:31:07 +00004306 return getDerived().RebuildObjCProtocolExpr(Protocol,
4307 E->getAtLoc(),
4308 /*FIXME:*/E->getAtLoc(),
4309 /*FIXME:*/E->getAtLoc(),
4310 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004311
Douglas Gregora16548e2009-08-11 05:31:07 +00004312}
4313
Mike Stump11289f42009-09-09 15:08:12 +00004314template<typename Derived>
4315Sema::OwningExprResult
4316TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004317 // FIXME: Implement this!
4318 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004319 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004320}
4321
Mike Stump11289f42009-09-09 15:08:12 +00004322template<typename Derived>
4323Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004324TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
4325 // FIXME: Implement this!
4326 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004327 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004328}
4329
Mike Stump11289f42009-09-09 15:08:12 +00004330template<typename Derived>
4331Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00004332TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
Mike Stump11289f42009-09-09 15:08:12 +00004333 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004334 // FIXME: Implement this!
4335 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004336 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004337}
4338
Mike Stump11289f42009-09-09 15:08:12 +00004339template<typename Derived>
4340Sema::OwningExprResult
4341TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004342 // FIXME: Implement this!
4343 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004344 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004345}
4346
Mike Stump11289f42009-09-09 15:08:12 +00004347template<typename Derived>
4348Sema::OwningExprResult
4349TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004350 // FIXME: Implement this!
4351 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004352 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004353}
4354
Mike Stump11289f42009-09-09 15:08:12 +00004355template<typename Derived>
4356Sema::OwningExprResult
4357TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004358 bool ArgumentChanged = false;
4359 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
4360 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
4361 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
4362 if (SubExpr.isInvalid())
4363 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004364
Douglas Gregora16548e2009-08-11 05:31:07 +00004365 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
4366 SubExprs.push_back(SubExpr.takeAs<Expr>());
4367 }
Mike Stump11289f42009-09-09 15:08:12 +00004368
Douglas Gregora16548e2009-08-11 05:31:07 +00004369 if (!getDerived().AlwaysRebuild() &&
4370 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004371 return SemaRef.Owned(E->Retain());
4372
Douglas Gregora16548e2009-08-11 05:31:07 +00004373 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
4374 move_arg(SubExprs),
4375 E->getRParenLoc());
4376}
4377
Mike Stump11289f42009-09-09 15:08:12 +00004378template<typename Derived>
4379Sema::OwningExprResult
4380TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004381 // FIXME: Implement this!
4382 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004383 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004384}
4385
Mike Stump11289f42009-09-09 15:08:12 +00004386template<typename Derived>
4387Sema::OwningExprResult
4388TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004389 // FIXME: Implement this!
4390 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004391 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004392}
Mike Stump11289f42009-09-09 15:08:12 +00004393
Douglas Gregora16548e2009-08-11 05:31:07 +00004394//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00004395// Type reconstruction
4396//===----------------------------------------------------------------------===//
4397
Mike Stump11289f42009-09-09 15:08:12 +00004398template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004399QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004400 return SemaRef.BuildPointerType(PointeeType, Qualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004401 getDerived().getBaseLocation(),
4402 getDerived().getBaseEntity());
4403}
4404
Mike Stump11289f42009-09-09 15:08:12 +00004405template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004406QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004407 return SemaRef.BuildBlockPointerType(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>
4413QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00004414TreeTransform<Derived>::RebuildLValueReferenceType(QualType ReferentType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004415 return SemaRef.BuildReferenceType(ReferentType, true, Qualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004416 getDerived().getBaseLocation(),
4417 getDerived().getBaseEntity());
4418}
4419
4420template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004421QualType
4422TreeTransform<Derived>::RebuildRValueReferenceType(QualType ReferentType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004423 return SemaRef.BuildReferenceType(ReferentType, false, Qualifiers(),
Mike Stump11289f42009-09-09 15:08:12 +00004424 getDerived().getBaseLocation(),
4425 getDerived().getBaseEntity());
4426}
4427
4428template<typename Derived>
4429QualType TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004430 QualType ClassType) {
John McCall8ccfcb52009-09-24 19:53:00 +00004431 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004432 getDerived().getBaseLocation(),
4433 getDerived().getBaseEntity());
4434}
4435
4436template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004437QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00004438TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
4439 ArrayType::ArraySizeModifier SizeMod,
4440 const llvm::APInt *Size,
4441 Expr *SizeExpr,
4442 unsigned IndexTypeQuals,
4443 SourceRange BracketsRange) {
4444 if (SizeExpr || !Size)
4445 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
4446 IndexTypeQuals, BracketsRange,
4447 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00004448
4449 QualType Types[] = {
4450 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
4451 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
4452 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00004453 };
4454 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
4455 QualType SizeType;
4456 for (unsigned I = 0; I != NumTypes; ++I)
4457 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
4458 SizeType = Types[I];
4459 break;
4460 }
Mike Stump11289f42009-09-09 15:08:12 +00004461
Douglas Gregord6ff3322009-08-04 16:50:30 +00004462 if (SizeType.isNull())
4463 SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false);
Mike Stump11289f42009-09-09 15:08:12 +00004464
Douglas Gregord6ff3322009-08-04 16:50:30 +00004465 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00004466 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004467 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00004468 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004469}
Mike Stump11289f42009-09-09 15:08:12 +00004470
Douglas Gregord6ff3322009-08-04 16:50:30 +00004471template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004472QualType
4473TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004474 ArrayType::ArraySizeModifier SizeMod,
4475 const llvm::APInt &Size,
4476 unsigned IndexTypeQuals) {
Mike Stump11289f42009-09-09 15:08:12 +00004477 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004478 IndexTypeQuals, SourceRange());
4479}
4480
4481template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004482QualType
Mike Stump11289f42009-09-09 15:08:12 +00004483TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004484 ArrayType::ArraySizeModifier SizeMod,
4485 unsigned IndexTypeQuals) {
Mike Stump11289f42009-09-09 15:08:12 +00004486 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004487 IndexTypeQuals, SourceRange());
4488}
Mike Stump11289f42009-09-09 15:08:12 +00004489
Douglas Gregord6ff3322009-08-04 16:50:30 +00004490template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004491QualType
4492TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004493 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00004494 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004495 unsigned IndexTypeQuals,
4496 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00004497 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004498 SizeExpr.takeAs<Expr>(),
4499 IndexTypeQuals, BracketsRange);
4500}
4501
4502template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004503QualType
4504TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004505 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00004506 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004507 unsigned IndexTypeQuals,
4508 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00004509 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004510 SizeExpr.takeAs<Expr>(),
4511 IndexTypeQuals, BracketsRange);
4512}
4513
4514template<typename Derived>
4515QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
4516 unsigned NumElements) {
4517 // FIXME: semantic checking!
4518 return SemaRef.Context.getVectorType(ElementType, NumElements);
4519}
Mike Stump11289f42009-09-09 15:08:12 +00004520
Douglas Gregord6ff3322009-08-04 16:50:30 +00004521template<typename Derived>
4522QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
4523 unsigned NumElements,
4524 SourceLocation AttributeLoc) {
4525 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
4526 NumElements, true);
4527 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00004528 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004529 AttributeLoc);
4530 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
4531 AttributeLoc);
4532}
Mike Stump11289f42009-09-09 15:08:12 +00004533
Douglas Gregord6ff3322009-08-04 16:50:30 +00004534template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004535QualType
4536TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00004537 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004538 SourceLocation AttributeLoc) {
4539 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
4540}
Mike Stump11289f42009-09-09 15:08:12 +00004541
Douglas Gregord6ff3322009-08-04 16:50:30 +00004542template<typename Derived>
4543QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00004544 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004545 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00004546 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004547 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00004548 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004549 Quals,
4550 getDerived().getBaseLocation(),
4551 getDerived().getBaseEntity());
4552}
Mike Stump11289f42009-09-09 15:08:12 +00004553
Douglas Gregord6ff3322009-08-04 16:50:30 +00004554template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004555QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004556 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
4557}
4558
4559template<typename Derived>
4560QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
4561 return SemaRef.Context.getTypeOfType(Underlying);
4562}
4563
4564template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004565QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004566 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
4567}
4568
4569template<typename Derived>
4570QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
4571 TemplateName Template,
4572 const TemplateArgument *Args,
4573 unsigned NumArgs) {
4574 // FIXME: Missing source locations for the template name, <, >.
4575 return SemaRef.CheckTemplateIdType(Template, getDerived().getBaseLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00004576 SourceLocation(), Args, NumArgs,
4577 SourceLocation());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004578}
Mike Stump11289f42009-09-09 15:08:12 +00004579
Douglas Gregor1135c352009-08-06 05:28:30 +00004580template<typename Derived>
4581NestedNameSpecifier *
4582TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
4583 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004584 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004585 QualType ObjectType,
4586 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00004587 CXXScopeSpec SS;
4588 // FIXME: The source location information is all wrong.
4589 SS.setRange(Range);
4590 SS.setScopeRep(Prefix);
4591 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00004592 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00004593 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004594 ObjectType,
4595 FirstQualifierInScope,
Douglas Gregore861bac2009-08-25 22:51:20 +00004596 false));
Douglas Gregor1135c352009-08-06 05:28:30 +00004597}
4598
4599template<typename Derived>
4600NestedNameSpecifier *
4601TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
4602 SourceRange Range,
4603 NamespaceDecl *NS) {
4604 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
4605}
4606
4607template<typename Derived>
4608NestedNameSpecifier *
4609TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
4610 SourceRange Range,
4611 bool TemplateKW,
4612 QualType T) {
4613 if (T->isDependentType() || T->isRecordType() ||
4614 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
John McCall8ccfcb52009-09-24 19:53:00 +00004615 assert(!T.hasQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00004616 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
4617 T.getTypePtr());
4618 }
Mike Stump11289f42009-09-09 15:08:12 +00004619
Douglas Gregor1135c352009-08-06 05:28:30 +00004620 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
4621 return 0;
4622}
Mike Stump11289f42009-09-09 15:08:12 +00004623
Douglas Gregor71dc5092009-08-06 06:41:21 +00004624template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004625TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00004626TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
4627 bool TemplateKW,
4628 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00004629 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00004630 Template);
4631}
4632
4633template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004634TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00004635TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
4636 bool TemplateKW,
4637 OverloadedFunctionDecl *Ovl) {
4638 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, Ovl);
4639}
4640
4641template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004642TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00004643TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00004644 const IdentifierInfo &II,
4645 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00004646 CXXScopeSpec SS;
4647 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00004648 SS.setScopeRep(Qualifier);
Douglas Gregor308047d2009-09-09 00:23:06 +00004649 return getSema().ActOnDependentTemplateName(
4650 /*FIXME:*/getDerived().getBaseLocation(),
4651 II,
4652 /*FIXME:*/getDerived().getBaseLocation(),
4653 SS,
4654 ObjectType.getAsOpaquePtr())
4655 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00004656}
Mike Stump11289f42009-09-09 15:08:12 +00004657
Douglas Gregora16548e2009-08-11 05:31:07 +00004658template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004659Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004660TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
4661 SourceLocation OpLoc,
4662 ExprArg Callee,
4663 ExprArg First,
4664 ExprArg Second) {
4665 Expr *FirstExpr = (Expr *)First.get();
4666 Expr *SecondExpr = (Expr *)Second.get();
4667 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00004668
Douglas Gregora16548e2009-08-11 05:31:07 +00004669 // Determine whether this should be a builtin operation.
4670 if (SecondExpr == 0 || isPostIncDec) {
4671 if (!FirstExpr->getType()->isOverloadableType()) {
4672 // The argument is not of overloadable type, so try to create a
4673 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00004674 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00004675 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00004676
Douglas Gregora16548e2009-08-11 05:31:07 +00004677 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
4678 }
4679 } else {
Mike Stump11289f42009-09-09 15:08:12 +00004680 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004681 !SecondExpr->getType()->isOverloadableType()) {
4682 // Neither of the arguments is an overloadable type, so try to
4683 // create a built-in binary operation.
4684 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00004685 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00004686 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
4687 if (Result.isInvalid())
4688 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004689
Douglas Gregora16548e2009-08-11 05:31:07 +00004690 First.release();
4691 Second.release();
4692 return move(Result);
4693 }
4694 }
Mike Stump11289f42009-09-09 15:08:12 +00004695
4696 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00004697 // used during overload resolution.
4698 Sema::FunctionSet Functions;
Mike Stump11289f42009-09-09 15:08:12 +00004699
4700 DeclRefExpr *DRE
Douglas Gregor32e2c842009-09-01 16:58:52 +00004701 = cast<DeclRefExpr>(((Expr *)Callee.get())->IgnoreParenCasts());
Mike Stump11289f42009-09-09 15:08:12 +00004702
Douglas Gregora16548e2009-08-11 05:31:07 +00004703 // FIXME: Do we have to check
4704 // IsAcceptableNonMemberOperatorCandidate for each of these?
Douglas Gregor32e2c842009-09-01 16:58:52 +00004705 for (OverloadIterator F(DRE->getDecl()), FEnd; F != FEnd; ++F)
Douglas Gregora16548e2009-08-11 05:31:07 +00004706 Functions.insert(*F);
Mike Stump11289f42009-09-09 15:08:12 +00004707
Douglas Gregora16548e2009-08-11 05:31:07 +00004708 // Add any functions found via argument-dependent lookup.
4709 Expr *Args[2] = { FirstExpr, SecondExpr };
4710 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00004711 DeclarationName OpName
Douglas Gregora16548e2009-08-11 05:31:07 +00004712 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
4713 SemaRef.ArgumentDependentLookup(OpName, Args, NumArgs, Functions);
Mike Stump11289f42009-09-09 15:08:12 +00004714
Douglas Gregora16548e2009-08-11 05:31:07 +00004715 // Create the overloaded operator invocation for unary operators.
4716 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00004717 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00004718 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
4719 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
4720 }
Mike Stump11289f42009-09-09 15:08:12 +00004721
Douglas Gregora16548e2009-08-11 05:31:07 +00004722 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00004723 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00004724 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00004725 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00004726 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
4727 if (Result.isInvalid())
4728 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004729
Douglas Gregora16548e2009-08-11 05:31:07 +00004730 First.release();
4731 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00004732 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00004733}
Mike Stump11289f42009-09-09 15:08:12 +00004734
Douglas Gregord6ff3322009-08-04 16:50:30 +00004735} // end namespace clang
4736
4737#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H