blob: fc069f7ba38ab12e8f64d302363777a586f91565 [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) {
Douglas Gregorae628892010-02-13 06:05:33 +0000528 if (NNS->isDependent()) {
529 CXXScopeSpec SS;
530 SS.setScopeRep(NNS);
531 if (!SemaRef.computeDeclContext(SS))
532 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000533 cast<TemplateSpecializationType>(T));
Douglas Gregorae628892010-02-13 06:05:33 +0000534 }
Mike Stump1eb44332009-09-09 15:08:12 +0000535
Douglas Gregor577f75a2009-08-04 16:50:30 +0000536 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000537 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000538
539 /// \brief Build a new typename type that refers to an identifier.
540 ///
541 /// By default, performs semantic analysis when building the typename type
Mike Stump1eb44332009-09-09 15:08:12 +0000542 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000543 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000544 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall833ca992009-10-29 08:12:44 +0000545 const IdentifierInfo *Id,
546 SourceRange SR) {
547 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000548 }
Mike Stump1eb44332009-09-09 15:08:12 +0000549
Douglas Gregordcee1a12009-08-06 05:28:30 +0000550 /// \brief Build a new nested-name-specifier given the prefix and an
551 /// identifier that names the next step in the nested-name-specifier.
552 ///
553 /// By default, performs semantic analysis when building the new
554 /// nested-name-specifier. Subclasses may override this routine to provide
555 /// different behavior.
556 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
557 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000558 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000559 QualType ObjectType,
560 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000561
562 /// \brief Build a new nested-name-specifier given the prefix and the
563 /// namespace named in the next step in the nested-name-specifier.
564 ///
565 /// By default, performs semantic analysis when building the new
566 /// nested-name-specifier. Subclasses may override this routine to provide
567 /// different behavior.
568 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
569 SourceRange Range,
570 NamespaceDecl *NS);
571
572 /// \brief Build a new nested-name-specifier given the prefix and the
573 /// type named in the next step in the nested-name-specifier.
574 ///
575 /// By default, performs semantic analysis when building the new
576 /// nested-name-specifier. Subclasses may override this routine to provide
577 /// different behavior.
578 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
579 SourceRange Range,
580 bool TemplateKW,
581 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000582
583 /// \brief Build a new template name given a nested name specifier, a flag
584 /// indicating whether the "template" keyword was provided, and the template
585 /// that the template name refers to.
586 ///
587 /// By default, builds the new template name directly. Subclasses may override
588 /// this routine to provide different behavior.
589 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
590 bool TemplateKW,
591 TemplateDecl *Template);
592
Douglas Gregord1067e52009-08-06 06:41:21 +0000593 /// \brief Build a new template name given a nested name specifier and the
594 /// name that is referred to as a template.
595 ///
596 /// By default, performs semantic analysis to determine whether the name can
597 /// be resolved to a specific template, then builds the appropriate kind of
598 /// template name. Subclasses may override this routine to provide different
599 /// behavior.
600 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000601 const IdentifierInfo &II,
602 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000603
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000604 /// \brief Build a new template name given a nested name specifier and the
605 /// overloaded operator name that is referred to as a template.
606 ///
607 /// By default, performs semantic analysis to determine whether the name can
608 /// be resolved to a specific template, then builds the appropriate kind of
609 /// template name. Subclasses may override this routine to provide different
610 /// behavior.
611 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
612 OverloadedOperatorKind Operator,
613 QualType ObjectType);
614
Douglas Gregor43959a92009-08-20 07:17:43 +0000615 /// \brief Build a new compound statement.
616 ///
617 /// By default, performs semantic analysis to build the new statement.
618 /// Subclasses may override this routine to provide different behavior.
619 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
620 MultiStmtArg Statements,
621 SourceLocation RBraceLoc,
622 bool IsStmtExpr) {
623 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
624 IsStmtExpr);
625 }
626
627 /// \brief Build a new case statement.
628 ///
629 /// By default, performs semantic analysis to build the new statement.
630 /// Subclasses may override this routine to provide different behavior.
631 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
632 ExprArg LHS,
633 SourceLocation EllipsisLoc,
634 ExprArg RHS,
635 SourceLocation ColonLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000636 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregor43959a92009-08-20 07:17:43 +0000637 ColonLoc);
638 }
Mike Stump1eb44332009-09-09 15:08:12 +0000639
Douglas Gregor43959a92009-08-20 07:17:43 +0000640 /// \brief Attach the body to a new case statement.
641 ///
642 /// By default, performs semantic analysis to build the new statement.
643 /// Subclasses may override this routine to provide different behavior.
644 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
645 getSema().ActOnCaseStmtBody(S.get(), move(Body));
646 return move(S);
647 }
Mike Stump1eb44332009-09-09 15:08:12 +0000648
Douglas Gregor43959a92009-08-20 07:17:43 +0000649 /// \brief Build a new default statement.
650 ///
651 /// By default, performs semantic analysis to build the new statement.
652 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000653 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000654 SourceLocation ColonLoc,
655 StmtArg SubStmt) {
Mike Stump1eb44332009-09-09 15:08:12 +0000656 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregor43959a92009-08-20 07:17:43 +0000657 /*CurScope=*/0);
658 }
Mike Stump1eb44332009-09-09 15:08:12 +0000659
Douglas Gregor43959a92009-08-20 07:17:43 +0000660 /// \brief Build a new label statement.
661 ///
662 /// By default, performs semantic analysis to build the new statement.
663 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000664 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000665 IdentifierInfo *Id,
666 SourceLocation ColonLoc,
667 StmtArg SubStmt) {
668 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
669 }
Mike Stump1eb44332009-09-09 15:08:12 +0000670
Douglas Gregor43959a92009-08-20 07:17:43 +0000671 /// \brief Build a new "if" statement.
672 ///
673 /// By default, performs semantic analysis to build the new statement.
674 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000675 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000676 VarDecl *CondVar, StmtArg Then,
677 SourceLocation ElseLoc, StmtArg Else) {
678 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
679 move(Then), ElseLoc, move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +0000680 }
Mike Stump1eb44332009-09-09 15:08:12 +0000681
Douglas Gregor43959a92009-08-20 07:17:43 +0000682 /// \brief Start building a new switch statement.
683 ///
684 /// By default, performs semantic analysis to build the new statement.
685 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000686 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
687 VarDecl *CondVar) {
688 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregor43959a92009-08-20 07:17:43 +0000689 }
Mike Stump1eb44332009-09-09 15:08:12 +0000690
Douglas Gregor43959a92009-08-20 07:17:43 +0000691 /// \brief Attach the body to the switch statement.
692 ///
693 /// By default, performs semantic analysis to build the new statement.
694 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000695 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000696 StmtArg Switch, StmtArg Body) {
697 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
698 move(Body));
699 }
700
701 /// \brief Build a new while statement.
702 ///
703 /// By default, performs semantic analysis to build the new statement.
704 /// Subclasses may override this routine to provide different behavior.
705 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
706 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000707 VarDecl *CondVar,
Douglas Gregor43959a92009-08-20 07:17:43 +0000708 StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000709 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
710 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000711 }
Mike Stump1eb44332009-09-09 15:08:12 +0000712
Douglas Gregor43959a92009-08-20 07:17:43 +0000713 /// \brief Build a new do-while statement.
714 ///
715 /// By default, performs semantic analysis to build the new statement.
716 /// Subclasses may override this routine to provide different behavior.
717 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
718 SourceLocation WhileLoc,
719 SourceLocation LParenLoc,
720 ExprArg Cond,
721 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000722 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000723 move(Cond), RParenLoc);
724 }
725
726 /// \brief Build a new for statement.
727 ///
728 /// By default, performs semantic analysis to build the new statement.
729 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000730 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000731 SourceLocation LParenLoc,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000732 StmtArg Init, Sema::FullExprArg Cond,
733 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000734 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000735 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
736 DeclPtrTy::make(CondVar),
737 Inc, RParenLoc, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000738 }
Mike Stump1eb44332009-09-09 15:08:12 +0000739
Douglas Gregor43959a92009-08-20 07:17:43 +0000740 /// \brief Build a new goto statement.
741 ///
742 /// By default, performs semantic analysis to build the new statement.
743 /// Subclasses may override this routine to provide different behavior.
744 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
745 SourceLocation LabelLoc,
746 LabelStmt *Label) {
747 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
748 }
749
750 /// \brief Build a new indirect goto statement.
751 ///
752 /// By default, performs semantic analysis to build the new statement.
753 /// Subclasses may override this routine to provide different behavior.
754 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
755 SourceLocation StarLoc,
756 ExprArg Target) {
757 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
758 }
Mike Stump1eb44332009-09-09 15:08:12 +0000759
Douglas Gregor43959a92009-08-20 07:17:43 +0000760 /// \brief Build a new return statement.
761 ///
762 /// By default, performs semantic analysis to build the new statement.
763 /// Subclasses may override this routine to provide different behavior.
764 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
765 ExprArg Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000766
Douglas Gregor43959a92009-08-20 07:17:43 +0000767 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
768 }
Mike Stump1eb44332009-09-09 15:08:12 +0000769
Douglas Gregor43959a92009-08-20 07:17:43 +0000770 /// \brief Build a new declaration statement.
771 ///
772 /// By default, performs semantic analysis to build the new statement.
773 /// Subclasses may override this routine to provide different behavior.
774 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000775 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000776 SourceLocation EndLoc) {
777 return getSema().Owned(
778 new (getSema().Context) DeclStmt(
779 DeclGroupRef::Create(getSema().Context,
780 Decls, NumDecls),
781 StartLoc, EndLoc));
782 }
Mike Stump1eb44332009-09-09 15:08:12 +0000783
Anders Carlsson703e3942010-01-24 05:50:09 +0000784 /// \brief Build a new inline asm statement.
785 ///
786 /// By default, performs semantic analysis to build the new statement.
787 /// Subclasses may override this routine to provide different behavior.
788 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
789 bool IsSimple,
790 bool IsVolatile,
791 unsigned NumOutputs,
792 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000793 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000794 MultiExprArg Constraints,
795 MultiExprArg Exprs,
796 ExprArg AsmString,
797 MultiExprArg Clobbers,
798 SourceLocation RParenLoc,
799 bool MSAsm) {
800 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
801 NumInputs, Names, move(Constraints),
802 move(Exprs), move(AsmString), move(Clobbers),
803 RParenLoc, MSAsm);
804 }
805
Douglas Gregor43959a92009-08-20 07:17:43 +0000806 /// \brief Build a new C++ exception declaration.
807 ///
808 /// By default, performs semantic analysis to build the new decaration.
809 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000810 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000811 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000812 IdentifierInfo *Name,
813 SourceLocation Loc,
814 SourceRange TypeRange) {
Mike Stump1eb44332009-09-09 15:08:12 +0000815 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000816 TypeRange);
817 }
818
819 /// \brief Build a new C++ catch statement.
820 ///
821 /// By default, performs semantic analysis to build the new statement.
822 /// Subclasses may override this routine to provide different behavior.
823 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
824 VarDecl *ExceptionDecl,
825 StmtArg Handler) {
826 return getSema().Owned(
Mike Stump1eb44332009-09-09 15:08:12 +0000827 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregor43959a92009-08-20 07:17:43 +0000828 Handler.takeAs<Stmt>()));
829 }
Mike Stump1eb44332009-09-09 15:08:12 +0000830
Douglas Gregor43959a92009-08-20 07:17:43 +0000831 /// \brief Build a new C++ try statement.
832 ///
833 /// By default, performs semantic analysis to build the new statement.
834 /// Subclasses may override this routine to provide different behavior.
835 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
836 StmtArg TryBlock,
837 MultiStmtArg Handlers) {
838 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
839 }
Mike Stump1eb44332009-09-09 15:08:12 +0000840
Douglas Gregorb98b1992009-08-11 05:31:07 +0000841 /// \brief Build a new expression that references a declaration.
842 ///
843 /// By default, performs semantic analysis to build the new expression.
844 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +0000845 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
846 LookupResult &R,
847 bool RequiresADL) {
848 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
849 }
850
851
852 /// \brief Build a new expression that references a declaration.
853 ///
854 /// By default, performs semantic analysis to build the new expression.
855 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora2813ce2009-10-23 18:54:35 +0000856 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
857 SourceRange QualifierRange,
John McCalldbd872f2009-12-08 09:08:17 +0000858 ValueDecl *VD, SourceLocation Loc,
859 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +0000860 CXXScopeSpec SS;
861 SS.setScopeRep(Qualifier);
862 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +0000863
864 // FIXME: loses template args.
865
866 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000867 }
Mike Stump1eb44332009-09-09 15:08:12 +0000868
Douglas Gregorb98b1992009-08-11 05:31:07 +0000869 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +0000870 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000871 /// By default, performs semantic analysis to build the new expression.
872 /// Subclasses may override this routine to provide different behavior.
873 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
874 SourceLocation RParen) {
875 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
876 }
877
Douglas Gregora71d8192009-09-04 17:36:40 +0000878 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000879 ///
Douglas Gregora71d8192009-09-04 17:36:40 +0000880 /// By default, performs semantic analysis to build the new expression.
881 /// Subclasses may override this routine to provide different behavior.
882 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
883 SourceLocation OperatorLoc,
884 bool isArrow,
885 SourceLocation DestroyedTypeLoc,
886 QualType DestroyedType,
887 NestedNameSpecifier *Qualifier,
888 SourceRange QualifierRange) {
889 CXXScopeSpec SS;
890 if (Qualifier) {
891 SS.setRange(QualifierRange);
892 SS.setScopeRep(Qualifier);
893 }
894
John McCallaa81e162009-12-01 22:10:20 +0000895 QualType BaseType = ((Expr*) Base.get())->getType();
896
Mike Stump1eb44332009-09-09 15:08:12 +0000897 DeclarationName Name
Douglas Gregora71d8192009-09-04 17:36:40 +0000898 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
899 SemaRef.Context.getCanonicalType(DestroyedType));
Mike Stump1eb44332009-09-09 15:08:12 +0000900
John McCallaa81e162009-12-01 22:10:20 +0000901 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
902 OperatorLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +0000903 SS, /*FIXME: FirstQualifier*/ 0,
904 Name, DestroyedTypeLoc,
905 /*TemplateArgs*/ 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000906 }
907
Douglas Gregorb98b1992009-08-11 05:31:07 +0000908 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000909 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000910 /// By default, performs semantic analysis to build the new expression.
911 /// Subclasses may override this routine to provide different behavior.
912 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
913 UnaryOperator::Opcode Opc,
914 ExprArg SubExpr) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +0000915 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +0000916 }
Mike Stump1eb44332009-09-09 15:08:12 +0000917
Douglas Gregorb98b1992009-08-11 05:31:07 +0000918 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +0000919 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000920 /// By default, performs semantic analysis to build the new expression.
921 /// Subclasses may override this routine to provide different behavior.
John McCalla93c9342009-12-07 02:54:59 +0000922 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +0000923 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000924 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +0000925 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000926 }
927
Mike Stump1eb44332009-09-09 15:08:12 +0000928 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +0000929 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +0000930 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000931 /// By default, performs semantic analysis to build the new expression.
932 /// Subclasses may override this routine to provide different behavior.
933 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
934 bool isSizeOf, SourceRange R) {
Mike Stump1eb44332009-09-09 15:08:12 +0000935 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +0000936 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
937 OpLoc, isSizeOf, R);
938 if (Result.isInvalid())
939 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +0000940
Douglas Gregorb98b1992009-08-11 05:31:07 +0000941 SubExpr.release();
942 return move(Result);
943 }
Mike Stump1eb44332009-09-09 15:08:12 +0000944
Douglas Gregorb98b1992009-08-11 05:31:07 +0000945 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000946 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000947 /// By default, performs semantic analysis to build the new expression.
948 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000949 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000950 SourceLocation LBracketLoc,
951 ExprArg RHS,
952 SourceLocation RBracketLoc) {
953 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump1eb44332009-09-09 15:08:12 +0000954 LBracketLoc, move(RHS),
Douglas Gregorb98b1992009-08-11 05:31:07 +0000955 RBracketLoc);
956 }
957
958 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000959 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000960 /// By default, performs semantic analysis to build the new expression.
961 /// Subclasses may override this routine to provide different behavior.
962 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
963 MultiExprArg Args,
964 SourceLocation *CommaLocs,
965 SourceLocation RParenLoc) {
966 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
967 move(Args), CommaLocs, RParenLoc);
968 }
969
970 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000971 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000972 /// By default, performs semantic analysis to build the new expression.
973 /// Subclasses may override this routine to provide different behavior.
974 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +0000975 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000976 NestedNameSpecifier *Qualifier,
977 SourceRange QualifierRange,
978 SourceLocation MemberLoc,
Eli Friedmanf595cc42009-12-04 06:40:45 +0000979 ValueDecl *Member,
John McCalld5532b62009-11-23 01:53:49 +0000980 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +0000981 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +0000982 if (!Member->getDeclName()) {
983 // We have a reference to an unnamed field.
984 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +0000985
Douglas Gregor83a56c42009-12-24 20:02:50 +0000986 Expr *BaseExpr = Base.takeAs<Expr>();
987 if (getSema().PerformObjectMemberConversion(BaseExpr, Member))
988 return getSema().ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +0000989
Mike Stump1eb44332009-09-09 15:08:12 +0000990 MemberExpr *ME =
Douglas Gregor83a56c42009-12-24 20:02:50 +0000991 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlssond8b285f2009-09-01 04:26:58 +0000992 Member, MemberLoc,
993 cast<FieldDecl>(Member)->getType());
994 return getSema().Owned(ME);
995 }
Mike Stump1eb44332009-09-09 15:08:12 +0000996
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000997 CXXScopeSpec SS;
998 if (Qualifier) {
999 SS.setRange(QualifierRange);
1000 SS.setScopeRep(Qualifier);
1001 }
1002
John McCallaa81e162009-12-01 22:10:20 +00001003 QualType BaseType = ((Expr*) Base.get())->getType();
1004
John McCallc2233c52010-01-15 08:34:02 +00001005 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1006 Sema::LookupMemberName);
1007 R.addDecl(Member);
1008 R.resolveKind();
1009
John McCallaa81e162009-12-01 22:10:20 +00001010 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1011 OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001012 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001013 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001014 }
Mike Stump1eb44332009-09-09 15:08:12 +00001015
Douglas Gregorb98b1992009-08-11 05:31:07 +00001016 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001017 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001018 /// By default, performs semantic analysis to build the new expression.
1019 /// Subclasses may override this routine to provide different behavior.
1020 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1021 BinaryOperator::Opcode Opc,
1022 ExprArg LHS, ExprArg RHS) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001023 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1024 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregorb98b1992009-08-11 05:31:07 +00001025 }
1026
1027 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001028 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001029 /// By default, performs semantic analysis to build the new expression.
1030 /// Subclasses may override this routine to provide different behavior.
1031 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1032 SourceLocation QuestionLoc,
1033 ExprArg LHS,
1034 SourceLocation ColonLoc,
1035 ExprArg RHS) {
Mike Stump1eb44332009-09-09 15:08:12 +00001036 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001037 move(LHS), move(RHS));
1038 }
1039
Douglas Gregorb98b1992009-08-11 05:31:07 +00001040 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001041 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001042 /// By default, performs semantic analysis to build the new expression.
1043 /// Subclasses may override this routine to provide different behavior.
John McCall9d125032010-01-15 18:39:57 +00001044 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1045 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001046 SourceLocation RParenLoc,
1047 ExprArg SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001048 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1049 move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001050 }
Mike Stump1eb44332009-09-09 15:08:12 +00001051
Douglas Gregorb98b1992009-08-11 05:31:07 +00001052 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001053 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001054 /// By default, performs semantic analysis to build the new expression.
1055 /// Subclasses may override this routine to provide different behavior.
1056 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001057 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001058 SourceLocation RParenLoc,
1059 ExprArg Init) {
John McCall42f56b52010-01-18 19:35:47 +00001060 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1061 move(Init));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001062 }
Mike Stump1eb44332009-09-09 15:08:12 +00001063
Douglas Gregorb98b1992009-08-11 05:31:07 +00001064 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001065 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001066 /// By default, performs semantic analysis to build the new expression.
1067 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001068 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001069 SourceLocation OpLoc,
1070 SourceLocation AccessorLoc,
1071 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001072
John McCall129e2df2009-11-30 22:42:35 +00001073 CXXScopeSpec SS;
John McCallaa81e162009-12-01 22:10:20 +00001074 QualType BaseType = ((Expr*) Base.get())->getType();
1075 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001076 OpLoc, /*IsArrow*/ false,
1077 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor2d1c2142009-11-03 19:44:04 +00001078 DeclarationName(&Accessor),
John McCall129e2df2009-11-30 22:42:35 +00001079 AccessorLoc,
1080 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001081 }
Mike Stump1eb44332009-09-09 15:08:12 +00001082
Douglas Gregorb98b1992009-08-11 05:31:07 +00001083 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001084 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001085 /// By default, performs semantic analysis to build the new expression.
1086 /// Subclasses may override this routine to provide different behavior.
1087 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1088 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001089 SourceLocation RBraceLoc,
1090 QualType ResultTy) {
1091 OwningExprResult Result
1092 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1093 if (Result.isInvalid() || ResultTy->isDependentType())
1094 return move(Result);
1095
1096 // Patch in the result type we were given, which may have been computed
1097 // when the initial InitListExpr was built.
1098 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1099 ILE->setType(ResultTy);
1100 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001101 }
Mike Stump1eb44332009-09-09 15:08:12 +00001102
Douglas Gregorb98b1992009-08-11 05:31:07 +00001103 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001104 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001105 /// By default, performs semantic analysis to build the new expression.
1106 /// Subclasses may override this routine to provide different behavior.
1107 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1108 MultiExprArg ArrayExprs,
1109 SourceLocation EqualOrColonLoc,
1110 bool GNUSyntax,
1111 ExprArg Init) {
1112 OwningExprResult Result
1113 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1114 move(Init));
1115 if (Result.isInvalid())
1116 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001117
Douglas Gregorb98b1992009-08-11 05:31:07 +00001118 ArrayExprs.release();
1119 return move(Result);
1120 }
Mike Stump1eb44332009-09-09 15:08:12 +00001121
Douglas Gregorb98b1992009-08-11 05:31:07 +00001122 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001123 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001124 /// By default, builds the implicit value initialization without performing
1125 /// any semantic analysis. Subclasses may override this routine to provide
1126 /// different behavior.
1127 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1128 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1129 }
Mike Stump1eb44332009-09-09 15:08:12 +00001130
Douglas Gregorb98b1992009-08-11 05:31:07 +00001131 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001132 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001133 /// By default, performs semantic analysis to build the new expression.
1134 /// Subclasses may override this routine to provide different behavior.
1135 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1136 QualType T, SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001137 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001138 RParenLoc);
1139 }
1140
1141 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001142 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001143 /// By default, performs semantic analysis to build the new expression.
1144 /// Subclasses may override this routine to provide different behavior.
1145 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1146 MultiExprArg SubExprs,
1147 SourceLocation RParenLoc) {
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001148 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1149 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001150 }
Mike Stump1eb44332009-09-09 15:08:12 +00001151
Douglas Gregorb98b1992009-08-11 05:31:07 +00001152 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001153 ///
1154 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001155 /// rather than attempting to map the label statement itself.
1156 /// Subclasses may override this routine to provide different behavior.
1157 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1158 SourceLocation LabelLoc,
1159 LabelStmt *Label) {
1160 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1161 }
Mike Stump1eb44332009-09-09 15:08:12 +00001162
Douglas Gregorb98b1992009-08-11 05:31:07 +00001163 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001164 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001165 /// By default, performs semantic analysis to build the new expression.
1166 /// Subclasses may override this routine to provide different behavior.
1167 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1168 StmtArg SubStmt,
1169 SourceLocation RParenLoc) {
1170 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1171 }
Mike Stump1eb44332009-09-09 15:08:12 +00001172
Douglas Gregorb98b1992009-08-11 05:31:07 +00001173 /// \brief Build a new __builtin_types_compatible_p expression.
1174 ///
1175 /// By default, performs semantic analysis to build the new expression.
1176 /// Subclasses may override this routine to provide different behavior.
1177 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1178 QualType T1, QualType T2,
1179 SourceLocation RParenLoc) {
1180 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1181 T1.getAsOpaquePtr(),
1182 T2.getAsOpaquePtr(),
1183 RParenLoc);
1184 }
Mike Stump1eb44332009-09-09 15:08:12 +00001185
Douglas Gregorb98b1992009-08-11 05:31:07 +00001186 /// \brief Build a new __builtin_choose_expr expression.
1187 ///
1188 /// By default, performs semantic analysis to build the new expression.
1189 /// Subclasses may override this routine to provide different behavior.
1190 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1191 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1192 SourceLocation RParenLoc) {
1193 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1194 move(Cond), move(LHS), move(RHS),
1195 RParenLoc);
1196 }
Mike Stump1eb44332009-09-09 15:08:12 +00001197
Douglas Gregorb98b1992009-08-11 05:31:07 +00001198 /// \brief Build a new overloaded operator call expression.
1199 ///
1200 /// By default, performs semantic analysis to build the new expression.
1201 /// The semantic analysis provides the behavior of template instantiation,
1202 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001203 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001204 /// argument-dependent lookup, etc. Subclasses may override this routine to
1205 /// provide different behavior.
1206 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1207 SourceLocation OpLoc,
1208 ExprArg Callee,
1209 ExprArg First,
1210 ExprArg Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001211
1212 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001213 /// reinterpret_cast.
1214 ///
1215 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001216 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001217 /// Subclasses may override this routine to provide different behavior.
1218 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1219 Stmt::StmtClass Class,
1220 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001221 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001222 SourceLocation RAngleLoc,
1223 SourceLocation LParenLoc,
1224 ExprArg SubExpr,
1225 SourceLocation RParenLoc) {
1226 switch (Class) {
1227 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001228 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001229 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001230 move(SubExpr), RParenLoc);
1231
1232 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001233 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001234 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001235 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001236
Douglas Gregorb98b1992009-08-11 05:31:07 +00001237 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001238 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001239 RAngleLoc, LParenLoc,
1240 move(SubExpr),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001241 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001242
Douglas Gregorb98b1992009-08-11 05:31:07 +00001243 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001244 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001245 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001246 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001247
Douglas Gregorb98b1992009-08-11 05:31:07 +00001248 default:
1249 assert(false && "Invalid C++ named cast");
1250 break;
1251 }
Mike Stump1eb44332009-09-09 15:08:12 +00001252
Douglas Gregorb98b1992009-08-11 05:31:07 +00001253 return getSema().ExprError();
1254 }
Mike Stump1eb44332009-09-09 15:08:12 +00001255
Douglas Gregorb98b1992009-08-11 05:31:07 +00001256 /// \brief Build a new C++ static_cast expression.
1257 ///
1258 /// By default, performs semantic analysis to build the new expression.
1259 /// Subclasses may override this routine to provide different behavior.
1260 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1261 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001262 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001263 SourceLocation RAngleLoc,
1264 SourceLocation LParenLoc,
1265 ExprArg SubExpr,
1266 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001267 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1268 TInfo, move(SubExpr),
1269 SourceRange(LAngleLoc, RAngleLoc),
1270 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001271 }
1272
1273 /// \brief Build a new C++ dynamic_cast expression.
1274 ///
1275 /// By default, performs semantic analysis to build the new expression.
1276 /// Subclasses may override this routine to provide different behavior.
1277 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1278 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001279 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001280 SourceLocation RAngleLoc,
1281 SourceLocation LParenLoc,
1282 ExprArg SubExpr,
1283 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001284 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1285 TInfo, move(SubExpr),
1286 SourceRange(LAngleLoc, RAngleLoc),
1287 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001288 }
1289
1290 /// \brief Build a new C++ reinterpret_cast expression.
1291 ///
1292 /// By default, performs semantic analysis to build the new expression.
1293 /// Subclasses may override this routine to provide different behavior.
1294 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1295 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001296 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001297 SourceLocation RAngleLoc,
1298 SourceLocation LParenLoc,
1299 ExprArg SubExpr,
1300 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001301 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1302 TInfo, move(SubExpr),
1303 SourceRange(LAngleLoc, RAngleLoc),
1304 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001305 }
1306
1307 /// \brief Build a new C++ const_cast expression.
1308 ///
1309 /// By default, performs semantic analysis to build the new expression.
1310 /// Subclasses may override this routine to provide different behavior.
1311 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1312 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001313 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001314 SourceLocation RAngleLoc,
1315 SourceLocation LParenLoc,
1316 ExprArg SubExpr,
1317 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001318 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1319 TInfo, move(SubExpr),
1320 SourceRange(LAngleLoc, RAngleLoc),
1321 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001322 }
Mike Stump1eb44332009-09-09 15:08:12 +00001323
Douglas Gregorb98b1992009-08-11 05:31:07 +00001324 /// \brief Build a new C++ functional-style cast expression.
1325 ///
1326 /// By default, performs semantic analysis to build the new expression.
1327 /// Subclasses may override this routine to provide different behavior.
1328 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001329 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001330 SourceLocation LParenLoc,
1331 ExprArg SubExpr,
1332 SourceLocation RParenLoc) {
Chris Lattner88650c32009-08-24 05:19:01 +00001333 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001334 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001335 TInfo->getType().getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001336 LParenLoc,
Chris Lattner88650c32009-08-24 05:19:01 +00001337 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump1eb44332009-09-09 15:08:12 +00001338 /*CommaLocs=*/0,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001339 RParenLoc);
1340 }
Mike Stump1eb44332009-09-09 15:08:12 +00001341
Douglas Gregorb98b1992009-08-11 05:31:07 +00001342 /// \brief Build a new C++ typeid(type) expression.
1343 ///
1344 /// By default, performs semantic analysis to build the new expression.
1345 /// Subclasses may override this routine to provide different behavior.
1346 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1347 SourceLocation LParenLoc,
1348 QualType T,
1349 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001350 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001351 T.getAsOpaquePtr(), RParenLoc);
1352 }
Mike Stump1eb44332009-09-09 15:08:12 +00001353
Douglas Gregorb98b1992009-08-11 05:31:07 +00001354 /// \brief Build a new C++ typeid(expr) expression.
1355 ///
1356 /// By default, performs semantic analysis to build the new expression.
1357 /// Subclasses may override this routine to provide different behavior.
1358 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1359 SourceLocation LParenLoc,
1360 ExprArg Operand,
1361 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001362 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001363 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1364 RParenLoc);
1365 if (Result.isInvalid())
1366 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001367
Douglas Gregorb98b1992009-08-11 05:31:07 +00001368 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1369 return move(Result);
Mike Stump1eb44332009-09-09 15:08:12 +00001370 }
1371
Douglas Gregorb98b1992009-08-11 05:31:07 +00001372 /// \brief Build a new C++ "this" expression.
1373 ///
1374 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001375 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001376 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001377 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001378 QualType ThisType,
1379 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001380 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001381 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1382 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001383 }
1384
1385 /// \brief Build a new C++ throw expression.
1386 ///
1387 /// By default, performs semantic analysis to build the new expression.
1388 /// Subclasses may override this routine to provide different behavior.
1389 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1390 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1391 }
1392
1393 /// \brief Build a new C++ default-argument expression.
1394 ///
1395 /// By default, builds a new default-argument expression, which does not
1396 /// require any semantic analysis. Subclasses may override this routine to
1397 /// provide different behavior.
Douglas Gregor036aed12009-12-23 23:03:06 +00001398 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1399 ParmVarDecl *Param) {
1400 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1401 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001402 }
1403
1404 /// \brief Build a new C++ zero-initialization expression.
1405 ///
1406 /// By default, performs semantic analysis to build the new expression.
1407 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001408 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 SourceLocation LParenLoc,
1410 QualType T,
1411 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001412 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1413 T.getAsOpaquePtr(), LParenLoc,
1414 MultiExprArg(getSema(), 0, 0),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 0, RParenLoc);
1416 }
Mike Stump1eb44332009-09-09 15:08:12 +00001417
Douglas Gregorb98b1992009-08-11 05:31:07 +00001418 /// \brief Build a new C++ "new" expression.
1419 ///
1420 /// By default, performs semantic analysis to build the new expression.
1421 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001422 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001423 bool UseGlobal,
1424 SourceLocation PlacementLParen,
1425 MultiExprArg PlacementArgs,
1426 SourceLocation PlacementRParen,
Mike Stump1eb44332009-09-09 15:08:12 +00001427 bool ParenTypeId,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001428 QualType AllocType,
1429 SourceLocation TypeLoc,
1430 SourceRange TypeRange,
1431 ExprArg ArraySize,
1432 SourceLocation ConstructorLParen,
1433 MultiExprArg ConstructorArgs,
1434 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001435 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001436 PlacementLParen,
1437 move(PlacementArgs),
1438 PlacementRParen,
1439 ParenTypeId,
1440 AllocType,
1441 TypeLoc,
1442 TypeRange,
1443 move(ArraySize),
1444 ConstructorLParen,
1445 move(ConstructorArgs),
1446 ConstructorRParen);
1447 }
Mike Stump1eb44332009-09-09 15:08:12 +00001448
Douglas Gregorb98b1992009-08-11 05:31:07 +00001449 /// \brief Build a new C++ "delete" expression.
1450 ///
1451 /// By default, performs semantic analysis to build the new expression.
1452 /// Subclasses may override this routine to provide different behavior.
1453 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1454 bool IsGlobalDelete,
1455 bool IsArrayForm,
1456 ExprArg Operand) {
1457 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1458 move(Operand));
1459 }
Mike Stump1eb44332009-09-09 15:08:12 +00001460
Douglas Gregorb98b1992009-08-11 05:31:07 +00001461 /// \brief Build a new unary type trait expression.
1462 ///
1463 /// By default, performs semantic analysis to build the new expression.
1464 /// Subclasses may override this routine to provide different behavior.
1465 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1466 SourceLocation StartLoc,
1467 SourceLocation LParenLoc,
1468 QualType T,
1469 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001470 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001471 T.getAsOpaquePtr(), RParenLoc);
1472 }
1473
Mike Stump1eb44332009-09-09 15:08:12 +00001474 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001475 /// expression.
1476 ///
1477 /// By default, performs semantic analysis to build the new expression.
1478 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001479 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 SourceRange QualifierRange,
1481 DeclarationName Name,
1482 SourceLocation Location,
John McCallf7a1a742009-11-24 19:00:30 +00001483 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 CXXScopeSpec SS;
1485 SS.setRange(QualifierRange);
1486 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001487
1488 if (TemplateArgs)
1489 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1490 *TemplateArgs);
1491
1492 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 }
1494
1495 /// \brief Build a new template-id expression.
1496 ///
1497 /// By default, performs semantic analysis to build the new expression.
1498 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001499 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1500 LookupResult &R,
1501 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001502 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001503 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001504 }
1505
1506 /// \brief Build a new object-construction expression.
1507 ///
1508 /// By default, performs semantic analysis to build the new expression.
1509 /// Subclasses may override this routine to provide different behavior.
1510 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001511 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 CXXConstructorDecl *Constructor,
1513 bool IsElidable,
1514 MultiExprArg Args) {
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001515 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1516 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1517 ConvertedArgs))
1518 return getSema().ExprError();
1519
1520 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1521 move_arg(ConvertedArgs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001522 }
1523
1524 /// \brief Build a new object-construction expression.
1525 ///
1526 /// By default, performs semantic analysis to build the new expression.
1527 /// Subclasses may override this routine to provide different behavior.
1528 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1529 QualType T,
1530 SourceLocation LParenLoc,
1531 MultiExprArg Args,
1532 SourceLocation *Commas,
1533 SourceLocation RParenLoc) {
1534 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1535 T.getAsOpaquePtr(),
1536 LParenLoc,
1537 move(Args),
1538 Commas,
1539 RParenLoc);
1540 }
1541
1542 /// \brief Build a new object-construction expression.
1543 ///
1544 /// By default, performs semantic analysis to build the new expression.
1545 /// Subclasses may override this routine to provide different behavior.
1546 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1547 QualType T,
1548 SourceLocation LParenLoc,
1549 MultiExprArg Args,
1550 SourceLocation *Commas,
1551 SourceLocation RParenLoc) {
1552 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1553 /*FIXME*/LParenLoc),
1554 T.getAsOpaquePtr(),
1555 LParenLoc,
1556 move(Args),
1557 Commas,
1558 RParenLoc);
1559 }
Mike Stump1eb44332009-09-09 15:08:12 +00001560
Douglas Gregorb98b1992009-08-11 05:31:07 +00001561 /// \brief Build a new member reference expression.
1562 ///
1563 /// By default, performs semantic analysis to build the new expression.
1564 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001565 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001566 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 bool IsArrow,
1568 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001569 NestedNameSpecifier *Qualifier,
1570 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001571 NamedDecl *FirstQualifierInScope,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001572 DeclarationName Name,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001573 SourceLocation MemberLoc,
John McCall129e2df2009-11-30 22:42:35 +00001574 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001575 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001576 SS.setRange(QualifierRange);
1577 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001578
John McCallaa81e162009-12-01 22:10:20 +00001579 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1580 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001581 SS, FirstQualifierInScope,
1582 Name, MemberLoc, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 }
1584
John McCall129e2df2009-11-30 22:42:35 +00001585 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001586 ///
1587 /// By default, performs semantic analysis to build the new expression.
1588 /// Subclasses may override this routine to provide different behavior.
John McCall129e2df2009-11-30 22:42:35 +00001589 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001590 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001591 SourceLocation OperatorLoc,
1592 bool IsArrow,
1593 NestedNameSpecifier *Qualifier,
1594 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001595 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001596 LookupResult &R,
1597 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001598 CXXScopeSpec SS;
1599 SS.setRange(QualifierRange);
1600 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001601
John McCallaa81e162009-12-01 22:10:20 +00001602 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1603 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001604 SS, FirstQualifierInScope,
1605 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001606 }
Mike Stump1eb44332009-09-09 15:08:12 +00001607
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 /// \brief Build a new Objective-C @encode expression.
1609 ///
1610 /// By default, performs semantic analysis to build the new expression.
1611 /// Subclasses may override this routine to provide different behavior.
1612 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1613 QualType T,
1614 SourceLocation RParenLoc) {
1615 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1616 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001617 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618
1619 /// \brief Build a new Objective-C protocol expression.
1620 ///
1621 /// By default, performs semantic analysis to build the new expression.
1622 /// Subclasses may override this routine to provide different behavior.
1623 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1624 SourceLocation AtLoc,
1625 SourceLocation ProtoLoc,
1626 SourceLocation LParenLoc,
1627 SourceLocation RParenLoc) {
1628 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1629 Protocol->getIdentifier(),
1630 AtLoc,
1631 ProtoLoc,
1632 LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001633 RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001634 }
Mike Stump1eb44332009-09-09 15:08:12 +00001635
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 /// \brief Build a new shuffle vector expression.
1637 ///
1638 /// By default, performs semantic analysis to build the new expression.
1639 /// Subclasses may override this routine to provide different behavior.
1640 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1641 MultiExprArg SubExprs,
1642 SourceLocation RParenLoc) {
1643 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001644 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001645 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1646 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1647 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1648 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001649
Douglas Gregorb98b1992009-08-11 05:31:07 +00001650 // Build a reference to the __builtin_shufflevector builtin
1651 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001652 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001654 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001656
1657 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 unsigned NumSubExprs = SubExprs.size();
1659 Expr **Subs = (Expr **)SubExprs.release();
1660 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1661 Subs, NumSubExprs,
1662 Builtin->getResultType(),
1663 RParenLoc);
1664 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001665
Douglas Gregorb98b1992009-08-11 05:31:07 +00001666 // Type-check the __builtin_shufflevector expression.
1667 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1668 if (Result.isInvalid())
1669 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001670
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001672 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001674};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001675
Douglas Gregor43959a92009-08-20 07:17:43 +00001676template<typename Derived>
1677Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1678 if (!S)
1679 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001680
Douglas Gregor43959a92009-08-20 07:17:43 +00001681 switch (S->getStmtClass()) {
1682 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001683
Douglas Gregor43959a92009-08-20 07:17:43 +00001684 // Transform individual statement nodes
1685#define STMT(Node, Parent) \
1686 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1687#define EXPR(Node, Parent)
1688#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001689
Douglas Gregor43959a92009-08-20 07:17:43 +00001690 // Transform expressions by calling TransformExpr.
1691#define STMT(Node, Parent)
John McCall09cc1412010-02-03 00:55:45 +00001692#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregor43959a92009-08-20 07:17:43 +00001693#define EXPR(Node, Parent) case Stmt::Node##Class:
1694#include "clang/AST/StmtNodes.def"
1695 {
1696 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1697 if (E.isInvalid())
1698 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001699
Anders Carlsson5ee56e92009-12-16 02:09:40 +00001700 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregor43959a92009-08-20 07:17:43 +00001701 }
Mike Stump1eb44332009-09-09 15:08:12 +00001702 }
1703
Douglas Gregor43959a92009-08-20 07:17:43 +00001704 return SemaRef.Owned(S->Retain());
1705}
Mike Stump1eb44332009-09-09 15:08:12 +00001706
1707
Douglas Gregor670444e2009-08-04 22:27:00 +00001708template<typename Derived>
John McCall454feb92009-12-08 09:21:05 +00001709Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 if (!E)
1711 return SemaRef.Owned(E);
1712
1713 switch (E->getStmtClass()) {
1714 case Stmt::NoStmtClass: break;
1715#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall09cc1412010-02-03 00:55:45 +00001716#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00001718 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001719#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001720 }
1721
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00001723}
1724
1725template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00001726NestedNameSpecifier *
1727TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00001728 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001729 QualType ObjectType,
1730 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00001731 if (!NNS)
1732 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001733
Douglas Gregor43959a92009-08-20 07:17:43 +00001734 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00001735 NestedNameSpecifier *Prefix = NNS->getPrefix();
1736 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00001737 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001738 ObjectType,
1739 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00001740 if (!Prefix)
1741 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001742
1743 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00001744 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00001745 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00001746 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001747 }
Mike Stump1eb44332009-09-09 15:08:12 +00001748
Douglas Gregordcee1a12009-08-06 05:28:30 +00001749 switch (NNS->getKind()) {
1750 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00001751 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00001752 "Identifier nested-name-specifier with no prefix or object type");
1753 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1754 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00001755 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001756
1757 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00001758 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00001759 ObjectType,
1760 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001761
Douglas Gregordcee1a12009-08-06 05:28:30 +00001762 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00001763 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00001764 = cast_or_null<NamespaceDecl>(
1765 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00001766 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00001767 Prefix == NNS->getPrefix() &&
1768 NS == NNS->getAsNamespace())
1769 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001770
Douglas Gregordcee1a12009-08-06 05:28:30 +00001771 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1772 }
Mike Stump1eb44332009-09-09 15:08:12 +00001773
Douglas Gregordcee1a12009-08-06 05:28:30 +00001774 case NestedNameSpecifier::Global:
1775 // There is no meaningful transformation that one could perform on the
1776 // global scope.
1777 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001778
Douglas Gregordcee1a12009-08-06 05:28:30 +00001779 case NestedNameSpecifier::TypeSpecWithTemplate:
1780 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00001781 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregordcee1a12009-08-06 05:28:30 +00001782 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregord1067e52009-08-06 06:41:21 +00001783 if (T.isNull())
1784 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001785
Douglas Gregordcee1a12009-08-06 05:28:30 +00001786 if (!getDerived().AlwaysRebuild() &&
1787 Prefix == NNS->getPrefix() &&
1788 T == QualType(NNS->getAsType(), 0))
1789 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001790
1791 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1792 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregordcee1a12009-08-06 05:28:30 +00001793 T);
1794 }
1795 }
Mike Stump1eb44332009-09-09 15:08:12 +00001796
Douglas Gregordcee1a12009-08-06 05:28:30 +00001797 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00001798 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001799}
1800
1801template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001802DeclarationName
Douglas Gregor81499bb2009-09-03 22:13:48 +00001803TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +00001804 SourceLocation Loc,
1805 QualType ObjectType) {
Douglas Gregor81499bb2009-09-03 22:13:48 +00001806 if (!Name)
1807 return Name;
1808
1809 switch (Name.getNameKind()) {
1810 case DeclarationName::Identifier:
1811 case DeclarationName::ObjCZeroArgSelector:
1812 case DeclarationName::ObjCOneArgSelector:
1813 case DeclarationName::ObjCMultiArgSelector:
1814 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00001815 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00001816 case DeclarationName::CXXUsingDirective:
1817 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001818
Douglas Gregor81499bb2009-09-03 22:13:48 +00001819 case DeclarationName::CXXConstructorName:
1820 case DeclarationName::CXXDestructorName:
1821 case DeclarationName::CXXConversionFunctionName: {
1822 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregordd62b152009-10-19 22:04:39 +00001823 QualType T;
1824 if (!ObjectType.isNull() &&
1825 isa<TemplateSpecializationType>(Name.getCXXNameType())) {
1826 TemplateSpecializationType *SpecType
1827 = cast<TemplateSpecializationType>(Name.getCXXNameType());
1828 T = TransformTemplateSpecializationType(SpecType, ObjectType);
1829 } else
1830 T = getDerived().TransformType(Name.getCXXNameType());
Douglas Gregor81499bb2009-09-03 22:13:48 +00001831 if (T.isNull())
1832 return DeclarationName();
Mike Stump1eb44332009-09-09 15:08:12 +00001833
Douglas Gregor81499bb2009-09-03 22:13:48 +00001834 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump1eb44332009-09-09 15:08:12 +00001835 Name.getNameKind(),
Douglas Gregor81499bb2009-09-03 22:13:48 +00001836 SemaRef.Context.getCanonicalType(T));
Douglas Gregor81499bb2009-09-03 22:13:48 +00001837 }
Mike Stump1eb44332009-09-09 15:08:12 +00001838 }
1839
Douglas Gregor81499bb2009-09-03 22:13:48 +00001840 return DeclarationName();
1841}
1842
1843template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001844TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001845TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1846 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00001847 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001848 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00001849 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1850 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1851 if (!NNS)
1852 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001853
Douglas Gregord1067e52009-08-06 06:41:21 +00001854 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001855 TemplateDecl *TransTemplate
Douglas Gregord1067e52009-08-06 06:41:21 +00001856 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1857 if (!TransTemplate)
1858 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001859
Douglas Gregord1067e52009-08-06 06:41:21 +00001860 if (!getDerived().AlwaysRebuild() &&
1861 NNS == QTN->getQualifier() &&
1862 TransTemplate == Template)
1863 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001864
Douglas Gregord1067e52009-08-06 06:41:21 +00001865 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1866 TransTemplate);
1867 }
Mike Stump1eb44332009-09-09 15:08:12 +00001868
John McCallf7a1a742009-11-24 19:00:30 +00001869 // These should be getting filtered out before they make it into the AST.
1870 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00001871 }
Mike Stump1eb44332009-09-09 15:08:12 +00001872
Douglas Gregord1067e52009-08-06 06:41:21 +00001873 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001874 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00001875 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1876 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001877 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00001878 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001879
Douglas Gregord1067e52009-08-06 06:41:21 +00001880 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00001881 NNS == DTN->getQualifier() &&
1882 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00001883 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001884
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001885 if (DTN->isIdentifier())
1886 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1887 ObjectType);
1888
1889 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1890 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00001891 }
Mike Stump1eb44332009-09-09 15:08:12 +00001892
Douglas Gregord1067e52009-08-06 06:41:21 +00001893 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001894 TemplateDecl *TransTemplate
Douglas Gregord1067e52009-08-06 06:41:21 +00001895 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1896 if (!TransTemplate)
1897 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001898
Douglas Gregord1067e52009-08-06 06:41:21 +00001899 if (!getDerived().AlwaysRebuild() &&
1900 TransTemplate == Template)
1901 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001902
Douglas Gregord1067e52009-08-06 06:41:21 +00001903 return TemplateName(TransTemplate);
1904 }
Mike Stump1eb44332009-09-09 15:08:12 +00001905
John McCallf7a1a742009-11-24 19:00:30 +00001906 // These should be getting filtered out before they reach the AST.
1907 assert(false && "overloaded function decl survived to here");
1908 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00001909}
1910
1911template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00001912void TreeTransform<Derived>::InventTemplateArgumentLoc(
1913 const TemplateArgument &Arg,
1914 TemplateArgumentLoc &Output) {
1915 SourceLocation Loc = getDerived().getBaseLocation();
1916 switch (Arg.getKind()) {
1917 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00001918 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00001919 break;
1920
1921 case TemplateArgument::Type:
1922 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00001923 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall833ca992009-10-29 08:12:44 +00001924
1925 break;
1926
Douglas Gregor788cd062009-11-11 01:00:40 +00001927 case TemplateArgument::Template:
1928 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1929 break;
1930
John McCall833ca992009-10-29 08:12:44 +00001931 case TemplateArgument::Expression:
1932 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1933 break;
1934
1935 case TemplateArgument::Declaration:
1936 case TemplateArgument::Integral:
1937 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00001938 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00001939 break;
1940 }
1941}
1942
1943template<typename Derived>
1944bool TreeTransform<Derived>::TransformTemplateArgument(
1945 const TemplateArgumentLoc &Input,
1946 TemplateArgumentLoc &Output) {
1947 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00001948 switch (Arg.getKind()) {
1949 case TemplateArgument::Null:
1950 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00001951 Output = Input;
1952 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00001953
Douglas Gregor670444e2009-08-04 22:27:00 +00001954 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00001955 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00001956 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00001957 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00001958
1959 DI = getDerived().TransformType(DI);
1960 if (!DI) return true;
1961
1962 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1963 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00001964 }
Mike Stump1eb44332009-09-09 15:08:12 +00001965
Douglas Gregor670444e2009-08-04 22:27:00 +00001966 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00001967 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00001968 DeclarationName Name;
1969 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1970 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00001971 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor670444e2009-08-04 22:27:00 +00001972 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00001973 if (!D) return true;
1974
John McCall828bff22009-10-29 18:45:58 +00001975 Expr *SourceExpr = Input.getSourceDeclExpression();
1976 if (SourceExpr) {
1977 EnterExpressionEvaluationContext Unevaluated(getSema(),
1978 Action::Unevaluated);
1979 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1980 if (E.isInvalid())
1981 SourceExpr = NULL;
1982 else {
1983 SourceExpr = E.takeAs<Expr>();
1984 SourceExpr->Retain();
1985 }
1986 }
1987
1988 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00001989 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00001990 }
Mike Stump1eb44332009-09-09 15:08:12 +00001991
Douglas Gregor788cd062009-11-11 01:00:40 +00001992 case TemplateArgument::Template: {
1993 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1994 TemplateName Template
1995 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1996 if (Template.isNull())
1997 return true;
1998
1999 Output = TemplateArgumentLoc(TemplateArgument(Template),
2000 Input.getTemplateQualifierRange(),
2001 Input.getTemplateNameLoc());
2002 return false;
2003 }
2004
Douglas Gregor670444e2009-08-04 22:27:00 +00002005 case TemplateArgument::Expression: {
2006 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002007 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002008 Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002009
John McCall833ca992009-10-29 08:12:44 +00002010 Expr *InputExpr = Input.getSourceExpression();
2011 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2012
2013 Sema::OwningExprResult E
2014 = getDerived().TransformExpr(InputExpr);
2015 if (E.isInvalid()) return true;
2016
2017 Expr *ETaken = E.takeAs<Expr>();
John McCall828bff22009-10-29 18:45:58 +00002018 ETaken->Retain();
John McCall833ca992009-10-29 08:12:44 +00002019 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2020 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002021 }
Mike Stump1eb44332009-09-09 15:08:12 +00002022
Douglas Gregor670444e2009-08-04 22:27:00 +00002023 case TemplateArgument::Pack: {
2024 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2025 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002026 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002027 AEnd = Arg.pack_end();
2028 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002029
John McCall833ca992009-10-29 08:12:44 +00002030 // FIXME: preserve source information here when we start
2031 // caring about parameter packs.
2032
John McCall828bff22009-10-29 18:45:58 +00002033 TemplateArgumentLoc InputArg;
2034 TemplateArgumentLoc OutputArg;
2035 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2036 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002037 return true;
2038
John McCall828bff22009-10-29 18:45:58 +00002039 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002040 }
2041 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002042 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002043 true);
John McCall828bff22009-10-29 18:45:58 +00002044 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002045 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002046 }
2047 }
Mike Stump1eb44332009-09-09 15:08:12 +00002048
Douglas Gregor670444e2009-08-04 22:27:00 +00002049 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002050 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002051}
2052
Douglas Gregor577f75a2009-08-04 16:50:30 +00002053//===----------------------------------------------------------------------===//
2054// Type transformation
2055//===----------------------------------------------------------------------===//
2056
2057template<typename Derived>
2058QualType TreeTransform<Derived>::TransformType(QualType T) {
2059 if (getDerived().AlreadyTransformed(T))
2060 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002061
John McCalla2becad2009-10-21 00:40:46 +00002062 // Temporary workaround. All of these transformations should
2063 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002064 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002065 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCalla2becad2009-10-21 00:40:46 +00002066
John McCalla93c9342009-12-07 02:54:59 +00002067 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00002068
John McCalla2becad2009-10-21 00:40:46 +00002069 if (!NewDI)
2070 return QualType();
2071
2072 return NewDI->getType();
2073}
2074
2075template<typename Derived>
John McCalla93c9342009-12-07 02:54:59 +00002076TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00002077 if (getDerived().AlreadyTransformed(DI->getType()))
2078 return DI;
2079
2080 TypeLocBuilder TLB;
2081
2082 TypeLoc TL = DI->getTypeLoc();
2083 TLB.reserve(TL.getFullDataSize());
2084
2085 QualType Result = getDerived().TransformType(TLB, TL);
2086 if (Result.isNull())
2087 return 0;
2088
John McCalla93c9342009-12-07 02:54:59 +00002089 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002090}
2091
2092template<typename Derived>
2093QualType
2094TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
2095 switch (T.getTypeLocClass()) {
2096#define ABSTRACT_TYPELOC(CLASS, PARENT)
2097#define TYPELOC(CLASS, PARENT) \
2098 case TypeLoc::CLASS: \
2099 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2100#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002101 }
Mike Stump1eb44332009-09-09 15:08:12 +00002102
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002103 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002104 return QualType();
2105}
2106
2107/// FIXME: By default, this routine adds type qualifiers only to types
2108/// that can have qualifiers, and silently suppresses those qualifiers
2109/// that are not permitted (e.g., qualifiers on reference or function
2110/// types). This is the right thing for template instantiation, but
2111/// probably not for other clients.
2112template<typename Derived>
2113QualType
2114TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
2115 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002116 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002117
2118 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2119 if (Result.isNull())
2120 return QualType();
2121
2122 // Silently suppress qualifiers if the result type can't be qualified.
2123 // FIXME: this is the right thing for template instantiation, but
2124 // probably not for other clients.
2125 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002126 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002127
John McCalla2becad2009-10-21 00:40:46 +00002128 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2129
2130 TLB.push<QualifiedTypeLoc>(Result);
2131
2132 // No location information to preserve.
2133
2134 return Result;
2135}
2136
2137template <class TyLoc> static inline
2138QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2139 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2140 NewT.setNameLoc(T.getNameLoc());
2141 return T.getType();
2142}
2143
2144// Ugly metaprogramming macros because I couldn't be bothered to make
2145// the equivalent template version work.
2146#define TransformPointerLikeType(TypeClass) do { \
2147 QualType PointeeType \
2148 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2149 if (PointeeType.isNull()) \
2150 return QualType(); \
2151 \
2152 QualType Result = TL.getType(); \
2153 if (getDerived().AlwaysRebuild() || \
2154 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall85737a72009-10-30 00:06:24 +00002155 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2156 TL.getSigilLoc()); \
John McCalla2becad2009-10-21 00:40:46 +00002157 if (Result.isNull()) \
2158 return QualType(); \
2159 } \
2160 \
2161 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2162 NewT.setSigilLoc(TL.getSigilLoc()); \
2163 \
2164 return Result; \
2165} while(0)
2166
John McCalla2becad2009-10-21 00:40:46 +00002167template<typename Derived>
2168QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
2169 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002170 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2171 NewT.setBuiltinLoc(T.getBuiltinLoc());
2172 if (T.needsExtraLocalData())
2173 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2174 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002175}
Mike Stump1eb44332009-09-09 15:08:12 +00002176
Douglas Gregor577f75a2009-08-04 16:50:30 +00002177template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002178QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
2179 ComplexTypeLoc T) {
2180 // FIXME: recurse?
2181 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002182}
Mike Stump1eb44332009-09-09 15:08:12 +00002183
Douglas Gregor577f75a2009-08-04 16:50:30 +00002184template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002185QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
2186 PointerTypeLoc TL) {
2187 TransformPointerLikeType(PointerType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002188}
Mike Stump1eb44332009-09-09 15:08:12 +00002189
2190template<typename Derived>
2191QualType
John McCalla2becad2009-10-21 00:40:46 +00002192TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
2193 BlockPointerTypeLoc TL) {
2194 TransformPointerLikeType(BlockPointerType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002195}
2196
John McCall85737a72009-10-30 00:06:24 +00002197/// Transforms a reference type. Note that somewhat paradoxically we
2198/// don't care whether the type itself is an l-value type or an r-value
2199/// type; we only care if the type was *written* as an l-value type
2200/// or an r-value type.
2201template<typename Derived>
2202QualType
2203TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
2204 ReferenceTypeLoc TL) {
2205 const ReferenceType *T = TL.getTypePtr();
2206
2207 // Note that this works with the pointee-as-written.
2208 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2209 if (PointeeType.isNull())
2210 return QualType();
2211
2212 QualType Result = TL.getType();
2213 if (getDerived().AlwaysRebuild() ||
2214 PointeeType != T->getPointeeTypeAsWritten()) {
2215 Result = getDerived().RebuildReferenceType(PointeeType,
2216 T->isSpelledAsLValue(),
2217 TL.getSigilLoc());
2218 if (Result.isNull())
2219 return QualType();
2220 }
2221
2222 // r-value references can be rebuilt as l-value references.
2223 ReferenceTypeLoc NewTL;
2224 if (isa<LValueReferenceType>(Result))
2225 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2226 else
2227 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2228 NewTL.setSigilLoc(TL.getSigilLoc());
2229
2230 return Result;
2231}
2232
Mike Stump1eb44332009-09-09 15:08:12 +00002233template<typename Derived>
2234QualType
John McCalla2becad2009-10-21 00:40:46 +00002235TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
2236 LValueReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00002237 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002238}
2239
Mike Stump1eb44332009-09-09 15:08:12 +00002240template<typename Derived>
2241QualType
John McCalla2becad2009-10-21 00:40:46 +00002242TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
2243 RValueReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00002244 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002245}
Mike Stump1eb44332009-09-09 15:08:12 +00002246
Douglas Gregor577f75a2009-08-04 16:50:30 +00002247template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002248QualType
John McCalla2becad2009-10-21 00:40:46 +00002249TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
2250 MemberPointerTypeLoc TL) {
2251 MemberPointerType *T = TL.getTypePtr();
2252
2253 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002254 if (PointeeType.isNull())
2255 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002256
John McCalla2becad2009-10-21 00:40:46 +00002257 // TODO: preserve source information for this.
2258 QualType ClassType
2259 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002260 if (ClassType.isNull())
2261 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002262
John McCalla2becad2009-10-21 00:40:46 +00002263 QualType Result = TL.getType();
2264 if (getDerived().AlwaysRebuild() ||
2265 PointeeType != T->getPointeeType() ||
2266 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002267 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2268 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002269 if (Result.isNull())
2270 return QualType();
2271 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002272
John McCalla2becad2009-10-21 00:40:46 +00002273 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2274 NewTL.setSigilLoc(TL.getSigilLoc());
2275
2276 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002277}
2278
Mike Stump1eb44332009-09-09 15:08:12 +00002279template<typename Derived>
2280QualType
John McCalla2becad2009-10-21 00:40:46 +00002281TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
2282 ConstantArrayTypeLoc TL) {
2283 ConstantArrayType *T = TL.getTypePtr();
2284 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002285 if (ElementType.isNull())
2286 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002287
John McCalla2becad2009-10-21 00:40:46 +00002288 QualType Result = TL.getType();
2289 if (getDerived().AlwaysRebuild() ||
2290 ElementType != T->getElementType()) {
2291 Result = getDerived().RebuildConstantArrayType(ElementType,
2292 T->getSizeModifier(),
2293 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002294 T->getIndexTypeCVRQualifiers(),
2295 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002296 if (Result.isNull())
2297 return QualType();
2298 }
2299
2300 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2301 NewTL.setLBracketLoc(TL.getLBracketLoc());
2302 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002303
John McCalla2becad2009-10-21 00:40:46 +00002304 Expr *Size = TL.getSizeExpr();
2305 if (Size) {
2306 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2307 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2308 }
2309 NewTL.setSizeExpr(Size);
2310
2311 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002312}
Mike Stump1eb44332009-09-09 15:08:12 +00002313
Douglas Gregor577f75a2009-08-04 16:50:30 +00002314template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002315QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002316 TypeLocBuilder &TLB,
2317 IncompleteArrayTypeLoc TL) {
2318 IncompleteArrayType *T = TL.getTypePtr();
2319 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002320 if (ElementType.isNull())
2321 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002322
John McCalla2becad2009-10-21 00:40:46 +00002323 QualType Result = TL.getType();
2324 if (getDerived().AlwaysRebuild() ||
2325 ElementType != T->getElementType()) {
2326 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002327 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002328 T->getIndexTypeCVRQualifiers(),
2329 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002330 if (Result.isNull())
2331 return QualType();
2332 }
2333
2334 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2335 NewTL.setLBracketLoc(TL.getLBracketLoc());
2336 NewTL.setRBracketLoc(TL.getRBracketLoc());
2337 NewTL.setSizeExpr(0);
2338
2339 return Result;
2340}
2341
2342template<typename Derived>
2343QualType
2344TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
2345 VariableArrayTypeLoc TL) {
2346 VariableArrayType *T = TL.getTypePtr();
2347 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2348 if (ElementType.isNull())
2349 return QualType();
2350
2351 // Array bounds are not potentially evaluated contexts
2352 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2353
2354 Sema::OwningExprResult SizeResult
2355 = getDerived().TransformExpr(T->getSizeExpr());
2356 if (SizeResult.isInvalid())
2357 return QualType();
2358
2359 Expr *Size = static_cast<Expr*>(SizeResult.get());
2360
2361 QualType Result = TL.getType();
2362 if (getDerived().AlwaysRebuild() ||
2363 ElementType != T->getElementType() ||
2364 Size != T->getSizeExpr()) {
2365 Result = getDerived().RebuildVariableArrayType(ElementType,
2366 T->getSizeModifier(),
2367 move(SizeResult),
2368 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002369 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002370 if (Result.isNull())
2371 return QualType();
2372 }
2373 else SizeResult.take();
2374
2375 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2376 NewTL.setLBracketLoc(TL.getLBracketLoc());
2377 NewTL.setRBracketLoc(TL.getRBracketLoc());
2378 NewTL.setSizeExpr(Size);
2379
2380 return Result;
2381}
2382
2383template<typename Derived>
2384QualType
2385TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
2386 DependentSizedArrayTypeLoc TL) {
2387 DependentSizedArrayType *T = TL.getTypePtr();
2388 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2389 if (ElementType.isNull())
2390 return QualType();
2391
2392 // Array bounds are not potentially evaluated contexts
2393 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2394
2395 Sema::OwningExprResult SizeResult
2396 = getDerived().TransformExpr(T->getSizeExpr());
2397 if (SizeResult.isInvalid())
2398 return QualType();
2399
2400 Expr *Size = static_cast<Expr*>(SizeResult.get());
2401
2402 QualType Result = TL.getType();
2403 if (getDerived().AlwaysRebuild() ||
2404 ElementType != T->getElementType() ||
2405 Size != T->getSizeExpr()) {
2406 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2407 T->getSizeModifier(),
2408 move(SizeResult),
2409 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002410 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002411 if (Result.isNull())
2412 return QualType();
2413 }
2414 else SizeResult.take();
2415
2416 // We might have any sort of array type now, but fortunately they
2417 // all have the same location layout.
2418 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2419 NewTL.setLBracketLoc(TL.getLBracketLoc());
2420 NewTL.setRBracketLoc(TL.getRBracketLoc());
2421 NewTL.setSizeExpr(Size);
2422
2423 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002424}
Mike Stump1eb44332009-09-09 15:08:12 +00002425
2426template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002427QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002428 TypeLocBuilder &TLB,
2429 DependentSizedExtVectorTypeLoc TL) {
2430 DependentSizedExtVectorType *T = TL.getTypePtr();
2431
2432 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002433 QualType ElementType = getDerived().TransformType(T->getElementType());
2434 if (ElementType.isNull())
2435 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002436
Douglas Gregor670444e2009-08-04 22:27:00 +00002437 // Vector sizes are not potentially evaluated contexts
2438 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2439
Douglas Gregor577f75a2009-08-04 16:50:30 +00002440 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2441 if (Size.isInvalid())
2442 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002443
John McCalla2becad2009-10-21 00:40:46 +00002444 QualType Result = TL.getType();
2445 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002446 ElementType != T->getElementType() ||
2447 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002448 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002449 move(Size),
2450 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002451 if (Result.isNull())
2452 return QualType();
2453 }
2454 else Size.take();
2455
2456 // Result might be dependent or not.
2457 if (isa<DependentSizedExtVectorType>(Result)) {
2458 DependentSizedExtVectorTypeLoc NewTL
2459 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2460 NewTL.setNameLoc(TL.getNameLoc());
2461 } else {
2462 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2463 NewTL.setNameLoc(TL.getNameLoc());
2464 }
2465
2466 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002467}
Mike Stump1eb44332009-09-09 15:08:12 +00002468
2469template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002470QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
2471 VectorTypeLoc TL) {
2472 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002473 QualType ElementType = getDerived().TransformType(T->getElementType());
2474 if (ElementType.isNull())
2475 return QualType();
2476
John McCalla2becad2009-10-21 00:40:46 +00002477 QualType Result = TL.getType();
2478 if (getDerived().AlwaysRebuild() ||
2479 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002480 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2481 T->isAltiVec(), T->isPixel());
John McCalla2becad2009-10-21 00:40:46 +00002482 if (Result.isNull())
2483 return QualType();
2484 }
2485
2486 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2487 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002488
John McCalla2becad2009-10-21 00:40:46 +00002489 return Result;
2490}
2491
2492template<typename Derived>
2493QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
2494 ExtVectorTypeLoc TL) {
2495 VectorType *T = TL.getTypePtr();
2496 QualType ElementType = getDerived().TransformType(T->getElementType());
2497 if (ElementType.isNull())
2498 return QualType();
2499
2500 QualType Result = TL.getType();
2501 if (getDerived().AlwaysRebuild() ||
2502 ElementType != T->getElementType()) {
2503 Result = getDerived().RebuildExtVectorType(ElementType,
2504 T->getNumElements(),
2505 /*FIXME*/ SourceLocation());
2506 if (Result.isNull())
2507 return QualType();
2508 }
2509
2510 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2511 NewTL.setNameLoc(TL.getNameLoc());
2512
2513 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002514}
Mike Stump1eb44332009-09-09 15:08:12 +00002515
2516template<typename Derived>
2517QualType
John McCalla2becad2009-10-21 00:40:46 +00002518TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
2519 FunctionProtoTypeLoc TL) {
2520 FunctionProtoType *T = TL.getTypePtr();
2521 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002522 if (ResultType.isNull())
2523 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002524
John McCalla2becad2009-10-21 00:40:46 +00002525 // Transform the parameters.
Douglas Gregor577f75a2009-08-04 16:50:30 +00002526 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002527 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2528 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2529 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump1eb44332009-09-09 15:08:12 +00002530
John McCalla2becad2009-10-21 00:40:46 +00002531 QualType NewType;
2532 ParmVarDecl *NewParm;
2533
2534 if (OldParm) {
John McCalla93c9342009-12-07 02:54:59 +00002535 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCalla2becad2009-10-21 00:40:46 +00002536 assert(OldDI->getType() == T->getArgType(i));
2537
John McCalla93c9342009-12-07 02:54:59 +00002538 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCalla2becad2009-10-21 00:40:46 +00002539 if (!NewDI)
2540 return QualType();
2541
2542 if (NewDI == OldDI)
2543 NewParm = OldParm;
2544 else
2545 NewParm = ParmVarDecl::Create(SemaRef.Context,
2546 OldParm->getDeclContext(),
2547 OldParm->getLocation(),
2548 OldParm->getIdentifier(),
2549 NewDI->getType(),
2550 NewDI,
2551 OldParm->getStorageClass(),
2552 /* DefArg */ NULL);
2553 NewType = NewParm->getType();
2554
2555 // Deal with the possibility that we don't have a parameter
2556 // declaration for this parameter.
2557 } else {
2558 NewParm = 0;
2559
2560 QualType OldType = T->getArgType(i);
2561 NewType = getDerived().TransformType(OldType);
2562 if (NewType.isNull())
2563 return QualType();
2564 }
2565
2566 ParamTypes.push_back(NewType);
2567 ParamDecls.push_back(NewParm);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002568 }
Mike Stump1eb44332009-09-09 15:08:12 +00002569
John McCalla2becad2009-10-21 00:40:46 +00002570 QualType Result = TL.getType();
2571 if (getDerived().AlwaysRebuild() ||
2572 ResultType != T->getResultType() ||
2573 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2574 Result = getDerived().RebuildFunctionProtoType(ResultType,
2575 ParamTypes.data(),
2576 ParamTypes.size(),
2577 T->isVariadic(),
2578 T->getTypeQuals());
2579 if (Result.isNull())
2580 return QualType();
2581 }
Mike Stump1eb44332009-09-09 15:08:12 +00002582
John McCalla2becad2009-10-21 00:40:46 +00002583 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2584 NewTL.setLParenLoc(TL.getLParenLoc());
2585 NewTL.setRParenLoc(TL.getRParenLoc());
2586 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2587 NewTL.setArg(i, ParamDecls[i]);
2588
2589 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002590}
Mike Stump1eb44332009-09-09 15:08:12 +00002591
Douglas Gregor577f75a2009-08-04 16:50:30 +00002592template<typename Derived>
2593QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002594 TypeLocBuilder &TLB,
2595 FunctionNoProtoTypeLoc TL) {
2596 FunctionNoProtoType *T = TL.getTypePtr();
2597 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2598 if (ResultType.isNull())
2599 return QualType();
2600
2601 QualType Result = TL.getType();
2602 if (getDerived().AlwaysRebuild() ||
2603 ResultType != T->getResultType())
2604 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2605
2606 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2607 NewTL.setLParenLoc(TL.getLParenLoc());
2608 NewTL.setRParenLoc(TL.getRParenLoc());
2609
2610 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002611}
Mike Stump1eb44332009-09-09 15:08:12 +00002612
John McCalled976492009-12-04 22:46:56 +00002613template<typename Derived> QualType
2614TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
2615 UnresolvedUsingTypeLoc TL) {
2616 UnresolvedUsingType *T = TL.getTypePtr();
2617 Decl *D = getDerived().TransformDecl(T->getDecl());
2618 if (!D)
2619 return QualType();
2620
2621 QualType Result = TL.getType();
2622 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2623 Result = getDerived().RebuildUnresolvedUsingType(D);
2624 if (Result.isNull())
2625 return QualType();
2626 }
2627
2628 // We might get an arbitrary type spec type back. We should at
2629 // least always get a type spec type, though.
2630 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2631 NewTL.setNameLoc(TL.getNameLoc());
2632
2633 return Result;
2634}
2635
Douglas Gregor577f75a2009-08-04 16:50:30 +00002636template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002637QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
2638 TypedefTypeLoc TL) {
2639 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002640 TypedefDecl *Typedef
2641 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2642 if (!Typedef)
2643 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002644
John McCalla2becad2009-10-21 00:40:46 +00002645 QualType Result = TL.getType();
2646 if (getDerived().AlwaysRebuild() ||
2647 Typedef != T->getDecl()) {
2648 Result = getDerived().RebuildTypedefType(Typedef);
2649 if (Result.isNull())
2650 return QualType();
2651 }
Mike Stump1eb44332009-09-09 15:08:12 +00002652
John McCalla2becad2009-10-21 00:40:46 +00002653 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2654 NewTL.setNameLoc(TL.getNameLoc());
2655
2656 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002657}
Mike Stump1eb44332009-09-09 15:08:12 +00002658
Douglas Gregor577f75a2009-08-04 16:50:30 +00002659template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002660QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
2661 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00002662 // typeof expressions are not potentially evaluated contexts
2663 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002664
John McCallcfb708c2010-01-13 20:03:27 +00002665 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002666 if (E.isInvalid())
2667 return QualType();
2668
John McCalla2becad2009-10-21 00:40:46 +00002669 QualType Result = TL.getType();
2670 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00002671 E.get() != TL.getUnderlyingExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002672 Result = getDerived().RebuildTypeOfExprType(move(E));
2673 if (Result.isNull())
2674 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002675 }
John McCalla2becad2009-10-21 00:40:46 +00002676 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002677
John McCalla2becad2009-10-21 00:40:46 +00002678 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002679 NewTL.setTypeofLoc(TL.getTypeofLoc());
2680 NewTL.setLParenLoc(TL.getLParenLoc());
2681 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00002682
2683 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002684}
Mike Stump1eb44332009-09-09 15:08:12 +00002685
2686template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002687QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
2688 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00002689 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2690 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2691 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00002692 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002693
John McCalla2becad2009-10-21 00:40:46 +00002694 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00002695 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2696 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00002697 if (Result.isNull())
2698 return QualType();
2699 }
Mike Stump1eb44332009-09-09 15:08:12 +00002700
John McCalla2becad2009-10-21 00:40:46 +00002701 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002702 NewTL.setTypeofLoc(TL.getTypeofLoc());
2703 NewTL.setLParenLoc(TL.getLParenLoc());
2704 NewTL.setRParenLoc(TL.getRParenLoc());
2705 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00002706
2707 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002708}
Mike Stump1eb44332009-09-09 15:08:12 +00002709
2710template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002711QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
2712 DecltypeTypeLoc TL) {
2713 DecltypeType *T = TL.getTypePtr();
2714
Douglas Gregor670444e2009-08-04 22:27:00 +00002715 // decltype expressions are not potentially evaluated contexts
2716 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002717
Douglas Gregor577f75a2009-08-04 16:50:30 +00002718 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2719 if (E.isInvalid())
2720 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002721
John McCalla2becad2009-10-21 00:40:46 +00002722 QualType Result = TL.getType();
2723 if (getDerived().AlwaysRebuild() ||
2724 E.get() != T->getUnderlyingExpr()) {
2725 Result = getDerived().RebuildDecltypeType(move(E));
2726 if (Result.isNull())
2727 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002728 }
John McCalla2becad2009-10-21 00:40:46 +00002729 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002730
John McCalla2becad2009-10-21 00:40:46 +00002731 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2732 NewTL.setNameLoc(TL.getNameLoc());
2733
2734 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002735}
2736
2737template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002738QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
2739 RecordTypeLoc TL) {
2740 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002741 RecordDecl *Record
John McCalla2becad2009-10-21 00:40:46 +00002742 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002743 if (!Record)
2744 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002745
John McCalla2becad2009-10-21 00:40:46 +00002746 QualType Result = TL.getType();
2747 if (getDerived().AlwaysRebuild() ||
2748 Record != T->getDecl()) {
2749 Result = getDerived().RebuildRecordType(Record);
2750 if (Result.isNull())
2751 return QualType();
2752 }
Mike Stump1eb44332009-09-09 15:08:12 +00002753
John McCalla2becad2009-10-21 00:40:46 +00002754 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2755 NewTL.setNameLoc(TL.getNameLoc());
2756
2757 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002758}
Mike Stump1eb44332009-09-09 15:08:12 +00002759
2760template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002761QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
2762 EnumTypeLoc TL) {
2763 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002764 EnumDecl *Enum
John McCalla2becad2009-10-21 00:40:46 +00002765 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002766 if (!Enum)
2767 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002768
John McCalla2becad2009-10-21 00:40:46 +00002769 QualType Result = TL.getType();
2770 if (getDerived().AlwaysRebuild() ||
2771 Enum != T->getDecl()) {
2772 Result = getDerived().RebuildEnumType(Enum);
2773 if (Result.isNull())
2774 return QualType();
2775 }
Mike Stump1eb44332009-09-09 15:08:12 +00002776
John McCalla2becad2009-10-21 00:40:46 +00002777 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2778 NewTL.setNameLoc(TL.getNameLoc());
2779
2780 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002781}
John McCall7da24312009-09-05 00:15:47 +00002782
2783template <typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002784QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
2785 ElaboratedTypeLoc TL) {
2786 ElaboratedType *T = TL.getTypePtr();
2787
2788 // FIXME: this should be a nested type.
John McCall7da24312009-09-05 00:15:47 +00002789 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2790 if (Underlying.isNull())
2791 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002792
John McCalla2becad2009-10-21 00:40:46 +00002793 QualType Result = TL.getType();
2794 if (getDerived().AlwaysRebuild() ||
2795 Underlying != T->getUnderlyingType()) {
2796 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2797 if (Result.isNull())
2798 return QualType();
2799 }
Mike Stump1eb44332009-09-09 15:08:12 +00002800
John McCalla2becad2009-10-21 00:40:46 +00002801 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2802 NewTL.setNameLoc(TL.getNameLoc());
2803
2804 return Result;
John McCall7da24312009-09-05 00:15:47 +00002805}
Mike Stump1eb44332009-09-09 15:08:12 +00002806
2807
Douglas Gregor577f75a2009-08-04 16:50:30 +00002808template<typename Derived>
2809QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00002810 TypeLocBuilder &TLB,
2811 TemplateTypeParmTypeLoc TL) {
2812 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002813}
2814
Mike Stump1eb44332009-09-09 15:08:12 +00002815template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00002816QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00002817 TypeLocBuilder &TLB,
2818 SubstTemplateTypeParmTypeLoc TL) {
2819 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00002820}
2821
2822template<typename Derived>
Douglas Gregordd62b152009-10-19 22:04:39 +00002823inline QualType
2824TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCalla2becad2009-10-21 00:40:46 +00002825 TypeLocBuilder &TLB,
2826 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00002827 return TransformTemplateSpecializationType(TLB, TL, QualType());
2828}
John McCalla2becad2009-10-21 00:40:46 +00002829
John McCall833ca992009-10-29 08:12:44 +00002830template<typename Derived>
2831QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2832 const TemplateSpecializationType *TST,
2833 QualType ObjectType) {
2834 // FIXME: this entire method is a temporary workaround; callers
2835 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00002836
John McCall833ca992009-10-29 08:12:44 +00002837 // Fake up a TemplateSpecializationTypeLoc.
2838 TypeLocBuilder TLB;
2839 TemplateSpecializationTypeLoc TL
2840 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2841
John McCall828bff22009-10-29 18:45:58 +00002842 SourceLocation BaseLoc = getDerived().getBaseLocation();
2843
2844 TL.setTemplateNameLoc(BaseLoc);
2845 TL.setLAngleLoc(BaseLoc);
2846 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00002847 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2848 const TemplateArgument &TA = TST->getArg(i);
2849 TemplateArgumentLoc TAL;
2850 getDerived().InventTemplateArgumentLoc(TA, TAL);
2851 TL.setArgLocInfo(i, TAL.getLocInfo());
2852 }
2853
2854 TypeLocBuilder IgnoredTLB;
2855 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00002856}
2857
2858template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002859QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00002860 TypeLocBuilder &TLB,
2861 TemplateSpecializationTypeLoc TL,
2862 QualType ObjectType) {
2863 const TemplateSpecializationType *T = TL.getTypePtr();
2864
Mike Stump1eb44332009-09-09 15:08:12 +00002865 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00002866 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002867 if (Template.isNull())
2868 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002869
John McCalld5532b62009-11-23 01:53:49 +00002870 TemplateArgumentListInfo NewTemplateArgs;
2871 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2872 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2873
2874 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2875 TemplateArgumentLoc Loc;
2876 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00002877 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00002878 NewTemplateArgs.addArgument(Loc);
2879 }
Mike Stump1eb44332009-09-09 15:08:12 +00002880
John McCall833ca992009-10-29 08:12:44 +00002881 // FIXME: maybe don't rebuild if all the template arguments are the same.
2882
2883 QualType Result =
2884 getDerived().RebuildTemplateSpecializationType(Template,
2885 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00002886 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00002887
2888 if (!Result.isNull()) {
2889 TemplateSpecializationTypeLoc NewTL
2890 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2891 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2892 NewTL.setLAngleLoc(TL.getLAngleLoc());
2893 NewTL.setRAngleLoc(TL.getRAngleLoc());
2894 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2895 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002896 }
Mike Stump1eb44332009-09-09 15:08:12 +00002897
John McCall833ca992009-10-29 08:12:44 +00002898 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002899}
Mike Stump1eb44332009-09-09 15:08:12 +00002900
2901template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002902QualType
2903TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
2904 QualifiedNameTypeLoc TL) {
2905 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002906 NestedNameSpecifier *NNS
2907 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2908 SourceRange());
2909 if (!NNS)
2910 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002911
Douglas Gregor577f75a2009-08-04 16:50:30 +00002912 QualType Named = getDerived().TransformType(T->getNamedType());
2913 if (Named.isNull())
2914 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002915
John McCalla2becad2009-10-21 00:40:46 +00002916 QualType Result = TL.getType();
2917 if (getDerived().AlwaysRebuild() ||
2918 NNS != T->getQualifier() ||
2919 Named != T->getNamedType()) {
2920 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2921 if (Result.isNull())
2922 return QualType();
2923 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002924
John McCalla2becad2009-10-21 00:40:46 +00002925 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2926 NewTL.setNameLoc(TL.getNameLoc());
2927
2928 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002929}
Mike Stump1eb44332009-09-09 15:08:12 +00002930
2931template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002932QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
2933 TypenameTypeLoc TL) {
2934 TypenameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00002935
2936 /* FIXME: preserve source information better than this */
2937 SourceRange SR(TL.getNameLoc());
2938
Douglas Gregor577f75a2009-08-04 16:50:30 +00002939 NestedNameSpecifier *NNS
John McCall833ca992009-10-29 08:12:44 +00002940 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002941 if (!NNS)
2942 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002943
John McCalla2becad2009-10-21 00:40:46 +00002944 QualType Result;
2945
Douglas Gregor577f75a2009-08-04 16:50:30 +00002946 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002947 QualType NewTemplateId
Douglas Gregor577f75a2009-08-04 16:50:30 +00002948 = getDerived().TransformType(QualType(TemplateId, 0));
2949 if (NewTemplateId.isNull())
2950 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002951
Douglas Gregor577f75a2009-08-04 16:50:30 +00002952 if (!getDerived().AlwaysRebuild() &&
2953 NNS == T->getQualifier() &&
2954 NewTemplateId == QualType(TemplateId, 0))
2955 return QualType(T, 0);
Mike Stump1eb44332009-09-09 15:08:12 +00002956
John McCalla2becad2009-10-21 00:40:46 +00002957 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2958 } else {
John McCall833ca992009-10-29 08:12:44 +00002959 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002960 }
John McCalla2becad2009-10-21 00:40:46 +00002961 if (Result.isNull())
2962 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002963
John McCalla2becad2009-10-21 00:40:46 +00002964 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2965 NewTL.setNameLoc(TL.getNameLoc());
2966
2967 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002968}
Mike Stump1eb44332009-09-09 15:08:12 +00002969
Douglas Gregor577f75a2009-08-04 16:50:30 +00002970template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002971QualType
2972TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
2973 ObjCInterfaceTypeLoc TL) {
John McCall54e14c42009-10-22 22:37:11 +00002974 assert(false && "TransformObjCInterfaceType unimplemented");
2975 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002976}
Mike Stump1eb44332009-09-09 15:08:12 +00002977
2978template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002979QualType
2980TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
2981 ObjCObjectPointerTypeLoc TL) {
John McCall54e14c42009-10-22 22:37:11 +00002982 assert(false && "TransformObjCObjectPointerType unimplemented");
2983 return QualType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00002984}
2985
Douglas Gregor577f75a2009-08-04 16:50:30 +00002986//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00002987// Statement transformation
2988//===----------------------------------------------------------------------===//
2989template<typename Derived>
2990Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00002991TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2992 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00002993}
2994
2995template<typename Derived>
2996Sema::OwningStmtResult
2997TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2998 return getDerived().TransformCompoundStmt(S, false);
2999}
3000
3001template<typename Derived>
3002Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003003TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003004 bool IsStmtExpr) {
3005 bool SubStmtChanged = false;
3006 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3007 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3008 B != BEnd; ++B) {
3009 OwningStmtResult Result = getDerived().TransformStmt(*B);
3010 if (Result.isInvalid())
3011 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003012
Douglas Gregor43959a92009-08-20 07:17:43 +00003013 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3014 Statements.push_back(Result.takeAs<Stmt>());
3015 }
Mike Stump1eb44332009-09-09 15:08:12 +00003016
Douglas Gregor43959a92009-08-20 07:17:43 +00003017 if (!getDerived().AlwaysRebuild() &&
3018 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003019 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003020
3021 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3022 move_arg(Statements),
3023 S->getRBracLoc(),
3024 IsStmtExpr);
3025}
Mike Stump1eb44332009-09-09 15:08:12 +00003026
Douglas Gregor43959a92009-08-20 07:17:43 +00003027template<typename Derived>
3028Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003029TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman264c1f82009-11-19 03:14:00 +00003030 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3031 {
3032 // The case value expressions are not potentially evaluated.
3033 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003034
Eli Friedman264c1f82009-11-19 03:14:00 +00003035 // Transform the left-hand case value.
3036 LHS = getDerived().TransformExpr(S->getLHS());
3037 if (LHS.isInvalid())
3038 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003039
Eli Friedman264c1f82009-11-19 03:14:00 +00003040 // Transform the right-hand case value (for the GNU case-range extension).
3041 RHS = getDerived().TransformExpr(S->getRHS());
3042 if (RHS.isInvalid())
3043 return SemaRef.StmtError();
3044 }
Mike Stump1eb44332009-09-09 15:08:12 +00003045
Douglas Gregor43959a92009-08-20 07:17:43 +00003046 // Build the case statement.
3047 // Case statements are always rebuilt so that they will attached to their
3048 // transformed switch statement.
3049 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3050 move(LHS),
3051 S->getEllipsisLoc(),
3052 move(RHS),
3053 S->getColonLoc());
3054 if (Case.isInvalid())
3055 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003056
Douglas Gregor43959a92009-08-20 07:17:43 +00003057 // Transform the statement following the case
3058 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3059 if (SubStmt.isInvalid())
3060 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003061
Douglas Gregor43959a92009-08-20 07:17:43 +00003062 // Attach the body to the case statement
3063 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3064}
3065
3066template<typename Derived>
3067Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003068TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003069 // Transform the statement following the default case
3070 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3071 if (SubStmt.isInvalid())
3072 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003073
Douglas Gregor43959a92009-08-20 07:17:43 +00003074 // Default statements are always rebuilt
3075 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3076 move(SubStmt));
3077}
Mike Stump1eb44332009-09-09 15:08:12 +00003078
Douglas Gregor43959a92009-08-20 07:17:43 +00003079template<typename Derived>
3080Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003081TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003082 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3083 if (SubStmt.isInvalid())
3084 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003085
Douglas Gregor43959a92009-08-20 07:17:43 +00003086 // FIXME: Pass the real colon location in.
3087 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3088 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3089 move(SubStmt));
3090}
Mike Stump1eb44332009-09-09 15:08:12 +00003091
Douglas Gregor43959a92009-08-20 07:17:43 +00003092template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003093Sema::OwningStmtResult
3094TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003095 // Transform the condition
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003096 OwningExprResult Cond(SemaRef);
3097 VarDecl *ConditionVar = 0;
3098 if (S->getConditionVariable()) {
3099 ConditionVar
3100 = cast_or_null<VarDecl>(
3101 getDerived().TransformDefinition(S->getConditionVariable()));
3102 if (!ConditionVar)
3103 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003104 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003105 Cond = getDerived().TransformExpr(S->getCond());
3106
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003107 if (Cond.isInvalid())
3108 return SemaRef.StmtError();
3109 }
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003110
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003111 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump1eb44332009-09-09 15:08:12 +00003112
Douglas Gregor43959a92009-08-20 07:17:43 +00003113 // Transform the "then" branch.
3114 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3115 if (Then.isInvalid())
3116 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003117
Douglas Gregor43959a92009-08-20 07:17:43 +00003118 // Transform the "else" branch.
3119 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3120 if (Else.isInvalid())
3121 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003122
Douglas Gregor43959a92009-08-20 07:17:43 +00003123 if (!getDerived().AlwaysRebuild() &&
3124 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003125 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003126 Then.get() == S->getThen() &&
3127 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003128 return SemaRef.Owned(S->Retain());
3129
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003130 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3131 move(Then),
Mike Stump1eb44332009-09-09 15:08:12 +00003132 S->getElseLoc(), move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +00003133}
3134
3135template<typename Derived>
3136Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003137TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003138 // Transform the condition.
Douglas Gregord3d53012009-11-24 17:07:59 +00003139 OwningExprResult Cond(SemaRef);
3140 VarDecl *ConditionVar = 0;
3141 if (S->getConditionVariable()) {
3142 ConditionVar
3143 = cast_or_null<VarDecl>(
3144 getDerived().TransformDefinition(S->getConditionVariable()));
3145 if (!ConditionVar)
3146 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003147 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003148 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003149
3150 if (Cond.isInvalid())
3151 return SemaRef.StmtError();
3152 }
Mike Stump1eb44332009-09-09 15:08:12 +00003153
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003154 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003155
Douglas Gregor43959a92009-08-20 07:17:43 +00003156 // Rebuild the switch statement.
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003157 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3158 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003159 if (Switch.isInvalid())
3160 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003161
Douglas Gregor43959a92009-08-20 07:17:43 +00003162 // Transform the body of the switch statement.
3163 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3164 if (Body.isInvalid())
3165 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003166
Douglas Gregor43959a92009-08-20 07:17:43 +00003167 // Complete the switch statement.
3168 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3169 move(Body));
3170}
Mike Stump1eb44332009-09-09 15:08:12 +00003171
Douglas Gregor43959a92009-08-20 07:17:43 +00003172template<typename Derived>
3173Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003174TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003175 // Transform the condition
Douglas Gregor5656e142009-11-24 21:15:44 +00003176 OwningExprResult Cond(SemaRef);
3177 VarDecl *ConditionVar = 0;
3178 if (S->getConditionVariable()) {
3179 ConditionVar
3180 = cast_or_null<VarDecl>(
3181 getDerived().TransformDefinition(S->getConditionVariable()));
3182 if (!ConditionVar)
3183 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003184 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003185 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003186
3187 if (Cond.isInvalid())
3188 return SemaRef.StmtError();
3189 }
Mike Stump1eb44332009-09-09 15:08:12 +00003190
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003191 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump1eb44332009-09-09 15:08:12 +00003192
Douglas Gregor43959a92009-08-20 07:17:43 +00003193 // Transform the body
3194 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3195 if (Body.isInvalid())
3196 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003197
Douglas Gregor43959a92009-08-20 07:17:43 +00003198 if (!getDerived().AlwaysRebuild() &&
3199 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003200 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003201 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003202 return SemaRef.Owned(S->Retain());
3203
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003204 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3205 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003206}
Mike Stump1eb44332009-09-09 15:08:12 +00003207
Douglas Gregor43959a92009-08-20 07:17:43 +00003208template<typename Derived>
3209Sema::OwningStmtResult
3210TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3211 // Transform the condition
3212 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3213 if (Cond.isInvalid())
3214 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003215
Douglas Gregor43959a92009-08-20 07:17:43 +00003216 // Transform the body
3217 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3218 if (Body.isInvalid())
3219 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003220
Douglas Gregor43959a92009-08-20 07:17:43 +00003221 if (!getDerived().AlwaysRebuild() &&
3222 Cond.get() == S->getCond() &&
3223 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003224 return SemaRef.Owned(S->Retain());
3225
Douglas Gregor43959a92009-08-20 07:17:43 +00003226 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3227 /*FIXME:*/S->getWhileLoc(), move(Cond),
3228 S->getRParenLoc());
3229}
Mike Stump1eb44332009-09-09 15:08:12 +00003230
Douglas Gregor43959a92009-08-20 07:17:43 +00003231template<typename Derived>
3232Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003233TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003234 // Transform the initialization statement
3235 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3236 if (Init.isInvalid())
3237 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003238
Douglas Gregor43959a92009-08-20 07:17:43 +00003239 // Transform the condition
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003240 OwningExprResult Cond(SemaRef);
3241 VarDecl *ConditionVar = 0;
3242 if (S->getConditionVariable()) {
3243 ConditionVar
3244 = cast_or_null<VarDecl>(
3245 getDerived().TransformDefinition(S->getConditionVariable()));
3246 if (!ConditionVar)
3247 return SemaRef.StmtError();
3248 } else {
3249 Cond = getDerived().TransformExpr(S->getCond());
3250
3251 if (Cond.isInvalid())
3252 return SemaRef.StmtError();
3253 }
Mike Stump1eb44332009-09-09 15:08:12 +00003254
Douglas Gregor43959a92009-08-20 07:17:43 +00003255 // Transform the increment
3256 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3257 if (Inc.isInvalid())
3258 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003259
Douglas Gregor43959a92009-08-20 07:17:43 +00003260 // Transform the body
3261 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3262 if (Body.isInvalid())
3263 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003264
Douglas Gregor43959a92009-08-20 07:17:43 +00003265 if (!getDerived().AlwaysRebuild() &&
3266 Init.get() == S->getInit() &&
3267 Cond.get() == S->getCond() &&
3268 Inc.get() == S->getInc() &&
3269 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003270 return SemaRef.Owned(S->Retain());
3271
Douglas Gregor43959a92009-08-20 07:17:43 +00003272 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003273 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003274 ConditionVar,
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003275 getSema().MakeFullExpr(Inc),
Douglas Gregor43959a92009-08-20 07:17:43 +00003276 S->getRParenLoc(), move(Body));
3277}
3278
3279template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003280Sema::OwningStmtResult
3281TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003282 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003283 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003284 S->getLabel());
3285}
3286
3287template<typename Derived>
3288Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003289TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003290 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3291 if (Target.isInvalid())
3292 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003293
Douglas Gregor43959a92009-08-20 07:17:43 +00003294 if (!getDerived().AlwaysRebuild() &&
3295 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003296 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003297
3298 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3299 move(Target));
3300}
3301
3302template<typename Derived>
3303Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003304TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3305 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003306}
Mike Stump1eb44332009-09-09 15:08:12 +00003307
Douglas Gregor43959a92009-08-20 07:17:43 +00003308template<typename Derived>
3309Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003310TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3311 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003312}
Mike Stump1eb44332009-09-09 15:08:12 +00003313
Douglas Gregor43959a92009-08-20 07:17:43 +00003314template<typename Derived>
3315Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003316TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003317 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3318 if (Result.isInvalid())
3319 return SemaRef.StmtError();
3320
Mike Stump1eb44332009-09-09 15:08:12 +00003321 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003322 // to tell whether the return type of the function has changed.
3323 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3324}
Mike Stump1eb44332009-09-09 15:08:12 +00003325
Douglas Gregor43959a92009-08-20 07:17:43 +00003326template<typename Derived>
3327Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003328TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003329 bool DeclChanged = false;
3330 llvm::SmallVector<Decl *, 4> Decls;
3331 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3332 D != DEnd; ++D) {
3333 Decl *Transformed = getDerived().TransformDefinition(*D);
3334 if (!Transformed)
3335 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003336
Douglas Gregor43959a92009-08-20 07:17:43 +00003337 if (Transformed != *D)
3338 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003339
Douglas Gregor43959a92009-08-20 07:17:43 +00003340 Decls.push_back(Transformed);
3341 }
Mike Stump1eb44332009-09-09 15:08:12 +00003342
Douglas Gregor43959a92009-08-20 07:17:43 +00003343 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003344 return SemaRef.Owned(S->Retain());
3345
3346 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003347 S->getStartLoc(), S->getEndLoc());
3348}
Mike Stump1eb44332009-09-09 15:08:12 +00003349
Douglas Gregor43959a92009-08-20 07:17:43 +00003350template<typename Derived>
3351Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003352TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003353 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003354 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003355}
3356
3357template<typename Derived>
3358Sema::OwningStmtResult
3359TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlsson703e3942010-01-24 05:50:09 +00003360
3361 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3362 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003363 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003364
Anders Carlsson703e3942010-01-24 05:50:09 +00003365 OwningExprResult AsmString(SemaRef);
3366 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3367
3368 bool ExprsChanged = false;
3369
3370 // Go through the outputs.
3371 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003372 Names.push_back(S->getOutputIdentifier(I));
Anders Carlssona5a79f72010-01-30 20:05:21 +00003373
Anders Carlsson703e3942010-01-24 05:50:09 +00003374 // No need to transform the constraint literal.
3375 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3376
3377 // Transform the output expr.
3378 Expr *OutputExpr = S->getOutputExpr(I);
3379 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3380 if (Result.isInvalid())
3381 return SemaRef.StmtError();
3382
3383 ExprsChanged |= Result.get() != OutputExpr;
3384
3385 Exprs.push_back(Result.takeAs<Expr>());
3386 }
3387
3388 // Go through the inputs.
3389 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003390 Names.push_back(S->getInputIdentifier(I));
Anders Carlssona5a79f72010-01-30 20:05:21 +00003391
Anders Carlsson703e3942010-01-24 05:50:09 +00003392 // No need to transform the constraint literal.
3393 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3394
3395 // Transform the input expr.
3396 Expr *InputExpr = S->getInputExpr(I);
3397 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3398 if (Result.isInvalid())
3399 return SemaRef.StmtError();
3400
3401 ExprsChanged |= Result.get() != InputExpr;
3402
3403 Exprs.push_back(Result.takeAs<Expr>());
3404 }
3405
3406 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3407 return SemaRef.Owned(S->Retain());
3408
3409 // Go through the clobbers.
3410 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3411 Clobbers.push_back(S->getClobber(I)->Retain());
3412
3413 // No need to transform the asm string literal.
3414 AsmString = SemaRef.Owned(S->getAsmString());
3415
3416 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3417 S->isSimple(),
3418 S->isVolatile(),
3419 S->getNumOutputs(),
3420 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003421 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003422 move_arg(Constraints),
3423 move_arg(Exprs),
3424 move(AsmString),
3425 move_arg(Clobbers),
3426 S->getRParenLoc(),
3427 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003428}
3429
3430
3431template<typename Derived>
3432Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003433TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003434 // FIXME: Implement this
3435 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003436 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003437}
Mike Stump1eb44332009-09-09 15:08:12 +00003438
Douglas Gregor43959a92009-08-20 07:17:43 +00003439template<typename Derived>
3440Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003441TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003442 // FIXME: Implement this
3443 assert(false && "Cannot transform an Objective-C @catch statement");
3444 return SemaRef.Owned(S->Retain());
3445}
Mike Stump1eb44332009-09-09 15:08:12 +00003446
Douglas Gregor43959a92009-08-20 07:17:43 +00003447template<typename Derived>
3448Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003449TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003450 // FIXME: Implement this
3451 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003452 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003453}
Mike Stump1eb44332009-09-09 15:08:12 +00003454
Douglas Gregor43959a92009-08-20 07:17:43 +00003455template<typename Derived>
3456Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003457TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003458 // FIXME: Implement this
3459 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003460 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003461}
Mike Stump1eb44332009-09-09 15:08:12 +00003462
Douglas Gregor43959a92009-08-20 07:17:43 +00003463template<typename Derived>
3464Sema::OwningStmtResult
3465TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003466 ObjCAtSynchronizedStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003467 // FIXME: Implement this
3468 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003469 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003470}
3471
3472template<typename Derived>
3473Sema::OwningStmtResult
3474TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003475 ObjCForCollectionStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003476 // FIXME: Implement this
3477 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003478 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003479}
3480
3481
3482template<typename Derived>
3483Sema::OwningStmtResult
3484TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3485 // Transform the exception declaration, if any.
3486 VarDecl *Var = 0;
3487 if (S->getExceptionDecl()) {
3488 VarDecl *ExceptionDecl = S->getExceptionDecl();
3489 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3490 ExceptionDecl->getDeclName());
3491
3492 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3493 if (T.isNull())
3494 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003495
Douglas Gregor43959a92009-08-20 07:17:43 +00003496 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3497 T,
John McCalla93c9342009-12-07 02:54:59 +00003498 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003499 ExceptionDecl->getIdentifier(),
3500 ExceptionDecl->getLocation(),
3501 /*FIXME: Inaccurate*/
3502 SourceRange(ExceptionDecl->getLocation()));
3503 if (!Var || Var->isInvalidDecl()) {
3504 if (Var)
3505 Var->Destroy(SemaRef.Context);
3506 return SemaRef.StmtError();
3507 }
3508 }
Mike Stump1eb44332009-09-09 15:08:12 +00003509
Douglas Gregor43959a92009-08-20 07:17:43 +00003510 // Transform the actual exception handler.
3511 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3512 if (Handler.isInvalid()) {
3513 if (Var)
3514 Var->Destroy(SemaRef.Context);
3515 return SemaRef.StmtError();
3516 }
Mike Stump1eb44332009-09-09 15:08:12 +00003517
Douglas Gregor43959a92009-08-20 07:17:43 +00003518 if (!getDerived().AlwaysRebuild() &&
3519 !Var &&
3520 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00003521 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003522
3523 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3524 Var,
3525 move(Handler));
3526}
Mike Stump1eb44332009-09-09 15:08:12 +00003527
Douglas Gregor43959a92009-08-20 07:17:43 +00003528template<typename Derived>
3529Sema::OwningStmtResult
3530TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3531 // Transform the try block itself.
Mike Stump1eb44332009-09-09 15:08:12 +00003532 OwningStmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00003533 = getDerived().TransformCompoundStmt(S->getTryBlock());
3534 if (TryBlock.isInvalid())
3535 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003536
Douglas Gregor43959a92009-08-20 07:17:43 +00003537 // Transform the handlers.
3538 bool HandlerChanged = false;
3539 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3540 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump1eb44332009-09-09 15:08:12 +00003541 OwningStmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00003542 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3543 if (Handler.isInvalid())
3544 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003545
Douglas Gregor43959a92009-08-20 07:17:43 +00003546 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3547 Handlers.push_back(Handler.takeAs<Stmt>());
3548 }
Mike Stump1eb44332009-09-09 15:08:12 +00003549
Douglas Gregor43959a92009-08-20 07:17:43 +00003550 if (!getDerived().AlwaysRebuild() &&
3551 TryBlock.get() == S->getTryBlock() &&
3552 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003553 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003554
3555 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump1eb44332009-09-09 15:08:12 +00003556 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00003557}
Mike Stump1eb44332009-09-09 15:08:12 +00003558
Douglas Gregor43959a92009-08-20 07:17:43 +00003559//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00003560// Expression transformation
3561//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00003562template<typename Derived>
3563Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003564TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003565 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003566}
Mike Stump1eb44332009-09-09 15:08:12 +00003567
3568template<typename Derived>
3569Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003570TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00003571 NestedNameSpecifier *Qualifier = 0;
3572 if (E->getQualifier()) {
3573 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3574 E->getQualifierRange());
3575 if (!Qualifier)
3576 return SemaRef.ExprError();
3577 }
John McCalldbd872f2009-12-08 09:08:17 +00003578
3579 ValueDecl *ND
3580 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00003581 if (!ND)
3582 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003583
Douglas Gregora2813ce2009-10-23 18:54:35 +00003584 if (!getDerived().AlwaysRebuild() &&
3585 Qualifier == E->getQualifier() &&
3586 ND == E->getDecl() &&
John McCalldbd872f2009-12-08 09:08:17 +00003587 !E->hasExplicitTemplateArgumentList()) {
3588
3589 // Mark it referenced in the new context regardless.
3590 // FIXME: this is a bit instantiation-specific.
3591 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3592
Mike Stump1eb44332009-09-09 15:08:12 +00003593 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00003594 }
John McCalldbd872f2009-12-08 09:08:17 +00003595
3596 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3597 if (E->hasExplicitTemplateArgumentList()) {
3598 TemplateArgs = &TransArgs;
3599 TransArgs.setLAngleLoc(E->getLAngleLoc());
3600 TransArgs.setRAngleLoc(E->getRAngleLoc());
3601 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3602 TemplateArgumentLoc Loc;
3603 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3604 return SemaRef.ExprError();
3605 TransArgs.addArgument(Loc);
3606 }
3607 }
3608
Douglas Gregora2813ce2009-10-23 18:54:35 +00003609 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCalldbd872f2009-12-08 09:08:17 +00003610 ND, E->getLocation(), TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003611}
Mike Stump1eb44332009-09-09 15:08:12 +00003612
Douglas Gregorb98b1992009-08-11 05:31:07 +00003613template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003614Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003615TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003616 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003617}
Mike Stump1eb44332009-09-09 15:08:12 +00003618
Douglas Gregorb98b1992009-08-11 05:31:07 +00003619template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003620Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003621TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003622 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003623}
Mike Stump1eb44332009-09-09 15:08:12 +00003624
Douglas Gregorb98b1992009-08-11 05:31:07 +00003625template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003626Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003627TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003628 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003629}
Mike Stump1eb44332009-09-09 15:08:12 +00003630
Douglas Gregorb98b1992009-08-11 05:31:07 +00003631template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003632Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003633TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003634 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003635}
Mike Stump1eb44332009-09-09 15:08:12 +00003636
Douglas Gregorb98b1992009-08-11 05:31:07 +00003637template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003638Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003639TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003640 return SemaRef.Owned(E->Retain());
3641}
3642
3643template<typename Derived>
3644Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003645TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003646 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3647 if (SubExpr.isInvalid())
3648 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003649
Douglas Gregorb98b1992009-08-11 05:31:07 +00003650 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003651 return SemaRef.Owned(E->Retain());
3652
3653 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003654 E->getRParen());
3655}
3656
Mike Stump1eb44332009-09-09 15:08:12 +00003657template<typename Derived>
3658Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003659TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3660 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003661 if (SubExpr.isInvalid())
3662 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003663
Douglas Gregorb98b1992009-08-11 05:31:07 +00003664 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003665 return SemaRef.Owned(E->Retain());
3666
Douglas Gregorb98b1992009-08-11 05:31:07 +00003667 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3668 E->getOpcode(),
3669 move(SubExpr));
3670}
Mike Stump1eb44332009-09-09 15:08:12 +00003671
Douglas Gregorb98b1992009-08-11 05:31:07 +00003672template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003673Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003674TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003675 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00003676 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00003677
John McCalla93c9342009-12-07 02:54:59 +00003678 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00003679 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003680 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003681
John McCall5ab75172009-11-04 07:28:41 +00003682 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003683 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003684
John McCall5ab75172009-11-04 07:28:41 +00003685 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00003686 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003687 E->getSourceRange());
3688 }
Mike Stump1eb44332009-09-09 15:08:12 +00003689
Douglas Gregorb98b1992009-08-11 05:31:07 +00003690 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00003691 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003692 // C++0x [expr.sizeof]p1:
3693 // The operand is either an expression, which is an unevaluated operand
3694 // [...]
3695 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003696
Douglas Gregorb98b1992009-08-11 05:31:07 +00003697 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3698 if (SubExpr.isInvalid())
3699 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003700
Douglas Gregorb98b1992009-08-11 05:31:07 +00003701 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3702 return SemaRef.Owned(E->Retain());
3703 }
Mike Stump1eb44332009-09-09 15:08:12 +00003704
Douglas Gregorb98b1992009-08-11 05:31:07 +00003705 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3706 E->isSizeOf(),
3707 E->getSourceRange());
3708}
Mike Stump1eb44332009-09-09 15:08:12 +00003709
Douglas Gregorb98b1992009-08-11 05:31:07 +00003710template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003711Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003712TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003713 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3714 if (LHS.isInvalid())
3715 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003716
Douglas Gregorb98b1992009-08-11 05:31:07 +00003717 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3718 if (RHS.isInvalid())
3719 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003720
3721
Douglas Gregorb98b1992009-08-11 05:31:07 +00003722 if (!getDerived().AlwaysRebuild() &&
3723 LHS.get() == E->getLHS() &&
3724 RHS.get() == E->getRHS())
3725 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003726
Douglas Gregorb98b1992009-08-11 05:31:07 +00003727 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3728 /*FIXME:*/E->getLHS()->getLocStart(),
3729 move(RHS),
3730 E->getRBracketLoc());
3731}
Mike Stump1eb44332009-09-09 15:08:12 +00003732
3733template<typename Derived>
3734Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003735TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003736 // Transform the callee.
3737 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3738 if (Callee.isInvalid())
3739 return SemaRef.ExprError();
3740
3741 // Transform arguments.
3742 bool ArgChanged = false;
3743 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3744 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3745 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3746 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3747 if (Arg.isInvalid())
3748 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003749
Douglas Gregorb98b1992009-08-11 05:31:07 +00003750 // FIXME: Wrong source location information for the ','.
3751 FakeCommaLocs.push_back(
3752 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00003753
3754 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003755 Args.push_back(Arg.takeAs<Expr>());
3756 }
Mike Stump1eb44332009-09-09 15:08:12 +00003757
Douglas Gregorb98b1992009-08-11 05:31:07 +00003758 if (!getDerived().AlwaysRebuild() &&
3759 Callee.get() == E->getCallee() &&
3760 !ArgChanged)
3761 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003762
Douglas Gregorb98b1992009-08-11 05:31:07 +00003763 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00003764 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003765 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3766 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3767 move_arg(Args),
3768 FakeCommaLocs.data(),
3769 E->getRParenLoc());
3770}
Mike Stump1eb44332009-09-09 15:08:12 +00003771
3772template<typename Derived>
3773Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003774TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003775 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3776 if (Base.isInvalid())
3777 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003778
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003779 NestedNameSpecifier *Qualifier = 0;
3780 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00003781 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003782 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3783 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00003784 if (Qualifier == 0)
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003785 return SemaRef.ExprError();
3786 }
Mike Stump1eb44332009-09-09 15:08:12 +00003787
Eli Friedmanf595cc42009-12-04 06:40:45 +00003788 ValueDecl *Member
3789 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00003790 if (!Member)
3791 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003792
Douglas Gregorb98b1992009-08-11 05:31:07 +00003793 if (!getDerived().AlwaysRebuild() &&
3794 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003795 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003796 Member == E->getMemberDecl() &&
Anders Carlsson1f240322009-12-22 05:24:09 +00003797 !E->hasExplicitTemplateArgumentList()) {
3798
3799 // Mark it referenced in the new context regardless.
3800 // FIXME: this is a bit instantiation-specific.
3801 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00003802 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00003803 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00003804
John McCalld5532b62009-11-23 01:53:49 +00003805 TemplateArgumentListInfo TransArgs;
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003806 if (E->hasExplicitTemplateArgumentList()) {
John McCalld5532b62009-11-23 01:53:49 +00003807 TransArgs.setLAngleLoc(E->getLAngleLoc());
3808 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003809 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00003810 TemplateArgumentLoc Loc;
3811 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003812 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00003813 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003814 }
3815 }
3816
Douglas Gregorb98b1992009-08-11 05:31:07 +00003817 // FIXME: Bogus source location for the operator
3818 SourceLocation FakeOperatorLoc
3819 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3820
John McCallc2233c52010-01-15 08:34:02 +00003821 // FIXME: to do this check properly, we will need to preserve the
3822 // first-qualifier-in-scope here, just in case we had a dependent
3823 // base (and therefore couldn't do the check) and a
3824 // nested-name-qualifier (and therefore could do the lookup).
3825 NamedDecl *FirstQualifierInScope = 0;
3826
Douglas Gregorb98b1992009-08-11 05:31:07 +00003827 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3828 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003829 Qualifier,
3830 E->getQualifierRange(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003831 E->getMemberLoc(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003832 Member,
John McCalld5532b62009-11-23 01:53:49 +00003833 (E->hasExplicitTemplateArgumentList()
3834 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00003835 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003836}
Mike Stump1eb44332009-09-09 15:08:12 +00003837
Douglas Gregorb98b1992009-08-11 05:31:07 +00003838template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00003839Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003840TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003841 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3842 if (LHS.isInvalid())
3843 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003844
Douglas Gregorb98b1992009-08-11 05:31:07 +00003845 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3846 if (RHS.isInvalid())
3847 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003848
Douglas Gregorb98b1992009-08-11 05:31:07 +00003849 if (!getDerived().AlwaysRebuild() &&
3850 LHS.get() == E->getLHS() &&
3851 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00003852 return SemaRef.Owned(E->Retain());
3853
Douglas Gregorb98b1992009-08-11 05:31:07 +00003854 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3855 move(LHS), move(RHS));
3856}
3857
Mike Stump1eb44332009-09-09 15:08:12 +00003858template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00003859Sema::OwningExprResult
3860TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00003861 CompoundAssignOperator *E) {
3862 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003863}
Mike Stump1eb44332009-09-09 15:08:12 +00003864
Douglas Gregorb98b1992009-08-11 05:31:07 +00003865template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003866Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003867TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003868 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3869 if (Cond.isInvalid())
3870 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003871
Douglas Gregorb98b1992009-08-11 05:31:07 +00003872 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3873 if (LHS.isInvalid())
3874 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003875
Douglas Gregorb98b1992009-08-11 05:31:07 +00003876 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3877 if (RHS.isInvalid())
3878 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003879
Douglas Gregorb98b1992009-08-11 05:31:07 +00003880 if (!getDerived().AlwaysRebuild() &&
3881 Cond.get() == E->getCond() &&
3882 LHS.get() == E->getLHS() &&
3883 RHS.get() == E->getRHS())
3884 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003885
3886 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00003887 E->getQuestionLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00003888 move(LHS),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00003889 E->getColonLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003890 move(RHS));
3891}
Mike Stump1eb44332009-09-09 15:08:12 +00003892
3893template<typename Derived>
3894Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003895TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00003896 // Implicit casts are eliminated during transformation, since they
3897 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00003898 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003899}
Mike Stump1eb44332009-09-09 15:08:12 +00003900
Douglas Gregorb98b1992009-08-11 05:31:07 +00003901template<typename Derived>
3902Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003903TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00003904 TypeSourceInfo *OldT;
3905 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00003906 {
3907 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00003908 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003909 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3910 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00003911
John McCall9d125032010-01-15 18:39:57 +00003912 OldT = E->getTypeInfoAsWritten();
3913 NewT = getDerived().TransformType(OldT);
3914 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003915 return SemaRef.ExprError();
3916 }
Mike Stump1eb44332009-09-09 15:08:12 +00003917
Douglas Gregora88cfbf2009-12-12 18:16:41 +00003918 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00003919 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003920 if (SubExpr.isInvalid())
3921 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003922
Douglas Gregorb98b1992009-08-11 05:31:07 +00003923 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00003924 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00003925 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003926 return SemaRef.Owned(E->Retain());
3927
John McCall9d125032010-01-15 18:39:57 +00003928 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
3929 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00003930 E->getRParenLoc(),
3931 move(SubExpr));
3932}
Mike Stump1eb44332009-09-09 15:08:12 +00003933
Douglas Gregorb98b1992009-08-11 05:31:07 +00003934template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003935Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003936TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00003937 TypeSourceInfo *OldT = E->getTypeSourceInfo();
3938 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
3939 if (!NewT)
3940 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003941
Douglas Gregorb98b1992009-08-11 05:31:07 +00003942 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3943 if (Init.isInvalid())
3944 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003945
Douglas Gregorb98b1992009-08-11 05:31:07 +00003946 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00003947 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00003948 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00003949 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003950
John McCall1d7d8d62010-01-19 22:33:45 +00003951 // Note: the expression type doesn't necessarily match the
3952 // type-as-written, but that's okay, because it should always be
3953 // derivable from the initializer.
3954
John McCall42f56b52010-01-18 19:35:47 +00003955 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00003956 /*FIXME:*/E->getInitializer()->getLocEnd(),
3957 move(Init));
3958}
Mike Stump1eb44332009-09-09 15:08:12 +00003959
Douglas Gregorb98b1992009-08-11 05:31:07 +00003960template<typename Derived>
3961Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003962TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003963 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3964 if (Base.isInvalid())
3965 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003966
Douglas Gregorb98b1992009-08-11 05:31:07 +00003967 if (!getDerived().AlwaysRebuild() &&
3968 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00003969 return SemaRef.Owned(E->Retain());
3970
Douglas Gregorb98b1992009-08-11 05:31:07 +00003971 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00003972 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003973 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3974 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3975 E->getAccessorLoc(),
3976 E->getAccessor());
3977}
Mike Stump1eb44332009-09-09 15:08:12 +00003978
Douglas Gregorb98b1992009-08-11 05:31:07 +00003979template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003980Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003981TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003982 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00003983
Douglas Gregorb98b1992009-08-11 05:31:07 +00003984 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3985 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3986 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3987 if (Init.isInvalid())
3988 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003989
Douglas Gregorb98b1992009-08-11 05:31:07 +00003990 InitChanged = InitChanged || Init.get() != E->getInit(I);
3991 Inits.push_back(Init.takeAs<Expr>());
3992 }
Mike Stump1eb44332009-09-09 15:08:12 +00003993
Douglas Gregorb98b1992009-08-11 05:31:07 +00003994 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003995 return SemaRef.Owned(E->Retain());
3996
Douglas Gregorb98b1992009-08-11 05:31:07 +00003997 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00003998 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003999}
Mike Stump1eb44332009-09-09 15:08:12 +00004000
Douglas Gregorb98b1992009-08-11 05:31:07 +00004001template<typename Derived>
4002Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004003TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004004 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004005
Douglas Gregor43959a92009-08-20 07:17:43 +00004006 // transform the initializer value
Douglas Gregorb98b1992009-08-11 05:31:07 +00004007 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4008 if (Init.isInvalid())
4009 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004010
Douglas Gregor43959a92009-08-20 07:17:43 +00004011 // transform the designators.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004012 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4013 bool ExprChanged = false;
4014 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4015 DEnd = E->designators_end();
4016 D != DEnd; ++D) {
4017 if (D->isFieldDesignator()) {
4018 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4019 D->getDotLoc(),
4020 D->getFieldLoc()));
4021 continue;
4022 }
Mike Stump1eb44332009-09-09 15:08:12 +00004023
Douglas Gregorb98b1992009-08-11 05:31:07 +00004024 if (D->isArrayDesignator()) {
4025 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4026 if (Index.isInvalid())
4027 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004028
4029 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004030 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004031
Douglas Gregorb98b1992009-08-11 05:31:07 +00004032 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4033 ArrayExprs.push_back(Index.release());
4034 continue;
4035 }
Mike Stump1eb44332009-09-09 15:08:12 +00004036
Douglas Gregorb98b1992009-08-11 05:31:07 +00004037 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump1eb44332009-09-09 15:08:12 +00004038 OwningExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004039 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4040 if (Start.isInvalid())
4041 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004042
Douglas Gregorb98b1992009-08-11 05:31:07 +00004043 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4044 if (End.isInvalid())
4045 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004046
4047 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004048 End.get(),
4049 D->getLBracketLoc(),
4050 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004051
Douglas Gregorb98b1992009-08-11 05:31:07 +00004052 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4053 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004054
Douglas Gregorb98b1992009-08-11 05:31:07 +00004055 ArrayExprs.push_back(Start.release());
4056 ArrayExprs.push_back(End.release());
4057 }
Mike Stump1eb44332009-09-09 15:08:12 +00004058
Douglas Gregorb98b1992009-08-11 05:31:07 +00004059 if (!getDerived().AlwaysRebuild() &&
4060 Init.get() == E->getInit() &&
4061 !ExprChanged)
4062 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004063
Douglas Gregorb98b1992009-08-11 05:31:07 +00004064 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4065 E->getEqualOrColonLoc(),
4066 E->usesGNUSyntax(), move(Init));
4067}
Mike Stump1eb44332009-09-09 15:08:12 +00004068
Douglas Gregorb98b1992009-08-11 05:31:07 +00004069template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004070Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004071TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004072 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004073 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4074
4075 // FIXME: Will we ever have proper type location here? Will we actually
4076 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004077 QualType T = getDerived().TransformType(E->getType());
4078 if (T.isNull())
4079 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004080
Douglas Gregorb98b1992009-08-11 05:31:07 +00004081 if (!getDerived().AlwaysRebuild() &&
4082 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004083 return SemaRef.Owned(E->Retain());
4084
Douglas Gregorb98b1992009-08-11 05:31:07 +00004085 return getDerived().RebuildImplicitValueInitExpr(T);
4086}
Mike Stump1eb44332009-09-09 15:08:12 +00004087
Douglas Gregorb98b1992009-08-11 05:31:07 +00004088template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004089Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004090TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004091 // FIXME: Do we want the type as written?
4092 QualType T;
Mike Stump1eb44332009-09-09 15:08:12 +00004093
Douglas Gregorb98b1992009-08-11 05:31:07 +00004094 {
4095 // FIXME: Source location isn't quite accurate.
4096 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4097 T = getDerived().TransformType(E->getType());
4098 if (T.isNull())
4099 return SemaRef.ExprError();
4100 }
Mike Stump1eb44332009-09-09 15:08:12 +00004101
Douglas Gregorb98b1992009-08-11 05:31:07 +00004102 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4103 if (SubExpr.isInvalid())
4104 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004105
Douglas Gregorb98b1992009-08-11 05:31:07 +00004106 if (!getDerived().AlwaysRebuild() &&
4107 T == E->getType() &&
4108 SubExpr.get() == E->getSubExpr())
4109 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004110
Douglas Gregorb98b1992009-08-11 05:31:07 +00004111 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4112 T, E->getRParenLoc());
4113}
4114
4115template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004116Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004117TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004118 bool ArgumentChanged = false;
4119 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4120 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4121 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4122 if (Init.isInvalid())
4123 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004124
Douglas Gregorb98b1992009-08-11 05:31:07 +00004125 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4126 Inits.push_back(Init.takeAs<Expr>());
4127 }
Mike Stump1eb44332009-09-09 15:08:12 +00004128
Douglas Gregorb98b1992009-08-11 05:31:07 +00004129 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4130 move_arg(Inits),
4131 E->getRParenLoc());
4132}
Mike Stump1eb44332009-09-09 15:08:12 +00004133
Douglas Gregorb98b1992009-08-11 05:31:07 +00004134/// \brief Transform an address-of-label expression.
4135///
4136/// By default, the transformation of an address-of-label expression always
4137/// rebuilds the expression, so that the label identifier can be resolved to
4138/// the corresponding label statement by semantic analysis.
4139template<typename Derived>
4140Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004141TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004142 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4143 E->getLabel());
4144}
Mike Stump1eb44332009-09-09 15:08:12 +00004145
4146template<typename Derived>
Douglas Gregorc86a6e92009-11-04 07:01:15 +00004147Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004148TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004149 OwningStmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004150 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4151 if (SubStmt.isInvalid())
4152 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004153
Douglas Gregorb98b1992009-08-11 05:31:07 +00004154 if (!getDerived().AlwaysRebuild() &&
4155 SubStmt.get() == E->getSubStmt())
4156 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004157
4158 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004159 move(SubStmt),
4160 E->getRParenLoc());
4161}
Mike Stump1eb44332009-09-09 15:08:12 +00004162
Douglas Gregorb98b1992009-08-11 05:31:07 +00004163template<typename Derived>
4164Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004165TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004166 QualType T1, T2;
4167 {
4168 // FIXME: Source location isn't quite accurate.
4169 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004170
Douglas Gregorb98b1992009-08-11 05:31:07 +00004171 T1 = getDerived().TransformType(E->getArgType1());
4172 if (T1.isNull())
4173 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004174
Douglas Gregorb98b1992009-08-11 05:31:07 +00004175 T2 = getDerived().TransformType(E->getArgType2());
4176 if (T2.isNull())
4177 return SemaRef.ExprError();
4178 }
4179
4180 if (!getDerived().AlwaysRebuild() &&
4181 T1 == E->getArgType1() &&
4182 T2 == E->getArgType2())
Mike Stump1eb44332009-09-09 15:08:12 +00004183 return SemaRef.Owned(E->Retain());
4184
Douglas Gregorb98b1992009-08-11 05:31:07 +00004185 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4186 T1, T2, E->getRParenLoc());
4187}
Mike Stump1eb44332009-09-09 15:08:12 +00004188
Douglas Gregorb98b1992009-08-11 05:31:07 +00004189template<typename Derived>
4190Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004191TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004192 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4193 if (Cond.isInvalid())
4194 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004195
Douglas Gregorb98b1992009-08-11 05:31:07 +00004196 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4197 if (LHS.isInvalid())
4198 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004199
Douglas Gregorb98b1992009-08-11 05:31:07 +00004200 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4201 if (RHS.isInvalid())
4202 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004203
Douglas Gregorb98b1992009-08-11 05:31:07 +00004204 if (!getDerived().AlwaysRebuild() &&
4205 Cond.get() == E->getCond() &&
4206 LHS.get() == E->getLHS() &&
4207 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004208 return SemaRef.Owned(E->Retain());
4209
Douglas Gregorb98b1992009-08-11 05:31:07 +00004210 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4211 move(Cond), move(LHS), move(RHS),
4212 E->getRParenLoc());
4213}
Mike Stump1eb44332009-09-09 15:08:12 +00004214
Douglas Gregorb98b1992009-08-11 05:31:07 +00004215template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004216Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004217TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004218 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004219}
4220
4221template<typename Derived>
4222Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004223TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004224 switch (E->getOperator()) {
4225 case OO_New:
4226 case OO_Delete:
4227 case OO_Array_New:
4228 case OO_Array_Delete:
4229 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4230 return SemaRef.ExprError();
4231
4232 case OO_Call: {
4233 // This is a call to an object's operator().
4234 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4235
4236 // Transform the object itself.
4237 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4238 if (Object.isInvalid())
4239 return SemaRef.ExprError();
4240
4241 // FIXME: Poor location information
4242 SourceLocation FakeLParenLoc
4243 = SemaRef.PP.getLocForEndOfToken(
4244 static_cast<Expr *>(Object.get())->getLocEnd());
4245
4246 // Transform the call arguments.
4247 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4248 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4249 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004250 if (getDerived().DropCallArgument(E->getArg(I)))
4251 break;
4252
Douglas Gregor668d6d92009-12-13 20:44:55 +00004253 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4254 if (Arg.isInvalid())
4255 return SemaRef.ExprError();
4256
4257 // FIXME: Poor source location information.
4258 SourceLocation FakeCommaLoc
4259 = SemaRef.PP.getLocForEndOfToken(
4260 static_cast<Expr *>(Arg.get())->getLocEnd());
4261 FakeCommaLocs.push_back(FakeCommaLoc);
4262 Args.push_back(Arg.release());
4263 }
4264
4265 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4266 move_arg(Args),
4267 FakeCommaLocs.data(),
4268 E->getLocEnd());
4269 }
4270
4271#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4272 case OO_##Name:
4273#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4274#include "clang/Basic/OperatorKinds.def"
4275 case OO_Subscript:
4276 // Handled below.
4277 break;
4278
4279 case OO_Conditional:
4280 llvm_unreachable("conditional operator is not actually overloadable");
4281 return SemaRef.ExprError();
4282
4283 case OO_None:
4284 case NUM_OVERLOADED_OPERATORS:
4285 llvm_unreachable("not an overloaded operator?");
4286 return SemaRef.ExprError();
4287 }
4288
Douglas Gregorb98b1992009-08-11 05:31:07 +00004289 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4290 if (Callee.isInvalid())
4291 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004292
John McCall454feb92009-12-08 09:21:05 +00004293 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004294 if (First.isInvalid())
4295 return SemaRef.ExprError();
4296
4297 OwningExprResult Second(SemaRef);
4298 if (E->getNumArgs() == 2) {
4299 Second = getDerived().TransformExpr(E->getArg(1));
4300 if (Second.isInvalid())
4301 return SemaRef.ExprError();
4302 }
Mike Stump1eb44332009-09-09 15:08:12 +00004303
Douglas Gregorb98b1992009-08-11 05:31:07 +00004304 if (!getDerived().AlwaysRebuild() &&
4305 Callee.get() == E->getCallee() &&
4306 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00004307 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4308 return SemaRef.Owned(E->Retain());
4309
Douglas Gregorb98b1992009-08-11 05:31:07 +00004310 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4311 E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004312 move(Callee),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004313 move(First),
4314 move(Second));
4315}
Mike Stump1eb44332009-09-09 15:08:12 +00004316
Douglas Gregorb98b1992009-08-11 05:31:07 +00004317template<typename Derived>
4318Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004319TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4320 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004321}
Mike Stump1eb44332009-09-09 15:08:12 +00004322
Douglas Gregorb98b1992009-08-11 05:31:07 +00004323template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004324Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004325TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004326 TypeSourceInfo *OldT;
4327 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004328 {
4329 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004330 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004331 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4332 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004333
John McCall9d125032010-01-15 18:39:57 +00004334 OldT = E->getTypeInfoAsWritten();
4335 NewT = getDerived().TransformType(OldT);
4336 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004337 return SemaRef.ExprError();
4338 }
Mike Stump1eb44332009-09-09 15:08:12 +00004339
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004340 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004341 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004342 if (SubExpr.isInvalid())
4343 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004344
Douglas Gregorb98b1992009-08-11 05:31:07 +00004345 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004346 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004347 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004348 return SemaRef.Owned(E->Retain());
4349
Douglas Gregorb98b1992009-08-11 05:31:07 +00004350 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00004351 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004352 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4353 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4354 SourceLocation FakeRParenLoc
4355 = SemaRef.PP.getLocForEndOfToken(
4356 E->getSubExpr()->getSourceRange().getEnd());
4357 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004358 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004359 FakeLAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00004360 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004361 FakeRAngleLoc,
4362 FakeRAngleLoc,
4363 move(SubExpr),
4364 FakeRParenLoc);
4365}
Mike Stump1eb44332009-09-09 15:08:12 +00004366
Douglas Gregorb98b1992009-08-11 05:31:07 +00004367template<typename Derived>
4368Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004369TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4370 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004371}
Mike Stump1eb44332009-09-09 15:08:12 +00004372
4373template<typename Derived>
4374Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004375TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4376 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004377}
4378
Douglas Gregorb98b1992009-08-11 05:31:07 +00004379template<typename Derived>
4380Sema::OwningExprResult
4381TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004382 CXXReinterpretCastExpr *E) {
4383 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004384}
Mike Stump1eb44332009-09-09 15:08:12 +00004385
Douglas Gregorb98b1992009-08-11 05:31:07 +00004386template<typename Derived>
4387Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004388TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4389 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004390}
Mike Stump1eb44332009-09-09 15:08:12 +00004391
Douglas Gregorb98b1992009-08-11 05:31:07 +00004392template<typename Derived>
4393Sema::OwningExprResult
4394TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004395 CXXFunctionalCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004396 TypeSourceInfo *OldT;
4397 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004398 {
4399 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004400
John McCall9d125032010-01-15 18:39:57 +00004401 OldT = E->getTypeInfoAsWritten();
4402 NewT = getDerived().TransformType(OldT);
4403 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004404 return SemaRef.ExprError();
4405 }
Mike Stump1eb44332009-09-09 15:08:12 +00004406
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004407 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004408 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004409 if (SubExpr.isInvalid())
4410 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004411
Douglas Gregorb98b1992009-08-11 05:31:07 +00004412 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004413 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004414 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004415 return SemaRef.Owned(E->Retain());
4416
Douglas Gregorb98b1992009-08-11 05:31:07 +00004417 // FIXME: The end of the type's source range is wrong
4418 return getDerived().RebuildCXXFunctionalCastExpr(
4419 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall9d125032010-01-15 18:39:57 +00004420 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004421 /*FIXME:*/E->getSubExpr()->getLocStart(),
4422 move(SubExpr),
4423 E->getRParenLoc());
4424}
Mike Stump1eb44332009-09-09 15:08:12 +00004425
Douglas Gregorb98b1992009-08-11 05:31:07 +00004426template<typename Derived>
4427Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004428TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004429 if (E->isTypeOperand()) {
4430 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004431
Douglas Gregorb98b1992009-08-11 05:31:07 +00004432 QualType T = getDerived().TransformType(E->getTypeOperand());
4433 if (T.isNull())
4434 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004435
Douglas Gregorb98b1992009-08-11 05:31:07 +00004436 if (!getDerived().AlwaysRebuild() &&
4437 T == E->getTypeOperand())
4438 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004439
Douglas Gregorb98b1992009-08-11 05:31:07 +00004440 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4441 /*FIXME:*/E->getLocStart(),
4442 T,
4443 E->getLocEnd());
4444 }
Mike Stump1eb44332009-09-09 15:08:12 +00004445
Douglas Gregorb98b1992009-08-11 05:31:07 +00004446 // We don't know whether the expression is potentially evaluated until
4447 // after we perform semantic analysis, so the expression is potentially
4448 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00004449 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004450 Action::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004451
Douglas Gregorb98b1992009-08-11 05:31:07 +00004452 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4453 if (SubExpr.isInvalid())
4454 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004455
Douglas Gregorb98b1992009-08-11 05:31:07 +00004456 if (!getDerived().AlwaysRebuild() &&
4457 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00004458 return SemaRef.Owned(E->Retain());
4459
Douglas Gregorb98b1992009-08-11 05:31:07 +00004460 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4461 /*FIXME:*/E->getLocStart(),
4462 move(SubExpr),
4463 E->getLocEnd());
4464}
4465
4466template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004467Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004468TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004469 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004470}
Mike Stump1eb44332009-09-09 15:08:12 +00004471
Douglas Gregorb98b1992009-08-11 05:31:07 +00004472template<typename Derived>
4473Sema::OwningExprResult
4474TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00004475 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004476 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004477}
Mike Stump1eb44332009-09-09 15:08:12 +00004478
Douglas Gregorb98b1992009-08-11 05:31:07 +00004479template<typename Derived>
4480Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004481TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004482 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004483
Douglas Gregorb98b1992009-08-11 05:31:07 +00004484 QualType T = getDerived().TransformType(E->getType());
4485 if (T.isNull())
4486 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004487
Douglas Gregorb98b1992009-08-11 05:31:07 +00004488 if (!getDerived().AlwaysRebuild() &&
4489 T == E->getType())
4490 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004491
Douglas Gregor828a1972010-01-07 23:12:05 +00004492 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004493}
Mike Stump1eb44332009-09-09 15:08:12 +00004494
Douglas Gregorb98b1992009-08-11 05:31:07 +00004495template<typename Derived>
4496Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004497TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004498 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4499 if (SubExpr.isInvalid())
4500 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004501
Douglas Gregorb98b1992009-08-11 05:31:07 +00004502 if (!getDerived().AlwaysRebuild() &&
4503 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004504 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004505
4506 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4507}
Mike Stump1eb44332009-09-09 15:08:12 +00004508
Douglas Gregorb98b1992009-08-11 05:31:07 +00004509template<typename Derived>
4510Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004511TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004512 ParmVarDecl *Param
Douglas Gregorb98b1992009-08-11 05:31:07 +00004513 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4514 if (!Param)
4515 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004516
Chandler Carruth53cb6f82010-02-08 06:42:49 +00004517 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004518 Param == E->getParam())
4519 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004520
Douglas Gregor036aed12009-12-23 23:03:06 +00004521 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004522}
Mike Stump1eb44332009-09-09 15:08:12 +00004523
Douglas Gregorb98b1992009-08-11 05:31:07 +00004524template<typename Derived>
4525Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004526TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004527 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4528
4529 QualType T = getDerived().TransformType(E->getType());
4530 if (T.isNull())
4531 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004532
Douglas Gregorb98b1992009-08-11 05:31:07 +00004533 if (!getDerived().AlwaysRebuild() &&
4534 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004535 return SemaRef.Owned(E->Retain());
4536
4537 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004538 /*FIXME:*/E->getTypeBeginLoc(),
4539 T,
4540 E->getRParenLoc());
4541}
Mike Stump1eb44332009-09-09 15:08:12 +00004542
Douglas Gregorb98b1992009-08-11 05:31:07 +00004543template<typename Derived>
4544Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004545TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004546 // Transform the type that we're allocating
4547 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4548 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4549 if (AllocType.isNull())
4550 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004551
Douglas Gregorb98b1992009-08-11 05:31:07 +00004552 // Transform the size of the array we're allocating (if any).
4553 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4554 if (ArraySize.isInvalid())
4555 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004556
Douglas Gregorb98b1992009-08-11 05:31:07 +00004557 // Transform the placement arguments (if any).
4558 bool ArgumentChanged = false;
4559 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4560 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4561 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4562 if (Arg.isInvalid())
4563 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004564
Douglas Gregorb98b1992009-08-11 05:31:07 +00004565 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4566 PlacementArgs.push_back(Arg.take());
4567 }
Mike Stump1eb44332009-09-09 15:08:12 +00004568
Douglas Gregor43959a92009-08-20 07:17:43 +00004569 // transform the constructor arguments (if any).
Douglas Gregorb98b1992009-08-11 05:31:07 +00004570 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4571 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4572 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4573 if (Arg.isInvalid())
4574 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004575
Douglas Gregorb98b1992009-08-11 05:31:07 +00004576 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4577 ConstructorArgs.push_back(Arg.take());
4578 }
Mike Stump1eb44332009-09-09 15:08:12 +00004579
Douglas Gregorb98b1992009-08-11 05:31:07 +00004580 if (!getDerived().AlwaysRebuild() &&
4581 AllocType == E->getAllocatedType() &&
4582 ArraySize.get() == E->getArraySize() &&
4583 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004584 return SemaRef.Owned(E->Retain());
4585
Douglas Gregor5b5ad842009-12-22 17:13:37 +00004586 if (!ArraySize.get()) {
4587 // If no array size was specified, but the new expression was
4588 // instantiated with an array type (e.g., "new T" where T is
4589 // instantiated with "int[4]"), extract the outer bound from the
4590 // array type as our array size. We do this with constant and
4591 // dependently-sized array types.
4592 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4593 if (!ArrayT) {
4594 // Do nothing
4595 } else if (const ConstantArrayType *ConsArrayT
4596 = dyn_cast<ConstantArrayType>(ArrayT)) {
4597 ArraySize
4598 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4599 ConsArrayT->getSize(),
4600 SemaRef.Context.getSizeType(),
4601 /*FIXME:*/E->getLocStart()));
4602 AllocType = ConsArrayT->getElementType();
4603 } else if (const DependentSizedArrayType *DepArrayT
4604 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4605 if (DepArrayT->getSizeExpr()) {
4606 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4607 AllocType = DepArrayT->getElementType();
4608 }
4609 }
4610 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004611 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4612 E->isGlobalNew(),
4613 /*FIXME:*/E->getLocStart(),
4614 move_arg(PlacementArgs),
4615 /*FIXME:*/E->getLocStart(),
4616 E->isParenTypeId(),
4617 AllocType,
4618 /*FIXME:*/E->getLocStart(),
4619 /*FIXME:*/SourceRange(),
4620 move(ArraySize),
4621 /*FIXME:*/E->getLocStart(),
4622 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00004623 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004624}
Mike Stump1eb44332009-09-09 15:08:12 +00004625
Douglas Gregorb98b1992009-08-11 05:31:07 +00004626template<typename Derived>
4627Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004628TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004629 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4630 if (Operand.isInvalid())
4631 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004632
Douglas Gregorb98b1992009-08-11 05:31:07 +00004633 if (!getDerived().AlwaysRebuild() &&
Mike Stump1eb44332009-09-09 15:08:12 +00004634 Operand.get() == E->getArgument())
4635 return SemaRef.Owned(E->Retain());
4636
Douglas Gregorb98b1992009-08-11 05:31:07 +00004637 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4638 E->isGlobalDelete(),
4639 E->isArrayForm(),
4640 move(Operand));
4641}
Mike Stump1eb44332009-09-09 15:08:12 +00004642
Douglas Gregorb98b1992009-08-11 05:31:07 +00004643template<typename Derived>
4644Sema::OwningExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00004645TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00004646 CXXPseudoDestructorExpr *E) {
Douglas Gregora71d8192009-09-04 17:36:40 +00004647 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4648 if (Base.isInvalid())
4649 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004650
Douglas Gregora71d8192009-09-04 17:36:40 +00004651 NestedNameSpecifier *Qualifier
4652 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4653 E->getQualifierRange());
4654 if (E->getQualifier() && !Qualifier)
4655 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004656
Douglas Gregora71d8192009-09-04 17:36:40 +00004657 QualType DestroyedType;
4658 {
4659 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4660 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4661 if (DestroyedType.isNull())
4662 return SemaRef.ExprError();
4663 }
Mike Stump1eb44332009-09-09 15:08:12 +00004664
Douglas Gregora71d8192009-09-04 17:36:40 +00004665 if (!getDerived().AlwaysRebuild() &&
4666 Base.get() == E->getBase() &&
4667 Qualifier == E->getQualifier() &&
4668 DestroyedType == E->getDestroyedType())
4669 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004670
Douglas Gregora71d8192009-09-04 17:36:40 +00004671 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4672 E->getOperatorLoc(),
4673 E->isArrow(),
4674 E->getDestroyedTypeLoc(),
4675 DestroyedType,
4676 Qualifier,
4677 E->getQualifierRange());
4678}
Mike Stump1eb44332009-09-09 15:08:12 +00004679
Douglas Gregora71d8192009-09-04 17:36:40 +00004680template<typename Derived>
4681Sema::OwningExprResult
John McCallba135432009-11-21 08:51:07 +00004682TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00004683 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00004684 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4685
4686 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4687 Sema::LookupOrdinaryName);
4688
4689 // Transform all the decls.
4690 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4691 E = Old->decls_end(); I != E; ++I) {
4692 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall9f54ad42009-12-10 09:41:52 +00004693 if (!InstD) {
4694 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4695 // This can happen because of dependent hiding.
4696 if (isa<UsingShadowDecl>(*I))
4697 continue;
4698 else
4699 return SemaRef.ExprError();
4700 }
John McCallf7a1a742009-11-24 19:00:30 +00004701
4702 // Expand using declarations.
4703 if (isa<UsingDecl>(InstD)) {
4704 UsingDecl *UD = cast<UsingDecl>(InstD);
4705 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4706 E = UD->shadow_end(); I != E; ++I)
4707 R.addDecl(*I);
4708 continue;
4709 }
4710
4711 R.addDecl(InstD);
4712 }
4713
4714 // Resolve a kind, but don't do any further analysis. If it's
4715 // ambiguous, the callee needs to deal with it.
4716 R.resolveKind();
4717
4718 // Rebuild the nested-name qualifier, if present.
4719 CXXScopeSpec SS;
4720 NestedNameSpecifier *Qualifier = 0;
4721 if (Old->getQualifier()) {
4722 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4723 Old->getQualifierRange());
4724 if (!Qualifier)
4725 return SemaRef.ExprError();
4726
4727 SS.setScopeRep(Qualifier);
4728 SS.setRange(Old->getQualifierRange());
4729 }
4730
4731 // If we have no template arguments, it's a normal declaration name.
4732 if (!Old->hasExplicitTemplateArgs())
4733 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4734
4735 // If we have template arguments, rebuild them, then rebuild the
4736 // templateid expression.
4737 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4738 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4739 TemplateArgumentLoc Loc;
4740 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4741 return SemaRef.ExprError();
4742 TransArgs.addArgument(Loc);
4743 }
4744
4745 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4746 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004747}
Mike Stump1eb44332009-09-09 15:08:12 +00004748
Douglas Gregorb98b1992009-08-11 05:31:07 +00004749template<typename Derived>
4750Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004751TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004752 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004753
Douglas Gregorb98b1992009-08-11 05:31:07 +00004754 QualType T = getDerived().TransformType(E->getQueriedType());
4755 if (T.isNull())
4756 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004757
Douglas Gregorb98b1992009-08-11 05:31:07 +00004758 if (!getDerived().AlwaysRebuild() &&
4759 T == E->getQueriedType())
4760 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004761
Douglas Gregorb98b1992009-08-11 05:31:07 +00004762 // FIXME: Bad location information
4763 SourceLocation FakeLParenLoc
4764 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump1eb44332009-09-09 15:08:12 +00004765
4766 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004767 E->getLocStart(),
4768 /*FIXME:*/FakeLParenLoc,
4769 T,
4770 E->getLocEnd());
4771}
Mike Stump1eb44332009-09-09 15:08:12 +00004772
Douglas Gregorb98b1992009-08-11 05:31:07 +00004773template<typename Derived>
4774Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00004775TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall454feb92009-12-08 09:21:05 +00004776 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004777 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00004778 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4779 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004780 if (!NNS)
4781 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004782
4783 DeclarationName Name
Douglas Gregor81499bb2009-09-03 22:13:48 +00004784 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4785 if (!Name)
4786 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004787
John McCallf7a1a742009-11-24 19:00:30 +00004788 if (!E->hasExplicitTemplateArgs()) {
4789 if (!getDerived().AlwaysRebuild() &&
4790 NNS == E->getQualifier() &&
4791 Name == E->getDeclName())
4792 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004793
John McCallf7a1a742009-11-24 19:00:30 +00004794 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4795 E->getQualifierRange(),
4796 Name, E->getLocation(),
4797 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00004798 }
John McCalld5532b62009-11-23 01:53:49 +00004799
4800 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004801 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004802 TemplateArgumentLoc Loc;
4803 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb98b1992009-08-11 05:31:07 +00004804 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004805 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004806 }
4807
John McCallf7a1a742009-11-24 19:00:30 +00004808 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4809 E->getQualifierRange(),
4810 Name, E->getLocation(),
4811 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004812}
4813
4814template<typename Derived>
4815Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004816TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00004817 // CXXConstructExprs are always implicit, so when we have a
4818 // 1-argument construction we just transform that argument.
4819 if (E->getNumArgs() == 1 ||
4820 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
4821 return getDerived().TransformExpr(E->getArg(0));
4822
Douglas Gregorb98b1992009-08-11 05:31:07 +00004823 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4824
4825 QualType T = getDerived().TransformType(E->getType());
4826 if (T.isNull())
4827 return SemaRef.ExprError();
4828
4829 CXXConstructorDecl *Constructor
4830 = cast_or_null<CXXConstructorDecl>(
4831 getDerived().TransformDecl(E->getConstructor()));
4832 if (!Constructor)
4833 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004834
Douglas Gregorb98b1992009-08-11 05:31:07 +00004835 bool ArgumentChanged = false;
4836 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00004837 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004838 ArgEnd = E->arg_end();
4839 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004840 if (getDerived().DropCallArgument(*Arg)) {
4841 ArgumentChanged = true;
4842 break;
4843 }
4844
Douglas Gregorb98b1992009-08-11 05:31:07 +00004845 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4846 if (TransArg.isInvalid())
4847 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004848
Douglas Gregorb98b1992009-08-11 05:31:07 +00004849 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4850 Args.push_back(TransArg.takeAs<Expr>());
4851 }
4852
4853 if (!getDerived().AlwaysRebuild() &&
4854 T == E->getType() &&
4855 Constructor == E->getConstructor() &&
4856 !ArgumentChanged)
4857 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004858
Douglas Gregor4411d2e2009-12-14 16:27:04 +00004859 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
4860 Constructor, E->isElidable(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004861 move_arg(Args));
4862}
Mike Stump1eb44332009-09-09 15:08:12 +00004863
Douglas Gregorb98b1992009-08-11 05:31:07 +00004864/// \brief Transform a C++ temporary-binding expression.
4865///
Douglas Gregor51326552009-12-24 18:51:59 +00004866/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
4867/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004868template<typename Derived>
4869Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004870TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00004871 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004872}
Mike Stump1eb44332009-09-09 15:08:12 +00004873
Anders Carlssoneb60edf2010-01-29 02:39:32 +00004874/// \brief Transform a C++ reference-binding expression.
4875///
4876/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
4877/// transform the subexpression and return that.
4878template<typename Derived>
4879Sema::OwningExprResult
4880TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
4881 return getDerived().TransformExpr(E->getSubExpr());
4882}
4883
Mike Stump1eb44332009-09-09 15:08:12 +00004884/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00004885/// be destroyed after the expression is evaluated.
4886///
Douglas Gregor51326552009-12-24 18:51:59 +00004887/// Since CXXExprWithTemporaries nodes are implicitly generated, we
4888/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004889template<typename Derived>
4890Sema::OwningExprResult
4891TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00004892 CXXExprWithTemporaries *E) {
4893 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004894}
Mike Stump1eb44332009-09-09 15:08:12 +00004895
Douglas Gregorb98b1992009-08-11 05:31:07 +00004896template<typename Derived>
4897Sema::OwningExprResult
4898TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall454feb92009-12-08 09:21:05 +00004899 CXXTemporaryObjectExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004900 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4901 QualType T = getDerived().TransformType(E->getType());
4902 if (T.isNull())
4903 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004904
Douglas Gregorb98b1992009-08-11 05:31:07 +00004905 CXXConstructorDecl *Constructor
4906 = cast_or_null<CXXConstructorDecl>(
4907 getDerived().TransformDecl(E->getConstructor()));
4908 if (!Constructor)
4909 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004910
Douglas Gregorb98b1992009-08-11 05:31:07 +00004911 bool ArgumentChanged = false;
4912 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4913 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00004914 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004915 ArgEnd = E->arg_end();
4916 Arg != ArgEnd; ++Arg) {
4917 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4918 if (TransArg.isInvalid())
4919 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004920
Douglas Gregorb98b1992009-08-11 05:31:07 +00004921 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4922 Args.push_back((Expr *)TransArg.release());
4923 }
Mike Stump1eb44332009-09-09 15:08:12 +00004924
Douglas Gregorb98b1992009-08-11 05:31:07 +00004925 if (!getDerived().AlwaysRebuild() &&
4926 T == E->getType() &&
4927 Constructor == E->getConstructor() &&
4928 !ArgumentChanged)
4929 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004930
Douglas Gregorb98b1992009-08-11 05:31:07 +00004931 // FIXME: Bogus location information
4932 SourceLocation CommaLoc;
4933 if (Args.size() > 1) {
4934 Expr *First = (Expr *)Args[0];
Mike Stump1eb44332009-09-09 15:08:12 +00004935 CommaLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004936 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4937 }
4938 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4939 T,
4940 /*FIXME:*/E->getTypeBeginLoc(),
4941 move_arg(Args),
4942 &CommaLoc,
4943 E->getLocEnd());
4944}
Mike Stump1eb44332009-09-09 15:08:12 +00004945
Douglas Gregorb98b1992009-08-11 05:31:07 +00004946template<typename Derived>
4947Sema::OwningExprResult
4948TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00004949 CXXUnresolvedConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004950 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4951 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4952 if (T.isNull())
4953 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004954
Douglas Gregorb98b1992009-08-11 05:31:07 +00004955 bool ArgumentChanged = false;
4956 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4957 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4958 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4959 ArgEnd = E->arg_end();
4960 Arg != ArgEnd; ++Arg) {
4961 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4962 if (TransArg.isInvalid())
4963 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004964
Douglas Gregorb98b1992009-08-11 05:31:07 +00004965 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4966 FakeCommaLocs.push_back(
4967 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4968 Args.push_back(TransArg.takeAs<Expr>());
4969 }
Mike Stump1eb44332009-09-09 15:08:12 +00004970
Douglas Gregorb98b1992009-08-11 05:31:07 +00004971 if (!getDerived().AlwaysRebuild() &&
4972 T == E->getTypeAsWritten() &&
4973 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004974 return SemaRef.Owned(E->Retain());
4975
Douglas Gregorb98b1992009-08-11 05:31:07 +00004976 // FIXME: we're faking the locations of the commas
4977 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4978 T,
4979 E->getLParenLoc(),
4980 move_arg(Args),
4981 FakeCommaLocs.data(),
4982 E->getRParenLoc());
4983}
Mike Stump1eb44332009-09-09 15:08:12 +00004984
Douglas Gregorb98b1992009-08-11 05:31:07 +00004985template<typename Derived>
4986Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00004987TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall454feb92009-12-08 09:21:05 +00004988 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004989 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00004990 OwningExprResult Base(SemaRef, (Expr*) 0);
4991 Expr *OldBase;
4992 QualType BaseType;
4993 QualType ObjectType;
4994 if (!E->isImplicitAccess()) {
4995 OldBase = E->getBase();
4996 Base = getDerived().TransformExpr(OldBase);
4997 if (Base.isInvalid())
4998 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004999
John McCallaa81e162009-12-01 22:10:20 +00005000 // Start the member reference and compute the object's type.
5001 Sema::TypeTy *ObjectTy = 0;
5002 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5003 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005004 E->isArrow()? tok::arrow : tok::period,
John McCallaa81e162009-12-01 22:10:20 +00005005 ObjectTy);
5006 if (Base.isInvalid())
5007 return SemaRef.ExprError();
5008
5009 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5010 BaseType = ((Expr*) Base.get())->getType();
5011 } else {
5012 OldBase = 0;
5013 BaseType = getDerived().TransformType(E->getBaseType());
5014 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5015 }
Mike Stump1eb44332009-09-09 15:08:12 +00005016
Douglas Gregor6cd21982009-10-20 05:58:46 +00005017 // Transform the first part of the nested-name-specifier that qualifies
5018 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005019 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005020 = getDerived().TransformFirstQualifierInScope(
5021 E->getFirstQualifierFoundInScope(),
5022 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005023
Douglas Gregora38c6872009-09-03 16:14:30 +00005024 NestedNameSpecifier *Qualifier = 0;
5025 if (E->getQualifier()) {
5026 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5027 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005028 ObjectType,
5029 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005030 if (!Qualifier)
5031 return SemaRef.ExprError();
5032 }
Mike Stump1eb44332009-09-09 15:08:12 +00005033
5034 DeclarationName Name
Douglas Gregordd62b152009-10-19 22:04:39 +00005035 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCallaa81e162009-12-01 22:10:20 +00005036 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00005037 if (!Name)
5038 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005039
John McCallaa81e162009-12-01 22:10:20 +00005040 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005041 // This is a reference to a member without an explicitly-specified
5042 // template argument list. Optimize for this common case.
5043 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005044 Base.get() == OldBase &&
5045 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005046 Qualifier == E->getQualifier() &&
5047 Name == E->getMember() &&
5048 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005049 return SemaRef.Owned(E->Retain());
5050
John McCall865d4472009-11-19 22:55:06 +00005051 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005052 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005053 E->isArrow(),
5054 E->getOperatorLoc(),
5055 Qualifier,
5056 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005057 FirstQualifierInScope,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005058 Name,
5059 E->getMemberLoc(),
John McCall129e2df2009-11-30 22:42:35 +00005060 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005061 }
5062
John McCalld5532b62009-11-23 01:53:49 +00005063 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005064 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005065 TemplateArgumentLoc Loc;
5066 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005067 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005068 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005069 }
Mike Stump1eb44332009-09-09 15:08:12 +00005070
John McCall865d4472009-11-19 22:55:06 +00005071 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005072 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005073 E->isArrow(),
5074 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005075 Qualifier,
5076 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005077 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005078 Name,
5079 E->getMemberLoc(),
5080 &TransArgs);
5081}
5082
5083template<typename Derived>
5084Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005085TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005086 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005087 OwningExprResult Base(SemaRef, (Expr*) 0);
5088 QualType BaseType;
5089 if (!Old->isImplicitAccess()) {
5090 Base = getDerived().TransformExpr(Old->getBase());
5091 if (Base.isInvalid())
5092 return SemaRef.ExprError();
5093 BaseType = ((Expr*) Base.get())->getType();
5094 } else {
5095 BaseType = getDerived().TransformType(Old->getBaseType());
5096 }
John McCall129e2df2009-11-30 22:42:35 +00005097
5098 NestedNameSpecifier *Qualifier = 0;
5099 if (Old->getQualifier()) {
5100 Qualifier
5101 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
5102 Old->getQualifierRange());
5103 if (Qualifier == 0)
5104 return SemaRef.ExprError();
5105 }
5106
5107 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5108 Sema::LookupOrdinaryName);
5109
5110 // Transform all the decls.
5111 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5112 E = Old->decls_end(); I != E; ++I) {
5113 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall9f54ad42009-12-10 09:41:52 +00005114 if (!InstD) {
5115 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5116 // This can happen because of dependent hiding.
5117 if (isa<UsingShadowDecl>(*I))
5118 continue;
5119 else
5120 return SemaRef.ExprError();
5121 }
John McCall129e2df2009-11-30 22:42:35 +00005122
5123 // Expand using declarations.
5124 if (isa<UsingDecl>(InstD)) {
5125 UsingDecl *UD = cast<UsingDecl>(InstD);
5126 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5127 E = UD->shadow_end(); I != E; ++I)
5128 R.addDecl(*I);
5129 continue;
5130 }
5131
5132 R.addDecl(InstD);
5133 }
5134
5135 R.resolveKind();
5136
5137 TemplateArgumentListInfo TransArgs;
5138 if (Old->hasExplicitTemplateArgs()) {
5139 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5140 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5141 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5142 TemplateArgumentLoc Loc;
5143 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5144 Loc))
5145 return SemaRef.ExprError();
5146 TransArgs.addArgument(Loc);
5147 }
5148 }
John McCallc2233c52010-01-15 08:34:02 +00005149
5150 // FIXME: to do this check properly, we will need to preserve the
5151 // first-qualifier-in-scope here, just in case we had a dependent
5152 // base (and therefore couldn't do the check) and a
5153 // nested-name-qualifier (and therefore could do the lookup).
5154 NamedDecl *FirstQualifierInScope = 0;
John McCall129e2df2009-11-30 22:42:35 +00005155
5156 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005157 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00005158 Old->getOperatorLoc(),
5159 Old->isArrow(),
5160 Qualifier,
5161 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00005162 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005163 R,
5164 (Old->hasExplicitTemplateArgs()
5165 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005166}
5167
5168template<typename Derived>
5169Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005170TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005171 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005172}
5173
Mike Stump1eb44332009-09-09 15:08:12 +00005174template<typename Derived>
5175Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005176TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005177 // FIXME: poor source location
5178 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5179 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5180 if (EncodedType.isNull())
5181 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005182
Douglas Gregorb98b1992009-08-11 05:31:07 +00005183 if (!getDerived().AlwaysRebuild() &&
5184 EncodedType == E->getEncodedType())
Mike Stump1eb44332009-09-09 15:08:12 +00005185 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005186
5187 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5188 EncodedType,
5189 E->getRParenLoc());
5190}
Mike Stump1eb44332009-09-09 15:08:12 +00005191
Douglas Gregorb98b1992009-08-11 05:31:07 +00005192template<typename Derived>
5193Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005194TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005195 // FIXME: Implement this!
5196 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005197 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005198}
5199
Mike Stump1eb44332009-09-09 15:08:12 +00005200template<typename Derived>
5201Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005202TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005203 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005204}
5205
Mike Stump1eb44332009-09-09 15:08:12 +00005206template<typename Derived>
5207Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005208TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005209 ObjCProtocolDecl *Protocol
Douglas Gregorb98b1992009-08-11 05:31:07 +00005210 = cast_or_null<ObjCProtocolDecl>(
5211 getDerived().TransformDecl(E->getProtocol()));
5212 if (!Protocol)
5213 return SemaRef.ExprError();
5214
5215 if (!getDerived().AlwaysRebuild() &&
5216 Protocol == E->getProtocol())
Mike Stump1eb44332009-09-09 15:08:12 +00005217 return SemaRef.Owned(E->Retain());
5218
Douglas Gregorb98b1992009-08-11 05:31:07 +00005219 return getDerived().RebuildObjCProtocolExpr(Protocol,
5220 E->getAtLoc(),
5221 /*FIXME:*/E->getAtLoc(),
5222 /*FIXME:*/E->getAtLoc(),
5223 E->getRParenLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00005224
Douglas Gregorb98b1992009-08-11 05:31:07 +00005225}
5226
Mike Stump1eb44332009-09-09 15:08:12 +00005227template<typename Derived>
5228Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005229TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005230 // FIXME: Implement this!
5231 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005232 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005233}
5234
Mike Stump1eb44332009-09-09 15:08:12 +00005235template<typename Derived>
5236Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005237TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005238 // FIXME: Implement this!
5239 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005240 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005241}
5242
Mike Stump1eb44332009-09-09 15:08:12 +00005243template<typename Derived>
5244Sema::OwningExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00005245TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00005246 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005247 // FIXME: Implement this!
5248 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005249 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005250}
5251
Mike Stump1eb44332009-09-09 15:08:12 +00005252template<typename Derived>
5253Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005254TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005255 // FIXME: Implement this!
5256 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005257 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005258}
5259
Mike Stump1eb44332009-09-09 15:08:12 +00005260template<typename Derived>
5261Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005262TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005263 // FIXME: Implement this!
5264 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005265 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005266}
5267
Mike Stump1eb44332009-09-09 15:08:12 +00005268template<typename Derived>
5269Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005270TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005271 bool ArgumentChanged = false;
5272 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5273 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5274 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5275 if (SubExpr.isInvalid())
5276 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005277
Douglas Gregorb98b1992009-08-11 05:31:07 +00005278 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5279 SubExprs.push_back(SubExpr.takeAs<Expr>());
5280 }
Mike Stump1eb44332009-09-09 15:08:12 +00005281
Douglas Gregorb98b1992009-08-11 05:31:07 +00005282 if (!getDerived().AlwaysRebuild() &&
5283 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005284 return SemaRef.Owned(E->Retain());
5285
Douglas Gregorb98b1992009-08-11 05:31:07 +00005286 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5287 move_arg(SubExprs),
5288 E->getRParenLoc());
5289}
5290
Mike Stump1eb44332009-09-09 15:08:12 +00005291template<typename Derived>
5292Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005293TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005294 // FIXME: Implement this!
5295 assert(false && "Cannot transform block expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005296 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005297}
5298
Mike Stump1eb44332009-09-09 15:08:12 +00005299template<typename Derived>
5300Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005301TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005302 // FIXME: Implement this!
5303 assert(false && "Cannot transform block-related expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005304 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005305}
Mike Stump1eb44332009-09-09 15:08:12 +00005306
Douglas Gregorb98b1992009-08-11 05:31:07 +00005307//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00005308// Type reconstruction
5309//===----------------------------------------------------------------------===//
5310
Mike Stump1eb44332009-09-09 15:08:12 +00005311template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005312QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5313 SourceLocation Star) {
5314 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005315 getDerived().getBaseEntity());
5316}
5317
Mike Stump1eb44332009-09-09 15:08:12 +00005318template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005319QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5320 SourceLocation Star) {
5321 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005322 getDerived().getBaseEntity());
5323}
5324
Mike Stump1eb44332009-09-09 15:08:12 +00005325template<typename Derived>
5326QualType
John McCall85737a72009-10-30 00:06:24 +00005327TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5328 bool WrittenAsLValue,
5329 SourceLocation Sigil) {
5330 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5331 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005332}
5333
5334template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005335QualType
John McCall85737a72009-10-30 00:06:24 +00005336TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5337 QualType ClassType,
5338 SourceLocation Sigil) {
John McCall0953e762009-09-24 19:53:00 +00005339 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall85737a72009-10-30 00:06:24 +00005340 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005341}
5342
5343template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005344QualType
John McCall85737a72009-10-30 00:06:24 +00005345TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5346 SourceLocation Sigil) {
5347 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCalla2becad2009-10-21 00:40:46 +00005348 getDerived().getBaseEntity());
5349}
5350
5351template<typename Derived>
5352QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00005353TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5354 ArrayType::ArraySizeModifier SizeMod,
5355 const llvm::APInt *Size,
5356 Expr *SizeExpr,
5357 unsigned IndexTypeQuals,
5358 SourceRange BracketsRange) {
5359 if (SizeExpr || !Size)
5360 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5361 IndexTypeQuals, BracketsRange,
5362 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00005363
5364 QualType Types[] = {
5365 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5366 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5367 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00005368 };
5369 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5370 QualType SizeType;
5371 for (unsigned I = 0; I != NumTypes; ++I)
5372 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5373 SizeType = Types[I];
5374 break;
5375 }
Mike Stump1eb44332009-09-09 15:08:12 +00005376
Douglas Gregor577f75a2009-08-04 16:50:30 +00005377 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005378 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005379 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00005380 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005381}
Mike Stump1eb44332009-09-09 15:08:12 +00005382
Douglas Gregor577f75a2009-08-04 16:50:30 +00005383template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005384QualType
5385TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005386 ArrayType::ArraySizeModifier SizeMod,
5387 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00005388 unsigned IndexTypeQuals,
5389 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005390 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00005391 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005392}
5393
5394template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005395QualType
Mike Stump1eb44332009-09-09 15:08:12 +00005396TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005397 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00005398 unsigned IndexTypeQuals,
5399 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005400 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00005401 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005402}
Mike Stump1eb44332009-09-09 15:08:12 +00005403
Douglas Gregor577f75a2009-08-04 16:50:30 +00005404template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005405QualType
5406TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005407 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005408 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005409 unsigned IndexTypeQuals,
5410 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005411 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005412 SizeExpr.takeAs<Expr>(),
5413 IndexTypeQuals, BracketsRange);
5414}
5415
5416template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005417QualType
5418TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005419 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005420 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005421 unsigned IndexTypeQuals,
5422 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005423 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005424 SizeExpr.takeAs<Expr>(),
5425 IndexTypeQuals, BracketsRange);
5426}
5427
5428template<typename Derived>
5429QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson82287d12010-02-05 00:12:22 +00005430 unsigned NumElements,
5431 bool IsAltiVec, bool IsPixel) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005432 // FIXME: semantic checking!
John Thompson82287d12010-02-05 00:12:22 +00005433 return SemaRef.Context.getVectorType(ElementType, NumElements,
5434 IsAltiVec, IsPixel);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005435}
Mike Stump1eb44332009-09-09 15:08:12 +00005436
Douglas Gregor577f75a2009-08-04 16:50:30 +00005437template<typename Derived>
5438QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5439 unsigned NumElements,
5440 SourceLocation AttributeLoc) {
5441 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5442 NumElements, true);
5443 IntegerLiteral *VectorSize
Mike Stump1eb44332009-09-09 15:08:12 +00005444 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005445 AttributeLoc);
5446 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5447 AttributeLoc);
5448}
Mike Stump1eb44332009-09-09 15:08:12 +00005449
Douglas Gregor577f75a2009-08-04 16:50:30 +00005450template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005451QualType
5452TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005453 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005454 SourceLocation AttributeLoc) {
5455 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5456}
Mike Stump1eb44332009-09-09 15:08:12 +00005457
Douglas Gregor577f75a2009-08-04 16:50:30 +00005458template<typename Derived>
5459QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00005460 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005461 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00005462 bool Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005463 unsigned Quals) {
Mike Stump1eb44332009-09-09 15:08:12 +00005464 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005465 Quals,
5466 getDerived().getBaseLocation(),
5467 getDerived().getBaseEntity());
5468}
Mike Stump1eb44332009-09-09 15:08:12 +00005469
Douglas Gregor577f75a2009-08-04 16:50:30 +00005470template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005471QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5472 return SemaRef.Context.getFunctionNoProtoType(T);
5473}
5474
5475template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00005476QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5477 assert(D && "no decl found");
5478 if (D->isInvalidDecl()) return QualType();
5479
5480 TypeDecl *Ty;
5481 if (isa<UsingDecl>(D)) {
5482 UsingDecl *Using = cast<UsingDecl>(D);
5483 assert(Using->isTypeName() &&
5484 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5485
5486 // A valid resolved using typename decl points to exactly one type decl.
5487 assert(++Using->shadow_begin() == Using->shadow_end());
5488 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5489
5490 } else {
5491 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5492 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5493 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5494 }
5495
5496 return SemaRef.Context.getTypeDeclType(Ty);
5497}
5498
5499template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00005500QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005501 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5502}
5503
5504template<typename Derived>
5505QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5506 return SemaRef.Context.getTypeOfType(Underlying);
5507}
5508
5509template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00005510QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005511 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5512}
5513
5514template<typename Derived>
5515QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00005516 TemplateName Template,
5517 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00005518 const TemplateArgumentListInfo &TemplateArgs) {
5519 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005520}
Mike Stump1eb44332009-09-09 15:08:12 +00005521
Douglas Gregordcee1a12009-08-06 05:28:30 +00005522template<typename Derived>
5523NestedNameSpecifier *
5524TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5525 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00005526 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00005527 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00005528 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00005529 CXXScopeSpec SS;
5530 // FIXME: The source location information is all wrong.
5531 SS.setRange(Range);
5532 SS.setScopeRep(Prefix);
5533 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00005534 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00005535 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00005536 ObjectType,
5537 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00005538 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00005539}
5540
5541template<typename Derived>
5542NestedNameSpecifier *
5543TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5544 SourceRange Range,
5545 NamespaceDecl *NS) {
5546 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5547}
5548
5549template<typename Derived>
5550NestedNameSpecifier *
5551TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5552 SourceRange Range,
5553 bool TemplateKW,
5554 QualType T) {
5555 if (T->isDependentType() || T->isRecordType() ||
5556 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00005557 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00005558 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5559 T.getTypePtr());
5560 }
Mike Stump1eb44332009-09-09 15:08:12 +00005561
Douglas Gregordcee1a12009-08-06 05:28:30 +00005562 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5563 return 0;
5564}
Mike Stump1eb44332009-09-09 15:08:12 +00005565
Douglas Gregord1067e52009-08-06 06:41:21 +00005566template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005567TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00005568TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5569 bool TemplateKW,
5570 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00005571 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00005572 Template);
5573}
5574
5575template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005576TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00005577TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005578 const IdentifierInfo &II,
5579 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00005580 CXXScopeSpec SS;
5581 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump1eb44332009-09-09 15:08:12 +00005582 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00005583 UnqualifiedId Name;
5584 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005585 return getSema().ActOnDependentTemplateName(
5586 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005587 SS,
Douglas Gregor014e88d2009-11-03 23:16:33 +00005588 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00005589 ObjectType.getAsOpaquePtr(),
5590 /*EnteringContext=*/false)
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005591 .template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00005592}
Mike Stump1eb44332009-09-09 15:08:12 +00005593
Douglas Gregorb98b1992009-08-11 05:31:07 +00005594template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00005595TemplateName
5596TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5597 OverloadedOperatorKind Operator,
5598 QualType ObjectType) {
5599 CXXScopeSpec SS;
5600 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5601 SS.setScopeRep(Qualifier);
5602 UnqualifiedId Name;
5603 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5604 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5605 Operator, SymbolLocations);
5606 return getSema().ActOnDependentTemplateName(
5607 /*FIXME:*/getDerived().getBaseLocation(),
5608 SS,
5609 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00005610 ObjectType.getAsOpaquePtr(),
5611 /*EnteringContext=*/false)
Douglas Gregorca1bdd72009-11-04 00:56:37 +00005612 .template getAsVal<TemplateName>();
5613}
5614
5615template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005616Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005617TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5618 SourceLocation OpLoc,
5619 ExprArg Callee,
5620 ExprArg First,
5621 ExprArg Second) {
5622 Expr *FirstExpr = (Expr *)First.get();
5623 Expr *SecondExpr = (Expr *)Second.get();
John McCallba135432009-11-21 08:51:07 +00005624 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005625 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00005626
Douglas Gregorb98b1992009-08-11 05:31:07 +00005627 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00005628 if (Op == OO_Subscript) {
5629 if (!FirstExpr->getType()->isOverloadableType() &&
5630 !SecondExpr->getType()->isOverloadableType())
5631 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCallba135432009-11-21 08:51:07 +00005632 CalleeExpr->getLocStart(),
Sebastian Redlf322ed62009-10-29 20:17:01 +00005633 move(Second), OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00005634 } else if (Op == OO_Arrow) {
5635 // -> is never a builtin operation.
5636 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redlf322ed62009-10-29 20:17:01 +00005637 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005638 if (!FirstExpr->getType()->isOverloadableType()) {
5639 // The argument is not of overloadable type, so try to create a
5640 // built-in unary operation.
Mike Stump1eb44332009-09-09 15:08:12 +00005641 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005642 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00005643
Douglas Gregorb98b1992009-08-11 05:31:07 +00005644 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5645 }
5646 } else {
Mike Stump1eb44332009-09-09 15:08:12 +00005647 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005648 !SecondExpr->getType()->isOverloadableType()) {
5649 // Neither of the arguments is an overloadable type, so try to
5650 // create a built-in binary operation.
5651 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00005652 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00005653 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5654 if (Result.isInvalid())
5655 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005656
Douglas Gregorb98b1992009-08-11 05:31:07 +00005657 First.release();
5658 Second.release();
5659 return move(Result);
5660 }
5661 }
Mike Stump1eb44332009-09-09 15:08:12 +00005662
5663 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00005664 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00005665 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00005666
John McCallba135432009-11-21 08:51:07 +00005667 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5668 assert(ULE->requiresADL());
5669
5670 // FIXME: Do we have to check
5671 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00005672 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00005673 } else {
John McCall6e266892010-01-26 03:27:55 +00005674 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCallba135432009-11-21 08:51:07 +00005675 }
Mike Stump1eb44332009-09-09 15:08:12 +00005676
Douglas Gregorb98b1992009-08-11 05:31:07 +00005677 // Add any functions found via argument-dependent lookup.
5678 Expr *Args[2] = { FirstExpr, SecondExpr };
5679 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00005680
Douglas Gregorb98b1992009-08-11 05:31:07 +00005681 // Create the overloaded operator invocation for unary operators.
5682 if (NumArgs == 1 || isPostIncDec) {
Mike Stump1eb44332009-09-09 15:08:12 +00005683 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005684 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5685 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5686 }
Mike Stump1eb44332009-09-09 15:08:12 +00005687
Sebastian Redlf322ed62009-10-29 20:17:01 +00005688 if (Op == OO_Subscript)
John McCallba135432009-11-21 08:51:07 +00005689 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5690 OpLoc,
5691 move(First),
5692 move(Second));
Sebastian Redlf322ed62009-10-29 20:17:01 +00005693
Douglas Gregorb98b1992009-08-11 05:31:07 +00005694 // Create the overloaded operator invocation for binary operators.
Mike Stump1eb44332009-09-09 15:08:12 +00005695 BinaryOperator::Opcode Opc =
Douglas Gregorb98b1992009-08-11 05:31:07 +00005696 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00005697 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00005698 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5699 if (Result.isInvalid())
5700 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005701
Douglas Gregorb98b1992009-08-11 05:31:07 +00005702 First.release();
5703 Second.release();
Mike Stump1eb44332009-09-09 15:08:12 +00005704 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005705}
Mike Stump1eb44332009-09-09 15:08:12 +00005706
Douglas Gregor577f75a2009-08-04 16:50:30 +00005707} // end namespace clang
5708
5709#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H