blob: 445ef0dac7976c6af67495e66d17356d78a56c22 [file] [log] [blame]
John McCalla2becad2009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregor577f75a2009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
16#include "Sema.h"
John McCallf7a1a742009-11-24 19:00:30 +000017#include "Lookup.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000020#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000021#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000023#include "clang/AST/Stmt.h"
24#include "clang/AST/StmtCXX.h"
25#include "clang/AST/StmtObjC.h"
John McCalla2becad2009-10-21 00:40:46 +000026#include "clang/AST/TypeLocBuilder.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000027#include "clang/Parse/Ownership.h"
28#include "clang/Parse/Designator.h"
29#include "clang/Lex/Preprocessor.h"
John McCalla2becad2009-10-21 00:40:46 +000030#include "llvm/Support/ErrorHandling.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000031#include <algorithm>
32
33namespace clang {
Mike Stump1eb44332009-09-09 15:08:12 +000034
Douglas Gregor577f75a2009-08-04 16:50:30 +000035/// \brief A semantic tree transformation that allows one to transform one
36/// abstract syntax tree into another.
37///
Mike Stump1eb44332009-09-09 15:08:12 +000038/// A new tree transformation is defined by creating a new subclass \c X of
39/// \c TreeTransform<X> and then overriding certain operations to provide
40/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000041/// instantiation is implemented as a tree transformation where the
42/// transformation of TemplateTypeParmType nodes involves substituting the
43/// template arguments for their corresponding template parameters; a similar
44/// transformation is performed for non-type template parameters and
45/// template template parameters.
46///
47/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000048/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000049/// override any of the transformation or rebuild operators by providing an
50/// operation with the same signature as the default implementation. The
51/// overridding function should not be virtual.
52///
53/// Semantic tree transformations are split into two stages, either of which
54/// can be replaced by a subclass. The "transform" step transforms an AST node
55/// or the parts of an AST node using the various transformation functions,
56/// then passes the pieces on to the "rebuild" step, which constructs a new AST
57/// node of the appropriate kind from the pieces. The default transformation
58/// routines recursively transform the operands to composite AST nodes (e.g.,
59/// the pointee type of a PointerType node) and, if any of those operand nodes
60/// were changed by the transformation, invokes the rebuild operation to create
61/// a new AST node.
62///
Mike Stump1eb44332009-09-09 15:08:12 +000063/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000064/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000065/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
66/// TransformTemplateName(), or TransformTemplateArgument() with entirely
67/// new implementations.
68///
69/// For more fine-grained transformations, subclasses can replace any of the
70/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000071/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000072/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000073/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000074/// parameters. Additionally, subclasses can override the \c RebuildXXX
75/// functions to control how AST nodes are rebuilt when their operands change.
76/// By default, \c TreeTransform will invoke semantic analysis to rebuild
77/// AST nodes. However, certain other tree transformations (e.g, cloning) may
78/// be able to use more efficient rebuild steps.
79///
80/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000081/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000082/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
83/// operands have not changed (\c AlwaysRebuild()), and customize the
84/// default locations and entity names used for type-checking
85/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000086template<typename Derived>
87class TreeTransform {
88protected:
89 Sema &SemaRef;
Mike Stump1eb44332009-09-09 15:08:12 +000090
91public:
Douglas Gregorb98b1992009-08-11 05:31:07 +000092 typedef Sema::OwningStmtResult OwningStmtResult;
93 typedef Sema::OwningExprResult OwningExprResult;
94 typedef Sema::StmtArg StmtArg;
95 typedef Sema::ExprArg ExprArg;
96 typedef Sema::MultiExprArg MultiExprArg;
Douglas Gregor43959a92009-08-20 07:17:43 +000097 typedef Sema::MultiStmtArg MultiStmtArg;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +000098 typedef Sema::DeclPtrTy DeclPtrTy;
99
Douglas Gregor577f75a2009-08-04 16:50:30 +0000100 /// \brief Initializes a new tree transformer.
101 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000102
Douglas Gregor577f75a2009-08-04 16:50:30 +0000103 /// \brief Retrieves a reference to the derived class.
104 Derived &getDerived() { return static_cast<Derived&>(*this); }
105
106 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000107 const Derived &getDerived() const {
108 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000109 }
110
111 /// \brief Retrieves a reference to the semantic analysis object used for
112 /// this tree transform.
113 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000114
Douglas Gregor577f75a2009-08-04 16:50:30 +0000115 /// \brief Whether the transformation should always rebuild AST nodes, even
116 /// if none of the children have changed.
117 ///
118 /// Subclasses may override this function to specify when the transformation
119 /// should rebuild all AST nodes.
120 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000121
Douglas Gregor577f75a2009-08-04 16:50:30 +0000122 /// \brief Returns the location of the entity being transformed, if that
123 /// information was not available elsewhere in the AST.
124 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000125 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000126 /// provide an alternative implementation that provides better location
127 /// information.
128 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000129
Douglas Gregor577f75a2009-08-04 16:50:30 +0000130 /// \brief Returns the name of the entity being transformed, if that
131 /// information was not available elsewhere in the AST.
132 ///
133 /// By default, returns an empty name. Subclasses can provide an alternative
134 /// implementation with a more precise name.
135 DeclarationName getBaseEntity() { return DeclarationName(); }
136
Douglas Gregorb98b1992009-08-11 05:31:07 +0000137 /// \brief Sets the "base" location and entity when that
138 /// information is known based on another transformation.
139 ///
140 /// By default, the source location and entity are ignored. Subclasses can
141 /// override this function to provide a customized implementation.
142 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000143
Douglas Gregorb98b1992009-08-11 05:31:07 +0000144 /// \brief RAII object that temporarily sets the base location and entity
145 /// used for reporting diagnostics in types.
146 class TemporaryBase {
147 TreeTransform &Self;
148 SourceLocation OldLocation;
149 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000150
Douglas Gregorb98b1992009-08-11 05:31:07 +0000151 public:
152 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000153 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000154 OldLocation = Self.getDerived().getBaseLocation();
155 OldEntity = Self.getDerived().getBaseEntity();
156 Self.getDerived().setBase(Location, Entity);
157 }
Mike Stump1eb44332009-09-09 15:08:12 +0000158
Douglas Gregorb98b1992009-08-11 05:31:07 +0000159 ~TemporaryBase() {
160 Self.getDerived().setBase(OldLocation, OldEntity);
161 }
162 };
Mike Stump1eb44332009-09-09 15:08:12 +0000163
164 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000165 /// transformed.
166 ///
167 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000168 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000169 /// not change. For example, template instantiation need not traverse
170 /// non-dependent types.
171 bool AlreadyTransformed(QualType T) {
172 return T.isNull();
173 }
174
Douglas Gregor6eef5192009-12-14 19:27:10 +0000175 /// \brief Determine whether the given call argument should be dropped, e.g.,
176 /// because it is a default argument.
177 ///
178 /// Subclasses can provide an alternative implementation of this routine to
179 /// determine which kinds of call arguments get dropped. By default,
180 /// CXXDefaultArgument nodes are dropped (prior to transformation).
181 bool DropCallArgument(Expr *E) {
182 return E->isDefaultArgument();
183 }
184
Douglas Gregor577f75a2009-08-04 16:50:30 +0000185 /// \brief Transforms the given type into another type.
186 ///
John McCalla2becad2009-10-21 00:40:46 +0000187 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000188 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000189 /// function. This is expensive, but we don't mind, because
190 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000191 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000192 ///
193 /// \returns the transformed type.
194 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000195
John McCalla2becad2009-10-21 00:40:46 +0000196 /// \brief Transforms the given type-with-location into a new
197 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000198 ///
John McCalla2becad2009-10-21 00:40:46 +0000199 /// By default, this routine transforms a type by delegating to the
200 /// appropriate TransformXXXType to build a new type. Subclasses
201 /// may override this function (to take over all type
202 /// transformations) or some set of the TransformXXXType functions
203 /// to alter the transformation.
John McCalla93c9342009-12-07 02:54:59 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000205
206 /// \brief Transform the given type-with-location into a new
207 /// type, collecting location information in the given builder
208 /// as necessary.
209 ///
210 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000211
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000212 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000213 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000214 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000215 /// appropriate TransformXXXStmt function to transform a specific kind of
216 /// statement or the TransformExpr() function to transform an expression.
217 /// Subclasses may override this function to transform statements using some
218 /// other mechanism.
219 ///
220 /// \returns the transformed statement.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000221 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000222
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000223 /// \brief Transform the given expression.
224 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000225 /// By default, this routine transforms an expression by delegating to the
226 /// appropriate TransformXXXExpr function to build a new expression.
227 /// Subclasses may override this function to transform expressions using some
228 /// other mechanism.
229 ///
230 /// \returns the transformed expression.
John McCall454feb92009-12-08 09:21:05 +0000231 OwningExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000232
Douglas Gregor577f75a2009-08-04 16:50:30 +0000233 /// \brief Transform the given declaration, which is referenced from a type
234 /// or expression.
235 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000236 /// By default, acts as the identity function on declarations. Subclasses
237 /// may override this function to provide alternate behavior.
238 Decl *TransformDecl(Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000239
240 /// \brief Transform the definition of the given declaration.
241 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000242 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000243 /// Subclasses may override this function to provide alternate behavior.
244 Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); }
Mike Stump1eb44332009-09-09 15:08:12 +0000245
Douglas Gregor6cd21982009-10-20 05:58:46 +0000246 /// \brief Transform the given declaration, which was the first part of a
247 /// nested-name-specifier in a member access expression.
248 ///
249 /// This specific declaration transformation only applies to the first
250 /// identifier in a nested-name-specifier of a member access expression, e.g.,
251 /// the \c T in \c x->T::member
252 ///
253 /// By default, invokes TransformDecl() to transform the declaration.
254 /// Subclasses may override this function to provide alternate behavior.
255 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
256 return cast_or_null<NamedDecl>(getDerived().TransformDecl(D));
257 }
258
Douglas Gregor577f75a2009-08-04 16:50:30 +0000259 /// \brief Transform the given nested-name-specifier.
260 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000261 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000262 /// nested-name-specifier. Subclasses may override this function to provide
263 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000264 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000265 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000266 QualType ObjectType = QualType(),
267 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000268
Douglas Gregor81499bb2009-09-03 22:13:48 +0000269 /// \brief Transform the given declaration name.
270 ///
271 /// By default, transforms the types of conversion function, constructor,
272 /// and destructor names and then (if needed) rebuilds the declaration name.
273 /// Identifiers and selectors are returned unmodified. Sublcasses may
274 /// override this function to provide alternate behavior.
275 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +0000276 SourceLocation Loc,
277 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000278
Douglas Gregor577f75a2009-08-04 16:50:30 +0000279 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000280 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000281 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000282 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000283 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000284 TemplateName TransformTemplateName(TemplateName Name,
285 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000286
Douglas Gregor577f75a2009-08-04 16:50:30 +0000287 /// \brief Transform the given template argument.
288 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000289 /// By default, this operation transforms the type, expression, or
290 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000291 /// new template argument from the transformed result. Subclasses may
292 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000293 ///
294 /// Returns true if there was an error.
295 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
296 TemplateArgumentLoc &Output);
297
298 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
299 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
300 TemplateArgumentLoc &ArgLoc);
301
John McCalla93c9342009-12-07 02:54:59 +0000302 /// \brief Fakes up a TypeSourceInfo for a type.
303 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
304 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000305 getDerived().getBaseLocation());
306 }
Mike Stump1eb44332009-09-09 15:08:12 +0000307
John McCalla2becad2009-10-21 00:40:46 +0000308#define ABSTRACT_TYPELOC(CLASS, PARENT)
309#define TYPELOC(CLASS, PARENT) \
310 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
311#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000312
John McCall85737a72009-10-30 00:06:24 +0000313 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
314
Douglas Gregordd62b152009-10-19 22:04:39 +0000315 QualType
316 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
317 QualType ObjectType);
John McCall833ca992009-10-29 08:12:44 +0000318
319 QualType
320 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
321 TemplateSpecializationTypeLoc TL,
322 QualType ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +0000323
Douglas Gregor43959a92009-08-20 07:17:43 +0000324 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Mike Stump1eb44332009-09-09 15:08:12 +0000325
Douglas Gregor43959a92009-08-20 07:17:43 +0000326#define STMT(Node, Parent) \
327 OwningStmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000328#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +0000329 OwningExprResult Transform##Node(Node *E);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000330#define ABSTRACT_EXPR(Node, Parent)
331#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +0000332
Douglas Gregor577f75a2009-08-04 16:50:30 +0000333 /// \brief Build a new pointer type given its pointee type.
334 ///
335 /// By default, performs semantic analysis when building the pointer type.
336 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000337 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000338
339 /// \brief Build a new block pointer type given its pointee type.
340 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000341 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000342 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000343 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000344
John McCall85737a72009-10-30 00:06:24 +0000345 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000346 ///
John McCall85737a72009-10-30 00:06:24 +0000347 /// By default, performs semantic analysis when building the
348 /// reference type. Subclasses may override this routine to provide
349 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000350 ///
John McCall85737a72009-10-30 00:06:24 +0000351 /// \param LValue whether the type was written with an lvalue sigil
352 /// or an rvalue sigil.
353 QualType RebuildReferenceType(QualType ReferentType,
354 bool LValue,
355 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000356
Douglas Gregor577f75a2009-08-04 16:50:30 +0000357 /// \brief Build a new member pointer type given the pointee type and the
358 /// class type it refers into.
359 ///
360 /// By default, performs semantic analysis when building the member pointer
361 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000362 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
363 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000364
John McCalla2becad2009-10-21 00:40:46 +0000365 /// \brief Build a new Objective C object pointer type.
John McCall85737a72009-10-30 00:06:24 +0000366 QualType RebuildObjCObjectPointerType(QualType PointeeType,
367 SourceLocation Sigil);
John McCalla2becad2009-10-21 00:40:46 +0000368
Douglas Gregor577f75a2009-08-04 16:50:30 +0000369 /// \brief Build a new array type given the element type, size
370 /// modifier, size of the array (if known), size expression, and index type
371 /// qualifiers.
372 ///
373 /// By default, performs semantic analysis when building the array type.
374 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000375 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000376 QualType RebuildArrayType(QualType ElementType,
377 ArrayType::ArraySizeModifier SizeMod,
378 const llvm::APInt *Size,
379 Expr *SizeExpr,
380 unsigned IndexTypeQuals,
381 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000382
Douglas Gregor577f75a2009-08-04 16:50:30 +0000383 /// \brief Build a new constant array type given the element type, size
384 /// modifier, (known) size of the array, and index type qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000388 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000389 ArrayType::ArraySizeModifier SizeMod,
390 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000391 unsigned IndexTypeQuals,
392 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000393
Douglas Gregor577f75a2009-08-04 16:50:30 +0000394 /// \brief Build a new incomplete array type given the element type, size
395 /// modifier, and index type qualifiers.
396 ///
397 /// By default, performs semantic analysis when building the array type.
398 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000399 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000400 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000401 unsigned IndexTypeQuals,
402 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000403
Mike Stump1eb44332009-09-09 15:08:12 +0000404 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000405 /// size modifier, size expression, and index type qualifiers.
406 ///
407 /// By default, performs semantic analysis when building the array type.
408 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000409 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000410 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000411 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000412 unsigned IndexTypeQuals,
413 SourceRange BracketsRange);
414
Mike Stump1eb44332009-09-09 15:08:12 +0000415 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000416 /// size modifier, size expression, and index type qualifiers.
417 ///
418 /// By default, performs semantic analysis when building the array type.
419 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000420 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000421 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000422 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000423 unsigned IndexTypeQuals,
424 SourceRange BracketsRange);
425
426 /// \brief Build a new vector type given the element type and
427 /// number of elements.
428 ///
429 /// By default, performs semantic analysis when building the vector type.
430 /// Subclasses may override this routine to provide different behavior.
431 QualType RebuildVectorType(QualType ElementType, unsigned NumElements);
Mike Stump1eb44332009-09-09 15:08:12 +0000432
Douglas Gregor577f75a2009-08-04 16:50:30 +0000433 /// \brief Build a new extended vector type given the element type and
434 /// number of elements.
435 ///
436 /// By default, performs semantic analysis when building the vector type.
437 /// Subclasses may override this routine to provide different behavior.
438 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
439 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000440
441 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000442 /// given the element type and number of elements.
443 ///
444 /// By default, performs semantic analysis when building the vector type.
445 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000446 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000447 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000448 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000449
Douglas Gregor577f75a2009-08-04 16:50:30 +0000450 /// \brief Build a new function type.
451 ///
452 /// By default, performs semantic analysis when building the function type.
453 /// Subclasses may override this routine to provide different behavior.
454 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000455 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000456 unsigned NumParamTypes,
457 bool Variadic, unsigned Quals);
Mike Stump1eb44332009-09-09 15:08:12 +0000458
John McCalla2becad2009-10-21 00:40:46 +0000459 /// \brief Build a new unprototyped function type.
460 QualType RebuildFunctionNoProtoType(QualType ResultType);
461
John McCalled976492009-12-04 22:46:56 +0000462 /// \brief Rebuild an unresolved typename type, given the decl that
463 /// the UnresolvedUsingTypenameDecl was transformed to.
464 QualType RebuildUnresolvedUsingType(Decl *D);
465
Douglas Gregor577f75a2009-08-04 16:50:30 +0000466 /// \brief Build a new typedef type.
467 QualType RebuildTypedefType(TypedefDecl *Typedef) {
468 return SemaRef.Context.getTypeDeclType(Typedef);
469 }
470
471 /// \brief Build a new class/struct/union type.
472 QualType RebuildRecordType(RecordDecl *Record) {
473 return SemaRef.Context.getTypeDeclType(Record);
474 }
475
476 /// \brief Build a new Enum type.
477 QualType RebuildEnumType(EnumDecl *Enum) {
478 return SemaRef.Context.getTypeDeclType(Enum);
479 }
John McCall7da24312009-09-05 00:15:47 +0000480
481 /// \brief Build a new elaborated type.
482 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
483 return SemaRef.Context.getElaboratedType(T, Tag);
484 }
Mike Stump1eb44332009-09-09 15:08:12 +0000485
486 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000487 ///
488 /// By default, performs semantic analysis when building the typeof type.
489 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000490 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000491
Mike Stump1eb44332009-09-09 15:08:12 +0000492 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000493 ///
494 /// By default, builds a new TypeOfType with the given underlying type.
495 QualType RebuildTypeOfType(QualType Underlying);
496
Mike Stump1eb44332009-09-09 15:08:12 +0000497 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000498 ///
499 /// By default, performs semantic analysis when building the decltype type.
500 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000501 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump1eb44332009-09-09 15:08:12 +0000502
Douglas Gregor577f75a2009-08-04 16:50:30 +0000503 /// \brief Build a new template specialization type.
504 ///
505 /// By default, performs semantic analysis when building the template
506 /// specialization type. Subclasses may override this routine to provide
507 /// different behavior.
508 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000509 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000510 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000511
Douglas Gregor577f75a2009-08-04 16:50:30 +0000512 /// \brief Build a new qualified name type.
513 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000514 /// By default, builds a new QualifiedNameType type from the
515 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregor577f75a2009-08-04 16:50:30 +0000516 /// this routine to provide different behavior.
517 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
518 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000519 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000520
521 /// \brief Build a new typename type that refers to a template-id.
522 ///
523 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump1eb44332009-09-09 15:08:12 +0000524 /// and the given type. Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000525 /// different behavior.
526 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
527 if (NNS->isDependent())
Mike Stump1eb44332009-09-09 15:08:12 +0000528 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000529 cast<TemplateSpecializationType>(T));
Mike Stump1eb44332009-09-09 15:08:12 +0000530
Douglas Gregor577f75a2009-08-04 16:50:30 +0000531 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000532 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000533
534 /// \brief Build a new typename type that refers to an identifier.
535 ///
536 /// By default, performs semantic analysis when building the typename type
Mike Stump1eb44332009-09-09 15:08:12 +0000537 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000538 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000539 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall833ca992009-10-29 08:12:44 +0000540 const IdentifierInfo *Id,
541 SourceRange SR) {
542 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000543 }
Mike Stump1eb44332009-09-09 15:08:12 +0000544
Douglas Gregordcee1a12009-08-06 05:28:30 +0000545 /// \brief Build a new nested-name-specifier given the prefix and an
546 /// identifier that names the next step in the nested-name-specifier.
547 ///
548 /// By default, performs semantic analysis when building the new
549 /// nested-name-specifier. Subclasses may override this routine to provide
550 /// different behavior.
551 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
552 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000553 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000554 QualType ObjectType,
555 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000556
557 /// \brief Build a new nested-name-specifier given the prefix and the
558 /// namespace named in the next step in the nested-name-specifier.
559 ///
560 /// By default, performs semantic analysis when building the new
561 /// nested-name-specifier. Subclasses may override this routine to provide
562 /// different behavior.
563 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
564 SourceRange Range,
565 NamespaceDecl *NS);
566
567 /// \brief Build a new nested-name-specifier given the prefix and the
568 /// type named in the next step in the nested-name-specifier.
569 ///
570 /// By default, performs semantic analysis when building the new
571 /// nested-name-specifier. Subclasses may override this routine to provide
572 /// different behavior.
573 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
574 SourceRange Range,
575 bool TemplateKW,
576 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000577
578 /// \brief Build a new template name given a nested name specifier, a flag
579 /// indicating whether the "template" keyword was provided, and the template
580 /// that the template name refers to.
581 ///
582 /// By default, builds the new template name directly. Subclasses may override
583 /// this routine to provide different behavior.
584 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
585 bool TemplateKW,
586 TemplateDecl *Template);
587
Douglas Gregord1067e52009-08-06 06:41:21 +0000588 /// \brief Build a new template name given a nested name specifier and the
589 /// name that is referred to as a template.
590 ///
591 /// By default, performs semantic analysis to determine whether the name can
592 /// be resolved to a specific template, then builds the appropriate kind of
593 /// template name. Subclasses may override this routine to provide different
594 /// behavior.
595 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000596 const IdentifierInfo &II,
597 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000598
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000599 /// \brief Build a new template name given a nested name specifier and the
600 /// overloaded operator name that is referred to as a template.
601 ///
602 /// By default, performs semantic analysis to determine whether the name can
603 /// be resolved to a specific template, then builds the appropriate kind of
604 /// template name. Subclasses may override this routine to provide different
605 /// behavior.
606 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
607 OverloadedOperatorKind Operator,
608 QualType ObjectType);
609
Douglas Gregor43959a92009-08-20 07:17:43 +0000610 /// \brief Build a new compound statement.
611 ///
612 /// By default, performs semantic analysis to build the new statement.
613 /// Subclasses may override this routine to provide different behavior.
614 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
615 MultiStmtArg Statements,
616 SourceLocation RBraceLoc,
617 bool IsStmtExpr) {
618 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
619 IsStmtExpr);
620 }
621
622 /// \brief Build a new case statement.
623 ///
624 /// By default, performs semantic analysis to build the new statement.
625 /// Subclasses may override this routine to provide different behavior.
626 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
627 ExprArg LHS,
628 SourceLocation EllipsisLoc,
629 ExprArg RHS,
630 SourceLocation ColonLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000631 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregor43959a92009-08-20 07:17:43 +0000632 ColonLoc);
633 }
Mike Stump1eb44332009-09-09 15:08:12 +0000634
Douglas Gregor43959a92009-08-20 07:17:43 +0000635 /// \brief Attach the body to a new case 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 RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
640 getSema().ActOnCaseStmtBody(S.get(), move(Body));
641 return move(S);
642 }
Mike Stump1eb44332009-09-09 15:08:12 +0000643
Douglas Gregor43959a92009-08-20 07:17:43 +0000644 /// \brief Build a new default statement.
645 ///
646 /// By default, performs semantic analysis to build the new statement.
647 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000648 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000649 SourceLocation ColonLoc,
650 StmtArg SubStmt) {
Mike Stump1eb44332009-09-09 15:08:12 +0000651 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregor43959a92009-08-20 07:17:43 +0000652 /*CurScope=*/0);
653 }
Mike Stump1eb44332009-09-09 15:08:12 +0000654
Douglas Gregor43959a92009-08-20 07:17:43 +0000655 /// \brief Build a new label statement.
656 ///
657 /// By default, performs semantic analysis to build the new statement.
658 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000659 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000660 IdentifierInfo *Id,
661 SourceLocation ColonLoc,
662 StmtArg SubStmt) {
663 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
664 }
Mike Stump1eb44332009-09-09 15:08:12 +0000665
Douglas Gregor43959a92009-08-20 07:17:43 +0000666 /// \brief Build a new "if" statement.
667 ///
668 /// By default, performs semantic analysis to build the new statement.
669 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000670 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000671 VarDecl *CondVar, StmtArg Then,
672 SourceLocation ElseLoc, StmtArg Else) {
673 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
674 move(Then), ElseLoc, move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +0000675 }
Mike Stump1eb44332009-09-09 15:08:12 +0000676
Douglas Gregor43959a92009-08-20 07:17:43 +0000677 /// \brief Start building a new switch statement.
678 ///
679 /// By default, performs semantic analysis to build the new statement.
680 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000681 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
682 VarDecl *CondVar) {
683 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregor43959a92009-08-20 07:17:43 +0000684 }
Mike Stump1eb44332009-09-09 15:08:12 +0000685
Douglas Gregor43959a92009-08-20 07:17:43 +0000686 /// \brief Attach the body to the switch statement.
687 ///
688 /// By default, performs semantic analysis to build the new statement.
689 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000690 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000691 StmtArg Switch, StmtArg Body) {
692 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
693 move(Body));
694 }
695
696 /// \brief Build a new while statement.
697 ///
698 /// By default, performs semantic analysis to build the new statement.
699 /// Subclasses may override this routine to provide different behavior.
700 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
701 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000702 VarDecl *CondVar,
Douglas Gregor43959a92009-08-20 07:17:43 +0000703 StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000704 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
705 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000706 }
Mike Stump1eb44332009-09-09 15:08:12 +0000707
Douglas Gregor43959a92009-08-20 07:17:43 +0000708 /// \brief Build a new do-while statement.
709 ///
710 /// By default, performs semantic analysis to build the new statement.
711 /// Subclasses may override this routine to provide different behavior.
712 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
713 SourceLocation WhileLoc,
714 SourceLocation LParenLoc,
715 ExprArg Cond,
716 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000717 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000718 move(Cond), RParenLoc);
719 }
720
721 /// \brief Build a new for statement.
722 ///
723 /// By default, performs semantic analysis to build the new statement.
724 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000725 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000726 SourceLocation LParenLoc,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000727 StmtArg Init, Sema::FullExprArg Cond,
728 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000729 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000730 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
731 DeclPtrTy::make(CondVar),
732 Inc, RParenLoc, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000733 }
Mike Stump1eb44332009-09-09 15:08:12 +0000734
Douglas Gregor43959a92009-08-20 07:17:43 +0000735 /// \brief Build a new goto statement.
736 ///
737 /// By default, performs semantic analysis to build the new statement.
738 /// Subclasses may override this routine to provide different behavior.
739 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
740 SourceLocation LabelLoc,
741 LabelStmt *Label) {
742 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
743 }
744
745 /// \brief Build a new indirect goto statement.
746 ///
747 /// By default, performs semantic analysis to build the new statement.
748 /// Subclasses may override this routine to provide different behavior.
749 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
750 SourceLocation StarLoc,
751 ExprArg Target) {
752 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
753 }
Mike Stump1eb44332009-09-09 15:08:12 +0000754
Douglas Gregor43959a92009-08-20 07:17:43 +0000755 /// \brief Build a new return statement.
756 ///
757 /// By default, performs semantic analysis to build the new statement.
758 /// Subclasses may override this routine to provide different behavior.
759 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
760 ExprArg Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000761
Douglas Gregor43959a92009-08-20 07:17:43 +0000762 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
763 }
Mike Stump1eb44332009-09-09 15:08:12 +0000764
Douglas Gregor43959a92009-08-20 07:17:43 +0000765 /// \brief Build a new declaration statement.
766 ///
767 /// By default, performs semantic analysis to build the new statement.
768 /// Subclasses may override this routine to provide different behavior.
769 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000770 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000771 SourceLocation EndLoc) {
772 return getSema().Owned(
773 new (getSema().Context) DeclStmt(
774 DeclGroupRef::Create(getSema().Context,
775 Decls, NumDecls),
776 StartLoc, EndLoc));
777 }
Mike Stump1eb44332009-09-09 15:08:12 +0000778
Douglas Gregor43959a92009-08-20 07:17:43 +0000779 /// \brief Build a new C++ exception declaration.
780 ///
781 /// By default, performs semantic analysis to build the new decaration.
782 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000783 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000784 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000785 IdentifierInfo *Name,
786 SourceLocation Loc,
787 SourceRange TypeRange) {
Mike Stump1eb44332009-09-09 15:08:12 +0000788 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000789 TypeRange);
790 }
791
792 /// \brief Build a new C++ catch statement.
793 ///
794 /// By default, performs semantic analysis to build the new statement.
795 /// Subclasses may override this routine to provide different behavior.
796 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
797 VarDecl *ExceptionDecl,
798 StmtArg Handler) {
799 return getSema().Owned(
Mike Stump1eb44332009-09-09 15:08:12 +0000800 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregor43959a92009-08-20 07:17:43 +0000801 Handler.takeAs<Stmt>()));
802 }
Mike Stump1eb44332009-09-09 15:08:12 +0000803
Douglas Gregor43959a92009-08-20 07:17:43 +0000804 /// \brief Build a new C++ try statement.
805 ///
806 /// By default, performs semantic analysis to build the new statement.
807 /// Subclasses may override this routine to provide different behavior.
808 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
809 StmtArg TryBlock,
810 MultiStmtArg Handlers) {
811 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
812 }
Mike Stump1eb44332009-09-09 15:08:12 +0000813
Douglas Gregorb98b1992009-08-11 05:31:07 +0000814 /// \brief Build a new expression that references a declaration.
815 ///
816 /// By default, performs semantic analysis to build the new expression.
817 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +0000818 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
819 LookupResult &R,
820 bool RequiresADL) {
821 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
822 }
823
824
825 /// \brief Build a new expression that references a declaration.
826 ///
827 /// By default, performs semantic analysis to build the new expression.
828 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora2813ce2009-10-23 18:54:35 +0000829 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
830 SourceRange QualifierRange,
John McCalldbd872f2009-12-08 09:08:17 +0000831 ValueDecl *VD, SourceLocation Loc,
832 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +0000833 CXXScopeSpec SS;
834 SS.setScopeRep(Qualifier);
835 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +0000836
837 // FIXME: loses template args.
838
839 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000840 }
Mike Stump1eb44332009-09-09 15:08:12 +0000841
Douglas Gregorb98b1992009-08-11 05:31:07 +0000842 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +0000843 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000844 /// By default, performs semantic analysis to build the new expression.
845 /// Subclasses may override this routine to provide different behavior.
846 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
847 SourceLocation RParen) {
848 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
849 }
850
Douglas Gregora71d8192009-09-04 17:36:40 +0000851 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000852 ///
Douglas Gregora71d8192009-09-04 17:36:40 +0000853 /// By default, performs semantic analysis to build the new expression.
854 /// Subclasses may override this routine to provide different behavior.
855 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
856 SourceLocation OperatorLoc,
857 bool isArrow,
858 SourceLocation DestroyedTypeLoc,
859 QualType DestroyedType,
860 NestedNameSpecifier *Qualifier,
861 SourceRange QualifierRange) {
862 CXXScopeSpec SS;
863 if (Qualifier) {
864 SS.setRange(QualifierRange);
865 SS.setScopeRep(Qualifier);
866 }
867
John McCallaa81e162009-12-01 22:10:20 +0000868 QualType BaseType = ((Expr*) Base.get())->getType();
869
Mike Stump1eb44332009-09-09 15:08:12 +0000870 DeclarationName Name
Douglas Gregora71d8192009-09-04 17:36:40 +0000871 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
872 SemaRef.Context.getCanonicalType(DestroyedType));
Mike Stump1eb44332009-09-09 15:08:12 +0000873
John McCallaa81e162009-12-01 22:10:20 +0000874 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
875 OperatorLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +0000876 SS, /*FIXME: FirstQualifier*/ 0,
877 Name, DestroyedTypeLoc,
878 /*TemplateArgs*/ 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000879 }
880
Douglas Gregorb98b1992009-08-11 05:31:07 +0000881 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000882 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000883 /// By default, performs semantic analysis to build the new expression.
884 /// Subclasses may override this routine to provide different behavior.
885 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
886 UnaryOperator::Opcode Opc,
887 ExprArg SubExpr) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +0000888 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +0000889 }
Mike Stump1eb44332009-09-09 15:08:12 +0000890
Douglas Gregorb98b1992009-08-11 05:31:07 +0000891 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +0000892 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000893 /// By default, performs semantic analysis to build the new expression.
894 /// Subclasses may override this routine to provide different behavior.
John McCalla93c9342009-12-07 02:54:59 +0000895 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +0000896 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000897 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +0000898 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000899 }
900
Mike Stump1eb44332009-09-09 15:08:12 +0000901 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +0000902 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +0000903 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000904 /// By default, performs semantic analysis to build the new expression.
905 /// Subclasses may override this routine to provide different behavior.
906 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
907 bool isSizeOf, SourceRange R) {
Mike Stump1eb44332009-09-09 15:08:12 +0000908 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +0000909 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
910 OpLoc, isSizeOf, R);
911 if (Result.isInvalid())
912 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +0000913
Douglas Gregorb98b1992009-08-11 05:31:07 +0000914 SubExpr.release();
915 return move(Result);
916 }
Mike Stump1eb44332009-09-09 15:08:12 +0000917
Douglas Gregorb98b1992009-08-11 05:31:07 +0000918 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000919 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000920 /// By default, performs semantic analysis to build the new expression.
921 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000922 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000923 SourceLocation LBracketLoc,
924 ExprArg RHS,
925 SourceLocation RBracketLoc) {
926 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump1eb44332009-09-09 15:08:12 +0000927 LBracketLoc, move(RHS),
Douglas Gregorb98b1992009-08-11 05:31:07 +0000928 RBracketLoc);
929 }
930
931 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000932 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000933 /// By default, performs semantic analysis to build the new expression.
934 /// Subclasses may override this routine to provide different behavior.
935 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
936 MultiExprArg Args,
937 SourceLocation *CommaLocs,
938 SourceLocation RParenLoc) {
939 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
940 move(Args), CommaLocs, RParenLoc);
941 }
942
943 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000944 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000945 /// By default, performs semantic analysis to build the new expression.
946 /// Subclasses may override this routine to provide different behavior.
947 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +0000948 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000949 NestedNameSpecifier *Qualifier,
950 SourceRange QualifierRange,
951 SourceLocation MemberLoc,
Eli Friedmanf595cc42009-12-04 06:40:45 +0000952 ValueDecl *Member,
John McCalld5532b62009-11-23 01:53:49 +0000953 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +0000954 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +0000955 if (!Member->getDeclName()) {
956 // We have a reference to an unnamed field.
957 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +0000958
Douglas Gregor83a56c42009-12-24 20:02:50 +0000959 Expr *BaseExpr = Base.takeAs<Expr>();
960 if (getSema().PerformObjectMemberConversion(BaseExpr, Member))
961 return getSema().ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +0000962
Mike Stump1eb44332009-09-09 15:08:12 +0000963 MemberExpr *ME =
Douglas Gregor83a56c42009-12-24 20:02:50 +0000964 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlssond8b285f2009-09-01 04:26:58 +0000965 Member, MemberLoc,
966 cast<FieldDecl>(Member)->getType());
967 return getSema().Owned(ME);
968 }
Mike Stump1eb44332009-09-09 15:08:12 +0000969
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000970 CXXScopeSpec SS;
971 if (Qualifier) {
972 SS.setRange(QualifierRange);
973 SS.setScopeRep(Qualifier);
974 }
975
John McCallaa81e162009-12-01 22:10:20 +0000976 QualType BaseType = ((Expr*) Base.get())->getType();
977
John McCallc2233c52010-01-15 08:34:02 +0000978 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
979 Sema::LookupMemberName);
980 R.addDecl(Member);
981 R.resolveKind();
982
John McCallaa81e162009-12-01 22:10:20 +0000983 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
984 OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +0000985 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +0000986 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000987 }
Mike Stump1eb44332009-09-09 15:08:12 +0000988
Douglas Gregorb98b1992009-08-11 05:31:07 +0000989 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000990 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000991 /// By default, performs semantic analysis to build the new expression.
992 /// Subclasses may override this routine to provide different behavior.
993 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
994 BinaryOperator::Opcode Opc,
995 ExprArg LHS, ExprArg RHS) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +0000996 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
997 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregorb98b1992009-08-11 05:31:07 +0000998 }
999
1000 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001001 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001002 /// By default, performs semantic analysis to build the new expression.
1003 /// Subclasses may override this routine to provide different behavior.
1004 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1005 SourceLocation QuestionLoc,
1006 ExprArg LHS,
1007 SourceLocation ColonLoc,
1008 ExprArg RHS) {
Mike Stump1eb44332009-09-09 15:08:12 +00001009 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001010 move(LHS), move(RHS));
1011 }
1012
Douglas Gregorb98b1992009-08-11 05:31:07 +00001013 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001014 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001015 /// By default, performs semantic analysis to build the new expression.
1016 /// Subclasses may override this routine to provide different behavior.
1017 OwningExprResult RebuildCStyleCaseExpr(SourceLocation LParenLoc,
1018 QualType ExplicitTy,
1019 SourceLocation RParenLoc,
1020 ExprArg SubExpr) {
1021 return getSema().ActOnCastExpr(/*Scope=*/0,
1022 LParenLoc,
1023 ExplicitTy.getAsOpaquePtr(),
1024 RParenLoc,
1025 move(SubExpr));
1026 }
Mike Stump1eb44332009-09-09 15:08:12 +00001027
Douglas Gregorb98b1992009-08-11 05:31:07 +00001028 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001029 ///
Douglas Gregorb98b1992009-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 RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
1033 QualType T,
1034 SourceLocation RParenLoc,
1035 ExprArg Init) {
1036 return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(),
1037 RParenLoc, move(Init));
1038 }
Mike Stump1eb44332009-09-09 15:08:12 +00001039
Douglas Gregorb98b1992009-08-11 05:31:07 +00001040 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001041 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001042 /// By default, performs semantic analysis to build the new expression.
1043 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001044 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001045 SourceLocation OpLoc,
1046 SourceLocation AccessorLoc,
1047 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001048
John McCall129e2df2009-11-30 22:42:35 +00001049 CXXScopeSpec SS;
John McCallaa81e162009-12-01 22:10:20 +00001050 QualType BaseType = ((Expr*) Base.get())->getType();
1051 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001052 OpLoc, /*IsArrow*/ false,
1053 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor2d1c2142009-11-03 19:44:04 +00001054 DeclarationName(&Accessor),
John McCall129e2df2009-11-30 22:42:35 +00001055 AccessorLoc,
1056 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001057 }
Mike Stump1eb44332009-09-09 15:08:12 +00001058
Douglas Gregorb98b1992009-08-11 05:31:07 +00001059 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001060 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001061 /// By default, performs semantic analysis to build the new expression.
1062 /// Subclasses may override this routine to provide different behavior.
1063 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1064 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001065 SourceLocation RBraceLoc,
1066 QualType ResultTy) {
1067 OwningExprResult Result
1068 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1069 if (Result.isInvalid() || ResultTy->isDependentType())
1070 return move(Result);
1071
1072 // Patch in the result type we were given, which may have been computed
1073 // when the initial InitListExpr was built.
1074 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1075 ILE->setType(ResultTy);
1076 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001077 }
Mike Stump1eb44332009-09-09 15:08:12 +00001078
Douglas Gregorb98b1992009-08-11 05:31:07 +00001079 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001080 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001081 /// By default, performs semantic analysis to build the new expression.
1082 /// Subclasses may override this routine to provide different behavior.
1083 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1084 MultiExprArg ArrayExprs,
1085 SourceLocation EqualOrColonLoc,
1086 bool GNUSyntax,
1087 ExprArg Init) {
1088 OwningExprResult Result
1089 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1090 move(Init));
1091 if (Result.isInvalid())
1092 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001093
Douglas Gregorb98b1992009-08-11 05:31:07 +00001094 ArrayExprs.release();
1095 return move(Result);
1096 }
Mike Stump1eb44332009-09-09 15:08:12 +00001097
Douglas Gregorb98b1992009-08-11 05:31:07 +00001098 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001099 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001100 /// By default, builds the implicit value initialization without performing
1101 /// any semantic analysis. Subclasses may override this routine to provide
1102 /// different behavior.
1103 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1104 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1105 }
Mike Stump1eb44332009-09-09 15:08:12 +00001106
Douglas Gregorb98b1992009-08-11 05:31:07 +00001107 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001108 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001109 /// By default, performs semantic analysis to build the new expression.
1110 /// Subclasses may override this routine to provide different behavior.
1111 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1112 QualType T, SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001113 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001114 RParenLoc);
1115 }
1116
1117 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001118 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001119 /// By default, performs semantic analysis to build the new expression.
1120 /// Subclasses may override this routine to provide different behavior.
1121 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1122 MultiExprArg SubExprs,
1123 SourceLocation RParenLoc) {
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001124 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1125 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001126 }
Mike Stump1eb44332009-09-09 15:08:12 +00001127
Douglas Gregorb98b1992009-08-11 05:31:07 +00001128 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001129 ///
1130 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001131 /// rather than attempting to map the label statement itself.
1132 /// Subclasses may override this routine to provide different behavior.
1133 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1134 SourceLocation LabelLoc,
1135 LabelStmt *Label) {
1136 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1137 }
Mike Stump1eb44332009-09-09 15:08:12 +00001138
Douglas Gregorb98b1992009-08-11 05:31:07 +00001139 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001140 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001141 /// By default, performs semantic analysis to build the new expression.
1142 /// Subclasses may override this routine to provide different behavior.
1143 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1144 StmtArg SubStmt,
1145 SourceLocation RParenLoc) {
1146 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1147 }
Mike Stump1eb44332009-09-09 15:08:12 +00001148
Douglas Gregorb98b1992009-08-11 05:31:07 +00001149 /// \brief Build a new __builtin_types_compatible_p expression.
1150 ///
1151 /// By default, performs semantic analysis to build the new expression.
1152 /// Subclasses may override this routine to provide different behavior.
1153 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1154 QualType T1, QualType T2,
1155 SourceLocation RParenLoc) {
1156 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1157 T1.getAsOpaquePtr(),
1158 T2.getAsOpaquePtr(),
1159 RParenLoc);
1160 }
Mike Stump1eb44332009-09-09 15:08:12 +00001161
Douglas Gregorb98b1992009-08-11 05:31:07 +00001162 /// \brief Build a new __builtin_choose_expr expression.
1163 ///
1164 /// By default, performs semantic analysis to build the new expression.
1165 /// Subclasses may override this routine to provide different behavior.
1166 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1167 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1168 SourceLocation RParenLoc) {
1169 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1170 move(Cond), move(LHS), move(RHS),
1171 RParenLoc);
1172 }
Mike Stump1eb44332009-09-09 15:08:12 +00001173
Douglas Gregorb98b1992009-08-11 05:31:07 +00001174 /// \brief Build a new overloaded operator call expression.
1175 ///
1176 /// By default, performs semantic analysis to build the new expression.
1177 /// The semantic analysis provides the behavior of template instantiation,
1178 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001179 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001180 /// argument-dependent lookup, etc. Subclasses may override this routine to
1181 /// provide different behavior.
1182 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1183 SourceLocation OpLoc,
1184 ExprArg Callee,
1185 ExprArg First,
1186 ExprArg Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001187
1188 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001189 /// reinterpret_cast.
1190 ///
1191 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001192 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001193 /// Subclasses may override this routine to provide different behavior.
1194 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1195 Stmt::StmtClass Class,
1196 SourceLocation LAngleLoc,
1197 QualType T,
1198 SourceLocation RAngleLoc,
1199 SourceLocation LParenLoc,
1200 ExprArg SubExpr,
1201 SourceLocation RParenLoc) {
1202 switch (Class) {
1203 case Stmt::CXXStaticCastExprClass:
Mike Stump1eb44332009-09-09 15:08:12 +00001204 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T,
1205 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001206 move(SubExpr), RParenLoc);
1207
1208 case Stmt::CXXDynamicCastExprClass:
Mike Stump1eb44332009-09-09 15:08:12 +00001209 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T,
1210 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001211 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001212
Douglas Gregorb98b1992009-08-11 05:31:07 +00001213 case Stmt::CXXReinterpretCastExprClass:
Mike Stump1eb44332009-09-09 15:08:12 +00001214 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T,
1215 RAngleLoc, LParenLoc,
1216 move(SubExpr),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001217 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001218
Douglas Gregorb98b1992009-08-11 05:31:07 +00001219 case Stmt::CXXConstCastExprClass:
Mike Stump1eb44332009-09-09 15:08:12 +00001220 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T,
1221 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001222 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001223
Douglas Gregorb98b1992009-08-11 05:31:07 +00001224 default:
1225 assert(false && "Invalid C++ named cast");
1226 break;
1227 }
Mike Stump1eb44332009-09-09 15:08:12 +00001228
Douglas Gregorb98b1992009-08-11 05:31:07 +00001229 return getSema().ExprError();
1230 }
Mike Stump1eb44332009-09-09 15:08:12 +00001231
Douglas Gregorb98b1992009-08-11 05:31:07 +00001232 /// \brief Build a new C++ static_cast expression.
1233 ///
1234 /// By default, performs semantic analysis to build the new expression.
1235 /// Subclasses may override this routine to provide different behavior.
1236 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1237 SourceLocation LAngleLoc,
1238 QualType T,
1239 SourceLocation RAngleLoc,
1240 SourceLocation LParenLoc,
1241 ExprArg SubExpr,
1242 SourceLocation RParenLoc) {
1243 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast,
Mike Stump1eb44332009-09-09 15:08:12 +00001244 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001245 LParenLoc, move(SubExpr), RParenLoc);
1246 }
1247
1248 /// \brief Build a new C++ dynamic_cast expression.
1249 ///
1250 /// By default, performs semantic analysis to build the new expression.
1251 /// Subclasses may override this routine to provide different behavior.
1252 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1253 SourceLocation LAngleLoc,
1254 QualType T,
1255 SourceLocation RAngleLoc,
1256 SourceLocation LParenLoc,
1257 ExprArg SubExpr,
1258 SourceLocation RParenLoc) {
1259 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
Mike Stump1eb44332009-09-09 15:08:12 +00001260 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001261 LParenLoc, move(SubExpr), RParenLoc);
1262 }
1263
1264 /// \brief Build a new C++ reinterpret_cast expression.
1265 ///
1266 /// By default, performs semantic analysis to build the new expression.
1267 /// Subclasses may override this routine to provide different behavior.
1268 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1269 SourceLocation LAngleLoc,
1270 QualType T,
1271 SourceLocation RAngleLoc,
1272 SourceLocation LParenLoc,
1273 ExprArg SubExpr,
1274 SourceLocation RParenLoc) {
1275 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1276 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
1277 LParenLoc, move(SubExpr), RParenLoc);
1278 }
1279
1280 /// \brief Build a new C++ const_cast expression.
1281 ///
1282 /// By default, performs semantic analysis to build the new expression.
1283 /// Subclasses may override this routine to provide different behavior.
1284 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1285 SourceLocation LAngleLoc,
1286 QualType T,
1287 SourceLocation RAngleLoc,
1288 SourceLocation LParenLoc,
1289 ExprArg SubExpr,
1290 SourceLocation RParenLoc) {
1291 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast,
Mike Stump1eb44332009-09-09 15:08:12 +00001292 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001293 LParenLoc, move(SubExpr), RParenLoc);
1294 }
Mike Stump1eb44332009-09-09 15:08:12 +00001295
Douglas Gregorb98b1992009-08-11 05:31:07 +00001296 /// \brief Build a new C++ functional-style cast expression.
1297 ///
1298 /// By default, performs semantic analysis to build the new expression.
1299 /// Subclasses may override this routine to provide different behavior.
1300 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
1301 QualType T,
1302 SourceLocation LParenLoc,
1303 ExprArg SubExpr,
1304 SourceLocation RParenLoc) {
Chris Lattner88650c32009-08-24 05:19:01 +00001305 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001306 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
1307 T.getAsOpaquePtr(),
1308 LParenLoc,
Chris Lattner88650c32009-08-24 05:19:01 +00001309 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump1eb44332009-09-09 15:08:12 +00001310 /*CommaLocs=*/0,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001311 RParenLoc);
1312 }
Mike Stump1eb44332009-09-09 15:08:12 +00001313
Douglas Gregorb98b1992009-08-11 05:31:07 +00001314 /// \brief Build a new C++ typeid(type) expression.
1315 ///
1316 /// By default, performs semantic analysis to build the new expression.
1317 /// Subclasses may override this routine to provide different behavior.
1318 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1319 SourceLocation LParenLoc,
1320 QualType T,
1321 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001322 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001323 T.getAsOpaquePtr(), RParenLoc);
1324 }
Mike Stump1eb44332009-09-09 15:08:12 +00001325
Douglas Gregorb98b1992009-08-11 05:31:07 +00001326 /// \brief Build a new C++ typeid(expr) expression.
1327 ///
1328 /// By default, performs semantic analysis to build the new expression.
1329 /// Subclasses may override this routine to provide different behavior.
1330 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1331 SourceLocation LParenLoc,
1332 ExprArg Operand,
1333 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001334 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001335 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1336 RParenLoc);
1337 if (Result.isInvalid())
1338 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001339
Douglas Gregorb98b1992009-08-11 05:31:07 +00001340 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1341 return move(Result);
Mike Stump1eb44332009-09-09 15:08:12 +00001342 }
1343
Douglas Gregorb98b1992009-08-11 05:31:07 +00001344 /// \brief Build a new C++ "this" expression.
1345 ///
1346 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001347 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001348 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001349 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001350 QualType ThisType,
1351 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001352 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001353 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1354 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001355 }
1356
1357 /// \brief Build a new C++ throw expression.
1358 ///
1359 /// By default, performs semantic analysis to build the new expression.
1360 /// Subclasses may override this routine to provide different behavior.
1361 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1362 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1363 }
1364
1365 /// \brief Build a new C++ default-argument expression.
1366 ///
1367 /// By default, builds a new default-argument expression, which does not
1368 /// require any semantic analysis. Subclasses may override this routine to
1369 /// provide different behavior.
Douglas Gregor036aed12009-12-23 23:03:06 +00001370 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1371 ParmVarDecl *Param) {
1372 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1373 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001374 }
1375
1376 /// \brief Build a new C++ zero-initialization expression.
1377 ///
1378 /// By default, performs semantic analysis to build the new expression.
1379 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001380 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001381 SourceLocation LParenLoc,
1382 QualType T,
1383 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001384 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1385 T.getAsOpaquePtr(), LParenLoc,
1386 MultiExprArg(getSema(), 0, 0),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001387 0, RParenLoc);
1388 }
Mike Stump1eb44332009-09-09 15:08:12 +00001389
Douglas Gregorb98b1992009-08-11 05:31:07 +00001390 /// \brief Build a new C++ "new" expression.
1391 ///
1392 /// By default, performs semantic analysis to build the new expression.
1393 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001394 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001395 bool UseGlobal,
1396 SourceLocation PlacementLParen,
1397 MultiExprArg PlacementArgs,
1398 SourceLocation PlacementRParen,
Mike Stump1eb44332009-09-09 15:08:12 +00001399 bool ParenTypeId,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001400 QualType AllocType,
1401 SourceLocation TypeLoc,
1402 SourceRange TypeRange,
1403 ExprArg ArraySize,
1404 SourceLocation ConstructorLParen,
1405 MultiExprArg ConstructorArgs,
1406 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001407 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001408 PlacementLParen,
1409 move(PlacementArgs),
1410 PlacementRParen,
1411 ParenTypeId,
1412 AllocType,
1413 TypeLoc,
1414 TypeRange,
1415 move(ArraySize),
1416 ConstructorLParen,
1417 move(ConstructorArgs),
1418 ConstructorRParen);
1419 }
Mike Stump1eb44332009-09-09 15:08:12 +00001420
Douglas Gregorb98b1992009-08-11 05:31:07 +00001421 /// \brief Build a new C++ "delete" 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 RebuildCXXDeleteExpr(SourceLocation StartLoc,
1426 bool IsGlobalDelete,
1427 bool IsArrayForm,
1428 ExprArg Operand) {
1429 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1430 move(Operand));
1431 }
Mike Stump1eb44332009-09-09 15:08:12 +00001432
Douglas Gregorb98b1992009-08-11 05:31:07 +00001433 /// \brief Build a new unary type trait expression.
1434 ///
1435 /// By default, performs semantic analysis to build the new expression.
1436 /// Subclasses may override this routine to provide different behavior.
1437 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1438 SourceLocation StartLoc,
1439 SourceLocation LParenLoc,
1440 QualType T,
1441 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001442 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001443 T.getAsOpaquePtr(), RParenLoc);
1444 }
1445
Mike Stump1eb44332009-09-09 15:08:12 +00001446 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001447 /// expression.
1448 ///
1449 /// By default, performs semantic analysis to build the new expression.
1450 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001451 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001452 SourceRange QualifierRange,
1453 DeclarationName Name,
1454 SourceLocation Location,
John McCallf7a1a742009-11-24 19:00:30 +00001455 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001456 CXXScopeSpec SS;
1457 SS.setRange(QualifierRange);
1458 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001459
1460 if (TemplateArgs)
1461 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1462 *TemplateArgs);
1463
1464 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001465 }
1466
1467 /// \brief Build a new template-id expression.
1468 ///
1469 /// By default, performs semantic analysis to build the new expression.
1470 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001471 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1472 LookupResult &R,
1473 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001474 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001475 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001476 }
1477
1478 /// \brief Build a new object-construction expression.
1479 ///
1480 /// By default, performs semantic analysis to build the new expression.
1481 /// Subclasses may override this routine to provide different behavior.
1482 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001483 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 CXXConstructorDecl *Constructor,
1485 bool IsElidable,
1486 MultiExprArg Args) {
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001487 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1488 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1489 ConvertedArgs))
1490 return getSema().ExprError();
1491
1492 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1493 move_arg(ConvertedArgs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001494 }
1495
1496 /// \brief Build a new object-construction expression.
1497 ///
1498 /// By default, performs semantic analysis to build the new expression.
1499 /// Subclasses may override this routine to provide different behavior.
1500 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1501 QualType T,
1502 SourceLocation LParenLoc,
1503 MultiExprArg Args,
1504 SourceLocation *Commas,
1505 SourceLocation RParenLoc) {
1506 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1507 T.getAsOpaquePtr(),
1508 LParenLoc,
1509 move(Args),
1510 Commas,
1511 RParenLoc);
1512 }
1513
1514 /// \brief Build a new object-construction expression.
1515 ///
1516 /// By default, performs semantic analysis to build the new expression.
1517 /// Subclasses may override this routine to provide different behavior.
1518 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1519 QualType T,
1520 SourceLocation LParenLoc,
1521 MultiExprArg Args,
1522 SourceLocation *Commas,
1523 SourceLocation RParenLoc) {
1524 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1525 /*FIXME*/LParenLoc),
1526 T.getAsOpaquePtr(),
1527 LParenLoc,
1528 move(Args),
1529 Commas,
1530 RParenLoc);
1531 }
Mike Stump1eb44332009-09-09 15:08:12 +00001532
Douglas Gregorb98b1992009-08-11 05:31:07 +00001533 /// \brief Build a new member reference expression.
1534 ///
1535 /// By default, performs semantic analysis to build the new expression.
1536 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001537 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001538 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001539 bool IsArrow,
1540 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001541 NestedNameSpecifier *Qualifier,
1542 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001543 NamedDecl *FirstQualifierInScope,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001544 DeclarationName Name,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001545 SourceLocation MemberLoc,
John McCall129e2df2009-11-30 22:42:35 +00001546 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001547 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001548 SS.setRange(QualifierRange);
1549 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001550
John McCallaa81e162009-12-01 22:10:20 +00001551 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1552 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001553 SS, FirstQualifierInScope,
1554 Name, MemberLoc, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001555 }
1556
John McCall129e2df2009-11-30 22:42:35 +00001557 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001558 ///
1559 /// By default, performs semantic analysis to build the new expression.
1560 /// Subclasses may override this routine to provide different behavior.
John McCall129e2df2009-11-30 22:42:35 +00001561 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001562 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001563 SourceLocation OperatorLoc,
1564 bool IsArrow,
1565 NestedNameSpecifier *Qualifier,
1566 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001567 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001568 LookupResult &R,
1569 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001570 CXXScopeSpec SS;
1571 SS.setRange(QualifierRange);
1572 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001573
John McCallaa81e162009-12-01 22:10:20 +00001574 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1575 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001576 SS, FirstQualifierInScope,
1577 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001578 }
Mike Stump1eb44332009-09-09 15:08:12 +00001579
Douglas Gregorb98b1992009-08-11 05:31:07 +00001580 /// \brief Build a new Objective-C @encode expression.
1581 ///
1582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
1584 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1585 QualType T,
1586 SourceLocation RParenLoc) {
1587 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1588 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001589 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590
1591 /// \brief Build a new Objective-C protocol expression.
1592 ///
1593 /// By default, performs semantic analysis to build the new expression.
1594 /// Subclasses may override this routine to provide different behavior.
1595 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1596 SourceLocation AtLoc,
1597 SourceLocation ProtoLoc,
1598 SourceLocation LParenLoc,
1599 SourceLocation RParenLoc) {
1600 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1601 Protocol->getIdentifier(),
1602 AtLoc,
1603 ProtoLoc,
1604 LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001605 RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 }
Mike Stump1eb44332009-09-09 15:08:12 +00001607
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 /// \brief Build a new shuffle vector expression.
1609 ///
1610 /// By default, performs semantic analysis to build the new expression.
1611 /// Subclasses may override this routine to provide different behavior.
1612 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1613 MultiExprArg SubExprs,
1614 SourceLocation RParenLoc) {
1615 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001616 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001617 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1618 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1619 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1620 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001621
Douglas Gregorb98b1992009-08-11 05:31:07 +00001622 // Build a reference to the __builtin_shufflevector builtin
1623 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001624 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001625 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001626 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001627 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001628
1629 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001630 unsigned NumSubExprs = SubExprs.size();
1631 Expr **Subs = (Expr **)SubExprs.release();
1632 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1633 Subs, NumSubExprs,
1634 Builtin->getResultType(),
1635 RParenLoc);
1636 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001637
Douglas Gregorb98b1992009-08-11 05:31:07 +00001638 // Type-check the __builtin_shufflevector expression.
1639 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1640 if (Result.isInvalid())
1641 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001642
Douglas Gregorb98b1992009-08-11 05:31:07 +00001643 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001644 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001645 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001646};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001647
Douglas Gregor43959a92009-08-20 07:17:43 +00001648template<typename Derived>
1649Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1650 if (!S)
1651 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001652
Douglas Gregor43959a92009-08-20 07:17:43 +00001653 switch (S->getStmtClass()) {
1654 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001655
Douglas Gregor43959a92009-08-20 07:17:43 +00001656 // Transform individual statement nodes
1657#define STMT(Node, Parent) \
1658 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1659#define EXPR(Node, Parent)
1660#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001661
Douglas Gregor43959a92009-08-20 07:17:43 +00001662 // Transform expressions by calling TransformExpr.
1663#define STMT(Node, Parent)
1664#define EXPR(Node, Parent) case Stmt::Node##Class:
1665#include "clang/AST/StmtNodes.def"
1666 {
1667 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1668 if (E.isInvalid())
1669 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001670
Anders Carlsson5ee56e92009-12-16 02:09:40 +00001671 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregor43959a92009-08-20 07:17:43 +00001672 }
Mike Stump1eb44332009-09-09 15:08:12 +00001673 }
1674
Douglas Gregor43959a92009-08-20 07:17:43 +00001675 return SemaRef.Owned(S->Retain());
1676}
Mike Stump1eb44332009-09-09 15:08:12 +00001677
1678
Douglas Gregor670444e2009-08-04 22:27:00 +00001679template<typename Derived>
John McCall454feb92009-12-08 09:21:05 +00001680Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 if (!E)
1682 return SemaRef.Owned(E);
1683
1684 switch (E->getStmtClass()) {
1685 case Stmt::NoStmtClass: break;
1686#define STMT(Node, Parent) case Stmt::Node##Class: break;
1687#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00001688 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001689#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001690 }
1691
Douglas Gregorb98b1992009-08-11 05:31:07 +00001692 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00001693}
1694
1695template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00001696NestedNameSpecifier *
1697TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00001698 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001699 QualType ObjectType,
1700 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00001701 if (!NNS)
1702 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001703
Douglas Gregor43959a92009-08-20 07:17:43 +00001704 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00001705 NestedNameSpecifier *Prefix = NNS->getPrefix();
1706 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00001707 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001708 ObjectType,
1709 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00001710 if (!Prefix)
1711 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001712
1713 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00001714 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00001715 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00001716 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001717 }
Mike Stump1eb44332009-09-09 15:08:12 +00001718
Douglas Gregordcee1a12009-08-06 05:28:30 +00001719 switch (NNS->getKind()) {
1720 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00001721 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00001722 "Identifier nested-name-specifier with no prefix or object type");
1723 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1724 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00001725 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001726
1727 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00001728 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00001729 ObjectType,
1730 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001731
Douglas Gregordcee1a12009-08-06 05:28:30 +00001732 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00001733 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00001734 = cast_or_null<NamespaceDecl>(
1735 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00001736 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00001737 Prefix == NNS->getPrefix() &&
1738 NS == NNS->getAsNamespace())
1739 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001740
Douglas Gregordcee1a12009-08-06 05:28:30 +00001741 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1742 }
Mike Stump1eb44332009-09-09 15:08:12 +00001743
Douglas Gregordcee1a12009-08-06 05:28:30 +00001744 case NestedNameSpecifier::Global:
1745 // There is no meaningful transformation that one could perform on the
1746 // global scope.
1747 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001748
Douglas Gregordcee1a12009-08-06 05:28:30 +00001749 case NestedNameSpecifier::TypeSpecWithTemplate:
1750 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00001751 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregordcee1a12009-08-06 05:28:30 +00001752 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregord1067e52009-08-06 06:41:21 +00001753 if (T.isNull())
1754 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001755
Douglas Gregordcee1a12009-08-06 05:28:30 +00001756 if (!getDerived().AlwaysRebuild() &&
1757 Prefix == NNS->getPrefix() &&
1758 T == QualType(NNS->getAsType(), 0))
1759 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001760
1761 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1762 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregordcee1a12009-08-06 05:28:30 +00001763 T);
1764 }
1765 }
Mike Stump1eb44332009-09-09 15:08:12 +00001766
Douglas Gregordcee1a12009-08-06 05:28:30 +00001767 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00001768 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001769}
1770
1771template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001772DeclarationName
Douglas Gregor81499bb2009-09-03 22:13:48 +00001773TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +00001774 SourceLocation Loc,
1775 QualType ObjectType) {
Douglas Gregor81499bb2009-09-03 22:13:48 +00001776 if (!Name)
1777 return Name;
1778
1779 switch (Name.getNameKind()) {
1780 case DeclarationName::Identifier:
1781 case DeclarationName::ObjCZeroArgSelector:
1782 case DeclarationName::ObjCOneArgSelector:
1783 case DeclarationName::ObjCMultiArgSelector:
1784 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00001785 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00001786 case DeclarationName::CXXUsingDirective:
1787 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001788
Douglas Gregor81499bb2009-09-03 22:13:48 +00001789 case DeclarationName::CXXConstructorName:
1790 case DeclarationName::CXXDestructorName:
1791 case DeclarationName::CXXConversionFunctionName: {
1792 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregordd62b152009-10-19 22:04:39 +00001793 QualType T;
1794 if (!ObjectType.isNull() &&
1795 isa<TemplateSpecializationType>(Name.getCXXNameType())) {
1796 TemplateSpecializationType *SpecType
1797 = cast<TemplateSpecializationType>(Name.getCXXNameType());
1798 T = TransformTemplateSpecializationType(SpecType, ObjectType);
1799 } else
1800 T = getDerived().TransformType(Name.getCXXNameType());
Douglas Gregor81499bb2009-09-03 22:13:48 +00001801 if (T.isNull())
1802 return DeclarationName();
Mike Stump1eb44332009-09-09 15:08:12 +00001803
Douglas Gregor81499bb2009-09-03 22:13:48 +00001804 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump1eb44332009-09-09 15:08:12 +00001805 Name.getNameKind(),
Douglas Gregor81499bb2009-09-03 22:13:48 +00001806 SemaRef.Context.getCanonicalType(T));
Douglas Gregor81499bb2009-09-03 22:13:48 +00001807 }
Mike Stump1eb44332009-09-09 15:08:12 +00001808 }
1809
Douglas Gregor81499bb2009-09-03 22:13:48 +00001810 return DeclarationName();
1811}
1812
1813template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001814TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001815TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1816 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00001817 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001818 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00001819 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1820 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1821 if (!NNS)
1822 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001823
Douglas Gregord1067e52009-08-06 06:41:21 +00001824 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001825 TemplateDecl *TransTemplate
Douglas Gregord1067e52009-08-06 06:41:21 +00001826 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1827 if (!TransTemplate)
1828 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001829
Douglas Gregord1067e52009-08-06 06:41:21 +00001830 if (!getDerived().AlwaysRebuild() &&
1831 NNS == QTN->getQualifier() &&
1832 TransTemplate == Template)
1833 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001834
Douglas Gregord1067e52009-08-06 06:41:21 +00001835 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1836 TransTemplate);
1837 }
Mike Stump1eb44332009-09-09 15:08:12 +00001838
John McCallf7a1a742009-11-24 19:00:30 +00001839 // These should be getting filtered out before they make it into the AST.
1840 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00001841 }
Mike Stump1eb44332009-09-09 15:08:12 +00001842
Douglas Gregord1067e52009-08-06 06:41:21 +00001843 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001844 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00001845 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1846 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001847 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00001848 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001849
Douglas Gregord1067e52009-08-06 06:41:21 +00001850 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00001851 NNS == DTN->getQualifier() &&
1852 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00001853 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001854
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001855 if (DTN->isIdentifier())
1856 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1857 ObjectType);
1858
1859 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1860 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00001861 }
Mike Stump1eb44332009-09-09 15:08:12 +00001862
Douglas Gregord1067e52009-08-06 06:41:21 +00001863 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001864 TemplateDecl *TransTemplate
Douglas Gregord1067e52009-08-06 06:41:21 +00001865 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1866 if (!TransTemplate)
1867 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001868
Douglas Gregord1067e52009-08-06 06:41:21 +00001869 if (!getDerived().AlwaysRebuild() &&
1870 TransTemplate == Template)
1871 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001872
Douglas Gregord1067e52009-08-06 06:41:21 +00001873 return TemplateName(TransTemplate);
1874 }
Mike Stump1eb44332009-09-09 15:08:12 +00001875
John McCallf7a1a742009-11-24 19:00:30 +00001876 // These should be getting filtered out before they reach the AST.
1877 assert(false && "overloaded function decl survived to here");
1878 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00001879}
1880
1881template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00001882void TreeTransform<Derived>::InventTemplateArgumentLoc(
1883 const TemplateArgument &Arg,
1884 TemplateArgumentLoc &Output) {
1885 SourceLocation Loc = getDerived().getBaseLocation();
1886 switch (Arg.getKind()) {
1887 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00001888 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00001889 break;
1890
1891 case TemplateArgument::Type:
1892 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00001893 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall833ca992009-10-29 08:12:44 +00001894
1895 break;
1896
Douglas Gregor788cd062009-11-11 01:00:40 +00001897 case TemplateArgument::Template:
1898 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1899 break;
1900
John McCall833ca992009-10-29 08:12:44 +00001901 case TemplateArgument::Expression:
1902 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1903 break;
1904
1905 case TemplateArgument::Declaration:
1906 case TemplateArgument::Integral:
1907 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00001908 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00001909 break;
1910 }
1911}
1912
1913template<typename Derived>
1914bool TreeTransform<Derived>::TransformTemplateArgument(
1915 const TemplateArgumentLoc &Input,
1916 TemplateArgumentLoc &Output) {
1917 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00001918 switch (Arg.getKind()) {
1919 case TemplateArgument::Null:
1920 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00001921 Output = Input;
1922 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00001923
Douglas Gregor670444e2009-08-04 22:27:00 +00001924 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00001925 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00001926 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00001927 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00001928
1929 DI = getDerived().TransformType(DI);
1930 if (!DI) return true;
1931
1932 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1933 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00001934 }
Mike Stump1eb44332009-09-09 15:08:12 +00001935
Douglas Gregor670444e2009-08-04 22:27:00 +00001936 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00001937 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00001938 DeclarationName Name;
1939 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1940 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00001941 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor670444e2009-08-04 22:27:00 +00001942 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00001943 if (!D) return true;
1944
John McCall828bff22009-10-29 18:45:58 +00001945 Expr *SourceExpr = Input.getSourceDeclExpression();
1946 if (SourceExpr) {
1947 EnterExpressionEvaluationContext Unevaluated(getSema(),
1948 Action::Unevaluated);
1949 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1950 if (E.isInvalid())
1951 SourceExpr = NULL;
1952 else {
1953 SourceExpr = E.takeAs<Expr>();
1954 SourceExpr->Retain();
1955 }
1956 }
1957
1958 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00001959 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00001960 }
Mike Stump1eb44332009-09-09 15:08:12 +00001961
Douglas Gregor788cd062009-11-11 01:00:40 +00001962 case TemplateArgument::Template: {
1963 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1964 TemplateName Template
1965 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1966 if (Template.isNull())
1967 return true;
1968
1969 Output = TemplateArgumentLoc(TemplateArgument(Template),
1970 Input.getTemplateQualifierRange(),
1971 Input.getTemplateNameLoc());
1972 return false;
1973 }
1974
Douglas Gregor670444e2009-08-04 22:27:00 +00001975 case TemplateArgument::Expression: {
1976 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00001977 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregor670444e2009-08-04 22:27:00 +00001978 Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00001979
John McCall833ca992009-10-29 08:12:44 +00001980 Expr *InputExpr = Input.getSourceExpression();
1981 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
1982
1983 Sema::OwningExprResult E
1984 = getDerived().TransformExpr(InputExpr);
1985 if (E.isInvalid()) return true;
1986
1987 Expr *ETaken = E.takeAs<Expr>();
John McCall828bff22009-10-29 18:45:58 +00001988 ETaken->Retain();
John McCall833ca992009-10-29 08:12:44 +00001989 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
1990 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00001991 }
Mike Stump1eb44332009-09-09 15:08:12 +00001992
Douglas Gregor670444e2009-08-04 22:27:00 +00001993 case TemplateArgument::Pack: {
1994 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
1995 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00001996 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00001997 AEnd = Arg.pack_end();
1998 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00001999
John McCall833ca992009-10-29 08:12:44 +00002000 // FIXME: preserve source information here when we start
2001 // caring about parameter packs.
2002
John McCall828bff22009-10-29 18:45:58 +00002003 TemplateArgumentLoc InputArg;
2004 TemplateArgumentLoc OutputArg;
2005 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2006 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002007 return true;
2008
John McCall828bff22009-10-29 18:45:58 +00002009 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002010 }
2011 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002012 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002013 true);
John McCall828bff22009-10-29 18:45:58 +00002014 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002015 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002016 }
2017 }
Mike Stump1eb44332009-09-09 15:08:12 +00002018
Douglas Gregor670444e2009-08-04 22:27:00 +00002019 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002020 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002021}
2022
Douglas Gregor577f75a2009-08-04 16:50:30 +00002023//===----------------------------------------------------------------------===//
2024// Type transformation
2025//===----------------------------------------------------------------------===//
2026
2027template<typename Derived>
2028QualType TreeTransform<Derived>::TransformType(QualType T) {
2029 if (getDerived().AlreadyTransformed(T))
2030 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002031
John McCalla2becad2009-10-21 00:40:46 +00002032 // Temporary workaround. All of these transformations should
2033 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002034 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002035 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCalla2becad2009-10-21 00:40:46 +00002036
John McCalla93c9342009-12-07 02:54:59 +00002037 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00002038
John McCalla2becad2009-10-21 00:40:46 +00002039 if (!NewDI)
2040 return QualType();
2041
2042 return NewDI->getType();
2043}
2044
2045template<typename Derived>
John McCalla93c9342009-12-07 02:54:59 +00002046TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00002047 if (getDerived().AlreadyTransformed(DI->getType()))
2048 return DI;
2049
2050 TypeLocBuilder TLB;
2051
2052 TypeLoc TL = DI->getTypeLoc();
2053 TLB.reserve(TL.getFullDataSize());
2054
2055 QualType Result = getDerived().TransformType(TLB, TL);
2056 if (Result.isNull())
2057 return 0;
2058
John McCalla93c9342009-12-07 02:54:59 +00002059 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002060}
2061
2062template<typename Derived>
2063QualType
2064TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
2065 switch (T.getTypeLocClass()) {
2066#define ABSTRACT_TYPELOC(CLASS, PARENT)
2067#define TYPELOC(CLASS, PARENT) \
2068 case TypeLoc::CLASS: \
2069 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2070#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002071 }
Mike Stump1eb44332009-09-09 15:08:12 +00002072
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002073 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002074 return QualType();
2075}
2076
2077/// FIXME: By default, this routine adds type qualifiers only to types
2078/// that can have qualifiers, and silently suppresses those qualifiers
2079/// that are not permitted (e.g., qualifiers on reference or function
2080/// types). This is the right thing for template instantiation, but
2081/// probably not for other clients.
2082template<typename Derived>
2083QualType
2084TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
2085 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002086 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002087
2088 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2089 if (Result.isNull())
2090 return QualType();
2091
2092 // Silently suppress qualifiers if the result type can't be qualified.
2093 // FIXME: this is the right thing for template instantiation, but
2094 // probably not for other clients.
2095 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002096 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002097
John McCalla2becad2009-10-21 00:40:46 +00002098 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2099
2100 TLB.push<QualifiedTypeLoc>(Result);
2101
2102 // No location information to preserve.
2103
2104 return Result;
2105}
2106
2107template <class TyLoc> static inline
2108QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2109 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2110 NewT.setNameLoc(T.getNameLoc());
2111 return T.getType();
2112}
2113
2114// Ugly metaprogramming macros because I couldn't be bothered to make
2115// the equivalent template version work.
2116#define TransformPointerLikeType(TypeClass) do { \
2117 QualType PointeeType \
2118 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2119 if (PointeeType.isNull()) \
2120 return QualType(); \
2121 \
2122 QualType Result = TL.getType(); \
2123 if (getDerived().AlwaysRebuild() || \
2124 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall85737a72009-10-30 00:06:24 +00002125 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2126 TL.getSigilLoc()); \
John McCalla2becad2009-10-21 00:40:46 +00002127 if (Result.isNull()) \
2128 return QualType(); \
2129 } \
2130 \
2131 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2132 NewT.setSigilLoc(TL.getSigilLoc()); \
2133 \
2134 return Result; \
2135} while(0)
2136
John McCalla2becad2009-10-21 00:40:46 +00002137template<typename Derived>
2138QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
2139 BuiltinTypeLoc T) {
2140 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002141}
Mike Stump1eb44332009-09-09 15:08:12 +00002142
Douglas Gregor577f75a2009-08-04 16:50:30 +00002143template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002144QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
2145 ComplexTypeLoc T) {
2146 // FIXME: recurse?
2147 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002148}
Mike Stump1eb44332009-09-09 15:08:12 +00002149
Douglas Gregor577f75a2009-08-04 16:50:30 +00002150template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002151QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
2152 PointerTypeLoc TL) {
2153 TransformPointerLikeType(PointerType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002154}
Mike Stump1eb44332009-09-09 15:08:12 +00002155
2156template<typename Derived>
2157QualType
John McCalla2becad2009-10-21 00:40:46 +00002158TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
2159 BlockPointerTypeLoc TL) {
2160 TransformPointerLikeType(BlockPointerType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002161}
2162
John McCall85737a72009-10-30 00:06:24 +00002163/// Transforms a reference type. Note that somewhat paradoxically we
2164/// don't care whether the type itself is an l-value type or an r-value
2165/// type; we only care if the type was *written* as an l-value type
2166/// or an r-value type.
2167template<typename Derived>
2168QualType
2169TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
2170 ReferenceTypeLoc TL) {
2171 const ReferenceType *T = TL.getTypePtr();
2172
2173 // Note that this works with the pointee-as-written.
2174 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2175 if (PointeeType.isNull())
2176 return QualType();
2177
2178 QualType Result = TL.getType();
2179 if (getDerived().AlwaysRebuild() ||
2180 PointeeType != T->getPointeeTypeAsWritten()) {
2181 Result = getDerived().RebuildReferenceType(PointeeType,
2182 T->isSpelledAsLValue(),
2183 TL.getSigilLoc());
2184 if (Result.isNull())
2185 return QualType();
2186 }
2187
2188 // r-value references can be rebuilt as l-value references.
2189 ReferenceTypeLoc NewTL;
2190 if (isa<LValueReferenceType>(Result))
2191 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2192 else
2193 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2194 NewTL.setSigilLoc(TL.getSigilLoc());
2195
2196 return Result;
2197}
2198
Mike Stump1eb44332009-09-09 15:08:12 +00002199template<typename Derived>
2200QualType
John McCalla2becad2009-10-21 00:40:46 +00002201TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
2202 LValueReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00002203 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002204}
2205
Mike Stump1eb44332009-09-09 15:08:12 +00002206template<typename Derived>
2207QualType
John McCalla2becad2009-10-21 00:40:46 +00002208TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
2209 RValueReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00002210 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002211}
Mike Stump1eb44332009-09-09 15:08:12 +00002212
Douglas Gregor577f75a2009-08-04 16:50:30 +00002213template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002214QualType
John McCalla2becad2009-10-21 00:40:46 +00002215TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
2216 MemberPointerTypeLoc TL) {
2217 MemberPointerType *T = TL.getTypePtr();
2218
2219 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002220 if (PointeeType.isNull())
2221 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002222
John McCalla2becad2009-10-21 00:40:46 +00002223 // TODO: preserve source information for this.
2224 QualType ClassType
2225 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002226 if (ClassType.isNull())
2227 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002228
John McCalla2becad2009-10-21 00:40:46 +00002229 QualType Result = TL.getType();
2230 if (getDerived().AlwaysRebuild() ||
2231 PointeeType != T->getPointeeType() ||
2232 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002233 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2234 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002235 if (Result.isNull())
2236 return QualType();
2237 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002238
John McCalla2becad2009-10-21 00:40:46 +00002239 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2240 NewTL.setSigilLoc(TL.getSigilLoc());
2241
2242 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002243}
2244
Mike Stump1eb44332009-09-09 15:08:12 +00002245template<typename Derived>
2246QualType
John McCalla2becad2009-10-21 00:40:46 +00002247TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
2248 ConstantArrayTypeLoc TL) {
2249 ConstantArrayType *T = TL.getTypePtr();
2250 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002251 if (ElementType.isNull())
2252 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002253
John McCalla2becad2009-10-21 00:40:46 +00002254 QualType Result = TL.getType();
2255 if (getDerived().AlwaysRebuild() ||
2256 ElementType != T->getElementType()) {
2257 Result = getDerived().RebuildConstantArrayType(ElementType,
2258 T->getSizeModifier(),
2259 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002260 T->getIndexTypeCVRQualifiers(),
2261 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002262 if (Result.isNull())
2263 return QualType();
2264 }
2265
2266 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2267 NewTL.setLBracketLoc(TL.getLBracketLoc());
2268 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002269
John McCalla2becad2009-10-21 00:40:46 +00002270 Expr *Size = TL.getSizeExpr();
2271 if (Size) {
2272 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2273 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2274 }
2275 NewTL.setSizeExpr(Size);
2276
2277 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002278}
Mike Stump1eb44332009-09-09 15:08:12 +00002279
Douglas Gregor577f75a2009-08-04 16:50:30 +00002280template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002281QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002282 TypeLocBuilder &TLB,
2283 IncompleteArrayTypeLoc TL) {
2284 IncompleteArrayType *T = TL.getTypePtr();
2285 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002286 if (ElementType.isNull())
2287 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002288
John McCalla2becad2009-10-21 00:40:46 +00002289 QualType Result = TL.getType();
2290 if (getDerived().AlwaysRebuild() ||
2291 ElementType != T->getElementType()) {
2292 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002293 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002294 T->getIndexTypeCVRQualifiers(),
2295 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002296 if (Result.isNull())
2297 return QualType();
2298 }
2299
2300 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2301 NewTL.setLBracketLoc(TL.getLBracketLoc());
2302 NewTL.setRBracketLoc(TL.getRBracketLoc());
2303 NewTL.setSizeExpr(0);
2304
2305 return Result;
2306}
2307
2308template<typename Derived>
2309QualType
2310TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
2311 VariableArrayTypeLoc TL) {
2312 VariableArrayType *T = TL.getTypePtr();
2313 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2314 if (ElementType.isNull())
2315 return QualType();
2316
2317 // Array bounds are not potentially evaluated contexts
2318 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2319
2320 Sema::OwningExprResult SizeResult
2321 = getDerived().TransformExpr(T->getSizeExpr());
2322 if (SizeResult.isInvalid())
2323 return QualType();
2324
2325 Expr *Size = static_cast<Expr*>(SizeResult.get());
2326
2327 QualType Result = TL.getType();
2328 if (getDerived().AlwaysRebuild() ||
2329 ElementType != T->getElementType() ||
2330 Size != T->getSizeExpr()) {
2331 Result = getDerived().RebuildVariableArrayType(ElementType,
2332 T->getSizeModifier(),
2333 move(SizeResult),
2334 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002335 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002336 if (Result.isNull())
2337 return QualType();
2338 }
2339 else SizeResult.take();
2340
2341 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2342 NewTL.setLBracketLoc(TL.getLBracketLoc());
2343 NewTL.setRBracketLoc(TL.getRBracketLoc());
2344 NewTL.setSizeExpr(Size);
2345
2346 return Result;
2347}
2348
2349template<typename Derived>
2350QualType
2351TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
2352 DependentSizedArrayTypeLoc TL) {
2353 DependentSizedArrayType *T = TL.getTypePtr();
2354 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2355 if (ElementType.isNull())
2356 return QualType();
2357
2358 // Array bounds are not potentially evaluated contexts
2359 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2360
2361 Sema::OwningExprResult SizeResult
2362 = getDerived().TransformExpr(T->getSizeExpr());
2363 if (SizeResult.isInvalid())
2364 return QualType();
2365
2366 Expr *Size = static_cast<Expr*>(SizeResult.get());
2367
2368 QualType Result = TL.getType();
2369 if (getDerived().AlwaysRebuild() ||
2370 ElementType != T->getElementType() ||
2371 Size != T->getSizeExpr()) {
2372 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2373 T->getSizeModifier(),
2374 move(SizeResult),
2375 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002376 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002377 if (Result.isNull())
2378 return QualType();
2379 }
2380 else SizeResult.take();
2381
2382 // We might have any sort of array type now, but fortunately they
2383 // all have the same location layout.
2384 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2385 NewTL.setLBracketLoc(TL.getLBracketLoc());
2386 NewTL.setRBracketLoc(TL.getRBracketLoc());
2387 NewTL.setSizeExpr(Size);
2388
2389 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002390}
Mike Stump1eb44332009-09-09 15:08:12 +00002391
2392template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002393QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002394 TypeLocBuilder &TLB,
2395 DependentSizedExtVectorTypeLoc TL) {
2396 DependentSizedExtVectorType *T = TL.getTypePtr();
2397
2398 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002399 QualType ElementType = getDerived().TransformType(T->getElementType());
2400 if (ElementType.isNull())
2401 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002402
Douglas Gregor670444e2009-08-04 22:27:00 +00002403 // Vector sizes are not potentially evaluated contexts
2404 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2405
Douglas Gregor577f75a2009-08-04 16:50:30 +00002406 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2407 if (Size.isInvalid())
2408 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002409
John McCalla2becad2009-10-21 00:40:46 +00002410 QualType Result = TL.getType();
2411 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002412 ElementType != T->getElementType() ||
2413 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002414 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002415 move(Size),
2416 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002417 if (Result.isNull())
2418 return QualType();
2419 }
2420 else Size.take();
2421
2422 // Result might be dependent or not.
2423 if (isa<DependentSizedExtVectorType>(Result)) {
2424 DependentSizedExtVectorTypeLoc NewTL
2425 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2426 NewTL.setNameLoc(TL.getNameLoc());
2427 } else {
2428 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2429 NewTL.setNameLoc(TL.getNameLoc());
2430 }
2431
2432 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002433}
Mike Stump1eb44332009-09-09 15:08:12 +00002434
2435template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002436QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
2437 VectorTypeLoc TL) {
2438 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002439 QualType ElementType = getDerived().TransformType(T->getElementType());
2440 if (ElementType.isNull())
2441 return QualType();
2442
John McCalla2becad2009-10-21 00:40:46 +00002443 QualType Result = TL.getType();
2444 if (getDerived().AlwaysRebuild() ||
2445 ElementType != T->getElementType()) {
2446 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements());
2447 if (Result.isNull())
2448 return QualType();
2449 }
2450
2451 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2452 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002453
John McCalla2becad2009-10-21 00:40:46 +00002454 return Result;
2455}
2456
2457template<typename Derived>
2458QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
2459 ExtVectorTypeLoc TL) {
2460 VectorType *T = TL.getTypePtr();
2461 QualType ElementType = getDerived().TransformType(T->getElementType());
2462 if (ElementType.isNull())
2463 return QualType();
2464
2465 QualType Result = TL.getType();
2466 if (getDerived().AlwaysRebuild() ||
2467 ElementType != T->getElementType()) {
2468 Result = getDerived().RebuildExtVectorType(ElementType,
2469 T->getNumElements(),
2470 /*FIXME*/ SourceLocation());
2471 if (Result.isNull())
2472 return QualType();
2473 }
2474
2475 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2476 NewTL.setNameLoc(TL.getNameLoc());
2477
2478 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002479}
Mike Stump1eb44332009-09-09 15:08:12 +00002480
2481template<typename Derived>
2482QualType
John McCalla2becad2009-10-21 00:40:46 +00002483TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
2484 FunctionProtoTypeLoc TL) {
2485 FunctionProtoType *T = TL.getTypePtr();
2486 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002487 if (ResultType.isNull())
2488 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002489
John McCalla2becad2009-10-21 00:40:46 +00002490 // Transform the parameters.
Douglas Gregor577f75a2009-08-04 16:50:30 +00002491 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002492 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2493 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2494 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump1eb44332009-09-09 15:08:12 +00002495
John McCalla2becad2009-10-21 00:40:46 +00002496 QualType NewType;
2497 ParmVarDecl *NewParm;
2498
2499 if (OldParm) {
John McCalla93c9342009-12-07 02:54:59 +00002500 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCalla2becad2009-10-21 00:40:46 +00002501 assert(OldDI->getType() == T->getArgType(i));
2502
John McCalla93c9342009-12-07 02:54:59 +00002503 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCalla2becad2009-10-21 00:40:46 +00002504 if (!NewDI)
2505 return QualType();
2506
2507 if (NewDI == OldDI)
2508 NewParm = OldParm;
2509 else
2510 NewParm = ParmVarDecl::Create(SemaRef.Context,
2511 OldParm->getDeclContext(),
2512 OldParm->getLocation(),
2513 OldParm->getIdentifier(),
2514 NewDI->getType(),
2515 NewDI,
2516 OldParm->getStorageClass(),
2517 /* DefArg */ NULL);
2518 NewType = NewParm->getType();
2519
2520 // Deal with the possibility that we don't have a parameter
2521 // declaration for this parameter.
2522 } else {
2523 NewParm = 0;
2524
2525 QualType OldType = T->getArgType(i);
2526 NewType = getDerived().TransformType(OldType);
2527 if (NewType.isNull())
2528 return QualType();
2529 }
2530
2531 ParamTypes.push_back(NewType);
2532 ParamDecls.push_back(NewParm);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002533 }
Mike Stump1eb44332009-09-09 15:08:12 +00002534
John McCalla2becad2009-10-21 00:40:46 +00002535 QualType Result = TL.getType();
2536 if (getDerived().AlwaysRebuild() ||
2537 ResultType != T->getResultType() ||
2538 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2539 Result = getDerived().RebuildFunctionProtoType(ResultType,
2540 ParamTypes.data(),
2541 ParamTypes.size(),
2542 T->isVariadic(),
2543 T->getTypeQuals());
2544 if (Result.isNull())
2545 return QualType();
2546 }
Mike Stump1eb44332009-09-09 15:08:12 +00002547
John McCalla2becad2009-10-21 00:40:46 +00002548 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2549 NewTL.setLParenLoc(TL.getLParenLoc());
2550 NewTL.setRParenLoc(TL.getRParenLoc());
2551 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2552 NewTL.setArg(i, ParamDecls[i]);
2553
2554 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002555}
Mike Stump1eb44332009-09-09 15:08:12 +00002556
Douglas Gregor577f75a2009-08-04 16:50:30 +00002557template<typename Derived>
2558QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002559 TypeLocBuilder &TLB,
2560 FunctionNoProtoTypeLoc TL) {
2561 FunctionNoProtoType *T = TL.getTypePtr();
2562 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2563 if (ResultType.isNull())
2564 return QualType();
2565
2566 QualType Result = TL.getType();
2567 if (getDerived().AlwaysRebuild() ||
2568 ResultType != T->getResultType())
2569 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2570
2571 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2572 NewTL.setLParenLoc(TL.getLParenLoc());
2573 NewTL.setRParenLoc(TL.getRParenLoc());
2574
2575 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002576}
Mike Stump1eb44332009-09-09 15:08:12 +00002577
John McCalled976492009-12-04 22:46:56 +00002578template<typename Derived> QualType
2579TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
2580 UnresolvedUsingTypeLoc TL) {
2581 UnresolvedUsingType *T = TL.getTypePtr();
2582 Decl *D = getDerived().TransformDecl(T->getDecl());
2583 if (!D)
2584 return QualType();
2585
2586 QualType Result = TL.getType();
2587 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2588 Result = getDerived().RebuildUnresolvedUsingType(D);
2589 if (Result.isNull())
2590 return QualType();
2591 }
2592
2593 // We might get an arbitrary type spec type back. We should at
2594 // least always get a type spec type, though.
2595 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2596 NewTL.setNameLoc(TL.getNameLoc());
2597
2598 return Result;
2599}
2600
Douglas Gregor577f75a2009-08-04 16:50:30 +00002601template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002602QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
2603 TypedefTypeLoc TL) {
2604 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002605 TypedefDecl *Typedef
2606 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2607 if (!Typedef)
2608 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002609
John McCalla2becad2009-10-21 00:40:46 +00002610 QualType Result = TL.getType();
2611 if (getDerived().AlwaysRebuild() ||
2612 Typedef != T->getDecl()) {
2613 Result = getDerived().RebuildTypedefType(Typedef);
2614 if (Result.isNull())
2615 return QualType();
2616 }
Mike Stump1eb44332009-09-09 15:08:12 +00002617
John McCalla2becad2009-10-21 00:40:46 +00002618 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2619 NewTL.setNameLoc(TL.getNameLoc());
2620
2621 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002622}
Mike Stump1eb44332009-09-09 15:08:12 +00002623
Douglas Gregor577f75a2009-08-04 16:50:30 +00002624template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002625QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
2626 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00002627 // typeof expressions are not potentially evaluated contexts
2628 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002629
John McCallcfb708c2010-01-13 20:03:27 +00002630 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002631 if (E.isInvalid())
2632 return QualType();
2633
John McCalla2becad2009-10-21 00:40:46 +00002634 QualType Result = TL.getType();
2635 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00002636 E.get() != TL.getUnderlyingExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002637 Result = getDerived().RebuildTypeOfExprType(move(E));
2638 if (Result.isNull())
2639 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002640 }
John McCalla2becad2009-10-21 00:40:46 +00002641 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002642
John McCalla2becad2009-10-21 00:40:46 +00002643 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002644 NewTL.setTypeofLoc(TL.getTypeofLoc());
2645 NewTL.setLParenLoc(TL.getLParenLoc());
2646 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00002647
2648 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002649}
Mike Stump1eb44332009-09-09 15:08:12 +00002650
2651template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002652QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
2653 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00002654 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2655 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2656 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00002657 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002658
John McCalla2becad2009-10-21 00:40:46 +00002659 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00002660 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2661 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00002662 if (Result.isNull())
2663 return QualType();
2664 }
Mike Stump1eb44332009-09-09 15:08:12 +00002665
John McCalla2becad2009-10-21 00:40:46 +00002666 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002667 NewTL.setTypeofLoc(TL.getTypeofLoc());
2668 NewTL.setLParenLoc(TL.getLParenLoc());
2669 NewTL.setRParenLoc(TL.getRParenLoc());
2670 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00002671
2672 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002673}
Mike Stump1eb44332009-09-09 15:08:12 +00002674
2675template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002676QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
2677 DecltypeTypeLoc TL) {
2678 DecltypeType *T = TL.getTypePtr();
2679
Douglas Gregor670444e2009-08-04 22:27:00 +00002680 // decltype expressions are not potentially evaluated contexts
2681 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002682
Douglas Gregor577f75a2009-08-04 16:50:30 +00002683 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2684 if (E.isInvalid())
2685 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002686
John McCalla2becad2009-10-21 00:40:46 +00002687 QualType Result = TL.getType();
2688 if (getDerived().AlwaysRebuild() ||
2689 E.get() != T->getUnderlyingExpr()) {
2690 Result = getDerived().RebuildDecltypeType(move(E));
2691 if (Result.isNull())
2692 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002693 }
John McCalla2becad2009-10-21 00:40:46 +00002694 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002695
John McCalla2becad2009-10-21 00:40:46 +00002696 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2697 NewTL.setNameLoc(TL.getNameLoc());
2698
2699 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002700}
2701
2702template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002703QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
2704 RecordTypeLoc TL) {
2705 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002706 RecordDecl *Record
John McCalla2becad2009-10-21 00:40:46 +00002707 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002708 if (!Record)
2709 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002710
John McCalla2becad2009-10-21 00:40:46 +00002711 QualType Result = TL.getType();
2712 if (getDerived().AlwaysRebuild() ||
2713 Record != T->getDecl()) {
2714 Result = getDerived().RebuildRecordType(Record);
2715 if (Result.isNull())
2716 return QualType();
2717 }
Mike Stump1eb44332009-09-09 15:08:12 +00002718
John McCalla2becad2009-10-21 00:40:46 +00002719 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2720 NewTL.setNameLoc(TL.getNameLoc());
2721
2722 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002723}
Mike Stump1eb44332009-09-09 15:08:12 +00002724
2725template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002726QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
2727 EnumTypeLoc TL) {
2728 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002729 EnumDecl *Enum
John McCalla2becad2009-10-21 00:40:46 +00002730 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002731 if (!Enum)
2732 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002733
John McCalla2becad2009-10-21 00:40:46 +00002734 QualType Result = TL.getType();
2735 if (getDerived().AlwaysRebuild() ||
2736 Enum != T->getDecl()) {
2737 Result = getDerived().RebuildEnumType(Enum);
2738 if (Result.isNull())
2739 return QualType();
2740 }
Mike Stump1eb44332009-09-09 15:08:12 +00002741
John McCalla2becad2009-10-21 00:40:46 +00002742 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2743 NewTL.setNameLoc(TL.getNameLoc());
2744
2745 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002746}
John McCall7da24312009-09-05 00:15:47 +00002747
2748template <typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002749QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
2750 ElaboratedTypeLoc TL) {
2751 ElaboratedType *T = TL.getTypePtr();
2752
2753 // FIXME: this should be a nested type.
John McCall7da24312009-09-05 00:15:47 +00002754 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2755 if (Underlying.isNull())
2756 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002757
John McCalla2becad2009-10-21 00:40:46 +00002758 QualType Result = TL.getType();
2759 if (getDerived().AlwaysRebuild() ||
2760 Underlying != T->getUnderlyingType()) {
2761 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2762 if (Result.isNull())
2763 return QualType();
2764 }
Mike Stump1eb44332009-09-09 15:08:12 +00002765
John McCalla2becad2009-10-21 00:40:46 +00002766 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2767 NewTL.setNameLoc(TL.getNameLoc());
2768
2769 return Result;
John McCall7da24312009-09-05 00:15:47 +00002770}
Mike Stump1eb44332009-09-09 15:08:12 +00002771
2772
Douglas Gregor577f75a2009-08-04 16:50:30 +00002773template<typename Derived>
2774QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00002775 TypeLocBuilder &TLB,
2776 TemplateTypeParmTypeLoc TL) {
2777 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002778}
2779
Mike Stump1eb44332009-09-09 15:08:12 +00002780template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00002781QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00002782 TypeLocBuilder &TLB,
2783 SubstTemplateTypeParmTypeLoc TL) {
2784 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00002785}
2786
2787template<typename Derived>
Douglas Gregordd62b152009-10-19 22:04:39 +00002788inline QualType
2789TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCalla2becad2009-10-21 00:40:46 +00002790 TypeLocBuilder &TLB,
2791 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00002792 return TransformTemplateSpecializationType(TLB, TL, QualType());
2793}
John McCalla2becad2009-10-21 00:40:46 +00002794
John McCall833ca992009-10-29 08:12:44 +00002795template<typename Derived>
2796QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2797 const TemplateSpecializationType *TST,
2798 QualType ObjectType) {
2799 // FIXME: this entire method is a temporary workaround; callers
2800 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00002801
John McCall833ca992009-10-29 08:12:44 +00002802 // Fake up a TemplateSpecializationTypeLoc.
2803 TypeLocBuilder TLB;
2804 TemplateSpecializationTypeLoc TL
2805 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2806
John McCall828bff22009-10-29 18:45:58 +00002807 SourceLocation BaseLoc = getDerived().getBaseLocation();
2808
2809 TL.setTemplateNameLoc(BaseLoc);
2810 TL.setLAngleLoc(BaseLoc);
2811 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00002812 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2813 const TemplateArgument &TA = TST->getArg(i);
2814 TemplateArgumentLoc TAL;
2815 getDerived().InventTemplateArgumentLoc(TA, TAL);
2816 TL.setArgLocInfo(i, TAL.getLocInfo());
2817 }
2818
2819 TypeLocBuilder IgnoredTLB;
2820 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00002821}
2822
2823template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002824QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00002825 TypeLocBuilder &TLB,
2826 TemplateSpecializationTypeLoc TL,
2827 QualType ObjectType) {
2828 const TemplateSpecializationType *T = TL.getTypePtr();
2829
Mike Stump1eb44332009-09-09 15:08:12 +00002830 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00002831 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002832 if (Template.isNull())
2833 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002834
John McCalld5532b62009-11-23 01:53:49 +00002835 TemplateArgumentListInfo NewTemplateArgs;
2836 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2837 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2838
2839 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2840 TemplateArgumentLoc Loc;
2841 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00002842 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00002843 NewTemplateArgs.addArgument(Loc);
2844 }
Mike Stump1eb44332009-09-09 15:08:12 +00002845
John McCall833ca992009-10-29 08:12:44 +00002846 // FIXME: maybe don't rebuild if all the template arguments are the same.
2847
2848 QualType Result =
2849 getDerived().RebuildTemplateSpecializationType(Template,
2850 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00002851 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00002852
2853 if (!Result.isNull()) {
2854 TemplateSpecializationTypeLoc NewTL
2855 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2856 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2857 NewTL.setLAngleLoc(TL.getLAngleLoc());
2858 NewTL.setRAngleLoc(TL.getRAngleLoc());
2859 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2860 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002861 }
Mike Stump1eb44332009-09-09 15:08:12 +00002862
John McCall833ca992009-10-29 08:12:44 +00002863 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002864}
Mike Stump1eb44332009-09-09 15:08:12 +00002865
2866template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002867QualType
2868TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
2869 QualifiedNameTypeLoc TL) {
2870 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002871 NestedNameSpecifier *NNS
2872 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2873 SourceRange());
2874 if (!NNS)
2875 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002876
Douglas Gregor577f75a2009-08-04 16:50:30 +00002877 QualType Named = getDerived().TransformType(T->getNamedType());
2878 if (Named.isNull())
2879 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002880
John McCalla2becad2009-10-21 00:40:46 +00002881 QualType Result = TL.getType();
2882 if (getDerived().AlwaysRebuild() ||
2883 NNS != T->getQualifier() ||
2884 Named != T->getNamedType()) {
2885 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2886 if (Result.isNull())
2887 return QualType();
2888 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002889
John McCalla2becad2009-10-21 00:40:46 +00002890 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2891 NewTL.setNameLoc(TL.getNameLoc());
2892
2893 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002894}
Mike Stump1eb44332009-09-09 15:08:12 +00002895
2896template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002897QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
2898 TypenameTypeLoc TL) {
2899 TypenameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00002900
2901 /* FIXME: preserve source information better than this */
2902 SourceRange SR(TL.getNameLoc());
2903
Douglas Gregor577f75a2009-08-04 16:50:30 +00002904 NestedNameSpecifier *NNS
John McCall833ca992009-10-29 08:12:44 +00002905 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002906 if (!NNS)
2907 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002908
John McCalla2becad2009-10-21 00:40:46 +00002909 QualType Result;
2910
Douglas Gregor577f75a2009-08-04 16:50:30 +00002911 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002912 QualType NewTemplateId
Douglas Gregor577f75a2009-08-04 16:50:30 +00002913 = getDerived().TransformType(QualType(TemplateId, 0));
2914 if (NewTemplateId.isNull())
2915 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002916
Douglas Gregor577f75a2009-08-04 16:50:30 +00002917 if (!getDerived().AlwaysRebuild() &&
2918 NNS == T->getQualifier() &&
2919 NewTemplateId == QualType(TemplateId, 0))
2920 return QualType(T, 0);
Mike Stump1eb44332009-09-09 15:08:12 +00002921
John McCalla2becad2009-10-21 00:40:46 +00002922 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2923 } else {
John McCall833ca992009-10-29 08:12:44 +00002924 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002925 }
John McCalla2becad2009-10-21 00:40:46 +00002926 if (Result.isNull())
2927 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002928
John McCalla2becad2009-10-21 00:40:46 +00002929 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2930 NewTL.setNameLoc(TL.getNameLoc());
2931
2932 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002933}
Mike Stump1eb44332009-09-09 15:08:12 +00002934
Douglas Gregor577f75a2009-08-04 16:50:30 +00002935template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002936QualType
2937TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
2938 ObjCInterfaceTypeLoc TL) {
John McCall54e14c42009-10-22 22:37:11 +00002939 assert(false && "TransformObjCInterfaceType unimplemented");
2940 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002941}
Mike Stump1eb44332009-09-09 15:08:12 +00002942
2943template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002944QualType
2945TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
2946 ObjCObjectPointerTypeLoc TL) {
John McCall54e14c42009-10-22 22:37:11 +00002947 assert(false && "TransformObjCObjectPointerType unimplemented");
2948 return QualType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00002949}
2950
Douglas Gregor577f75a2009-08-04 16:50:30 +00002951//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00002952// Statement transformation
2953//===----------------------------------------------------------------------===//
2954template<typename Derived>
2955Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00002956TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2957 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00002958}
2959
2960template<typename Derived>
2961Sema::OwningStmtResult
2962TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2963 return getDerived().TransformCompoundStmt(S, false);
2964}
2965
2966template<typename Derived>
2967Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00002968TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00002969 bool IsStmtExpr) {
2970 bool SubStmtChanged = false;
2971 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
2972 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
2973 B != BEnd; ++B) {
2974 OwningStmtResult Result = getDerived().TransformStmt(*B);
2975 if (Result.isInvalid())
2976 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002977
Douglas Gregor43959a92009-08-20 07:17:43 +00002978 SubStmtChanged = SubStmtChanged || Result.get() != *B;
2979 Statements.push_back(Result.takeAs<Stmt>());
2980 }
Mike Stump1eb44332009-09-09 15:08:12 +00002981
Douglas Gregor43959a92009-08-20 07:17:43 +00002982 if (!getDerived().AlwaysRebuild() &&
2983 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00002984 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00002985
2986 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
2987 move_arg(Statements),
2988 S->getRBracLoc(),
2989 IsStmtExpr);
2990}
Mike Stump1eb44332009-09-09 15:08:12 +00002991
Douglas Gregor43959a92009-08-20 07:17:43 +00002992template<typename Derived>
2993Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00002994TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman264c1f82009-11-19 03:14:00 +00002995 OwningExprResult LHS(SemaRef), RHS(SemaRef);
2996 {
2997 // The case value expressions are not potentially evaluated.
2998 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002999
Eli Friedman264c1f82009-11-19 03:14:00 +00003000 // Transform the left-hand case value.
3001 LHS = getDerived().TransformExpr(S->getLHS());
3002 if (LHS.isInvalid())
3003 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003004
Eli Friedman264c1f82009-11-19 03:14:00 +00003005 // Transform the right-hand case value (for the GNU case-range extension).
3006 RHS = getDerived().TransformExpr(S->getRHS());
3007 if (RHS.isInvalid())
3008 return SemaRef.StmtError();
3009 }
Mike Stump1eb44332009-09-09 15:08:12 +00003010
Douglas Gregor43959a92009-08-20 07:17:43 +00003011 // Build the case statement.
3012 // Case statements are always rebuilt so that they will attached to their
3013 // transformed switch statement.
3014 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3015 move(LHS),
3016 S->getEllipsisLoc(),
3017 move(RHS),
3018 S->getColonLoc());
3019 if (Case.isInvalid())
3020 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003021
Douglas Gregor43959a92009-08-20 07:17:43 +00003022 // Transform the statement following the case
3023 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3024 if (SubStmt.isInvalid())
3025 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003026
Douglas Gregor43959a92009-08-20 07:17:43 +00003027 // Attach the body to the case statement
3028 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3029}
3030
3031template<typename Derived>
3032Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003033TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003034 // Transform the statement following the default case
3035 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3036 if (SubStmt.isInvalid())
3037 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003038
Douglas Gregor43959a92009-08-20 07:17:43 +00003039 // Default statements are always rebuilt
3040 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3041 move(SubStmt));
3042}
Mike Stump1eb44332009-09-09 15:08:12 +00003043
Douglas Gregor43959a92009-08-20 07:17:43 +00003044template<typename Derived>
3045Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003046TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003047 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3048 if (SubStmt.isInvalid())
3049 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003050
Douglas Gregor43959a92009-08-20 07:17:43 +00003051 // FIXME: Pass the real colon location in.
3052 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3053 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3054 move(SubStmt));
3055}
Mike Stump1eb44332009-09-09 15:08:12 +00003056
Douglas Gregor43959a92009-08-20 07:17:43 +00003057template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003058Sema::OwningStmtResult
3059TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003060 // Transform the condition
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003061 OwningExprResult Cond(SemaRef);
3062 VarDecl *ConditionVar = 0;
3063 if (S->getConditionVariable()) {
3064 ConditionVar
3065 = cast_or_null<VarDecl>(
3066 getDerived().TransformDefinition(S->getConditionVariable()));
3067 if (!ConditionVar)
3068 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003069 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003070 Cond = getDerived().TransformExpr(S->getCond());
3071
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003072 if (Cond.isInvalid())
3073 return SemaRef.StmtError();
3074 }
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003075
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003076 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump1eb44332009-09-09 15:08:12 +00003077
Douglas Gregor43959a92009-08-20 07:17:43 +00003078 // Transform the "then" branch.
3079 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3080 if (Then.isInvalid())
3081 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003082
Douglas Gregor43959a92009-08-20 07:17:43 +00003083 // Transform the "else" branch.
3084 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3085 if (Else.isInvalid())
3086 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003087
Douglas Gregor43959a92009-08-20 07:17:43 +00003088 if (!getDerived().AlwaysRebuild() &&
3089 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003090 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003091 Then.get() == S->getThen() &&
3092 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003093 return SemaRef.Owned(S->Retain());
3094
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003095 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3096 move(Then),
Mike Stump1eb44332009-09-09 15:08:12 +00003097 S->getElseLoc(), move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +00003098}
3099
3100template<typename Derived>
3101Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003102TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003103 // Transform the condition.
Douglas Gregord3d53012009-11-24 17:07:59 +00003104 OwningExprResult Cond(SemaRef);
3105 VarDecl *ConditionVar = 0;
3106 if (S->getConditionVariable()) {
3107 ConditionVar
3108 = cast_or_null<VarDecl>(
3109 getDerived().TransformDefinition(S->getConditionVariable()));
3110 if (!ConditionVar)
3111 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003112 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003113 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003114
3115 if (Cond.isInvalid())
3116 return SemaRef.StmtError();
3117 }
Mike Stump1eb44332009-09-09 15:08:12 +00003118
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003119 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003120
Douglas Gregor43959a92009-08-20 07:17:43 +00003121 // Rebuild the switch statement.
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003122 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3123 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003124 if (Switch.isInvalid())
3125 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003126
Douglas Gregor43959a92009-08-20 07:17:43 +00003127 // Transform the body of the switch statement.
3128 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3129 if (Body.isInvalid())
3130 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003131
Douglas Gregor43959a92009-08-20 07:17:43 +00003132 // Complete the switch statement.
3133 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3134 move(Body));
3135}
Mike Stump1eb44332009-09-09 15:08:12 +00003136
Douglas Gregor43959a92009-08-20 07:17:43 +00003137template<typename Derived>
3138Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003139TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003140 // Transform the condition
Douglas Gregor5656e142009-11-24 21:15:44 +00003141 OwningExprResult Cond(SemaRef);
3142 VarDecl *ConditionVar = 0;
3143 if (S->getConditionVariable()) {
3144 ConditionVar
3145 = cast_or_null<VarDecl>(
3146 getDerived().TransformDefinition(S->getConditionVariable()));
3147 if (!ConditionVar)
3148 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003149 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003150 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003151
3152 if (Cond.isInvalid())
3153 return SemaRef.StmtError();
3154 }
Mike Stump1eb44332009-09-09 15:08:12 +00003155
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003156 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump1eb44332009-09-09 15:08:12 +00003157
Douglas Gregor43959a92009-08-20 07:17:43 +00003158 // Transform the body
3159 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3160 if (Body.isInvalid())
3161 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003162
Douglas Gregor43959a92009-08-20 07:17:43 +00003163 if (!getDerived().AlwaysRebuild() &&
3164 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003165 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003166 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003167 return SemaRef.Owned(S->Retain());
3168
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003169 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3170 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003171}
Mike Stump1eb44332009-09-09 15:08:12 +00003172
Douglas Gregor43959a92009-08-20 07:17:43 +00003173template<typename Derived>
3174Sema::OwningStmtResult
3175TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3176 // Transform the condition
3177 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3178 if (Cond.isInvalid())
3179 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003180
Douglas Gregor43959a92009-08-20 07:17:43 +00003181 // Transform the body
3182 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3183 if (Body.isInvalid())
3184 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003185
Douglas Gregor43959a92009-08-20 07:17:43 +00003186 if (!getDerived().AlwaysRebuild() &&
3187 Cond.get() == S->getCond() &&
3188 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003189 return SemaRef.Owned(S->Retain());
3190
Douglas Gregor43959a92009-08-20 07:17:43 +00003191 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3192 /*FIXME:*/S->getWhileLoc(), move(Cond),
3193 S->getRParenLoc());
3194}
Mike Stump1eb44332009-09-09 15:08:12 +00003195
Douglas Gregor43959a92009-08-20 07:17:43 +00003196template<typename Derived>
3197Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003198TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003199 // Transform the initialization statement
3200 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3201 if (Init.isInvalid())
3202 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003203
Douglas Gregor43959a92009-08-20 07:17:43 +00003204 // Transform the condition
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003205 OwningExprResult Cond(SemaRef);
3206 VarDecl *ConditionVar = 0;
3207 if (S->getConditionVariable()) {
3208 ConditionVar
3209 = cast_or_null<VarDecl>(
3210 getDerived().TransformDefinition(S->getConditionVariable()));
3211 if (!ConditionVar)
3212 return SemaRef.StmtError();
3213 } else {
3214 Cond = getDerived().TransformExpr(S->getCond());
3215
3216 if (Cond.isInvalid())
3217 return SemaRef.StmtError();
3218 }
Mike Stump1eb44332009-09-09 15:08:12 +00003219
Douglas Gregor43959a92009-08-20 07:17:43 +00003220 // Transform the increment
3221 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3222 if (Inc.isInvalid())
3223 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003224
Douglas Gregor43959a92009-08-20 07:17:43 +00003225 // Transform the body
3226 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3227 if (Body.isInvalid())
3228 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003229
Douglas Gregor43959a92009-08-20 07:17:43 +00003230 if (!getDerived().AlwaysRebuild() &&
3231 Init.get() == S->getInit() &&
3232 Cond.get() == S->getCond() &&
3233 Inc.get() == S->getInc() &&
3234 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003235 return SemaRef.Owned(S->Retain());
3236
Douglas Gregor43959a92009-08-20 07:17:43 +00003237 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003238 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003239 ConditionVar,
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003240 getSema().MakeFullExpr(Inc),
Douglas Gregor43959a92009-08-20 07:17:43 +00003241 S->getRParenLoc(), move(Body));
3242}
3243
3244template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003245Sema::OwningStmtResult
3246TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003247 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003248 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003249 S->getLabel());
3250}
3251
3252template<typename Derived>
3253Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003254TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003255 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3256 if (Target.isInvalid())
3257 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003258
Douglas Gregor43959a92009-08-20 07:17:43 +00003259 if (!getDerived().AlwaysRebuild() &&
3260 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003261 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003262
3263 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3264 move(Target));
3265}
3266
3267template<typename Derived>
3268Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003269TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3270 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003271}
Mike Stump1eb44332009-09-09 15:08:12 +00003272
Douglas Gregor43959a92009-08-20 07:17:43 +00003273template<typename Derived>
3274Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003275TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3276 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003277}
Mike Stump1eb44332009-09-09 15:08:12 +00003278
Douglas Gregor43959a92009-08-20 07:17:43 +00003279template<typename Derived>
3280Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003281TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003282 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3283 if (Result.isInvalid())
3284 return SemaRef.StmtError();
3285
Mike Stump1eb44332009-09-09 15:08:12 +00003286 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003287 // to tell whether the return type of the function has changed.
3288 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3289}
Mike Stump1eb44332009-09-09 15:08:12 +00003290
Douglas Gregor43959a92009-08-20 07:17:43 +00003291template<typename Derived>
3292Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003293TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003294 bool DeclChanged = false;
3295 llvm::SmallVector<Decl *, 4> Decls;
3296 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3297 D != DEnd; ++D) {
3298 Decl *Transformed = getDerived().TransformDefinition(*D);
3299 if (!Transformed)
3300 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003301
Douglas Gregor43959a92009-08-20 07:17:43 +00003302 if (Transformed != *D)
3303 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003304
Douglas Gregor43959a92009-08-20 07:17:43 +00003305 Decls.push_back(Transformed);
3306 }
Mike Stump1eb44332009-09-09 15:08:12 +00003307
Douglas Gregor43959a92009-08-20 07:17:43 +00003308 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003309 return SemaRef.Owned(S->Retain());
3310
3311 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003312 S->getStartLoc(), S->getEndLoc());
3313}
Mike Stump1eb44332009-09-09 15:08:12 +00003314
Douglas Gregor43959a92009-08-20 07:17:43 +00003315template<typename Derived>
3316Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003317TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003318 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003319 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003320}
3321
3322template<typename Derived>
3323Sema::OwningStmtResult
3324TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
3325 // FIXME: Implement!
3326 assert(false && "Inline assembly cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003327 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003328}
3329
3330
3331template<typename Derived>
3332Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003333TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003334 // FIXME: Implement this
3335 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003336 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003337}
Mike Stump1eb44332009-09-09 15:08:12 +00003338
Douglas Gregor43959a92009-08-20 07:17:43 +00003339template<typename Derived>
3340Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003341TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003342 // FIXME: Implement this
3343 assert(false && "Cannot transform an Objective-C @catch statement");
3344 return SemaRef.Owned(S->Retain());
3345}
Mike Stump1eb44332009-09-09 15:08:12 +00003346
Douglas Gregor43959a92009-08-20 07:17:43 +00003347template<typename Derived>
3348Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003349TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003350 // FIXME: Implement this
3351 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003352 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003353}
Mike Stump1eb44332009-09-09 15:08:12 +00003354
Douglas Gregor43959a92009-08-20 07:17:43 +00003355template<typename Derived>
3356Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003357TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003358 // FIXME: Implement this
3359 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003360 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003361}
Mike Stump1eb44332009-09-09 15:08:12 +00003362
Douglas Gregor43959a92009-08-20 07:17:43 +00003363template<typename Derived>
3364Sema::OwningStmtResult
3365TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003366 ObjCAtSynchronizedStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003367 // FIXME: Implement this
3368 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003369 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003370}
3371
3372template<typename Derived>
3373Sema::OwningStmtResult
3374TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003375 ObjCForCollectionStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003376 // FIXME: Implement this
3377 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003378 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003379}
3380
3381
3382template<typename Derived>
3383Sema::OwningStmtResult
3384TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3385 // Transform the exception declaration, if any.
3386 VarDecl *Var = 0;
3387 if (S->getExceptionDecl()) {
3388 VarDecl *ExceptionDecl = S->getExceptionDecl();
3389 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3390 ExceptionDecl->getDeclName());
3391
3392 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3393 if (T.isNull())
3394 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003395
Douglas Gregor43959a92009-08-20 07:17:43 +00003396 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3397 T,
John McCalla93c9342009-12-07 02:54:59 +00003398 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003399 ExceptionDecl->getIdentifier(),
3400 ExceptionDecl->getLocation(),
3401 /*FIXME: Inaccurate*/
3402 SourceRange(ExceptionDecl->getLocation()));
3403 if (!Var || Var->isInvalidDecl()) {
3404 if (Var)
3405 Var->Destroy(SemaRef.Context);
3406 return SemaRef.StmtError();
3407 }
3408 }
Mike Stump1eb44332009-09-09 15:08:12 +00003409
Douglas Gregor43959a92009-08-20 07:17:43 +00003410 // Transform the actual exception handler.
3411 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3412 if (Handler.isInvalid()) {
3413 if (Var)
3414 Var->Destroy(SemaRef.Context);
3415 return SemaRef.StmtError();
3416 }
Mike Stump1eb44332009-09-09 15:08:12 +00003417
Douglas Gregor43959a92009-08-20 07:17:43 +00003418 if (!getDerived().AlwaysRebuild() &&
3419 !Var &&
3420 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00003421 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003422
3423 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3424 Var,
3425 move(Handler));
3426}
Mike Stump1eb44332009-09-09 15:08:12 +00003427
Douglas Gregor43959a92009-08-20 07:17:43 +00003428template<typename Derived>
3429Sema::OwningStmtResult
3430TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3431 // Transform the try block itself.
Mike Stump1eb44332009-09-09 15:08:12 +00003432 OwningStmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00003433 = getDerived().TransformCompoundStmt(S->getTryBlock());
3434 if (TryBlock.isInvalid())
3435 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003436
Douglas Gregor43959a92009-08-20 07:17:43 +00003437 // Transform the handlers.
3438 bool HandlerChanged = false;
3439 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3440 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump1eb44332009-09-09 15:08:12 +00003441 OwningStmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00003442 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3443 if (Handler.isInvalid())
3444 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003445
Douglas Gregor43959a92009-08-20 07:17:43 +00003446 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3447 Handlers.push_back(Handler.takeAs<Stmt>());
3448 }
Mike Stump1eb44332009-09-09 15:08:12 +00003449
Douglas Gregor43959a92009-08-20 07:17:43 +00003450 if (!getDerived().AlwaysRebuild() &&
3451 TryBlock.get() == S->getTryBlock() &&
3452 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003453 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003454
3455 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump1eb44332009-09-09 15:08:12 +00003456 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00003457}
Mike Stump1eb44332009-09-09 15:08:12 +00003458
Douglas Gregor43959a92009-08-20 07:17:43 +00003459//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00003460// Expression transformation
3461//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00003462template<typename Derived>
3463Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003464TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003465 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003466}
Mike Stump1eb44332009-09-09 15:08:12 +00003467
3468template<typename Derived>
3469Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003470TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00003471 NestedNameSpecifier *Qualifier = 0;
3472 if (E->getQualifier()) {
3473 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3474 E->getQualifierRange());
3475 if (!Qualifier)
3476 return SemaRef.ExprError();
3477 }
John McCalldbd872f2009-12-08 09:08:17 +00003478
3479 ValueDecl *ND
3480 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00003481 if (!ND)
3482 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003483
Douglas Gregora2813ce2009-10-23 18:54:35 +00003484 if (!getDerived().AlwaysRebuild() &&
3485 Qualifier == E->getQualifier() &&
3486 ND == E->getDecl() &&
John McCalldbd872f2009-12-08 09:08:17 +00003487 !E->hasExplicitTemplateArgumentList()) {
3488
3489 // Mark it referenced in the new context regardless.
3490 // FIXME: this is a bit instantiation-specific.
3491 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3492
Mike Stump1eb44332009-09-09 15:08:12 +00003493 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00003494 }
John McCalldbd872f2009-12-08 09:08:17 +00003495
3496 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3497 if (E->hasExplicitTemplateArgumentList()) {
3498 TemplateArgs = &TransArgs;
3499 TransArgs.setLAngleLoc(E->getLAngleLoc());
3500 TransArgs.setRAngleLoc(E->getRAngleLoc());
3501 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3502 TemplateArgumentLoc Loc;
3503 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3504 return SemaRef.ExprError();
3505 TransArgs.addArgument(Loc);
3506 }
3507 }
3508
Douglas Gregora2813ce2009-10-23 18:54:35 +00003509 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCalldbd872f2009-12-08 09:08:17 +00003510 ND, E->getLocation(), TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003511}
Mike Stump1eb44332009-09-09 15:08:12 +00003512
Douglas Gregorb98b1992009-08-11 05:31:07 +00003513template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003514Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003515TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003516 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003517}
Mike Stump1eb44332009-09-09 15:08:12 +00003518
Douglas Gregorb98b1992009-08-11 05:31:07 +00003519template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003520Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003521TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003522 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003523}
Mike Stump1eb44332009-09-09 15:08:12 +00003524
Douglas Gregorb98b1992009-08-11 05:31:07 +00003525template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003526Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003527TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003528 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003529}
Mike Stump1eb44332009-09-09 15:08:12 +00003530
Douglas Gregorb98b1992009-08-11 05:31:07 +00003531template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003532Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003533TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003534 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003535}
Mike Stump1eb44332009-09-09 15:08:12 +00003536
Douglas Gregorb98b1992009-08-11 05:31:07 +00003537template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003538Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003539TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003540 return SemaRef.Owned(E->Retain());
3541}
3542
3543template<typename Derived>
3544Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003545TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003546 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3547 if (SubExpr.isInvalid())
3548 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003549
Douglas Gregorb98b1992009-08-11 05:31:07 +00003550 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003551 return SemaRef.Owned(E->Retain());
3552
3553 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003554 E->getRParen());
3555}
3556
Mike Stump1eb44332009-09-09 15:08:12 +00003557template<typename Derived>
3558Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003559TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3560 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003561 if (SubExpr.isInvalid())
3562 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003563
Douglas Gregorb98b1992009-08-11 05:31:07 +00003564 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003565 return SemaRef.Owned(E->Retain());
3566
Douglas Gregorb98b1992009-08-11 05:31:07 +00003567 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3568 E->getOpcode(),
3569 move(SubExpr));
3570}
Mike Stump1eb44332009-09-09 15:08:12 +00003571
Douglas Gregorb98b1992009-08-11 05:31:07 +00003572template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003573Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003574TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003575 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00003576 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00003577
John McCalla93c9342009-12-07 02:54:59 +00003578 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00003579 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003580 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003581
John McCall5ab75172009-11-04 07:28:41 +00003582 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003583 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003584
John McCall5ab75172009-11-04 07:28:41 +00003585 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00003586 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003587 E->getSourceRange());
3588 }
Mike Stump1eb44332009-09-09 15:08:12 +00003589
Douglas Gregorb98b1992009-08-11 05:31:07 +00003590 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00003591 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003592 // C++0x [expr.sizeof]p1:
3593 // The operand is either an expression, which is an unevaluated operand
3594 // [...]
3595 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003596
Douglas Gregorb98b1992009-08-11 05:31:07 +00003597 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3598 if (SubExpr.isInvalid())
3599 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003600
Douglas Gregorb98b1992009-08-11 05:31:07 +00003601 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3602 return SemaRef.Owned(E->Retain());
3603 }
Mike Stump1eb44332009-09-09 15:08:12 +00003604
Douglas Gregorb98b1992009-08-11 05:31:07 +00003605 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3606 E->isSizeOf(),
3607 E->getSourceRange());
3608}
Mike Stump1eb44332009-09-09 15:08:12 +00003609
Douglas Gregorb98b1992009-08-11 05:31:07 +00003610template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003611Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003612TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003613 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3614 if (LHS.isInvalid())
3615 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003616
Douglas Gregorb98b1992009-08-11 05:31:07 +00003617 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3618 if (RHS.isInvalid())
3619 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003620
3621
Douglas Gregorb98b1992009-08-11 05:31:07 +00003622 if (!getDerived().AlwaysRebuild() &&
3623 LHS.get() == E->getLHS() &&
3624 RHS.get() == E->getRHS())
3625 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003626
Douglas Gregorb98b1992009-08-11 05:31:07 +00003627 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3628 /*FIXME:*/E->getLHS()->getLocStart(),
3629 move(RHS),
3630 E->getRBracketLoc());
3631}
Mike Stump1eb44332009-09-09 15:08:12 +00003632
3633template<typename Derived>
3634Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003635TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003636 // Transform the callee.
3637 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3638 if (Callee.isInvalid())
3639 return SemaRef.ExprError();
3640
3641 // Transform arguments.
3642 bool ArgChanged = false;
3643 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3644 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3645 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3646 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3647 if (Arg.isInvalid())
3648 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003649
Douglas Gregorb98b1992009-08-11 05:31:07 +00003650 // FIXME: Wrong source location information for the ','.
3651 FakeCommaLocs.push_back(
3652 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00003653
3654 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003655 Args.push_back(Arg.takeAs<Expr>());
3656 }
Mike Stump1eb44332009-09-09 15:08:12 +00003657
Douglas Gregorb98b1992009-08-11 05:31:07 +00003658 if (!getDerived().AlwaysRebuild() &&
3659 Callee.get() == E->getCallee() &&
3660 !ArgChanged)
3661 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003662
Douglas Gregorb98b1992009-08-11 05:31:07 +00003663 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00003664 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003665 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3666 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3667 move_arg(Args),
3668 FakeCommaLocs.data(),
3669 E->getRParenLoc());
3670}
Mike Stump1eb44332009-09-09 15:08:12 +00003671
3672template<typename Derived>
3673Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003674TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003675 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3676 if (Base.isInvalid())
3677 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003678
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003679 NestedNameSpecifier *Qualifier = 0;
3680 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00003681 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003682 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3683 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00003684 if (Qualifier == 0)
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003685 return SemaRef.ExprError();
3686 }
Mike Stump1eb44332009-09-09 15:08:12 +00003687
Eli Friedmanf595cc42009-12-04 06:40:45 +00003688 ValueDecl *Member
3689 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00003690 if (!Member)
3691 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003692
Douglas Gregorb98b1992009-08-11 05:31:07 +00003693 if (!getDerived().AlwaysRebuild() &&
3694 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003695 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003696 Member == E->getMemberDecl() &&
Anders Carlsson1f240322009-12-22 05:24:09 +00003697 !E->hasExplicitTemplateArgumentList()) {
3698
3699 // Mark it referenced in the new context regardless.
3700 // FIXME: this is a bit instantiation-specific.
3701 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00003702 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00003703 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00003704
John McCalld5532b62009-11-23 01:53:49 +00003705 TemplateArgumentListInfo TransArgs;
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003706 if (E->hasExplicitTemplateArgumentList()) {
John McCalld5532b62009-11-23 01:53:49 +00003707 TransArgs.setLAngleLoc(E->getLAngleLoc());
3708 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003709 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00003710 TemplateArgumentLoc Loc;
3711 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003712 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00003713 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003714 }
3715 }
3716
Douglas Gregorb98b1992009-08-11 05:31:07 +00003717 // FIXME: Bogus source location for the operator
3718 SourceLocation FakeOperatorLoc
3719 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3720
John McCallc2233c52010-01-15 08:34:02 +00003721 // FIXME: to do this check properly, we will need to preserve the
3722 // first-qualifier-in-scope here, just in case we had a dependent
3723 // base (and therefore couldn't do the check) and a
3724 // nested-name-qualifier (and therefore could do the lookup).
3725 NamedDecl *FirstQualifierInScope = 0;
3726
Douglas Gregorb98b1992009-08-11 05:31:07 +00003727 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3728 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003729 Qualifier,
3730 E->getQualifierRange(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003731 E->getMemberLoc(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003732 Member,
John McCalld5532b62009-11-23 01:53:49 +00003733 (E->hasExplicitTemplateArgumentList()
3734 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00003735 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003736}
Mike Stump1eb44332009-09-09 15:08:12 +00003737
Douglas Gregorb98b1992009-08-11 05:31:07 +00003738template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00003739Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003740TreeTransform<Derived>::TransformCastExpr(CastExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003741 assert(false && "Cannot transform abstract class");
3742 return SemaRef.Owned(E->Retain());
3743}
3744
3745template<typename Derived>
3746Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003747TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003748 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3749 if (LHS.isInvalid())
3750 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003751
Douglas Gregorb98b1992009-08-11 05:31:07 +00003752 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3753 if (RHS.isInvalid())
3754 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003755
Douglas Gregorb98b1992009-08-11 05:31:07 +00003756 if (!getDerived().AlwaysRebuild() &&
3757 LHS.get() == E->getLHS() &&
3758 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00003759 return SemaRef.Owned(E->Retain());
3760
Douglas Gregorb98b1992009-08-11 05:31:07 +00003761 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3762 move(LHS), move(RHS));
3763}
3764
Mike Stump1eb44332009-09-09 15:08:12 +00003765template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00003766Sema::OwningExprResult
3767TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00003768 CompoundAssignOperator *E) {
3769 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003770}
Mike Stump1eb44332009-09-09 15:08:12 +00003771
Douglas Gregorb98b1992009-08-11 05:31:07 +00003772template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003773Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003774TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003775 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3776 if (Cond.isInvalid())
3777 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003778
Douglas Gregorb98b1992009-08-11 05:31:07 +00003779 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3780 if (LHS.isInvalid())
3781 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003782
Douglas Gregorb98b1992009-08-11 05:31:07 +00003783 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3784 if (RHS.isInvalid())
3785 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003786
Douglas Gregorb98b1992009-08-11 05:31:07 +00003787 if (!getDerived().AlwaysRebuild() &&
3788 Cond.get() == E->getCond() &&
3789 LHS.get() == E->getLHS() &&
3790 RHS.get() == E->getRHS())
3791 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003792
3793 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00003794 E->getQuestionLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00003795 move(LHS),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00003796 E->getColonLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003797 move(RHS));
3798}
Mike Stump1eb44332009-09-09 15:08:12 +00003799
3800template<typename Derived>
3801Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003802TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00003803 // Implicit casts are eliminated during transformation, since they
3804 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00003805 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003806}
Mike Stump1eb44332009-09-09 15:08:12 +00003807
Douglas Gregorb98b1992009-08-11 05:31:07 +00003808template<typename Derived>
3809Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003810TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003811 assert(false && "Cannot transform abstract class");
3812 return SemaRef.Owned(E->Retain());
3813}
3814
3815template<typename Derived>
3816Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003817TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003818 QualType T;
3819 {
3820 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00003821 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003822 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3823 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00003824
Douglas Gregorb98b1992009-08-11 05:31:07 +00003825 T = getDerived().TransformType(E->getTypeAsWritten());
3826 if (T.isNull())
3827 return SemaRef.ExprError();
3828 }
Mike Stump1eb44332009-09-09 15:08:12 +00003829
Douglas Gregora88cfbf2009-12-12 18:16:41 +00003830 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00003831 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003832 if (SubExpr.isInvalid())
3833 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003834
Douglas Gregorb98b1992009-08-11 05:31:07 +00003835 if (!getDerived().AlwaysRebuild() &&
3836 T == E->getTypeAsWritten() &&
3837 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003838 return SemaRef.Owned(E->Retain());
3839
Douglas Gregorb98b1992009-08-11 05:31:07 +00003840 return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T,
3841 E->getRParenLoc(),
3842 move(SubExpr));
3843}
Mike Stump1eb44332009-09-09 15:08:12 +00003844
Douglas Gregorb98b1992009-08-11 05:31:07 +00003845template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003846Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003847TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003848 QualType T;
3849 {
3850 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00003851 SourceLocation FakeTypeLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003852 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3853 TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00003854
Douglas Gregorb98b1992009-08-11 05:31:07 +00003855 T = getDerived().TransformType(E->getType());
3856 if (T.isNull())
3857 return SemaRef.ExprError();
3858 }
Mike Stump1eb44332009-09-09 15:08:12 +00003859
Douglas Gregorb98b1992009-08-11 05:31:07 +00003860 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3861 if (Init.isInvalid())
3862 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003863
Douglas Gregorb98b1992009-08-11 05:31:07 +00003864 if (!getDerived().AlwaysRebuild() &&
3865 T == E->getType() &&
3866 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00003867 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003868
3869 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T,
3870 /*FIXME:*/E->getInitializer()->getLocEnd(),
3871 move(Init));
3872}
Mike Stump1eb44332009-09-09 15:08:12 +00003873
Douglas Gregorb98b1992009-08-11 05:31:07 +00003874template<typename Derived>
3875Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003876TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003877 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3878 if (Base.isInvalid())
3879 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003880
Douglas Gregorb98b1992009-08-11 05:31:07 +00003881 if (!getDerived().AlwaysRebuild() &&
3882 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00003883 return SemaRef.Owned(E->Retain());
3884
Douglas Gregorb98b1992009-08-11 05:31:07 +00003885 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00003886 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003887 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3888 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3889 E->getAccessorLoc(),
3890 E->getAccessor());
3891}
Mike Stump1eb44332009-09-09 15:08:12 +00003892
Douglas Gregorb98b1992009-08-11 05:31:07 +00003893template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003894Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003895TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003896 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00003897
Douglas Gregorb98b1992009-08-11 05:31:07 +00003898 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3899 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3900 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3901 if (Init.isInvalid())
3902 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003903
Douglas Gregorb98b1992009-08-11 05:31:07 +00003904 InitChanged = InitChanged || Init.get() != E->getInit(I);
3905 Inits.push_back(Init.takeAs<Expr>());
3906 }
Mike Stump1eb44332009-09-09 15:08:12 +00003907
Douglas Gregorb98b1992009-08-11 05:31:07 +00003908 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003909 return SemaRef.Owned(E->Retain());
3910
Douglas Gregorb98b1992009-08-11 05:31:07 +00003911 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00003912 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003913}
Mike Stump1eb44332009-09-09 15:08:12 +00003914
Douglas Gregorb98b1992009-08-11 05:31:07 +00003915template<typename Derived>
3916Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003917TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003918 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00003919
Douglas Gregor43959a92009-08-20 07:17:43 +00003920 // transform the initializer value
Douglas Gregorb98b1992009-08-11 05:31:07 +00003921 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3922 if (Init.isInvalid())
3923 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003924
Douglas Gregor43959a92009-08-20 07:17:43 +00003925 // transform the designators.
Douglas Gregorb98b1992009-08-11 05:31:07 +00003926 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3927 bool ExprChanged = false;
3928 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3929 DEnd = E->designators_end();
3930 D != DEnd; ++D) {
3931 if (D->isFieldDesignator()) {
3932 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3933 D->getDotLoc(),
3934 D->getFieldLoc()));
3935 continue;
3936 }
Mike Stump1eb44332009-09-09 15:08:12 +00003937
Douglas Gregorb98b1992009-08-11 05:31:07 +00003938 if (D->isArrayDesignator()) {
3939 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3940 if (Index.isInvalid())
3941 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003942
3943 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003944 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00003945
Douglas Gregorb98b1992009-08-11 05:31:07 +00003946 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3947 ArrayExprs.push_back(Index.release());
3948 continue;
3949 }
Mike Stump1eb44332009-09-09 15:08:12 +00003950
Douglas Gregorb98b1992009-08-11 05:31:07 +00003951 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump1eb44332009-09-09 15:08:12 +00003952 OwningExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00003953 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3954 if (Start.isInvalid())
3955 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003956
Douglas Gregorb98b1992009-08-11 05:31:07 +00003957 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3958 if (End.isInvalid())
3959 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003960
3961 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003962 End.get(),
3963 D->getLBracketLoc(),
3964 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00003965
Douglas Gregorb98b1992009-08-11 05:31:07 +00003966 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
3967 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00003968
Douglas Gregorb98b1992009-08-11 05:31:07 +00003969 ArrayExprs.push_back(Start.release());
3970 ArrayExprs.push_back(End.release());
3971 }
Mike Stump1eb44332009-09-09 15:08:12 +00003972
Douglas Gregorb98b1992009-08-11 05:31:07 +00003973 if (!getDerived().AlwaysRebuild() &&
3974 Init.get() == E->getInit() &&
3975 !ExprChanged)
3976 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003977
Douglas Gregorb98b1992009-08-11 05:31:07 +00003978 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
3979 E->getEqualOrColonLoc(),
3980 E->usesGNUSyntax(), move(Init));
3981}
Mike Stump1eb44332009-09-09 15:08:12 +00003982
Douglas Gregorb98b1992009-08-11 05:31:07 +00003983template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003984Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00003985TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00003986 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00003987 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3988
3989 // FIXME: Will we ever have proper type location here? Will we actually
3990 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00003991 QualType T = getDerived().TransformType(E->getType());
3992 if (T.isNull())
3993 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003994
Douglas Gregorb98b1992009-08-11 05:31:07 +00003995 if (!getDerived().AlwaysRebuild() &&
3996 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00003997 return SemaRef.Owned(E->Retain());
3998
Douglas Gregorb98b1992009-08-11 05:31:07 +00003999 return getDerived().RebuildImplicitValueInitExpr(T);
4000}
Mike Stump1eb44332009-09-09 15:08:12 +00004001
Douglas Gregorb98b1992009-08-11 05:31:07 +00004002template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004003Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004004TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004005 // FIXME: Do we want the type as written?
4006 QualType T;
Mike Stump1eb44332009-09-09 15:08:12 +00004007
Douglas Gregorb98b1992009-08-11 05:31:07 +00004008 {
4009 // FIXME: Source location isn't quite accurate.
4010 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4011 T = getDerived().TransformType(E->getType());
4012 if (T.isNull())
4013 return SemaRef.ExprError();
4014 }
Mike Stump1eb44332009-09-09 15:08:12 +00004015
Douglas Gregorb98b1992009-08-11 05:31:07 +00004016 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4017 if (SubExpr.isInvalid())
4018 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004019
Douglas Gregorb98b1992009-08-11 05:31:07 +00004020 if (!getDerived().AlwaysRebuild() &&
4021 T == E->getType() &&
4022 SubExpr.get() == E->getSubExpr())
4023 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004024
Douglas Gregorb98b1992009-08-11 05:31:07 +00004025 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4026 T, E->getRParenLoc());
4027}
4028
4029template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004030Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004031TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004032 bool ArgumentChanged = false;
4033 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4034 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4035 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4036 if (Init.isInvalid())
4037 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004038
Douglas Gregorb98b1992009-08-11 05:31:07 +00004039 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4040 Inits.push_back(Init.takeAs<Expr>());
4041 }
Mike Stump1eb44332009-09-09 15:08:12 +00004042
Douglas Gregorb98b1992009-08-11 05:31:07 +00004043 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4044 move_arg(Inits),
4045 E->getRParenLoc());
4046}
Mike Stump1eb44332009-09-09 15:08:12 +00004047
Douglas Gregorb98b1992009-08-11 05:31:07 +00004048/// \brief Transform an address-of-label expression.
4049///
4050/// By default, the transformation of an address-of-label expression always
4051/// rebuilds the expression, so that the label identifier can be resolved to
4052/// the corresponding label statement by semantic analysis.
4053template<typename Derived>
4054Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004055TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004056 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4057 E->getLabel());
4058}
Mike Stump1eb44332009-09-09 15:08:12 +00004059
4060template<typename Derived>
Douglas Gregorc86a6e92009-11-04 07:01:15 +00004061Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004062TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004063 OwningStmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004064 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4065 if (SubStmt.isInvalid())
4066 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004067
Douglas Gregorb98b1992009-08-11 05:31:07 +00004068 if (!getDerived().AlwaysRebuild() &&
4069 SubStmt.get() == E->getSubStmt())
4070 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004071
4072 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004073 move(SubStmt),
4074 E->getRParenLoc());
4075}
Mike Stump1eb44332009-09-09 15:08:12 +00004076
Douglas Gregorb98b1992009-08-11 05:31:07 +00004077template<typename Derived>
4078Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004079TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004080 QualType T1, T2;
4081 {
4082 // FIXME: Source location isn't quite accurate.
4083 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004084
Douglas Gregorb98b1992009-08-11 05:31:07 +00004085 T1 = getDerived().TransformType(E->getArgType1());
4086 if (T1.isNull())
4087 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004088
Douglas Gregorb98b1992009-08-11 05:31:07 +00004089 T2 = getDerived().TransformType(E->getArgType2());
4090 if (T2.isNull())
4091 return SemaRef.ExprError();
4092 }
4093
4094 if (!getDerived().AlwaysRebuild() &&
4095 T1 == E->getArgType1() &&
4096 T2 == E->getArgType2())
Mike Stump1eb44332009-09-09 15:08:12 +00004097 return SemaRef.Owned(E->Retain());
4098
Douglas Gregorb98b1992009-08-11 05:31:07 +00004099 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4100 T1, T2, E->getRParenLoc());
4101}
Mike Stump1eb44332009-09-09 15:08:12 +00004102
Douglas Gregorb98b1992009-08-11 05:31:07 +00004103template<typename Derived>
4104Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004105TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004106 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4107 if (Cond.isInvalid())
4108 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004109
Douglas Gregorb98b1992009-08-11 05:31:07 +00004110 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4111 if (LHS.isInvalid())
4112 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004113
Douglas Gregorb98b1992009-08-11 05:31:07 +00004114 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4115 if (RHS.isInvalid())
4116 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004117
Douglas Gregorb98b1992009-08-11 05:31:07 +00004118 if (!getDerived().AlwaysRebuild() &&
4119 Cond.get() == E->getCond() &&
4120 LHS.get() == E->getLHS() &&
4121 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004122 return SemaRef.Owned(E->Retain());
4123
Douglas Gregorb98b1992009-08-11 05:31:07 +00004124 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4125 move(Cond), move(LHS), move(RHS),
4126 E->getRParenLoc());
4127}
Mike Stump1eb44332009-09-09 15:08:12 +00004128
Douglas Gregorb98b1992009-08-11 05:31:07 +00004129template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004130Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004131TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004132 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004133}
4134
4135template<typename Derived>
4136Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004137TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004138 switch (E->getOperator()) {
4139 case OO_New:
4140 case OO_Delete:
4141 case OO_Array_New:
4142 case OO_Array_Delete:
4143 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4144 return SemaRef.ExprError();
4145
4146 case OO_Call: {
4147 // This is a call to an object's operator().
4148 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4149
4150 // Transform the object itself.
4151 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4152 if (Object.isInvalid())
4153 return SemaRef.ExprError();
4154
4155 // FIXME: Poor location information
4156 SourceLocation FakeLParenLoc
4157 = SemaRef.PP.getLocForEndOfToken(
4158 static_cast<Expr *>(Object.get())->getLocEnd());
4159
4160 // Transform the call arguments.
4161 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4162 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4163 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004164 if (getDerived().DropCallArgument(E->getArg(I)))
4165 break;
4166
Douglas Gregor668d6d92009-12-13 20:44:55 +00004167 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4168 if (Arg.isInvalid())
4169 return SemaRef.ExprError();
4170
4171 // FIXME: Poor source location information.
4172 SourceLocation FakeCommaLoc
4173 = SemaRef.PP.getLocForEndOfToken(
4174 static_cast<Expr *>(Arg.get())->getLocEnd());
4175 FakeCommaLocs.push_back(FakeCommaLoc);
4176 Args.push_back(Arg.release());
4177 }
4178
4179 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4180 move_arg(Args),
4181 FakeCommaLocs.data(),
4182 E->getLocEnd());
4183 }
4184
4185#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4186 case OO_##Name:
4187#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4188#include "clang/Basic/OperatorKinds.def"
4189 case OO_Subscript:
4190 // Handled below.
4191 break;
4192
4193 case OO_Conditional:
4194 llvm_unreachable("conditional operator is not actually overloadable");
4195 return SemaRef.ExprError();
4196
4197 case OO_None:
4198 case NUM_OVERLOADED_OPERATORS:
4199 llvm_unreachable("not an overloaded operator?");
4200 return SemaRef.ExprError();
4201 }
4202
Douglas Gregorb98b1992009-08-11 05:31:07 +00004203 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4204 if (Callee.isInvalid())
4205 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004206
John McCall454feb92009-12-08 09:21:05 +00004207 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004208 if (First.isInvalid())
4209 return SemaRef.ExprError();
4210
4211 OwningExprResult Second(SemaRef);
4212 if (E->getNumArgs() == 2) {
4213 Second = getDerived().TransformExpr(E->getArg(1));
4214 if (Second.isInvalid())
4215 return SemaRef.ExprError();
4216 }
Mike Stump1eb44332009-09-09 15:08:12 +00004217
Douglas Gregorb98b1992009-08-11 05:31:07 +00004218 if (!getDerived().AlwaysRebuild() &&
4219 Callee.get() == E->getCallee() &&
4220 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00004221 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4222 return SemaRef.Owned(E->Retain());
4223
Douglas Gregorb98b1992009-08-11 05:31:07 +00004224 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4225 E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004226 move(Callee),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004227 move(First),
4228 move(Second));
4229}
Mike Stump1eb44332009-09-09 15:08:12 +00004230
Douglas Gregorb98b1992009-08-11 05:31:07 +00004231template<typename Derived>
4232Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004233TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4234 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004235}
Mike Stump1eb44332009-09-09 15:08:12 +00004236
Douglas Gregorb98b1992009-08-11 05:31:07 +00004237template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004238Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004239TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004240 QualType ExplicitTy;
4241 {
4242 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004243 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004244 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4245 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004246
Douglas Gregorb98b1992009-08-11 05:31:07 +00004247 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4248 if (ExplicitTy.isNull())
4249 return SemaRef.ExprError();
4250 }
Mike Stump1eb44332009-09-09 15:08:12 +00004251
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004252 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004253 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004254 if (SubExpr.isInvalid())
4255 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004256
Douglas Gregorb98b1992009-08-11 05:31:07 +00004257 if (!getDerived().AlwaysRebuild() &&
4258 ExplicitTy == E->getTypeAsWritten() &&
4259 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004260 return SemaRef.Owned(E->Retain());
4261
Douglas Gregorb98b1992009-08-11 05:31:07 +00004262 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00004263 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004264 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4265 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4266 SourceLocation FakeRParenLoc
4267 = SemaRef.PP.getLocForEndOfToken(
4268 E->getSubExpr()->getSourceRange().getEnd());
4269 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004270 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004271 FakeLAngleLoc,
4272 ExplicitTy,
4273 FakeRAngleLoc,
4274 FakeRAngleLoc,
4275 move(SubExpr),
4276 FakeRParenLoc);
4277}
Mike Stump1eb44332009-09-09 15:08:12 +00004278
Douglas Gregorb98b1992009-08-11 05:31:07 +00004279template<typename Derived>
4280Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004281TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4282 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004283}
Mike Stump1eb44332009-09-09 15:08:12 +00004284
4285template<typename Derived>
4286Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004287TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4288 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004289}
4290
Douglas Gregorb98b1992009-08-11 05:31:07 +00004291template<typename Derived>
4292Sema::OwningExprResult
4293TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004294 CXXReinterpretCastExpr *E) {
4295 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004296}
Mike Stump1eb44332009-09-09 15:08:12 +00004297
Douglas Gregorb98b1992009-08-11 05:31:07 +00004298template<typename Derived>
4299Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004300TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4301 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004302}
Mike Stump1eb44332009-09-09 15:08:12 +00004303
Douglas Gregorb98b1992009-08-11 05:31:07 +00004304template<typename Derived>
4305Sema::OwningExprResult
4306TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004307 CXXFunctionalCastExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004308 QualType ExplicitTy;
4309 {
4310 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004311
Douglas Gregorb98b1992009-08-11 05:31:07 +00004312 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4313 if (ExplicitTy.isNull())
4314 return SemaRef.ExprError();
4315 }
Mike Stump1eb44332009-09-09 15:08:12 +00004316
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004317 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004318 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004319 if (SubExpr.isInvalid())
4320 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004321
Douglas Gregorb98b1992009-08-11 05:31:07 +00004322 if (!getDerived().AlwaysRebuild() &&
4323 ExplicitTy == E->getTypeAsWritten() &&
4324 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004325 return SemaRef.Owned(E->Retain());
4326
Douglas Gregorb98b1992009-08-11 05:31:07 +00004327 // FIXME: The end of the type's source range is wrong
4328 return getDerived().RebuildCXXFunctionalCastExpr(
4329 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
4330 ExplicitTy,
4331 /*FIXME:*/E->getSubExpr()->getLocStart(),
4332 move(SubExpr),
4333 E->getRParenLoc());
4334}
Mike Stump1eb44332009-09-09 15:08:12 +00004335
Douglas Gregorb98b1992009-08-11 05:31:07 +00004336template<typename Derived>
4337Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004338TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004339 if (E->isTypeOperand()) {
4340 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004341
Douglas Gregorb98b1992009-08-11 05:31:07 +00004342 QualType T = getDerived().TransformType(E->getTypeOperand());
4343 if (T.isNull())
4344 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004345
Douglas Gregorb98b1992009-08-11 05:31:07 +00004346 if (!getDerived().AlwaysRebuild() &&
4347 T == E->getTypeOperand())
4348 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004349
Douglas Gregorb98b1992009-08-11 05:31:07 +00004350 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4351 /*FIXME:*/E->getLocStart(),
4352 T,
4353 E->getLocEnd());
4354 }
Mike Stump1eb44332009-09-09 15:08:12 +00004355
Douglas Gregorb98b1992009-08-11 05:31:07 +00004356 // We don't know whether the expression is potentially evaluated until
4357 // after we perform semantic analysis, so the expression is potentially
4358 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00004359 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004360 Action::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004361
Douglas Gregorb98b1992009-08-11 05:31:07 +00004362 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4363 if (SubExpr.isInvalid())
4364 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004365
Douglas Gregorb98b1992009-08-11 05:31:07 +00004366 if (!getDerived().AlwaysRebuild() &&
4367 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00004368 return SemaRef.Owned(E->Retain());
4369
Douglas Gregorb98b1992009-08-11 05:31:07 +00004370 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4371 /*FIXME:*/E->getLocStart(),
4372 move(SubExpr),
4373 E->getLocEnd());
4374}
4375
4376template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004377Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004378TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004379 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004380}
Mike Stump1eb44332009-09-09 15:08:12 +00004381
Douglas Gregorb98b1992009-08-11 05:31:07 +00004382template<typename Derived>
4383Sema::OwningExprResult
4384TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00004385 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004386 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004387}
Mike Stump1eb44332009-09-09 15:08:12 +00004388
Douglas Gregorb98b1992009-08-11 05:31:07 +00004389template<typename Derived>
4390Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004391TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004392 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004393
Douglas Gregorb98b1992009-08-11 05:31:07 +00004394 QualType T = getDerived().TransformType(E->getType());
4395 if (T.isNull())
4396 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004397
Douglas Gregorb98b1992009-08-11 05:31:07 +00004398 if (!getDerived().AlwaysRebuild() &&
4399 T == E->getType())
4400 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004401
Douglas Gregor828a1972010-01-07 23:12:05 +00004402 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004403}
Mike Stump1eb44332009-09-09 15:08:12 +00004404
Douglas Gregorb98b1992009-08-11 05:31:07 +00004405template<typename Derived>
4406Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004407TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004408 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4409 if (SubExpr.isInvalid())
4410 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004411
Douglas Gregorb98b1992009-08-11 05:31:07 +00004412 if (!getDerived().AlwaysRebuild() &&
4413 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004414 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004415
4416 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4417}
Mike Stump1eb44332009-09-09 15:08:12 +00004418
Douglas Gregorb98b1992009-08-11 05:31:07 +00004419template<typename Derived>
4420Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004421TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004422 ParmVarDecl *Param
Douglas Gregorb98b1992009-08-11 05:31:07 +00004423 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4424 if (!Param)
4425 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004426
Douglas Gregorb98b1992009-08-11 05:31:07 +00004427 if (getDerived().AlwaysRebuild() &&
4428 Param == E->getParam())
4429 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004430
Douglas Gregor036aed12009-12-23 23:03:06 +00004431 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004432}
Mike Stump1eb44332009-09-09 15:08:12 +00004433
Douglas Gregorb98b1992009-08-11 05:31:07 +00004434template<typename Derived>
4435Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004436TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004437 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4438
4439 QualType T = getDerived().TransformType(E->getType());
4440 if (T.isNull())
4441 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004442
Douglas Gregorb98b1992009-08-11 05:31:07 +00004443 if (!getDerived().AlwaysRebuild() &&
4444 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004445 return SemaRef.Owned(E->Retain());
4446
4447 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004448 /*FIXME:*/E->getTypeBeginLoc(),
4449 T,
4450 E->getRParenLoc());
4451}
Mike Stump1eb44332009-09-09 15:08:12 +00004452
Douglas Gregorb98b1992009-08-11 05:31:07 +00004453template<typename Derived>
4454Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004455TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004456 // Transform the type that we're allocating
4457 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4458 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4459 if (AllocType.isNull())
4460 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004461
Douglas Gregorb98b1992009-08-11 05:31:07 +00004462 // Transform the size of the array we're allocating (if any).
4463 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4464 if (ArraySize.isInvalid())
4465 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004466
Douglas Gregorb98b1992009-08-11 05:31:07 +00004467 // Transform the placement arguments (if any).
4468 bool ArgumentChanged = false;
4469 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4470 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4471 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4472 if (Arg.isInvalid())
4473 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004474
Douglas Gregorb98b1992009-08-11 05:31:07 +00004475 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4476 PlacementArgs.push_back(Arg.take());
4477 }
Mike Stump1eb44332009-09-09 15:08:12 +00004478
Douglas Gregor43959a92009-08-20 07:17:43 +00004479 // transform the constructor arguments (if any).
Douglas Gregorb98b1992009-08-11 05:31:07 +00004480 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4481 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4482 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4483 if (Arg.isInvalid())
4484 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004485
Douglas Gregorb98b1992009-08-11 05:31:07 +00004486 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4487 ConstructorArgs.push_back(Arg.take());
4488 }
Mike Stump1eb44332009-09-09 15:08:12 +00004489
Douglas Gregorb98b1992009-08-11 05:31:07 +00004490 if (!getDerived().AlwaysRebuild() &&
4491 AllocType == E->getAllocatedType() &&
4492 ArraySize.get() == E->getArraySize() &&
4493 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004494 return SemaRef.Owned(E->Retain());
4495
Douglas Gregor5b5ad842009-12-22 17:13:37 +00004496 if (!ArraySize.get()) {
4497 // If no array size was specified, but the new expression was
4498 // instantiated with an array type (e.g., "new T" where T is
4499 // instantiated with "int[4]"), extract the outer bound from the
4500 // array type as our array size. We do this with constant and
4501 // dependently-sized array types.
4502 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4503 if (!ArrayT) {
4504 // Do nothing
4505 } else if (const ConstantArrayType *ConsArrayT
4506 = dyn_cast<ConstantArrayType>(ArrayT)) {
4507 ArraySize
4508 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4509 ConsArrayT->getSize(),
4510 SemaRef.Context.getSizeType(),
4511 /*FIXME:*/E->getLocStart()));
4512 AllocType = ConsArrayT->getElementType();
4513 } else if (const DependentSizedArrayType *DepArrayT
4514 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4515 if (DepArrayT->getSizeExpr()) {
4516 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4517 AllocType = DepArrayT->getElementType();
4518 }
4519 }
4520 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004521 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4522 E->isGlobalNew(),
4523 /*FIXME:*/E->getLocStart(),
4524 move_arg(PlacementArgs),
4525 /*FIXME:*/E->getLocStart(),
4526 E->isParenTypeId(),
4527 AllocType,
4528 /*FIXME:*/E->getLocStart(),
4529 /*FIXME:*/SourceRange(),
4530 move(ArraySize),
4531 /*FIXME:*/E->getLocStart(),
4532 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00004533 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004534}
Mike Stump1eb44332009-09-09 15:08:12 +00004535
Douglas Gregorb98b1992009-08-11 05:31:07 +00004536template<typename Derived>
4537Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004538TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004539 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4540 if (Operand.isInvalid())
4541 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004542
Douglas Gregorb98b1992009-08-11 05:31:07 +00004543 if (!getDerived().AlwaysRebuild() &&
Mike Stump1eb44332009-09-09 15:08:12 +00004544 Operand.get() == E->getArgument())
4545 return SemaRef.Owned(E->Retain());
4546
Douglas Gregorb98b1992009-08-11 05:31:07 +00004547 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4548 E->isGlobalDelete(),
4549 E->isArrayForm(),
4550 move(Operand));
4551}
Mike Stump1eb44332009-09-09 15:08:12 +00004552
Douglas Gregorb98b1992009-08-11 05:31:07 +00004553template<typename Derived>
4554Sema::OwningExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00004555TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00004556 CXXPseudoDestructorExpr *E) {
Douglas Gregora71d8192009-09-04 17:36:40 +00004557 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4558 if (Base.isInvalid())
4559 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004560
Douglas Gregora71d8192009-09-04 17:36:40 +00004561 NestedNameSpecifier *Qualifier
4562 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4563 E->getQualifierRange());
4564 if (E->getQualifier() && !Qualifier)
4565 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004566
Douglas Gregora71d8192009-09-04 17:36:40 +00004567 QualType DestroyedType;
4568 {
4569 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4570 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4571 if (DestroyedType.isNull())
4572 return SemaRef.ExprError();
4573 }
Mike Stump1eb44332009-09-09 15:08:12 +00004574
Douglas Gregora71d8192009-09-04 17:36:40 +00004575 if (!getDerived().AlwaysRebuild() &&
4576 Base.get() == E->getBase() &&
4577 Qualifier == E->getQualifier() &&
4578 DestroyedType == E->getDestroyedType())
4579 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004580
Douglas Gregora71d8192009-09-04 17:36:40 +00004581 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4582 E->getOperatorLoc(),
4583 E->isArrow(),
4584 E->getDestroyedTypeLoc(),
4585 DestroyedType,
4586 Qualifier,
4587 E->getQualifierRange());
4588}
Mike Stump1eb44332009-09-09 15:08:12 +00004589
Douglas Gregora71d8192009-09-04 17:36:40 +00004590template<typename Derived>
4591Sema::OwningExprResult
John McCallba135432009-11-21 08:51:07 +00004592TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00004593 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00004594 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4595
4596 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4597 Sema::LookupOrdinaryName);
4598
4599 // Transform all the decls.
4600 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4601 E = Old->decls_end(); I != E; ++I) {
4602 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall9f54ad42009-12-10 09:41:52 +00004603 if (!InstD) {
4604 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4605 // This can happen because of dependent hiding.
4606 if (isa<UsingShadowDecl>(*I))
4607 continue;
4608 else
4609 return SemaRef.ExprError();
4610 }
John McCallf7a1a742009-11-24 19:00:30 +00004611
4612 // Expand using declarations.
4613 if (isa<UsingDecl>(InstD)) {
4614 UsingDecl *UD = cast<UsingDecl>(InstD);
4615 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4616 E = UD->shadow_end(); I != E; ++I)
4617 R.addDecl(*I);
4618 continue;
4619 }
4620
4621 R.addDecl(InstD);
4622 }
4623
4624 // Resolve a kind, but don't do any further analysis. If it's
4625 // ambiguous, the callee needs to deal with it.
4626 R.resolveKind();
4627
4628 // Rebuild the nested-name qualifier, if present.
4629 CXXScopeSpec SS;
4630 NestedNameSpecifier *Qualifier = 0;
4631 if (Old->getQualifier()) {
4632 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4633 Old->getQualifierRange());
4634 if (!Qualifier)
4635 return SemaRef.ExprError();
4636
4637 SS.setScopeRep(Qualifier);
4638 SS.setRange(Old->getQualifierRange());
4639 }
4640
4641 // If we have no template arguments, it's a normal declaration name.
4642 if (!Old->hasExplicitTemplateArgs())
4643 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4644
4645 // If we have template arguments, rebuild them, then rebuild the
4646 // templateid expression.
4647 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4648 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4649 TemplateArgumentLoc Loc;
4650 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4651 return SemaRef.ExprError();
4652 TransArgs.addArgument(Loc);
4653 }
4654
4655 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4656 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004657}
Mike Stump1eb44332009-09-09 15:08:12 +00004658
Douglas Gregorb98b1992009-08-11 05:31:07 +00004659template<typename Derived>
4660Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004661TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004662 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004663
Douglas Gregorb98b1992009-08-11 05:31:07 +00004664 QualType T = getDerived().TransformType(E->getQueriedType());
4665 if (T.isNull())
4666 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004667
Douglas Gregorb98b1992009-08-11 05:31:07 +00004668 if (!getDerived().AlwaysRebuild() &&
4669 T == E->getQueriedType())
4670 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004671
Douglas Gregorb98b1992009-08-11 05:31:07 +00004672 // FIXME: Bad location information
4673 SourceLocation FakeLParenLoc
4674 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump1eb44332009-09-09 15:08:12 +00004675
4676 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004677 E->getLocStart(),
4678 /*FIXME:*/FakeLParenLoc,
4679 T,
4680 E->getLocEnd());
4681}
Mike Stump1eb44332009-09-09 15:08:12 +00004682
Douglas Gregorb98b1992009-08-11 05:31:07 +00004683template<typename Derived>
4684Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00004685TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall454feb92009-12-08 09:21:05 +00004686 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004687 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00004688 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4689 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004690 if (!NNS)
4691 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004692
4693 DeclarationName Name
Douglas Gregor81499bb2009-09-03 22:13:48 +00004694 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4695 if (!Name)
4696 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004697
John McCallf7a1a742009-11-24 19:00:30 +00004698 if (!E->hasExplicitTemplateArgs()) {
4699 if (!getDerived().AlwaysRebuild() &&
4700 NNS == E->getQualifier() &&
4701 Name == E->getDeclName())
4702 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004703
John McCallf7a1a742009-11-24 19:00:30 +00004704 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4705 E->getQualifierRange(),
4706 Name, E->getLocation(),
4707 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00004708 }
John McCalld5532b62009-11-23 01:53:49 +00004709
4710 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004711 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004712 TemplateArgumentLoc Loc;
4713 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb98b1992009-08-11 05:31:07 +00004714 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004715 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004716 }
4717
John McCallf7a1a742009-11-24 19:00:30 +00004718 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4719 E->getQualifierRange(),
4720 Name, E->getLocation(),
4721 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004722}
4723
4724template<typename Derived>
4725Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004726TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004727 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4728
4729 QualType T = getDerived().TransformType(E->getType());
4730 if (T.isNull())
4731 return SemaRef.ExprError();
4732
4733 CXXConstructorDecl *Constructor
4734 = cast_or_null<CXXConstructorDecl>(
4735 getDerived().TransformDecl(E->getConstructor()));
4736 if (!Constructor)
4737 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004738
Douglas Gregorb98b1992009-08-11 05:31:07 +00004739 bool ArgumentChanged = false;
4740 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00004741 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004742 ArgEnd = E->arg_end();
4743 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004744 if (getDerived().DropCallArgument(*Arg)) {
4745 ArgumentChanged = true;
4746 break;
4747 }
4748
Douglas Gregorb98b1992009-08-11 05:31:07 +00004749 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4750 if (TransArg.isInvalid())
4751 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004752
Douglas Gregorb98b1992009-08-11 05:31:07 +00004753 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4754 Args.push_back(TransArg.takeAs<Expr>());
4755 }
4756
4757 if (!getDerived().AlwaysRebuild() &&
4758 T == E->getType() &&
4759 Constructor == E->getConstructor() &&
4760 !ArgumentChanged)
4761 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004762
Douglas Gregor4411d2e2009-12-14 16:27:04 +00004763 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
4764 Constructor, E->isElidable(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004765 move_arg(Args));
4766}
Mike Stump1eb44332009-09-09 15:08:12 +00004767
Douglas Gregorb98b1992009-08-11 05:31:07 +00004768/// \brief Transform a C++ temporary-binding expression.
4769///
Douglas Gregor51326552009-12-24 18:51:59 +00004770/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
4771/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004772template<typename Derived>
4773Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004774TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00004775 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004776}
Mike Stump1eb44332009-09-09 15:08:12 +00004777
4778/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00004779/// be destroyed after the expression is evaluated.
4780///
Douglas Gregor51326552009-12-24 18:51:59 +00004781/// Since CXXExprWithTemporaries nodes are implicitly generated, we
4782/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004783template<typename Derived>
4784Sema::OwningExprResult
4785TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00004786 CXXExprWithTemporaries *E) {
4787 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004788}
Mike Stump1eb44332009-09-09 15:08:12 +00004789
Douglas Gregorb98b1992009-08-11 05:31:07 +00004790template<typename Derived>
4791Sema::OwningExprResult
4792TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall454feb92009-12-08 09:21:05 +00004793 CXXTemporaryObjectExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004794 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4795 QualType T = getDerived().TransformType(E->getType());
4796 if (T.isNull())
4797 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004798
Douglas Gregorb98b1992009-08-11 05:31:07 +00004799 CXXConstructorDecl *Constructor
4800 = cast_or_null<CXXConstructorDecl>(
4801 getDerived().TransformDecl(E->getConstructor()));
4802 if (!Constructor)
4803 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004804
Douglas Gregorb98b1992009-08-11 05:31:07 +00004805 bool ArgumentChanged = false;
4806 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4807 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00004808 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004809 ArgEnd = E->arg_end();
4810 Arg != ArgEnd; ++Arg) {
4811 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4812 if (TransArg.isInvalid())
4813 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004814
Douglas Gregorb98b1992009-08-11 05:31:07 +00004815 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4816 Args.push_back((Expr *)TransArg.release());
4817 }
Mike Stump1eb44332009-09-09 15:08:12 +00004818
Douglas Gregorb98b1992009-08-11 05:31:07 +00004819 if (!getDerived().AlwaysRebuild() &&
4820 T == E->getType() &&
4821 Constructor == E->getConstructor() &&
4822 !ArgumentChanged)
4823 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004824
Douglas Gregorb98b1992009-08-11 05:31:07 +00004825 // FIXME: Bogus location information
4826 SourceLocation CommaLoc;
4827 if (Args.size() > 1) {
4828 Expr *First = (Expr *)Args[0];
Mike Stump1eb44332009-09-09 15:08:12 +00004829 CommaLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004830 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4831 }
4832 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4833 T,
4834 /*FIXME:*/E->getTypeBeginLoc(),
4835 move_arg(Args),
4836 &CommaLoc,
4837 E->getLocEnd());
4838}
Mike Stump1eb44332009-09-09 15:08:12 +00004839
Douglas Gregorb98b1992009-08-11 05:31:07 +00004840template<typename Derived>
4841Sema::OwningExprResult
4842TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00004843 CXXUnresolvedConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004844 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4845 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4846 if (T.isNull())
4847 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004848
Douglas Gregorb98b1992009-08-11 05:31:07 +00004849 bool ArgumentChanged = false;
4850 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4851 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4852 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4853 ArgEnd = E->arg_end();
4854 Arg != ArgEnd; ++Arg) {
4855 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4856 if (TransArg.isInvalid())
4857 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004858
Douglas Gregorb98b1992009-08-11 05:31:07 +00004859 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4860 FakeCommaLocs.push_back(
4861 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4862 Args.push_back(TransArg.takeAs<Expr>());
4863 }
Mike Stump1eb44332009-09-09 15:08:12 +00004864
Douglas Gregorb98b1992009-08-11 05:31:07 +00004865 if (!getDerived().AlwaysRebuild() &&
4866 T == E->getTypeAsWritten() &&
4867 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004868 return SemaRef.Owned(E->Retain());
4869
Douglas Gregorb98b1992009-08-11 05:31:07 +00004870 // FIXME: we're faking the locations of the commas
4871 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4872 T,
4873 E->getLParenLoc(),
4874 move_arg(Args),
4875 FakeCommaLocs.data(),
4876 E->getRParenLoc());
4877}
Mike Stump1eb44332009-09-09 15:08:12 +00004878
Douglas Gregorb98b1992009-08-11 05:31:07 +00004879template<typename Derived>
4880Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00004881TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall454feb92009-12-08 09:21:05 +00004882 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004883 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00004884 OwningExprResult Base(SemaRef, (Expr*) 0);
4885 Expr *OldBase;
4886 QualType BaseType;
4887 QualType ObjectType;
4888 if (!E->isImplicitAccess()) {
4889 OldBase = E->getBase();
4890 Base = getDerived().TransformExpr(OldBase);
4891 if (Base.isInvalid())
4892 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004893
John McCallaa81e162009-12-01 22:10:20 +00004894 // Start the member reference and compute the object's type.
4895 Sema::TypeTy *ObjectTy = 0;
4896 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4897 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00004898 E->isArrow()? tok::arrow : tok::period,
John McCallaa81e162009-12-01 22:10:20 +00004899 ObjectTy);
4900 if (Base.isInvalid())
4901 return SemaRef.ExprError();
4902
4903 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
4904 BaseType = ((Expr*) Base.get())->getType();
4905 } else {
4906 OldBase = 0;
4907 BaseType = getDerived().TransformType(E->getBaseType());
4908 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
4909 }
Mike Stump1eb44332009-09-09 15:08:12 +00004910
Douglas Gregor6cd21982009-10-20 05:58:46 +00004911 // Transform the first part of the nested-name-specifier that qualifies
4912 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00004913 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00004914 = getDerived().TransformFirstQualifierInScope(
4915 E->getFirstQualifierFoundInScope(),
4916 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00004917
Douglas Gregora38c6872009-09-03 16:14:30 +00004918 NestedNameSpecifier *Qualifier = 0;
4919 if (E->getQualifier()) {
4920 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4921 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00004922 ObjectType,
4923 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00004924 if (!Qualifier)
4925 return SemaRef.ExprError();
4926 }
Mike Stump1eb44332009-09-09 15:08:12 +00004927
4928 DeclarationName Name
Douglas Gregordd62b152009-10-19 22:04:39 +00004929 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCallaa81e162009-12-01 22:10:20 +00004930 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00004931 if (!Name)
4932 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004933
John McCallaa81e162009-12-01 22:10:20 +00004934 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00004935 // This is a reference to a member without an explicitly-specified
4936 // template argument list. Optimize for this common case.
4937 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00004938 Base.get() == OldBase &&
4939 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00004940 Qualifier == E->getQualifier() &&
4941 Name == E->getMember() &&
4942 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00004943 return SemaRef.Owned(E->Retain());
4944
John McCall865d4472009-11-19 22:55:06 +00004945 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00004946 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00004947 E->isArrow(),
4948 E->getOperatorLoc(),
4949 Qualifier,
4950 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00004951 FirstQualifierInScope,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00004952 Name,
4953 E->getMemberLoc(),
John McCall129e2df2009-11-30 22:42:35 +00004954 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00004955 }
4956
John McCalld5532b62009-11-23 01:53:49 +00004957 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00004958 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004959 TemplateArgumentLoc Loc;
4960 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00004961 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004962 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00004963 }
Mike Stump1eb44332009-09-09 15:08:12 +00004964
John McCall865d4472009-11-19 22:55:06 +00004965 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00004966 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004967 E->isArrow(),
4968 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00004969 Qualifier,
4970 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00004971 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00004972 Name,
4973 E->getMemberLoc(),
4974 &TransArgs);
4975}
4976
4977template<typename Derived>
4978Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004979TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00004980 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00004981 OwningExprResult Base(SemaRef, (Expr*) 0);
4982 QualType BaseType;
4983 if (!Old->isImplicitAccess()) {
4984 Base = getDerived().TransformExpr(Old->getBase());
4985 if (Base.isInvalid())
4986 return SemaRef.ExprError();
4987 BaseType = ((Expr*) Base.get())->getType();
4988 } else {
4989 BaseType = getDerived().TransformType(Old->getBaseType());
4990 }
John McCall129e2df2009-11-30 22:42:35 +00004991
4992 NestedNameSpecifier *Qualifier = 0;
4993 if (Old->getQualifier()) {
4994 Qualifier
4995 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4996 Old->getQualifierRange());
4997 if (Qualifier == 0)
4998 return SemaRef.ExprError();
4999 }
5000
5001 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5002 Sema::LookupOrdinaryName);
5003
5004 // Transform all the decls.
5005 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5006 E = Old->decls_end(); I != E; ++I) {
5007 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall9f54ad42009-12-10 09:41:52 +00005008 if (!InstD) {
5009 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5010 // This can happen because of dependent hiding.
5011 if (isa<UsingShadowDecl>(*I))
5012 continue;
5013 else
5014 return SemaRef.ExprError();
5015 }
John McCall129e2df2009-11-30 22:42:35 +00005016
5017 // Expand using declarations.
5018 if (isa<UsingDecl>(InstD)) {
5019 UsingDecl *UD = cast<UsingDecl>(InstD);
5020 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5021 E = UD->shadow_end(); I != E; ++I)
5022 R.addDecl(*I);
5023 continue;
5024 }
5025
5026 R.addDecl(InstD);
5027 }
5028
5029 R.resolveKind();
5030
5031 TemplateArgumentListInfo TransArgs;
5032 if (Old->hasExplicitTemplateArgs()) {
5033 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5034 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5035 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5036 TemplateArgumentLoc Loc;
5037 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5038 Loc))
5039 return SemaRef.ExprError();
5040 TransArgs.addArgument(Loc);
5041 }
5042 }
John McCallc2233c52010-01-15 08:34:02 +00005043
5044 // FIXME: to do this check properly, we will need to preserve the
5045 // first-qualifier-in-scope here, just in case we had a dependent
5046 // base (and therefore couldn't do the check) and a
5047 // nested-name-qualifier (and therefore could do the lookup).
5048 NamedDecl *FirstQualifierInScope = 0;
John McCall129e2df2009-11-30 22:42:35 +00005049
5050 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005051 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00005052 Old->getOperatorLoc(),
5053 Old->isArrow(),
5054 Qualifier,
5055 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00005056 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005057 R,
5058 (Old->hasExplicitTemplateArgs()
5059 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005060}
5061
5062template<typename Derived>
5063Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005064TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005065 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005066}
5067
Mike Stump1eb44332009-09-09 15:08:12 +00005068template<typename Derived>
5069Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005070TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005071 // FIXME: poor source location
5072 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5073 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5074 if (EncodedType.isNull())
5075 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005076
Douglas Gregorb98b1992009-08-11 05:31:07 +00005077 if (!getDerived().AlwaysRebuild() &&
5078 EncodedType == E->getEncodedType())
Mike Stump1eb44332009-09-09 15:08:12 +00005079 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005080
5081 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5082 EncodedType,
5083 E->getRParenLoc());
5084}
Mike Stump1eb44332009-09-09 15:08:12 +00005085
Douglas Gregorb98b1992009-08-11 05:31:07 +00005086template<typename Derived>
5087Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005088TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005089 // FIXME: Implement this!
5090 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005091 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005092}
5093
Mike Stump1eb44332009-09-09 15:08:12 +00005094template<typename Derived>
5095Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005096TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005097 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005098}
5099
Mike Stump1eb44332009-09-09 15:08:12 +00005100template<typename Derived>
5101Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005102TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005103 ObjCProtocolDecl *Protocol
Douglas Gregorb98b1992009-08-11 05:31:07 +00005104 = cast_or_null<ObjCProtocolDecl>(
5105 getDerived().TransformDecl(E->getProtocol()));
5106 if (!Protocol)
5107 return SemaRef.ExprError();
5108
5109 if (!getDerived().AlwaysRebuild() &&
5110 Protocol == E->getProtocol())
Mike Stump1eb44332009-09-09 15:08:12 +00005111 return SemaRef.Owned(E->Retain());
5112
Douglas Gregorb98b1992009-08-11 05:31:07 +00005113 return getDerived().RebuildObjCProtocolExpr(Protocol,
5114 E->getAtLoc(),
5115 /*FIXME:*/E->getAtLoc(),
5116 /*FIXME:*/E->getAtLoc(),
5117 E->getRParenLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00005118
Douglas Gregorb98b1992009-08-11 05:31:07 +00005119}
5120
Mike Stump1eb44332009-09-09 15:08:12 +00005121template<typename Derived>
5122Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005123TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005124 // FIXME: Implement this!
5125 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005126 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005127}
5128
Mike Stump1eb44332009-09-09 15:08:12 +00005129template<typename Derived>
5130Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005131TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005132 // FIXME: Implement this!
5133 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005134 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005135}
5136
Mike Stump1eb44332009-09-09 15:08:12 +00005137template<typename Derived>
5138Sema::OwningExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00005139TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00005140 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005141 // FIXME: Implement this!
5142 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005143 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005144}
5145
Mike Stump1eb44332009-09-09 15:08:12 +00005146template<typename Derived>
5147Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005148TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005149 // FIXME: Implement this!
5150 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005151 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005152}
5153
Mike Stump1eb44332009-09-09 15:08:12 +00005154template<typename Derived>
5155Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005156TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005157 // FIXME: Implement this!
5158 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005159 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005160}
5161
Mike Stump1eb44332009-09-09 15:08:12 +00005162template<typename Derived>
5163Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005164TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005165 bool ArgumentChanged = false;
5166 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5167 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5168 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5169 if (SubExpr.isInvalid())
5170 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005171
Douglas Gregorb98b1992009-08-11 05:31:07 +00005172 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5173 SubExprs.push_back(SubExpr.takeAs<Expr>());
5174 }
Mike Stump1eb44332009-09-09 15:08:12 +00005175
Douglas Gregorb98b1992009-08-11 05:31:07 +00005176 if (!getDerived().AlwaysRebuild() &&
5177 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005178 return SemaRef.Owned(E->Retain());
5179
Douglas Gregorb98b1992009-08-11 05:31:07 +00005180 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5181 move_arg(SubExprs),
5182 E->getRParenLoc());
5183}
5184
Mike Stump1eb44332009-09-09 15:08:12 +00005185template<typename Derived>
5186Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005187TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005188 // FIXME: Implement this!
5189 assert(false && "Cannot transform block expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005190 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005191}
5192
Mike Stump1eb44332009-09-09 15:08:12 +00005193template<typename Derived>
5194Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005195TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005196 // FIXME: Implement this!
5197 assert(false && "Cannot transform block-related expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005198 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005199}
Mike Stump1eb44332009-09-09 15:08:12 +00005200
Douglas Gregorb98b1992009-08-11 05:31:07 +00005201//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00005202// Type reconstruction
5203//===----------------------------------------------------------------------===//
5204
Mike Stump1eb44332009-09-09 15:08:12 +00005205template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005206QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5207 SourceLocation Star) {
5208 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005209 getDerived().getBaseEntity());
5210}
5211
Mike Stump1eb44332009-09-09 15:08:12 +00005212template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005213QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5214 SourceLocation Star) {
5215 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005216 getDerived().getBaseEntity());
5217}
5218
Mike Stump1eb44332009-09-09 15:08:12 +00005219template<typename Derived>
5220QualType
John McCall85737a72009-10-30 00:06:24 +00005221TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5222 bool WrittenAsLValue,
5223 SourceLocation Sigil) {
5224 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5225 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005226}
5227
5228template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005229QualType
John McCall85737a72009-10-30 00:06:24 +00005230TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5231 QualType ClassType,
5232 SourceLocation Sigil) {
John McCall0953e762009-09-24 19:53:00 +00005233 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall85737a72009-10-30 00:06:24 +00005234 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005235}
5236
5237template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005238QualType
John McCall85737a72009-10-30 00:06:24 +00005239TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5240 SourceLocation Sigil) {
5241 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCalla2becad2009-10-21 00:40:46 +00005242 getDerived().getBaseEntity());
5243}
5244
5245template<typename Derived>
5246QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00005247TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5248 ArrayType::ArraySizeModifier SizeMod,
5249 const llvm::APInt *Size,
5250 Expr *SizeExpr,
5251 unsigned IndexTypeQuals,
5252 SourceRange BracketsRange) {
5253 if (SizeExpr || !Size)
5254 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5255 IndexTypeQuals, BracketsRange,
5256 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00005257
5258 QualType Types[] = {
5259 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5260 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5261 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00005262 };
5263 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5264 QualType SizeType;
5265 for (unsigned I = 0; I != NumTypes; ++I)
5266 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5267 SizeType = Types[I];
5268 break;
5269 }
Mike Stump1eb44332009-09-09 15:08:12 +00005270
Douglas Gregor577f75a2009-08-04 16:50:30 +00005271 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005272 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005273 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00005274 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005275}
Mike Stump1eb44332009-09-09 15:08:12 +00005276
Douglas Gregor577f75a2009-08-04 16:50:30 +00005277template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005278QualType
5279TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005280 ArrayType::ArraySizeModifier SizeMod,
5281 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00005282 unsigned IndexTypeQuals,
5283 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005284 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00005285 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005286}
5287
5288template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005289QualType
Mike Stump1eb44332009-09-09 15:08:12 +00005290TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005291 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00005292 unsigned IndexTypeQuals,
5293 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005294 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00005295 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005296}
Mike Stump1eb44332009-09-09 15:08:12 +00005297
Douglas Gregor577f75a2009-08-04 16:50:30 +00005298template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005299QualType
5300TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005301 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005302 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005303 unsigned IndexTypeQuals,
5304 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005305 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005306 SizeExpr.takeAs<Expr>(),
5307 IndexTypeQuals, BracketsRange);
5308}
5309
5310template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005311QualType
5312TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005313 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005314 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005315 unsigned IndexTypeQuals,
5316 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005317 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005318 SizeExpr.takeAs<Expr>(),
5319 IndexTypeQuals, BracketsRange);
5320}
5321
5322template<typename Derived>
5323QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
5324 unsigned NumElements) {
5325 // FIXME: semantic checking!
5326 return SemaRef.Context.getVectorType(ElementType, NumElements);
5327}
Mike Stump1eb44332009-09-09 15:08:12 +00005328
Douglas Gregor577f75a2009-08-04 16:50:30 +00005329template<typename Derived>
5330QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5331 unsigned NumElements,
5332 SourceLocation AttributeLoc) {
5333 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5334 NumElements, true);
5335 IntegerLiteral *VectorSize
Mike Stump1eb44332009-09-09 15:08:12 +00005336 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005337 AttributeLoc);
5338 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5339 AttributeLoc);
5340}
Mike Stump1eb44332009-09-09 15:08:12 +00005341
Douglas Gregor577f75a2009-08-04 16:50:30 +00005342template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005343QualType
5344TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005345 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005346 SourceLocation AttributeLoc) {
5347 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5348}
Mike Stump1eb44332009-09-09 15:08:12 +00005349
Douglas Gregor577f75a2009-08-04 16:50:30 +00005350template<typename Derived>
5351QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00005352 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005353 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00005354 bool Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005355 unsigned Quals) {
Mike Stump1eb44332009-09-09 15:08:12 +00005356 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005357 Quals,
5358 getDerived().getBaseLocation(),
5359 getDerived().getBaseEntity());
5360}
Mike Stump1eb44332009-09-09 15:08:12 +00005361
Douglas Gregor577f75a2009-08-04 16:50:30 +00005362template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005363QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5364 return SemaRef.Context.getFunctionNoProtoType(T);
5365}
5366
5367template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00005368QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5369 assert(D && "no decl found");
5370 if (D->isInvalidDecl()) return QualType();
5371
5372 TypeDecl *Ty;
5373 if (isa<UsingDecl>(D)) {
5374 UsingDecl *Using = cast<UsingDecl>(D);
5375 assert(Using->isTypeName() &&
5376 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5377
5378 // A valid resolved using typename decl points to exactly one type decl.
5379 assert(++Using->shadow_begin() == Using->shadow_end());
5380 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5381
5382 } else {
5383 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5384 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5385 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5386 }
5387
5388 return SemaRef.Context.getTypeDeclType(Ty);
5389}
5390
5391template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00005392QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005393 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5394}
5395
5396template<typename Derived>
5397QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5398 return SemaRef.Context.getTypeOfType(Underlying);
5399}
5400
5401template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00005402QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005403 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5404}
5405
5406template<typename Derived>
5407QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00005408 TemplateName Template,
5409 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00005410 const TemplateArgumentListInfo &TemplateArgs) {
5411 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005412}
Mike Stump1eb44332009-09-09 15:08:12 +00005413
Douglas Gregordcee1a12009-08-06 05:28:30 +00005414template<typename Derived>
5415NestedNameSpecifier *
5416TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5417 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00005418 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00005419 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00005420 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00005421 CXXScopeSpec SS;
5422 // FIXME: The source location information is all wrong.
5423 SS.setRange(Range);
5424 SS.setScopeRep(Prefix);
5425 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00005426 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00005427 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00005428 ObjectType,
5429 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00005430 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00005431}
5432
5433template<typename Derived>
5434NestedNameSpecifier *
5435TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5436 SourceRange Range,
5437 NamespaceDecl *NS) {
5438 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5439}
5440
5441template<typename Derived>
5442NestedNameSpecifier *
5443TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5444 SourceRange Range,
5445 bool TemplateKW,
5446 QualType T) {
5447 if (T->isDependentType() || T->isRecordType() ||
5448 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00005449 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00005450 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5451 T.getTypePtr());
5452 }
Mike Stump1eb44332009-09-09 15:08:12 +00005453
Douglas Gregordcee1a12009-08-06 05:28:30 +00005454 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5455 return 0;
5456}
Mike Stump1eb44332009-09-09 15:08:12 +00005457
Douglas Gregord1067e52009-08-06 06:41:21 +00005458template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005459TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00005460TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5461 bool TemplateKW,
5462 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00005463 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00005464 Template);
5465}
5466
5467template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005468TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00005469TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005470 const IdentifierInfo &II,
5471 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00005472 CXXScopeSpec SS;
5473 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump1eb44332009-09-09 15:08:12 +00005474 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00005475 UnqualifiedId Name;
5476 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005477 return getSema().ActOnDependentTemplateName(
5478 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005479 SS,
Douglas Gregor014e88d2009-11-03 23:16:33 +00005480 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00005481 ObjectType.getAsOpaquePtr(),
5482 /*EnteringContext=*/false)
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005483 .template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00005484}
Mike Stump1eb44332009-09-09 15:08:12 +00005485
Douglas Gregorb98b1992009-08-11 05:31:07 +00005486template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00005487TemplateName
5488TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5489 OverloadedOperatorKind Operator,
5490 QualType ObjectType) {
5491 CXXScopeSpec SS;
5492 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5493 SS.setScopeRep(Qualifier);
5494 UnqualifiedId Name;
5495 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5496 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5497 Operator, SymbolLocations);
5498 return getSema().ActOnDependentTemplateName(
5499 /*FIXME:*/getDerived().getBaseLocation(),
5500 SS,
5501 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00005502 ObjectType.getAsOpaquePtr(),
5503 /*EnteringContext=*/false)
Douglas Gregorca1bdd72009-11-04 00:56:37 +00005504 .template getAsVal<TemplateName>();
5505}
5506
5507template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005508Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005509TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5510 SourceLocation OpLoc,
5511 ExprArg Callee,
5512 ExprArg First,
5513 ExprArg Second) {
5514 Expr *FirstExpr = (Expr *)First.get();
5515 Expr *SecondExpr = (Expr *)Second.get();
John McCallba135432009-11-21 08:51:07 +00005516 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005517 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00005518
Douglas Gregorb98b1992009-08-11 05:31:07 +00005519 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00005520 if (Op == OO_Subscript) {
5521 if (!FirstExpr->getType()->isOverloadableType() &&
5522 !SecondExpr->getType()->isOverloadableType())
5523 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCallba135432009-11-21 08:51:07 +00005524 CalleeExpr->getLocStart(),
Sebastian Redlf322ed62009-10-29 20:17:01 +00005525 move(Second), OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00005526 } else if (Op == OO_Arrow) {
5527 // -> is never a builtin operation.
5528 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redlf322ed62009-10-29 20:17:01 +00005529 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005530 if (!FirstExpr->getType()->isOverloadableType()) {
5531 // The argument is not of overloadable type, so try to create a
5532 // built-in unary operation.
Mike Stump1eb44332009-09-09 15:08:12 +00005533 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005534 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00005535
Douglas Gregorb98b1992009-08-11 05:31:07 +00005536 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5537 }
5538 } else {
Mike Stump1eb44332009-09-09 15:08:12 +00005539 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005540 !SecondExpr->getType()->isOverloadableType()) {
5541 // Neither of the arguments is an overloadable type, so try to
5542 // create a built-in binary operation.
5543 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00005544 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00005545 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5546 if (Result.isInvalid())
5547 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005548
Douglas Gregorb98b1992009-08-11 05:31:07 +00005549 First.release();
5550 Second.release();
5551 return move(Result);
5552 }
5553 }
Mike Stump1eb44332009-09-09 15:08:12 +00005554
5555 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00005556 // used during overload resolution.
5557 Sema::FunctionSet Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00005558
John McCallba135432009-11-21 08:51:07 +00005559 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5560 assert(ULE->requiresADL());
5561
5562 // FIXME: Do we have to check
5563 // IsAcceptableNonMemberOperatorCandidate for each of these?
5564 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(),
5565 E = ULE->decls_end(); I != E; ++I)
5566 Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I));
5567 } else {
5568 Functions.insert(AnyFunctionDecl::getFromNamedDecl(
5569 cast<DeclRefExpr>(CalleeExpr)->getDecl()));
5570 }
Mike Stump1eb44332009-09-09 15:08:12 +00005571
Douglas Gregorb98b1992009-08-11 05:31:07 +00005572 // Add any functions found via argument-dependent lookup.
5573 Expr *Args[2] = { FirstExpr, SecondExpr };
5574 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00005575 DeclarationName OpName
Douglas Gregorb98b1992009-08-11 05:31:07 +00005576 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
Sebastian Redl644be852009-10-23 19:23:15 +00005577 SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs,
5578 Functions);
Mike Stump1eb44332009-09-09 15:08:12 +00005579
Douglas Gregorb98b1992009-08-11 05:31:07 +00005580 // Create the overloaded operator invocation for unary operators.
5581 if (NumArgs == 1 || isPostIncDec) {
Mike Stump1eb44332009-09-09 15:08:12 +00005582 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005583 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5584 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5585 }
Mike Stump1eb44332009-09-09 15:08:12 +00005586
Sebastian Redlf322ed62009-10-29 20:17:01 +00005587 if (Op == OO_Subscript)
John McCallba135432009-11-21 08:51:07 +00005588 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5589 OpLoc,
5590 move(First),
5591 move(Second));
Sebastian Redlf322ed62009-10-29 20:17:01 +00005592
Douglas Gregorb98b1992009-08-11 05:31:07 +00005593 // Create the overloaded operator invocation for binary operators.
Mike Stump1eb44332009-09-09 15:08:12 +00005594 BinaryOperator::Opcode Opc =
Douglas Gregorb98b1992009-08-11 05:31:07 +00005595 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00005596 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00005597 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5598 if (Result.isInvalid())
5599 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005600
Douglas Gregorb98b1992009-08-11 05:31:07 +00005601 First.release();
5602 Second.release();
Mike Stump1eb44332009-09-09 15:08:12 +00005603 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005604}
Mike Stump1eb44332009-09-09 15:08:12 +00005605
Douglas Gregor577f75a2009-08-04 16:50:30 +00005606} // end namespace clang
5607
5608#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H