blob: 02dabbb2f589c474ccc91366b8113f019dd9391b [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.
John Thompson82287d12010-02-05 00:12:22 +0000431 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
432 bool IsAltiVec, bool IsPixel);
Mike Stump1eb44332009-09-09 15:08:12 +0000433
Douglas Gregor577f75a2009-08-04 16:50:30 +0000434 /// \brief Build a new extended vector type given the element type and
435 /// number of elements.
436 ///
437 /// By default, performs semantic analysis when building the vector type.
438 /// Subclasses may override this routine to provide different behavior.
439 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
440 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000441
442 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000443 /// given the element type and number of elements.
444 ///
445 /// By default, performs semantic analysis when building the vector type.
446 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000447 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000448 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000449 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000450
Douglas Gregor577f75a2009-08-04 16:50:30 +0000451 /// \brief Build a new function type.
452 ///
453 /// By default, performs semantic analysis when building the function type.
454 /// Subclasses may override this routine to provide different behavior.
455 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000456 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000457 unsigned NumParamTypes,
458 bool Variadic, unsigned Quals);
Mike Stump1eb44332009-09-09 15:08:12 +0000459
John McCalla2becad2009-10-21 00:40:46 +0000460 /// \brief Build a new unprototyped function type.
461 QualType RebuildFunctionNoProtoType(QualType ResultType);
462
John McCalled976492009-12-04 22:46:56 +0000463 /// \brief Rebuild an unresolved typename type, given the decl that
464 /// the UnresolvedUsingTypenameDecl was transformed to.
465 QualType RebuildUnresolvedUsingType(Decl *D);
466
Douglas Gregor577f75a2009-08-04 16:50:30 +0000467 /// \brief Build a new typedef type.
468 QualType RebuildTypedefType(TypedefDecl *Typedef) {
469 return SemaRef.Context.getTypeDeclType(Typedef);
470 }
471
472 /// \brief Build a new class/struct/union type.
473 QualType RebuildRecordType(RecordDecl *Record) {
474 return SemaRef.Context.getTypeDeclType(Record);
475 }
476
477 /// \brief Build a new Enum type.
478 QualType RebuildEnumType(EnumDecl *Enum) {
479 return SemaRef.Context.getTypeDeclType(Enum);
480 }
John McCall7da24312009-09-05 00:15:47 +0000481
482 /// \brief Build a new elaborated type.
483 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
484 return SemaRef.Context.getElaboratedType(T, Tag);
485 }
Mike Stump1eb44332009-09-09 15:08:12 +0000486
487 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000488 ///
489 /// By default, performs semantic analysis when building the typeof type.
490 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000491 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000492
Mike Stump1eb44332009-09-09 15:08:12 +0000493 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000494 ///
495 /// By default, builds a new TypeOfType with the given underlying type.
496 QualType RebuildTypeOfType(QualType Underlying);
497
Mike Stump1eb44332009-09-09 15:08:12 +0000498 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000499 ///
500 /// By default, performs semantic analysis when building the decltype type.
501 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000502 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump1eb44332009-09-09 15:08:12 +0000503
Douglas Gregor577f75a2009-08-04 16:50:30 +0000504 /// \brief Build a new template specialization type.
505 ///
506 /// By default, performs semantic analysis when building the template
507 /// specialization type. Subclasses may override this routine to provide
508 /// different behavior.
509 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000510 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000511 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000512
Douglas Gregor577f75a2009-08-04 16:50:30 +0000513 /// \brief Build a new qualified name type.
514 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000515 /// By default, builds a new QualifiedNameType type from the
516 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregor577f75a2009-08-04 16:50:30 +0000517 /// this routine to provide different behavior.
518 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
519 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000520 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000521
522 /// \brief Build a new typename type that refers to a template-id.
523 ///
524 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump1eb44332009-09-09 15:08:12 +0000525 /// and the given type. Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000526 /// different behavior.
527 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
528 if (NNS->isDependent())
Mike Stump1eb44332009-09-09 15:08:12 +0000529 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000530 cast<TemplateSpecializationType>(T));
Mike Stump1eb44332009-09-09 15:08:12 +0000531
Douglas Gregor577f75a2009-08-04 16:50:30 +0000532 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000533 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000534
535 /// \brief Build a new typename type that refers to an identifier.
536 ///
537 /// By default, performs semantic analysis when building the typename type
Mike Stump1eb44332009-09-09 15:08:12 +0000538 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000539 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000540 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall833ca992009-10-29 08:12:44 +0000541 const IdentifierInfo *Id,
542 SourceRange SR) {
543 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000544 }
Mike Stump1eb44332009-09-09 15:08:12 +0000545
Douglas Gregordcee1a12009-08-06 05:28:30 +0000546 /// \brief Build a new nested-name-specifier given the prefix and an
547 /// identifier that names the next step in the nested-name-specifier.
548 ///
549 /// By default, performs semantic analysis when building the new
550 /// nested-name-specifier. Subclasses may override this routine to provide
551 /// different behavior.
552 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
553 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000554 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000555 QualType ObjectType,
556 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000557
558 /// \brief Build a new nested-name-specifier given the prefix and the
559 /// namespace named in the next step in the nested-name-specifier.
560 ///
561 /// By default, performs semantic analysis when building the new
562 /// nested-name-specifier. Subclasses may override this routine to provide
563 /// different behavior.
564 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
565 SourceRange Range,
566 NamespaceDecl *NS);
567
568 /// \brief Build a new nested-name-specifier given the prefix and the
569 /// type named in the next step in the nested-name-specifier.
570 ///
571 /// By default, performs semantic analysis when building the new
572 /// nested-name-specifier. Subclasses may override this routine to provide
573 /// different behavior.
574 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
575 SourceRange Range,
576 bool TemplateKW,
577 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000578
579 /// \brief Build a new template name given a nested name specifier, a flag
580 /// indicating whether the "template" keyword was provided, and the template
581 /// that the template name refers to.
582 ///
583 /// By default, builds the new template name directly. Subclasses may override
584 /// this routine to provide different behavior.
585 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
586 bool TemplateKW,
587 TemplateDecl *Template);
588
Douglas Gregord1067e52009-08-06 06:41:21 +0000589 /// \brief Build a new template name given a nested name specifier and the
590 /// name that is referred to as a template.
591 ///
592 /// By default, performs semantic analysis to determine whether the name can
593 /// be resolved to a specific template, then builds the appropriate kind of
594 /// template name. Subclasses may override this routine to provide different
595 /// behavior.
596 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000597 const IdentifierInfo &II,
598 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000599
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000600 /// \brief Build a new template name given a nested name specifier and the
601 /// overloaded operator name that is referred to as a template.
602 ///
603 /// By default, performs semantic analysis to determine whether the name can
604 /// be resolved to a specific template, then builds the appropriate kind of
605 /// template name. Subclasses may override this routine to provide different
606 /// behavior.
607 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
608 OverloadedOperatorKind Operator,
609 QualType ObjectType);
610
Douglas Gregor43959a92009-08-20 07:17:43 +0000611 /// \brief Build a new compound statement.
612 ///
613 /// By default, performs semantic analysis to build the new statement.
614 /// Subclasses may override this routine to provide different behavior.
615 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
616 MultiStmtArg Statements,
617 SourceLocation RBraceLoc,
618 bool IsStmtExpr) {
619 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
620 IsStmtExpr);
621 }
622
623 /// \brief Build a new case statement.
624 ///
625 /// By default, performs semantic analysis to build the new statement.
626 /// Subclasses may override this routine to provide different behavior.
627 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
628 ExprArg LHS,
629 SourceLocation EllipsisLoc,
630 ExprArg RHS,
631 SourceLocation ColonLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000632 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregor43959a92009-08-20 07:17:43 +0000633 ColonLoc);
634 }
Mike Stump1eb44332009-09-09 15:08:12 +0000635
Douglas Gregor43959a92009-08-20 07:17:43 +0000636 /// \brief Attach the body to a new case statement.
637 ///
638 /// By default, performs semantic analysis to build the new statement.
639 /// Subclasses may override this routine to provide different behavior.
640 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
641 getSema().ActOnCaseStmtBody(S.get(), move(Body));
642 return move(S);
643 }
Mike Stump1eb44332009-09-09 15:08:12 +0000644
Douglas Gregor43959a92009-08-20 07:17:43 +0000645 /// \brief Build a new default statement.
646 ///
647 /// By default, performs semantic analysis to build the new statement.
648 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000649 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000650 SourceLocation ColonLoc,
651 StmtArg SubStmt) {
Mike Stump1eb44332009-09-09 15:08:12 +0000652 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregor43959a92009-08-20 07:17:43 +0000653 /*CurScope=*/0);
654 }
Mike Stump1eb44332009-09-09 15:08:12 +0000655
Douglas Gregor43959a92009-08-20 07:17:43 +0000656 /// \brief Build a new label statement.
657 ///
658 /// By default, performs semantic analysis to build the new statement.
659 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000660 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000661 IdentifierInfo *Id,
662 SourceLocation ColonLoc,
663 StmtArg SubStmt) {
664 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
665 }
Mike Stump1eb44332009-09-09 15:08:12 +0000666
Douglas Gregor43959a92009-08-20 07:17:43 +0000667 /// \brief Build a new "if" statement.
668 ///
669 /// By default, performs semantic analysis to build the new statement.
670 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000671 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000672 VarDecl *CondVar, StmtArg Then,
673 SourceLocation ElseLoc, StmtArg Else) {
674 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
675 move(Then), ElseLoc, move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +0000676 }
Mike Stump1eb44332009-09-09 15:08:12 +0000677
Douglas Gregor43959a92009-08-20 07:17:43 +0000678 /// \brief Start building a new switch statement.
679 ///
680 /// By default, performs semantic analysis to build the new statement.
681 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000682 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
683 VarDecl *CondVar) {
684 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregor43959a92009-08-20 07:17:43 +0000685 }
Mike Stump1eb44332009-09-09 15:08:12 +0000686
Douglas Gregor43959a92009-08-20 07:17:43 +0000687 /// \brief Attach the body to the switch statement.
688 ///
689 /// By default, performs semantic analysis to build the new statement.
690 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000691 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000692 StmtArg Switch, StmtArg Body) {
693 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
694 move(Body));
695 }
696
697 /// \brief Build a new while statement.
698 ///
699 /// By default, performs semantic analysis to build the new statement.
700 /// Subclasses may override this routine to provide different behavior.
701 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
702 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000703 VarDecl *CondVar,
Douglas Gregor43959a92009-08-20 07:17:43 +0000704 StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000705 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
706 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000707 }
Mike Stump1eb44332009-09-09 15:08:12 +0000708
Douglas Gregor43959a92009-08-20 07:17:43 +0000709 /// \brief Build a new do-while statement.
710 ///
711 /// By default, performs semantic analysis to build the new statement.
712 /// Subclasses may override this routine to provide different behavior.
713 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
714 SourceLocation WhileLoc,
715 SourceLocation LParenLoc,
716 ExprArg Cond,
717 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000718 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000719 move(Cond), RParenLoc);
720 }
721
722 /// \brief Build a new for statement.
723 ///
724 /// By default, performs semantic analysis to build the new statement.
725 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000726 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000727 SourceLocation LParenLoc,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000728 StmtArg Init, Sema::FullExprArg Cond,
729 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000730 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000731 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
732 DeclPtrTy::make(CondVar),
733 Inc, RParenLoc, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000734 }
Mike Stump1eb44332009-09-09 15:08:12 +0000735
Douglas Gregor43959a92009-08-20 07:17:43 +0000736 /// \brief Build a new goto statement.
737 ///
738 /// By default, performs semantic analysis to build the new statement.
739 /// Subclasses may override this routine to provide different behavior.
740 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
741 SourceLocation LabelLoc,
742 LabelStmt *Label) {
743 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
744 }
745
746 /// \brief Build a new indirect goto statement.
747 ///
748 /// By default, performs semantic analysis to build the new statement.
749 /// Subclasses may override this routine to provide different behavior.
750 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
751 SourceLocation StarLoc,
752 ExprArg Target) {
753 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
754 }
Mike Stump1eb44332009-09-09 15:08:12 +0000755
Douglas Gregor43959a92009-08-20 07:17:43 +0000756 /// \brief Build a new return statement.
757 ///
758 /// By default, performs semantic analysis to build the new statement.
759 /// Subclasses may override this routine to provide different behavior.
760 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
761 ExprArg Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000762
Douglas Gregor43959a92009-08-20 07:17:43 +0000763 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
764 }
Mike Stump1eb44332009-09-09 15:08:12 +0000765
Douglas Gregor43959a92009-08-20 07:17:43 +0000766 /// \brief Build a new declaration statement.
767 ///
768 /// By default, performs semantic analysis to build the new statement.
769 /// Subclasses may override this routine to provide different behavior.
770 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000771 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000772 SourceLocation EndLoc) {
773 return getSema().Owned(
774 new (getSema().Context) DeclStmt(
775 DeclGroupRef::Create(getSema().Context,
776 Decls, NumDecls),
777 StartLoc, EndLoc));
778 }
Mike Stump1eb44332009-09-09 15:08:12 +0000779
Anders Carlsson703e3942010-01-24 05:50:09 +0000780 /// \brief Build a new inline asm statement.
781 ///
782 /// By default, performs semantic analysis to build the new statement.
783 /// Subclasses may override this routine to provide different behavior.
784 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
785 bool IsSimple,
786 bool IsVolatile,
787 unsigned NumOutputs,
788 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000789 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000790 MultiExprArg Constraints,
791 MultiExprArg Exprs,
792 ExprArg AsmString,
793 MultiExprArg Clobbers,
794 SourceLocation RParenLoc,
795 bool MSAsm) {
796 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
797 NumInputs, Names, move(Constraints),
798 move(Exprs), move(AsmString), move(Clobbers),
799 RParenLoc, MSAsm);
800 }
801
Douglas Gregor43959a92009-08-20 07:17:43 +0000802 /// \brief Build a new C++ exception declaration.
803 ///
804 /// By default, performs semantic analysis to build the new decaration.
805 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000806 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000807 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000808 IdentifierInfo *Name,
809 SourceLocation Loc,
810 SourceRange TypeRange) {
Mike Stump1eb44332009-09-09 15:08:12 +0000811 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000812 TypeRange);
813 }
814
815 /// \brief Build a new C++ catch statement.
816 ///
817 /// By default, performs semantic analysis to build the new statement.
818 /// Subclasses may override this routine to provide different behavior.
819 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
820 VarDecl *ExceptionDecl,
821 StmtArg Handler) {
822 return getSema().Owned(
Mike Stump1eb44332009-09-09 15:08:12 +0000823 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregor43959a92009-08-20 07:17:43 +0000824 Handler.takeAs<Stmt>()));
825 }
Mike Stump1eb44332009-09-09 15:08:12 +0000826
Douglas Gregor43959a92009-08-20 07:17:43 +0000827 /// \brief Build a new C++ try statement.
828 ///
829 /// By default, performs semantic analysis to build the new statement.
830 /// Subclasses may override this routine to provide different behavior.
831 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
832 StmtArg TryBlock,
833 MultiStmtArg Handlers) {
834 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
835 }
Mike Stump1eb44332009-09-09 15:08:12 +0000836
Douglas Gregorb98b1992009-08-11 05:31:07 +0000837 /// \brief Build a new expression that references a declaration.
838 ///
839 /// By default, performs semantic analysis to build the new expression.
840 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +0000841 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
842 LookupResult &R,
843 bool RequiresADL) {
844 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
845 }
846
847
848 /// \brief Build a new expression that references a declaration.
849 ///
850 /// By default, performs semantic analysis to build the new expression.
851 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora2813ce2009-10-23 18:54:35 +0000852 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
853 SourceRange QualifierRange,
John McCalldbd872f2009-12-08 09:08:17 +0000854 ValueDecl *VD, SourceLocation Loc,
855 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +0000856 CXXScopeSpec SS;
857 SS.setScopeRep(Qualifier);
858 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +0000859
860 // FIXME: loses template args.
861
862 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000863 }
Mike Stump1eb44332009-09-09 15:08:12 +0000864
Douglas Gregorb98b1992009-08-11 05:31:07 +0000865 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +0000866 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000867 /// By default, performs semantic analysis to build the new expression.
868 /// Subclasses may override this routine to provide different behavior.
869 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
870 SourceLocation RParen) {
871 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
872 }
873
Douglas Gregora71d8192009-09-04 17:36:40 +0000874 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000875 ///
Douglas Gregora71d8192009-09-04 17:36:40 +0000876 /// By default, performs semantic analysis to build the new expression.
877 /// Subclasses may override this routine to provide different behavior.
878 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
879 SourceLocation OperatorLoc,
880 bool isArrow,
881 SourceLocation DestroyedTypeLoc,
882 QualType DestroyedType,
883 NestedNameSpecifier *Qualifier,
884 SourceRange QualifierRange) {
885 CXXScopeSpec SS;
886 if (Qualifier) {
887 SS.setRange(QualifierRange);
888 SS.setScopeRep(Qualifier);
889 }
890
John McCallaa81e162009-12-01 22:10:20 +0000891 QualType BaseType = ((Expr*) Base.get())->getType();
892
Mike Stump1eb44332009-09-09 15:08:12 +0000893 DeclarationName Name
Douglas Gregora71d8192009-09-04 17:36:40 +0000894 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
895 SemaRef.Context.getCanonicalType(DestroyedType));
Mike Stump1eb44332009-09-09 15:08:12 +0000896
John McCallaa81e162009-12-01 22:10:20 +0000897 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
898 OperatorLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +0000899 SS, /*FIXME: FirstQualifier*/ 0,
900 Name, DestroyedTypeLoc,
901 /*TemplateArgs*/ 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000902 }
903
Douglas Gregorb98b1992009-08-11 05:31:07 +0000904 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000905 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000906 /// By default, performs semantic analysis to build the new expression.
907 /// Subclasses may override this routine to provide different behavior.
908 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
909 UnaryOperator::Opcode Opc,
910 ExprArg SubExpr) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +0000911 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +0000912 }
Mike Stump1eb44332009-09-09 15:08:12 +0000913
Douglas Gregorb98b1992009-08-11 05:31:07 +0000914 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +0000915 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000916 /// By default, performs semantic analysis to build the new expression.
917 /// Subclasses may override this routine to provide different behavior.
John McCalla93c9342009-12-07 02:54:59 +0000918 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +0000919 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000920 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +0000921 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000922 }
923
Mike Stump1eb44332009-09-09 15:08:12 +0000924 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +0000925 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +0000926 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000927 /// By default, performs semantic analysis to build the new expression.
928 /// Subclasses may override this routine to provide different behavior.
929 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
930 bool isSizeOf, SourceRange R) {
Mike Stump1eb44332009-09-09 15:08:12 +0000931 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +0000932 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
933 OpLoc, isSizeOf, R);
934 if (Result.isInvalid())
935 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +0000936
Douglas Gregorb98b1992009-08-11 05:31:07 +0000937 SubExpr.release();
938 return move(Result);
939 }
Mike Stump1eb44332009-09-09 15:08:12 +0000940
Douglas Gregorb98b1992009-08-11 05:31:07 +0000941 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000942 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000943 /// By default, performs semantic analysis to build the new expression.
944 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000945 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000946 SourceLocation LBracketLoc,
947 ExprArg RHS,
948 SourceLocation RBracketLoc) {
949 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump1eb44332009-09-09 15:08:12 +0000950 LBracketLoc, move(RHS),
Douglas Gregorb98b1992009-08-11 05:31:07 +0000951 RBracketLoc);
952 }
953
954 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000955 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000956 /// By default, performs semantic analysis to build the new expression.
957 /// Subclasses may override this routine to provide different behavior.
958 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
959 MultiExprArg Args,
960 SourceLocation *CommaLocs,
961 SourceLocation RParenLoc) {
962 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
963 move(Args), CommaLocs, RParenLoc);
964 }
965
966 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000967 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000968 /// By default, performs semantic analysis to build the new expression.
969 /// Subclasses may override this routine to provide different behavior.
970 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +0000971 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000972 NestedNameSpecifier *Qualifier,
973 SourceRange QualifierRange,
974 SourceLocation MemberLoc,
Eli Friedmanf595cc42009-12-04 06:40:45 +0000975 ValueDecl *Member,
John McCalld5532b62009-11-23 01:53:49 +0000976 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +0000977 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +0000978 if (!Member->getDeclName()) {
979 // We have a reference to an unnamed field.
980 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +0000981
Douglas Gregor83a56c42009-12-24 20:02:50 +0000982 Expr *BaseExpr = Base.takeAs<Expr>();
983 if (getSema().PerformObjectMemberConversion(BaseExpr, Member))
984 return getSema().ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +0000985
Mike Stump1eb44332009-09-09 15:08:12 +0000986 MemberExpr *ME =
Douglas Gregor83a56c42009-12-24 20:02:50 +0000987 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlssond8b285f2009-09-01 04:26:58 +0000988 Member, MemberLoc,
989 cast<FieldDecl>(Member)->getType());
990 return getSema().Owned(ME);
991 }
Mike Stump1eb44332009-09-09 15:08:12 +0000992
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000993 CXXScopeSpec SS;
994 if (Qualifier) {
995 SS.setRange(QualifierRange);
996 SS.setScopeRep(Qualifier);
997 }
998
John McCallaa81e162009-12-01 22:10:20 +0000999 QualType BaseType = ((Expr*) Base.get())->getType();
1000
John McCallc2233c52010-01-15 08:34:02 +00001001 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1002 Sema::LookupMemberName);
1003 R.addDecl(Member);
1004 R.resolveKind();
1005
John McCallaa81e162009-12-01 22:10:20 +00001006 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1007 OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001008 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001009 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001010 }
Mike Stump1eb44332009-09-09 15:08:12 +00001011
Douglas Gregorb98b1992009-08-11 05:31:07 +00001012 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001013 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001014 /// By default, performs semantic analysis to build the new expression.
1015 /// Subclasses may override this routine to provide different behavior.
1016 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1017 BinaryOperator::Opcode Opc,
1018 ExprArg LHS, ExprArg RHS) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001019 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1020 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregorb98b1992009-08-11 05:31:07 +00001021 }
1022
1023 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001024 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001025 /// By default, performs semantic analysis to build the new expression.
1026 /// Subclasses may override this routine to provide different behavior.
1027 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1028 SourceLocation QuestionLoc,
1029 ExprArg LHS,
1030 SourceLocation ColonLoc,
1031 ExprArg RHS) {
Mike Stump1eb44332009-09-09 15:08:12 +00001032 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001033 move(LHS), move(RHS));
1034 }
1035
Douglas Gregorb98b1992009-08-11 05:31:07 +00001036 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001037 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001038 /// By default, performs semantic analysis to build the new expression.
1039 /// Subclasses may override this routine to provide different behavior.
John McCall9d125032010-01-15 18:39:57 +00001040 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1041 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001042 SourceLocation RParenLoc,
1043 ExprArg SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001044 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1045 move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001046 }
Mike Stump1eb44332009-09-09 15:08:12 +00001047
Douglas Gregorb98b1992009-08-11 05:31:07 +00001048 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001049 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001050 /// By default, performs semantic analysis to build the new expression.
1051 /// Subclasses may override this routine to provide different behavior.
1052 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001053 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001054 SourceLocation RParenLoc,
1055 ExprArg Init) {
John McCall42f56b52010-01-18 19:35:47 +00001056 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1057 move(Init));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001058 }
Mike Stump1eb44332009-09-09 15:08:12 +00001059
Douglas Gregorb98b1992009-08-11 05:31:07 +00001060 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001061 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001062 /// By default, performs semantic analysis to build the new expression.
1063 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001064 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001065 SourceLocation OpLoc,
1066 SourceLocation AccessorLoc,
1067 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001068
John McCall129e2df2009-11-30 22:42:35 +00001069 CXXScopeSpec SS;
John McCallaa81e162009-12-01 22:10:20 +00001070 QualType BaseType = ((Expr*) Base.get())->getType();
1071 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001072 OpLoc, /*IsArrow*/ false,
1073 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor2d1c2142009-11-03 19:44:04 +00001074 DeclarationName(&Accessor),
John McCall129e2df2009-11-30 22:42:35 +00001075 AccessorLoc,
1076 /* TemplateArgs */ 0);
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 initializer list 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 RebuildInitList(SourceLocation LBraceLoc,
1084 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001085 SourceLocation RBraceLoc,
1086 QualType ResultTy) {
1087 OwningExprResult Result
1088 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1089 if (Result.isInvalid() || ResultTy->isDependentType())
1090 return move(Result);
1091
1092 // Patch in the result type we were given, which may have been computed
1093 // when the initial InitListExpr was built.
1094 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1095 ILE->setType(ResultTy);
1096 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001097 }
Mike Stump1eb44332009-09-09 15:08:12 +00001098
Douglas Gregorb98b1992009-08-11 05:31:07 +00001099 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001100 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001101 /// By default, performs semantic analysis to build the new expression.
1102 /// Subclasses may override this routine to provide different behavior.
1103 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1104 MultiExprArg ArrayExprs,
1105 SourceLocation EqualOrColonLoc,
1106 bool GNUSyntax,
1107 ExprArg Init) {
1108 OwningExprResult Result
1109 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1110 move(Init));
1111 if (Result.isInvalid())
1112 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001113
Douglas Gregorb98b1992009-08-11 05:31:07 +00001114 ArrayExprs.release();
1115 return move(Result);
1116 }
Mike Stump1eb44332009-09-09 15:08:12 +00001117
Douglas Gregorb98b1992009-08-11 05:31:07 +00001118 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001119 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001120 /// By default, builds the implicit value initialization without performing
1121 /// any semantic analysis. Subclasses may override this routine to provide
1122 /// different behavior.
1123 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1124 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1125 }
Mike Stump1eb44332009-09-09 15:08:12 +00001126
Douglas Gregorb98b1992009-08-11 05:31:07 +00001127 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001128 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001129 /// By default, performs semantic analysis to build the new expression.
1130 /// Subclasses may override this routine to provide different behavior.
1131 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1132 QualType T, SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001133 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001134 RParenLoc);
1135 }
1136
1137 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001138 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001139 /// By default, performs semantic analysis to build the new expression.
1140 /// Subclasses may override this routine to provide different behavior.
1141 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1142 MultiExprArg SubExprs,
1143 SourceLocation RParenLoc) {
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001144 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1145 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001146 }
Mike Stump1eb44332009-09-09 15:08:12 +00001147
Douglas Gregorb98b1992009-08-11 05:31:07 +00001148 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001149 ///
1150 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001151 /// rather than attempting to map the label statement itself.
1152 /// Subclasses may override this routine to provide different behavior.
1153 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1154 SourceLocation LabelLoc,
1155 LabelStmt *Label) {
1156 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1157 }
Mike Stump1eb44332009-09-09 15:08:12 +00001158
Douglas Gregorb98b1992009-08-11 05:31:07 +00001159 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001160 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001161 /// By default, performs semantic analysis to build the new expression.
1162 /// Subclasses may override this routine to provide different behavior.
1163 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1164 StmtArg SubStmt,
1165 SourceLocation RParenLoc) {
1166 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1167 }
Mike Stump1eb44332009-09-09 15:08:12 +00001168
Douglas Gregorb98b1992009-08-11 05:31:07 +00001169 /// \brief Build a new __builtin_types_compatible_p expression.
1170 ///
1171 /// By default, performs semantic analysis to build the new expression.
1172 /// Subclasses may override this routine to provide different behavior.
1173 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1174 QualType T1, QualType T2,
1175 SourceLocation RParenLoc) {
1176 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1177 T1.getAsOpaquePtr(),
1178 T2.getAsOpaquePtr(),
1179 RParenLoc);
1180 }
Mike Stump1eb44332009-09-09 15:08:12 +00001181
Douglas Gregorb98b1992009-08-11 05:31:07 +00001182 /// \brief Build a new __builtin_choose_expr expression.
1183 ///
1184 /// By default, performs semantic analysis to build the new expression.
1185 /// Subclasses may override this routine to provide different behavior.
1186 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1187 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1188 SourceLocation RParenLoc) {
1189 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1190 move(Cond), move(LHS), move(RHS),
1191 RParenLoc);
1192 }
Mike Stump1eb44332009-09-09 15:08:12 +00001193
Douglas Gregorb98b1992009-08-11 05:31:07 +00001194 /// \brief Build a new overloaded operator call expression.
1195 ///
1196 /// By default, performs semantic analysis to build the new expression.
1197 /// The semantic analysis provides the behavior of template instantiation,
1198 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001199 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001200 /// argument-dependent lookup, etc. Subclasses may override this routine to
1201 /// provide different behavior.
1202 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1203 SourceLocation OpLoc,
1204 ExprArg Callee,
1205 ExprArg First,
1206 ExprArg Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001207
1208 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001209 /// reinterpret_cast.
1210 ///
1211 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001212 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001213 /// Subclasses may override this routine to provide different behavior.
1214 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1215 Stmt::StmtClass Class,
1216 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001217 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001218 SourceLocation RAngleLoc,
1219 SourceLocation LParenLoc,
1220 ExprArg SubExpr,
1221 SourceLocation RParenLoc) {
1222 switch (Class) {
1223 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001224 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001225 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001226 move(SubExpr), RParenLoc);
1227
1228 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001229 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001230 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001231 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001232
Douglas Gregorb98b1992009-08-11 05:31:07 +00001233 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001234 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001235 RAngleLoc, LParenLoc,
1236 move(SubExpr),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001237 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001238
Douglas Gregorb98b1992009-08-11 05:31:07 +00001239 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001240 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001241 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001242 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001243
Douglas Gregorb98b1992009-08-11 05:31:07 +00001244 default:
1245 assert(false && "Invalid C++ named cast");
1246 break;
1247 }
Mike Stump1eb44332009-09-09 15:08:12 +00001248
Douglas Gregorb98b1992009-08-11 05:31:07 +00001249 return getSema().ExprError();
1250 }
Mike Stump1eb44332009-09-09 15:08:12 +00001251
Douglas Gregorb98b1992009-08-11 05:31:07 +00001252 /// \brief Build a new C++ static_cast expression.
1253 ///
1254 /// By default, performs semantic analysis to build the new expression.
1255 /// Subclasses may override this routine to provide different behavior.
1256 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1257 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001258 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001259 SourceLocation RAngleLoc,
1260 SourceLocation LParenLoc,
1261 ExprArg SubExpr,
1262 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001263 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1264 TInfo, move(SubExpr),
1265 SourceRange(LAngleLoc, RAngleLoc),
1266 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001267 }
1268
1269 /// \brief Build a new C++ dynamic_cast expression.
1270 ///
1271 /// By default, performs semantic analysis to build the new expression.
1272 /// Subclasses may override this routine to provide different behavior.
1273 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1274 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001275 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001276 SourceLocation RAngleLoc,
1277 SourceLocation LParenLoc,
1278 ExprArg SubExpr,
1279 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001280 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1281 TInfo, move(SubExpr),
1282 SourceRange(LAngleLoc, RAngleLoc),
1283 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001284 }
1285
1286 /// \brief Build a new C++ reinterpret_cast expression.
1287 ///
1288 /// By default, performs semantic analysis to build the new expression.
1289 /// Subclasses may override this routine to provide different behavior.
1290 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1291 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001292 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001293 SourceLocation RAngleLoc,
1294 SourceLocation LParenLoc,
1295 ExprArg SubExpr,
1296 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001297 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1298 TInfo, move(SubExpr),
1299 SourceRange(LAngleLoc, RAngleLoc),
1300 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001301 }
1302
1303 /// \brief Build a new C++ const_cast expression.
1304 ///
1305 /// By default, performs semantic analysis to build the new expression.
1306 /// Subclasses may override this routine to provide different behavior.
1307 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1308 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001309 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001310 SourceLocation RAngleLoc,
1311 SourceLocation LParenLoc,
1312 ExprArg SubExpr,
1313 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001314 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1315 TInfo, move(SubExpr),
1316 SourceRange(LAngleLoc, RAngleLoc),
1317 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001318 }
Mike Stump1eb44332009-09-09 15:08:12 +00001319
Douglas Gregorb98b1992009-08-11 05:31:07 +00001320 /// \brief Build a new C++ functional-style cast expression.
1321 ///
1322 /// By default, performs semantic analysis to build the new expression.
1323 /// Subclasses may override this routine to provide different behavior.
1324 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001325 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001326 SourceLocation LParenLoc,
1327 ExprArg SubExpr,
1328 SourceLocation RParenLoc) {
Chris Lattner88650c32009-08-24 05:19:01 +00001329 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001330 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001331 TInfo->getType().getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001332 LParenLoc,
Chris Lattner88650c32009-08-24 05:19:01 +00001333 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump1eb44332009-09-09 15:08:12 +00001334 /*CommaLocs=*/0,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001335 RParenLoc);
1336 }
Mike Stump1eb44332009-09-09 15:08:12 +00001337
Douglas Gregorb98b1992009-08-11 05:31:07 +00001338 /// \brief Build a new C++ typeid(type) expression.
1339 ///
1340 /// By default, performs semantic analysis to build the new expression.
1341 /// Subclasses may override this routine to provide different behavior.
1342 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1343 SourceLocation LParenLoc,
1344 QualType T,
1345 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001346 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001347 T.getAsOpaquePtr(), RParenLoc);
1348 }
Mike Stump1eb44332009-09-09 15:08:12 +00001349
Douglas Gregorb98b1992009-08-11 05:31:07 +00001350 /// \brief Build a new C++ typeid(expr) expression.
1351 ///
1352 /// By default, performs semantic analysis to build the new expression.
1353 /// Subclasses may override this routine to provide different behavior.
1354 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1355 SourceLocation LParenLoc,
1356 ExprArg Operand,
1357 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001358 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001359 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1360 RParenLoc);
1361 if (Result.isInvalid())
1362 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001363
Douglas Gregorb98b1992009-08-11 05:31:07 +00001364 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1365 return move(Result);
Mike Stump1eb44332009-09-09 15:08:12 +00001366 }
1367
Douglas Gregorb98b1992009-08-11 05:31:07 +00001368 /// \brief Build a new C++ "this" expression.
1369 ///
1370 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001371 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001372 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001373 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001374 QualType ThisType,
1375 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001376 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001377 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1378 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001379 }
1380
1381 /// \brief Build a new C++ throw expression.
1382 ///
1383 /// By default, performs semantic analysis to build the new expression.
1384 /// Subclasses may override this routine to provide different behavior.
1385 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1386 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1387 }
1388
1389 /// \brief Build a new C++ default-argument expression.
1390 ///
1391 /// By default, builds a new default-argument expression, which does not
1392 /// require any semantic analysis. Subclasses may override this routine to
1393 /// provide different behavior.
Douglas Gregor036aed12009-12-23 23:03:06 +00001394 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1395 ParmVarDecl *Param) {
1396 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1397 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001398 }
1399
1400 /// \brief Build a new C++ zero-initialization expression.
1401 ///
1402 /// By default, performs semantic analysis to build the new expression.
1403 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001404 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001405 SourceLocation LParenLoc,
1406 QualType T,
1407 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001408 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1409 T.getAsOpaquePtr(), LParenLoc,
1410 MultiExprArg(getSema(), 0, 0),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001411 0, RParenLoc);
1412 }
Mike Stump1eb44332009-09-09 15:08:12 +00001413
Douglas Gregorb98b1992009-08-11 05:31:07 +00001414 /// \brief Build a new C++ "new" expression.
1415 ///
1416 /// By default, performs semantic analysis to build the new expression.
1417 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001418 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001419 bool UseGlobal,
1420 SourceLocation PlacementLParen,
1421 MultiExprArg PlacementArgs,
1422 SourceLocation PlacementRParen,
Mike Stump1eb44332009-09-09 15:08:12 +00001423 bool ParenTypeId,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001424 QualType AllocType,
1425 SourceLocation TypeLoc,
1426 SourceRange TypeRange,
1427 ExprArg ArraySize,
1428 SourceLocation ConstructorLParen,
1429 MultiExprArg ConstructorArgs,
1430 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001431 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001432 PlacementLParen,
1433 move(PlacementArgs),
1434 PlacementRParen,
1435 ParenTypeId,
1436 AllocType,
1437 TypeLoc,
1438 TypeRange,
1439 move(ArraySize),
1440 ConstructorLParen,
1441 move(ConstructorArgs),
1442 ConstructorRParen);
1443 }
Mike Stump1eb44332009-09-09 15:08:12 +00001444
Douglas Gregorb98b1992009-08-11 05:31:07 +00001445 /// \brief Build a new C++ "delete" expression.
1446 ///
1447 /// By default, performs semantic analysis to build the new expression.
1448 /// Subclasses may override this routine to provide different behavior.
1449 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1450 bool IsGlobalDelete,
1451 bool IsArrayForm,
1452 ExprArg Operand) {
1453 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1454 move(Operand));
1455 }
Mike Stump1eb44332009-09-09 15:08:12 +00001456
Douglas Gregorb98b1992009-08-11 05:31:07 +00001457 /// \brief Build a new unary type trait expression.
1458 ///
1459 /// By default, performs semantic analysis to build the new expression.
1460 /// Subclasses may override this routine to provide different behavior.
1461 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1462 SourceLocation StartLoc,
1463 SourceLocation LParenLoc,
1464 QualType T,
1465 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001466 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001467 T.getAsOpaquePtr(), RParenLoc);
1468 }
1469
Mike Stump1eb44332009-09-09 15:08:12 +00001470 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001471 /// expression.
1472 ///
1473 /// By default, performs semantic analysis to build the new expression.
1474 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001475 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001476 SourceRange QualifierRange,
1477 DeclarationName Name,
1478 SourceLocation Location,
John McCallf7a1a742009-11-24 19:00:30 +00001479 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 CXXScopeSpec SS;
1481 SS.setRange(QualifierRange);
1482 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001483
1484 if (TemplateArgs)
1485 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1486 *TemplateArgs);
1487
1488 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489 }
1490
1491 /// \brief Build a new template-id expression.
1492 ///
1493 /// By default, performs semantic analysis to build the new expression.
1494 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001495 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1496 LookupResult &R,
1497 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001498 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001499 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001500 }
1501
1502 /// \brief Build a new object-construction expression.
1503 ///
1504 /// By default, performs semantic analysis to build the new expression.
1505 /// Subclasses may override this routine to provide different behavior.
1506 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001507 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001508 CXXConstructorDecl *Constructor,
1509 bool IsElidable,
1510 MultiExprArg Args) {
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001511 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1512 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1513 ConvertedArgs))
1514 return getSema().ExprError();
1515
1516 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1517 move_arg(ConvertedArgs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 }
1519
1520 /// \brief Build a new object-construction expression.
1521 ///
1522 /// By default, performs semantic analysis to build the new expression.
1523 /// Subclasses may override this routine to provide different behavior.
1524 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1525 QualType T,
1526 SourceLocation LParenLoc,
1527 MultiExprArg Args,
1528 SourceLocation *Commas,
1529 SourceLocation RParenLoc) {
1530 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1531 T.getAsOpaquePtr(),
1532 LParenLoc,
1533 move(Args),
1534 Commas,
1535 RParenLoc);
1536 }
1537
1538 /// \brief Build a new object-construction expression.
1539 ///
1540 /// By default, performs semantic analysis to build the new expression.
1541 /// Subclasses may override this routine to provide different behavior.
1542 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1543 QualType T,
1544 SourceLocation LParenLoc,
1545 MultiExprArg Args,
1546 SourceLocation *Commas,
1547 SourceLocation RParenLoc) {
1548 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1549 /*FIXME*/LParenLoc),
1550 T.getAsOpaquePtr(),
1551 LParenLoc,
1552 move(Args),
1553 Commas,
1554 RParenLoc);
1555 }
Mike Stump1eb44332009-09-09 15:08:12 +00001556
Douglas Gregorb98b1992009-08-11 05:31:07 +00001557 /// \brief Build a new member reference expression.
1558 ///
1559 /// By default, performs semantic analysis to build the new expression.
1560 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001561 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001562 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 bool IsArrow,
1564 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001565 NestedNameSpecifier *Qualifier,
1566 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001567 NamedDecl *FirstQualifierInScope,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001568 DeclarationName Name,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001569 SourceLocation MemberLoc,
John McCall129e2df2009-11-30 22:42:35 +00001570 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001572 SS.setRange(QualifierRange);
1573 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001574
John McCallaa81e162009-12-01 22:10:20 +00001575 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1576 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001577 SS, FirstQualifierInScope,
1578 Name, MemberLoc, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001579 }
1580
John McCall129e2df2009-11-30 22:42:35 +00001581 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001582 ///
1583 /// By default, performs semantic analysis to build the new expression.
1584 /// Subclasses may override this routine to provide different behavior.
John McCall129e2df2009-11-30 22:42:35 +00001585 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001586 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001587 SourceLocation OperatorLoc,
1588 bool IsArrow,
1589 NestedNameSpecifier *Qualifier,
1590 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001591 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001592 LookupResult &R,
1593 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001594 CXXScopeSpec SS;
1595 SS.setRange(QualifierRange);
1596 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001597
John McCallaa81e162009-12-01 22:10:20 +00001598 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1599 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001600 SS, FirstQualifierInScope,
1601 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001602 }
Mike Stump1eb44332009-09-09 15:08:12 +00001603
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 /// \brief Build a new Objective-C @encode expression.
1605 ///
1606 /// By default, performs semantic analysis to build the new expression.
1607 /// Subclasses may override this routine to provide different behavior.
1608 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1609 QualType T,
1610 SourceLocation RParenLoc) {
1611 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1612 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001613 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614
1615 /// \brief Build a new Objective-C protocol expression.
1616 ///
1617 /// By default, performs semantic analysis to build the new expression.
1618 /// Subclasses may override this routine to provide different behavior.
1619 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1620 SourceLocation AtLoc,
1621 SourceLocation ProtoLoc,
1622 SourceLocation LParenLoc,
1623 SourceLocation RParenLoc) {
1624 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1625 Protocol->getIdentifier(),
1626 AtLoc,
1627 ProtoLoc,
1628 LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001629 RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001630 }
Mike Stump1eb44332009-09-09 15:08:12 +00001631
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 /// \brief Build a new shuffle vector expression.
1633 ///
1634 /// By default, performs semantic analysis to build the new expression.
1635 /// Subclasses may override this routine to provide different behavior.
1636 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1637 MultiExprArg SubExprs,
1638 SourceLocation RParenLoc) {
1639 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001640 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001641 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1642 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1643 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1644 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001645
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 // Build a reference to the __builtin_shufflevector builtin
1647 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001648 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001649 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001650 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001651 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001652
1653 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001654 unsigned NumSubExprs = SubExprs.size();
1655 Expr **Subs = (Expr **)SubExprs.release();
1656 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1657 Subs, NumSubExprs,
1658 Builtin->getResultType(),
1659 RParenLoc);
1660 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001661
Douglas Gregorb98b1992009-08-11 05:31:07 +00001662 // Type-check the __builtin_shufflevector expression.
1663 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1664 if (Result.isInvalid())
1665 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001666
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001668 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001670};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671
Douglas Gregor43959a92009-08-20 07:17:43 +00001672template<typename Derived>
1673Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1674 if (!S)
1675 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001676
Douglas Gregor43959a92009-08-20 07:17:43 +00001677 switch (S->getStmtClass()) {
1678 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001679
Douglas Gregor43959a92009-08-20 07:17:43 +00001680 // Transform individual statement nodes
1681#define STMT(Node, Parent) \
1682 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1683#define EXPR(Node, Parent)
1684#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001685
Douglas Gregor43959a92009-08-20 07:17:43 +00001686 // Transform expressions by calling TransformExpr.
1687#define STMT(Node, Parent)
John McCall09cc1412010-02-03 00:55:45 +00001688#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregor43959a92009-08-20 07:17:43 +00001689#define EXPR(Node, Parent) case Stmt::Node##Class:
1690#include "clang/AST/StmtNodes.def"
1691 {
1692 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1693 if (E.isInvalid())
1694 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001695
Anders Carlsson5ee56e92009-12-16 02:09:40 +00001696 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregor43959a92009-08-20 07:17:43 +00001697 }
Mike Stump1eb44332009-09-09 15:08:12 +00001698 }
1699
Douglas Gregor43959a92009-08-20 07:17:43 +00001700 return SemaRef.Owned(S->Retain());
1701}
Mike Stump1eb44332009-09-09 15:08:12 +00001702
1703
Douglas Gregor670444e2009-08-04 22:27:00 +00001704template<typename Derived>
John McCall454feb92009-12-08 09:21:05 +00001705Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001706 if (!E)
1707 return SemaRef.Owned(E);
1708
1709 switch (E->getStmtClass()) {
1710 case Stmt::NoStmtClass: break;
1711#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall09cc1412010-02-03 00:55:45 +00001712#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00001714 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001715#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001716 }
1717
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00001719}
1720
1721template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00001722NestedNameSpecifier *
1723TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00001724 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001725 QualType ObjectType,
1726 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00001727 if (!NNS)
1728 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001729
Douglas Gregor43959a92009-08-20 07:17:43 +00001730 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00001731 NestedNameSpecifier *Prefix = NNS->getPrefix();
1732 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00001733 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001734 ObjectType,
1735 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00001736 if (!Prefix)
1737 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001738
1739 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00001740 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00001741 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00001742 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001743 }
Mike Stump1eb44332009-09-09 15:08:12 +00001744
Douglas Gregordcee1a12009-08-06 05:28:30 +00001745 switch (NNS->getKind()) {
1746 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00001747 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00001748 "Identifier nested-name-specifier with no prefix or object type");
1749 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1750 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00001751 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001752
1753 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00001754 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00001755 ObjectType,
1756 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001757
Douglas Gregordcee1a12009-08-06 05:28:30 +00001758 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00001759 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00001760 = cast_or_null<NamespaceDecl>(
1761 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00001762 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00001763 Prefix == NNS->getPrefix() &&
1764 NS == NNS->getAsNamespace())
1765 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001766
Douglas Gregordcee1a12009-08-06 05:28:30 +00001767 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1768 }
Mike Stump1eb44332009-09-09 15:08:12 +00001769
Douglas Gregordcee1a12009-08-06 05:28:30 +00001770 case NestedNameSpecifier::Global:
1771 // There is no meaningful transformation that one could perform on the
1772 // global scope.
1773 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001774
Douglas Gregordcee1a12009-08-06 05:28:30 +00001775 case NestedNameSpecifier::TypeSpecWithTemplate:
1776 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00001777 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregordcee1a12009-08-06 05:28:30 +00001778 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregord1067e52009-08-06 06:41:21 +00001779 if (T.isNull())
1780 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001781
Douglas Gregordcee1a12009-08-06 05:28:30 +00001782 if (!getDerived().AlwaysRebuild() &&
1783 Prefix == NNS->getPrefix() &&
1784 T == QualType(NNS->getAsType(), 0))
1785 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001786
1787 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1788 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregordcee1a12009-08-06 05:28:30 +00001789 T);
1790 }
1791 }
Mike Stump1eb44332009-09-09 15:08:12 +00001792
Douglas Gregordcee1a12009-08-06 05:28:30 +00001793 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00001794 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001795}
1796
1797template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001798DeclarationName
Douglas Gregor81499bb2009-09-03 22:13:48 +00001799TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +00001800 SourceLocation Loc,
1801 QualType ObjectType) {
Douglas Gregor81499bb2009-09-03 22:13:48 +00001802 if (!Name)
1803 return Name;
1804
1805 switch (Name.getNameKind()) {
1806 case DeclarationName::Identifier:
1807 case DeclarationName::ObjCZeroArgSelector:
1808 case DeclarationName::ObjCOneArgSelector:
1809 case DeclarationName::ObjCMultiArgSelector:
1810 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00001811 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00001812 case DeclarationName::CXXUsingDirective:
1813 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001814
Douglas Gregor81499bb2009-09-03 22:13:48 +00001815 case DeclarationName::CXXConstructorName:
1816 case DeclarationName::CXXDestructorName:
1817 case DeclarationName::CXXConversionFunctionName: {
1818 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregordd62b152009-10-19 22:04:39 +00001819 QualType T;
1820 if (!ObjectType.isNull() &&
1821 isa<TemplateSpecializationType>(Name.getCXXNameType())) {
1822 TemplateSpecializationType *SpecType
1823 = cast<TemplateSpecializationType>(Name.getCXXNameType());
1824 T = TransformTemplateSpecializationType(SpecType, ObjectType);
1825 } else
1826 T = getDerived().TransformType(Name.getCXXNameType());
Douglas Gregor81499bb2009-09-03 22:13:48 +00001827 if (T.isNull())
1828 return DeclarationName();
Mike Stump1eb44332009-09-09 15:08:12 +00001829
Douglas Gregor81499bb2009-09-03 22:13:48 +00001830 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump1eb44332009-09-09 15:08:12 +00001831 Name.getNameKind(),
Douglas Gregor81499bb2009-09-03 22:13:48 +00001832 SemaRef.Context.getCanonicalType(T));
Douglas Gregor81499bb2009-09-03 22:13:48 +00001833 }
Mike Stump1eb44332009-09-09 15:08:12 +00001834 }
1835
Douglas Gregor81499bb2009-09-03 22:13:48 +00001836 return DeclarationName();
1837}
1838
1839template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001840TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001841TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1842 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00001843 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001844 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00001845 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1846 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1847 if (!NNS)
1848 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001849
Douglas Gregord1067e52009-08-06 06:41:21 +00001850 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001851 TemplateDecl *TransTemplate
Douglas Gregord1067e52009-08-06 06:41:21 +00001852 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1853 if (!TransTemplate)
1854 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001855
Douglas Gregord1067e52009-08-06 06:41:21 +00001856 if (!getDerived().AlwaysRebuild() &&
1857 NNS == QTN->getQualifier() &&
1858 TransTemplate == Template)
1859 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001860
Douglas Gregord1067e52009-08-06 06:41:21 +00001861 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1862 TransTemplate);
1863 }
Mike Stump1eb44332009-09-09 15:08:12 +00001864
John McCallf7a1a742009-11-24 19:00:30 +00001865 // These should be getting filtered out before they make it into the AST.
1866 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00001867 }
Mike Stump1eb44332009-09-09 15:08:12 +00001868
Douglas Gregord1067e52009-08-06 06:41:21 +00001869 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001870 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00001871 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1872 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001873 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00001874 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001875
Douglas Gregord1067e52009-08-06 06:41:21 +00001876 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00001877 NNS == DTN->getQualifier() &&
1878 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00001879 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001880
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001881 if (DTN->isIdentifier())
1882 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1883 ObjectType);
1884
1885 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1886 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00001887 }
Mike Stump1eb44332009-09-09 15:08:12 +00001888
Douglas Gregord1067e52009-08-06 06:41:21 +00001889 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001890 TemplateDecl *TransTemplate
Douglas Gregord1067e52009-08-06 06:41:21 +00001891 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1892 if (!TransTemplate)
1893 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001894
Douglas Gregord1067e52009-08-06 06:41:21 +00001895 if (!getDerived().AlwaysRebuild() &&
1896 TransTemplate == Template)
1897 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001898
Douglas Gregord1067e52009-08-06 06:41:21 +00001899 return TemplateName(TransTemplate);
1900 }
Mike Stump1eb44332009-09-09 15:08:12 +00001901
John McCallf7a1a742009-11-24 19:00:30 +00001902 // These should be getting filtered out before they reach the AST.
1903 assert(false && "overloaded function decl survived to here");
1904 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00001905}
1906
1907template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00001908void TreeTransform<Derived>::InventTemplateArgumentLoc(
1909 const TemplateArgument &Arg,
1910 TemplateArgumentLoc &Output) {
1911 SourceLocation Loc = getDerived().getBaseLocation();
1912 switch (Arg.getKind()) {
1913 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00001914 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00001915 break;
1916
1917 case TemplateArgument::Type:
1918 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00001919 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall833ca992009-10-29 08:12:44 +00001920
1921 break;
1922
Douglas Gregor788cd062009-11-11 01:00:40 +00001923 case TemplateArgument::Template:
1924 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1925 break;
1926
John McCall833ca992009-10-29 08:12:44 +00001927 case TemplateArgument::Expression:
1928 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1929 break;
1930
1931 case TemplateArgument::Declaration:
1932 case TemplateArgument::Integral:
1933 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00001934 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00001935 break;
1936 }
1937}
1938
1939template<typename Derived>
1940bool TreeTransform<Derived>::TransformTemplateArgument(
1941 const TemplateArgumentLoc &Input,
1942 TemplateArgumentLoc &Output) {
1943 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00001944 switch (Arg.getKind()) {
1945 case TemplateArgument::Null:
1946 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00001947 Output = Input;
1948 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00001949
Douglas Gregor670444e2009-08-04 22:27:00 +00001950 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00001951 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00001952 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00001953 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00001954
1955 DI = getDerived().TransformType(DI);
1956 if (!DI) return true;
1957
1958 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1959 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00001960 }
Mike Stump1eb44332009-09-09 15:08:12 +00001961
Douglas Gregor670444e2009-08-04 22:27:00 +00001962 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00001963 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00001964 DeclarationName Name;
1965 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1966 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00001967 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor670444e2009-08-04 22:27:00 +00001968 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00001969 if (!D) return true;
1970
John McCall828bff22009-10-29 18:45:58 +00001971 Expr *SourceExpr = Input.getSourceDeclExpression();
1972 if (SourceExpr) {
1973 EnterExpressionEvaluationContext Unevaluated(getSema(),
1974 Action::Unevaluated);
1975 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1976 if (E.isInvalid())
1977 SourceExpr = NULL;
1978 else {
1979 SourceExpr = E.takeAs<Expr>();
1980 SourceExpr->Retain();
1981 }
1982 }
1983
1984 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00001985 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00001986 }
Mike Stump1eb44332009-09-09 15:08:12 +00001987
Douglas Gregor788cd062009-11-11 01:00:40 +00001988 case TemplateArgument::Template: {
1989 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1990 TemplateName Template
1991 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1992 if (Template.isNull())
1993 return true;
1994
1995 Output = TemplateArgumentLoc(TemplateArgument(Template),
1996 Input.getTemplateQualifierRange(),
1997 Input.getTemplateNameLoc());
1998 return false;
1999 }
2000
Douglas Gregor670444e2009-08-04 22:27:00 +00002001 case TemplateArgument::Expression: {
2002 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002003 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002004 Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002005
John McCall833ca992009-10-29 08:12:44 +00002006 Expr *InputExpr = Input.getSourceExpression();
2007 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2008
2009 Sema::OwningExprResult E
2010 = getDerived().TransformExpr(InputExpr);
2011 if (E.isInvalid()) return true;
2012
2013 Expr *ETaken = E.takeAs<Expr>();
John McCall828bff22009-10-29 18:45:58 +00002014 ETaken->Retain();
John McCall833ca992009-10-29 08:12:44 +00002015 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2016 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002017 }
Mike Stump1eb44332009-09-09 15:08:12 +00002018
Douglas Gregor670444e2009-08-04 22:27:00 +00002019 case TemplateArgument::Pack: {
2020 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2021 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002022 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002023 AEnd = Arg.pack_end();
2024 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002025
John McCall833ca992009-10-29 08:12:44 +00002026 // FIXME: preserve source information here when we start
2027 // caring about parameter packs.
2028
John McCall828bff22009-10-29 18:45:58 +00002029 TemplateArgumentLoc InputArg;
2030 TemplateArgumentLoc OutputArg;
2031 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2032 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002033 return true;
2034
John McCall828bff22009-10-29 18:45:58 +00002035 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002036 }
2037 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002038 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002039 true);
John McCall828bff22009-10-29 18:45:58 +00002040 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002041 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002042 }
2043 }
Mike Stump1eb44332009-09-09 15:08:12 +00002044
Douglas Gregor670444e2009-08-04 22:27:00 +00002045 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002046 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002047}
2048
Douglas Gregor577f75a2009-08-04 16:50:30 +00002049//===----------------------------------------------------------------------===//
2050// Type transformation
2051//===----------------------------------------------------------------------===//
2052
2053template<typename Derived>
2054QualType TreeTransform<Derived>::TransformType(QualType T) {
2055 if (getDerived().AlreadyTransformed(T))
2056 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002057
John McCalla2becad2009-10-21 00:40:46 +00002058 // Temporary workaround. All of these transformations should
2059 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002060 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002061 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCalla2becad2009-10-21 00:40:46 +00002062
John McCalla93c9342009-12-07 02:54:59 +00002063 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00002064
John McCalla2becad2009-10-21 00:40:46 +00002065 if (!NewDI)
2066 return QualType();
2067
2068 return NewDI->getType();
2069}
2070
2071template<typename Derived>
John McCalla93c9342009-12-07 02:54:59 +00002072TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00002073 if (getDerived().AlreadyTransformed(DI->getType()))
2074 return DI;
2075
2076 TypeLocBuilder TLB;
2077
2078 TypeLoc TL = DI->getTypeLoc();
2079 TLB.reserve(TL.getFullDataSize());
2080
2081 QualType Result = getDerived().TransformType(TLB, TL);
2082 if (Result.isNull())
2083 return 0;
2084
John McCalla93c9342009-12-07 02:54:59 +00002085 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002086}
2087
2088template<typename Derived>
2089QualType
2090TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
2091 switch (T.getTypeLocClass()) {
2092#define ABSTRACT_TYPELOC(CLASS, PARENT)
2093#define TYPELOC(CLASS, PARENT) \
2094 case TypeLoc::CLASS: \
2095 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2096#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002097 }
Mike Stump1eb44332009-09-09 15:08:12 +00002098
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002099 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002100 return QualType();
2101}
2102
2103/// FIXME: By default, this routine adds type qualifiers only to types
2104/// that can have qualifiers, and silently suppresses those qualifiers
2105/// that are not permitted (e.g., qualifiers on reference or function
2106/// types). This is the right thing for template instantiation, but
2107/// probably not for other clients.
2108template<typename Derived>
2109QualType
2110TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
2111 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002112 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002113
2114 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2115 if (Result.isNull())
2116 return QualType();
2117
2118 // Silently suppress qualifiers if the result type can't be qualified.
2119 // FIXME: this is the right thing for template instantiation, but
2120 // probably not for other clients.
2121 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002122 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002123
John McCalla2becad2009-10-21 00:40:46 +00002124 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2125
2126 TLB.push<QualifiedTypeLoc>(Result);
2127
2128 // No location information to preserve.
2129
2130 return Result;
2131}
2132
2133template <class TyLoc> static inline
2134QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2135 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2136 NewT.setNameLoc(T.getNameLoc());
2137 return T.getType();
2138}
2139
2140// Ugly metaprogramming macros because I couldn't be bothered to make
2141// the equivalent template version work.
2142#define TransformPointerLikeType(TypeClass) do { \
2143 QualType PointeeType \
2144 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2145 if (PointeeType.isNull()) \
2146 return QualType(); \
2147 \
2148 QualType Result = TL.getType(); \
2149 if (getDerived().AlwaysRebuild() || \
2150 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall85737a72009-10-30 00:06:24 +00002151 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2152 TL.getSigilLoc()); \
John McCalla2becad2009-10-21 00:40:46 +00002153 if (Result.isNull()) \
2154 return QualType(); \
2155 } \
2156 \
2157 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2158 NewT.setSigilLoc(TL.getSigilLoc()); \
2159 \
2160 return Result; \
2161} while(0)
2162
John McCalla2becad2009-10-21 00:40:46 +00002163template<typename Derived>
2164QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
2165 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002166 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2167 NewT.setBuiltinLoc(T.getBuiltinLoc());
2168 if (T.needsExtraLocalData())
2169 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2170 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002171}
Mike Stump1eb44332009-09-09 15:08:12 +00002172
Douglas Gregor577f75a2009-08-04 16:50:30 +00002173template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002174QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
2175 ComplexTypeLoc T) {
2176 // FIXME: recurse?
2177 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002178}
Mike Stump1eb44332009-09-09 15:08:12 +00002179
Douglas Gregor577f75a2009-08-04 16:50:30 +00002180template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002181QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
2182 PointerTypeLoc TL) {
2183 TransformPointerLikeType(PointerType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002184}
Mike Stump1eb44332009-09-09 15:08:12 +00002185
2186template<typename Derived>
2187QualType
John McCalla2becad2009-10-21 00:40:46 +00002188TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
2189 BlockPointerTypeLoc TL) {
2190 TransformPointerLikeType(BlockPointerType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002191}
2192
John McCall85737a72009-10-30 00:06:24 +00002193/// Transforms a reference type. Note that somewhat paradoxically we
2194/// don't care whether the type itself is an l-value type or an r-value
2195/// type; we only care if the type was *written* as an l-value type
2196/// or an r-value type.
2197template<typename Derived>
2198QualType
2199TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
2200 ReferenceTypeLoc TL) {
2201 const ReferenceType *T = TL.getTypePtr();
2202
2203 // Note that this works with the pointee-as-written.
2204 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2205 if (PointeeType.isNull())
2206 return QualType();
2207
2208 QualType Result = TL.getType();
2209 if (getDerived().AlwaysRebuild() ||
2210 PointeeType != T->getPointeeTypeAsWritten()) {
2211 Result = getDerived().RebuildReferenceType(PointeeType,
2212 T->isSpelledAsLValue(),
2213 TL.getSigilLoc());
2214 if (Result.isNull())
2215 return QualType();
2216 }
2217
2218 // r-value references can be rebuilt as l-value references.
2219 ReferenceTypeLoc NewTL;
2220 if (isa<LValueReferenceType>(Result))
2221 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2222 else
2223 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2224 NewTL.setSigilLoc(TL.getSigilLoc());
2225
2226 return Result;
2227}
2228
Mike Stump1eb44332009-09-09 15:08:12 +00002229template<typename Derived>
2230QualType
John McCalla2becad2009-10-21 00:40:46 +00002231TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
2232 LValueReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00002233 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002234}
2235
Mike Stump1eb44332009-09-09 15:08:12 +00002236template<typename Derived>
2237QualType
John McCalla2becad2009-10-21 00:40:46 +00002238TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
2239 RValueReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00002240 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002241}
Mike Stump1eb44332009-09-09 15:08:12 +00002242
Douglas Gregor577f75a2009-08-04 16:50:30 +00002243template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002244QualType
John McCalla2becad2009-10-21 00:40:46 +00002245TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
2246 MemberPointerTypeLoc TL) {
2247 MemberPointerType *T = TL.getTypePtr();
2248
2249 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002250 if (PointeeType.isNull())
2251 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002252
John McCalla2becad2009-10-21 00:40:46 +00002253 // TODO: preserve source information for this.
2254 QualType ClassType
2255 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002256 if (ClassType.isNull())
2257 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002258
John McCalla2becad2009-10-21 00:40:46 +00002259 QualType Result = TL.getType();
2260 if (getDerived().AlwaysRebuild() ||
2261 PointeeType != T->getPointeeType() ||
2262 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002263 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2264 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002265 if (Result.isNull())
2266 return QualType();
2267 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002268
John McCalla2becad2009-10-21 00:40:46 +00002269 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2270 NewTL.setSigilLoc(TL.getSigilLoc());
2271
2272 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002273}
2274
Mike Stump1eb44332009-09-09 15:08:12 +00002275template<typename Derived>
2276QualType
John McCalla2becad2009-10-21 00:40:46 +00002277TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
2278 ConstantArrayTypeLoc TL) {
2279 ConstantArrayType *T = TL.getTypePtr();
2280 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002281 if (ElementType.isNull())
2282 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002283
John McCalla2becad2009-10-21 00:40:46 +00002284 QualType Result = TL.getType();
2285 if (getDerived().AlwaysRebuild() ||
2286 ElementType != T->getElementType()) {
2287 Result = getDerived().RebuildConstantArrayType(ElementType,
2288 T->getSizeModifier(),
2289 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002290 T->getIndexTypeCVRQualifiers(),
2291 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002292 if (Result.isNull())
2293 return QualType();
2294 }
2295
2296 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2297 NewTL.setLBracketLoc(TL.getLBracketLoc());
2298 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002299
John McCalla2becad2009-10-21 00:40:46 +00002300 Expr *Size = TL.getSizeExpr();
2301 if (Size) {
2302 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2303 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2304 }
2305 NewTL.setSizeExpr(Size);
2306
2307 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002308}
Mike Stump1eb44332009-09-09 15:08:12 +00002309
Douglas Gregor577f75a2009-08-04 16:50:30 +00002310template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002311QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002312 TypeLocBuilder &TLB,
2313 IncompleteArrayTypeLoc TL) {
2314 IncompleteArrayType *T = TL.getTypePtr();
2315 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002316 if (ElementType.isNull())
2317 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002318
John McCalla2becad2009-10-21 00:40:46 +00002319 QualType Result = TL.getType();
2320 if (getDerived().AlwaysRebuild() ||
2321 ElementType != T->getElementType()) {
2322 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002323 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002324 T->getIndexTypeCVRQualifiers(),
2325 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002326 if (Result.isNull())
2327 return QualType();
2328 }
2329
2330 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2331 NewTL.setLBracketLoc(TL.getLBracketLoc());
2332 NewTL.setRBracketLoc(TL.getRBracketLoc());
2333 NewTL.setSizeExpr(0);
2334
2335 return Result;
2336}
2337
2338template<typename Derived>
2339QualType
2340TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
2341 VariableArrayTypeLoc TL) {
2342 VariableArrayType *T = TL.getTypePtr();
2343 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2344 if (ElementType.isNull())
2345 return QualType();
2346
2347 // Array bounds are not potentially evaluated contexts
2348 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2349
2350 Sema::OwningExprResult SizeResult
2351 = getDerived().TransformExpr(T->getSizeExpr());
2352 if (SizeResult.isInvalid())
2353 return QualType();
2354
2355 Expr *Size = static_cast<Expr*>(SizeResult.get());
2356
2357 QualType Result = TL.getType();
2358 if (getDerived().AlwaysRebuild() ||
2359 ElementType != T->getElementType() ||
2360 Size != T->getSizeExpr()) {
2361 Result = getDerived().RebuildVariableArrayType(ElementType,
2362 T->getSizeModifier(),
2363 move(SizeResult),
2364 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002365 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002366 if (Result.isNull())
2367 return QualType();
2368 }
2369 else SizeResult.take();
2370
2371 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2372 NewTL.setLBracketLoc(TL.getLBracketLoc());
2373 NewTL.setRBracketLoc(TL.getRBracketLoc());
2374 NewTL.setSizeExpr(Size);
2375
2376 return Result;
2377}
2378
2379template<typename Derived>
2380QualType
2381TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
2382 DependentSizedArrayTypeLoc TL) {
2383 DependentSizedArrayType *T = TL.getTypePtr();
2384 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2385 if (ElementType.isNull())
2386 return QualType();
2387
2388 // Array bounds are not potentially evaluated contexts
2389 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2390
2391 Sema::OwningExprResult SizeResult
2392 = getDerived().TransformExpr(T->getSizeExpr());
2393 if (SizeResult.isInvalid())
2394 return QualType();
2395
2396 Expr *Size = static_cast<Expr*>(SizeResult.get());
2397
2398 QualType Result = TL.getType();
2399 if (getDerived().AlwaysRebuild() ||
2400 ElementType != T->getElementType() ||
2401 Size != T->getSizeExpr()) {
2402 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2403 T->getSizeModifier(),
2404 move(SizeResult),
2405 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002406 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002407 if (Result.isNull())
2408 return QualType();
2409 }
2410 else SizeResult.take();
2411
2412 // We might have any sort of array type now, but fortunately they
2413 // all have the same location layout.
2414 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2415 NewTL.setLBracketLoc(TL.getLBracketLoc());
2416 NewTL.setRBracketLoc(TL.getRBracketLoc());
2417 NewTL.setSizeExpr(Size);
2418
2419 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002420}
Mike Stump1eb44332009-09-09 15:08:12 +00002421
2422template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002423QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002424 TypeLocBuilder &TLB,
2425 DependentSizedExtVectorTypeLoc TL) {
2426 DependentSizedExtVectorType *T = TL.getTypePtr();
2427
2428 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002429 QualType ElementType = getDerived().TransformType(T->getElementType());
2430 if (ElementType.isNull())
2431 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002432
Douglas Gregor670444e2009-08-04 22:27:00 +00002433 // Vector sizes are not potentially evaluated contexts
2434 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2435
Douglas Gregor577f75a2009-08-04 16:50:30 +00002436 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2437 if (Size.isInvalid())
2438 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002439
John McCalla2becad2009-10-21 00:40:46 +00002440 QualType Result = TL.getType();
2441 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002442 ElementType != T->getElementType() ||
2443 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002444 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002445 move(Size),
2446 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002447 if (Result.isNull())
2448 return QualType();
2449 }
2450 else Size.take();
2451
2452 // Result might be dependent or not.
2453 if (isa<DependentSizedExtVectorType>(Result)) {
2454 DependentSizedExtVectorTypeLoc NewTL
2455 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2456 NewTL.setNameLoc(TL.getNameLoc());
2457 } else {
2458 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2459 NewTL.setNameLoc(TL.getNameLoc());
2460 }
2461
2462 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002463}
Mike Stump1eb44332009-09-09 15:08:12 +00002464
2465template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002466QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
2467 VectorTypeLoc TL) {
2468 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002469 QualType ElementType = getDerived().TransformType(T->getElementType());
2470 if (ElementType.isNull())
2471 return QualType();
2472
John McCalla2becad2009-10-21 00:40:46 +00002473 QualType Result = TL.getType();
2474 if (getDerived().AlwaysRebuild() ||
2475 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002476 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2477 T->isAltiVec(), T->isPixel());
John McCalla2becad2009-10-21 00:40:46 +00002478 if (Result.isNull())
2479 return QualType();
2480 }
2481
2482 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2483 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002484
John McCalla2becad2009-10-21 00:40:46 +00002485 return Result;
2486}
2487
2488template<typename Derived>
2489QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
2490 ExtVectorTypeLoc TL) {
2491 VectorType *T = TL.getTypePtr();
2492 QualType ElementType = getDerived().TransformType(T->getElementType());
2493 if (ElementType.isNull())
2494 return QualType();
2495
2496 QualType Result = TL.getType();
2497 if (getDerived().AlwaysRebuild() ||
2498 ElementType != T->getElementType()) {
2499 Result = getDerived().RebuildExtVectorType(ElementType,
2500 T->getNumElements(),
2501 /*FIXME*/ SourceLocation());
2502 if (Result.isNull())
2503 return QualType();
2504 }
2505
2506 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2507 NewTL.setNameLoc(TL.getNameLoc());
2508
2509 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002510}
Mike Stump1eb44332009-09-09 15:08:12 +00002511
2512template<typename Derived>
2513QualType
John McCalla2becad2009-10-21 00:40:46 +00002514TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
2515 FunctionProtoTypeLoc TL) {
2516 FunctionProtoType *T = TL.getTypePtr();
2517 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002518 if (ResultType.isNull())
2519 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002520
John McCalla2becad2009-10-21 00:40:46 +00002521 // Transform the parameters.
Douglas Gregor577f75a2009-08-04 16:50:30 +00002522 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002523 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2524 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2525 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump1eb44332009-09-09 15:08:12 +00002526
John McCalla2becad2009-10-21 00:40:46 +00002527 QualType NewType;
2528 ParmVarDecl *NewParm;
2529
2530 if (OldParm) {
John McCalla93c9342009-12-07 02:54:59 +00002531 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCalla2becad2009-10-21 00:40:46 +00002532 assert(OldDI->getType() == T->getArgType(i));
2533
John McCalla93c9342009-12-07 02:54:59 +00002534 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCalla2becad2009-10-21 00:40:46 +00002535 if (!NewDI)
2536 return QualType();
2537
2538 if (NewDI == OldDI)
2539 NewParm = OldParm;
2540 else
2541 NewParm = ParmVarDecl::Create(SemaRef.Context,
2542 OldParm->getDeclContext(),
2543 OldParm->getLocation(),
2544 OldParm->getIdentifier(),
2545 NewDI->getType(),
2546 NewDI,
2547 OldParm->getStorageClass(),
2548 /* DefArg */ NULL);
2549 NewType = NewParm->getType();
2550
2551 // Deal with the possibility that we don't have a parameter
2552 // declaration for this parameter.
2553 } else {
2554 NewParm = 0;
2555
2556 QualType OldType = T->getArgType(i);
2557 NewType = getDerived().TransformType(OldType);
2558 if (NewType.isNull())
2559 return QualType();
2560 }
2561
2562 ParamTypes.push_back(NewType);
2563 ParamDecls.push_back(NewParm);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002564 }
Mike Stump1eb44332009-09-09 15:08:12 +00002565
John McCalla2becad2009-10-21 00:40:46 +00002566 QualType Result = TL.getType();
2567 if (getDerived().AlwaysRebuild() ||
2568 ResultType != T->getResultType() ||
2569 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2570 Result = getDerived().RebuildFunctionProtoType(ResultType,
2571 ParamTypes.data(),
2572 ParamTypes.size(),
2573 T->isVariadic(),
2574 T->getTypeQuals());
2575 if (Result.isNull())
2576 return QualType();
2577 }
Mike Stump1eb44332009-09-09 15:08:12 +00002578
John McCalla2becad2009-10-21 00:40:46 +00002579 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2580 NewTL.setLParenLoc(TL.getLParenLoc());
2581 NewTL.setRParenLoc(TL.getRParenLoc());
2582 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2583 NewTL.setArg(i, ParamDecls[i]);
2584
2585 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002586}
Mike Stump1eb44332009-09-09 15:08:12 +00002587
Douglas Gregor577f75a2009-08-04 16:50:30 +00002588template<typename Derived>
2589QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002590 TypeLocBuilder &TLB,
2591 FunctionNoProtoTypeLoc TL) {
2592 FunctionNoProtoType *T = TL.getTypePtr();
2593 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2594 if (ResultType.isNull())
2595 return QualType();
2596
2597 QualType Result = TL.getType();
2598 if (getDerived().AlwaysRebuild() ||
2599 ResultType != T->getResultType())
2600 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2601
2602 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2603 NewTL.setLParenLoc(TL.getLParenLoc());
2604 NewTL.setRParenLoc(TL.getRParenLoc());
2605
2606 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002607}
Mike Stump1eb44332009-09-09 15:08:12 +00002608
John McCalled976492009-12-04 22:46:56 +00002609template<typename Derived> QualType
2610TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
2611 UnresolvedUsingTypeLoc TL) {
2612 UnresolvedUsingType *T = TL.getTypePtr();
2613 Decl *D = getDerived().TransformDecl(T->getDecl());
2614 if (!D)
2615 return QualType();
2616
2617 QualType Result = TL.getType();
2618 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2619 Result = getDerived().RebuildUnresolvedUsingType(D);
2620 if (Result.isNull())
2621 return QualType();
2622 }
2623
2624 // We might get an arbitrary type spec type back. We should at
2625 // least always get a type spec type, though.
2626 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2627 NewTL.setNameLoc(TL.getNameLoc());
2628
2629 return Result;
2630}
2631
Douglas Gregor577f75a2009-08-04 16:50:30 +00002632template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002633QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
2634 TypedefTypeLoc TL) {
2635 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002636 TypedefDecl *Typedef
2637 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2638 if (!Typedef)
2639 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002640
John McCalla2becad2009-10-21 00:40:46 +00002641 QualType Result = TL.getType();
2642 if (getDerived().AlwaysRebuild() ||
2643 Typedef != T->getDecl()) {
2644 Result = getDerived().RebuildTypedefType(Typedef);
2645 if (Result.isNull())
2646 return QualType();
2647 }
Mike Stump1eb44332009-09-09 15:08:12 +00002648
John McCalla2becad2009-10-21 00:40:46 +00002649 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2650 NewTL.setNameLoc(TL.getNameLoc());
2651
2652 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002653}
Mike Stump1eb44332009-09-09 15:08:12 +00002654
Douglas Gregor577f75a2009-08-04 16:50:30 +00002655template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002656QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
2657 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00002658 // typeof expressions are not potentially evaluated contexts
2659 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002660
John McCallcfb708c2010-01-13 20:03:27 +00002661 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002662 if (E.isInvalid())
2663 return QualType();
2664
John McCalla2becad2009-10-21 00:40:46 +00002665 QualType Result = TL.getType();
2666 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00002667 E.get() != TL.getUnderlyingExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002668 Result = getDerived().RebuildTypeOfExprType(move(E));
2669 if (Result.isNull())
2670 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002671 }
John McCalla2becad2009-10-21 00:40:46 +00002672 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002673
John McCalla2becad2009-10-21 00:40:46 +00002674 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002675 NewTL.setTypeofLoc(TL.getTypeofLoc());
2676 NewTL.setLParenLoc(TL.getLParenLoc());
2677 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00002678
2679 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002680}
Mike Stump1eb44332009-09-09 15:08:12 +00002681
2682template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002683QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
2684 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00002685 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2686 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2687 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00002688 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002689
John McCalla2becad2009-10-21 00:40:46 +00002690 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00002691 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2692 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00002693 if (Result.isNull())
2694 return QualType();
2695 }
Mike Stump1eb44332009-09-09 15:08:12 +00002696
John McCalla2becad2009-10-21 00:40:46 +00002697 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002698 NewTL.setTypeofLoc(TL.getTypeofLoc());
2699 NewTL.setLParenLoc(TL.getLParenLoc());
2700 NewTL.setRParenLoc(TL.getRParenLoc());
2701 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00002702
2703 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002704}
Mike Stump1eb44332009-09-09 15:08:12 +00002705
2706template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002707QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
2708 DecltypeTypeLoc TL) {
2709 DecltypeType *T = TL.getTypePtr();
2710
Douglas Gregor670444e2009-08-04 22:27:00 +00002711 // decltype expressions are not potentially evaluated contexts
2712 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002713
Douglas Gregor577f75a2009-08-04 16:50:30 +00002714 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2715 if (E.isInvalid())
2716 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002717
John McCalla2becad2009-10-21 00:40:46 +00002718 QualType Result = TL.getType();
2719 if (getDerived().AlwaysRebuild() ||
2720 E.get() != T->getUnderlyingExpr()) {
2721 Result = getDerived().RebuildDecltypeType(move(E));
2722 if (Result.isNull())
2723 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002724 }
John McCalla2becad2009-10-21 00:40:46 +00002725 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002726
John McCalla2becad2009-10-21 00:40:46 +00002727 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2728 NewTL.setNameLoc(TL.getNameLoc());
2729
2730 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002731}
2732
2733template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002734QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
2735 RecordTypeLoc TL) {
2736 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002737 RecordDecl *Record
John McCalla2becad2009-10-21 00:40:46 +00002738 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002739 if (!Record)
2740 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002741
John McCalla2becad2009-10-21 00:40:46 +00002742 QualType Result = TL.getType();
2743 if (getDerived().AlwaysRebuild() ||
2744 Record != T->getDecl()) {
2745 Result = getDerived().RebuildRecordType(Record);
2746 if (Result.isNull())
2747 return QualType();
2748 }
Mike Stump1eb44332009-09-09 15:08:12 +00002749
John McCalla2becad2009-10-21 00:40:46 +00002750 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2751 NewTL.setNameLoc(TL.getNameLoc());
2752
2753 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002754}
Mike Stump1eb44332009-09-09 15:08:12 +00002755
2756template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002757QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
2758 EnumTypeLoc TL) {
2759 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002760 EnumDecl *Enum
John McCalla2becad2009-10-21 00:40:46 +00002761 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002762 if (!Enum)
2763 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002764
John McCalla2becad2009-10-21 00:40:46 +00002765 QualType Result = TL.getType();
2766 if (getDerived().AlwaysRebuild() ||
2767 Enum != T->getDecl()) {
2768 Result = getDerived().RebuildEnumType(Enum);
2769 if (Result.isNull())
2770 return QualType();
2771 }
Mike Stump1eb44332009-09-09 15:08:12 +00002772
John McCalla2becad2009-10-21 00:40:46 +00002773 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2774 NewTL.setNameLoc(TL.getNameLoc());
2775
2776 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002777}
John McCall7da24312009-09-05 00:15:47 +00002778
2779template <typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002780QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
2781 ElaboratedTypeLoc TL) {
2782 ElaboratedType *T = TL.getTypePtr();
2783
2784 // FIXME: this should be a nested type.
John McCall7da24312009-09-05 00:15:47 +00002785 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2786 if (Underlying.isNull())
2787 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002788
John McCalla2becad2009-10-21 00:40:46 +00002789 QualType Result = TL.getType();
2790 if (getDerived().AlwaysRebuild() ||
2791 Underlying != T->getUnderlyingType()) {
2792 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2793 if (Result.isNull())
2794 return QualType();
2795 }
Mike Stump1eb44332009-09-09 15:08:12 +00002796
John McCalla2becad2009-10-21 00:40:46 +00002797 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2798 NewTL.setNameLoc(TL.getNameLoc());
2799
2800 return Result;
John McCall7da24312009-09-05 00:15:47 +00002801}
Mike Stump1eb44332009-09-09 15:08:12 +00002802
2803
Douglas Gregor577f75a2009-08-04 16:50:30 +00002804template<typename Derived>
2805QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00002806 TypeLocBuilder &TLB,
2807 TemplateTypeParmTypeLoc TL) {
2808 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002809}
2810
Mike Stump1eb44332009-09-09 15:08:12 +00002811template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00002812QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00002813 TypeLocBuilder &TLB,
2814 SubstTemplateTypeParmTypeLoc TL) {
2815 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00002816}
2817
2818template<typename Derived>
Douglas Gregordd62b152009-10-19 22:04:39 +00002819inline QualType
2820TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCalla2becad2009-10-21 00:40:46 +00002821 TypeLocBuilder &TLB,
2822 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00002823 return TransformTemplateSpecializationType(TLB, TL, QualType());
2824}
John McCalla2becad2009-10-21 00:40:46 +00002825
John McCall833ca992009-10-29 08:12:44 +00002826template<typename Derived>
2827QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2828 const TemplateSpecializationType *TST,
2829 QualType ObjectType) {
2830 // FIXME: this entire method is a temporary workaround; callers
2831 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00002832
John McCall833ca992009-10-29 08:12:44 +00002833 // Fake up a TemplateSpecializationTypeLoc.
2834 TypeLocBuilder TLB;
2835 TemplateSpecializationTypeLoc TL
2836 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2837
John McCall828bff22009-10-29 18:45:58 +00002838 SourceLocation BaseLoc = getDerived().getBaseLocation();
2839
2840 TL.setTemplateNameLoc(BaseLoc);
2841 TL.setLAngleLoc(BaseLoc);
2842 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00002843 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2844 const TemplateArgument &TA = TST->getArg(i);
2845 TemplateArgumentLoc TAL;
2846 getDerived().InventTemplateArgumentLoc(TA, TAL);
2847 TL.setArgLocInfo(i, TAL.getLocInfo());
2848 }
2849
2850 TypeLocBuilder IgnoredTLB;
2851 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00002852}
2853
2854template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002855QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00002856 TypeLocBuilder &TLB,
2857 TemplateSpecializationTypeLoc TL,
2858 QualType ObjectType) {
2859 const TemplateSpecializationType *T = TL.getTypePtr();
2860
Mike Stump1eb44332009-09-09 15:08:12 +00002861 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00002862 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002863 if (Template.isNull())
2864 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002865
John McCalld5532b62009-11-23 01:53:49 +00002866 TemplateArgumentListInfo NewTemplateArgs;
2867 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2868 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2869
2870 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2871 TemplateArgumentLoc Loc;
2872 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00002873 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00002874 NewTemplateArgs.addArgument(Loc);
2875 }
Mike Stump1eb44332009-09-09 15:08:12 +00002876
John McCall833ca992009-10-29 08:12:44 +00002877 // FIXME: maybe don't rebuild if all the template arguments are the same.
2878
2879 QualType Result =
2880 getDerived().RebuildTemplateSpecializationType(Template,
2881 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00002882 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00002883
2884 if (!Result.isNull()) {
2885 TemplateSpecializationTypeLoc NewTL
2886 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2887 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2888 NewTL.setLAngleLoc(TL.getLAngleLoc());
2889 NewTL.setRAngleLoc(TL.getRAngleLoc());
2890 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2891 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002892 }
Mike Stump1eb44332009-09-09 15:08:12 +00002893
John McCall833ca992009-10-29 08:12:44 +00002894 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002895}
Mike Stump1eb44332009-09-09 15:08:12 +00002896
2897template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002898QualType
2899TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
2900 QualifiedNameTypeLoc TL) {
2901 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002902 NestedNameSpecifier *NNS
2903 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2904 SourceRange());
2905 if (!NNS)
2906 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002907
Douglas Gregor577f75a2009-08-04 16:50:30 +00002908 QualType Named = getDerived().TransformType(T->getNamedType());
2909 if (Named.isNull())
2910 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002911
John McCalla2becad2009-10-21 00:40:46 +00002912 QualType Result = TL.getType();
2913 if (getDerived().AlwaysRebuild() ||
2914 NNS != T->getQualifier() ||
2915 Named != T->getNamedType()) {
2916 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2917 if (Result.isNull())
2918 return QualType();
2919 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002920
John McCalla2becad2009-10-21 00:40:46 +00002921 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2922 NewTL.setNameLoc(TL.getNameLoc());
2923
2924 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002925}
Mike Stump1eb44332009-09-09 15:08:12 +00002926
2927template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002928QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
2929 TypenameTypeLoc TL) {
2930 TypenameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00002931
2932 /* FIXME: preserve source information better than this */
2933 SourceRange SR(TL.getNameLoc());
2934
Douglas Gregor577f75a2009-08-04 16:50:30 +00002935 NestedNameSpecifier *NNS
John McCall833ca992009-10-29 08:12:44 +00002936 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002937 if (!NNS)
2938 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002939
John McCalla2becad2009-10-21 00:40:46 +00002940 QualType Result;
2941
Douglas Gregor577f75a2009-08-04 16:50:30 +00002942 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002943 QualType NewTemplateId
Douglas Gregor577f75a2009-08-04 16:50:30 +00002944 = getDerived().TransformType(QualType(TemplateId, 0));
2945 if (NewTemplateId.isNull())
2946 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002947
Douglas Gregor577f75a2009-08-04 16:50:30 +00002948 if (!getDerived().AlwaysRebuild() &&
2949 NNS == T->getQualifier() &&
2950 NewTemplateId == QualType(TemplateId, 0))
2951 return QualType(T, 0);
Mike Stump1eb44332009-09-09 15:08:12 +00002952
John McCalla2becad2009-10-21 00:40:46 +00002953 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2954 } else {
John McCall833ca992009-10-29 08:12:44 +00002955 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002956 }
John McCalla2becad2009-10-21 00:40:46 +00002957 if (Result.isNull())
2958 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002959
John McCalla2becad2009-10-21 00:40:46 +00002960 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2961 NewTL.setNameLoc(TL.getNameLoc());
2962
2963 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002964}
Mike Stump1eb44332009-09-09 15:08:12 +00002965
Douglas Gregor577f75a2009-08-04 16:50:30 +00002966template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002967QualType
2968TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
2969 ObjCInterfaceTypeLoc TL) {
John McCall54e14c42009-10-22 22:37:11 +00002970 assert(false && "TransformObjCInterfaceType unimplemented");
2971 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002972}
Mike Stump1eb44332009-09-09 15:08:12 +00002973
2974template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002975QualType
2976TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
2977 ObjCObjectPointerTypeLoc TL) {
John McCall54e14c42009-10-22 22:37:11 +00002978 assert(false && "TransformObjCObjectPointerType unimplemented");
2979 return QualType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00002980}
2981
Douglas Gregor577f75a2009-08-04 16:50:30 +00002982//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00002983// Statement transformation
2984//===----------------------------------------------------------------------===//
2985template<typename Derived>
2986Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00002987TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2988 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00002989}
2990
2991template<typename Derived>
2992Sema::OwningStmtResult
2993TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2994 return getDerived().TransformCompoundStmt(S, false);
2995}
2996
2997template<typename Derived>
2998Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00002999TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003000 bool IsStmtExpr) {
3001 bool SubStmtChanged = false;
3002 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3003 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3004 B != BEnd; ++B) {
3005 OwningStmtResult Result = getDerived().TransformStmt(*B);
3006 if (Result.isInvalid())
3007 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003008
Douglas Gregor43959a92009-08-20 07:17:43 +00003009 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3010 Statements.push_back(Result.takeAs<Stmt>());
3011 }
Mike Stump1eb44332009-09-09 15:08:12 +00003012
Douglas Gregor43959a92009-08-20 07:17:43 +00003013 if (!getDerived().AlwaysRebuild() &&
3014 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003015 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003016
3017 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3018 move_arg(Statements),
3019 S->getRBracLoc(),
3020 IsStmtExpr);
3021}
Mike Stump1eb44332009-09-09 15:08:12 +00003022
Douglas Gregor43959a92009-08-20 07:17:43 +00003023template<typename Derived>
3024Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003025TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman264c1f82009-11-19 03:14:00 +00003026 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3027 {
3028 // The case value expressions are not potentially evaluated.
3029 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003030
Eli Friedman264c1f82009-11-19 03:14:00 +00003031 // Transform the left-hand case value.
3032 LHS = getDerived().TransformExpr(S->getLHS());
3033 if (LHS.isInvalid())
3034 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003035
Eli Friedman264c1f82009-11-19 03:14:00 +00003036 // Transform the right-hand case value (for the GNU case-range extension).
3037 RHS = getDerived().TransformExpr(S->getRHS());
3038 if (RHS.isInvalid())
3039 return SemaRef.StmtError();
3040 }
Mike Stump1eb44332009-09-09 15:08:12 +00003041
Douglas Gregor43959a92009-08-20 07:17:43 +00003042 // Build the case statement.
3043 // Case statements are always rebuilt so that they will attached to their
3044 // transformed switch statement.
3045 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3046 move(LHS),
3047 S->getEllipsisLoc(),
3048 move(RHS),
3049 S->getColonLoc());
3050 if (Case.isInvalid())
3051 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003052
Douglas Gregor43959a92009-08-20 07:17:43 +00003053 // Transform the statement following the case
3054 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3055 if (SubStmt.isInvalid())
3056 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003057
Douglas Gregor43959a92009-08-20 07:17:43 +00003058 // Attach the body to the case statement
3059 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3060}
3061
3062template<typename Derived>
3063Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003064TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003065 // Transform the statement following the default case
3066 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3067 if (SubStmt.isInvalid())
3068 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003069
Douglas Gregor43959a92009-08-20 07:17:43 +00003070 // Default statements are always rebuilt
3071 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3072 move(SubStmt));
3073}
Mike Stump1eb44332009-09-09 15:08:12 +00003074
Douglas Gregor43959a92009-08-20 07:17:43 +00003075template<typename Derived>
3076Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003077TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003078 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3079 if (SubStmt.isInvalid())
3080 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003081
Douglas Gregor43959a92009-08-20 07:17:43 +00003082 // FIXME: Pass the real colon location in.
3083 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3084 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3085 move(SubStmt));
3086}
Mike Stump1eb44332009-09-09 15:08:12 +00003087
Douglas Gregor43959a92009-08-20 07:17:43 +00003088template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003089Sema::OwningStmtResult
3090TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003091 // Transform the condition
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003092 OwningExprResult Cond(SemaRef);
3093 VarDecl *ConditionVar = 0;
3094 if (S->getConditionVariable()) {
3095 ConditionVar
3096 = cast_or_null<VarDecl>(
3097 getDerived().TransformDefinition(S->getConditionVariable()));
3098 if (!ConditionVar)
3099 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003100 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003101 Cond = getDerived().TransformExpr(S->getCond());
3102
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003103 if (Cond.isInvalid())
3104 return SemaRef.StmtError();
3105 }
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003106
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003107 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump1eb44332009-09-09 15:08:12 +00003108
Douglas Gregor43959a92009-08-20 07:17:43 +00003109 // Transform the "then" branch.
3110 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3111 if (Then.isInvalid())
3112 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003113
Douglas Gregor43959a92009-08-20 07:17:43 +00003114 // Transform the "else" branch.
3115 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3116 if (Else.isInvalid())
3117 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003118
Douglas Gregor43959a92009-08-20 07:17:43 +00003119 if (!getDerived().AlwaysRebuild() &&
3120 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003121 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003122 Then.get() == S->getThen() &&
3123 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003124 return SemaRef.Owned(S->Retain());
3125
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003126 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3127 move(Then),
Mike Stump1eb44332009-09-09 15:08:12 +00003128 S->getElseLoc(), move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +00003129}
3130
3131template<typename Derived>
3132Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003133TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003134 // Transform the condition.
Douglas Gregord3d53012009-11-24 17:07:59 +00003135 OwningExprResult Cond(SemaRef);
3136 VarDecl *ConditionVar = 0;
3137 if (S->getConditionVariable()) {
3138 ConditionVar
3139 = cast_or_null<VarDecl>(
3140 getDerived().TransformDefinition(S->getConditionVariable()));
3141 if (!ConditionVar)
3142 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003143 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003144 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003145
3146 if (Cond.isInvalid())
3147 return SemaRef.StmtError();
3148 }
Mike Stump1eb44332009-09-09 15:08:12 +00003149
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003150 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003151
Douglas Gregor43959a92009-08-20 07:17:43 +00003152 // Rebuild the switch statement.
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003153 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3154 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003155 if (Switch.isInvalid())
3156 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003157
Douglas Gregor43959a92009-08-20 07:17:43 +00003158 // Transform the body of the switch statement.
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 // Complete the switch statement.
3164 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3165 move(Body));
3166}
Mike Stump1eb44332009-09-09 15:08:12 +00003167
Douglas Gregor43959a92009-08-20 07:17:43 +00003168template<typename Derived>
3169Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003170TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003171 // Transform the condition
Douglas Gregor5656e142009-11-24 21:15:44 +00003172 OwningExprResult Cond(SemaRef);
3173 VarDecl *ConditionVar = 0;
3174 if (S->getConditionVariable()) {
3175 ConditionVar
3176 = cast_or_null<VarDecl>(
3177 getDerived().TransformDefinition(S->getConditionVariable()));
3178 if (!ConditionVar)
3179 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003180 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003181 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003182
3183 if (Cond.isInvalid())
3184 return SemaRef.StmtError();
3185 }
Mike Stump1eb44332009-09-09 15:08:12 +00003186
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003187 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump1eb44332009-09-09 15:08:12 +00003188
Douglas Gregor43959a92009-08-20 07:17:43 +00003189 // Transform the body
3190 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3191 if (Body.isInvalid())
3192 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003193
Douglas Gregor43959a92009-08-20 07:17:43 +00003194 if (!getDerived().AlwaysRebuild() &&
3195 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003196 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003197 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003198 return SemaRef.Owned(S->Retain());
3199
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003200 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3201 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003202}
Mike Stump1eb44332009-09-09 15:08:12 +00003203
Douglas Gregor43959a92009-08-20 07:17:43 +00003204template<typename Derived>
3205Sema::OwningStmtResult
3206TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3207 // Transform the condition
3208 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3209 if (Cond.isInvalid())
3210 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003211
Douglas Gregor43959a92009-08-20 07:17:43 +00003212 // Transform the body
3213 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3214 if (Body.isInvalid())
3215 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003216
Douglas Gregor43959a92009-08-20 07:17:43 +00003217 if (!getDerived().AlwaysRebuild() &&
3218 Cond.get() == S->getCond() &&
3219 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003220 return SemaRef.Owned(S->Retain());
3221
Douglas Gregor43959a92009-08-20 07:17:43 +00003222 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3223 /*FIXME:*/S->getWhileLoc(), move(Cond),
3224 S->getRParenLoc());
3225}
Mike Stump1eb44332009-09-09 15:08:12 +00003226
Douglas Gregor43959a92009-08-20 07:17:43 +00003227template<typename Derived>
3228Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003229TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003230 // Transform the initialization statement
3231 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3232 if (Init.isInvalid())
3233 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003234
Douglas Gregor43959a92009-08-20 07:17:43 +00003235 // Transform the condition
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003236 OwningExprResult Cond(SemaRef);
3237 VarDecl *ConditionVar = 0;
3238 if (S->getConditionVariable()) {
3239 ConditionVar
3240 = cast_or_null<VarDecl>(
3241 getDerived().TransformDefinition(S->getConditionVariable()));
3242 if (!ConditionVar)
3243 return SemaRef.StmtError();
3244 } else {
3245 Cond = getDerived().TransformExpr(S->getCond());
3246
3247 if (Cond.isInvalid())
3248 return SemaRef.StmtError();
3249 }
Mike Stump1eb44332009-09-09 15:08:12 +00003250
Douglas Gregor43959a92009-08-20 07:17:43 +00003251 // Transform the increment
3252 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3253 if (Inc.isInvalid())
3254 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003255
Douglas Gregor43959a92009-08-20 07:17:43 +00003256 // Transform the body
3257 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3258 if (Body.isInvalid())
3259 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003260
Douglas Gregor43959a92009-08-20 07:17:43 +00003261 if (!getDerived().AlwaysRebuild() &&
3262 Init.get() == S->getInit() &&
3263 Cond.get() == S->getCond() &&
3264 Inc.get() == S->getInc() &&
3265 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003266 return SemaRef.Owned(S->Retain());
3267
Douglas Gregor43959a92009-08-20 07:17:43 +00003268 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003269 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003270 ConditionVar,
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003271 getSema().MakeFullExpr(Inc),
Douglas Gregor43959a92009-08-20 07:17:43 +00003272 S->getRParenLoc(), move(Body));
3273}
3274
3275template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003276Sema::OwningStmtResult
3277TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003278 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003279 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003280 S->getLabel());
3281}
3282
3283template<typename Derived>
3284Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003285TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003286 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3287 if (Target.isInvalid())
3288 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003289
Douglas Gregor43959a92009-08-20 07:17:43 +00003290 if (!getDerived().AlwaysRebuild() &&
3291 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003292 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003293
3294 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3295 move(Target));
3296}
3297
3298template<typename Derived>
3299Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003300TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3301 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003302}
Mike Stump1eb44332009-09-09 15:08:12 +00003303
Douglas Gregor43959a92009-08-20 07:17:43 +00003304template<typename Derived>
3305Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003306TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3307 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003308}
Mike Stump1eb44332009-09-09 15:08:12 +00003309
Douglas Gregor43959a92009-08-20 07:17:43 +00003310template<typename Derived>
3311Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003312TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003313 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3314 if (Result.isInvalid())
3315 return SemaRef.StmtError();
3316
Mike Stump1eb44332009-09-09 15:08:12 +00003317 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003318 // to tell whether the return type of the function has changed.
3319 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3320}
Mike Stump1eb44332009-09-09 15:08:12 +00003321
Douglas Gregor43959a92009-08-20 07:17:43 +00003322template<typename Derived>
3323Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003324TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003325 bool DeclChanged = false;
3326 llvm::SmallVector<Decl *, 4> Decls;
3327 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3328 D != DEnd; ++D) {
3329 Decl *Transformed = getDerived().TransformDefinition(*D);
3330 if (!Transformed)
3331 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003332
Douglas Gregor43959a92009-08-20 07:17:43 +00003333 if (Transformed != *D)
3334 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003335
Douglas Gregor43959a92009-08-20 07:17:43 +00003336 Decls.push_back(Transformed);
3337 }
Mike Stump1eb44332009-09-09 15:08:12 +00003338
Douglas Gregor43959a92009-08-20 07:17:43 +00003339 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003340 return SemaRef.Owned(S->Retain());
3341
3342 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003343 S->getStartLoc(), S->getEndLoc());
3344}
Mike Stump1eb44332009-09-09 15:08:12 +00003345
Douglas Gregor43959a92009-08-20 07:17:43 +00003346template<typename Derived>
3347Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003348TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003349 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003350 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003351}
3352
3353template<typename Derived>
3354Sema::OwningStmtResult
3355TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlsson703e3942010-01-24 05:50:09 +00003356
3357 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3358 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003359 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003360
Anders Carlsson703e3942010-01-24 05:50:09 +00003361 OwningExprResult AsmString(SemaRef);
3362 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3363
3364 bool ExprsChanged = false;
3365
3366 // Go through the outputs.
3367 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003368 Names.push_back(S->getOutputIdentifier(I));
Anders Carlssona5a79f72010-01-30 20:05:21 +00003369
Anders Carlsson703e3942010-01-24 05:50:09 +00003370 // No need to transform the constraint literal.
3371 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3372
3373 // Transform the output expr.
3374 Expr *OutputExpr = S->getOutputExpr(I);
3375 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3376 if (Result.isInvalid())
3377 return SemaRef.StmtError();
3378
3379 ExprsChanged |= Result.get() != OutputExpr;
3380
3381 Exprs.push_back(Result.takeAs<Expr>());
3382 }
3383
3384 // Go through the inputs.
3385 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003386 Names.push_back(S->getInputIdentifier(I));
Anders Carlssona5a79f72010-01-30 20:05:21 +00003387
Anders Carlsson703e3942010-01-24 05:50:09 +00003388 // No need to transform the constraint literal.
3389 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3390
3391 // Transform the input expr.
3392 Expr *InputExpr = S->getInputExpr(I);
3393 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3394 if (Result.isInvalid())
3395 return SemaRef.StmtError();
3396
3397 ExprsChanged |= Result.get() != InputExpr;
3398
3399 Exprs.push_back(Result.takeAs<Expr>());
3400 }
3401
3402 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3403 return SemaRef.Owned(S->Retain());
3404
3405 // Go through the clobbers.
3406 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3407 Clobbers.push_back(S->getClobber(I)->Retain());
3408
3409 // No need to transform the asm string literal.
3410 AsmString = SemaRef.Owned(S->getAsmString());
3411
3412 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3413 S->isSimple(),
3414 S->isVolatile(),
3415 S->getNumOutputs(),
3416 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003417 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003418 move_arg(Constraints),
3419 move_arg(Exprs),
3420 move(AsmString),
3421 move_arg(Clobbers),
3422 S->getRParenLoc(),
3423 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003424}
3425
3426
3427template<typename Derived>
3428Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003429TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003430 // FIXME: Implement this
3431 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003432 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003433}
Mike Stump1eb44332009-09-09 15:08:12 +00003434
Douglas Gregor43959a92009-08-20 07:17:43 +00003435template<typename Derived>
3436Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003437TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003438 // FIXME: Implement this
3439 assert(false && "Cannot transform an Objective-C @catch statement");
3440 return SemaRef.Owned(S->Retain());
3441}
Mike Stump1eb44332009-09-09 15:08:12 +00003442
Douglas Gregor43959a92009-08-20 07:17:43 +00003443template<typename Derived>
3444Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003445TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003446 // FIXME: Implement this
3447 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003448 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003449}
Mike Stump1eb44332009-09-09 15:08:12 +00003450
Douglas Gregor43959a92009-08-20 07:17:43 +00003451template<typename Derived>
3452Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003453TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003454 // FIXME: Implement this
3455 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003456 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003457}
Mike Stump1eb44332009-09-09 15:08:12 +00003458
Douglas Gregor43959a92009-08-20 07:17:43 +00003459template<typename Derived>
3460Sema::OwningStmtResult
3461TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003462 ObjCAtSynchronizedStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003463 // FIXME: Implement this
3464 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003465 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003466}
3467
3468template<typename Derived>
3469Sema::OwningStmtResult
3470TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003471 ObjCForCollectionStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003472 // FIXME: Implement this
3473 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003474 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003475}
3476
3477
3478template<typename Derived>
3479Sema::OwningStmtResult
3480TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3481 // Transform the exception declaration, if any.
3482 VarDecl *Var = 0;
3483 if (S->getExceptionDecl()) {
3484 VarDecl *ExceptionDecl = S->getExceptionDecl();
3485 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3486 ExceptionDecl->getDeclName());
3487
3488 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3489 if (T.isNull())
3490 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003491
Douglas Gregor43959a92009-08-20 07:17:43 +00003492 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3493 T,
John McCalla93c9342009-12-07 02:54:59 +00003494 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003495 ExceptionDecl->getIdentifier(),
3496 ExceptionDecl->getLocation(),
3497 /*FIXME: Inaccurate*/
3498 SourceRange(ExceptionDecl->getLocation()));
3499 if (!Var || Var->isInvalidDecl()) {
3500 if (Var)
3501 Var->Destroy(SemaRef.Context);
3502 return SemaRef.StmtError();
3503 }
3504 }
Mike Stump1eb44332009-09-09 15:08:12 +00003505
Douglas Gregor43959a92009-08-20 07:17:43 +00003506 // Transform the actual exception handler.
3507 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3508 if (Handler.isInvalid()) {
3509 if (Var)
3510 Var->Destroy(SemaRef.Context);
3511 return SemaRef.StmtError();
3512 }
Mike Stump1eb44332009-09-09 15:08:12 +00003513
Douglas Gregor43959a92009-08-20 07:17:43 +00003514 if (!getDerived().AlwaysRebuild() &&
3515 !Var &&
3516 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00003517 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003518
3519 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3520 Var,
3521 move(Handler));
3522}
Mike Stump1eb44332009-09-09 15:08:12 +00003523
Douglas Gregor43959a92009-08-20 07:17:43 +00003524template<typename Derived>
3525Sema::OwningStmtResult
3526TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3527 // Transform the try block itself.
Mike Stump1eb44332009-09-09 15:08:12 +00003528 OwningStmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00003529 = getDerived().TransformCompoundStmt(S->getTryBlock());
3530 if (TryBlock.isInvalid())
3531 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003532
Douglas Gregor43959a92009-08-20 07:17:43 +00003533 // Transform the handlers.
3534 bool HandlerChanged = false;
3535 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3536 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump1eb44332009-09-09 15:08:12 +00003537 OwningStmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00003538 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3539 if (Handler.isInvalid())
3540 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003541
Douglas Gregor43959a92009-08-20 07:17:43 +00003542 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3543 Handlers.push_back(Handler.takeAs<Stmt>());
3544 }
Mike Stump1eb44332009-09-09 15:08:12 +00003545
Douglas Gregor43959a92009-08-20 07:17:43 +00003546 if (!getDerived().AlwaysRebuild() &&
3547 TryBlock.get() == S->getTryBlock() &&
3548 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003549 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003550
3551 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump1eb44332009-09-09 15:08:12 +00003552 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00003553}
Mike Stump1eb44332009-09-09 15:08:12 +00003554
Douglas Gregor43959a92009-08-20 07:17:43 +00003555//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00003556// Expression transformation
3557//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00003558template<typename Derived>
3559Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003560TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003561 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003562}
Mike Stump1eb44332009-09-09 15:08:12 +00003563
3564template<typename Derived>
3565Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003566TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00003567 NestedNameSpecifier *Qualifier = 0;
3568 if (E->getQualifier()) {
3569 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3570 E->getQualifierRange());
3571 if (!Qualifier)
3572 return SemaRef.ExprError();
3573 }
John McCalldbd872f2009-12-08 09:08:17 +00003574
3575 ValueDecl *ND
3576 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00003577 if (!ND)
3578 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003579
Douglas Gregora2813ce2009-10-23 18:54:35 +00003580 if (!getDerived().AlwaysRebuild() &&
3581 Qualifier == E->getQualifier() &&
3582 ND == E->getDecl() &&
John McCalldbd872f2009-12-08 09:08:17 +00003583 !E->hasExplicitTemplateArgumentList()) {
3584
3585 // Mark it referenced in the new context regardless.
3586 // FIXME: this is a bit instantiation-specific.
3587 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3588
Mike Stump1eb44332009-09-09 15:08:12 +00003589 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00003590 }
John McCalldbd872f2009-12-08 09:08:17 +00003591
3592 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3593 if (E->hasExplicitTemplateArgumentList()) {
3594 TemplateArgs = &TransArgs;
3595 TransArgs.setLAngleLoc(E->getLAngleLoc());
3596 TransArgs.setRAngleLoc(E->getRAngleLoc());
3597 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3598 TemplateArgumentLoc Loc;
3599 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3600 return SemaRef.ExprError();
3601 TransArgs.addArgument(Loc);
3602 }
3603 }
3604
Douglas Gregora2813ce2009-10-23 18:54:35 +00003605 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCalldbd872f2009-12-08 09:08:17 +00003606 ND, E->getLocation(), TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003607}
Mike Stump1eb44332009-09-09 15:08:12 +00003608
Douglas Gregorb98b1992009-08-11 05:31:07 +00003609template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003610Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003611TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003612 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003613}
Mike Stump1eb44332009-09-09 15:08:12 +00003614
Douglas Gregorb98b1992009-08-11 05:31:07 +00003615template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003616Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003617TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003618 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003619}
Mike Stump1eb44332009-09-09 15:08:12 +00003620
Douglas Gregorb98b1992009-08-11 05:31:07 +00003621template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003622Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003623TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003624 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003625}
Mike Stump1eb44332009-09-09 15:08:12 +00003626
Douglas Gregorb98b1992009-08-11 05:31:07 +00003627template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003628Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003629TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003630 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003631}
Mike Stump1eb44332009-09-09 15:08:12 +00003632
Douglas Gregorb98b1992009-08-11 05:31:07 +00003633template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003634Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003635TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003636 return SemaRef.Owned(E->Retain());
3637}
3638
3639template<typename Derived>
3640Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003641TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003642 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3643 if (SubExpr.isInvalid())
3644 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003645
Douglas Gregorb98b1992009-08-11 05:31:07 +00003646 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003647 return SemaRef.Owned(E->Retain());
3648
3649 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003650 E->getRParen());
3651}
3652
Mike Stump1eb44332009-09-09 15:08:12 +00003653template<typename Derived>
3654Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003655TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3656 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003657 if (SubExpr.isInvalid())
3658 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003659
Douglas Gregorb98b1992009-08-11 05:31:07 +00003660 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003661 return SemaRef.Owned(E->Retain());
3662
Douglas Gregorb98b1992009-08-11 05:31:07 +00003663 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3664 E->getOpcode(),
3665 move(SubExpr));
3666}
Mike Stump1eb44332009-09-09 15:08:12 +00003667
Douglas Gregorb98b1992009-08-11 05:31:07 +00003668template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003669Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003670TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003671 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00003672 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00003673
John McCalla93c9342009-12-07 02:54:59 +00003674 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00003675 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003676 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003677
John McCall5ab75172009-11-04 07:28:41 +00003678 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003679 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003680
John McCall5ab75172009-11-04 07:28:41 +00003681 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00003682 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003683 E->getSourceRange());
3684 }
Mike Stump1eb44332009-09-09 15:08:12 +00003685
Douglas Gregorb98b1992009-08-11 05:31:07 +00003686 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00003687 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003688 // C++0x [expr.sizeof]p1:
3689 // The operand is either an expression, which is an unevaluated operand
3690 // [...]
3691 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003692
Douglas Gregorb98b1992009-08-11 05:31:07 +00003693 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3694 if (SubExpr.isInvalid())
3695 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003696
Douglas Gregorb98b1992009-08-11 05:31:07 +00003697 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3698 return SemaRef.Owned(E->Retain());
3699 }
Mike Stump1eb44332009-09-09 15:08:12 +00003700
Douglas Gregorb98b1992009-08-11 05:31:07 +00003701 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3702 E->isSizeOf(),
3703 E->getSourceRange());
3704}
Mike Stump1eb44332009-09-09 15:08:12 +00003705
Douglas Gregorb98b1992009-08-11 05:31:07 +00003706template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003707Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003708TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003709 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3710 if (LHS.isInvalid())
3711 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003712
Douglas Gregorb98b1992009-08-11 05:31:07 +00003713 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3714 if (RHS.isInvalid())
3715 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003716
3717
Douglas Gregorb98b1992009-08-11 05:31:07 +00003718 if (!getDerived().AlwaysRebuild() &&
3719 LHS.get() == E->getLHS() &&
3720 RHS.get() == E->getRHS())
3721 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003722
Douglas Gregorb98b1992009-08-11 05:31:07 +00003723 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3724 /*FIXME:*/E->getLHS()->getLocStart(),
3725 move(RHS),
3726 E->getRBracketLoc());
3727}
Mike Stump1eb44332009-09-09 15:08:12 +00003728
3729template<typename Derived>
3730Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003731TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003732 // Transform the callee.
3733 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3734 if (Callee.isInvalid())
3735 return SemaRef.ExprError();
3736
3737 // Transform arguments.
3738 bool ArgChanged = false;
3739 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3740 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3741 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3742 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3743 if (Arg.isInvalid())
3744 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003745
Douglas Gregorb98b1992009-08-11 05:31:07 +00003746 // FIXME: Wrong source location information for the ','.
3747 FakeCommaLocs.push_back(
3748 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00003749
3750 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003751 Args.push_back(Arg.takeAs<Expr>());
3752 }
Mike Stump1eb44332009-09-09 15:08:12 +00003753
Douglas Gregorb98b1992009-08-11 05:31:07 +00003754 if (!getDerived().AlwaysRebuild() &&
3755 Callee.get() == E->getCallee() &&
3756 !ArgChanged)
3757 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003758
Douglas Gregorb98b1992009-08-11 05:31:07 +00003759 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00003760 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003761 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3762 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3763 move_arg(Args),
3764 FakeCommaLocs.data(),
3765 E->getRParenLoc());
3766}
Mike Stump1eb44332009-09-09 15:08:12 +00003767
3768template<typename Derived>
3769Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003770TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003771 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3772 if (Base.isInvalid())
3773 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003774
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003775 NestedNameSpecifier *Qualifier = 0;
3776 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00003777 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003778 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3779 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00003780 if (Qualifier == 0)
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003781 return SemaRef.ExprError();
3782 }
Mike Stump1eb44332009-09-09 15:08:12 +00003783
Eli Friedmanf595cc42009-12-04 06:40:45 +00003784 ValueDecl *Member
3785 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00003786 if (!Member)
3787 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003788
Douglas Gregorb98b1992009-08-11 05:31:07 +00003789 if (!getDerived().AlwaysRebuild() &&
3790 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003791 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003792 Member == E->getMemberDecl() &&
Anders Carlsson1f240322009-12-22 05:24:09 +00003793 !E->hasExplicitTemplateArgumentList()) {
3794
3795 // Mark it referenced in the new context regardless.
3796 // FIXME: this is a bit instantiation-specific.
3797 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00003798 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00003799 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00003800
John McCalld5532b62009-11-23 01:53:49 +00003801 TemplateArgumentListInfo TransArgs;
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003802 if (E->hasExplicitTemplateArgumentList()) {
John McCalld5532b62009-11-23 01:53:49 +00003803 TransArgs.setLAngleLoc(E->getLAngleLoc());
3804 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003805 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00003806 TemplateArgumentLoc Loc;
3807 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003808 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00003809 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003810 }
3811 }
3812
Douglas Gregorb98b1992009-08-11 05:31:07 +00003813 // FIXME: Bogus source location for the operator
3814 SourceLocation FakeOperatorLoc
3815 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3816
John McCallc2233c52010-01-15 08:34:02 +00003817 // FIXME: to do this check properly, we will need to preserve the
3818 // first-qualifier-in-scope here, just in case we had a dependent
3819 // base (and therefore couldn't do the check) and a
3820 // nested-name-qualifier (and therefore could do the lookup).
3821 NamedDecl *FirstQualifierInScope = 0;
3822
Douglas Gregorb98b1992009-08-11 05:31:07 +00003823 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3824 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003825 Qualifier,
3826 E->getQualifierRange(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003827 E->getMemberLoc(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003828 Member,
John McCalld5532b62009-11-23 01:53:49 +00003829 (E->hasExplicitTemplateArgumentList()
3830 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00003831 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003832}
Mike Stump1eb44332009-09-09 15:08:12 +00003833
Douglas Gregorb98b1992009-08-11 05:31:07 +00003834template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00003835Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003836TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003837 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3838 if (LHS.isInvalid())
3839 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003840
Douglas Gregorb98b1992009-08-11 05:31:07 +00003841 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3842 if (RHS.isInvalid())
3843 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003844
Douglas Gregorb98b1992009-08-11 05:31:07 +00003845 if (!getDerived().AlwaysRebuild() &&
3846 LHS.get() == E->getLHS() &&
3847 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00003848 return SemaRef.Owned(E->Retain());
3849
Douglas Gregorb98b1992009-08-11 05:31:07 +00003850 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3851 move(LHS), move(RHS));
3852}
3853
Mike Stump1eb44332009-09-09 15:08:12 +00003854template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00003855Sema::OwningExprResult
3856TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00003857 CompoundAssignOperator *E) {
3858 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003859}
Mike Stump1eb44332009-09-09 15:08:12 +00003860
Douglas Gregorb98b1992009-08-11 05:31:07 +00003861template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003862Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003863TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003864 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3865 if (Cond.isInvalid())
3866 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003867
Douglas Gregorb98b1992009-08-11 05:31:07 +00003868 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3869 if (LHS.isInvalid())
3870 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003871
Douglas Gregorb98b1992009-08-11 05:31:07 +00003872 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3873 if (RHS.isInvalid())
3874 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003875
Douglas Gregorb98b1992009-08-11 05:31:07 +00003876 if (!getDerived().AlwaysRebuild() &&
3877 Cond.get() == E->getCond() &&
3878 LHS.get() == E->getLHS() &&
3879 RHS.get() == E->getRHS())
3880 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003881
3882 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00003883 E->getQuestionLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00003884 move(LHS),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00003885 E->getColonLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003886 move(RHS));
3887}
Mike Stump1eb44332009-09-09 15:08:12 +00003888
3889template<typename Derived>
3890Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003891TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00003892 // Implicit casts are eliminated during transformation, since they
3893 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00003894 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003895}
Mike Stump1eb44332009-09-09 15:08:12 +00003896
Douglas Gregorb98b1992009-08-11 05:31:07 +00003897template<typename Derived>
3898Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003899TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00003900 TypeSourceInfo *OldT;
3901 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00003902 {
3903 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00003904 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003905 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3906 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00003907
John McCall9d125032010-01-15 18:39:57 +00003908 OldT = E->getTypeInfoAsWritten();
3909 NewT = getDerived().TransformType(OldT);
3910 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003911 return SemaRef.ExprError();
3912 }
Mike Stump1eb44332009-09-09 15:08:12 +00003913
Douglas Gregora88cfbf2009-12-12 18:16:41 +00003914 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00003915 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003916 if (SubExpr.isInvalid())
3917 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003918
Douglas Gregorb98b1992009-08-11 05:31:07 +00003919 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00003920 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00003921 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003922 return SemaRef.Owned(E->Retain());
3923
John McCall9d125032010-01-15 18:39:57 +00003924 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
3925 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00003926 E->getRParenLoc(),
3927 move(SubExpr));
3928}
Mike Stump1eb44332009-09-09 15:08:12 +00003929
Douglas Gregorb98b1992009-08-11 05:31:07 +00003930template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003931Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003932TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00003933 TypeSourceInfo *OldT = E->getTypeSourceInfo();
3934 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
3935 if (!NewT)
3936 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003937
Douglas Gregorb98b1992009-08-11 05:31:07 +00003938 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3939 if (Init.isInvalid())
3940 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003941
Douglas Gregorb98b1992009-08-11 05:31:07 +00003942 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00003943 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00003944 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00003945 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003946
John McCall1d7d8d62010-01-19 22:33:45 +00003947 // Note: the expression type doesn't necessarily match the
3948 // type-as-written, but that's okay, because it should always be
3949 // derivable from the initializer.
3950
John McCall42f56b52010-01-18 19:35:47 +00003951 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00003952 /*FIXME:*/E->getInitializer()->getLocEnd(),
3953 move(Init));
3954}
Mike Stump1eb44332009-09-09 15:08:12 +00003955
Douglas Gregorb98b1992009-08-11 05:31:07 +00003956template<typename Derived>
3957Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003958TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003959 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3960 if (Base.isInvalid())
3961 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003962
Douglas Gregorb98b1992009-08-11 05:31:07 +00003963 if (!getDerived().AlwaysRebuild() &&
3964 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00003965 return SemaRef.Owned(E->Retain());
3966
Douglas Gregorb98b1992009-08-11 05:31:07 +00003967 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00003968 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003969 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3970 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3971 E->getAccessorLoc(),
3972 E->getAccessor());
3973}
Mike Stump1eb44332009-09-09 15:08:12 +00003974
Douglas Gregorb98b1992009-08-11 05:31:07 +00003975template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003976Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003977TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003978 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00003979
Douglas Gregorb98b1992009-08-11 05:31:07 +00003980 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3981 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3982 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3983 if (Init.isInvalid())
3984 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003985
Douglas Gregorb98b1992009-08-11 05:31:07 +00003986 InitChanged = InitChanged || Init.get() != E->getInit(I);
3987 Inits.push_back(Init.takeAs<Expr>());
3988 }
Mike Stump1eb44332009-09-09 15:08:12 +00003989
Douglas Gregorb98b1992009-08-11 05:31:07 +00003990 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003991 return SemaRef.Owned(E->Retain());
3992
Douglas Gregorb98b1992009-08-11 05:31:07 +00003993 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00003994 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003995}
Mike Stump1eb44332009-09-09 15:08:12 +00003996
Douglas Gregorb98b1992009-08-11 05:31:07 +00003997template<typename Derived>
3998Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003999TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004000 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004001
Douglas Gregor43959a92009-08-20 07:17:43 +00004002 // transform the initializer value
Douglas Gregorb98b1992009-08-11 05:31:07 +00004003 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4004 if (Init.isInvalid())
4005 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004006
Douglas Gregor43959a92009-08-20 07:17:43 +00004007 // transform the designators.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004008 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4009 bool ExprChanged = false;
4010 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4011 DEnd = E->designators_end();
4012 D != DEnd; ++D) {
4013 if (D->isFieldDesignator()) {
4014 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4015 D->getDotLoc(),
4016 D->getFieldLoc()));
4017 continue;
4018 }
Mike Stump1eb44332009-09-09 15:08:12 +00004019
Douglas Gregorb98b1992009-08-11 05:31:07 +00004020 if (D->isArrayDesignator()) {
4021 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4022 if (Index.isInvalid())
4023 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004024
4025 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004026 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004027
Douglas Gregorb98b1992009-08-11 05:31:07 +00004028 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4029 ArrayExprs.push_back(Index.release());
4030 continue;
4031 }
Mike Stump1eb44332009-09-09 15:08:12 +00004032
Douglas Gregorb98b1992009-08-11 05:31:07 +00004033 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump1eb44332009-09-09 15:08:12 +00004034 OwningExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004035 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4036 if (Start.isInvalid())
4037 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004038
Douglas Gregorb98b1992009-08-11 05:31:07 +00004039 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4040 if (End.isInvalid())
4041 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004042
4043 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004044 End.get(),
4045 D->getLBracketLoc(),
4046 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004047
Douglas Gregorb98b1992009-08-11 05:31:07 +00004048 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4049 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004050
Douglas Gregorb98b1992009-08-11 05:31:07 +00004051 ArrayExprs.push_back(Start.release());
4052 ArrayExprs.push_back(End.release());
4053 }
Mike Stump1eb44332009-09-09 15:08:12 +00004054
Douglas Gregorb98b1992009-08-11 05:31:07 +00004055 if (!getDerived().AlwaysRebuild() &&
4056 Init.get() == E->getInit() &&
4057 !ExprChanged)
4058 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004059
Douglas Gregorb98b1992009-08-11 05:31:07 +00004060 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4061 E->getEqualOrColonLoc(),
4062 E->usesGNUSyntax(), move(Init));
4063}
Mike Stump1eb44332009-09-09 15:08:12 +00004064
Douglas Gregorb98b1992009-08-11 05:31:07 +00004065template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004066Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004067TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004068 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004069 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4070
4071 // FIXME: Will we ever have proper type location here? Will we actually
4072 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004073 QualType T = getDerived().TransformType(E->getType());
4074 if (T.isNull())
4075 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004076
Douglas Gregorb98b1992009-08-11 05:31:07 +00004077 if (!getDerived().AlwaysRebuild() &&
4078 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004079 return SemaRef.Owned(E->Retain());
4080
Douglas Gregorb98b1992009-08-11 05:31:07 +00004081 return getDerived().RebuildImplicitValueInitExpr(T);
4082}
Mike Stump1eb44332009-09-09 15:08:12 +00004083
Douglas Gregorb98b1992009-08-11 05:31:07 +00004084template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004085Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004086TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004087 // FIXME: Do we want the type as written?
4088 QualType T;
Mike Stump1eb44332009-09-09 15:08:12 +00004089
Douglas Gregorb98b1992009-08-11 05:31:07 +00004090 {
4091 // FIXME: Source location isn't quite accurate.
4092 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4093 T = getDerived().TransformType(E->getType());
4094 if (T.isNull())
4095 return SemaRef.ExprError();
4096 }
Mike Stump1eb44332009-09-09 15:08:12 +00004097
Douglas Gregorb98b1992009-08-11 05:31:07 +00004098 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4099 if (SubExpr.isInvalid())
4100 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004101
Douglas Gregorb98b1992009-08-11 05:31:07 +00004102 if (!getDerived().AlwaysRebuild() &&
4103 T == E->getType() &&
4104 SubExpr.get() == E->getSubExpr())
4105 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004106
Douglas Gregorb98b1992009-08-11 05:31:07 +00004107 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4108 T, E->getRParenLoc());
4109}
4110
4111template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004112Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004113TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004114 bool ArgumentChanged = false;
4115 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4116 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4117 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4118 if (Init.isInvalid())
4119 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004120
Douglas Gregorb98b1992009-08-11 05:31:07 +00004121 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4122 Inits.push_back(Init.takeAs<Expr>());
4123 }
Mike Stump1eb44332009-09-09 15:08:12 +00004124
Douglas Gregorb98b1992009-08-11 05:31:07 +00004125 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4126 move_arg(Inits),
4127 E->getRParenLoc());
4128}
Mike Stump1eb44332009-09-09 15:08:12 +00004129
Douglas Gregorb98b1992009-08-11 05:31:07 +00004130/// \brief Transform an address-of-label expression.
4131///
4132/// By default, the transformation of an address-of-label expression always
4133/// rebuilds the expression, so that the label identifier can be resolved to
4134/// the corresponding label statement by semantic analysis.
4135template<typename Derived>
4136Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004137TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004138 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4139 E->getLabel());
4140}
Mike Stump1eb44332009-09-09 15:08:12 +00004141
4142template<typename Derived>
Douglas Gregorc86a6e92009-11-04 07:01:15 +00004143Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004144TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004145 OwningStmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004146 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4147 if (SubStmt.isInvalid())
4148 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004149
Douglas Gregorb98b1992009-08-11 05:31:07 +00004150 if (!getDerived().AlwaysRebuild() &&
4151 SubStmt.get() == E->getSubStmt())
4152 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004153
4154 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004155 move(SubStmt),
4156 E->getRParenLoc());
4157}
Mike Stump1eb44332009-09-09 15:08:12 +00004158
Douglas Gregorb98b1992009-08-11 05:31:07 +00004159template<typename Derived>
4160Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004161TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004162 QualType T1, T2;
4163 {
4164 // FIXME: Source location isn't quite accurate.
4165 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004166
Douglas Gregorb98b1992009-08-11 05:31:07 +00004167 T1 = getDerived().TransformType(E->getArgType1());
4168 if (T1.isNull())
4169 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004170
Douglas Gregorb98b1992009-08-11 05:31:07 +00004171 T2 = getDerived().TransformType(E->getArgType2());
4172 if (T2.isNull())
4173 return SemaRef.ExprError();
4174 }
4175
4176 if (!getDerived().AlwaysRebuild() &&
4177 T1 == E->getArgType1() &&
4178 T2 == E->getArgType2())
Mike Stump1eb44332009-09-09 15:08:12 +00004179 return SemaRef.Owned(E->Retain());
4180
Douglas Gregorb98b1992009-08-11 05:31:07 +00004181 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4182 T1, T2, E->getRParenLoc());
4183}
Mike Stump1eb44332009-09-09 15:08:12 +00004184
Douglas Gregorb98b1992009-08-11 05:31:07 +00004185template<typename Derived>
4186Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004187TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004188 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4189 if (Cond.isInvalid())
4190 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004191
Douglas Gregorb98b1992009-08-11 05:31:07 +00004192 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4193 if (LHS.isInvalid())
4194 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004195
Douglas Gregorb98b1992009-08-11 05:31:07 +00004196 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4197 if (RHS.isInvalid())
4198 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004199
Douglas Gregorb98b1992009-08-11 05:31:07 +00004200 if (!getDerived().AlwaysRebuild() &&
4201 Cond.get() == E->getCond() &&
4202 LHS.get() == E->getLHS() &&
4203 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004204 return SemaRef.Owned(E->Retain());
4205
Douglas Gregorb98b1992009-08-11 05:31:07 +00004206 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4207 move(Cond), move(LHS), move(RHS),
4208 E->getRParenLoc());
4209}
Mike Stump1eb44332009-09-09 15:08:12 +00004210
Douglas Gregorb98b1992009-08-11 05:31:07 +00004211template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004212Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004213TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004214 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004215}
4216
4217template<typename Derived>
4218Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004219TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004220 switch (E->getOperator()) {
4221 case OO_New:
4222 case OO_Delete:
4223 case OO_Array_New:
4224 case OO_Array_Delete:
4225 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4226 return SemaRef.ExprError();
4227
4228 case OO_Call: {
4229 // This is a call to an object's operator().
4230 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4231
4232 // Transform the object itself.
4233 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4234 if (Object.isInvalid())
4235 return SemaRef.ExprError();
4236
4237 // FIXME: Poor location information
4238 SourceLocation FakeLParenLoc
4239 = SemaRef.PP.getLocForEndOfToken(
4240 static_cast<Expr *>(Object.get())->getLocEnd());
4241
4242 // Transform the call arguments.
4243 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4244 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4245 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004246 if (getDerived().DropCallArgument(E->getArg(I)))
4247 break;
4248
Douglas Gregor668d6d92009-12-13 20:44:55 +00004249 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4250 if (Arg.isInvalid())
4251 return SemaRef.ExprError();
4252
4253 // FIXME: Poor source location information.
4254 SourceLocation FakeCommaLoc
4255 = SemaRef.PP.getLocForEndOfToken(
4256 static_cast<Expr *>(Arg.get())->getLocEnd());
4257 FakeCommaLocs.push_back(FakeCommaLoc);
4258 Args.push_back(Arg.release());
4259 }
4260
4261 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4262 move_arg(Args),
4263 FakeCommaLocs.data(),
4264 E->getLocEnd());
4265 }
4266
4267#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4268 case OO_##Name:
4269#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4270#include "clang/Basic/OperatorKinds.def"
4271 case OO_Subscript:
4272 // Handled below.
4273 break;
4274
4275 case OO_Conditional:
4276 llvm_unreachable("conditional operator is not actually overloadable");
4277 return SemaRef.ExprError();
4278
4279 case OO_None:
4280 case NUM_OVERLOADED_OPERATORS:
4281 llvm_unreachable("not an overloaded operator?");
4282 return SemaRef.ExprError();
4283 }
4284
Douglas Gregorb98b1992009-08-11 05:31:07 +00004285 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4286 if (Callee.isInvalid())
4287 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004288
John McCall454feb92009-12-08 09:21:05 +00004289 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004290 if (First.isInvalid())
4291 return SemaRef.ExprError();
4292
4293 OwningExprResult Second(SemaRef);
4294 if (E->getNumArgs() == 2) {
4295 Second = getDerived().TransformExpr(E->getArg(1));
4296 if (Second.isInvalid())
4297 return SemaRef.ExprError();
4298 }
Mike Stump1eb44332009-09-09 15:08:12 +00004299
Douglas Gregorb98b1992009-08-11 05:31:07 +00004300 if (!getDerived().AlwaysRebuild() &&
4301 Callee.get() == E->getCallee() &&
4302 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00004303 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4304 return SemaRef.Owned(E->Retain());
4305
Douglas Gregorb98b1992009-08-11 05:31:07 +00004306 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4307 E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004308 move(Callee),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004309 move(First),
4310 move(Second));
4311}
Mike Stump1eb44332009-09-09 15:08:12 +00004312
Douglas Gregorb98b1992009-08-11 05:31:07 +00004313template<typename Derived>
4314Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004315TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4316 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004317}
Mike Stump1eb44332009-09-09 15:08:12 +00004318
Douglas Gregorb98b1992009-08-11 05:31:07 +00004319template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004320Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004321TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004322 TypeSourceInfo *OldT;
4323 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004324 {
4325 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004326 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004327 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4328 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004329
John McCall9d125032010-01-15 18:39:57 +00004330 OldT = E->getTypeInfoAsWritten();
4331 NewT = getDerived().TransformType(OldT);
4332 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004333 return SemaRef.ExprError();
4334 }
Mike Stump1eb44332009-09-09 15:08:12 +00004335
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004336 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004337 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004338 if (SubExpr.isInvalid())
4339 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004340
Douglas Gregorb98b1992009-08-11 05:31:07 +00004341 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004342 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004343 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004344 return SemaRef.Owned(E->Retain());
4345
Douglas Gregorb98b1992009-08-11 05:31:07 +00004346 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00004347 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004348 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4349 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4350 SourceLocation FakeRParenLoc
4351 = SemaRef.PP.getLocForEndOfToken(
4352 E->getSubExpr()->getSourceRange().getEnd());
4353 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004354 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004355 FakeLAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00004356 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004357 FakeRAngleLoc,
4358 FakeRAngleLoc,
4359 move(SubExpr),
4360 FakeRParenLoc);
4361}
Mike Stump1eb44332009-09-09 15:08:12 +00004362
Douglas Gregorb98b1992009-08-11 05:31:07 +00004363template<typename Derived>
4364Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004365TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4366 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004367}
Mike Stump1eb44332009-09-09 15:08:12 +00004368
4369template<typename Derived>
4370Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004371TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4372 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004373}
4374
Douglas Gregorb98b1992009-08-11 05:31:07 +00004375template<typename Derived>
4376Sema::OwningExprResult
4377TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004378 CXXReinterpretCastExpr *E) {
4379 return getDerived().TransformCXXNamedCastExpr(E);
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
John McCall454feb92009-12-08 09:21:05 +00004384TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4385 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004386}
Mike Stump1eb44332009-09-09 15:08:12 +00004387
Douglas Gregorb98b1992009-08-11 05:31:07 +00004388template<typename Derived>
4389Sema::OwningExprResult
4390TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004391 CXXFunctionalCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004392 TypeSourceInfo *OldT;
4393 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004394 {
4395 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004396
John McCall9d125032010-01-15 18:39:57 +00004397 OldT = E->getTypeInfoAsWritten();
4398 NewT = getDerived().TransformType(OldT);
4399 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004400 return SemaRef.ExprError();
4401 }
Mike Stump1eb44332009-09-09 15:08:12 +00004402
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004403 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004404 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004405 if (SubExpr.isInvalid())
4406 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004407
Douglas Gregorb98b1992009-08-11 05:31:07 +00004408 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004409 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004410 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004411 return SemaRef.Owned(E->Retain());
4412
Douglas Gregorb98b1992009-08-11 05:31:07 +00004413 // FIXME: The end of the type's source range is wrong
4414 return getDerived().RebuildCXXFunctionalCastExpr(
4415 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall9d125032010-01-15 18:39:57 +00004416 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004417 /*FIXME:*/E->getSubExpr()->getLocStart(),
4418 move(SubExpr),
4419 E->getRParenLoc());
4420}
Mike Stump1eb44332009-09-09 15:08:12 +00004421
Douglas Gregorb98b1992009-08-11 05:31:07 +00004422template<typename Derived>
4423Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004424TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004425 if (E->isTypeOperand()) {
4426 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004427
Douglas Gregorb98b1992009-08-11 05:31:07 +00004428 QualType T = getDerived().TransformType(E->getTypeOperand());
4429 if (T.isNull())
4430 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004431
Douglas Gregorb98b1992009-08-11 05:31:07 +00004432 if (!getDerived().AlwaysRebuild() &&
4433 T == E->getTypeOperand())
4434 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004435
Douglas Gregorb98b1992009-08-11 05:31:07 +00004436 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4437 /*FIXME:*/E->getLocStart(),
4438 T,
4439 E->getLocEnd());
4440 }
Mike Stump1eb44332009-09-09 15:08:12 +00004441
Douglas Gregorb98b1992009-08-11 05:31:07 +00004442 // We don't know whether the expression is potentially evaluated until
4443 // after we perform semantic analysis, so the expression is potentially
4444 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00004445 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004446 Action::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004447
Douglas Gregorb98b1992009-08-11 05:31:07 +00004448 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4449 if (SubExpr.isInvalid())
4450 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004451
Douglas Gregorb98b1992009-08-11 05:31:07 +00004452 if (!getDerived().AlwaysRebuild() &&
4453 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00004454 return SemaRef.Owned(E->Retain());
4455
Douglas Gregorb98b1992009-08-11 05:31:07 +00004456 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4457 /*FIXME:*/E->getLocStart(),
4458 move(SubExpr),
4459 E->getLocEnd());
4460}
4461
4462template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004463Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004464TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004465 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004466}
Mike Stump1eb44332009-09-09 15:08:12 +00004467
Douglas Gregorb98b1992009-08-11 05:31:07 +00004468template<typename Derived>
4469Sema::OwningExprResult
4470TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00004471 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004472 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004473}
Mike Stump1eb44332009-09-09 15:08:12 +00004474
Douglas Gregorb98b1992009-08-11 05:31:07 +00004475template<typename Derived>
4476Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004477TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004478 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004479
Douglas Gregorb98b1992009-08-11 05:31:07 +00004480 QualType T = getDerived().TransformType(E->getType());
4481 if (T.isNull())
4482 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004483
Douglas Gregorb98b1992009-08-11 05:31:07 +00004484 if (!getDerived().AlwaysRebuild() &&
4485 T == E->getType())
4486 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004487
Douglas Gregor828a1972010-01-07 23:12:05 +00004488 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004489}
Mike Stump1eb44332009-09-09 15:08:12 +00004490
Douglas Gregorb98b1992009-08-11 05:31:07 +00004491template<typename Derived>
4492Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004493TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004494 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4495 if (SubExpr.isInvalid())
4496 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004497
Douglas Gregorb98b1992009-08-11 05:31:07 +00004498 if (!getDerived().AlwaysRebuild() &&
4499 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004500 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004501
4502 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4503}
Mike Stump1eb44332009-09-09 15:08:12 +00004504
Douglas Gregorb98b1992009-08-11 05:31:07 +00004505template<typename Derived>
4506Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004507TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004508 ParmVarDecl *Param
Douglas Gregorb98b1992009-08-11 05:31:07 +00004509 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4510 if (!Param)
4511 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004512
Chandler Carruth53cb6f82010-02-08 06:42:49 +00004513 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004514 Param == E->getParam())
4515 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004516
Douglas Gregor036aed12009-12-23 23:03:06 +00004517 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004518}
Mike Stump1eb44332009-09-09 15:08:12 +00004519
Douglas Gregorb98b1992009-08-11 05:31:07 +00004520template<typename Derived>
4521Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004522TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004523 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4524
4525 QualType T = getDerived().TransformType(E->getType());
4526 if (T.isNull())
4527 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004528
Douglas Gregorb98b1992009-08-11 05:31:07 +00004529 if (!getDerived().AlwaysRebuild() &&
4530 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004531 return SemaRef.Owned(E->Retain());
4532
4533 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004534 /*FIXME:*/E->getTypeBeginLoc(),
4535 T,
4536 E->getRParenLoc());
4537}
Mike Stump1eb44332009-09-09 15:08:12 +00004538
Douglas Gregorb98b1992009-08-11 05:31:07 +00004539template<typename Derived>
4540Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004541TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004542 // Transform the type that we're allocating
4543 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4544 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4545 if (AllocType.isNull())
4546 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004547
Douglas Gregorb98b1992009-08-11 05:31:07 +00004548 // Transform the size of the array we're allocating (if any).
4549 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4550 if (ArraySize.isInvalid())
4551 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004552
Douglas Gregorb98b1992009-08-11 05:31:07 +00004553 // Transform the placement arguments (if any).
4554 bool ArgumentChanged = false;
4555 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4556 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4557 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4558 if (Arg.isInvalid())
4559 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004560
Douglas Gregorb98b1992009-08-11 05:31:07 +00004561 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4562 PlacementArgs.push_back(Arg.take());
4563 }
Mike Stump1eb44332009-09-09 15:08:12 +00004564
Douglas Gregor43959a92009-08-20 07:17:43 +00004565 // transform the constructor arguments (if any).
Douglas Gregorb98b1992009-08-11 05:31:07 +00004566 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4567 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4568 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4569 if (Arg.isInvalid())
4570 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004571
Douglas Gregorb98b1992009-08-11 05:31:07 +00004572 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4573 ConstructorArgs.push_back(Arg.take());
4574 }
Mike Stump1eb44332009-09-09 15:08:12 +00004575
Douglas Gregorb98b1992009-08-11 05:31:07 +00004576 if (!getDerived().AlwaysRebuild() &&
4577 AllocType == E->getAllocatedType() &&
4578 ArraySize.get() == E->getArraySize() &&
4579 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004580 return SemaRef.Owned(E->Retain());
4581
Douglas Gregor5b5ad842009-12-22 17:13:37 +00004582 if (!ArraySize.get()) {
4583 // If no array size was specified, but the new expression was
4584 // instantiated with an array type (e.g., "new T" where T is
4585 // instantiated with "int[4]"), extract the outer bound from the
4586 // array type as our array size. We do this with constant and
4587 // dependently-sized array types.
4588 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4589 if (!ArrayT) {
4590 // Do nothing
4591 } else if (const ConstantArrayType *ConsArrayT
4592 = dyn_cast<ConstantArrayType>(ArrayT)) {
4593 ArraySize
4594 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4595 ConsArrayT->getSize(),
4596 SemaRef.Context.getSizeType(),
4597 /*FIXME:*/E->getLocStart()));
4598 AllocType = ConsArrayT->getElementType();
4599 } else if (const DependentSizedArrayType *DepArrayT
4600 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4601 if (DepArrayT->getSizeExpr()) {
4602 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4603 AllocType = DepArrayT->getElementType();
4604 }
4605 }
4606 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004607 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4608 E->isGlobalNew(),
4609 /*FIXME:*/E->getLocStart(),
4610 move_arg(PlacementArgs),
4611 /*FIXME:*/E->getLocStart(),
4612 E->isParenTypeId(),
4613 AllocType,
4614 /*FIXME:*/E->getLocStart(),
4615 /*FIXME:*/SourceRange(),
4616 move(ArraySize),
4617 /*FIXME:*/E->getLocStart(),
4618 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00004619 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004620}
Mike Stump1eb44332009-09-09 15:08:12 +00004621
Douglas Gregorb98b1992009-08-11 05:31:07 +00004622template<typename Derived>
4623Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004624TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004625 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4626 if (Operand.isInvalid())
4627 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004628
Douglas Gregorb98b1992009-08-11 05:31:07 +00004629 if (!getDerived().AlwaysRebuild() &&
Mike Stump1eb44332009-09-09 15:08:12 +00004630 Operand.get() == E->getArgument())
4631 return SemaRef.Owned(E->Retain());
4632
Douglas Gregorb98b1992009-08-11 05:31:07 +00004633 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4634 E->isGlobalDelete(),
4635 E->isArrayForm(),
4636 move(Operand));
4637}
Mike Stump1eb44332009-09-09 15:08:12 +00004638
Douglas Gregorb98b1992009-08-11 05:31:07 +00004639template<typename Derived>
4640Sema::OwningExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00004641TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00004642 CXXPseudoDestructorExpr *E) {
Douglas Gregora71d8192009-09-04 17:36:40 +00004643 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4644 if (Base.isInvalid())
4645 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004646
Douglas Gregora71d8192009-09-04 17:36:40 +00004647 NestedNameSpecifier *Qualifier
4648 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4649 E->getQualifierRange());
4650 if (E->getQualifier() && !Qualifier)
4651 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004652
Douglas Gregora71d8192009-09-04 17:36:40 +00004653 QualType DestroyedType;
4654 {
4655 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4656 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4657 if (DestroyedType.isNull())
4658 return SemaRef.ExprError();
4659 }
Mike Stump1eb44332009-09-09 15:08:12 +00004660
Douglas Gregora71d8192009-09-04 17:36:40 +00004661 if (!getDerived().AlwaysRebuild() &&
4662 Base.get() == E->getBase() &&
4663 Qualifier == E->getQualifier() &&
4664 DestroyedType == E->getDestroyedType())
4665 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004666
Douglas Gregora71d8192009-09-04 17:36:40 +00004667 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4668 E->getOperatorLoc(),
4669 E->isArrow(),
4670 E->getDestroyedTypeLoc(),
4671 DestroyedType,
4672 Qualifier,
4673 E->getQualifierRange());
4674}
Mike Stump1eb44332009-09-09 15:08:12 +00004675
Douglas Gregora71d8192009-09-04 17:36:40 +00004676template<typename Derived>
4677Sema::OwningExprResult
John McCallba135432009-11-21 08:51:07 +00004678TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00004679 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00004680 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4681
4682 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4683 Sema::LookupOrdinaryName);
4684
4685 // Transform all the decls.
4686 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4687 E = Old->decls_end(); I != E; ++I) {
4688 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall9f54ad42009-12-10 09:41:52 +00004689 if (!InstD) {
4690 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4691 // This can happen because of dependent hiding.
4692 if (isa<UsingShadowDecl>(*I))
4693 continue;
4694 else
4695 return SemaRef.ExprError();
4696 }
John McCallf7a1a742009-11-24 19:00:30 +00004697
4698 // Expand using declarations.
4699 if (isa<UsingDecl>(InstD)) {
4700 UsingDecl *UD = cast<UsingDecl>(InstD);
4701 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4702 E = UD->shadow_end(); I != E; ++I)
4703 R.addDecl(*I);
4704 continue;
4705 }
4706
4707 R.addDecl(InstD);
4708 }
4709
4710 // Resolve a kind, but don't do any further analysis. If it's
4711 // ambiguous, the callee needs to deal with it.
4712 R.resolveKind();
4713
4714 // Rebuild the nested-name qualifier, if present.
4715 CXXScopeSpec SS;
4716 NestedNameSpecifier *Qualifier = 0;
4717 if (Old->getQualifier()) {
4718 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4719 Old->getQualifierRange());
4720 if (!Qualifier)
4721 return SemaRef.ExprError();
4722
4723 SS.setScopeRep(Qualifier);
4724 SS.setRange(Old->getQualifierRange());
4725 }
4726
4727 // If we have no template arguments, it's a normal declaration name.
4728 if (!Old->hasExplicitTemplateArgs())
4729 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4730
4731 // If we have template arguments, rebuild them, then rebuild the
4732 // templateid expression.
4733 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4734 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4735 TemplateArgumentLoc Loc;
4736 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4737 return SemaRef.ExprError();
4738 TransArgs.addArgument(Loc);
4739 }
4740
4741 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4742 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004743}
Mike Stump1eb44332009-09-09 15:08:12 +00004744
Douglas Gregorb98b1992009-08-11 05:31:07 +00004745template<typename Derived>
4746Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004747TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004748 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004749
Douglas Gregorb98b1992009-08-11 05:31:07 +00004750 QualType T = getDerived().TransformType(E->getQueriedType());
4751 if (T.isNull())
4752 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004753
Douglas Gregorb98b1992009-08-11 05:31:07 +00004754 if (!getDerived().AlwaysRebuild() &&
4755 T == E->getQueriedType())
4756 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004757
Douglas Gregorb98b1992009-08-11 05:31:07 +00004758 // FIXME: Bad location information
4759 SourceLocation FakeLParenLoc
4760 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump1eb44332009-09-09 15:08:12 +00004761
4762 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004763 E->getLocStart(),
4764 /*FIXME:*/FakeLParenLoc,
4765 T,
4766 E->getLocEnd());
4767}
Mike Stump1eb44332009-09-09 15:08:12 +00004768
Douglas Gregorb98b1992009-08-11 05:31:07 +00004769template<typename Derived>
4770Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00004771TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall454feb92009-12-08 09:21:05 +00004772 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004773 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00004774 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4775 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004776 if (!NNS)
4777 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004778
4779 DeclarationName Name
Douglas Gregor81499bb2009-09-03 22:13:48 +00004780 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4781 if (!Name)
4782 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004783
John McCallf7a1a742009-11-24 19:00:30 +00004784 if (!E->hasExplicitTemplateArgs()) {
4785 if (!getDerived().AlwaysRebuild() &&
4786 NNS == E->getQualifier() &&
4787 Name == E->getDeclName())
4788 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004789
John McCallf7a1a742009-11-24 19:00:30 +00004790 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4791 E->getQualifierRange(),
4792 Name, E->getLocation(),
4793 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00004794 }
John McCalld5532b62009-11-23 01:53:49 +00004795
4796 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004797 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004798 TemplateArgumentLoc Loc;
4799 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb98b1992009-08-11 05:31:07 +00004800 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004801 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004802 }
4803
John McCallf7a1a742009-11-24 19:00:30 +00004804 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4805 E->getQualifierRange(),
4806 Name, E->getLocation(),
4807 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004808}
4809
4810template<typename Derived>
4811Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004812TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00004813 // CXXConstructExprs are always implicit, so when we have a
4814 // 1-argument construction we just transform that argument.
4815 if (E->getNumArgs() == 1 ||
4816 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
4817 return getDerived().TransformExpr(E->getArg(0));
4818
Douglas Gregorb98b1992009-08-11 05:31:07 +00004819 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4820
4821 QualType T = getDerived().TransformType(E->getType());
4822 if (T.isNull())
4823 return SemaRef.ExprError();
4824
4825 CXXConstructorDecl *Constructor
4826 = cast_or_null<CXXConstructorDecl>(
4827 getDerived().TransformDecl(E->getConstructor()));
4828 if (!Constructor)
4829 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004830
Douglas Gregorb98b1992009-08-11 05:31:07 +00004831 bool ArgumentChanged = false;
4832 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00004833 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004834 ArgEnd = E->arg_end();
4835 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004836 if (getDerived().DropCallArgument(*Arg)) {
4837 ArgumentChanged = true;
4838 break;
4839 }
4840
Douglas Gregorb98b1992009-08-11 05:31:07 +00004841 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4842 if (TransArg.isInvalid())
4843 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004844
Douglas Gregorb98b1992009-08-11 05:31:07 +00004845 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4846 Args.push_back(TransArg.takeAs<Expr>());
4847 }
4848
4849 if (!getDerived().AlwaysRebuild() &&
4850 T == E->getType() &&
4851 Constructor == E->getConstructor() &&
4852 !ArgumentChanged)
4853 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004854
Douglas Gregor4411d2e2009-12-14 16:27:04 +00004855 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
4856 Constructor, E->isElidable(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004857 move_arg(Args));
4858}
Mike Stump1eb44332009-09-09 15:08:12 +00004859
Douglas Gregorb98b1992009-08-11 05:31:07 +00004860/// \brief Transform a C++ temporary-binding expression.
4861///
Douglas Gregor51326552009-12-24 18:51:59 +00004862/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
4863/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004864template<typename Derived>
4865Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004866TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00004867 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004868}
Mike Stump1eb44332009-09-09 15:08:12 +00004869
Anders Carlssoneb60edf2010-01-29 02:39:32 +00004870/// \brief Transform a C++ reference-binding expression.
4871///
4872/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
4873/// transform the subexpression and return that.
4874template<typename Derived>
4875Sema::OwningExprResult
4876TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
4877 return getDerived().TransformExpr(E->getSubExpr());
4878}
4879
Mike Stump1eb44332009-09-09 15:08:12 +00004880/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00004881/// be destroyed after the expression is evaluated.
4882///
Douglas Gregor51326552009-12-24 18:51:59 +00004883/// Since CXXExprWithTemporaries nodes are implicitly generated, we
4884/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004885template<typename Derived>
4886Sema::OwningExprResult
4887TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00004888 CXXExprWithTemporaries *E) {
4889 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004890}
Mike Stump1eb44332009-09-09 15:08:12 +00004891
Douglas Gregorb98b1992009-08-11 05:31:07 +00004892template<typename Derived>
4893Sema::OwningExprResult
4894TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall454feb92009-12-08 09:21:05 +00004895 CXXTemporaryObjectExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004896 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4897 QualType T = getDerived().TransformType(E->getType());
4898 if (T.isNull())
4899 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004900
Douglas Gregorb98b1992009-08-11 05:31:07 +00004901 CXXConstructorDecl *Constructor
4902 = cast_or_null<CXXConstructorDecl>(
4903 getDerived().TransformDecl(E->getConstructor()));
4904 if (!Constructor)
4905 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004906
Douglas Gregorb98b1992009-08-11 05:31:07 +00004907 bool ArgumentChanged = false;
4908 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4909 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00004910 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004911 ArgEnd = E->arg_end();
4912 Arg != ArgEnd; ++Arg) {
4913 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4914 if (TransArg.isInvalid())
4915 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004916
Douglas Gregorb98b1992009-08-11 05:31:07 +00004917 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4918 Args.push_back((Expr *)TransArg.release());
4919 }
Mike Stump1eb44332009-09-09 15:08:12 +00004920
Douglas Gregorb98b1992009-08-11 05:31:07 +00004921 if (!getDerived().AlwaysRebuild() &&
4922 T == E->getType() &&
4923 Constructor == E->getConstructor() &&
4924 !ArgumentChanged)
4925 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004926
Douglas Gregorb98b1992009-08-11 05:31:07 +00004927 // FIXME: Bogus location information
4928 SourceLocation CommaLoc;
4929 if (Args.size() > 1) {
4930 Expr *First = (Expr *)Args[0];
Mike Stump1eb44332009-09-09 15:08:12 +00004931 CommaLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004932 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4933 }
4934 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4935 T,
4936 /*FIXME:*/E->getTypeBeginLoc(),
4937 move_arg(Args),
4938 &CommaLoc,
4939 E->getLocEnd());
4940}
Mike Stump1eb44332009-09-09 15:08:12 +00004941
Douglas Gregorb98b1992009-08-11 05:31:07 +00004942template<typename Derived>
4943Sema::OwningExprResult
4944TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00004945 CXXUnresolvedConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004946 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4947 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4948 if (T.isNull())
4949 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004950
Douglas Gregorb98b1992009-08-11 05:31:07 +00004951 bool ArgumentChanged = false;
4952 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4953 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4954 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4955 ArgEnd = E->arg_end();
4956 Arg != ArgEnd; ++Arg) {
4957 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4958 if (TransArg.isInvalid())
4959 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004960
Douglas Gregorb98b1992009-08-11 05:31:07 +00004961 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4962 FakeCommaLocs.push_back(
4963 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4964 Args.push_back(TransArg.takeAs<Expr>());
4965 }
Mike Stump1eb44332009-09-09 15:08:12 +00004966
Douglas Gregorb98b1992009-08-11 05:31:07 +00004967 if (!getDerived().AlwaysRebuild() &&
4968 T == E->getTypeAsWritten() &&
4969 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004970 return SemaRef.Owned(E->Retain());
4971
Douglas Gregorb98b1992009-08-11 05:31:07 +00004972 // FIXME: we're faking the locations of the commas
4973 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4974 T,
4975 E->getLParenLoc(),
4976 move_arg(Args),
4977 FakeCommaLocs.data(),
4978 E->getRParenLoc());
4979}
Mike Stump1eb44332009-09-09 15:08:12 +00004980
Douglas Gregorb98b1992009-08-11 05:31:07 +00004981template<typename Derived>
4982Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00004983TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall454feb92009-12-08 09:21:05 +00004984 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004985 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00004986 OwningExprResult Base(SemaRef, (Expr*) 0);
4987 Expr *OldBase;
4988 QualType BaseType;
4989 QualType ObjectType;
4990 if (!E->isImplicitAccess()) {
4991 OldBase = E->getBase();
4992 Base = getDerived().TransformExpr(OldBase);
4993 if (Base.isInvalid())
4994 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004995
John McCallaa81e162009-12-01 22:10:20 +00004996 // Start the member reference and compute the object's type.
4997 Sema::TypeTy *ObjectTy = 0;
4998 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4999 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005000 E->isArrow()? tok::arrow : tok::period,
John McCallaa81e162009-12-01 22:10:20 +00005001 ObjectTy);
5002 if (Base.isInvalid())
5003 return SemaRef.ExprError();
5004
5005 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5006 BaseType = ((Expr*) Base.get())->getType();
5007 } else {
5008 OldBase = 0;
5009 BaseType = getDerived().TransformType(E->getBaseType());
5010 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5011 }
Mike Stump1eb44332009-09-09 15:08:12 +00005012
Douglas Gregor6cd21982009-10-20 05:58:46 +00005013 // Transform the first part of the nested-name-specifier that qualifies
5014 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005015 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005016 = getDerived().TransformFirstQualifierInScope(
5017 E->getFirstQualifierFoundInScope(),
5018 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005019
Douglas Gregora38c6872009-09-03 16:14:30 +00005020 NestedNameSpecifier *Qualifier = 0;
5021 if (E->getQualifier()) {
5022 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5023 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005024 ObjectType,
5025 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005026 if (!Qualifier)
5027 return SemaRef.ExprError();
5028 }
Mike Stump1eb44332009-09-09 15:08:12 +00005029
5030 DeclarationName Name
Douglas Gregordd62b152009-10-19 22:04:39 +00005031 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCallaa81e162009-12-01 22:10:20 +00005032 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00005033 if (!Name)
5034 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005035
John McCallaa81e162009-12-01 22:10:20 +00005036 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005037 // This is a reference to a member without an explicitly-specified
5038 // template argument list. Optimize for this common case.
5039 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005040 Base.get() == OldBase &&
5041 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005042 Qualifier == E->getQualifier() &&
5043 Name == E->getMember() &&
5044 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005045 return SemaRef.Owned(E->Retain());
5046
John McCall865d4472009-11-19 22:55:06 +00005047 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005048 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005049 E->isArrow(),
5050 E->getOperatorLoc(),
5051 Qualifier,
5052 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005053 FirstQualifierInScope,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005054 Name,
5055 E->getMemberLoc(),
John McCall129e2df2009-11-30 22:42:35 +00005056 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005057 }
5058
John McCalld5532b62009-11-23 01:53:49 +00005059 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005060 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005061 TemplateArgumentLoc Loc;
5062 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005063 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005064 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005065 }
Mike Stump1eb44332009-09-09 15:08:12 +00005066
John McCall865d4472009-11-19 22:55:06 +00005067 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005068 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005069 E->isArrow(),
5070 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005071 Qualifier,
5072 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005073 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005074 Name,
5075 E->getMemberLoc(),
5076 &TransArgs);
5077}
5078
5079template<typename Derived>
5080Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005081TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005082 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005083 OwningExprResult Base(SemaRef, (Expr*) 0);
5084 QualType BaseType;
5085 if (!Old->isImplicitAccess()) {
5086 Base = getDerived().TransformExpr(Old->getBase());
5087 if (Base.isInvalid())
5088 return SemaRef.ExprError();
5089 BaseType = ((Expr*) Base.get())->getType();
5090 } else {
5091 BaseType = getDerived().TransformType(Old->getBaseType());
5092 }
John McCall129e2df2009-11-30 22:42:35 +00005093
5094 NestedNameSpecifier *Qualifier = 0;
5095 if (Old->getQualifier()) {
5096 Qualifier
5097 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
5098 Old->getQualifierRange());
5099 if (Qualifier == 0)
5100 return SemaRef.ExprError();
5101 }
5102
5103 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5104 Sema::LookupOrdinaryName);
5105
5106 // Transform all the decls.
5107 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5108 E = Old->decls_end(); I != E; ++I) {
5109 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall9f54ad42009-12-10 09:41:52 +00005110 if (!InstD) {
5111 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5112 // This can happen because of dependent hiding.
5113 if (isa<UsingShadowDecl>(*I))
5114 continue;
5115 else
5116 return SemaRef.ExprError();
5117 }
John McCall129e2df2009-11-30 22:42:35 +00005118
5119 // Expand using declarations.
5120 if (isa<UsingDecl>(InstD)) {
5121 UsingDecl *UD = cast<UsingDecl>(InstD);
5122 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5123 E = UD->shadow_end(); I != E; ++I)
5124 R.addDecl(*I);
5125 continue;
5126 }
5127
5128 R.addDecl(InstD);
5129 }
5130
5131 R.resolveKind();
5132
5133 TemplateArgumentListInfo TransArgs;
5134 if (Old->hasExplicitTemplateArgs()) {
5135 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5136 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5137 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5138 TemplateArgumentLoc Loc;
5139 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5140 Loc))
5141 return SemaRef.ExprError();
5142 TransArgs.addArgument(Loc);
5143 }
5144 }
John McCallc2233c52010-01-15 08:34:02 +00005145
5146 // FIXME: to do this check properly, we will need to preserve the
5147 // first-qualifier-in-scope here, just in case we had a dependent
5148 // base (and therefore couldn't do the check) and a
5149 // nested-name-qualifier (and therefore could do the lookup).
5150 NamedDecl *FirstQualifierInScope = 0;
John McCall129e2df2009-11-30 22:42:35 +00005151
5152 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005153 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00005154 Old->getOperatorLoc(),
5155 Old->isArrow(),
5156 Qualifier,
5157 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00005158 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005159 R,
5160 (Old->hasExplicitTemplateArgs()
5161 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005162}
5163
5164template<typename Derived>
5165Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005166TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005167 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005168}
5169
Mike Stump1eb44332009-09-09 15:08:12 +00005170template<typename Derived>
5171Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005172TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005173 // FIXME: poor source location
5174 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5175 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5176 if (EncodedType.isNull())
5177 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005178
Douglas Gregorb98b1992009-08-11 05:31:07 +00005179 if (!getDerived().AlwaysRebuild() &&
5180 EncodedType == E->getEncodedType())
Mike Stump1eb44332009-09-09 15:08:12 +00005181 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005182
5183 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5184 EncodedType,
5185 E->getRParenLoc());
5186}
Mike Stump1eb44332009-09-09 15:08:12 +00005187
Douglas Gregorb98b1992009-08-11 05:31:07 +00005188template<typename Derived>
5189Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005190TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005191 // FIXME: Implement this!
5192 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005193 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005194}
5195
Mike Stump1eb44332009-09-09 15:08:12 +00005196template<typename Derived>
5197Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005198TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005199 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005200}
5201
Mike Stump1eb44332009-09-09 15:08:12 +00005202template<typename Derived>
5203Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005204TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005205 ObjCProtocolDecl *Protocol
Douglas Gregorb98b1992009-08-11 05:31:07 +00005206 = cast_or_null<ObjCProtocolDecl>(
5207 getDerived().TransformDecl(E->getProtocol()));
5208 if (!Protocol)
5209 return SemaRef.ExprError();
5210
5211 if (!getDerived().AlwaysRebuild() &&
5212 Protocol == E->getProtocol())
Mike Stump1eb44332009-09-09 15:08:12 +00005213 return SemaRef.Owned(E->Retain());
5214
Douglas Gregorb98b1992009-08-11 05:31:07 +00005215 return getDerived().RebuildObjCProtocolExpr(Protocol,
5216 E->getAtLoc(),
5217 /*FIXME:*/E->getAtLoc(),
5218 /*FIXME:*/E->getAtLoc(),
5219 E->getRParenLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00005220
Douglas Gregorb98b1992009-08-11 05:31:07 +00005221}
5222
Mike Stump1eb44332009-09-09 15:08:12 +00005223template<typename Derived>
5224Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005225TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005226 // FIXME: Implement this!
5227 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005228 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005229}
5230
Mike Stump1eb44332009-09-09 15:08:12 +00005231template<typename Derived>
5232Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005233TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005234 // FIXME: Implement this!
5235 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005236 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005237}
5238
Mike Stump1eb44332009-09-09 15:08:12 +00005239template<typename Derived>
5240Sema::OwningExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00005241TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00005242 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005243 // FIXME: Implement this!
5244 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005245 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005246}
5247
Mike Stump1eb44332009-09-09 15:08:12 +00005248template<typename Derived>
5249Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005250TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005251 // FIXME: Implement this!
5252 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005253 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005254}
5255
Mike Stump1eb44332009-09-09 15:08:12 +00005256template<typename Derived>
5257Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005258TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005259 // FIXME: Implement this!
5260 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005261 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005262}
5263
Mike Stump1eb44332009-09-09 15:08:12 +00005264template<typename Derived>
5265Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005266TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005267 bool ArgumentChanged = false;
5268 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5269 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5270 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5271 if (SubExpr.isInvalid())
5272 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005273
Douglas Gregorb98b1992009-08-11 05:31:07 +00005274 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5275 SubExprs.push_back(SubExpr.takeAs<Expr>());
5276 }
Mike Stump1eb44332009-09-09 15:08:12 +00005277
Douglas Gregorb98b1992009-08-11 05:31:07 +00005278 if (!getDerived().AlwaysRebuild() &&
5279 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005280 return SemaRef.Owned(E->Retain());
5281
Douglas Gregorb98b1992009-08-11 05:31:07 +00005282 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5283 move_arg(SubExprs),
5284 E->getRParenLoc());
5285}
5286
Mike Stump1eb44332009-09-09 15:08:12 +00005287template<typename Derived>
5288Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005289TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005290 // FIXME: Implement this!
5291 assert(false && "Cannot transform block expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005292 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005293}
5294
Mike Stump1eb44332009-09-09 15:08:12 +00005295template<typename Derived>
5296Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005297TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005298 // FIXME: Implement this!
5299 assert(false && "Cannot transform block-related expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005300 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005301}
Mike Stump1eb44332009-09-09 15:08:12 +00005302
Douglas Gregorb98b1992009-08-11 05:31:07 +00005303//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00005304// Type reconstruction
5305//===----------------------------------------------------------------------===//
5306
Mike Stump1eb44332009-09-09 15:08:12 +00005307template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005308QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5309 SourceLocation Star) {
5310 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005311 getDerived().getBaseEntity());
5312}
5313
Mike Stump1eb44332009-09-09 15:08:12 +00005314template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005315QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5316 SourceLocation Star) {
5317 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005318 getDerived().getBaseEntity());
5319}
5320
Mike Stump1eb44332009-09-09 15:08:12 +00005321template<typename Derived>
5322QualType
John McCall85737a72009-10-30 00:06:24 +00005323TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5324 bool WrittenAsLValue,
5325 SourceLocation Sigil) {
5326 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5327 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005328}
5329
5330template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005331QualType
John McCall85737a72009-10-30 00:06:24 +00005332TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5333 QualType ClassType,
5334 SourceLocation Sigil) {
John McCall0953e762009-09-24 19:53:00 +00005335 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall85737a72009-10-30 00:06:24 +00005336 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005337}
5338
5339template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005340QualType
John McCall85737a72009-10-30 00:06:24 +00005341TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5342 SourceLocation Sigil) {
5343 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCalla2becad2009-10-21 00:40:46 +00005344 getDerived().getBaseEntity());
5345}
5346
5347template<typename Derived>
5348QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00005349TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5350 ArrayType::ArraySizeModifier SizeMod,
5351 const llvm::APInt *Size,
5352 Expr *SizeExpr,
5353 unsigned IndexTypeQuals,
5354 SourceRange BracketsRange) {
5355 if (SizeExpr || !Size)
5356 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5357 IndexTypeQuals, BracketsRange,
5358 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00005359
5360 QualType Types[] = {
5361 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5362 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5363 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00005364 };
5365 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5366 QualType SizeType;
5367 for (unsigned I = 0; I != NumTypes; ++I)
5368 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5369 SizeType = Types[I];
5370 break;
5371 }
Mike Stump1eb44332009-09-09 15:08:12 +00005372
Douglas Gregor577f75a2009-08-04 16:50:30 +00005373 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005374 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005375 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00005376 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005377}
Mike Stump1eb44332009-09-09 15:08:12 +00005378
Douglas Gregor577f75a2009-08-04 16:50:30 +00005379template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005380QualType
5381TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005382 ArrayType::ArraySizeModifier SizeMod,
5383 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00005384 unsigned IndexTypeQuals,
5385 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005386 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00005387 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005388}
5389
5390template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005391QualType
Mike Stump1eb44332009-09-09 15:08:12 +00005392TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005393 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00005394 unsigned IndexTypeQuals,
5395 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005396 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00005397 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005398}
Mike Stump1eb44332009-09-09 15:08:12 +00005399
Douglas Gregor577f75a2009-08-04 16:50:30 +00005400template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005401QualType
5402TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005403 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005404 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005405 unsigned IndexTypeQuals,
5406 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005407 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005408 SizeExpr.takeAs<Expr>(),
5409 IndexTypeQuals, BracketsRange);
5410}
5411
5412template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005413QualType
5414TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005415 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005416 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005417 unsigned IndexTypeQuals,
5418 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005419 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005420 SizeExpr.takeAs<Expr>(),
5421 IndexTypeQuals, BracketsRange);
5422}
5423
5424template<typename Derived>
5425QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson82287d12010-02-05 00:12:22 +00005426 unsigned NumElements,
5427 bool IsAltiVec, bool IsPixel) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005428 // FIXME: semantic checking!
John Thompson82287d12010-02-05 00:12:22 +00005429 return SemaRef.Context.getVectorType(ElementType, NumElements,
5430 IsAltiVec, IsPixel);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005431}
Mike Stump1eb44332009-09-09 15:08:12 +00005432
Douglas Gregor577f75a2009-08-04 16:50:30 +00005433template<typename Derived>
5434QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5435 unsigned NumElements,
5436 SourceLocation AttributeLoc) {
5437 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5438 NumElements, true);
5439 IntegerLiteral *VectorSize
Mike Stump1eb44332009-09-09 15:08:12 +00005440 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005441 AttributeLoc);
5442 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5443 AttributeLoc);
5444}
Mike Stump1eb44332009-09-09 15:08:12 +00005445
Douglas Gregor577f75a2009-08-04 16:50:30 +00005446template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005447QualType
5448TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005449 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005450 SourceLocation AttributeLoc) {
5451 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5452}
Mike Stump1eb44332009-09-09 15:08:12 +00005453
Douglas Gregor577f75a2009-08-04 16:50:30 +00005454template<typename Derived>
5455QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00005456 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005457 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00005458 bool Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005459 unsigned Quals) {
Mike Stump1eb44332009-09-09 15:08:12 +00005460 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005461 Quals,
5462 getDerived().getBaseLocation(),
5463 getDerived().getBaseEntity());
5464}
Mike Stump1eb44332009-09-09 15:08:12 +00005465
Douglas Gregor577f75a2009-08-04 16:50:30 +00005466template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005467QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5468 return SemaRef.Context.getFunctionNoProtoType(T);
5469}
5470
5471template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00005472QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5473 assert(D && "no decl found");
5474 if (D->isInvalidDecl()) return QualType();
5475
5476 TypeDecl *Ty;
5477 if (isa<UsingDecl>(D)) {
5478 UsingDecl *Using = cast<UsingDecl>(D);
5479 assert(Using->isTypeName() &&
5480 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5481
5482 // A valid resolved using typename decl points to exactly one type decl.
5483 assert(++Using->shadow_begin() == Using->shadow_end());
5484 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5485
5486 } else {
5487 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5488 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5489 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5490 }
5491
5492 return SemaRef.Context.getTypeDeclType(Ty);
5493}
5494
5495template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00005496QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005497 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5498}
5499
5500template<typename Derived>
5501QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5502 return SemaRef.Context.getTypeOfType(Underlying);
5503}
5504
5505template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00005506QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005507 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5508}
5509
5510template<typename Derived>
5511QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00005512 TemplateName Template,
5513 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00005514 const TemplateArgumentListInfo &TemplateArgs) {
5515 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005516}
Mike Stump1eb44332009-09-09 15:08:12 +00005517
Douglas Gregordcee1a12009-08-06 05:28:30 +00005518template<typename Derived>
5519NestedNameSpecifier *
5520TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5521 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00005522 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00005523 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00005524 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00005525 CXXScopeSpec SS;
5526 // FIXME: The source location information is all wrong.
5527 SS.setRange(Range);
5528 SS.setScopeRep(Prefix);
5529 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00005530 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00005531 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00005532 ObjectType,
5533 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00005534 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00005535}
5536
5537template<typename Derived>
5538NestedNameSpecifier *
5539TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5540 SourceRange Range,
5541 NamespaceDecl *NS) {
5542 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5543}
5544
5545template<typename Derived>
5546NestedNameSpecifier *
5547TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5548 SourceRange Range,
5549 bool TemplateKW,
5550 QualType T) {
5551 if (T->isDependentType() || T->isRecordType() ||
5552 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00005553 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00005554 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5555 T.getTypePtr());
5556 }
Mike Stump1eb44332009-09-09 15:08:12 +00005557
Douglas Gregordcee1a12009-08-06 05:28:30 +00005558 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5559 return 0;
5560}
Mike Stump1eb44332009-09-09 15:08:12 +00005561
Douglas Gregord1067e52009-08-06 06:41:21 +00005562template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005563TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00005564TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5565 bool TemplateKW,
5566 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00005567 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00005568 Template);
5569}
5570
5571template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005572TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00005573TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005574 const IdentifierInfo &II,
5575 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00005576 CXXScopeSpec SS;
5577 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump1eb44332009-09-09 15:08:12 +00005578 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00005579 UnqualifiedId Name;
5580 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005581 return getSema().ActOnDependentTemplateName(
5582 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005583 SS,
Douglas Gregor014e88d2009-11-03 23:16:33 +00005584 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00005585 ObjectType.getAsOpaquePtr(),
5586 /*EnteringContext=*/false)
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005587 .template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00005588}
Mike Stump1eb44332009-09-09 15:08:12 +00005589
Douglas Gregorb98b1992009-08-11 05:31:07 +00005590template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00005591TemplateName
5592TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5593 OverloadedOperatorKind Operator,
5594 QualType ObjectType) {
5595 CXXScopeSpec SS;
5596 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5597 SS.setScopeRep(Qualifier);
5598 UnqualifiedId Name;
5599 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5600 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5601 Operator, SymbolLocations);
5602 return getSema().ActOnDependentTemplateName(
5603 /*FIXME:*/getDerived().getBaseLocation(),
5604 SS,
5605 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00005606 ObjectType.getAsOpaquePtr(),
5607 /*EnteringContext=*/false)
Douglas Gregorca1bdd72009-11-04 00:56:37 +00005608 .template getAsVal<TemplateName>();
5609}
5610
5611template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005612Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005613TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5614 SourceLocation OpLoc,
5615 ExprArg Callee,
5616 ExprArg First,
5617 ExprArg Second) {
5618 Expr *FirstExpr = (Expr *)First.get();
5619 Expr *SecondExpr = (Expr *)Second.get();
John McCallba135432009-11-21 08:51:07 +00005620 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005621 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00005622
Douglas Gregorb98b1992009-08-11 05:31:07 +00005623 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00005624 if (Op == OO_Subscript) {
5625 if (!FirstExpr->getType()->isOverloadableType() &&
5626 !SecondExpr->getType()->isOverloadableType())
5627 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCallba135432009-11-21 08:51:07 +00005628 CalleeExpr->getLocStart(),
Sebastian Redlf322ed62009-10-29 20:17:01 +00005629 move(Second), OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00005630 } else if (Op == OO_Arrow) {
5631 // -> is never a builtin operation.
5632 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redlf322ed62009-10-29 20:17:01 +00005633 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005634 if (!FirstExpr->getType()->isOverloadableType()) {
5635 // The argument is not of overloadable type, so try to create a
5636 // built-in unary operation.
Mike Stump1eb44332009-09-09 15:08:12 +00005637 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005638 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00005639
Douglas Gregorb98b1992009-08-11 05:31:07 +00005640 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5641 }
5642 } else {
Mike Stump1eb44332009-09-09 15:08:12 +00005643 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005644 !SecondExpr->getType()->isOverloadableType()) {
5645 // Neither of the arguments is an overloadable type, so try to
5646 // create a built-in binary operation.
5647 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00005648 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00005649 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5650 if (Result.isInvalid())
5651 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005652
Douglas Gregorb98b1992009-08-11 05:31:07 +00005653 First.release();
5654 Second.release();
5655 return move(Result);
5656 }
5657 }
Mike Stump1eb44332009-09-09 15:08:12 +00005658
5659 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00005660 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00005661 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00005662
John McCallba135432009-11-21 08:51:07 +00005663 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5664 assert(ULE->requiresADL());
5665
5666 // FIXME: Do we have to check
5667 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00005668 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00005669 } else {
John McCall6e266892010-01-26 03:27:55 +00005670 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCallba135432009-11-21 08:51:07 +00005671 }
Mike Stump1eb44332009-09-09 15:08:12 +00005672
Douglas Gregorb98b1992009-08-11 05:31:07 +00005673 // Add any functions found via argument-dependent lookup.
5674 Expr *Args[2] = { FirstExpr, SecondExpr };
5675 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00005676
Douglas Gregorb98b1992009-08-11 05:31:07 +00005677 // Create the overloaded operator invocation for unary operators.
5678 if (NumArgs == 1 || isPostIncDec) {
Mike Stump1eb44332009-09-09 15:08:12 +00005679 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005680 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5681 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5682 }
Mike Stump1eb44332009-09-09 15:08:12 +00005683
Sebastian Redlf322ed62009-10-29 20:17:01 +00005684 if (Op == OO_Subscript)
John McCallba135432009-11-21 08:51:07 +00005685 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5686 OpLoc,
5687 move(First),
5688 move(Second));
Sebastian Redlf322ed62009-10-29 20:17:01 +00005689
Douglas Gregorb98b1992009-08-11 05:31:07 +00005690 // Create the overloaded operator invocation for binary operators.
Mike Stump1eb44332009-09-09 15:08:12 +00005691 BinaryOperator::Opcode Opc =
Douglas Gregorb98b1992009-08-11 05:31:07 +00005692 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00005693 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00005694 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5695 if (Result.isInvalid())
5696 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005697
Douglas Gregorb98b1992009-08-11 05:31:07 +00005698 First.release();
5699 Second.release();
Mike Stump1eb44332009-09-09 15:08:12 +00005700 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005701}
Mike Stump1eb44332009-09-09 15:08:12 +00005702
Douglas Gregor577f75a2009-08-04 16:50:30 +00005703} // end namespace clang
5704
5705#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H