blob: 4e29c3ad85f9334f7275ed39264884ff1db318f0 [file] [log] [blame]
John McCalla2becad2009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregor577f75a2009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
16#include "Sema.h"
John McCallf7a1a742009-11-24 19:00:30 +000017#include "Lookup.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000020#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000021#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000023#include "clang/AST/Stmt.h"
24#include "clang/AST/StmtCXX.h"
25#include "clang/AST/StmtObjC.h"
John McCalla2becad2009-10-21 00:40:46 +000026#include "clang/AST/TypeLocBuilder.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000027#include "clang/Parse/Ownership.h"
28#include "clang/Parse/Designator.h"
29#include "clang/Lex/Preprocessor.h"
John McCalla2becad2009-10-21 00:40:46 +000030#include "llvm/Support/ErrorHandling.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000031#include <algorithm>
32
33namespace clang {
Mike Stump1eb44332009-09-09 15:08:12 +000034
Douglas Gregor577f75a2009-08-04 16:50:30 +000035/// \brief A semantic tree transformation that allows one to transform one
36/// abstract syntax tree into another.
37///
Mike Stump1eb44332009-09-09 15:08:12 +000038/// A new tree transformation is defined by creating a new subclass \c X of
39/// \c TreeTransform<X> and then overriding certain operations to provide
40/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000041/// instantiation is implemented as a tree transformation where the
42/// transformation of TemplateTypeParmType nodes involves substituting the
43/// template arguments for their corresponding template parameters; a similar
44/// transformation is performed for non-type template parameters and
45/// template template parameters.
46///
47/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000048/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000049/// override any of the transformation or rebuild operators by providing an
50/// operation with the same signature as the default implementation. The
51/// overridding function should not be virtual.
52///
53/// Semantic tree transformations are split into two stages, either of which
54/// can be replaced by a subclass. The "transform" step transforms an AST node
55/// or the parts of an AST node using the various transformation functions,
56/// then passes the pieces on to the "rebuild" step, which constructs a new AST
57/// node of the appropriate kind from the pieces. The default transformation
58/// routines recursively transform the operands to composite AST nodes (e.g.,
59/// the pointee type of a PointerType node) and, if any of those operand nodes
60/// were changed by the transformation, invokes the rebuild operation to create
61/// a new AST node.
62///
Mike Stump1eb44332009-09-09 15:08:12 +000063/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000064/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000065/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
66/// TransformTemplateName(), or TransformTemplateArgument() with entirely
67/// new implementations.
68///
69/// For more fine-grained transformations, subclasses can replace any of the
70/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000071/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000072/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000073/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000074/// parameters. Additionally, subclasses can override the \c RebuildXXX
75/// functions to control how AST nodes are rebuilt when their operands change.
76/// By default, \c TreeTransform will invoke semantic analysis to rebuild
77/// AST nodes. However, certain other tree transformations (e.g, cloning) may
78/// be able to use more efficient rebuild steps.
79///
80/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000081/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000082/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
83/// operands have not changed (\c AlwaysRebuild()), and customize the
84/// default locations and entity names used for type-checking
85/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000086template<typename Derived>
87class TreeTransform {
88protected:
89 Sema &SemaRef;
Mike Stump1eb44332009-09-09 15:08:12 +000090
91public:
Douglas Gregorb98b1992009-08-11 05:31:07 +000092 typedef Sema::OwningStmtResult OwningStmtResult;
93 typedef Sema::OwningExprResult OwningExprResult;
94 typedef Sema::StmtArg StmtArg;
95 typedef Sema::ExprArg ExprArg;
96 typedef Sema::MultiExprArg MultiExprArg;
Douglas Gregor43959a92009-08-20 07:17:43 +000097 typedef Sema::MultiStmtArg MultiStmtArg;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +000098 typedef Sema::DeclPtrTy DeclPtrTy;
99
Douglas Gregor577f75a2009-08-04 16:50:30 +0000100 /// \brief Initializes a new tree transformer.
101 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000102
Douglas Gregor577f75a2009-08-04 16:50:30 +0000103 /// \brief Retrieves a reference to the derived class.
104 Derived &getDerived() { return static_cast<Derived&>(*this); }
105
106 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000107 const Derived &getDerived() const {
108 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000109 }
110
111 /// \brief Retrieves a reference to the semantic analysis object used for
112 /// this tree transform.
113 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000114
Douglas Gregor577f75a2009-08-04 16:50:30 +0000115 /// \brief Whether the transformation should always rebuild AST nodes, even
116 /// if none of the children have changed.
117 ///
118 /// Subclasses may override this function to specify when the transformation
119 /// should rebuild all AST nodes.
120 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000121
Douglas Gregor577f75a2009-08-04 16:50:30 +0000122 /// \brief Returns the location of the entity being transformed, if that
123 /// information was not available elsewhere in the AST.
124 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000125 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000126 /// provide an alternative implementation that provides better location
127 /// information.
128 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000129
Douglas Gregor577f75a2009-08-04 16:50:30 +0000130 /// \brief Returns the name of the entity being transformed, if that
131 /// information was not available elsewhere in the AST.
132 ///
133 /// By default, returns an empty name. Subclasses can provide an alternative
134 /// implementation with a more precise name.
135 DeclarationName getBaseEntity() { return DeclarationName(); }
136
Douglas Gregorb98b1992009-08-11 05:31:07 +0000137 /// \brief Sets the "base" location and entity when that
138 /// information is known based on another transformation.
139 ///
140 /// By default, the source location and entity are ignored. Subclasses can
141 /// override this function to provide a customized implementation.
142 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000143
Douglas Gregorb98b1992009-08-11 05:31:07 +0000144 /// \brief RAII object that temporarily sets the base location and entity
145 /// used for reporting diagnostics in types.
146 class TemporaryBase {
147 TreeTransform &Self;
148 SourceLocation OldLocation;
149 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000150
Douglas Gregorb98b1992009-08-11 05:31:07 +0000151 public:
152 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000153 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000154 OldLocation = Self.getDerived().getBaseLocation();
155 OldEntity = Self.getDerived().getBaseEntity();
156 Self.getDerived().setBase(Location, Entity);
157 }
Mike Stump1eb44332009-09-09 15:08:12 +0000158
Douglas Gregorb98b1992009-08-11 05:31:07 +0000159 ~TemporaryBase() {
160 Self.getDerived().setBase(OldLocation, OldEntity);
161 }
162 };
Mike Stump1eb44332009-09-09 15:08:12 +0000163
164 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000165 /// transformed.
166 ///
167 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000168 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000169 /// not change. For example, template instantiation need not traverse
170 /// non-dependent types.
171 bool AlreadyTransformed(QualType T) {
172 return T.isNull();
173 }
174
Douglas Gregor6eef5192009-12-14 19:27:10 +0000175 /// \brief Determine whether the given call argument should be dropped, e.g.,
176 /// because it is a default argument.
177 ///
178 /// Subclasses can provide an alternative implementation of this routine to
179 /// determine which kinds of call arguments get dropped. By default,
180 /// CXXDefaultArgument nodes are dropped (prior to transformation).
181 bool DropCallArgument(Expr *E) {
182 return E->isDefaultArgument();
183 }
184
Douglas Gregor577f75a2009-08-04 16:50:30 +0000185 /// \brief Transforms the given type into another type.
186 ///
John McCalla2becad2009-10-21 00:40:46 +0000187 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000188 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000189 /// function. This is expensive, but we don't mind, because
190 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000191 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000192 ///
193 /// \returns the transformed type.
194 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000195
John McCalla2becad2009-10-21 00:40:46 +0000196 /// \brief Transforms the given type-with-location into a new
197 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000198 ///
John McCalla2becad2009-10-21 00:40:46 +0000199 /// By default, this routine transforms a type by delegating to the
200 /// appropriate TransformXXXType to build a new type. Subclasses
201 /// may override this function (to take over all type
202 /// transformations) or some set of the TransformXXXType functions
203 /// to alter the transformation.
John McCalla93c9342009-12-07 02:54:59 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000205
206 /// \brief Transform the given type-with-location into a new
207 /// type, collecting location information in the given builder
208 /// as necessary.
209 ///
210 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000211
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000212 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000213 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000214 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000215 /// appropriate TransformXXXStmt function to transform a specific kind of
216 /// statement or the TransformExpr() function to transform an expression.
217 /// Subclasses may override this function to transform statements using some
218 /// other mechanism.
219 ///
220 /// \returns the transformed statement.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000221 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000222
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000223 /// \brief Transform the given expression.
224 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000225 /// By default, this routine transforms an expression by delegating to the
226 /// appropriate TransformXXXExpr function to build a new expression.
227 /// Subclasses may override this function to transform expressions using some
228 /// other mechanism.
229 ///
230 /// \returns the transformed expression.
John McCall454feb92009-12-08 09:21:05 +0000231 OwningExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000232
Douglas Gregor577f75a2009-08-04 16:50:30 +0000233 /// \brief Transform the given declaration, which is referenced from a type
234 /// or expression.
235 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000236 /// By default, acts as the identity function on declarations. Subclasses
237 /// may override this function to provide alternate behavior.
238 Decl *TransformDecl(Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000239
240 /// \brief Transform the definition of the given declaration.
241 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000242 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000243 /// Subclasses may override this function to provide alternate behavior.
244 Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); }
Mike Stump1eb44332009-09-09 15:08:12 +0000245
Douglas Gregor6cd21982009-10-20 05:58:46 +0000246 /// \brief Transform the given declaration, which was the first part of a
247 /// nested-name-specifier in a member access expression.
248 ///
249 /// This specific declaration transformation only applies to the first
250 /// identifier in a nested-name-specifier of a member access expression, e.g.,
251 /// the \c T in \c x->T::member
252 ///
253 /// By default, invokes TransformDecl() to transform the declaration.
254 /// Subclasses may override this function to provide alternate behavior.
255 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
256 return cast_or_null<NamedDecl>(getDerived().TransformDecl(D));
257 }
258
Douglas Gregor577f75a2009-08-04 16:50:30 +0000259 /// \brief Transform the given nested-name-specifier.
260 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000261 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000262 /// nested-name-specifier. Subclasses may override this function to provide
263 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000264 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000265 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000266 QualType ObjectType = QualType(),
267 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000268
Douglas Gregor81499bb2009-09-03 22:13:48 +0000269 /// \brief Transform the given declaration name.
270 ///
271 /// By default, transforms the types of conversion function, constructor,
272 /// and destructor names and then (if needed) rebuilds the declaration name.
273 /// Identifiers and selectors are returned unmodified. Sublcasses may
274 /// override this function to provide alternate behavior.
275 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +0000276 SourceLocation Loc,
277 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000278
Douglas Gregor577f75a2009-08-04 16:50:30 +0000279 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000280 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000281 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000282 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000283 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000284 TemplateName TransformTemplateName(TemplateName Name,
285 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000286
Douglas Gregor577f75a2009-08-04 16:50:30 +0000287 /// \brief Transform the given template argument.
288 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000289 /// By default, this operation transforms the type, expression, or
290 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000291 /// new template argument from the transformed result. Subclasses may
292 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000293 ///
294 /// Returns true if there was an error.
295 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
296 TemplateArgumentLoc &Output);
297
298 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
299 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
300 TemplateArgumentLoc &ArgLoc);
301
John McCalla93c9342009-12-07 02:54:59 +0000302 /// \brief Fakes up a TypeSourceInfo for a type.
303 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
304 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000305 getDerived().getBaseLocation());
306 }
Mike Stump1eb44332009-09-09 15:08:12 +0000307
John McCalla2becad2009-10-21 00:40:46 +0000308#define ABSTRACT_TYPELOC(CLASS, PARENT)
309#define TYPELOC(CLASS, PARENT) \
310 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
311#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000312
John McCall85737a72009-10-30 00:06:24 +0000313 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
314
Douglas Gregordd62b152009-10-19 22:04:39 +0000315 QualType
316 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
317 QualType ObjectType);
John McCall833ca992009-10-29 08:12:44 +0000318
319 QualType
320 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
321 TemplateSpecializationTypeLoc TL,
322 QualType ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +0000323
Douglas Gregor43959a92009-08-20 07:17:43 +0000324 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Mike Stump1eb44332009-09-09 15:08:12 +0000325
Douglas Gregor43959a92009-08-20 07:17:43 +0000326#define STMT(Node, Parent) \
327 OwningStmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000328#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +0000329 OwningExprResult Transform##Node(Node *E);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000330#define ABSTRACT_EXPR(Node, Parent)
331#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +0000332
Douglas Gregor577f75a2009-08-04 16:50:30 +0000333 /// \brief Build a new pointer type given its pointee type.
334 ///
335 /// By default, performs semantic analysis when building the pointer type.
336 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000337 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000338
339 /// \brief Build a new block pointer type given its pointee type.
340 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000341 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000342 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000343 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000344
John McCall85737a72009-10-30 00:06:24 +0000345 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000346 ///
John McCall85737a72009-10-30 00:06:24 +0000347 /// By default, performs semantic analysis when building the
348 /// reference type. Subclasses may override this routine to provide
349 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000350 ///
John McCall85737a72009-10-30 00:06:24 +0000351 /// \param LValue whether the type was written with an lvalue sigil
352 /// or an rvalue sigil.
353 QualType RebuildReferenceType(QualType ReferentType,
354 bool LValue,
355 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000356
Douglas Gregor577f75a2009-08-04 16:50:30 +0000357 /// \brief Build a new member pointer type given the pointee type and the
358 /// class type it refers into.
359 ///
360 /// By default, performs semantic analysis when building the member pointer
361 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000362 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
363 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000364
John McCalla2becad2009-10-21 00:40:46 +0000365 /// \brief Build a new Objective C object pointer type.
John McCall85737a72009-10-30 00:06:24 +0000366 QualType RebuildObjCObjectPointerType(QualType PointeeType,
367 SourceLocation Sigil);
John McCalla2becad2009-10-21 00:40:46 +0000368
Douglas Gregor577f75a2009-08-04 16:50:30 +0000369 /// \brief Build a new array type given the element type, size
370 /// modifier, size of the array (if known), size expression, and index type
371 /// qualifiers.
372 ///
373 /// By default, performs semantic analysis when building the array type.
374 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000375 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000376 QualType RebuildArrayType(QualType ElementType,
377 ArrayType::ArraySizeModifier SizeMod,
378 const llvm::APInt *Size,
379 Expr *SizeExpr,
380 unsigned IndexTypeQuals,
381 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000382
Douglas Gregor577f75a2009-08-04 16:50:30 +0000383 /// \brief Build a new constant array type given the element type, size
384 /// modifier, (known) size of the array, and index type qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000388 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000389 ArrayType::ArraySizeModifier SizeMod,
390 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000391 unsigned IndexTypeQuals,
392 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000393
Douglas Gregor577f75a2009-08-04 16:50:30 +0000394 /// \brief Build a new incomplete array type given the element type, size
395 /// modifier, and index type qualifiers.
396 ///
397 /// By default, performs semantic analysis when building the array type.
398 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000399 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000400 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000401 unsigned IndexTypeQuals,
402 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000403
Mike Stump1eb44332009-09-09 15:08:12 +0000404 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000405 /// size modifier, size expression, and index type qualifiers.
406 ///
407 /// By default, performs semantic analysis when building the array type.
408 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000409 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000410 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000411 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000412 unsigned IndexTypeQuals,
413 SourceRange BracketsRange);
414
Mike Stump1eb44332009-09-09 15:08:12 +0000415 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000416 /// size modifier, size expression, and index type qualifiers.
417 ///
418 /// By default, performs semantic analysis when building the array type.
419 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000420 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000421 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000422 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000423 unsigned IndexTypeQuals,
424 SourceRange BracketsRange);
425
426 /// \brief Build a new vector type given the element type and
427 /// number of elements.
428 ///
429 /// By default, performs semantic analysis when building the vector type.
430 /// Subclasses may override this routine to provide different behavior.
431 QualType RebuildVectorType(QualType ElementType, unsigned NumElements);
Mike Stump1eb44332009-09-09 15:08:12 +0000432
Douglas Gregor577f75a2009-08-04 16:50:30 +0000433 /// \brief Build a new extended vector type given the element type and
434 /// number of elements.
435 ///
436 /// By default, performs semantic analysis when building the vector type.
437 /// Subclasses may override this routine to provide different behavior.
438 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
439 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000440
441 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000442 /// given the element type and number of elements.
443 ///
444 /// By default, performs semantic analysis when building the vector type.
445 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000446 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000447 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000448 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000449
Douglas Gregor577f75a2009-08-04 16:50:30 +0000450 /// \brief Build a new function type.
451 ///
452 /// By default, performs semantic analysis when building the function type.
453 /// Subclasses may override this routine to provide different behavior.
454 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000455 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000456 unsigned NumParamTypes,
457 bool Variadic, unsigned Quals);
Mike Stump1eb44332009-09-09 15:08:12 +0000458
John McCalla2becad2009-10-21 00:40:46 +0000459 /// \brief Build a new unprototyped function type.
460 QualType RebuildFunctionNoProtoType(QualType ResultType);
461
John McCalled976492009-12-04 22:46:56 +0000462 /// \brief Rebuild an unresolved typename type, given the decl that
463 /// the UnresolvedUsingTypenameDecl was transformed to.
464 QualType RebuildUnresolvedUsingType(Decl *D);
465
Douglas Gregor577f75a2009-08-04 16:50:30 +0000466 /// \brief Build a new typedef type.
467 QualType RebuildTypedefType(TypedefDecl *Typedef) {
468 return SemaRef.Context.getTypeDeclType(Typedef);
469 }
470
471 /// \brief Build a new class/struct/union type.
472 QualType RebuildRecordType(RecordDecl *Record) {
473 return SemaRef.Context.getTypeDeclType(Record);
474 }
475
476 /// \brief Build a new Enum type.
477 QualType RebuildEnumType(EnumDecl *Enum) {
478 return SemaRef.Context.getTypeDeclType(Enum);
479 }
John McCall7da24312009-09-05 00:15:47 +0000480
481 /// \brief Build a new elaborated type.
482 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
483 return SemaRef.Context.getElaboratedType(T, Tag);
484 }
Mike Stump1eb44332009-09-09 15:08:12 +0000485
486 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000487 ///
488 /// By default, performs semantic analysis when building the typeof type.
489 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000490 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000491
Mike Stump1eb44332009-09-09 15:08:12 +0000492 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000493 ///
494 /// By default, builds a new TypeOfType with the given underlying type.
495 QualType RebuildTypeOfType(QualType Underlying);
496
Mike Stump1eb44332009-09-09 15:08:12 +0000497 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000498 ///
499 /// By default, performs semantic analysis when building the decltype type.
500 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000501 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump1eb44332009-09-09 15:08:12 +0000502
Douglas Gregor577f75a2009-08-04 16:50:30 +0000503 /// \brief Build a new template specialization type.
504 ///
505 /// By default, performs semantic analysis when building the template
506 /// specialization type. Subclasses may override this routine to provide
507 /// different behavior.
508 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000509 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000510 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000511
Douglas Gregor577f75a2009-08-04 16:50:30 +0000512 /// \brief Build a new qualified name type.
513 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000514 /// By default, builds a new QualifiedNameType type from the
515 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregor577f75a2009-08-04 16:50:30 +0000516 /// this routine to provide different behavior.
517 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
518 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000519 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000520
521 /// \brief Build a new typename type that refers to a template-id.
522 ///
523 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump1eb44332009-09-09 15:08:12 +0000524 /// and the given type. Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000525 /// different behavior.
526 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
527 if (NNS->isDependent())
Mike Stump1eb44332009-09-09 15:08:12 +0000528 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000529 cast<TemplateSpecializationType>(T));
Mike Stump1eb44332009-09-09 15:08:12 +0000530
Douglas Gregor577f75a2009-08-04 16:50:30 +0000531 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000532 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000533
534 /// \brief Build a new typename type that refers to an identifier.
535 ///
536 /// By default, performs semantic analysis when building the typename type
Mike Stump1eb44332009-09-09 15:08:12 +0000537 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000538 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000539 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall833ca992009-10-29 08:12:44 +0000540 const IdentifierInfo *Id,
541 SourceRange SR) {
542 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000543 }
Mike Stump1eb44332009-09-09 15:08:12 +0000544
Douglas Gregordcee1a12009-08-06 05:28:30 +0000545 /// \brief Build a new nested-name-specifier given the prefix and an
546 /// identifier that names the next step in the nested-name-specifier.
547 ///
548 /// By default, performs semantic analysis when building the new
549 /// nested-name-specifier. Subclasses may override this routine to provide
550 /// different behavior.
551 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
552 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000553 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000554 QualType ObjectType,
555 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000556
557 /// \brief Build a new nested-name-specifier given the prefix and the
558 /// namespace named in the next step in the nested-name-specifier.
559 ///
560 /// By default, performs semantic analysis when building the new
561 /// nested-name-specifier. Subclasses may override this routine to provide
562 /// different behavior.
563 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
564 SourceRange Range,
565 NamespaceDecl *NS);
566
567 /// \brief Build a new nested-name-specifier given the prefix and the
568 /// type named in the next step in the nested-name-specifier.
569 ///
570 /// By default, performs semantic analysis when building the new
571 /// nested-name-specifier. Subclasses may override this routine to provide
572 /// different behavior.
573 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
574 SourceRange Range,
575 bool TemplateKW,
576 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000577
578 /// \brief Build a new template name given a nested name specifier, a flag
579 /// indicating whether the "template" keyword was provided, and the template
580 /// that the template name refers to.
581 ///
582 /// By default, builds the new template name directly. Subclasses may override
583 /// this routine to provide different behavior.
584 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
585 bool TemplateKW,
586 TemplateDecl *Template);
587
Douglas Gregord1067e52009-08-06 06:41:21 +0000588 /// \brief Build a new template name given a nested name specifier and the
589 /// name that is referred to as a template.
590 ///
591 /// By default, performs semantic analysis to determine whether the name can
592 /// be resolved to a specific template, then builds the appropriate kind of
593 /// template name. Subclasses may override this routine to provide different
594 /// behavior.
595 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000596 const IdentifierInfo &II,
597 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000598
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000599 /// \brief Build a new template name given a nested name specifier and the
600 /// overloaded operator name that is referred to as a template.
601 ///
602 /// By default, performs semantic analysis to determine whether the name can
603 /// be resolved to a specific template, then builds the appropriate kind of
604 /// template name. Subclasses may override this routine to provide different
605 /// behavior.
606 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
607 OverloadedOperatorKind Operator,
608 QualType ObjectType);
609
Douglas Gregor43959a92009-08-20 07:17:43 +0000610 /// \brief Build a new compound statement.
611 ///
612 /// By default, performs semantic analysis to build the new statement.
613 /// Subclasses may override this routine to provide different behavior.
614 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
615 MultiStmtArg Statements,
616 SourceLocation RBraceLoc,
617 bool IsStmtExpr) {
618 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
619 IsStmtExpr);
620 }
621
622 /// \brief Build a new case statement.
623 ///
624 /// By default, performs semantic analysis to build the new statement.
625 /// Subclasses may override this routine to provide different behavior.
626 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
627 ExprArg LHS,
628 SourceLocation EllipsisLoc,
629 ExprArg RHS,
630 SourceLocation ColonLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000631 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregor43959a92009-08-20 07:17:43 +0000632 ColonLoc);
633 }
Mike Stump1eb44332009-09-09 15:08:12 +0000634
Douglas Gregor43959a92009-08-20 07:17:43 +0000635 /// \brief Attach the body to a new case statement.
636 ///
637 /// By default, performs semantic analysis to build the new statement.
638 /// Subclasses may override this routine to provide different behavior.
639 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
640 getSema().ActOnCaseStmtBody(S.get(), move(Body));
641 return move(S);
642 }
Mike Stump1eb44332009-09-09 15:08:12 +0000643
Douglas Gregor43959a92009-08-20 07:17:43 +0000644 /// \brief Build a new default statement.
645 ///
646 /// By default, performs semantic analysis to build the new statement.
647 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000648 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000649 SourceLocation ColonLoc,
650 StmtArg SubStmt) {
Mike Stump1eb44332009-09-09 15:08:12 +0000651 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregor43959a92009-08-20 07:17:43 +0000652 /*CurScope=*/0);
653 }
Mike Stump1eb44332009-09-09 15:08:12 +0000654
Douglas Gregor43959a92009-08-20 07:17:43 +0000655 /// \brief Build a new label statement.
656 ///
657 /// By default, performs semantic analysis to build the new statement.
658 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000659 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000660 IdentifierInfo *Id,
661 SourceLocation ColonLoc,
662 StmtArg SubStmt) {
663 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
664 }
Mike Stump1eb44332009-09-09 15:08:12 +0000665
Douglas Gregor43959a92009-08-20 07:17:43 +0000666 /// \brief Build a new "if" statement.
667 ///
668 /// By default, performs semantic analysis to build the new statement.
669 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000670 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000671 VarDecl *CondVar, StmtArg Then,
672 SourceLocation ElseLoc, StmtArg Else) {
673 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
674 move(Then), ElseLoc, move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +0000675 }
Mike Stump1eb44332009-09-09 15:08:12 +0000676
Douglas Gregor43959a92009-08-20 07:17:43 +0000677 /// \brief Start building a new switch statement.
678 ///
679 /// By default, performs semantic analysis to build the new statement.
680 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000681 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
682 VarDecl *CondVar) {
683 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregor43959a92009-08-20 07:17:43 +0000684 }
Mike Stump1eb44332009-09-09 15:08:12 +0000685
Douglas Gregor43959a92009-08-20 07:17:43 +0000686 /// \brief Attach the body to the switch statement.
687 ///
688 /// By default, performs semantic analysis to build the new statement.
689 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000690 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000691 StmtArg Switch, StmtArg Body) {
692 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
693 move(Body));
694 }
695
696 /// \brief Build a new while statement.
697 ///
698 /// By default, performs semantic analysis to build the new statement.
699 /// Subclasses may override this routine to provide different behavior.
700 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
701 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000702 VarDecl *CondVar,
Douglas Gregor43959a92009-08-20 07:17:43 +0000703 StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000704 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
705 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000706 }
Mike Stump1eb44332009-09-09 15:08:12 +0000707
Douglas Gregor43959a92009-08-20 07:17:43 +0000708 /// \brief Build a new do-while statement.
709 ///
710 /// By default, performs semantic analysis to build the new statement.
711 /// Subclasses may override this routine to provide different behavior.
712 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
713 SourceLocation WhileLoc,
714 SourceLocation LParenLoc,
715 ExprArg Cond,
716 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000717 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000718 move(Cond), RParenLoc);
719 }
720
721 /// \brief Build a new for statement.
722 ///
723 /// By default, performs semantic analysis to build the new statement.
724 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000725 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000726 SourceLocation LParenLoc,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000727 StmtArg Init, Sema::FullExprArg Cond,
728 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000729 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000730 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
731 DeclPtrTy::make(CondVar),
732 Inc, RParenLoc, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000733 }
Mike Stump1eb44332009-09-09 15:08:12 +0000734
Douglas Gregor43959a92009-08-20 07:17:43 +0000735 /// \brief Build a new goto statement.
736 ///
737 /// By default, performs semantic analysis to build the new statement.
738 /// Subclasses may override this routine to provide different behavior.
739 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
740 SourceLocation LabelLoc,
741 LabelStmt *Label) {
742 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
743 }
744
745 /// \brief Build a new indirect goto statement.
746 ///
747 /// By default, performs semantic analysis to build the new statement.
748 /// Subclasses may override this routine to provide different behavior.
749 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
750 SourceLocation StarLoc,
751 ExprArg Target) {
752 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
753 }
Mike Stump1eb44332009-09-09 15:08:12 +0000754
Douglas Gregor43959a92009-08-20 07:17:43 +0000755 /// \brief Build a new return statement.
756 ///
757 /// By default, performs semantic analysis to build the new statement.
758 /// Subclasses may override this routine to provide different behavior.
759 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
760 ExprArg Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000761
Douglas Gregor43959a92009-08-20 07:17:43 +0000762 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
763 }
Mike Stump1eb44332009-09-09 15:08:12 +0000764
Douglas Gregor43959a92009-08-20 07:17:43 +0000765 /// \brief Build a new declaration statement.
766 ///
767 /// By default, performs semantic analysis to build the new statement.
768 /// Subclasses may override this routine to provide different behavior.
769 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000770 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000771 SourceLocation EndLoc) {
772 return getSema().Owned(
773 new (getSema().Context) DeclStmt(
774 DeclGroupRef::Create(getSema().Context,
775 Decls, NumDecls),
776 StartLoc, EndLoc));
777 }
Mike Stump1eb44332009-09-09 15:08:12 +0000778
Anders Carlsson703e3942010-01-24 05:50:09 +0000779 /// \brief Build a new inline asm statement.
780 ///
781 /// By default, performs semantic analysis to build the new statement.
782 /// Subclasses may override this routine to provide different behavior.
783 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
784 bool IsSimple,
785 bool IsVolatile,
786 unsigned NumOutputs,
787 unsigned NumInputs,
788 const std::string *Names,
789 MultiExprArg Constraints,
790 MultiExprArg Exprs,
791 ExprArg AsmString,
792 MultiExprArg Clobbers,
793 SourceLocation RParenLoc,
794 bool MSAsm) {
795 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
796 NumInputs, Names, move(Constraints),
797 move(Exprs), move(AsmString), move(Clobbers),
798 RParenLoc, MSAsm);
799 }
800
Douglas Gregor43959a92009-08-20 07:17:43 +0000801 /// \brief Build a new C++ exception declaration.
802 ///
803 /// By default, performs semantic analysis to build the new decaration.
804 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000805 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000806 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000807 IdentifierInfo *Name,
808 SourceLocation Loc,
809 SourceRange TypeRange) {
Mike Stump1eb44332009-09-09 15:08:12 +0000810 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000811 TypeRange);
812 }
813
814 /// \brief Build a new C++ catch statement.
815 ///
816 /// By default, performs semantic analysis to build the new statement.
817 /// Subclasses may override this routine to provide different behavior.
818 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
819 VarDecl *ExceptionDecl,
820 StmtArg Handler) {
821 return getSema().Owned(
Mike Stump1eb44332009-09-09 15:08:12 +0000822 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregor43959a92009-08-20 07:17:43 +0000823 Handler.takeAs<Stmt>()));
824 }
Mike Stump1eb44332009-09-09 15:08:12 +0000825
Douglas Gregor43959a92009-08-20 07:17:43 +0000826 /// \brief Build a new C++ try statement.
827 ///
828 /// By default, performs semantic analysis to build the new statement.
829 /// Subclasses may override this routine to provide different behavior.
830 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
831 StmtArg TryBlock,
832 MultiStmtArg Handlers) {
833 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
834 }
Mike Stump1eb44332009-09-09 15:08:12 +0000835
Douglas Gregorb98b1992009-08-11 05:31:07 +0000836 /// \brief Build a new expression that references a declaration.
837 ///
838 /// By default, performs semantic analysis to build the new expression.
839 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +0000840 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
841 LookupResult &R,
842 bool RequiresADL) {
843 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
844 }
845
846
847 /// \brief Build a new expression that references a declaration.
848 ///
849 /// By default, performs semantic analysis to build the new expression.
850 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora2813ce2009-10-23 18:54:35 +0000851 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
852 SourceRange QualifierRange,
John McCalldbd872f2009-12-08 09:08:17 +0000853 ValueDecl *VD, SourceLocation Loc,
854 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +0000855 CXXScopeSpec SS;
856 SS.setScopeRep(Qualifier);
857 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +0000858
859 // FIXME: loses template args.
860
861 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000862 }
Mike Stump1eb44332009-09-09 15:08:12 +0000863
Douglas Gregorb98b1992009-08-11 05:31:07 +0000864 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +0000865 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000866 /// By default, performs semantic analysis to build the new expression.
867 /// Subclasses may override this routine to provide different behavior.
868 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
869 SourceLocation RParen) {
870 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
871 }
872
Douglas Gregora71d8192009-09-04 17:36:40 +0000873 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000874 ///
Douglas Gregora71d8192009-09-04 17:36:40 +0000875 /// By default, performs semantic analysis to build the new expression.
876 /// Subclasses may override this routine to provide different behavior.
877 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
878 SourceLocation OperatorLoc,
879 bool isArrow,
880 SourceLocation DestroyedTypeLoc,
881 QualType DestroyedType,
882 NestedNameSpecifier *Qualifier,
883 SourceRange QualifierRange) {
884 CXXScopeSpec SS;
885 if (Qualifier) {
886 SS.setRange(QualifierRange);
887 SS.setScopeRep(Qualifier);
888 }
889
John McCallaa81e162009-12-01 22:10:20 +0000890 QualType BaseType = ((Expr*) Base.get())->getType();
891
Mike Stump1eb44332009-09-09 15:08:12 +0000892 DeclarationName Name
Douglas Gregora71d8192009-09-04 17:36:40 +0000893 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
894 SemaRef.Context.getCanonicalType(DestroyedType));
Mike Stump1eb44332009-09-09 15:08:12 +0000895
John McCallaa81e162009-12-01 22:10:20 +0000896 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
897 OperatorLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +0000898 SS, /*FIXME: FirstQualifier*/ 0,
899 Name, DestroyedTypeLoc,
900 /*TemplateArgs*/ 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000901 }
902
Douglas Gregorb98b1992009-08-11 05:31:07 +0000903 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000904 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000905 /// By default, performs semantic analysis to build the new expression.
906 /// Subclasses may override this routine to provide different behavior.
907 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
908 UnaryOperator::Opcode Opc,
909 ExprArg SubExpr) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +0000910 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +0000911 }
Mike Stump1eb44332009-09-09 15:08:12 +0000912
Douglas Gregorb98b1992009-08-11 05:31:07 +0000913 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +0000914 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000915 /// By default, performs semantic analysis to build the new expression.
916 /// Subclasses may override this routine to provide different behavior.
John McCalla93c9342009-12-07 02:54:59 +0000917 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +0000918 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000919 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +0000920 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000921 }
922
Mike Stump1eb44332009-09-09 15:08:12 +0000923 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +0000924 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +0000925 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000926 /// By default, performs semantic analysis to build the new expression.
927 /// Subclasses may override this routine to provide different behavior.
928 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
929 bool isSizeOf, SourceRange R) {
Mike Stump1eb44332009-09-09 15:08:12 +0000930 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +0000931 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
932 OpLoc, isSizeOf, R);
933 if (Result.isInvalid())
934 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +0000935
Douglas Gregorb98b1992009-08-11 05:31:07 +0000936 SubExpr.release();
937 return move(Result);
938 }
Mike Stump1eb44332009-09-09 15:08:12 +0000939
Douglas Gregorb98b1992009-08-11 05:31:07 +0000940 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000941 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000942 /// By default, performs semantic analysis to build the new expression.
943 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000944 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000945 SourceLocation LBracketLoc,
946 ExprArg RHS,
947 SourceLocation RBracketLoc) {
948 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump1eb44332009-09-09 15:08:12 +0000949 LBracketLoc, move(RHS),
Douglas Gregorb98b1992009-08-11 05:31:07 +0000950 RBracketLoc);
951 }
952
953 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000954 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000955 /// By default, performs semantic analysis to build the new expression.
956 /// Subclasses may override this routine to provide different behavior.
957 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
958 MultiExprArg Args,
959 SourceLocation *CommaLocs,
960 SourceLocation RParenLoc) {
961 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
962 move(Args), CommaLocs, RParenLoc);
963 }
964
965 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000966 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000967 /// By default, performs semantic analysis to build the new expression.
968 /// Subclasses may override this routine to provide different behavior.
969 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +0000970 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000971 NestedNameSpecifier *Qualifier,
972 SourceRange QualifierRange,
973 SourceLocation MemberLoc,
Eli Friedmanf595cc42009-12-04 06:40:45 +0000974 ValueDecl *Member,
John McCalld5532b62009-11-23 01:53:49 +0000975 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +0000976 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +0000977 if (!Member->getDeclName()) {
978 // We have a reference to an unnamed field.
979 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +0000980
Douglas Gregor83a56c42009-12-24 20:02:50 +0000981 Expr *BaseExpr = Base.takeAs<Expr>();
982 if (getSema().PerformObjectMemberConversion(BaseExpr, Member))
983 return getSema().ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +0000984
Mike Stump1eb44332009-09-09 15:08:12 +0000985 MemberExpr *ME =
Douglas Gregor83a56c42009-12-24 20:02:50 +0000986 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlssond8b285f2009-09-01 04:26:58 +0000987 Member, MemberLoc,
988 cast<FieldDecl>(Member)->getType());
989 return getSema().Owned(ME);
990 }
Mike Stump1eb44332009-09-09 15:08:12 +0000991
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000992 CXXScopeSpec SS;
993 if (Qualifier) {
994 SS.setRange(QualifierRange);
995 SS.setScopeRep(Qualifier);
996 }
997
John McCallaa81e162009-12-01 22:10:20 +0000998 QualType BaseType = ((Expr*) Base.get())->getType();
999
John McCallc2233c52010-01-15 08:34:02 +00001000 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1001 Sema::LookupMemberName);
1002 R.addDecl(Member);
1003 R.resolveKind();
1004
John McCallaa81e162009-12-01 22:10:20 +00001005 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1006 OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001007 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001008 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001009 }
Mike Stump1eb44332009-09-09 15:08:12 +00001010
Douglas Gregorb98b1992009-08-11 05:31:07 +00001011 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001012 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001013 /// By default, performs semantic analysis to build the new expression.
1014 /// Subclasses may override this routine to provide different behavior.
1015 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1016 BinaryOperator::Opcode Opc,
1017 ExprArg LHS, ExprArg RHS) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001018 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1019 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregorb98b1992009-08-11 05:31:07 +00001020 }
1021
1022 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001023 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001024 /// By default, performs semantic analysis to build the new expression.
1025 /// Subclasses may override this routine to provide different behavior.
1026 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1027 SourceLocation QuestionLoc,
1028 ExprArg LHS,
1029 SourceLocation ColonLoc,
1030 ExprArg RHS) {
Mike Stump1eb44332009-09-09 15:08:12 +00001031 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001032 move(LHS), move(RHS));
1033 }
1034
Douglas Gregorb98b1992009-08-11 05:31:07 +00001035 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001036 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001037 /// By default, performs semantic analysis to build the new expression.
1038 /// Subclasses may override this routine to provide different behavior.
John McCall9d125032010-01-15 18:39:57 +00001039 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1040 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001041 SourceLocation RParenLoc,
1042 ExprArg SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001043 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1044 move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001045 }
Mike Stump1eb44332009-09-09 15:08:12 +00001046
Douglas Gregorb98b1992009-08-11 05:31:07 +00001047 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001048 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001049 /// By default, performs semantic analysis to build the new expression.
1050 /// Subclasses may override this routine to provide different behavior.
1051 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001052 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001053 SourceLocation RParenLoc,
1054 ExprArg Init) {
John McCall42f56b52010-01-18 19:35:47 +00001055 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1056 move(Init));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001057 }
Mike Stump1eb44332009-09-09 15:08:12 +00001058
Douglas Gregorb98b1992009-08-11 05:31:07 +00001059 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001060 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001061 /// By default, performs semantic analysis to build the new expression.
1062 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001063 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001064 SourceLocation OpLoc,
1065 SourceLocation AccessorLoc,
1066 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001067
John McCall129e2df2009-11-30 22:42:35 +00001068 CXXScopeSpec SS;
John McCallaa81e162009-12-01 22:10:20 +00001069 QualType BaseType = ((Expr*) Base.get())->getType();
1070 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001071 OpLoc, /*IsArrow*/ false,
1072 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor2d1c2142009-11-03 19:44:04 +00001073 DeclarationName(&Accessor),
John McCall129e2df2009-11-30 22:42:35 +00001074 AccessorLoc,
1075 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001076 }
Mike Stump1eb44332009-09-09 15:08:12 +00001077
Douglas Gregorb98b1992009-08-11 05:31:07 +00001078 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001079 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001080 /// By default, performs semantic analysis to build the new expression.
1081 /// Subclasses may override this routine to provide different behavior.
1082 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1083 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001084 SourceLocation RBraceLoc,
1085 QualType ResultTy) {
1086 OwningExprResult Result
1087 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1088 if (Result.isInvalid() || ResultTy->isDependentType())
1089 return move(Result);
1090
1091 // Patch in the result type we were given, which may have been computed
1092 // when the initial InitListExpr was built.
1093 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1094 ILE->setType(ResultTy);
1095 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001096 }
Mike Stump1eb44332009-09-09 15:08:12 +00001097
Douglas Gregorb98b1992009-08-11 05:31:07 +00001098 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001099 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001100 /// By default, performs semantic analysis to build the new expression.
1101 /// Subclasses may override this routine to provide different behavior.
1102 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1103 MultiExprArg ArrayExprs,
1104 SourceLocation EqualOrColonLoc,
1105 bool GNUSyntax,
1106 ExprArg Init) {
1107 OwningExprResult Result
1108 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1109 move(Init));
1110 if (Result.isInvalid())
1111 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001112
Douglas Gregorb98b1992009-08-11 05:31:07 +00001113 ArrayExprs.release();
1114 return move(Result);
1115 }
Mike Stump1eb44332009-09-09 15:08:12 +00001116
Douglas Gregorb98b1992009-08-11 05:31:07 +00001117 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001118 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001119 /// By default, builds the implicit value initialization without performing
1120 /// any semantic analysis. Subclasses may override this routine to provide
1121 /// different behavior.
1122 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1123 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1124 }
Mike Stump1eb44332009-09-09 15:08:12 +00001125
Douglas Gregorb98b1992009-08-11 05:31:07 +00001126 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001127 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001128 /// By default, performs semantic analysis to build the new expression.
1129 /// Subclasses may override this routine to provide different behavior.
1130 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1131 QualType T, SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001132 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001133 RParenLoc);
1134 }
1135
1136 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001137 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001138 /// By default, performs semantic analysis to build the new expression.
1139 /// Subclasses may override this routine to provide different behavior.
1140 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1141 MultiExprArg SubExprs,
1142 SourceLocation RParenLoc) {
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001143 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1144 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001145 }
Mike Stump1eb44332009-09-09 15:08:12 +00001146
Douglas Gregorb98b1992009-08-11 05:31:07 +00001147 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001148 ///
1149 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001150 /// rather than attempting to map the label statement itself.
1151 /// Subclasses may override this routine to provide different behavior.
1152 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1153 SourceLocation LabelLoc,
1154 LabelStmt *Label) {
1155 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1156 }
Mike Stump1eb44332009-09-09 15:08:12 +00001157
Douglas Gregorb98b1992009-08-11 05:31:07 +00001158 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001159 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001160 /// By default, performs semantic analysis to build the new expression.
1161 /// Subclasses may override this routine to provide different behavior.
1162 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1163 StmtArg SubStmt,
1164 SourceLocation RParenLoc) {
1165 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1166 }
Mike Stump1eb44332009-09-09 15:08:12 +00001167
Douglas Gregorb98b1992009-08-11 05:31:07 +00001168 /// \brief Build a new __builtin_types_compatible_p expression.
1169 ///
1170 /// By default, performs semantic analysis to build the new expression.
1171 /// Subclasses may override this routine to provide different behavior.
1172 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1173 QualType T1, QualType T2,
1174 SourceLocation RParenLoc) {
1175 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1176 T1.getAsOpaquePtr(),
1177 T2.getAsOpaquePtr(),
1178 RParenLoc);
1179 }
Mike Stump1eb44332009-09-09 15:08:12 +00001180
Douglas Gregorb98b1992009-08-11 05:31:07 +00001181 /// \brief Build a new __builtin_choose_expr expression.
1182 ///
1183 /// By default, performs semantic analysis to build the new expression.
1184 /// Subclasses may override this routine to provide different behavior.
1185 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1186 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1187 SourceLocation RParenLoc) {
1188 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1189 move(Cond), move(LHS), move(RHS),
1190 RParenLoc);
1191 }
Mike Stump1eb44332009-09-09 15:08:12 +00001192
Douglas Gregorb98b1992009-08-11 05:31:07 +00001193 /// \brief Build a new overloaded operator call expression.
1194 ///
1195 /// By default, performs semantic analysis to build the new expression.
1196 /// The semantic analysis provides the behavior of template instantiation,
1197 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001198 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001199 /// argument-dependent lookup, etc. Subclasses may override this routine to
1200 /// provide different behavior.
1201 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1202 SourceLocation OpLoc,
1203 ExprArg Callee,
1204 ExprArg First,
1205 ExprArg Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001206
1207 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001208 /// reinterpret_cast.
1209 ///
1210 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001211 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001212 /// Subclasses may override this routine to provide different behavior.
1213 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1214 Stmt::StmtClass Class,
1215 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001216 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001217 SourceLocation RAngleLoc,
1218 SourceLocation LParenLoc,
1219 ExprArg SubExpr,
1220 SourceLocation RParenLoc) {
1221 switch (Class) {
1222 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001223 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001224 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001225 move(SubExpr), RParenLoc);
1226
1227 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001228 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001229 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001230 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001231
Douglas Gregorb98b1992009-08-11 05:31:07 +00001232 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001233 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001234 RAngleLoc, LParenLoc,
1235 move(SubExpr),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001236 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001237
Douglas Gregorb98b1992009-08-11 05:31:07 +00001238 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001239 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001240 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001241 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001242
Douglas Gregorb98b1992009-08-11 05:31:07 +00001243 default:
1244 assert(false && "Invalid C++ named cast");
1245 break;
1246 }
Mike Stump1eb44332009-09-09 15:08:12 +00001247
Douglas Gregorb98b1992009-08-11 05:31:07 +00001248 return getSema().ExprError();
1249 }
Mike Stump1eb44332009-09-09 15:08:12 +00001250
Douglas Gregorb98b1992009-08-11 05:31:07 +00001251 /// \brief Build a new C++ static_cast expression.
1252 ///
1253 /// By default, performs semantic analysis to build the new expression.
1254 /// Subclasses may override this routine to provide different behavior.
1255 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1256 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001257 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001258 SourceLocation RAngleLoc,
1259 SourceLocation LParenLoc,
1260 ExprArg SubExpr,
1261 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001262 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1263 TInfo, move(SubExpr),
1264 SourceRange(LAngleLoc, RAngleLoc),
1265 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001266 }
1267
1268 /// \brief Build a new C++ dynamic_cast expression.
1269 ///
1270 /// By default, performs semantic analysis to build the new expression.
1271 /// Subclasses may override this routine to provide different behavior.
1272 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1273 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001274 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001275 SourceLocation RAngleLoc,
1276 SourceLocation LParenLoc,
1277 ExprArg SubExpr,
1278 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001279 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1280 TInfo, move(SubExpr),
1281 SourceRange(LAngleLoc, RAngleLoc),
1282 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001283 }
1284
1285 /// \brief Build a new C++ reinterpret_cast expression.
1286 ///
1287 /// By default, performs semantic analysis to build the new expression.
1288 /// Subclasses may override this routine to provide different behavior.
1289 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1290 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001291 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001292 SourceLocation RAngleLoc,
1293 SourceLocation LParenLoc,
1294 ExprArg SubExpr,
1295 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001296 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1297 TInfo, move(SubExpr),
1298 SourceRange(LAngleLoc, RAngleLoc),
1299 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001300 }
1301
1302 /// \brief Build a new C++ const_cast expression.
1303 ///
1304 /// By default, performs semantic analysis to build the new expression.
1305 /// Subclasses may override this routine to provide different behavior.
1306 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1307 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001308 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001309 SourceLocation RAngleLoc,
1310 SourceLocation LParenLoc,
1311 ExprArg SubExpr,
1312 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001313 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1314 TInfo, move(SubExpr),
1315 SourceRange(LAngleLoc, RAngleLoc),
1316 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001317 }
Mike Stump1eb44332009-09-09 15:08:12 +00001318
Douglas Gregorb98b1992009-08-11 05:31:07 +00001319 /// \brief Build a new C++ functional-style cast expression.
1320 ///
1321 /// By default, performs semantic analysis to build the new expression.
1322 /// Subclasses may override this routine to provide different behavior.
1323 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001324 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001325 SourceLocation LParenLoc,
1326 ExprArg SubExpr,
1327 SourceLocation RParenLoc) {
Chris Lattner88650c32009-08-24 05:19:01 +00001328 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001329 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001330 TInfo->getType().getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001331 LParenLoc,
Chris Lattner88650c32009-08-24 05:19:01 +00001332 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump1eb44332009-09-09 15:08:12 +00001333 /*CommaLocs=*/0,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001334 RParenLoc);
1335 }
Mike Stump1eb44332009-09-09 15:08:12 +00001336
Douglas Gregorb98b1992009-08-11 05:31:07 +00001337 /// \brief Build a new C++ typeid(type) expression.
1338 ///
1339 /// By default, performs semantic analysis to build the new expression.
1340 /// Subclasses may override this routine to provide different behavior.
1341 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1342 SourceLocation LParenLoc,
1343 QualType T,
1344 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001345 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001346 T.getAsOpaquePtr(), RParenLoc);
1347 }
Mike Stump1eb44332009-09-09 15:08:12 +00001348
Douglas Gregorb98b1992009-08-11 05:31:07 +00001349 /// \brief Build a new C++ typeid(expr) expression.
1350 ///
1351 /// By default, performs semantic analysis to build the new expression.
1352 /// Subclasses may override this routine to provide different behavior.
1353 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1354 SourceLocation LParenLoc,
1355 ExprArg Operand,
1356 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001357 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001358 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1359 RParenLoc);
1360 if (Result.isInvalid())
1361 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001362
Douglas Gregorb98b1992009-08-11 05:31:07 +00001363 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1364 return move(Result);
Mike Stump1eb44332009-09-09 15:08:12 +00001365 }
1366
Douglas Gregorb98b1992009-08-11 05:31:07 +00001367 /// \brief Build a new C++ "this" expression.
1368 ///
1369 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001370 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001371 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001372 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001373 QualType ThisType,
1374 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001375 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001376 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1377 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001378 }
1379
1380 /// \brief Build a new C++ throw expression.
1381 ///
1382 /// By default, performs semantic analysis to build the new expression.
1383 /// Subclasses may override this routine to provide different behavior.
1384 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1385 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1386 }
1387
1388 /// \brief Build a new C++ default-argument expression.
1389 ///
1390 /// By default, builds a new default-argument expression, which does not
1391 /// require any semantic analysis. Subclasses may override this routine to
1392 /// provide different behavior.
Douglas Gregor036aed12009-12-23 23:03:06 +00001393 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1394 ParmVarDecl *Param) {
1395 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1396 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001397 }
1398
1399 /// \brief Build a new C++ zero-initialization expression.
1400 ///
1401 /// By default, performs semantic analysis to build the new expression.
1402 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001403 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001404 SourceLocation LParenLoc,
1405 QualType T,
1406 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001407 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1408 T.getAsOpaquePtr(), LParenLoc,
1409 MultiExprArg(getSema(), 0, 0),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001410 0, RParenLoc);
1411 }
Mike Stump1eb44332009-09-09 15:08:12 +00001412
Douglas Gregorb98b1992009-08-11 05:31:07 +00001413 /// \brief Build a new C++ "new" expression.
1414 ///
1415 /// By default, performs semantic analysis to build the new expression.
1416 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001417 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001418 bool UseGlobal,
1419 SourceLocation PlacementLParen,
1420 MultiExprArg PlacementArgs,
1421 SourceLocation PlacementRParen,
Mike Stump1eb44332009-09-09 15:08:12 +00001422 bool ParenTypeId,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001423 QualType AllocType,
1424 SourceLocation TypeLoc,
1425 SourceRange TypeRange,
1426 ExprArg ArraySize,
1427 SourceLocation ConstructorLParen,
1428 MultiExprArg ConstructorArgs,
1429 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001430 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001431 PlacementLParen,
1432 move(PlacementArgs),
1433 PlacementRParen,
1434 ParenTypeId,
1435 AllocType,
1436 TypeLoc,
1437 TypeRange,
1438 move(ArraySize),
1439 ConstructorLParen,
1440 move(ConstructorArgs),
1441 ConstructorRParen);
1442 }
Mike Stump1eb44332009-09-09 15:08:12 +00001443
Douglas Gregorb98b1992009-08-11 05:31:07 +00001444 /// \brief Build a new C++ "delete" expression.
1445 ///
1446 /// By default, performs semantic analysis to build the new expression.
1447 /// Subclasses may override this routine to provide different behavior.
1448 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1449 bool IsGlobalDelete,
1450 bool IsArrayForm,
1451 ExprArg Operand) {
1452 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1453 move(Operand));
1454 }
Mike Stump1eb44332009-09-09 15:08:12 +00001455
Douglas Gregorb98b1992009-08-11 05:31:07 +00001456 /// \brief Build a new unary type trait expression.
1457 ///
1458 /// By default, performs semantic analysis to build the new expression.
1459 /// Subclasses may override this routine to provide different behavior.
1460 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1461 SourceLocation StartLoc,
1462 SourceLocation LParenLoc,
1463 QualType T,
1464 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001465 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001466 T.getAsOpaquePtr(), RParenLoc);
1467 }
1468
Mike Stump1eb44332009-09-09 15:08:12 +00001469 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001470 /// expression.
1471 ///
1472 /// By default, performs semantic analysis to build the new expression.
1473 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001474 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001475 SourceRange QualifierRange,
1476 DeclarationName Name,
1477 SourceLocation Location,
John McCallf7a1a742009-11-24 19:00:30 +00001478 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001479 CXXScopeSpec SS;
1480 SS.setRange(QualifierRange);
1481 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001482
1483 if (TemplateArgs)
1484 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1485 *TemplateArgs);
1486
1487 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001488 }
1489
1490 /// \brief Build a new template-id expression.
1491 ///
1492 /// By default, performs semantic analysis to build the new expression.
1493 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001494 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1495 LookupResult &R,
1496 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001497 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001498 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001499 }
1500
1501 /// \brief Build a new object-construction expression.
1502 ///
1503 /// By default, performs semantic analysis to build the new expression.
1504 /// Subclasses may override this routine to provide different behavior.
1505 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001506 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 CXXConstructorDecl *Constructor,
1508 bool IsElidable,
1509 MultiExprArg Args) {
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001510 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1511 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1512 ConvertedArgs))
1513 return getSema().ExprError();
1514
1515 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1516 move_arg(ConvertedArgs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001517 }
1518
1519 /// \brief Build a new object-construction expression.
1520 ///
1521 /// By default, performs semantic analysis to build the new expression.
1522 /// Subclasses may override this routine to provide different behavior.
1523 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1524 QualType T,
1525 SourceLocation LParenLoc,
1526 MultiExprArg Args,
1527 SourceLocation *Commas,
1528 SourceLocation RParenLoc) {
1529 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1530 T.getAsOpaquePtr(),
1531 LParenLoc,
1532 move(Args),
1533 Commas,
1534 RParenLoc);
1535 }
1536
1537 /// \brief Build a new object-construction expression.
1538 ///
1539 /// By default, performs semantic analysis to build the new expression.
1540 /// Subclasses may override this routine to provide different behavior.
1541 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1542 QualType T,
1543 SourceLocation LParenLoc,
1544 MultiExprArg Args,
1545 SourceLocation *Commas,
1546 SourceLocation RParenLoc) {
1547 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1548 /*FIXME*/LParenLoc),
1549 T.getAsOpaquePtr(),
1550 LParenLoc,
1551 move(Args),
1552 Commas,
1553 RParenLoc);
1554 }
Mike Stump1eb44332009-09-09 15:08:12 +00001555
Douglas Gregorb98b1992009-08-11 05:31:07 +00001556 /// \brief Build a new member reference expression.
1557 ///
1558 /// By default, performs semantic analysis to build the new expression.
1559 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001560 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001561 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001562 bool IsArrow,
1563 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001564 NestedNameSpecifier *Qualifier,
1565 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001566 NamedDecl *FirstQualifierInScope,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 DeclarationName Name,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001568 SourceLocation MemberLoc,
John McCall129e2df2009-11-30 22:42:35 +00001569 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001571 SS.setRange(QualifierRange);
1572 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001573
John McCallaa81e162009-12-01 22:10:20 +00001574 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1575 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001576 SS, FirstQualifierInScope,
1577 Name, MemberLoc, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 }
1579
John McCall129e2df2009-11-30 22:42:35 +00001580 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001581 ///
1582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
John McCall129e2df2009-11-30 22:42:35 +00001584 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001585 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001586 SourceLocation OperatorLoc,
1587 bool IsArrow,
1588 NestedNameSpecifier *Qualifier,
1589 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001590 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001591 LookupResult &R,
1592 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001593 CXXScopeSpec SS;
1594 SS.setRange(QualifierRange);
1595 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001596
John McCallaa81e162009-12-01 22:10:20 +00001597 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1598 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001599 SS, FirstQualifierInScope,
1600 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001601 }
Mike Stump1eb44332009-09-09 15:08:12 +00001602
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 /// \brief Build a new Objective-C @encode expression.
1604 ///
1605 /// By default, performs semantic analysis to build the new expression.
1606 /// Subclasses may override this routine to provide different behavior.
1607 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1608 QualType T,
1609 SourceLocation RParenLoc) {
1610 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1611 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001612 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001613
1614 /// \brief Build a new Objective-C protocol expression.
1615 ///
1616 /// By default, performs semantic analysis to build the new expression.
1617 /// Subclasses may override this routine to provide different behavior.
1618 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1619 SourceLocation AtLoc,
1620 SourceLocation ProtoLoc,
1621 SourceLocation LParenLoc,
1622 SourceLocation RParenLoc) {
1623 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1624 Protocol->getIdentifier(),
1625 AtLoc,
1626 ProtoLoc,
1627 LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001628 RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001629 }
Mike Stump1eb44332009-09-09 15:08:12 +00001630
Douglas Gregorb98b1992009-08-11 05:31:07 +00001631 /// \brief Build a new shuffle vector expression.
1632 ///
1633 /// By default, performs semantic analysis to build the new expression.
1634 /// Subclasses may override this routine to provide different behavior.
1635 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1636 MultiExprArg SubExprs,
1637 SourceLocation RParenLoc) {
1638 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001639 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001640 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1641 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1642 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1643 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001644
Douglas Gregorb98b1992009-08-11 05:31:07 +00001645 // Build a reference to the __builtin_shufflevector builtin
1646 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001647 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001649 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001650 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001651
1652 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 unsigned NumSubExprs = SubExprs.size();
1654 Expr **Subs = (Expr **)SubExprs.release();
1655 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1656 Subs, NumSubExprs,
1657 Builtin->getResultType(),
1658 RParenLoc);
1659 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001660
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 // Type-check the __builtin_shufflevector expression.
1662 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1663 if (Result.isInvalid())
1664 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001665
Douglas Gregorb98b1992009-08-11 05:31:07 +00001666 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001667 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001669};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001670
Douglas Gregor43959a92009-08-20 07:17:43 +00001671template<typename Derived>
1672Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1673 if (!S)
1674 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001675
Douglas Gregor43959a92009-08-20 07:17:43 +00001676 switch (S->getStmtClass()) {
1677 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001678
Douglas Gregor43959a92009-08-20 07:17:43 +00001679 // Transform individual statement nodes
1680#define STMT(Node, Parent) \
1681 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1682#define EXPR(Node, Parent)
1683#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001684
Douglas Gregor43959a92009-08-20 07:17:43 +00001685 // Transform expressions by calling TransformExpr.
1686#define STMT(Node, Parent)
1687#define EXPR(Node, Parent) case Stmt::Node##Class:
1688#include "clang/AST/StmtNodes.def"
1689 {
1690 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1691 if (E.isInvalid())
1692 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001693
Anders Carlsson5ee56e92009-12-16 02:09:40 +00001694 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregor43959a92009-08-20 07:17:43 +00001695 }
Mike Stump1eb44332009-09-09 15:08:12 +00001696 }
1697
Douglas Gregor43959a92009-08-20 07:17:43 +00001698 return SemaRef.Owned(S->Retain());
1699}
Mike Stump1eb44332009-09-09 15:08:12 +00001700
1701
Douglas Gregor670444e2009-08-04 22:27:00 +00001702template<typename Derived>
John McCall454feb92009-12-08 09:21:05 +00001703Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 if (!E)
1705 return SemaRef.Owned(E);
1706
1707 switch (E->getStmtClass()) {
1708 case Stmt::NoStmtClass: break;
1709#define STMT(Node, Parent) case Stmt::Node##Class: break;
1710#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00001711 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001713 }
1714
Douglas Gregorb98b1992009-08-11 05:31:07 +00001715 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00001716}
1717
1718template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00001719NestedNameSpecifier *
1720TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00001721 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001722 QualType ObjectType,
1723 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00001724 if (!NNS)
1725 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001726
Douglas Gregor43959a92009-08-20 07:17:43 +00001727 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00001728 NestedNameSpecifier *Prefix = NNS->getPrefix();
1729 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00001730 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001731 ObjectType,
1732 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00001733 if (!Prefix)
1734 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001735
1736 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00001737 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00001738 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00001739 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001740 }
Mike Stump1eb44332009-09-09 15:08:12 +00001741
Douglas Gregordcee1a12009-08-06 05:28:30 +00001742 switch (NNS->getKind()) {
1743 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00001744 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00001745 "Identifier nested-name-specifier with no prefix or object type");
1746 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1747 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00001748 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001749
1750 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00001751 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00001752 ObjectType,
1753 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001754
Douglas Gregordcee1a12009-08-06 05:28:30 +00001755 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00001756 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00001757 = cast_or_null<NamespaceDecl>(
1758 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00001759 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00001760 Prefix == NNS->getPrefix() &&
1761 NS == NNS->getAsNamespace())
1762 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001763
Douglas Gregordcee1a12009-08-06 05:28:30 +00001764 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1765 }
Mike Stump1eb44332009-09-09 15:08:12 +00001766
Douglas Gregordcee1a12009-08-06 05:28:30 +00001767 case NestedNameSpecifier::Global:
1768 // There is no meaningful transformation that one could perform on the
1769 // global scope.
1770 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001771
Douglas Gregordcee1a12009-08-06 05:28:30 +00001772 case NestedNameSpecifier::TypeSpecWithTemplate:
1773 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00001774 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregordcee1a12009-08-06 05:28:30 +00001775 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregord1067e52009-08-06 06:41:21 +00001776 if (T.isNull())
1777 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001778
Douglas Gregordcee1a12009-08-06 05:28:30 +00001779 if (!getDerived().AlwaysRebuild() &&
1780 Prefix == NNS->getPrefix() &&
1781 T == QualType(NNS->getAsType(), 0))
1782 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001783
1784 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1785 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregordcee1a12009-08-06 05:28:30 +00001786 T);
1787 }
1788 }
Mike Stump1eb44332009-09-09 15:08:12 +00001789
Douglas Gregordcee1a12009-08-06 05:28:30 +00001790 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00001791 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001792}
1793
1794template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001795DeclarationName
Douglas Gregor81499bb2009-09-03 22:13:48 +00001796TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +00001797 SourceLocation Loc,
1798 QualType ObjectType) {
Douglas Gregor81499bb2009-09-03 22:13:48 +00001799 if (!Name)
1800 return Name;
1801
1802 switch (Name.getNameKind()) {
1803 case DeclarationName::Identifier:
1804 case DeclarationName::ObjCZeroArgSelector:
1805 case DeclarationName::ObjCOneArgSelector:
1806 case DeclarationName::ObjCMultiArgSelector:
1807 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00001808 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00001809 case DeclarationName::CXXUsingDirective:
1810 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001811
Douglas Gregor81499bb2009-09-03 22:13:48 +00001812 case DeclarationName::CXXConstructorName:
1813 case DeclarationName::CXXDestructorName:
1814 case DeclarationName::CXXConversionFunctionName: {
1815 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregordd62b152009-10-19 22:04:39 +00001816 QualType T;
1817 if (!ObjectType.isNull() &&
1818 isa<TemplateSpecializationType>(Name.getCXXNameType())) {
1819 TemplateSpecializationType *SpecType
1820 = cast<TemplateSpecializationType>(Name.getCXXNameType());
1821 T = TransformTemplateSpecializationType(SpecType, ObjectType);
1822 } else
1823 T = getDerived().TransformType(Name.getCXXNameType());
Douglas Gregor81499bb2009-09-03 22:13:48 +00001824 if (T.isNull())
1825 return DeclarationName();
Mike Stump1eb44332009-09-09 15:08:12 +00001826
Douglas Gregor81499bb2009-09-03 22:13:48 +00001827 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump1eb44332009-09-09 15:08:12 +00001828 Name.getNameKind(),
Douglas Gregor81499bb2009-09-03 22:13:48 +00001829 SemaRef.Context.getCanonicalType(T));
Douglas Gregor81499bb2009-09-03 22:13:48 +00001830 }
Mike Stump1eb44332009-09-09 15:08:12 +00001831 }
1832
Douglas Gregor81499bb2009-09-03 22:13:48 +00001833 return DeclarationName();
1834}
1835
1836template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001837TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001838TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1839 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00001840 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001841 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00001842 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1843 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1844 if (!NNS)
1845 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001846
Douglas Gregord1067e52009-08-06 06:41:21 +00001847 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001848 TemplateDecl *TransTemplate
Douglas Gregord1067e52009-08-06 06:41:21 +00001849 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1850 if (!TransTemplate)
1851 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001852
Douglas Gregord1067e52009-08-06 06:41:21 +00001853 if (!getDerived().AlwaysRebuild() &&
1854 NNS == QTN->getQualifier() &&
1855 TransTemplate == Template)
1856 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001857
Douglas Gregord1067e52009-08-06 06:41:21 +00001858 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1859 TransTemplate);
1860 }
Mike Stump1eb44332009-09-09 15:08:12 +00001861
John McCallf7a1a742009-11-24 19:00:30 +00001862 // These should be getting filtered out before they make it into the AST.
1863 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00001864 }
Mike Stump1eb44332009-09-09 15:08:12 +00001865
Douglas Gregord1067e52009-08-06 06:41:21 +00001866 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001867 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00001868 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1869 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001870 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00001871 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001872
Douglas Gregord1067e52009-08-06 06:41:21 +00001873 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00001874 NNS == DTN->getQualifier() &&
1875 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00001876 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001877
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001878 if (DTN->isIdentifier())
1879 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1880 ObjectType);
1881
1882 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1883 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00001884 }
Mike Stump1eb44332009-09-09 15:08:12 +00001885
Douglas Gregord1067e52009-08-06 06:41:21 +00001886 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001887 TemplateDecl *TransTemplate
Douglas Gregord1067e52009-08-06 06:41:21 +00001888 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1889 if (!TransTemplate)
1890 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001891
Douglas Gregord1067e52009-08-06 06:41:21 +00001892 if (!getDerived().AlwaysRebuild() &&
1893 TransTemplate == Template)
1894 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001895
Douglas Gregord1067e52009-08-06 06:41:21 +00001896 return TemplateName(TransTemplate);
1897 }
Mike Stump1eb44332009-09-09 15:08:12 +00001898
John McCallf7a1a742009-11-24 19:00:30 +00001899 // These should be getting filtered out before they reach the AST.
1900 assert(false && "overloaded function decl survived to here");
1901 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00001902}
1903
1904template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00001905void TreeTransform<Derived>::InventTemplateArgumentLoc(
1906 const TemplateArgument &Arg,
1907 TemplateArgumentLoc &Output) {
1908 SourceLocation Loc = getDerived().getBaseLocation();
1909 switch (Arg.getKind()) {
1910 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00001911 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00001912 break;
1913
1914 case TemplateArgument::Type:
1915 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00001916 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall833ca992009-10-29 08:12:44 +00001917
1918 break;
1919
Douglas Gregor788cd062009-11-11 01:00:40 +00001920 case TemplateArgument::Template:
1921 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1922 break;
1923
John McCall833ca992009-10-29 08:12:44 +00001924 case TemplateArgument::Expression:
1925 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1926 break;
1927
1928 case TemplateArgument::Declaration:
1929 case TemplateArgument::Integral:
1930 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00001931 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00001932 break;
1933 }
1934}
1935
1936template<typename Derived>
1937bool TreeTransform<Derived>::TransformTemplateArgument(
1938 const TemplateArgumentLoc &Input,
1939 TemplateArgumentLoc &Output) {
1940 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00001941 switch (Arg.getKind()) {
1942 case TemplateArgument::Null:
1943 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00001944 Output = Input;
1945 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00001946
Douglas Gregor670444e2009-08-04 22:27:00 +00001947 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00001948 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00001949 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00001950 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00001951
1952 DI = getDerived().TransformType(DI);
1953 if (!DI) return true;
1954
1955 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1956 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00001957 }
Mike Stump1eb44332009-09-09 15:08:12 +00001958
Douglas Gregor670444e2009-08-04 22:27:00 +00001959 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00001960 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00001961 DeclarationName Name;
1962 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1963 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00001964 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor670444e2009-08-04 22:27:00 +00001965 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00001966 if (!D) return true;
1967
John McCall828bff22009-10-29 18:45:58 +00001968 Expr *SourceExpr = Input.getSourceDeclExpression();
1969 if (SourceExpr) {
1970 EnterExpressionEvaluationContext Unevaluated(getSema(),
1971 Action::Unevaluated);
1972 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1973 if (E.isInvalid())
1974 SourceExpr = NULL;
1975 else {
1976 SourceExpr = E.takeAs<Expr>();
1977 SourceExpr->Retain();
1978 }
1979 }
1980
1981 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00001982 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00001983 }
Mike Stump1eb44332009-09-09 15:08:12 +00001984
Douglas Gregor788cd062009-11-11 01:00:40 +00001985 case TemplateArgument::Template: {
1986 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1987 TemplateName Template
1988 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1989 if (Template.isNull())
1990 return true;
1991
1992 Output = TemplateArgumentLoc(TemplateArgument(Template),
1993 Input.getTemplateQualifierRange(),
1994 Input.getTemplateNameLoc());
1995 return false;
1996 }
1997
Douglas Gregor670444e2009-08-04 22:27:00 +00001998 case TemplateArgument::Expression: {
1999 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002000 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002001 Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002002
John McCall833ca992009-10-29 08:12:44 +00002003 Expr *InputExpr = Input.getSourceExpression();
2004 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2005
2006 Sema::OwningExprResult E
2007 = getDerived().TransformExpr(InputExpr);
2008 if (E.isInvalid()) return true;
2009
2010 Expr *ETaken = E.takeAs<Expr>();
John McCall828bff22009-10-29 18:45:58 +00002011 ETaken->Retain();
John McCall833ca992009-10-29 08:12:44 +00002012 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2013 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002014 }
Mike Stump1eb44332009-09-09 15:08:12 +00002015
Douglas Gregor670444e2009-08-04 22:27:00 +00002016 case TemplateArgument::Pack: {
2017 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2018 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002019 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002020 AEnd = Arg.pack_end();
2021 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002022
John McCall833ca992009-10-29 08:12:44 +00002023 // FIXME: preserve source information here when we start
2024 // caring about parameter packs.
2025
John McCall828bff22009-10-29 18:45:58 +00002026 TemplateArgumentLoc InputArg;
2027 TemplateArgumentLoc OutputArg;
2028 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2029 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002030 return true;
2031
John McCall828bff22009-10-29 18:45:58 +00002032 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002033 }
2034 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002035 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002036 true);
John McCall828bff22009-10-29 18:45:58 +00002037 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002038 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002039 }
2040 }
Mike Stump1eb44332009-09-09 15:08:12 +00002041
Douglas Gregor670444e2009-08-04 22:27:00 +00002042 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002043 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002044}
2045
Douglas Gregor577f75a2009-08-04 16:50:30 +00002046//===----------------------------------------------------------------------===//
2047// Type transformation
2048//===----------------------------------------------------------------------===//
2049
2050template<typename Derived>
2051QualType TreeTransform<Derived>::TransformType(QualType T) {
2052 if (getDerived().AlreadyTransformed(T))
2053 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002054
John McCalla2becad2009-10-21 00:40:46 +00002055 // Temporary workaround. All of these transformations should
2056 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002057 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002058 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCalla2becad2009-10-21 00:40:46 +00002059
John McCalla93c9342009-12-07 02:54:59 +00002060 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00002061
John McCalla2becad2009-10-21 00:40:46 +00002062 if (!NewDI)
2063 return QualType();
2064
2065 return NewDI->getType();
2066}
2067
2068template<typename Derived>
John McCalla93c9342009-12-07 02:54:59 +00002069TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00002070 if (getDerived().AlreadyTransformed(DI->getType()))
2071 return DI;
2072
2073 TypeLocBuilder TLB;
2074
2075 TypeLoc TL = DI->getTypeLoc();
2076 TLB.reserve(TL.getFullDataSize());
2077
2078 QualType Result = getDerived().TransformType(TLB, TL);
2079 if (Result.isNull())
2080 return 0;
2081
John McCalla93c9342009-12-07 02:54:59 +00002082 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002083}
2084
2085template<typename Derived>
2086QualType
2087TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
2088 switch (T.getTypeLocClass()) {
2089#define ABSTRACT_TYPELOC(CLASS, PARENT)
2090#define TYPELOC(CLASS, PARENT) \
2091 case TypeLoc::CLASS: \
2092 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2093#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002094 }
Mike Stump1eb44332009-09-09 15:08:12 +00002095
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002096 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002097 return QualType();
2098}
2099
2100/// FIXME: By default, this routine adds type qualifiers only to types
2101/// that can have qualifiers, and silently suppresses those qualifiers
2102/// that are not permitted (e.g., qualifiers on reference or function
2103/// types). This is the right thing for template instantiation, but
2104/// probably not for other clients.
2105template<typename Derived>
2106QualType
2107TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
2108 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002109 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002110
2111 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2112 if (Result.isNull())
2113 return QualType();
2114
2115 // Silently suppress qualifiers if the result type can't be qualified.
2116 // FIXME: this is the right thing for template instantiation, but
2117 // probably not for other clients.
2118 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002119 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002120
John McCalla2becad2009-10-21 00:40:46 +00002121 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2122
2123 TLB.push<QualifiedTypeLoc>(Result);
2124
2125 // No location information to preserve.
2126
2127 return Result;
2128}
2129
2130template <class TyLoc> static inline
2131QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2132 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2133 NewT.setNameLoc(T.getNameLoc());
2134 return T.getType();
2135}
2136
2137// Ugly metaprogramming macros because I couldn't be bothered to make
2138// the equivalent template version work.
2139#define TransformPointerLikeType(TypeClass) do { \
2140 QualType PointeeType \
2141 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2142 if (PointeeType.isNull()) \
2143 return QualType(); \
2144 \
2145 QualType Result = TL.getType(); \
2146 if (getDerived().AlwaysRebuild() || \
2147 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall85737a72009-10-30 00:06:24 +00002148 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2149 TL.getSigilLoc()); \
John McCalla2becad2009-10-21 00:40:46 +00002150 if (Result.isNull()) \
2151 return QualType(); \
2152 } \
2153 \
2154 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2155 NewT.setSigilLoc(TL.getSigilLoc()); \
2156 \
2157 return Result; \
2158} while(0)
2159
John McCalla2becad2009-10-21 00:40:46 +00002160template<typename Derived>
2161QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
2162 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002163 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2164 NewT.setBuiltinLoc(T.getBuiltinLoc());
2165 if (T.needsExtraLocalData())
2166 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2167 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002168}
Mike Stump1eb44332009-09-09 15:08:12 +00002169
Douglas Gregor577f75a2009-08-04 16:50:30 +00002170template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002171QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
2172 ComplexTypeLoc T) {
2173 // FIXME: recurse?
2174 return TransformTypeSpecType(TLB, T);
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>::TransformPointerType(TypeLocBuilder &TLB,
2179 PointerTypeLoc TL) {
2180 TransformPointerLikeType(PointerType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002181}
Mike Stump1eb44332009-09-09 15:08:12 +00002182
2183template<typename Derived>
2184QualType
John McCalla2becad2009-10-21 00:40:46 +00002185TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
2186 BlockPointerTypeLoc TL) {
2187 TransformPointerLikeType(BlockPointerType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002188}
2189
John McCall85737a72009-10-30 00:06:24 +00002190/// Transforms a reference type. Note that somewhat paradoxically we
2191/// don't care whether the type itself is an l-value type or an r-value
2192/// type; we only care if the type was *written* as an l-value type
2193/// or an r-value type.
2194template<typename Derived>
2195QualType
2196TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
2197 ReferenceTypeLoc TL) {
2198 const ReferenceType *T = TL.getTypePtr();
2199
2200 // Note that this works with the pointee-as-written.
2201 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2202 if (PointeeType.isNull())
2203 return QualType();
2204
2205 QualType Result = TL.getType();
2206 if (getDerived().AlwaysRebuild() ||
2207 PointeeType != T->getPointeeTypeAsWritten()) {
2208 Result = getDerived().RebuildReferenceType(PointeeType,
2209 T->isSpelledAsLValue(),
2210 TL.getSigilLoc());
2211 if (Result.isNull())
2212 return QualType();
2213 }
2214
2215 // r-value references can be rebuilt as l-value references.
2216 ReferenceTypeLoc NewTL;
2217 if (isa<LValueReferenceType>(Result))
2218 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2219 else
2220 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2221 NewTL.setSigilLoc(TL.getSigilLoc());
2222
2223 return Result;
2224}
2225
Mike Stump1eb44332009-09-09 15:08:12 +00002226template<typename Derived>
2227QualType
John McCalla2becad2009-10-21 00:40:46 +00002228TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
2229 LValueReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00002230 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002231}
2232
Mike Stump1eb44332009-09-09 15:08:12 +00002233template<typename Derived>
2234QualType
John McCalla2becad2009-10-21 00:40:46 +00002235TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
2236 RValueReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00002237 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002238}
Mike Stump1eb44332009-09-09 15:08:12 +00002239
Douglas Gregor577f75a2009-08-04 16:50:30 +00002240template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002241QualType
John McCalla2becad2009-10-21 00:40:46 +00002242TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
2243 MemberPointerTypeLoc TL) {
2244 MemberPointerType *T = TL.getTypePtr();
2245
2246 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002247 if (PointeeType.isNull())
2248 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002249
John McCalla2becad2009-10-21 00:40:46 +00002250 // TODO: preserve source information for this.
2251 QualType ClassType
2252 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002253 if (ClassType.isNull())
2254 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002255
John McCalla2becad2009-10-21 00:40:46 +00002256 QualType Result = TL.getType();
2257 if (getDerived().AlwaysRebuild() ||
2258 PointeeType != T->getPointeeType() ||
2259 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002260 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2261 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002262 if (Result.isNull())
2263 return QualType();
2264 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002265
John McCalla2becad2009-10-21 00:40:46 +00002266 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2267 NewTL.setSigilLoc(TL.getSigilLoc());
2268
2269 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002270}
2271
Mike Stump1eb44332009-09-09 15:08:12 +00002272template<typename Derived>
2273QualType
John McCalla2becad2009-10-21 00:40:46 +00002274TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
2275 ConstantArrayTypeLoc TL) {
2276 ConstantArrayType *T = TL.getTypePtr();
2277 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002278 if (ElementType.isNull())
2279 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002280
John McCalla2becad2009-10-21 00:40:46 +00002281 QualType Result = TL.getType();
2282 if (getDerived().AlwaysRebuild() ||
2283 ElementType != T->getElementType()) {
2284 Result = getDerived().RebuildConstantArrayType(ElementType,
2285 T->getSizeModifier(),
2286 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002287 T->getIndexTypeCVRQualifiers(),
2288 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002289 if (Result.isNull())
2290 return QualType();
2291 }
2292
2293 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2294 NewTL.setLBracketLoc(TL.getLBracketLoc());
2295 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002296
John McCalla2becad2009-10-21 00:40:46 +00002297 Expr *Size = TL.getSizeExpr();
2298 if (Size) {
2299 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2300 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2301 }
2302 NewTL.setSizeExpr(Size);
2303
2304 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002305}
Mike Stump1eb44332009-09-09 15:08:12 +00002306
Douglas Gregor577f75a2009-08-04 16:50:30 +00002307template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002308QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002309 TypeLocBuilder &TLB,
2310 IncompleteArrayTypeLoc TL) {
2311 IncompleteArrayType *T = TL.getTypePtr();
2312 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002313 if (ElementType.isNull())
2314 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002315
John McCalla2becad2009-10-21 00:40:46 +00002316 QualType Result = TL.getType();
2317 if (getDerived().AlwaysRebuild() ||
2318 ElementType != T->getElementType()) {
2319 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002320 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002321 T->getIndexTypeCVRQualifiers(),
2322 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002323 if (Result.isNull())
2324 return QualType();
2325 }
2326
2327 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2328 NewTL.setLBracketLoc(TL.getLBracketLoc());
2329 NewTL.setRBracketLoc(TL.getRBracketLoc());
2330 NewTL.setSizeExpr(0);
2331
2332 return Result;
2333}
2334
2335template<typename Derived>
2336QualType
2337TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
2338 VariableArrayTypeLoc TL) {
2339 VariableArrayType *T = TL.getTypePtr();
2340 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2341 if (ElementType.isNull())
2342 return QualType();
2343
2344 // Array bounds are not potentially evaluated contexts
2345 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2346
2347 Sema::OwningExprResult SizeResult
2348 = getDerived().TransformExpr(T->getSizeExpr());
2349 if (SizeResult.isInvalid())
2350 return QualType();
2351
2352 Expr *Size = static_cast<Expr*>(SizeResult.get());
2353
2354 QualType Result = TL.getType();
2355 if (getDerived().AlwaysRebuild() ||
2356 ElementType != T->getElementType() ||
2357 Size != T->getSizeExpr()) {
2358 Result = getDerived().RebuildVariableArrayType(ElementType,
2359 T->getSizeModifier(),
2360 move(SizeResult),
2361 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002362 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002363 if (Result.isNull())
2364 return QualType();
2365 }
2366 else SizeResult.take();
2367
2368 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2369 NewTL.setLBracketLoc(TL.getLBracketLoc());
2370 NewTL.setRBracketLoc(TL.getRBracketLoc());
2371 NewTL.setSizeExpr(Size);
2372
2373 return Result;
2374}
2375
2376template<typename Derived>
2377QualType
2378TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
2379 DependentSizedArrayTypeLoc TL) {
2380 DependentSizedArrayType *T = TL.getTypePtr();
2381 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2382 if (ElementType.isNull())
2383 return QualType();
2384
2385 // Array bounds are not potentially evaluated contexts
2386 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2387
2388 Sema::OwningExprResult SizeResult
2389 = getDerived().TransformExpr(T->getSizeExpr());
2390 if (SizeResult.isInvalid())
2391 return QualType();
2392
2393 Expr *Size = static_cast<Expr*>(SizeResult.get());
2394
2395 QualType Result = TL.getType();
2396 if (getDerived().AlwaysRebuild() ||
2397 ElementType != T->getElementType() ||
2398 Size != T->getSizeExpr()) {
2399 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2400 T->getSizeModifier(),
2401 move(SizeResult),
2402 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002403 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002404 if (Result.isNull())
2405 return QualType();
2406 }
2407 else SizeResult.take();
2408
2409 // We might have any sort of array type now, but fortunately they
2410 // all have the same location layout.
2411 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2412 NewTL.setLBracketLoc(TL.getLBracketLoc());
2413 NewTL.setRBracketLoc(TL.getRBracketLoc());
2414 NewTL.setSizeExpr(Size);
2415
2416 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002417}
Mike Stump1eb44332009-09-09 15:08:12 +00002418
2419template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002420QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002421 TypeLocBuilder &TLB,
2422 DependentSizedExtVectorTypeLoc TL) {
2423 DependentSizedExtVectorType *T = TL.getTypePtr();
2424
2425 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002426 QualType ElementType = getDerived().TransformType(T->getElementType());
2427 if (ElementType.isNull())
2428 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002429
Douglas Gregor670444e2009-08-04 22:27:00 +00002430 // Vector sizes are not potentially evaluated contexts
2431 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2432
Douglas Gregor577f75a2009-08-04 16:50:30 +00002433 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2434 if (Size.isInvalid())
2435 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002436
John McCalla2becad2009-10-21 00:40:46 +00002437 QualType Result = TL.getType();
2438 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002439 ElementType != T->getElementType() ||
2440 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002441 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002442 move(Size),
2443 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002444 if (Result.isNull())
2445 return QualType();
2446 }
2447 else Size.take();
2448
2449 // Result might be dependent or not.
2450 if (isa<DependentSizedExtVectorType>(Result)) {
2451 DependentSizedExtVectorTypeLoc NewTL
2452 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2453 NewTL.setNameLoc(TL.getNameLoc());
2454 } else {
2455 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2456 NewTL.setNameLoc(TL.getNameLoc());
2457 }
2458
2459 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002460}
Mike Stump1eb44332009-09-09 15:08:12 +00002461
2462template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002463QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
2464 VectorTypeLoc TL) {
2465 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002466 QualType ElementType = getDerived().TransformType(T->getElementType());
2467 if (ElementType.isNull())
2468 return QualType();
2469
John McCalla2becad2009-10-21 00:40:46 +00002470 QualType Result = TL.getType();
2471 if (getDerived().AlwaysRebuild() ||
2472 ElementType != T->getElementType()) {
2473 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements());
2474 if (Result.isNull())
2475 return QualType();
2476 }
2477
2478 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2479 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002480
John McCalla2becad2009-10-21 00:40:46 +00002481 return Result;
2482}
2483
2484template<typename Derived>
2485QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
2486 ExtVectorTypeLoc TL) {
2487 VectorType *T = TL.getTypePtr();
2488 QualType ElementType = getDerived().TransformType(T->getElementType());
2489 if (ElementType.isNull())
2490 return QualType();
2491
2492 QualType Result = TL.getType();
2493 if (getDerived().AlwaysRebuild() ||
2494 ElementType != T->getElementType()) {
2495 Result = getDerived().RebuildExtVectorType(ElementType,
2496 T->getNumElements(),
2497 /*FIXME*/ SourceLocation());
2498 if (Result.isNull())
2499 return QualType();
2500 }
2501
2502 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2503 NewTL.setNameLoc(TL.getNameLoc());
2504
2505 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002506}
Mike Stump1eb44332009-09-09 15:08:12 +00002507
2508template<typename Derived>
2509QualType
John McCalla2becad2009-10-21 00:40:46 +00002510TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
2511 FunctionProtoTypeLoc TL) {
2512 FunctionProtoType *T = TL.getTypePtr();
2513 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002514 if (ResultType.isNull())
2515 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002516
John McCalla2becad2009-10-21 00:40:46 +00002517 // Transform the parameters.
Douglas Gregor577f75a2009-08-04 16:50:30 +00002518 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002519 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2520 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2521 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump1eb44332009-09-09 15:08:12 +00002522
John McCalla2becad2009-10-21 00:40:46 +00002523 QualType NewType;
2524 ParmVarDecl *NewParm;
2525
2526 if (OldParm) {
John McCalla93c9342009-12-07 02:54:59 +00002527 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCalla2becad2009-10-21 00:40:46 +00002528 assert(OldDI->getType() == T->getArgType(i));
2529
John McCalla93c9342009-12-07 02:54:59 +00002530 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCalla2becad2009-10-21 00:40:46 +00002531 if (!NewDI)
2532 return QualType();
2533
2534 if (NewDI == OldDI)
2535 NewParm = OldParm;
2536 else
2537 NewParm = ParmVarDecl::Create(SemaRef.Context,
2538 OldParm->getDeclContext(),
2539 OldParm->getLocation(),
2540 OldParm->getIdentifier(),
2541 NewDI->getType(),
2542 NewDI,
2543 OldParm->getStorageClass(),
2544 /* DefArg */ NULL);
2545 NewType = NewParm->getType();
2546
2547 // Deal with the possibility that we don't have a parameter
2548 // declaration for this parameter.
2549 } else {
2550 NewParm = 0;
2551
2552 QualType OldType = T->getArgType(i);
2553 NewType = getDerived().TransformType(OldType);
2554 if (NewType.isNull())
2555 return QualType();
2556 }
2557
2558 ParamTypes.push_back(NewType);
2559 ParamDecls.push_back(NewParm);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002560 }
Mike Stump1eb44332009-09-09 15:08:12 +00002561
John McCalla2becad2009-10-21 00:40:46 +00002562 QualType Result = TL.getType();
2563 if (getDerived().AlwaysRebuild() ||
2564 ResultType != T->getResultType() ||
2565 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2566 Result = getDerived().RebuildFunctionProtoType(ResultType,
2567 ParamTypes.data(),
2568 ParamTypes.size(),
2569 T->isVariadic(),
2570 T->getTypeQuals());
2571 if (Result.isNull())
2572 return QualType();
2573 }
Mike Stump1eb44332009-09-09 15:08:12 +00002574
John McCalla2becad2009-10-21 00:40:46 +00002575 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2576 NewTL.setLParenLoc(TL.getLParenLoc());
2577 NewTL.setRParenLoc(TL.getRParenLoc());
2578 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2579 NewTL.setArg(i, ParamDecls[i]);
2580
2581 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002582}
Mike Stump1eb44332009-09-09 15:08:12 +00002583
Douglas Gregor577f75a2009-08-04 16:50:30 +00002584template<typename Derived>
2585QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002586 TypeLocBuilder &TLB,
2587 FunctionNoProtoTypeLoc TL) {
2588 FunctionNoProtoType *T = TL.getTypePtr();
2589 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2590 if (ResultType.isNull())
2591 return QualType();
2592
2593 QualType Result = TL.getType();
2594 if (getDerived().AlwaysRebuild() ||
2595 ResultType != T->getResultType())
2596 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2597
2598 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2599 NewTL.setLParenLoc(TL.getLParenLoc());
2600 NewTL.setRParenLoc(TL.getRParenLoc());
2601
2602 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002603}
Mike Stump1eb44332009-09-09 15:08:12 +00002604
John McCalled976492009-12-04 22:46:56 +00002605template<typename Derived> QualType
2606TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
2607 UnresolvedUsingTypeLoc TL) {
2608 UnresolvedUsingType *T = TL.getTypePtr();
2609 Decl *D = getDerived().TransformDecl(T->getDecl());
2610 if (!D)
2611 return QualType();
2612
2613 QualType Result = TL.getType();
2614 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2615 Result = getDerived().RebuildUnresolvedUsingType(D);
2616 if (Result.isNull())
2617 return QualType();
2618 }
2619
2620 // We might get an arbitrary type spec type back. We should at
2621 // least always get a type spec type, though.
2622 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2623 NewTL.setNameLoc(TL.getNameLoc());
2624
2625 return Result;
2626}
2627
Douglas Gregor577f75a2009-08-04 16:50:30 +00002628template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002629QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
2630 TypedefTypeLoc TL) {
2631 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002632 TypedefDecl *Typedef
2633 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2634 if (!Typedef)
2635 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002636
John McCalla2becad2009-10-21 00:40:46 +00002637 QualType Result = TL.getType();
2638 if (getDerived().AlwaysRebuild() ||
2639 Typedef != T->getDecl()) {
2640 Result = getDerived().RebuildTypedefType(Typedef);
2641 if (Result.isNull())
2642 return QualType();
2643 }
Mike Stump1eb44332009-09-09 15:08:12 +00002644
John McCalla2becad2009-10-21 00:40:46 +00002645 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2646 NewTL.setNameLoc(TL.getNameLoc());
2647
2648 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002649}
Mike Stump1eb44332009-09-09 15:08:12 +00002650
Douglas Gregor577f75a2009-08-04 16:50:30 +00002651template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002652QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
2653 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00002654 // typeof expressions are not potentially evaluated contexts
2655 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002656
John McCallcfb708c2010-01-13 20:03:27 +00002657 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002658 if (E.isInvalid())
2659 return QualType();
2660
John McCalla2becad2009-10-21 00:40:46 +00002661 QualType Result = TL.getType();
2662 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00002663 E.get() != TL.getUnderlyingExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002664 Result = getDerived().RebuildTypeOfExprType(move(E));
2665 if (Result.isNull())
2666 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002667 }
John McCalla2becad2009-10-21 00:40:46 +00002668 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002669
John McCalla2becad2009-10-21 00:40:46 +00002670 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002671 NewTL.setTypeofLoc(TL.getTypeofLoc());
2672 NewTL.setLParenLoc(TL.getLParenLoc());
2673 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00002674
2675 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002676}
Mike Stump1eb44332009-09-09 15:08:12 +00002677
2678template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002679QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
2680 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00002681 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2682 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2683 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00002684 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002685
John McCalla2becad2009-10-21 00:40:46 +00002686 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00002687 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2688 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00002689 if (Result.isNull())
2690 return QualType();
2691 }
Mike Stump1eb44332009-09-09 15:08:12 +00002692
John McCalla2becad2009-10-21 00:40:46 +00002693 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002694 NewTL.setTypeofLoc(TL.getTypeofLoc());
2695 NewTL.setLParenLoc(TL.getLParenLoc());
2696 NewTL.setRParenLoc(TL.getRParenLoc());
2697 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00002698
2699 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002700}
Mike Stump1eb44332009-09-09 15:08:12 +00002701
2702template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002703QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
2704 DecltypeTypeLoc TL) {
2705 DecltypeType *T = TL.getTypePtr();
2706
Douglas Gregor670444e2009-08-04 22:27:00 +00002707 // decltype expressions are not potentially evaluated contexts
2708 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002709
Douglas Gregor577f75a2009-08-04 16:50:30 +00002710 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2711 if (E.isInvalid())
2712 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002713
John McCalla2becad2009-10-21 00:40:46 +00002714 QualType Result = TL.getType();
2715 if (getDerived().AlwaysRebuild() ||
2716 E.get() != T->getUnderlyingExpr()) {
2717 Result = getDerived().RebuildDecltypeType(move(E));
2718 if (Result.isNull())
2719 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002720 }
John McCalla2becad2009-10-21 00:40:46 +00002721 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002722
John McCalla2becad2009-10-21 00:40:46 +00002723 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2724 NewTL.setNameLoc(TL.getNameLoc());
2725
2726 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002727}
2728
2729template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002730QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
2731 RecordTypeLoc TL) {
2732 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002733 RecordDecl *Record
John McCalla2becad2009-10-21 00:40:46 +00002734 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002735 if (!Record)
2736 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002737
John McCalla2becad2009-10-21 00:40:46 +00002738 QualType Result = TL.getType();
2739 if (getDerived().AlwaysRebuild() ||
2740 Record != T->getDecl()) {
2741 Result = getDerived().RebuildRecordType(Record);
2742 if (Result.isNull())
2743 return QualType();
2744 }
Mike Stump1eb44332009-09-09 15:08:12 +00002745
John McCalla2becad2009-10-21 00:40:46 +00002746 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2747 NewTL.setNameLoc(TL.getNameLoc());
2748
2749 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002750}
Mike Stump1eb44332009-09-09 15:08:12 +00002751
2752template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002753QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
2754 EnumTypeLoc TL) {
2755 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002756 EnumDecl *Enum
John McCalla2becad2009-10-21 00:40:46 +00002757 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002758 if (!Enum)
2759 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002760
John McCalla2becad2009-10-21 00:40:46 +00002761 QualType Result = TL.getType();
2762 if (getDerived().AlwaysRebuild() ||
2763 Enum != T->getDecl()) {
2764 Result = getDerived().RebuildEnumType(Enum);
2765 if (Result.isNull())
2766 return QualType();
2767 }
Mike Stump1eb44332009-09-09 15:08:12 +00002768
John McCalla2becad2009-10-21 00:40:46 +00002769 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2770 NewTL.setNameLoc(TL.getNameLoc());
2771
2772 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002773}
John McCall7da24312009-09-05 00:15:47 +00002774
2775template <typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002776QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
2777 ElaboratedTypeLoc TL) {
2778 ElaboratedType *T = TL.getTypePtr();
2779
2780 // FIXME: this should be a nested type.
John McCall7da24312009-09-05 00:15:47 +00002781 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2782 if (Underlying.isNull())
2783 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002784
John McCalla2becad2009-10-21 00:40:46 +00002785 QualType Result = TL.getType();
2786 if (getDerived().AlwaysRebuild() ||
2787 Underlying != T->getUnderlyingType()) {
2788 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2789 if (Result.isNull())
2790 return QualType();
2791 }
Mike Stump1eb44332009-09-09 15:08:12 +00002792
John McCalla2becad2009-10-21 00:40:46 +00002793 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2794 NewTL.setNameLoc(TL.getNameLoc());
2795
2796 return Result;
John McCall7da24312009-09-05 00:15:47 +00002797}
Mike Stump1eb44332009-09-09 15:08:12 +00002798
2799
Douglas Gregor577f75a2009-08-04 16:50:30 +00002800template<typename Derived>
2801QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00002802 TypeLocBuilder &TLB,
2803 TemplateTypeParmTypeLoc TL) {
2804 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002805}
2806
Mike Stump1eb44332009-09-09 15:08:12 +00002807template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00002808QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00002809 TypeLocBuilder &TLB,
2810 SubstTemplateTypeParmTypeLoc TL) {
2811 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00002812}
2813
2814template<typename Derived>
Douglas Gregordd62b152009-10-19 22:04:39 +00002815inline QualType
2816TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCalla2becad2009-10-21 00:40:46 +00002817 TypeLocBuilder &TLB,
2818 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00002819 return TransformTemplateSpecializationType(TLB, TL, QualType());
2820}
John McCalla2becad2009-10-21 00:40:46 +00002821
John McCall833ca992009-10-29 08:12:44 +00002822template<typename Derived>
2823QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2824 const TemplateSpecializationType *TST,
2825 QualType ObjectType) {
2826 // FIXME: this entire method is a temporary workaround; callers
2827 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00002828
John McCall833ca992009-10-29 08:12:44 +00002829 // Fake up a TemplateSpecializationTypeLoc.
2830 TypeLocBuilder TLB;
2831 TemplateSpecializationTypeLoc TL
2832 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2833
John McCall828bff22009-10-29 18:45:58 +00002834 SourceLocation BaseLoc = getDerived().getBaseLocation();
2835
2836 TL.setTemplateNameLoc(BaseLoc);
2837 TL.setLAngleLoc(BaseLoc);
2838 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00002839 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2840 const TemplateArgument &TA = TST->getArg(i);
2841 TemplateArgumentLoc TAL;
2842 getDerived().InventTemplateArgumentLoc(TA, TAL);
2843 TL.setArgLocInfo(i, TAL.getLocInfo());
2844 }
2845
2846 TypeLocBuilder IgnoredTLB;
2847 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00002848}
2849
2850template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002851QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00002852 TypeLocBuilder &TLB,
2853 TemplateSpecializationTypeLoc TL,
2854 QualType ObjectType) {
2855 const TemplateSpecializationType *T = TL.getTypePtr();
2856
Mike Stump1eb44332009-09-09 15:08:12 +00002857 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00002858 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002859 if (Template.isNull())
2860 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002861
John McCalld5532b62009-11-23 01:53:49 +00002862 TemplateArgumentListInfo NewTemplateArgs;
2863 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2864 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2865
2866 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2867 TemplateArgumentLoc Loc;
2868 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00002869 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00002870 NewTemplateArgs.addArgument(Loc);
2871 }
Mike Stump1eb44332009-09-09 15:08:12 +00002872
John McCall833ca992009-10-29 08:12:44 +00002873 // FIXME: maybe don't rebuild if all the template arguments are the same.
2874
2875 QualType Result =
2876 getDerived().RebuildTemplateSpecializationType(Template,
2877 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00002878 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00002879
2880 if (!Result.isNull()) {
2881 TemplateSpecializationTypeLoc NewTL
2882 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2883 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2884 NewTL.setLAngleLoc(TL.getLAngleLoc());
2885 NewTL.setRAngleLoc(TL.getRAngleLoc());
2886 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2887 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002888 }
Mike Stump1eb44332009-09-09 15:08:12 +00002889
John McCall833ca992009-10-29 08:12:44 +00002890 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002891}
Mike Stump1eb44332009-09-09 15:08:12 +00002892
2893template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002894QualType
2895TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
2896 QualifiedNameTypeLoc TL) {
2897 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002898 NestedNameSpecifier *NNS
2899 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2900 SourceRange());
2901 if (!NNS)
2902 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002903
Douglas Gregor577f75a2009-08-04 16:50:30 +00002904 QualType Named = getDerived().TransformType(T->getNamedType());
2905 if (Named.isNull())
2906 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002907
John McCalla2becad2009-10-21 00:40:46 +00002908 QualType Result = TL.getType();
2909 if (getDerived().AlwaysRebuild() ||
2910 NNS != T->getQualifier() ||
2911 Named != T->getNamedType()) {
2912 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2913 if (Result.isNull())
2914 return QualType();
2915 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002916
John McCalla2becad2009-10-21 00:40:46 +00002917 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2918 NewTL.setNameLoc(TL.getNameLoc());
2919
2920 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002921}
Mike Stump1eb44332009-09-09 15:08:12 +00002922
2923template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002924QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
2925 TypenameTypeLoc TL) {
2926 TypenameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00002927
2928 /* FIXME: preserve source information better than this */
2929 SourceRange SR(TL.getNameLoc());
2930
Douglas Gregor577f75a2009-08-04 16:50:30 +00002931 NestedNameSpecifier *NNS
John McCall833ca992009-10-29 08:12:44 +00002932 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002933 if (!NNS)
2934 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002935
John McCalla2becad2009-10-21 00:40:46 +00002936 QualType Result;
2937
Douglas Gregor577f75a2009-08-04 16:50:30 +00002938 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002939 QualType NewTemplateId
Douglas Gregor577f75a2009-08-04 16:50:30 +00002940 = getDerived().TransformType(QualType(TemplateId, 0));
2941 if (NewTemplateId.isNull())
2942 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002943
Douglas Gregor577f75a2009-08-04 16:50:30 +00002944 if (!getDerived().AlwaysRebuild() &&
2945 NNS == T->getQualifier() &&
2946 NewTemplateId == QualType(TemplateId, 0))
2947 return QualType(T, 0);
Mike Stump1eb44332009-09-09 15:08:12 +00002948
John McCalla2becad2009-10-21 00:40:46 +00002949 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2950 } else {
John McCall833ca992009-10-29 08:12:44 +00002951 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002952 }
John McCalla2becad2009-10-21 00:40:46 +00002953 if (Result.isNull())
2954 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002955
John McCalla2becad2009-10-21 00:40:46 +00002956 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2957 NewTL.setNameLoc(TL.getNameLoc());
2958
2959 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002960}
Mike Stump1eb44332009-09-09 15:08:12 +00002961
Douglas Gregor577f75a2009-08-04 16:50:30 +00002962template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002963QualType
2964TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
2965 ObjCInterfaceTypeLoc TL) {
John McCall54e14c42009-10-22 22:37:11 +00002966 assert(false && "TransformObjCInterfaceType unimplemented");
2967 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002968}
Mike Stump1eb44332009-09-09 15:08:12 +00002969
2970template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002971QualType
2972TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
2973 ObjCObjectPointerTypeLoc TL) {
John McCall54e14c42009-10-22 22:37:11 +00002974 assert(false && "TransformObjCObjectPointerType unimplemented");
2975 return QualType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00002976}
2977
Douglas Gregor577f75a2009-08-04 16:50:30 +00002978//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00002979// Statement transformation
2980//===----------------------------------------------------------------------===//
2981template<typename Derived>
2982Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00002983TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2984 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00002985}
2986
2987template<typename Derived>
2988Sema::OwningStmtResult
2989TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2990 return getDerived().TransformCompoundStmt(S, false);
2991}
2992
2993template<typename Derived>
2994Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00002995TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00002996 bool IsStmtExpr) {
2997 bool SubStmtChanged = false;
2998 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
2999 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3000 B != BEnd; ++B) {
3001 OwningStmtResult Result = getDerived().TransformStmt(*B);
3002 if (Result.isInvalid())
3003 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003004
Douglas Gregor43959a92009-08-20 07:17:43 +00003005 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3006 Statements.push_back(Result.takeAs<Stmt>());
3007 }
Mike Stump1eb44332009-09-09 15:08:12 +00003008
Douglas Gregor43959a92009-08-20 07:17:43 +00003009 if (!getDerived().AlwaysRebuild() &&
3010 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003011 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003012
3013 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3014 move_arg(Statements),
3015 S->getRBracLoc(),
3016 IsStmtExpr);
3017}
Mike Stump1eb44332009-09-09 15:08:12 +00003018
Douglas Gregor43959a92009-08-20 07:17:43 +00003019template<typename Derived>
3020Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003021TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman264c1f82009-11-19 03:14:00 +00003022 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3023 {
3024 // The case value expressions are not potentially evaluated.
3025 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003026
Eli Friedman264c1f82009-11-19 03:14:00 +00003027 // Transform the left-hand case value.
3028 LHS = getDerived().TransformExpr(S->getLHS());
3029 if (LHS.isInvalid())
3030 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003031
Eli Friedman264c1f82009-11-19 03:14:00 +00003032 // Transform the right-hand case value (for the GNU case-range extension).
3033 RHS = getDerived().TransformExpr(S->getRHS());
3034 if (RHS.isInvalid())
3035 return SemaRef.StmtError();
3036 }
Mike Stump1eb44332009-09-09 15:08:12 +00003037
Douglas Gregor43959a92009-08-20 07:17:43 +00003038 // Build the case statement.
3039 // Case statements are always rebuilt so that they will attached to their
3040 // transformed switch statement.
3041 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3042 move(LHS),
3043 S->getEllipsisLoc(),
3044 move(RHS),
3045 S->getColonLoc());
3046 if (Case.isInvalid())
3047 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003048
Douglas Gregor43959a92009-08-20 07:17:43 +00003049 // Transform the statement following the case
3050 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3051 if (SubStmt.isInvalid())
3052 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003053
Douglas Gregor43959a92009-08-20 07:17:43 +00003054 // Attach the body to the case statement
3055 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3056}
3057
3058template<typename Derived>
3059Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003060TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003061 // Transform the statement following the default case
3062 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3063 if (SubStmt.isInvalid())
3064 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003065
Douglas Gregor43959a92009-08-20 07:17:43 +00003066 // Default statements are always rebuilt
3067 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3068 move(SubStmt));
3069}
Mike Stump1eb44332009-09-09 15:08:12 +00003070
Douglas Gregor43959a92009-08-20 07:17:43 +00003071template<typename Derived>
3072Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003073TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003074 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3075 if (SubStmt.isInvalid())
3076 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003077
Douglas Gregor43959a92009-08-20 07:17:43 +00003078 // FIXME: Pass the real colon location in.
3079 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3080 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3081 move(SubStmt));
3082}
Mike Stump1eb44332009-09-09 15:08:12 +00003083
Douglas Gregor43959a92009-08-20 07:17:43 +00003084template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003085Sema::OwningStmtResult
3086TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003087 // Transform the condition
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003088 OwningExprResult Cond(SemaRef);
3089 VarDecl *ConditionVar = 0;
3090 if (S->getConditionVariable()) {
3091 ConditionVar
3092 = cast_or_null<VarDecl>(
3093 getDerived().TransformDefinition(S->getConditionVariable()));
3094 if (!ConditionVar)
3095 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003096 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003097 Cond = getDerived().TransformExpr(S->getCond());
3098
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003099 if (Cond.isInvalid())
3100 return SemaRef.StmtError();
3101 }
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003102
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003103 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump1eb44332009-09-09 15:08:12 +00003104
Douglas Gregor43959a92009-08-20 07:17:43 +00003105 // Transform the "then" branch.
3106 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3107 if (Then.isInvalid())
3108 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003109
Douglas Gregor43959a92009-08-20 07:17:43 +00003110 // Transform the "else" branch.
3111 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3112 if (Else.isInvalid())
3113 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003114
Douglas Gregor43959a92009-08-20 07:17:43 +00003115 if (!getDerived().AlwaysRebuild() &&
3116 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003117 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003118 Then.get() == S->getThen() &&
3119 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003120 return SemaRef.Owned(S->Retain());
3121
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003122 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3123 move(Then),
Mike Stump1eb44332009-09-09 15:08:12 +00003124 S->getElseLoc(), move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +00003125}
3126
3127template<typename Derived>
3128Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003129TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003130 // Transform the condition.
Douglas Gregord3d53012009-11-24 17:07:59 +00003131 OwningExprResult Cond(SemaRef);
3132 VarDecl *ConditionVar = 0;
3133 if (S->getConditionVariable()) {
3134 ConditionVar
3135 = cast_or_null<VarDecl>(
3136 getDerived().TransformDefinition(S->getConditionVariable()));
3137 if (!ConditionVar)
3138 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003139 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003140 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003141
3142 if (Cond.isInvalid())
3143 return SemaRef.StmtError();
3144 }
Mike Stump1eb44332009-09-09 15:08:12 +00003145
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003146 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003147
Douglas Gregor43959a92009-08-20 07:17:43 +00003148 // Rebuild the switch statement.
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003149 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3150 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003151 if (Switch.isInvalid())
3152 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003153
Douglas Gregor43959a92009-08-20 07:17:43 +00003154 // Transform the body of the switch statement.
3155 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3156 if (Body.isInvalid())
3157 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003158
Douglas Gregor43959a92009-08-20 07:17:43 +00003159 // Complete the switch statement.
3160 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3161 move(Body));
3162}
Mike Stump1eb44332009-09-09 15:08:12 +00003163
Douglas Gregor43959a92009-08-20 07:17:43 +00003164template<typename Derived>
3165Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003166TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003167 // Transform the condition
Douglas Gregor5656e142009-11-24 21:15:44 +00003168 OwningExprResult Cond(SemaRef);
3169 VarDecl *ConditionVar = 0;
3170 if (S->getConditionVariable()) {
3171 ConditionVar
3172 = cast_or_null<VarDecl>(
3173 getDerived().TransformDefinition(S->getConditionVariable()));
3174 if (!ConditionVar)
3175 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003176 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003177 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003178
3179 if (Cond.isInvalid())
3180 return SemaRef.StmtError();
3181 }
Mike Stump1eb44332009-09-09 15:08:12 +00003182
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003183 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump1eb44332009-09-09 15:08:12 +00003184
Douglas Gregor43959a92009-08-20 07:17:43 +00003185 // Transform the body
3186 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3187 if (Body.isInvalid())
3188 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003189
Douglas Gregor43959a92009-08-20 07:17:43 +00003190 if (!getDerived().AlwaysRebuild() &&
3191 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003192 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003193 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003194 return SemaRef.Owned(S->Retain());
3195
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003196 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3197 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003198}
Mike Stump1eb44332009-09-09 15:08:12 +00003199
Douglas Gregor43959a92009-08-20 07:17:43 +00003200template<typename Derived>
3201Sema::OwningStmtResult
3202TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3203 // Transform the condition
3204 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3205 if (Cond.isInvalid())
3206 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003207
Douglas Gregor43959a92009-08-20 07:17:43 +00003208 // Transform the body
3209 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3210 if (Body.isInvalid())
3211 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003212
Douglas Gregor43959a92009-08-20 07:17:43 +00003213 if (!getDerived().AlwaysRebuild() &&
3214 Cond.get() == S->getCond() &&
3215 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003216 return SemaRef.Owned(S->Retain());
3217
Douglas Gregor43959a92009-08-20 07:17:43 +00003218 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3219 /*FIXME:*/S->getWhileLoc(), move(Cond),
3220 S->getRParenLoc());
3221}
Mike Stump1eb44332009-09-09 15:08:12 +00003222
Douglas Gregor43959a92009-08-20 07:17:43 +00003223template<typename Derived>
3224Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003225TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003226 // Transform the initialization statement
3227 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3228 if (Init.isInvalid())
3229 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003230
Douglas Gregor43959a92009-08-20 07:17:43 +00003231 // Transform the condition
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003232 OwningExprResult Cond(SemaRef);
3233 VarDecl *ConditionVar = 0;
3234 if (S->getConditionVariable()) {
3235 ConditionVar
3236 = cast_or_null<VarDecl>(
3237 getDerived().TransformDefinition(S->getConditionVariable()));
3238 if (!ConditionVar)
3239 return SemaRef.StmtError();
3240 } else {
3241 Cond = getDerived().TransformExpr(S->getCond());
3242
3243 if (Cond.isInvalid())
3244 return SemaRef.StmtError();
3245 }
Mike Stump1eb44332009-09-09 15:08:12 +00003246
Douglas Gregor43959a92009-08-20 07:17:43 +00003247 // Transform the increment
3248 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3249 if (Inc.isInvalid())
3250 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003251
Douglas Gregor43959a92009-08-20 07:17:43 +00003252 // Transform the body
3253 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3254 if (Body.isInvalid())
3255 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003256
Douglas Gregor43959a92009-08-20 07:17:43 +00003257 if (!getDerived().AlwaysRebuild() &&
3258 Init.get() == S->getInit() &&
3259 Cond.get() == S->getCond() &&
3260 Inc.get() == S->getInc() &&
3261 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003262 return SemaRef.Owned(S->Retain());
3263
Douglas Gregor43959a92009-08-20 07:17:43 +00003264 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003265 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003266 ConditionVar,
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003267 getSema().MakeFullExpr(Inc),
Douglas Gregor43959a92009-08-20 07:17:43 +00003268 S->getRParenLoc(), move(Body));
3269}
3270
3271template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003272Sema::OwningStmtResult
3273TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003274 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003275 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003276 S->getLabel());
3277}
3278
3279template<typename Derived>
3280Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003281TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003282 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3283 if (Target.isInvalid())
3284 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003285
Douglas Gregor43959a92009-08-20 07:17:43 +00003286 if (!getDerived().AlwaysRebuild() &&
3287 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003288 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003289
3290 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3291 move(Target));
3292}
3293
3294template<typename Derived>
3295Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003296TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3297 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003298}
Mike Stump1eb44332009-09-09 15:08:12 +00003299
Douglas Gregor43959a92009-08-20 07:17:43 +00003300template<typename Derived>
3301Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003302TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3303 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003304}
Mike Stump1eb44332009-09-09 15:08:12 +00003305
Douglas Gregor43959a92009-08-20 07:17:43 +00003306template<typename Derived>
3307Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003308TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003309 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3310 if (Result.isInvalid())
3311 return SemaRef.StmtError();
3312
Mike Stump1eb44332009-09-09 15:08:12 +00003313 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003314 // to tell whether the return type of the function has changed.
3315 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3316}
Mike Stump1eb44332009-09-09 15:08:12 +00003317
Douglas Gregor43959a92009-08-20 07:17:43 +00003318template<typename Derived>
3319Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003320TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003321 bool DeclChanged = false;
3322 llvm::SmallVector<Decl *, 4> Decls;
3323 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3324 D != DEnd; ++D) {
3325 Decl *Transformed = getDerived().TransformDefinition(*D);
3326 if (!Transformed)
3327 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003328
Douglas Gregor43959a92009-08-20 07:17:43 +00003329 if (Transformed != *D)
3330 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003331
Douglas Gregor43959a92009-08-20 07:17:43 +00003332 Decls.push_back(Transformed);
3333 }
Mike Stump1eb44332009-09-09 15:08:12 +00003334
Douglas Gregor43959a92009-08-20 07:17:43 +00003335 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003336 return SemaRef.Owned(S->Retain());
3337
3338 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003339 S->getStartLoc(), S->getEndLoc());
3340}
Mike Stump1eb44332009-09-09 15:08:12 +00003341
Douglas Gregor43959a92009-08-20 07:17:43 +00003342template<typename Derived>
3343Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003344TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003345 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003346 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003347}
3348
3349template<typename Derived>
3350Sema::OwningStmtResult
3351TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlsson703e3942010-01-24 05:50:09 +00003352
3353 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3354 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
3355 OwningExprResult AsmString(SemaRef);
3356 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3357
3358 bool ExprsChanged = false;
3359
3360 // Go through the outputs.
3361 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
3362 // No need to transform the constraint literal.
3363 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3364
3365 // Transform the output expr.
3366 Expr *OutputExpr = S->getOutputExpr(I);
3367 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3368 if (Result.isInvalid())
3369 return SemaRef.StmtError();
3370
3371 ExprsChanged |= Result.get() != OutputExpr;
3372
3373 Exprs.push_back(Result.takeAs<Expr>());
3374 }
3375
3376 // Go through the inputs.
3377 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
3378 // No need to transform the constraint literal.
3379 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3380
3381 // Transform the input expr.
3382 Expr *InputExpr = S->getInputExpr(I);
3383 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3384 if (Result.isInvalid())
3385 return SemaRef.StmtError();
3386
3387 ExprsChanged |= Result.get() != InputExpr;
3388
3389 Exprs.push_back(Result.takeAs<Expr>());
3390 }
3391
3392 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3393 return SemaRef.Owned(S->Retain());
3394
3395 // Go through the clobbers.
3396 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3397 Clobbers.push_back(S->getClobber(I)->Retain());
3398
3399 // No need to transform the asm string literal.
3400 AsmString = SemaRef.Owned(S->getAsmString());
3401
3402 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3403 S->isSimple(),
3404 S->isVolatile(),
3405 S->getNumOutputs(),
3406 S->getNumInputs(),
3407 S->begin_output_names(),
3408 move_arg(Constraints),
3409 move_arg(Exprs),
3410 move(AsmString),
3411 move_arg(Clobbers),
3412 S->getRParenLoc(),
3413 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003414}
3415
3416
3417template<typename Derived>
3418Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003419TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003420 // FIXME: Implement this
3421 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003422 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003423}
Mike Stump1eb44332009-09-09 15:08:12 +00003424
Douglas Gregor43959a92009-08-20 07:17:43 +00003425template<typename Derived>
3426Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003427TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003428 // FIXME: Implement this
3429 assert(false && "Cannot transform an Objective-C @catch statement");
3430 return SemaRef.Owned(S->Retain());
3431}
Mike Stump1eb44332009-09-09 15:08:12 +00003432
Douglas Gregor43959a92009-08-20 07:17:43 +00003433template<typename Derived>
3434Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003435TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003436 // FIXME: Implement this
3437 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003438 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003439}
Mike Stump1eb44332009-09-09 15:08:12 +00003440
Douglas Gregor43959a92009-08-20 07:17:43 +00003441template<typename Derived>
3442Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003443TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003444 // FIXME: Implement this
3445 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003446 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003447}
Mike Stump1eb44332009-09-09 15:08:12 +00003448
Douglas Gregor43959a92009-08-20 07:17:43 +00003449template<typename Derived>
3450Sema::OwningStmtResult
3451TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003452 ObjCAtSynchronizedStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003453 // FIXME: Implement this
3454 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003455 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003456}
3457
3458template<typename Derived>
3459Sema::OwningStmtResult
3460TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003461 ObjCForCollectionStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003462 // FIXME: Implement this
3463 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003464 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003465}
3466
3467
3468template<typename Derived>
3469Sema::OwningStmtResult
3470TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3471 // Transform the exception declaration, if any.
3472 VarDecl *Var = 0;
3473 if (S->getExceptionDecl()) {
3474 VarDecl *ExceptionDecl = S->getExceptionDecl();
3475 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3476 ExceptionDecl->getDeclName());
3477
3478 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3479 if (T.isNull())
3480 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003481
Douglas Gregor43959a92009-08-20 07:17:43 +00003482 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3483 T,
John McCalla93c9342009-12-07 02:54:59 +00003484 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003485 ExceptionDecl->getIdentifier(),
3486 ExceptionDecl->getLocation(),
3487 /*FIXME: Inaccurate*/
3488 SourceRange(ExceptionDecl->getLocation()));
3489 if (!Var || Var->isInvalidDecl()) {
3490 if (Var)
3491 Var->Destroy(SemaRef.Context);
3492 return SemaRef.StmtError();
3493 }
3494 }
Mike Stump1eb44332009-09-09 15:08:12 +00003495
Douglas Gregor43959a92009-08-20 07:17:43 +00003496 // Transform the actual exception handler.
3497 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3498 if (Handler.isInvalid()) {
3499 if (Var)
3500 Var->Destroy(SemaRef.Context);
3501 return SemaRef.StmtError();
3502 }
Mike Stump1eb44332009-09-09 15:08:12 +00003503
Douglas Gregor43959a92009-08-20 07:17:43 +00003504 if (!getDerived().AlwaysRebuild() &&
3505 !Var &&
3506 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00003507 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003508
3509 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3510 Var,
3511 move(Handler));
3512}
Mike Stump1eb44332009-09-09 15:08:12 +00003513
Douglas Gregor43959a92009-08-20 07:17:43 +00003514template<typename Derived>
3515Sema::OwningStmtResult
3516TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3517 // Transform the try block itself.
Mike Stump1eb44332009-09-09 15:08:12 +00003518 OwningStmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00003519 = getDerived().TransformCompoundStmt(S->getTryBlock());
3520 if (TryBlock.isInvalid())
3521 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003522
Douglas Gregor43959a92009-08-20 07:17:43 +00003523 // Transform the handlers.
3524 bool HandlerChanged = false;
3525 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3526 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump1eb44332009-09-09 15:08:12 +00003527 OwningStmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00003528 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3529 if (Handler.isInvalid())
3530 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003531
Douglas Gregor43959a92009-08-20 07:17:43 +00003532 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3533 Handlers.push_back(Handler.takeAs<Stmt>());
3534 }
Mike Stump1eb44332009-09-09 15:08:12 +00003535
Douglas Gregor43959a92009-08-20 07:17:43 +00003536 if (!getDerived().AlwaysRebuild() &&
3537 TryBlock.get() == S->getTryBlock() &&
3538 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003539 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003540
3541 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump1eb44332009-09-09 15:08:12 +00003542 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00003543}
Mike Stump1eb44332009-09-09 15:08:12 +00003544
Douglas Gregor43959a92009-08-20 07:17:43 +00003545//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00003546// Expression transformation
3547//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00003548template<typename Derived>
3549Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003550TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003551 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003552}
Mike Stump1eb44332009-09-09 15:08:12 +00003553
3554template<typename Derived>
3555Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003556TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00003557 NestedNameSpecifier *Qualifier = 0;
3558 if (E->getQualifier()) {
3559 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3560 E->getQualifierRange());
3561 if (!Qualifier)
3562 return SemaRef.ExprError();
3563 }
John McCalldbd872f2009-12-08 09:08:17 +00003564
3565 ValueDecl *ND
3566 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00003567 if (!ND)
3568 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003569
Douglas Gregora2813ce2009-10-23 18:54:35 +00003570 if (!getDerived().AlwaysRebuild() &&
3571 Qualifier == E->getQualifier() &&
3572 ND == E->getDecl() &&
John McCalldbd872f2009-12-08 09:08:17 +00003573 !E->hasExplicitTemplateArgumentList()) {
3574
3575 // Mark it referenced in the new context regardless.
3576 // FIXME: this is a bit instantiation-specific.
3577 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3578
Mike Stump1eb44332009-09-09 15:08:12 +00003579 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00003580 }
John McCalldbd872f2009-12-08 09:08:17 +00003581
3582 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3583 if (E->hasExplicitTemplateArgumentList()) {
3584 TemplateArgs = &TransArgs;
3585 TransArgs.setLAngleLoc(E->getLAngleLoc());
3586 TransArgs.setRAngleLoc(E->getRAngleLoc());
3587 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3588 TemplateArgumentLoc Loc;
3589 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3590 return SemaRef.ExprError();
3591 TransArgs.addArgument(Loc);
3592 }
3593 }
3594
Douglas Gregora2813ce2009-10-23 18:54:35 +00003595 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCalldbd872f2009-12-08 09:08:17 +00003596 ND, E->getLocation(), TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003597}
Mike Stump1eb44332009-09-09 15:08:12 +00003598
Douglas Gregorb98b1992009-08-11 05:31:07 +00003599template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003600Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003601TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003602 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003603}
Mike Stump1eb44332009-09-09 15:08:12 +00003604
Douglas Gregorb98b1992009-08-11 05:31:07 +00003605template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003606Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003607TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003608 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003609}
Mike Stump1eb44332009-09-09 15:08:12 +00003610
Douglas Gregorb98b1992009-08-11 05:31:07 +00003611template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003612Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003613TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003614 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003615}
Mike Stump1eb44332009-09-09 15:08:12 +00003616
Douglas Gregorb98b1992009-08-11 05:31:07 +00003617template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003618Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003619TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003620 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003621}
Mike Stump1eb44332009-09-09 15:08:12 +00003622
Douglas Gregorb98b1992009-08-11 05:31:07 +00003623template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003624Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003625TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003626 return SemaRef.Owned(E->Retain());
3627}
3628
3629template<typename Derived>
3630Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003631TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003632 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3633 if (SubExpr.isInvalid())
3634 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003635
Douglas Gregorb98b1992009-08-11 05:31:07 +00003636 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003637 return SemaRef.Owned(E->Retain());
3638
3639 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003640 E->getRParen());
3641}
3642
Mike Stump1eb44332009-09-09 15:08:12 +00003643template<typename Derived>
3644Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003645TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3646 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003647 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
Douglas Gregorb98b1992009-08-11 05:31:07 +00003653 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3654 E->getOpcode(),
3655 move(SubExpr));
3656}
Mike Stump1eb44332009-09-09 15:08:12 +00003657
Douglas Gregorb98b1992009-08-11 05:31:07 +00003658template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003659Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003660TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003661 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00003662 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00003663
John McCalla93c9342009-12-07 02:54:59 +00003664 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00003665 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003666 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003667
John McCall5ab75172009-11-04 07:28:41 +00003668 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003669 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003670
John McCall5ab75172009-11-04 07:28:41 +00003671 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00003672 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003673 E->getSourceRange());
3674 }
Mike Stump1eb44332009-09-09 15:08:12 +00003675
Douglas Gregorb98b1992009-08-11 05:31:07 +00003676 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00003677 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003678 // C++0x [expr.sizeof]p1:
3679 // The operand is either an expression, which is an unevaluated operand
3680 // [...]
3681 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003682
Douglas Gregorb98b1992009-08-11 05:31:07 +00003683 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3684 if (SubExpr.isInvalid())
3685 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003686
Douglas Gregorb98b1992009-08-11 05:31:07 +00003687 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3688 return SemaRef.Owned(E->Retain());
3689 }
Mike Stump1eb44332009-09-09 15:08:12 +00003690
Douglas Gregorb98b1992009-08-11 05:31:07 +00003691 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3692 E->isSizeOf(),
3693 E->getSourceRange());
3694}
Mike Stump1eb44332009-09-09 15:08:12 +00003695
Douglas Gregorb98b1992009-08-11 05:31:07 +00003696template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003697Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003698TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003699 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3700 if (LHS.isInvalid())
3701 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003702
Douglas Gregorb98b1992009-08-11 05:31:07 +00003703 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3704 if (RHS.isInvalid())
3705 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003706
3707
Douglas Gregorb98b1992009-08-11 05:31:07 +00003708 if (!getDerived().AlwaysRebuild() &&
3709 LHS.get() == E->getLHS() &&
3710 RHS.get() == E->getRHS())
3711 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003712
Douglas Gregorb98b1992009-08-11 05:31:07 +00003713 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3714 /*FIXME:*/E->getLHS()->getLocStart(),
3715 move(RHS),
3716 E->getRBracketLoc());
3717}
Mike Stump1eb44332009-09-09 15:08:12 +00003718
3719template<typename Derived>
3720Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003721TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003722 // Transform the callee.
3723 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3724 if (Callee.isInvalid())
3725 return SemaRef.ExprError();
3726
3727 // Transform arguments.
3728 bool ArgChanged = false;
3729 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3730 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3731 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3732 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3733 if (Arg.isInvalid())
3734 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003735
Douglas Gregorb98b1992009-08-11 05:31:07 +00003736 // FIXME: Wrong source location information for the ','.
3737 FakeCommaLocs.push_back(
3738 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00003739
3740 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003741 Args.push_back(Arg.takeAs<Expr>());
3742 }
Mike Stump1eb44332009-09-09 15:08:12 +00003743
Douglas Gregorb98b1992009-08-11 05:31:07 +00003744 if (!getDerived().AlwaysRebuild() &&
3745 Callee.get() == E->getCallee() &&
3746 !ArgChanged)
3747 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003748
Douglas Gregorb98b1992009-08-11 05:31:07 +00003749 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00003750 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003751 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3752 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3753 move_arg(Args),
3754 FakeCommaLocs.data(),
3755 E->getRParenLoc());
3756}
Mike Stump1eb44332009-09-09 15:08:12 +00003757
3758template<typename Derived>
3759Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003760TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003761 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3762 if (Base.isInvalid())
3763 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003764
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003765 NestedNameSpecifier *Qualifier = 0;
3766 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00003767 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003768 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3769 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00003770 if (Qualifier == 0)
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003771 return SemaRef.ExprError();
3772 }
Mike Stump1eb44332009-09-09 15:08:12 +00003773
Eli Friedmanf595cc42009-12-04 06:40:45 +00003774 ValueDecl *Member
3775 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00003776 if (!Member)
3777 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003778
Douglas Gregorb98b1992009-08-11 05:31:07 +00003779 if (!getDerived().AlwaysRebuild() &&
3780 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003781 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003782 Member == E->getMemberDecl() &&
Anders Carlsson1f240322009-12-22 05:24:09 +00003783 !E->hasExplicitTemplateArgumentList()) {
3784
3785 // Mark it referenced in the new context regardless.
3786 // FIXME: this is a bit instantiation-specific.
3787 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00003788 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00003789 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00003790
John McCalld5532b62009-11-23 01:53:49 +00003791 TemplateArgumentListInfo TransArgs;
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003792 if (E->hasExplicitTemplateArgumentList()) {
John McCalld5532b62009-11-23 01:53:49 +00003793 TransArgs.setLAngleLoc(E->getLAngleLoc());
3794 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003795 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00003796 TemplateArgumentLoc Loc;
3797 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003798 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00003799 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003800 }
3801 }
3802
Douglas Gregorb98b1992009-08-11 05:31:07 +00003803 // FIXME: Bogus source location for the operator
3804 SourceLocation FakeOperatorLoc
3805 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3806
John McCallc2233c52010-01-15 08:34:02 +00003807 // FIXME: to do this check properly, we will need to preserve the
3808 // first-qualifier-in-scope here, just in case we had a dependent
3809 // base (and therefore couldn't do the check) and a
3810 // nested-name-qualifier (and therefore could do the lookup).
3811 NamedDecl *FirstQualifierInScope = 0;
3812
Douglas Gregorb98b1992009-08-11 05:31:07 +00003813 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3814 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003815 Qualifier,
3816 E->getQualifierRange(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003817 E->getMemberLoc(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003818 Member,
John McCalld5532b62009-11-23 01:53:49 +00003819 (E->hasExplicitTemplateArgumentList()
3820 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00003821 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003822}
Mike Stump1eb44332009-09-09 15:08:12 +00003823
Douglas Gregorb98b1992009-08-11 05:31:07 +00003824template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00003825Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003826TreeTransform<Derived>::TransformCastExpr(CastExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003827 assert(false && "Cannot transform abstract class");
3828 return SemaRef.Owned(E->Retain());
3829}
3830
3831template<typename Derived>
3832Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003833TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003834 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3835 if (LHS.isInvalid())
3836 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003837
Douglas Gregorb98b1992009-08-11 05:31:07 +00003838 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3839 if (RHS.isInvalid())
3840 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003841
Douglas Gregorb98b1992009-08-11 05:31:07 +00003842 if (!getDerived().AlwaysRebuild() &&
3843 LHS.get() == E->getLHS() &&
3844 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00003845 return SemaRef.Owned(E->Retain());
3846
Douglas Gregorb98b1992009-08-11 05:31:07 +00003847 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3848 move(LHS), move(RHS));
3849}
3850
Mike Stump1eb44332009-09-09 15:08:12 +00003851template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00003852Sema::OwningExprResult
3853TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00003854 CompoundAssignOperator *E) {
3855 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003856}
Mike Stump1eb44332009-09-09 15:08:12 +00003857
Douglas Gregorb98b1992009-08-11 05:31:07 +00003858template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003859Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003860TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003861 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3862 if (Cond.isInvalid())
3863 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003864
Douglas Gregorb98b1992009-08-11 05:31:07 +00003865 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3866 if (LHS.isInvalid())
3867 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003868
Douglas Gregorb98b1992009-08-11 05:31:07 +00003869 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3870 if (RHS.isInvalid())
3871 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003872
Douglas Gregorb98b1992009-08-11 05:31:07 +00003873 if (!getDerived().AlwaysRebuild() &&
3874 Cond.get() == E->getCond() &&
3875 LHS.get() == E->getLHS() &&
3876 RHS.get() == E->getRHS())
3877 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003878
3879 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00003880 E->getQuestionLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00003881 move(LHS),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00003882 E->getColonLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003883 move(RHS));
3884}
Mike Stump1eb44332009-09-09 15:08:12 +00003885
3886template<typename Derived>
3887Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003888TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00003889 // Implicit casts are eliminated during transformation, since they
3890 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00003891 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003892}
Mike Stump1eb44332009-09-09 15:08:12 +00003893
Douglas Gregorb98b1992009-08-11 05:31:07 +00003894template<typename Derived>
3895Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003896TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003897 assert(false && "Cannot transform abstract class");
3898 return SemaRef.Owned(E->Retain());
3899}
3900
3901template<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
Douglas Gregorb98b1992009-08-11 05:31:07 +00004517 if (getDerived().AlwaysRebuild() &&
4518 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 Gregorb98b1992009-08-11 05:31:07 +00004817 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4818
4819 QualType T = getDerived().TransformType(E->getType());
4820 if (T.isNull())
4821 return SemaRef.ExprError();
4822
4823 CXXConstructorDecl *Constructor
4824 = cast_or_null<CXXConstructorDecl>(
4825 getDerived().TransformDecl(E->getConstructor()));
4826 if (!Constructor)
4827 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004828
Douglas Gregorb98b1992009-08-11 05:31:07 +00004829 bool ArgumentChanged = false;
4830 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00004831 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004832 ArgEnd = E->arg_end();
4833 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004834 if (getDerived().DropCallArgument(*Arg)) {
4835 ArgumentChanged = true;
4836 break;
4837 }
4838
Douglas Gregorb98b1992009-08-11 05:31:07 +00004839 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4840 if (TransArg.isInvalid())
4841 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004842
Douglas Gregorb98b1992009-08-11 05:31:07 +00004843 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4844 Args.push_back(TransArg.takeAs<Expr>());
4845 }
4846
4847 if (!getDerived().AlwaysRebuild() &&
4848 T == E->getType() &&
4849 Constructor == E->getConstructor() &&
4850 !ArgumentChanged)
4851 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004852
Douglas Gregor4411d2e2009-12-14 16:27:04 +00004853 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
4854 Constructor, E->isElidable(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004855 move_arg(Args));
4856}
Mike Stump1eb44332009-09-09 15:08:12 +00004857
Douglas Gregorb98b1992009-08-11 05:31:07 +00004858/// \brief Transform a C++ temporary-binding expression.
4859///
Douglas Gregor51326552009-12-24 18:51:59 +00004860/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
4861/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004862template<typename Derived>
4863Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004864TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00004865 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004866}
Mike Stump1eb44332009-09-09 15:08:12 +00004867
Anders Carlssoneb60edf2010-01-29 02:39:32 +00004868/// \brief Transform a C++ reference-binding expression.
4869///
4870/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
4871/// transform the subexpression and return that.
4872template<typename Derived>
4873Sema::OwningExprResult
4874TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
4875 return getDerived().TransformExpr(E->getSubExpr());
4876}
4877
Mike Stump1eb44332009-09-09 15:08:12 +00004878/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00004879/// be destroyed after the expression is evaluated.
4880///
Douglas Gregor51326552009-12-24 18:51:59 +00004881/// Since CXXExprWithTemporaries nodes are implicitly generated, we
4882/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004883template<typename Derived>
4884Sema::OwningExprResult
4885TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00004886 CXXExprWithTemporaries *E) {
4887 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004888}
Mike Stump1eb44332009-09-09 15:08:12 +00004889
Douglas Gregorb98b1992009-08-11 05:31:07 +00004890template<typename Derived>
4891Sema::OwningExprResult
4892TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall454feb92009-12-08 09:21:05 +00004893 CXXTemporaryObjectExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004894 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4895 QualType T = getDerived().TransformType(E->getType());
4896 if (T.isNull())
4897 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004898
Douglas Gregorb98b1992009-08-11 05:31:07 +00004899 CXXConstructorDecl *Constructor
4900 = cast_or_null<CXXConstructorDecl>(
4901 getDerived().TransformDecl(E->getConstructor()));
4902 if (!Constructor)
4903 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004904
Douglas Gregorb98b1992009-08-11 05:31:07 +00004905 bool ArgumentChanged = false;
4906 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4907 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00004908 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004909 ArgEnd = E->arg_end();
4910 Arg != ArgEnd; ++Arg) {
4911 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4912 if (TransArg.isInvalid())
4913 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004914
Douglas Gregorb98b1992009-08-11 05:31:07 +00004915 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4916 Args.push_back((Expr *)TransArg.release());
4917 }
Mike Stump1eb44332009-09-09 15:08:12 +00004918
Douglas Gregorb98b1992009-08-11 05:31:07 +00004919 if (!getDerived().AlwaysRebuild() &&
4920 T == E->getType() &&
4921 Constructor == E->getConstructor() &&
4922 !ArgumentChanged)
4923 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004924
Douglas Gregorb98b1992009-08-11 05:31:07 +00004925 // FIXME: Bogus location information
4926 SourceLocation CommaLoc;
4927 if (Args.size() > 1) {
4928 Expr *First = (Expr *)Args[0];
Mike Stump1eb44332009-09-09 15:08:12 +00004929 CommaLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004930 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4931 }
4932 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4933 T,
4934 /*FIXME:*/E->getTypeBeginLoc(),
4935 move_arg(Args),
4936 &CommaLoc,
4937 E->getLocEnd());
4938}
Mike Stump1eb44332009-09-09 15:08:12 +00004939
Douglas Gregorb98b1992009-08-11 05:31:07 +00004940template<typename Derived>
4941Sema::OwningExprResult
4942TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00004943 CXXUnresolvedConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004944 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4945 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4946 if (T.isNull())
4947 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004948
Douglas Gregorb98b1992009-08-11 05:31:07 +00004949 bool ArgumentChanged = false;
4950 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4951 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4952 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4953 ArgEnd = E->arg_end();
4954 Arg != ArgEnd; ++Arg) {
4955 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4956 if (TransArg.isInvalid())
4957 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004958
Douglas Gregorb98b1992009-08-11 05:31:07 +00004959 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4960 FakeCommaLocs.push_back(
4961 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4962 Args.push_back(TransArg.takeAs<Expr>());
4963 }
Mike Stump1eb44332009-09-09 15:08:12 +00004964
Douglas Gregorb98b1992009-08-11 05:31:07 +00004965 if (!getDerived().AlwaysRebuild() &&
4966 T == E->getTypeAsWritten() &&
4967 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004968 return SemaRef.Owned(E->Retain());
4969
Douglas Gregorb98b1992009-08-11 05:31:07 +00004970 // FIXME: we're faking the locations of the commas
4971 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4972 T,
4973 E->getLParenLoc(),
4974 move_arg(Args),
4975 FakeCommaLocs.data(),
4976 E->getRParenLoc());
4977}
Mike Stump1eb44332009-09-09 15:08:12 +00004978
Douglas Gregorb98b1992009-08-11 05:31:07 +00004979template<typename Derived>
4980Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00004981TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall454feb92009-12-08 09:21:05 +00004982 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004983 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00004984 OwningExprResult Base(SemaRef, (Expr*) 0);
4985 Expr *OldBase;
4986 QualType BaseType;
4987 QualType ObjectType;
4988 if (!E->isImplicitAccess()) {
4989 OldBase = E->getBase();
4990 Base = getDerived().TransformExpr(OldBase);
4991 if (Base.isInvalid())
4992 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004993
John McCallaa81e162009-12-01 22:10:20 +00004994 // Start the member reference and compute the object's type.
4995 Sema::TypeTy *ObjectTy = 0;
4996 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4997 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00004998 E->isArrow()? tok::arrow : tok::period,
John McCallaa81e162009-12-01 22:10:20 +00004999 ObjectTy);
5000 if (Base.isInvalid())
5001 return SemaRef.ExprError();
5002
5003 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5004 BaseType = ((Expr*) Base.get())->getType();
5005 } else {
5006 OldBase = 0;
5007 BaseType = getDerived().TransformType(E->getBaseType());
5008 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5009 }
Mike Stump1eb44332009-09-09 15:08:12 +00005010
Douglas Gregor6cd21982009-10-20 05:58:46 +00005011 // Transform the first part of the nested-name-specifier that qualifies
5012 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005013 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005014 = getDerived().TransformFirstQualifierInScope(
5015 E->getFirstQualifierFoundInScope(),
5016 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005017
Douglas Gregora38c6872009-09-03 16:14:30 +00005018 NestedNameSpecifier *Qualifier = 0;
5019 if (E->getQualifier()) {
5020 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5021 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005022 ObjectType,
5023 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005024 if (!Qualifier)
5025 return SemaRef.ExprError();
5026 }
Mike Stump1eb44332009-09-09 15:08:12 +00005027
5028 DeclarationName Name
Douglas Gregordd62b152009-10-19 22:04:39 +00005029 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCallaa81e162009-12-01 22:10:20 +00005030 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00005031 if (!Name)
5032 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005033
John McCallaa81e162009-12-01 22:10:20 +00005034 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005035 // This is a reference to a member without an explicitly-specified
5036 // template argument list. Optimize for this common case.
5037 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005038 Base.get() == OldBase &&
5039 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005040 Qualifier == E->getQualifier() &&
5041 Name == E->getMember() &&
5042 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005043 return SemaRef.Owned(E->Retain());
5044
John McCall865d4472009-11-19 22:55:06 +00005045 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005046 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005047 E->isArrow(),
5048 E->getOperatorLoc(),
5049 Qualifier,
5050 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005051 FirstQualifierInScope,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005052 Name,
5053 E->getMemberLoc(),
John McCall129e2df2009-11-30 22:42:35 +00005054 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005055 }
5056
John McCalld5532b62009-11-23 01:53:49 +00005057 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005058 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005059 TemplateArgumentLoc Loc;
5060 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005061 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005062 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005063 }
Mike Stump1eb44332009-09-09 15:08:12 +00005064
John McCall865d4472009-11-19 22:55:06 +00005065 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005066 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005067 E->isArrow(),
5068 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005069 Qualifier,
5070 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005071 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005072 Name,
5073 E->getMemberLoc(),
5074 &TransArgs);
5075}
5076
5077template<typename Derived>
5078Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005079TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005080 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005081 OwningExprResult Base(SemaRef, (Expr*) 0);
5082 QualType BaseType;
5083 if (!Old->isImplicitAccess()) {
5084 Base = getDerived().TransformExpr(Old->getBase());
5085 if (Base.isInvalid())
5086 return SemaRef.ExprError();
5087 BaseType = ((Expr*) Base.get())->getType();
5088 } else {
5089 BaseType = getDerived().TransformType(Old->getBaseType());
5090 }
John McCall129e2df2009-11-30 22:42:35 +00005091
5092 NestedNameSpecifier *Qualifier = 0;
5093 if (Old->getQualifier()) {
5094 Qualifier
5095 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
5096 Old->getQualifierRange());
5097 if (Qualifier == 0)
5098 return SemaRef.ExprError();
5099 }
5100
5101 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5102 Sema::LookupOrdinaryName);
5103
5104 // Transform all the decls.
5105 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5106 E = Old->decls_end(); I != E; ++I) {
5107 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall9f54ad42009-12-10 09:41:52 +00005108 if (!InstD) {
5109 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5110 // This can happen because of dependent hiding.
5111 if (isa<UsingShadowDecl>(*I))
5112 continue;
5113 else
5114 return SemaRef.ExprError();
5115 }
John McCall129e2df2009-11-30 22:42:35 +00005116
5117 // Expand using declarations.
5118 if (isa<UsingDecl>(InstD)) {
5119 UsingDecl *UD = cast<UsingDecl>(InstD);
5120 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5121 E = UD->shadow_end(); I != E; ++I)
5122 R.addDecl(*I);
5123 continue;
5124 }
5125
5126 R.addDecl(InstD);
5127 }
5128
5129 R.resolveKind();
5130
5131 TemplateArgumentListInfo TransArgs;
5132 if (Old->hasExplicitTemplateArgs()) {
5133 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5134 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5135 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5136 TemplateArgumentLoc Loc;
5137 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5138 Loc))
5139 return SemaRef.ExprError();
5140 TransArgs.addArgument(Loc);
5141 }
5142 }
John McCallc2233c52010-01-15 08:34:02 +00005143
5144 // FIXME: to do this check properly, we will need to preserve the
5145 // first-qualifier-in-scope here, just in case we had a dependent
5146 // base (and therefore couldn't do the check) and a
5147 // nested-name-qualifier (and therefore could do the lookup).
5148 NamedDecl *FirstQualifierInScope = 0;
John McCall129e2df2009-11-30 22:42:35 +00005149
5150 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005151 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00005152 Old->getOperatorLoc(),
5153 Old->isArrow(),
5154 Qualifier,
5155 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00005156 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005157 R,
5158 (Old->hasExplicitTemplateArgs()
5159 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005160}
5161
5162template<typename Derived>
5163Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005164TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005165 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005166}
5167
Mike Stump1eb44332009-09-09 15:08:12 +00005168template<typename Derived>
5169Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005170TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005171 // FIXME: poor source location
5172 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5173 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5174 if (EncodedType.isNull())
5175 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005176
Douglas Gregorb98b1992009-08-11 05:31:07 +00005177 if (!getDerived().AlwaysRebuild() &&
5178 EncodedType == E->getEncodedType())
Mike Stump1eb44332009-09-09 15:08:12 +00005179 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005180
5181 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5182 EncodedType,
5183 E->getRParenLoc());
5184}
Mike Stump1eb44332009-09-09 15:08:12 +00005185
Douglas Gregorb98b1992009-08-11 05:31:07 +00005186template<typename Derived>
5187Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005188TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005189 // FIXME: Implement this!
5190 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005191 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005192}
5193
Mike Stump1eb44332009-09-09 15:08:12 +00005194template<typename Derived>
5195Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005196TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
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>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005203 ObjCProtocolDecl *Protocol
Douglas Gregorb98b1992009-08-11 05:31:07 +00005204 = cast_or_null<ObjCProtocolDecl>(
5205 getDerived().TransformDecl(E->getProtocol()));
5206 if (!Protocol)
5207 return SemaRef.ExprError();
5208
5209 if (!getDerived().AlwaysRebuild() &&
5210 Protocol == E->getProtocol())
Mike Stump1eb44332009-09-09 15:08:12 +00005211 return SemaRef.Owned(E->Retain());
5212
Douglas Gregorb98b1992009-08-11 05:31:07 +00005213 return getDerived().RebuildObjCProtocolExpr(Protocol,
5214 E->getAtLoc(),
5215 /*FIXME:*/E->getAtLoc(),
5216 /*FIXME:*/E->getAtLoc(),
5217 E->getRParenLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00005218
Douglas Gregorb98b1992009-08-11 05:31:07 +00005219}
5220
Mike Stump1eb44332009-09-09 15:08:12 +00005221template<typename Derived>
5222Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005223TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005224 // FIXME: Implement this!
5225 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005226 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005227}
5228
Mike Stump1eb44332009-09-09 15:08:12 +00005229template<typename Derived>
5230Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005231TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005232 // FIXME: Implement this!
5233 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005234 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005235}
5236
Mike Stump1eb44332009-09-09 15:08:12 +00005237template<typename Derived>
5238Sema::OwningExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00005239TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00005240 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005241 // FIXME: Implement this!
5242 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005243 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005244}
5245
Mike Stump1eb44332009-09-09 15:08:12 +00005246template<typename Derived>
5247Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005248TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005249 // FIXME: Implement this!
5250 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005251 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005252}
5253
Mike Stump1eb44332009-09-09 15:08:12 +00005254template<typename Derived>
5255Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005256TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005257 // FIXME: Implement this!
5258 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005259 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005260}
5261
Mike Stump1eb44332009-09-09 15:08:12 +00005262template<typename Derived>
5263Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005264TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005265 bool ArgumentChanged = false;
5266 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5267 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5268 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5269 if (SubExpr.isInvalid())
5270 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005271
Douglas Gregorb98b1992009-08-11 05:31:07 +00005272 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5273 SubExprs.push_back(SubExpr.takeAs<Expr>());
5274 }
Mike Stump1eb44332009-09-09 15:08:12 +00005275
Douglas Gregorb98b1992009-08-11 05:31:07 +00005276 if (!getDerived().AlwaysRebuild() &&
5277 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005278 return SemaRef.Owned(E->Retain());
5279
Douglas Gregorb98b1992009-08-11 05:31:07 +00005280 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5281 move_arg(SubExprs),
5282 E->getRParenLoc());
5283}
5284
Mike Stump1eb44332009-09-09 15:08:12 +00005285template<typename Derived>
5286Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005287TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005288 // FIXME: Implement this!
5289 assert(false && "Cannot transform block expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005290 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005291}
5292
Mike Stump1eb44332009-09-09 15:08:12 +00005293template<typename Derived>
5294Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005295TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005296 // FIXME: Implement this!
5297 assert(false && "Cannot transform block-related expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005298 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005299}
Mike Stump1eb44332009-09-09 15:08:12 +00005300
Douglas Gregorb98b1992009-08-11 05:31:07 +00005301//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00005302// Type reconstruction
5303//===----------------------------------------------------------------------===//
5304
Mike Stump1eb44332009-09-09 15:08:12 +00005305template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005306QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5307 SourceLocation Star) {
5308 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005309 getDerived().getBaseEntity());
5310}
5311
Mike Stump1eb44332009-09-09 15:08:12 +00005312template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005313QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5314 SourceLocation Star) {
5315 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005316 getDerived().getBaseEntity());
5317}
5318
Mike Stump1eb44332009-09-09 15:08:12 +00005319template<typename Derived>
5320QualType
John McCall85737a72009-10-30 00:06:24 +00005321TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5322 bool WrittenAsLValue,
5323 SourceLocation Sigil) {
5324 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5325 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005326}
5327
5328template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005329QualType
John McCall85737a72009-10-30 00:06:24 +00005330TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5331 QualType ClassType,
5332 SourceLocation Sigil) {
John McCall0953e762009-09-24 19:53:00 +00005333 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall85737a72009-10-30 00:06:24 +00005334 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005335}
5336
5337template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005338QualType
John McCall85737a72009-10-30 00:06:24 +00005339TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5340 SourceLocation Sigil) {
5341 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCalla2becad2009-10-21 00:40:46 +00005342 getDerived().getBaseEntity());
5343}
5344
5345template<typename Derived>
5346QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00005347TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5348 ArrayType::ArraySizeModifier SizeMod,
5349 const llvm::APInt *Size,
5350 Expr *SizeExpr,
5351 unsigned IndexTypeQuals,
5352 SourceRange BracketsRange) {
5353 if (SizeExpr || !Size)
5354 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5355 IndexTypeQuals, BracketsRange,
5356 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00005357
5358 QualType Types[] = {
5359 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5360 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5361 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00005362 };
5363 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5364 QualType SizeType;
5365 for (unsigned I = 0; I != NumTypes; ++I)
5366 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5367 SizeType = Types[I];
5368 break;
5369 }
Mike Stump1eb44332009-09-09 15:08:12 +00005370
Douglas Gregor577f75a2009-08-04 16:50:30 +00005371 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005372 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005373 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00005374 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005375}
Mike Stump1eb44332009-09-09 15:08:12 +00005376
Douglas Gregor577f75a2009-08-04 16:50:30 +00005377template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005378QualType
5379TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005380 ArrayType::ArraySizeModifier SizeMod,
5381 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00005382 unsigned IndexTypeQuals,
5383 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005384 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00005385 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005386}
5387
5388template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005389QualType
Mike Stump1eb44332009-09-09 15:08:12 +00005390TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005391 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00005392 unsigned IndexTypeQuals,
5393 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005394 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00005395 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005396}
Mike Stump1eb44332009-09-09 15:08:12 +00005397
Douglas Gregor577f75a2009-08-04 16:50:30 +00005398template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005399QualType
5400TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005401 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005402 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005403 unsigned IndexTypeQuals,
5404 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005405 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005406 SizeExpr.takeAs<Expr>(),
5407 IndexTypeQuals, BracketsRange);
5408}
5409
5410template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005411QualType
5412TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005413 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005414 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005415 unsigned IndexTypeQuals,
5416 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005417 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005418 SizeExpr.takeAs<Expr>(),
5419 IndexTypeQuals, BracketsRange);
5420}
5421
5422template<typename Derived>
5423QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
5424 unsigned NumElements) {
5425 // FIXME: semantic checking!
5426 return SemaRef.Context.getVectorType(ElementType, NumElements);
5427}
Mike Stump1eb44332009-09-09 15:08:12 +00005428
Douglas Gregor577f75a2009-08-04 16:50:30 +00005429template<typename Derived>
5430QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5431 unsigned NumElements,
5432 SourceLocation AttributeLoc) {
5433 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5434 NumElements, true);
5435 IntegerLiteral *VectorSize
Mike Stump1eb44332009-09-09 15:08:12 +00005436 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005437 AttributeLoc);
5438 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5439 AttributeLoc);
5440}
Mike Stump1eb44332009-09-09 15:08:12 +00005441
Douglas Gregor577f75a2009-08-04 16:50:30 +00005442template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005443QualType
5444TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005445 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005446 SourceLocation AttributeLoc) {
5447 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5448}
Mike Stump1eb44332009-09-09 15:08:12 +00005449
Douglas Gregor577f75a2009-08-04 16:50:30 +00005450template<typename Derived>
5451QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00005452 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005453 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00005454 bool Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005455 unsigned Quals) {
Mike Stump1eb44332009-09-09 15:08:12 +00005456 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005457 Quals,
5458 getDerived().getBaseLocation(),
5459 getDerived().getBaseEntity());
5460}
Mike Stump1eb44332009-09-09 15:08:12 +00005461
Douglas Gregor577f75a2009-08-04 16:50:30 +00005462template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005463QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5464 return SemaRef.Context.getFunctionNoProtoType(T);
5465}
5466
5467template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00005468QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5469 assert(D && "no decl found");
5470 if (D->isInvalidDecl()) return QualType();
5471
5472 TypeDecl *Ty;
5473 if (isa<UsingDecl>(D)) {
5474 UsingDecl *Using = cast<UsingDecl>(D);
5475 assert(Using->isTypeName() &&
5476 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5477
5478 // A valid resolved using typename decl points to exactly one type decl.
5479 assert(++Using->shadow_begin() == Using->shadow_end());
5480 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5481
5482 } else {
5483 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5484 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5485 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5486 }
5487
5488 return SemaRef.Context.getTypeDeclType(Ty);
5489}
5490
5491template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00005492QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005493 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5494}
5495
5496template<typename Derived>
5497QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5498 return SemaRef.Context.getTypeOfType(Underlying);
5499}
5500
5501template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00005502QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005503 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5504}
5505
5506template<typename Derived>
5507QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00005508 TemplateName Template,
5509 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00005510 const TemplateArgumentListInfo &TemplateArgs) {
5511 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005512}
Mike Stump1eb44332009-09-09 15:08:12 +00005513
Douglas Gregordcee1a12009-08-06 05:28:30 +00005514template<typename Derived>
5515NestedNameSpecifier *
5516TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5517 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00005518 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00005519 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00005520 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00005521 CXXScopeSpec SS;
5522 // FIXME: The source location information is all wrong.
5523 SS.setRange(Range);
5524 SS.setScopeRep(Prefix);
5525 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00005526 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00005527 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00005528 ObjectType,
5529 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00005530 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00005531}
5532
5533template<typename Derived>
5534NestedNameSpecifier *
5535TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5536 SourceRange Range,
5537 NamespaceDecl *NS) {
5538 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5539}
5540
5541template<typename Derived>
5542NestedNameSpecifier *
5543TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5544 SourceRange Range,
5545 bool TemplateKW,
5546 QualType T) {
5547 if (T->isDependentType() || T->isRecordType() ||
5548 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00005549 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00005550 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5551 T.getTypePtr());
5552 }
Mike Stump1eb44332009-09-09 15:08:12 +00005553
Douglas Gregordcee1a12009-08-06 05:28:30 +00005554 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5555 return 0;
5556}
Mike Stump1eb44332009-09-09 15:08:12 +00005557
Douglas Gregord1067e52009-08-06 06:41:21 +00005558template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005559TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00005560TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5561 bool TemplateKW,
5562 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00005563 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00005564 Template);
5565}
5566
5567template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005568TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00005569TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005570 const IdentifierInfo &II,
5571 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00005572 CXXScopeSpec SS;
5573 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump1eb44332009-09-09 15:08:12 +00005574 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00005575 UnqualifiedId Name;
5576 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005577 return getSema().ActOnDependentTemplateName(
5578 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005579 SS,
Douglas Gregor014e88d2009-11-03 23:16:33 +00005580 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00005581 ObjectType.getAsOpaquePtr(),
5582 /*EnteringContext=*/false)
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005583 .template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00005584}
Mike Stump1eb44332009-09-09 15:08:12 +00005585
Douglas Gregorb98b1992009-08-11 05:31:07 +00005586template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00005587TemplateName
5588TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5589 OverloadedOperatorKind Operator,
5590 QualType ObjectType) {
5591 CXXScopeSpec SS;
5592 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5593 SS.setScopeRep(Qualifier);
5594 UnqualifiedId Name;
5595 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5596 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5597 Operator, SymbolLocations);
5598 return getSema().ActOnDependentTemplateName(
5599 /*FIXME:*/getDerived().getBaseLocation(),
5600 SS,
5601 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00005602 ObjectType.getAsOpaquePtr(),
5603 /*EnteringContext=*/false)
Douglas Gregorca1bdd72009-11-04 00:56:37 +00005604 .template getAsVal<TemplateName>();
5605}
5606
5607template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005608Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005609TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5610 SourceLocation OpLoc,
5611 ExprArg Callee,
5612 ExprArg First,
5613 ExprArg Second) {
5614 Expr *FirstExpr = (Expr *)First.get();
5615 Expr *SecondExpr = (Expr *)Second.get();
John McCallba135432009-11-21 08:51:07 +00005616 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005617 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00005618
Douglas Gregorb98b1992009-08-11 05:31:07 +00005619 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00005620 if (Op == OO_Subscript) {
5621 if (!FirstExpr->getType()->isOverloadableType() &&
5622 !SecondExpr->getType()->isOverloadableType())
5623 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCallba135432009-11-21 08:51:07 +00005624 CalleeExpr->getLocStart(),
Sebastian Redlf322ed62009-10-29 20:17:01 +00005625 move(Second), OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00005626 } else if (Op == OO_Arrow) {
5627 // -> is never a builtin operation.
5628 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redlf322ed62009-10-29 20:17:01 +00005629 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005630 if (!FirstExpr->getType()->isOverloadableType()) {
5631 // The argument is not of overloadable type, so try to create a
5632 // built-in unary operation.
Mike Stump1eb44332009-09-09 15:08:12 +00005633 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005634 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00005635
Douglas Gregorb98b1992009-08-11 05:31:07 +00005636 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5637 }
5638 } else {
Mike Stump1eb44332009-09-09 15:08:12 +00005639 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005640 !SecondExpr->getType()->isOverloadableType()) {
5641 // Neither of the arguments is an overloadable type, so try to
5642 // create a built-in binary operation.
5643 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00005644 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00005645 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5646 if (Result.isInvalid())
5647 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005648
Douglas Gregorb98b1992009-08-11 05:31:07 +00005649 First.release();
5650 Second.release();
5651 return move(Result);
5652 }
5653 }
Mike Stump1eb44332009-09-09 15:08:12 +00005654
5655 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00005656 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00005657 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00005658
John McCallba135432009-11-21 08:51:07 +00005659 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5660 assert(ULE->requiresADL());
5661
5662 // FIXME: Do we have to check
5663 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00005664 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00005665 } else {
John McCall6e266892010-01-26 03:27:55 +00005666 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCallba135432009-11-21 08:51:07 +00005667 }
Mike Stump1eb44332009-09-09 15:08:12 +00005668
Douglas Gregorb98b1992009-08-11 05:31:07 +00005669 // Add any functions found via argument-dependent lookup.
5670 Expr *Args[2] = { FirstExpr, SecondExpr };
5671 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00005672
Douglas Gregorb98b1992009-08-11 05:31:07 +00005673 // Create the overloaded operator invocation for unary operators.
5674 if (NumArgs == 1 || isPostIncDec) {
Mike Stump1eb44332009-09-09 15:08:12 +00005675 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005676 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5677 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5678 }
Mike Stump1eb44332009-09-09 15:08:12 +00005679
Sebastian Redlf322ed62009-10-29 20:17:01 +00005680 if (Op == OO_Subscript)
John McCallba135432009-11-21 08:51:07 +00005681 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5682 OpLoc,
5683 move(First),
5684 move(Second));
Sebastian Redlf322ed62009-10-29 20:17:01 +00005685
Douglas Gregorb98b1992009-08-11 05:31:07 +00005686 // Create the overloaded operator invocation for binary operators.
Mike Stump1eb44332009-09-09 15:08:12 +00005687 BinaryOperator::Opcode Opc =
Douglas Gregorb98b1992009-08-11 05:31:07 +00005688 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00005689 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00005690 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5691 if (Result.isInvalid())
5692 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005693
Douglas Gregorb98b1992009-08-11 05:31:07 +00005694 First.release();
5695 Second.release();
Mike Stump1eb44332009-09-09 15:08:12 +00005696 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005697}
Mike Stump1eb44332009-09-09 15:08:12 +00005698
Douglas Gregor577f75a2009-08-04 16:50:30 +00005699} // end namespace clang
5700
5701#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H