blob: d6f3352266aa896101e2fd1fc26f7a6d3d25087b [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.
Douglas Gregor124b8782010-02-16 19:09:40 +0000194 QualType TransformType(QualType T, QualType ObjectType = QualType());
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.
Douglas Gregor124b8782010-02-16 19:09:40 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
205 QualType ObjectType = QualType());
John McCalla2becad2009-10-21 00:40:46 +0000206
207 /// \brief Transform the given type-with-location into a new
208 /// type, collecting location information in the given builder
209 /// as necessary.
210 ///
Douglas Gregor124b8782010-02-16 19:09:40 +0000211 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
212 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000213
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000214 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000215 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000216 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000217 /// appropriate TransformXXXStmt function to transform a specific kind of
218 /// statement or the TransformExpr() function to transform an expression.
219 /// Subclasses may override this function to transform statements using some
220 /// other mechanism.
221 ///
222 /// \returns the transformed statement.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000223 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000224
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000225 /// \brief Transform the given expression.
226 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000227 /// By default, this routine transforms an expression by delegating to the
228 /// appropriate TransformXXXExpr function to build a new expression.
229 /// Subclasses may override this function to transform expressions using some
230 /// other mechanism.
231 ///
232 /// \returns the transformed expression.
John McCall454feb92009-12-08 09:21:05 +0000233 OwningExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000234
Douglas Gregor577f75a2009-08-04 16:50:30 +0000235 /// \brief Transform the given declaration, which is referenced from a type
236 /// or expression.
237 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000238 /// By default, acts as the identity function on declarations. Subclasses
239 /// may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000240 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000241
242 /// \brief Transform the definition of the given declaration.
243 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000244 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000245 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000246 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +0000247 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000248 }
Mike Stump1eb44332009-09-09 15:08:12 +0000249
Douglas Gregor6cd21982009-10-20 05:58:46 +0000250 /// \brief Transform the given declaration, which was the first part of a
251 /// nested-name-specifier in a member access expression.
252 ///
253 /// This specific declaration transformation only applies to the first
254 /// identifier in a nested-name-specifier of a member access expression, e.g.,
255 /// the \c T in \c x->T::member
256 ///
257 /// By default, invokes TransformDecl() to transform the declaration.
258 /// Subclasses may override this function to provide alternate behavior.
259 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000260 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000261 }
262
Douglas Gregor577f75a2009-08-04 16:50:30 +0000263 /// \brief Transform the given nested-name-specifier.
264 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000265 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000266 /// nested-name-specifier. Subclasses may override this function to provide
267 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000268 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000269 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000270 QualType ObjectType = QualType(),
271 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000272
Douglas Gregor81499bb2009-09-03 22:13:48 +0000273 /// \brief Transform the given declaration name.
274 ///
275 /// By default, transforms the types of conversion function, constructor,
276 /// and destructor names and then (if needed) rebuilds the declaration name.
277 /// Identifiers and selectors are returned unmodified. Sublcasses may
278 /// override this function to provide alternate behavior.
279 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +0000280 SourceLocation Loc,
281 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000282
Douglas Gregor577f75a2009-08-04 16:50:30 +0000283 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000284 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000285 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000286 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000287 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000288 TemplateName TransformTemplateName(TemplateName Name,
289 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000290
Douglas Gregor577f75a2009-08-04 16:50:30 +0000291 /// \brief Transform the given template argument.
292 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000293 /// By default, this operation transforms the type, expression, or
294 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000295 /// new template argument from the transformed result. Subclasses may
296 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000297 ///
298 /// Returns true if there was an error.
299 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
300 TemplateArgumentLoc &Output);
301
302 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
303 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
304 TemplateArgumentLoc &ArgLoc);
305
John McCalla93c9342009-12-07 02:54:59 +0000306 /// \brief Fakes up a TypeSourceInfo for a type.
307 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
308 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000309 getDerived().getBaseLocation());
310 }
Mike Stump1eb44332009-09-09 15:08:12 +0000311
John McCalla2becad2009-10-21 00:40:46 +0000312#define ABSTRACT_TYPELOC(CLASS, PARENT)
313#define TYPELOC(CLASS, PARENT) \
Douglas Gregor124b8782010-02-16 19:09:40 +0000314 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
315 QualType ObjectType = QualType());
John McCalla2becad2009-10-21 00:40:46 +0000316#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000317
John McCall21ef0fa2010-03-11 09:03:00 +0000318 /// \brief Transforms the parameters of a function type into the
319 /// given vectors.
320 ///
321 /// The result vectors should be kept in sync; null entries in the
322 /// variables vector are acceptable.
323 ///
324 /// Return true on error.
325 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
326 llvm::SmallVectorImpl<QualType> &PTypes,
327 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
328
329 /// \brief Transforms a single function-type parameter. Return null
330 /// on error.
331 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
332
Douglas Gregor124b8782010-02-16 19:09:40 +0000333 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
334 QualType ObjectType);
John McCall85737a72009-10-30 00:06:24 +0000335
Douglas Gregordd62b152009-10-19 22:04:39 +0000336 QualType
337 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
338 QualType ObjectType);
John McCall833ca992009-10-29 08:12:44 +0000339
Douglas Gregor43959a92009-08-20 07:17:43 +0000340 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Mike Stump1eb44332009-09-09 15:08:12 +0000341
Douglas Gregor43959a92009-08-20 07:17:43 +0000342#define STMT(Node, Parent) \
343 OwningStmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000344#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +0000345 OwningExprResult Transform##Node(Node *E);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000346#define ABSTRACT_EXPR(Node, Parent)
347#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +0000348
Douglas Gregor577f75a2009-08-04 16:50:30 +0000349 /// \brief Build a new pointer type given its pointee type.
350 ///
351 /// By default, performs semantic analysis when building the pointer type.
352 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000353 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000354
355 /// \brief Build a new block pointer type given its pointee type.
356 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000357 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000358 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000359 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000360
John McCall85737a72009-10-30 00:06:24 +0000361 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000362 ///
John McCall85737a72009-10-30 00:06:24 +0000363 /// By default, performs semantic analysis when building the
364 /// reference type. Subclasses may override this routine to provide
365 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000366 ///
John McCall85737a72009-10-30 00:06:24 +0000367 /// \param LValue whether the type was written with an lvalue sigil
368 /// or an rvalue sigil.
369 QualType RebuildReferenceType(QualType ReferentType,
370 bool LValue,
371 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000372
Douglas Gregor577f75a2009-08-04 16:50:30 +0000373 /// \brief Build a new member pointer type given the pointee type and the
374 /// class type it refers into.
375 ///
376 /// By default, performs semantic analysis when building the member pointer
377 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000378 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
379 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000380
John McCalla2becad2009-10-21 00:40:46 +0000381 /// \brief Build a new Objective C object pointer type.
John McCall85737a72009-10-30 00:06:24 +0000382 QualType RebuildObjCObjectPointerType(QualType PointeeType,
383 SourceLocation Sigil);
John McCalla2becad2009-10-21 00:40:46 +0000384
Douglas Gregor577f75a2009-08-04 16:50:30 +0000385 /// \brief Build a new array type given the element type, size
386 /// modifier, size of the array (if known), size expression, and index type
387 /// qualifiers.
388 ///
389 /// By default, performs semantic analysis when building the array type.
390 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000391 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000392 QualType RebuildArrayType(QualType ElementType,
393 ArrayType::ArraySizeModifier SizeMod,
394 const llvm::APInt *Size,
395 Expr *SizeExpr,
396 unsigned IndexTypeQuals,
397 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000398
Douglas Gregor577f75a2009-08-04 16:50:30 +0000399 /// \brief Build a new constant array type given the element type, size
400 /// modifier, (known) size of the array, and index type qualifiers.
401 ///
402 /// By default, performs semantic analysis when building the array type.
403 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000404 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000405 ArrayType::ArraySizeModifier SizeMod,
406 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000407 unsigned IndexTypeQuals,
408 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000409
Douglas Gregor577f75a2009-08-04 16:50:30 +0000410 /// \brief Build a new incomplete array type given the element type, size
411 /// modifier, and index type qualifiers.
412 ///
413 /// By default, performs semantic analysis when building the array type.
414 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000415 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000416 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000417 unsigned IndexTypeQuals,
418 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000419
Mike Stump1eb44332009-09-09 15:08:12 +0000420 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000421 /// size modifier, size expression, and index type qualifiers.
422 ///
423 /// By default, performs semantic analysis when building the array type.
424 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000425 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000426 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000427 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000428 unsigned IndexTypeQuals,
429 SourceRange BracketsRange);
430
Mike Stump1eb44332009-09-09 15:08:12 +0000431 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000432 /// size modifier, size expression, and index type qualifiers.
433 ///
434 /// By default, performs semantic analysis when building the array type.
435 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000436 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000437 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000438 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000439 unsigned IndexTypeQuals,
440 SourceRange BracketsRange);
441
442 /// \brief Build a new vector type given the element type and
443 /// number of elements.
444 ///
445 /// By default, performs semantic analysis when building the vector type.
446 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000447 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
448 bool IsAltiVec, bool IsPixel);
Mike Stump1eb44332009-09-09 15:08:12 +0000449
Douglas Gregor577f75a2009-08-04 16:50:30 +0000450 /// \brief Build a new extended vector type given the element type and
451 /// number of elements.
452 ///
453 /// By default, performs semantic analysis when building the vector type.
454 /// Subclasses may override this routine to provide different behavior.
455 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
456 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000457
458 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000459 /// given the element type and number of elements.
460 ///
461 /// By default, performs semantic analysis when building the vector type.
462 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000463 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000464 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000465 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000466
Douglas Gregor577f75a2009-08-04 16:50:30 +0000467 /// \brief Build a new function type.
468 ///
469 /// By default, performs semantic analysis when building the function type.
470 /// Subclasses may override this routine to provide different behavior.
471 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000472 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000473 unsigned NumParamTypes,
474 bool Variadic, unsigned Quals);
Mike Stump1eb44332009-09-09 15:08:12 +0000475
John McCalla2becad2009-10-21 00:40:46 +0000476 /// \brief Build a new unprototyped function type.
477 QualType RebuildFunctionNoProtoType(QualType ResultType);
478
John McCalled976492009-12-04 22:46:56 +0000479 /// \brief Rebuild an unresolved typename type, given the decl that
480 /// the UnresolvedUsingTypenameDecl was transformed to.
481 QualType RebuildUnresolvedUsingType(Decl *D);
482
Douglas Gregor577f75a2009-08-04 16:50:30 +0000483 /// \brief Build a new typedef type.
484 QualType RebuildTypedefType(TypedefDecl *Typedef) {
485 return SemaRef.Context.getTypeDeclType(Typedef);
486 }
487
488 /// \brief Build a new class/struct/union type.
489 QualType RebuildRecordType(RecordDecl *Record) {
490 return SemaRef.Context.getTypeDeclType(Record);
491 }
492
493 /// \brief Build a new Enum type.
494 QualType RebuildEnumType(EnumDecl *Enum) {
495 return SemaRef.Context.getTypeDeclType(Enum);
496 }
John McCall7da24312009-09-05 00:15:47 +0000497
498 /// \brief Build a new elaborated type.
499 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
500 return SemaRef.Context.getElaboratedType(T, Tag);
501 }
Mike Stump1eb44332009-09-09 15:08:12 +0000502
503 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000504 ///
505 /// By default, performs semantic analysis when building the typeof type.
506 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000507 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000508
Mike Stump1eb44332009-09-09 15:08:12 +0000509 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000510 ///
511 /// By default, builds a new TypeOfType with the given underlying type.
512 QualType RebuildTypeOfType(QualType Underlying);
513
Mike Stump1eb44332009-09-09 15:08:12 +0000514 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000515 ///
516 /// By default, performs semantic analysis when building the decltype type.
517 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000518 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump1eb44332009-09-09 15:08:12 +0000519
Douglas Gregor577f75a2009-08-04 16:50:30 +0000520 /// \brief Build a new template specialization type.
521 ///
522 /// By default, performs semantic analysis when building the template
523 /// specialization type. Subclasses may override this routine to provide
524 /// different behavior.
525 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000526 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000527 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000528
Douglas Gregor577f75a2009-08-04 16:50:30 +0000529 /// \brief Build a new qualified name type.
530 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000531 /// By default, builds a new QualifiedNameType type from the
532 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregor577f75a2009-08-04 16:50:30 +0000533 /// this routine to provide different behavior.
534 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
535 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000536 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000537
538 /// \brief Build a new typename type that refers to a template-id.
539 ///
540 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump1eb44332009-09-09 15:08:12 +0000541 /// and the given type. Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000542 /// different behavior.
543 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
Douglas Gregorae628892010-02-13 06:05:33 +0000544 if (NNS->isDependent()) {
545 CXXScopeSpec SS;
546 SS.setScopeRep(NNS);
547 if (!SemaRef.computeDeclContext(SS))
548 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000549 cast<TemplateSpecializationType>(T));
Douglas Gregorae628892010-02-13 06:05:33 +0000550 }
Mike Stump1eb44332009-09-09 15:08:12 +0000551
Douglas Gregor577f75a2009-08-04 16:50:30 +0000552 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000553 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000554
555 /// \brief Build a new typename type that refers to an identifier.
556 ///
557 /// By default, performs semantic analysis when building the typename type
Mike Stump1eb44332009-09-09 15:08:12 +0000558 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000559 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000560 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall833ca992009-10-29 08:12:44 +0000561 const IdentifierInfo *Id,
562 SourceRange SR) {
563 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000564 }
Mike Stump1eb44332009-09-09 15:08:12 +0000565
Douglas Gregordcee1a12009-08-06 05:28:30 +0000566 /// \brief Build a new nested-name-specifier given the prefix and an
567 /// identifier that names the next step in the nested-name-specifier.
568 ///
569 /// By default, performs semantic analysis when building the new
570 /// nested-name-specifier. Subclasses may override this routine to provide
571 /// different behavior.
572 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
573 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000574 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000575 QualType ObjectType,
576 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000577
578 /// \brief Build a new nested-name-specifier given the prefix and the
579 /// namespace named in the next step in the nested-name-specifier.
580 ///
581 /// By default, performs semantic analysis when building the new
582 /// nested-name-specifier. Subclasses may override this routine to provide
583 /// different behavior.
584 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
585 SourceRange Range,
586 NamespaceDecl *NS);
587
588 /// \brief Build a new nested-name-specifier given the prefix and the
589 /// type named in the next step in the nested-name-specifier.
590 ///
591 /// By default, performs semantic analysis when building the new
592 /// nested-name-specifier. Subclasses may override this routine to provide
593 /// different behavior.
594 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
595 SourceRange Range,
596 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000597 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000598
599 /// \brief Build a new template name given a nested name specifier, a flag
600 /// indicating whether the "template" keyword was provided, and the template
601 /// that the template name refers to.
602 ///
603 /// By default, builds the new template name directly. Subclasses may override
604 /// this routine to provide different behavior.
605 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
606 bool TemplateKW,
607 TemplateDecl *Template);
608
Douglas Gregord1067e52009-08-06 06:41:21 +0000609 /// \brief Build a new template name given a nested name specifier and the
610 /// name that is referred to as a template.
611 ///
612 /// By default, performs semantic analysis to determine whether the name can
613 /// be resolved to a specific template, then builds the appropriate kind of
614 /// template name. Subclasses may override this routine to provide different
615 /// behavior.
616 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000617 const IdentifierInfo &II,
618 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000619
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000620 /// \brief Build a new template name given a nested name specifier and the
621 /// overloaded operator name that is referred to as a template.
622 ///
623 /// By default, performs semantic analysis to determine whether the name can
624 /// be resolved to a specific template, then builds the appropriate kind of
625 /// template name. Subclasses may override this routine to provide different
626 /// behavior.
627 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
628 OverloadedOperatorKind Operator,
629 QualType ObjectType);
630
Douglas Gregor43959a92009-08-20 07:17:43 +0000631 /// \brief Build a new compound statement.
632 ///
633 /// By default, performs semantic analysis to build the new statement.
634 /// Subclasses may override this routine to provide different behavior.
635 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
636 MultiStmtArg Statements,
637 SourceLocation RBraceLoc,
638 bool IsStmtExpr) {
639 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
640 IsStmtExpr);
641 }
642
643 /// \brief Build a new case statement.
644 ///
645 /// By default, performs semantic analysis to build the new statement.
646 /// Subclasses may override this routine to provide different behavior.
647 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
648 ExprArg LHS,
649 SourceLocation EllipsisLoc,
650 ExprArg RHS,
651 SourceLocation ColonLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000652 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregor43959a92009-08-20 07:17:43 +0000653 ColonLoc);
654 }
Mike Stump1eb44332009-09-09 15:08:12 +0000655
Douglas Gregor43959a92009-08-20 07:17:43 +0000656 /// \brief Attach the body to a new case statement.
657 ///
658 /// By default, performs semantic analysis to build the new statement.
659 /// Subclasses may override this routine to provide different behavior.
660 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
661 getSema().ActOnCaseStmtBody(S.get(), move(Body));
662 return move(S);
663 }
Mike Stump1eb44332009-09-09 15:08:12 +0000664
Douglas Gregor43959a92009-08-20 07:17:43 +0000665 /// \brief Build a new default statement.
666 ///
667 /// By default, performs semantic analysis to build the new statement.
668 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000669 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000670 SourceLocation ColonLoc,
671 StmtArg SubStmt) {
Mike Stump1eb44332009-09-09 15:08:12 +0000672 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregor43959a92009-08-20 07:17:43 +0000673 /*CurScope=*/0);
674 }
Mike Stump1eb44332009-09-09 15:08:12 +0000675
Douglas Gregor43959a92009-08-20 07:17:43 +0000676 /// \brief Build a new label statement.
677 ///
678 /// By default, performs semantic analysis to build the new statement.
679 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000680 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000681 IdentifierInfo *Id,
682 SourceLocation ColonLoc,
683 StmtArg SubStmt) {
684 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
685 }
Mike Stump1eb44332009-09-09 15:08:12 +0000686
Douglas Gregor43959a92009-08-20 07:17:43 +0000687 /// \brief Build a new "if" statement.
688 ///
689 /// By default, performs semantic analysis to build the new statement.
690 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000691 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000692 VarDecl *CondVar, StmtArg Then,
693 SourceLocation ElseLoc, StmtArg Else) {
694 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
695 move(Then), ElseLoc, move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +0000696 }
Mike Stump1eb44332009-09-09 15:08:12 +0000697
Douglas Gregor43959a92009-08-20 07:17:43 +0000698 /// \brief Start building a new switch statement.
699 ///
700 /// By default, performs semantic analysis to build the new statement.
701 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000702 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
703 VarDecl *CondVar) {
704 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregor43959a92009-08-20 07:17:43 +0000705 }
Mike Stump1eb44332009-09-09 15:08:12 +0000706
Douglas Gregor43959a92009-08-20 07:17:43 +0000707 /// \brief Attach the body to the switch statement.
708 ///
709 /// By default, performs semantic analysis to build the new statement.
710 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000711 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000712 StmtArg Switch, StmtArg Body) {
713 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
714 move(Body));
715 }
716
717 /// \brief Build a new while statement.
718 ///
719 /// By default, performs semantic analysis to build the new statement.
720 /// Subclasses may override this routine to provide different behavior.
721 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
722 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000723 VarDecl *CondVar,
Douglas Gregor43959a92009-08-20 07:17:43 +0000724 StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000725 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
726 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000727 }
Mike Stump1eb44332009-09-09 15:08:12 +0000728
Douglas Gregor43959a92009-08-20 07:17:43 +0000729 /// \brief Build a new do-while statement.
730 ///
731 /// By default, performs semantic analysis to build the new statement.
732 /// Subclasses may override this routine to provide different behavior.
733 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
734 SourceLocation WhileLoc,
735 SourceLocation LParenLoc,
736 ExprArg Cond,
737 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000738 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000739 move(Cond), RParenLoc);
740 }
741
742 /// \brief Build a new for statement.
743 ///
744 /// By default, performs semantic analysis to build the new statement.
745 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000746 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000747 SourceLocation LParenLoc,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000748 StmtArg Init, Sema::FullExprArg Cond,
749 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000750 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000751 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
752 DeclPtrTy::make(CondVar),
753 Inc, RParenLoc, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000754 }
Mike Stump1eb44332009-09-09 15:08:12 +0000755
Douglas Gregor43959a92009-08-20 07:17:43 +0000756 /// \brief Build a new goto statement.
757 ///
758 /// By default, performs semantic analysis to build the new statement.
759 /// Subclasses may override this routine to provide different behavior.
760 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
761 SourceLocation LabelLoc,
762 LabelStmt *Label) {
763 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
764 }
765
766 /// \brief Build a new indirect goto statement.
767 ///
768 /// By default, performs semantic analysis to build the new statement.
769 /// Subclasses may override this routine to provide different behavior.
770 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
771 SourceLocation StarLoc,
772 ExprArg Target) {
773 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
774 }
Mike Stump1eb44332009-09-09 15:08:12 +0000775
Douglas Gregor43959a92009-08-20 07:17:43 +0000776 /// \brief Build a new return statement.
777 ///
778 /// By default, performs semantic analysis to build the new statement.
779 /// Subclasses may override this routine to provide different behavior.
780 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
781 ExprArg Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000782
Douglas Gregor43959a92009-08-20 07:17:43 +0000783 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
784 }
Mike Stump1eb44332009-09-09 15:08:12 +0000785
Douglas Gregor43959a92009-08-20 07:17:43 +0000786 /// \brief Build a new declaration statement.
787 ///
788 /// By default, performs semantic analysis to build the new statement.
789 /// Subclasses may override this routine to provide different behavior.
790 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000791 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000792 SourceLocation EndLoc) {
793 return getSema().Owned(
794 new (getSema().Context) DeclStmt(
795 DeclGroupRef::Create(getSema().Context,
796 Decls, NumDecls),
797 StartLoc, EndLoc));
798 }
Mike Stump1eb44332009-09-09 15:08:12 +0000799
Anders Carlsson703e3942010-01-24 05:50:09 +0000800 /// \brief Build a new inline asm statement.
801 ///
802 /// By default, performs semantic analysis to build the new statement.
803 /// Subclasses may override this routine to provide different behavior.
804 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
805 bool IsSimple,
806 bool IsVolatile,
807 unsigned NumOutputs,
808 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000809 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000810 MultiExprArg Constraints,
811 MultiExprArg Exprs,
812 ExprArg AsmString,
813 MultiExprArg Clobbers,
814 SourceLocation RParenLoc,
815 bool MSAsm) {
816 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
817 NumInputs, Names, move(Constraints),
818 move(Exprs), move(AsmString), move(Clobbers),
819 RParenLoc, MSAsm);
820 }
821
Douglas Gregor43959a92009-08-20 07:17:43 +0000822 /// \brief Build a new C++ exception declaration.
823 ///
824 /// By default, performs semantic analysis to build the new decaration.
825 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000826 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000827 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000828 IdentifierInfo *Name,
829 SourceLocation Loc,
830 SourceRange TypeRange) {
Mike Stump1eb44332009-09-09 15:08:12 +0000831 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000832 TypeRange);
833 }
834
835 /// \brief Build a new C++ catch statement.
836 ///
837 /// By default, performs semantic analysis to build the new statement.
838 /// Subclasses may override this routine to provide different behavior.
839 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
840 VarDecl *ExceptionDecl,
841 StmtArg Handler) {
842 return getSema().Owned(
Mike Stump1eb44332009-09-09 15:08:12 +0000843 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregor43959a92009-08-20 07:17:43 +0000844 Handler.takeAs<Stmt>()));
845 }
Mike Stump1eb44332009-09-09 15:08:12 +0000846
Douglas Gregor43959a92009-08-20 07:17:43 +0000847 /// \brief Build a new C++ try statement.
848 ///
849 /// By default, performs semantic analysis to build the new statement.
850 /// Subclasses may override this routine to provide different behavior.
851 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
852 StmtArg TryBlock,
853 MultiStmtArg Handlers) {
854 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
855 }
Mike Stump1eb44332009-09-09 15:08:12 +0000856
Douglas Gregorb98b1992009-08-11 05:31:07 +0000857 /// \brief Build a new expression that references a declaration.
858 ///
859 /// By default, performs semantic analysis to build the new expression.
860 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +0000861 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
862 LookupResult &R,
863 bool RequiresADL) {
864 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
865 }
866
867
868 /// \brief Build a new expression that references a declaration.
869 ///
870 /// By default, performs semantic analysis to build the new expression.
871 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora2813ce2009-10-23 18:54:35 +0000872 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
873 SourceRange QualifierRange,
John McCalldbd872f2009-12-08 09:08:17 +0000874 ValueDecl *VD, SourceLocation Loc,
875 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +0000876 CXXScopeSpec SS;
877 SS.setScopeRep(Qualifier);
878 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +0000879
880 // FIXME: loses template args.
881
882 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000883 }
Mike Stump1eb44332009-09-09 15:08:12 +0000884
Douglas Gregorb98b1992009-08-11 05:31:07 +0000885 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +0000886 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000887 /// By default, performs semantic analysis to build the new expression.
888 /// Subclasses may override this routine to provide different behavior.
889 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
890 SourceLocation RParen) {
891 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
892 }
893
Douglas Gregora71d8192009-09-04 17:36:40 +0000894 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000895 ///
Douglas Gregora71d8192009-09-04 17:36:40 +0000896 /// By default, performs semantic analysis to build the new expression.
897 /// Subclasses may override this routine to provide different behavior.
898 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
899 SourceLocation OperatorLoc,
900 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000901 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +0000902 SourceRange QualifierRange,
903 TypeSourceInfo *ScopeType,
904 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +0000905 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000906 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +0000907
Douglas Gregorb98b1992009-08-11 05:31:07 +0000908 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000909 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000910 /// By default, performs semantic analysis to build the new expression.
911 /// Subclasses may override this routine to provide different behavior.
912 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
913 UnaryOperator::Opcode Opc,
914 ExprArg SubExpr) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +0000915 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +0000916 }
Mike Stump1eb44332009-09-09 15:08:12 +0000917
Douglas Gregorb98b1992009-08-11 05:31:07 +0000918 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +0000919 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000920 /// By default, performs semantic analysis to build the new expression.
921 /// Subclasses may override this routine to provide different behavior.
John McCalla93c9342009-12-07 02:54:59 +0000922 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +0000923 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000924 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +0000925 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000926 }
927
Mike Stump1eb44332009-09-09 15:08:12 +0000928 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +0000929 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +0000930 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000931 /// By default, performs semantic analysis to build the new expression.
932 /// Subclasses may override this routine to provide different behavior.
933 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
934 bool isSizeOf, SourceRange R) {
Mike Stump1eb44332009-09-09 15:08:12 +0000935 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +0000936 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
937 OpLoc, isSizeOf, R);
938 if (Result.isInvalid())
939 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +0000940
Douglas Gregorb98b1992009-08-11 05:31:07 +0000941 SubExpr.release();
942 return move(Result);
943 }
Mike Stump1eb44332009-09-09 15:08:12 +0000944
Douglas Gregorb98b1992009-08-11 05:31:07 +0000945 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000946 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000947 /// By default, performs semantic analysis to build the new expression.
948 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000949 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000950 SourceLocation LBracketLoc,
951 ExprArg RHS,
952 SourceLocation RBracketLoc) {
953 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump1eb44332009-09-09 15:08:12 +0000954 LBracketLoc, move(RHS),
Douglas Gregorb98b1992009-08-11 05:31:07 +0000955 RBracketLoc);
956 }
957
958 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000959 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000960 /// By default, performs semantic analysis to build the new expression.
961 /// Subclasses may override this routine to provide different behavior.
962 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
963 MultiExprArg Args,
964 SourceLocation *CommaLocs,
965 SourceLocation RParenLoc) {
966 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
967 move(Args), CommaLocs, RParenLoc);
968 }
969
970 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000971 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000972 /// By default, performs semantic analysis to build the new expression.
973 /// Subclasses may override this routine to provide different behavior.
974 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +0000975 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000976 NestedNameSpecifier *Qualifier,
977 SourceRange QualifierRange,
978 SourceLocation MemberLoc,
Eli Friedmanf595cc42009-12-04 06:40:45 +0000979 ValueDecl *Member,
John McCalld5532b62009-11-23 01:53:49 +0000980 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +0000981 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +0000982 if (!Member->getDeclName()) {
983 // We have a reference to an unnamed field.
984 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +0000985
Douglas Gregor83a56c42009-12-24 20:02:50 +0000986 Expr *BaseExpr = Base.takeAs<Expr>();
Douglas Gregor5fccd362010-03-03 23:55:11 +0000987 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, Member))
Douglas Gregor83a56c42009-12-24 20:02:50 +0000988 return getSema().ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +0000989
Mike Stump1eb44332009-09-09 15:08:12 +0000990 MemberExpr *ME =
Douglas Gregor83a56c42009-12-24 20:02:50 +0000991 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlssond8b285f2009-09-01 04:26:58 +0000992 Member, MemberLoc,
993 cast<FieldDecl>(Member)->getType());
994 return getSema().Owned(ME);
995 }
Mike Stump1eb44332009-09-09 15:08:12 +0000996
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000997 CXXScopeSpec SS;
998 if (Qualifier) {
999 SS.setRange(QualifierRange);
1000 SS.setScopeRep(Qualifier);
1001 }
1002
John McCallaa81e162009-12-01 22:10:20 +00001003 QualType BaseType = ((Expr*) Base.get())->getType();
1004
John McCallc2233c52010-01-15 08:34:02 +00001005 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1006 Sema::LookupMemberName);
1007 R.addDecl(Member);
1008 R.resolveKind();
1009
John McCallaa81e162009-12-01 22:10:20 +00001010 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1011 OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001012 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001013 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001014 }
Mike Stump1eb44332009-09-09 15:08:12 +00001015
Douglas Gregorb98b1992009-08-11 05:31:07 +00001016 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001017 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001018 /// By default, performs semantic analysis to build the new expression.
1019 /// Subclasses may override this routine to provide different behavior.
1020 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1021 BinaryOperator::Opcode Opc,
1022 ExprArg LHS, ExprArg RHS) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001023 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1024 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregorb98b1992009-08-11 05:31:07 +00001025 }
1026
1027 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001028 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001029 /// By default, performs semantic analysis to build the new expression.
1030 /// Subclasses may override this routine to provide different behavior.
1031 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1032 SourceLocation QuestionLoc,
1033 ExprArg LHS,
1034 SourceLocation ColonLoc,
1035 ExprArg RHS) {
Mike Stump1eb44332009-09-09 15:08:12 +00001036 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001037 move(LHS), move(RHS));
1038 }
1039
Douglas Gregorb98b1992009-08-11 05:31:07 +00001040 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001041 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001042 /// By default, performs semantic analysis to build the new expression.
1043 /// Subclasses may override this routine to provide different behavior.
John McCall9d125032010-01-15 18:39:57 +00001044 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1045 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001046 SourceLocation RParenLoc,
1047 ExprArg SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001048 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1049 move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001050 }
Mike Stump1eb44332009-09-09 15:08:12 +00001051
Douglas Gregorb98b1992009-08-11 05:31:07 +00001052 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001053 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001054 /// By default, performs semantic analysis to build the new expression.
1055 /// Subclasses may override this routine to provide different behavior.
1056 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001057 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001058 SourceLocation RParenLoc,
1059 ExprArg Init) {
John McCall42f56b52010-01-18 19:35:47 +00001060 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1061 move(Init));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001062 }
Mike Stump1eb44332009-09-09 15:08:12 +00001063
Douglas Gregorb98b1992009-08-11 05:31:07 +00001064 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001065 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001066 /// By default, performs semantic analysis to build the new expression.
1067 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001068 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001069 SourceLocation OpLoc,
1070 SourceLocation AccessorLoc,
1071 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001072
John McCall129e2df2009-11-30 22:42:35 +00001073 CXXScopeSpec SS;
John McCallaa81e162009-12-01 22:10:20 +00001074 QualType BaseType = ((Expr*) Base.get())->getType();
1075 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001076 OpLoc, /*IsArrow*/ false,
1077 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor2d1c2142009-11-03 19:44:04 +00001078 DeclarationName(&Accessor),
John McCall129e2df2009-11-30 22:42:35 +00001079 AccessorLoc,
1080 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001081 }
Mike Stump1eb44332009-09-09 15:08:12 +00001082
Douglas Gregorb98b1992009-08-11 05:31:07 +00001083 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001084 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001085 /// By default, performs semantic analysis to build the new expression.
1086 /// Subclasses may override this routine to provide different behavior.
1087 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1088 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001089 SourceLocation RBraceLoc,
1090 QualType ResultTy) {
1091 OwningExprResult Result
1092 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1093 if (Result.isInvalid() || ResultTy->isDependentType())
1094 return move(Result);
1095
1096 // Patch in the result type we were given, which may have been computed
1097 // when the initial InitListExpr was built.
1098 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1099 ILE->setType(ResultTy);
1100 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001101 }
Mike Stump1eb44332009-09-09 15:08:12 +00001102
Douglas Gregorb98b1992009-08-11 05:31:07 +00001103 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001104 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001105 /// By default, performs semantic analysis to build the new expression.
1106 /// Subclasses may override this routine to provide different behavior.
1107 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1108 MultiExprArg ArrayExprs,
1109 SourceLocation EqualOrColonLoc,
1110 bool GNUSyntax,
1111 ExprArg Init) {
1112 OwningExprResult Result
1113 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1114 move(Init));
1115 if (Result.isInvalid())
1116 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001117
Douglas Gregorb98b1992009-08-11 05:31:07 +00001118 ArrayExprs.release();
1119 return move(Result);
1120 }
Mike Stump1eb44332009-09-09 15:08:12 +00001121
Douglas Gregorb98b1992009-08-11 05:31:07 +00001122 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001123 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001124 /// By default, builds the implicit value initialization without performing
1125 /// any semantic analysis. Subclasses may override this routine to provide
1126 /// different behavior.
1127 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1128 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1129 }
Mike Stump1eb44332009-09-09 15:08:12 +00001130
Douglas Gregorb98b1992009-08-11 05:31:07 +00001131 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001132 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001133 /// By default, performs semantic analysis to build the new expression.
1134 /// Subclasses may override this routine to provide different behavior.
1135 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1136 QualType T, SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001137 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001138 RParenLoc);
1139 }
1140
1141 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001142 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001143 /// By default, performs semantic analysis to build the new expression.
1144 /// Subclasses may override this routine to provide different behavior.
1145 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1146 MultiExprArg SubExprs,
1147 SourceLocation RParenLoc) {
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001148 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1149 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001150 }
Mike Stump1eb44332009-09-09 15:08:12 +00001151
Douglas Gregorb98b1992009-08-11 05:31:07 +00001152 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001153 ///
1154 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001155 /// rather than attempting to map the label statement itself.
1156 /// Subclasses may override this routine to provide different behavior.
1157 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1158 SourceLocation LabelLoc,
1159 LabelStmt *Label) {
1160 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1161 }
Mike Stump1eb44332009-09-09 15:08:12 +00001162
Douglas Gregorb98b1992009-08-11 05:31:07 +00001163 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001164 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001165 /// By default, performs semantic analysis to build the new expression.
1166 /// Subclasses may override this routine to provide different behavior.
1167 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1168 StmtArg SubStmt,
1169 SourceLocation RParenLoc) {
1170 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1171 }
Mike Stump1eb44332009-09-09 15:08:12 +00001172
Douglas Gregorb98b1992009-08-11 05:31:07 +00001173 /// \brief Build a new __builtin_types_compatible_p expression.
1174 ///
1175 /// By default, performs semantic analysis to build the new expression.
1176 /// Subclasses may override this routine to provide different behavior.
1177 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1178 QualType T1, QualType T2,
1179 SourceLocation RParenLoc) {
1180 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1181 T1.getAsOpaquePtr(),
1182 T2.getAsOpaquePtr(),
1183 RParenLoc);
1184 }
Mike Stump1eb44332009-09-09 15:08:12 +00001185
Douglas Gregorb98b1992009-08-11 05:31:07 +00001186 /// \brief Build a new __builtin_choose_expr expression.
1187 ///
1188 /// By default, performs semantic analysis to build the new expression.
1189 /// Subclasses may override this routine to provide different behavior.
1190 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1191 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1192 SourceLocation RParenLoc) {
1193 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1194 move(Cond), move(LHS), move(RHS),
1195 RParenLoc);
1196 }
Mike Stump1eb44332009-09-09 15:08:12 +00001197
Douglas Gregorb98b1992009-08-11 05:31:07 +00001198 /// \brief Build a new overloaded operator call expression.
1199 ///
1200 /// By default, performs semantic analysis to build the new expression.
1201 /// The semantic analysis provides the behavior of template instantiation,
1202 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001203 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001204 /// argument-dependent lookup, etc. Subclasses may override this routine to
1205 /// provide different behavior.
1206 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1207 SourceLocation OpLoc,
1208 ExprArg Callee,
1209 ExprArg First,
1210 ExprArg Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001211
1212 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001213 /// reinterpret_cast.
1214 ///
1215 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001216 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001217 /// Subclasses may override this routine to provide different behavior.
1218 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1219 Stmt::StmtClass Class,
1220 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001221 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001222 SourceLocation RAngleLoc,
1223 SourceLocation LParenLoc,
1224 ExprArg SubExpr,
1225 SourceLocation RParenLoc) {
1226 switch (Class) {
1227 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001228 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001229 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001230 move(SubExpr), RParenLoc);
1231
1232 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001233 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001234 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001235 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001236
Douglas Gregorb98b1992009-08-11 05:31:07 +00001237 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001238 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001239 RAngleLoc, LParenLoc,
1240 move(SubExpr),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001241 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001242
Douglas Gregorb98b1992009-08-11 05:31:07 +00001243 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001244 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001245 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001246 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001247
Douglas Gregorb98b1992009-08-11 05:31:07 +00001248 default:
1249 assert(false && "Invalid C++ named cast");
1250 break;
1251 }
Mike Stump1eb44332009-09-09 15:08:12 +00001252
Douglas Gregorb98b1992009-08-11 05:31:07 +00001253 return getSema().ExprError();
1254 }
Mike Stump1eb44332009-09-09 15:08:12 +00001255
Douglas Gregorb98b1992009-08-11 05:31:07 +00001256 /// \brief Build a new C++ static_cast expression.
1257 ///
1258 /// By default, performs semantic analysis to build the new expression.
1259 /// Subclasses may override this routine to provide different behavior.
1260 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1261 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001262 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001263 SourceLocation RAngleLoc,
1264 SourceLocation LParenLoc,
1265 ExprArg SubExpr,
1266 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001267 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1268 TInfo, move(SubExpr),
1269 SourceRange(LAngleLoc, RAngleLoc),
1270 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001271 }
1272
1273 /// \brief Build a new C++ dynamic_cast expression.
1274 ///
1275 /// By default, performs semantic analysis to build the new expression.
1276 /// Subclasses may override this routine to provide different behavior.
1277 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1278 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001279 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001280 SourceLocation RAngleLoc,
1281 SourceLocation LParenLoc,
1282 ExprArg SubExpr,
1283 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001284 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1285 TInfo, move(SubExpr),
1286 SourceRange(LAngleLoc, RAngleLoc),
1287 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001288 }
1289
1290 /// \brief Build a new C++ reinterpret_cast expression.
1291 ///
1292 /// By default, performs semantic analysis to build the new expression.
1293 /// Subclasses may override this routine to provide different behavior.
1294 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1295 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001296 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001297 SourceLocation RAngleLoc,
1298 SourceLocation LParenLoc,
1299 ExprArg SubExpr,
1300 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001301 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1302 TInfo, move(SubExpr),
1303 SourceRange(LAngleLoc, RAngleLoc),
1304 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001305 }
1306
1307 /// \brief Build a new C++ const_cast expression.
1308 ///
1309 /// By default, performs semantic analysis to build the new expression.
1310 /// Subclasses may override this routine to provide different behavior.
1311 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1312 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001313 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001314 SourceLocation RAngleLoc,
1315 SourceLocation LParenLoc,
1316 ExprArg SubExpr,
1317 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001318 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1319 TInfo, move(SubExpr),
1320 SourceRange(LAngleLoc, RAngleLoc),
1321 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001322 }
Mike Stump1eb44332009-09-09 15:08:12 +00001323
Douglas Gregorb98b1992009-08-11 05:31:07 +00001324 /// \brief Build a new C++ functional-style cast expression.
1325 ///
1326 /// By default, performs semantic analysis to build the new expression.
1327 /// Subclasses may override this routine to provide different behavior.
1328 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001329 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001330 SourceLocation LParenLoc,
1331 ExprArg SubExpr,
1332 SourceLocation RParenLoc) {
Chris Lattner88650c32009-08-24 05:19:01 +00001333 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001334 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001335 TInfo->getType().getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001336 LParenLoc,
Chris Lattner88650c32009-08-24 05:19:01 +00001337 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump1eb44332009-09-09 15:08:12 +00001338 /*CommaLocs=*/0,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001339 RParenLoc);
1340 }
Mike Stump1eb44332009-09-09 15:08:12 +00001341
Douglas Gregorb98b1992009-08-11 05:31:07 +00001342 /// \brief Build a new C++ typeid(type) expression.
1343 ///
1344 /// By default, performs semantic analysis to build the new expression.
1345 /// Subclasses may override this routine to provide different behavior.
1346 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1347 SourceLocation LParenLoc,
1348 QualType T,
1349 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001350 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001351 T.getAsOpaquePtr(), RParenLoc);
1352 }
Mike Stump1eb44332009-09-09 15:08:12 +00001353
Douglas Gregorb98b1992009-08-11 05:31:07 +00001354 /// \brief Build a new C++ typeid(expr) expression.
1355 ///
1356 /// By default, performs semantic analysis to build the new expression.
1357 /// Subclasses may override this routine to provide different behavior.
1358 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1359 SourceLocation LParenLoc,
1360 ExprArg Operand,
1361 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001362 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001363 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1364 RParenLoc);
1365 if (Result.isInvalid())
1366 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001367
Douglas Gregorb98b1992009-08-11 05:31:07 +00001368 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1369 return move(Result);
Mike Stump1eb44332009-09-09 15:08:12 +00001370 }
1371
Douglas Gregorb98b1992009-08-11 05:31:07 +00001372 /// \brief Build a new C++ "this" expression.
1373 ///
1374 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001375 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001376 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001377 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001378 QualType ThisType,
1379 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001380 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001381 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1382 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001383 }
1384
1385 /// \brief Build a new C++ throw expression.
1386 ///
1387 /// By default, performs semantic analysis to build the new expression.
1388 /// Subclasses may override this routine to provide different behavior.
1389 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1390 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1391 }
1392
1393 /// \brief Build a new C++ default-argument expression.
1394 ///
1395 /// By default, builds a new default-argument expression, which does not
1396 /// require any semantic analysis. Subclasses may override this routine to
1397 /// provide different behavior.
Douglas Gregor036aed12009-12-23 23:03:06 +00001398 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1399 ParmVarDecl *Param) {
1400 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1401 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001402 }
1403
1404 /// \brief Build a new C++ zero-initialization expression.
1405 ///
1406 /// By default, performs semantic analysis to build the new expression.
1407 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001408 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 SourceLocation LParenLoc,
1410 QualType T,
1411 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001412 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1413 T.getAsOpaquePtr(), LParenLoc,
1414 MultiExprArg(getSema(), 0, 0),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 0, RParenLoc);
1416 }
Mike Stump1eb44332009-09-09 15:08:12 +00001417
Douglas Gregorb98b1992009-08-11 05:31:07 +00001418 /// \brief Build a new C++ "new" expression.
1419 ///
1420 /// By default, performs semantic analysis to build the new expression.
1421 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001422 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001423 bool UseGlobal,
1424 SourceLocation PlacementLParen,
1425 MultiExprArg PlacementArgs,
1426 SourceLocation PlacementRParen,
Mike Stump1eb44332009-09-09 15:08:12 +00001427 bool ParenTypeId,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001428 QualType AllocType,
1429 SourceLocation TypeLoc,
1430 SourceRange TypeRange,
1431 ExprArg ArraySize,
1432 SourceLocation ConstructorLParen,
1433 MultiExprArg ConstructorArgs,
1434 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001435 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001436 PlacementLParen,
1437 move(PlacementArgs),
1438 PlacementRParen,
1439 ParenTypeId,
1440 AllocType,
1441 TypeLoc,
1442 TypeRange,
1443 move(ArraySize),
1444 ConstructorLParen,
1445 move(ConstructorArgs),
1446 ConstructorRParen);
1447 }
Mike Stump1eb44332009-09-09 15:08:12 +00001448
Douglas Gregorb98b1992009-08-11 05:31:07 +00001449 /// \brief Build a new C++ "delete" expression.
1450 ///
1451 /// By default, performs semantic analysis to build the new expression.
1452 /// Subclasses may override this routine to provide different behavior.
1453 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1454 bool IsGlobalDelete,
1455 bool IsArrayForm,
1456 ExprArg Operand) {
1457 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1458 move(Operand));
1459 }
Mike Stump1eb44332009-09-09 15:08:12 +00001460
Douglas Gregorb98b1992009-08-11 05:31:07 +00001461 /// \brief Build a new unary type trait expression.
1462 ///
1463 /// By default, performs semantic analysis to build the new expression.
1464 /// Subclasses may override this routine to provide different behavior.
1465 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1466 SourceLocation StartLoc,
1467 SourceLocation LParenLoc,
1468 QualType T,
1469 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001470 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001471 T.getAsOpaquePtr(), RParenLoc);
1472 }
1473
Mike Stump1eb44332009-09-09 15:08:12 +00001474 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001475 /// expression.
1476 ///
1477 /// By default, performs semantic analysis to build the new expression.
1478 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001479 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 SourceRange QualifierRange,
1481 DeclarationName Name,
1482 SourceLocation Location,
John McCallf7a1a742009-11-24 19:00:30 +00001483 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 CXXScopeSpec SS;
1485 SS.setRange(QualifierRange);
1486 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001487
1488 if (TemplateArgs)
1489 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1490 *TemplateArgs);
1491
1492 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 }
1494
1495 /// \brief Build a new template-id expression.
1496 ///
1497 /// By default, performs semantic analysis to build the new expression.
1498 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001499 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1500 LookupResult &R,
1501 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001502 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001503 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001504 }
1505
1506 /// \brief Build a new object-construction expression.
1507 ///
1508 /// By default, performs semantic analysis to build the new expression.
1509 /// Subclasses may override this routine to provide different behavior.
1510 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001511 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 CXXConstructorDecl *Constructor,
1513 bool IsElidable,
1514 MultiExprArg Args) {
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001515 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1516 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1517 ConvertedArgs))
1518 return getSema().ExprError();
1519
1520 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1521 move_arg(ConvertedArgs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001522 }
1523
1524 /// \brief Build a new object-construction expression.
1525 ///
1526 /// By default, performs semantic analysis to build the new expression.
1527 /// Subclasses may override this routine to provide different behavior.
1528 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1529 QualType T,
1530 SourceLocation LParenLoc,
1531 MultiExprArg Args,
1532 SourceLocation *Commas,
1533 SourceLocation RParenLoc) {
1534 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1535 T.getAsOpaquePtr(),
1536 LParenLoc,
1537 move(Args),
1538 Commas,
1539 RParenLoc);
1540 }
1541
1542 /// \brief Build a new object-construction expression.
1543 ///
1544 /// By default, performs semantic analysis to build the new expression.
1545 /// Subclasses may override this routine to provide different behavior.
1546 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1547 QualType T,
1548 SourceLocation LParenLoc,
1549 MultiExprArg Args,
1550 SourceLocation *Commas,
1551 SourceLocation RParenLoc) {
1552 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1553 /*FIXME*/LParenLoc),
1554 T.getAsOpaquePtr(),
1555 LParenLoc,
1556 move(Args),
1557 Commas,
1558 RParenLoc);
1559 }
Mike Stump1eb44332009-09-09 15:08:12 +00001560
Douglas Gregorb98b1992009-08-11 05:31:07 +00001561 /// \brief Build a new member reference expression.
1562 ///
1563 /// By default, performs semantic analysis to build the new expression.
1564 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001565 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001566 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 bool IsArrow,
1568 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001569 NestedNameSpecifier *Qualifier,
1570 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001571 NamedDecl *FirstQualifierInScope,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001572 DeclarationName Name,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001573 SourceLocation MemberLoc,
John McCall129e2df2009-11-30 22:42:35 +00001574 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001575 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001576 SS.setRange(QualifierRange);
1577 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001578
John McCallaa81e162009-12-01 22:10:20 +00001579 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1580 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001581 SS, FirstQualifierInScope,
1582 Name, MemberLoc, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 }
1584
John McCall129e2df2009-11-30 22:42:35 +00001585 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001586 ///
1587 /// By default, performs semantic analysis to build the new expression.
1588 /// Subclasses may override this routine to provide different behavior.
John McCall129e2df2009-11-30 22:42:35 +00001589 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001590 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001591 SourceLocation OperatorLoc,
1592 bool IsArrow,
1593 NestedNameSpecifier *Qualifier,
1594 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001595 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001596 LookupResult &R,
1597 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001598 CXXScopeSpec SS;
1599 SS.setRange(QualifierRange);
1600 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001601
John McCallaa81e162009-12-01 22:10:20 +00001602 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1603 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001604 SS, FirstQualifierInScope,
1605 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001606 }
Mike Stump1eb44332009-09-09 15:08:12 +00001607
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 /// \brief Build a new Objective-C @encode expression.
1609 ///
1610 /// By default, performs semantic analysis to build the new expression.
1611 /// Subclasses may override this routine to provide different behavior.
1612 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1613 QualType T,
1614 SourceLocation RParenLoc) {
1615 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1616 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001617 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618
1619 /// \brief Build a new Objective-C protocol expression.
1620 ///
1621 /// By default, performs semantic analysis to build the new expression.
1622 /// Subclasses may override this routine to provide different behavior.
1623 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1624 SourceLocation AtLoc,
1625 SourceLocation ProtoLoc,
1626 SourceLocation LParenLoc,
1627 SourceLocation RParenLoc) {
1628 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1629 Protocol->getIdentifier(),
1630 AtLoc,
1631 ProtoLoc,
1632 LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001633 RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001634 }
Mike Stump1eb44332009-09-09 15:08:12 +00001635
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 /// \brief Build a new shuffle vector expression.
1637 ///
1638 /// By default, performs semantic analysis to build the new expression.
1639 /// Subclasses may override this routine to provide different behavior.
1640 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1641 MultiExprArg SubExprs,
1642 SourceLocation RParenLoc) {
1643 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001644 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001645 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1646 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1647 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1648 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001649
Douglas Gregorb98b1992009-08-11 05:31:07 +00001650 // Build a reference to the __builtin_shufflevector builtin
1651 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001652 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001654 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001656
1657 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 unsigned NumSubExprs = SubExprs.size();
1659 Expr **Subs = (Expr **)SubExprs.release();
1660 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1661 Subs, NumSubExprs,
1662 Builtin->getResultType(),
1663 RParenLoc);
1664 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001665
Douglas Gregorb98b1992009-08-11 05:31:07 +00001666 // Type-check the __builtin_shufflevector expression.
1667 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1668 if (Result.isInvalid())
1669 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001670
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001672 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001674};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001675
Douglas Gregor43959a92009-08-20 07:17:43 +00001676template<typename Derived>
1677Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1678 if (!S)
1679 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001680
Douglas Gregor43959a92009-08-20 07:17:43 +00001681 switch (S->getStmtClass()) {
1682 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001683
Douglas Gregor43959a92009-08-20 07:17:43 +00001684 // Transform individual statement nodes
1685#define STMT(Node, Parent) \
1686 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1687#define EXPR(Node, Parent)
1688#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001689
Douglas Gregor43959a92009-08-20 07:17:43 +00001690 // Transform expressions by calling TransformExpr.
1691#define STMT(Node, Parent)
John McCall09cc1412010-02-03 00:55:45 +00001692#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregor43959a92009-08-20 07:17:43 +00001693#define EXPR(Node, Parent) case Stmt::Node##Class:
1694#include "clang/AST/StmtNodes.def"
1695 {
1696 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1697 if (E.isInvalid())
1698 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001699
Anders Carlsson5ee56e92009-12-16 02:09:40 +00001700 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregor43959a92009-08-20 07:17:43 +00001701 }
Mike Stump1eb44332009-09-09 15:08:12 +00001702 }
1703
Douglas Gregor43959a92009-08-20 07:17:43 +00001704 return SemaRef.Owned(S->Retain());
1705}
Mike Stump1eb44332009-09-09 15:08:12 +00001706
1707
Douglas Gregor670444e2009-08-04 22:27:00 +00001708template<typename Derived>
John McCall454feb92009-12-08 09:21:05 +00001709Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 if (!E)
1711 return SemaRef.Owned(E);
1712
1713 switch (E->getStmtClass()) {
1714 case Stmt::NoStmtClass: break;
1715#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall09cc1412010-02-03 00:55:45 +00001716#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00001718 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001719#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001720 }
1721
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00001723}
1724
1725template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00001726NestedNameSpecifier *
1727TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00001728 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001729 QualType ObjectType,
1730 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00001731 if (!NNS)
1732 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001733
Douglas Gregor43959a92009-08-20 07:17:43 +00001734 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00001735 NestedNameSpecifier *Prefix = NNS->getPrefix();
1736 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00001737 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001738 ObjectType,
1739 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00001740 if (!Prefix)
1741 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001742
1743 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00001744 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00001745 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00001746 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001747 }
Mike Stump1eb44332009-09-09 15:08:12 +00001748
Douglas Gregordcee1a12009-08-06 05:28:30 +00001749 switch (NNS->getKind()) {
1750 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00001751 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00001752 "Identifier nested-name-specifier with no prefix or object type");
1753 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1754 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00001755 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001756
1757 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00001758 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00001759 ObjectType,
1760 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001761
Douglas Gregordcee1a12009-08-06 05:28:30 +00001762 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00001763 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00001764 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00001765 getDerived().TransformDecl(Range.getBegin(),
1766 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00001767 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00001768 Prefix == NNS->getPrefix() &&
1769 NS == NNS->getAsNamespace())
1770 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001771
Douglas Gregordcee1a12009-08-06 05:28:30 +00001772 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1773 }
Mike Stump1eb44332009-09-09 15:08:12 +00001774
Douglas Gregordcee1a12009-08-06 05:28:30 +00001775 case NestedNameSpecifier::Global:
1776 // There is no meaningful transformation that one could perform on the
1777 // global scope.
1778 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001779
Douglas Gregordcee1a12009-08-06 05:28:30 +00001780 case NestedNameSpecifier::TypeSpecWithTemplate:
1781 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00001782 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor124b8782010-02-16 19:09:40 +00001783 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
1784 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00001785 if (T.isNull())
1786 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001787
Douglas Gregordcee1a12009-08-06 05:28:30 +00001788 if (!getDerived().AlwaysRebuild() &&
1789 Prefix == NNS->getPrefix() &&
1790 T == QualType(NNS->getAsType(), 0))
1791 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001792
1793 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1794 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00001795 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00001796 }
1797 }
Mike Stump1eb44332009-09-09 15:08:12 +00001798
Douglas Gregordcee1a12009-08-06 05:28:30 +00001799 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00001800 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001801}
1802
1803template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001804DeclarationName
Douglas Gregor81499bb2009-09-03 22:13:48 +00001805TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +00001806 SourceLocation Loc,
1807 QualType ObjectType) {
Douglas Gregor81499bb2009-09-03 22:13:48 +00001808 if (!Name)
1809 return Name;
1810
1811 switch (Name.getNameKind()) {
1812 case DeclarationName::Identifier:
1813 case DeclarationName::ObjCZeroArgSelector:
1814 case DeclarationName::ObjCOneArgSelector:
1815 case DeclarationName::ObjCMultiArgSelector:
1816 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00001817 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00001818 case DeclarationName::CXXUsingDirective:
1819 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001820
Douglas Gregor81499bb2009-09-03 22:13:48 +00001821 case DeclarationName::CXXConstructorName:
1822 case DeclarationName::CXXDestructorName:
1823 case DeclarationName::CXXConversionFunctionName: {
1824 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregor124b8782010-02-16 19:09:40 +00001825 QualType T = getDerived().TransformType(Name.getCXXNameType(),
1826 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00001827 if (T.isNull())
1828 return DeclarationName();
Mike Stump1eb44332009-09-09 15:08:12 +00001829
Douglas Gregor81499bb2009-09-03 22:13:48 +00001830 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump1eb44332009-09-09 15:08:12 +00001831 Name.getNameKind(),
Douglas Gregor81499bb2009-09-03 22:13:48 +00001832 SemaRef.Context.getCanonicalType(T));
Douglas Gregor81499bb2009-09-03 22:13:48 +00001833 }
Mike Stump1eb44332009-09-09 15:08:12 +00001834 }
1835
Douglas Gregor81499bb2009-09-03 22:13:48 +00001836 return DeclarationName();
1837}
1838
1839template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001840TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001841TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1842 QualType ObjectType) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00001843 SourceLocation Loc = getDerived().getBaseLocation();
1844
Douglas Gregord1067e52009-08-06 06:41:21 +00001845 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001846 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00001847 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00001848 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1849 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00001850 if (!NNS)
1851 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001852
Douglas Gregord1067e52009-08-06 06:41:21 +00001853 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001854 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00001855 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00001856 if (!TransTemplate)
1857 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001858
Douglas Gregord1067e52009-08-06 06:41:21 +00001859 if (!getDerived().AlwaysRebuild() &&
1860 NNS == QTN->getQualifier() &&
1861 TransTemplate == Template)
1862 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001863
Douglas Gregord1067e52009-08-06 06:41:21 +00001864 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1865 TransTemplate);
1866 }
Mike Stump1eb44332009-09-09 15:08:12 +00001867
John McCallf7a1a742009-11-24 19:00:30 +00001868 // These should be getting filtered out before they make it into the AST.
1869 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00001870 }
Mike Stump1eb44332009-09-09 15:08:12 +00001871
Douglas Gregord1067e52009-08-06 06:41:21 +00001872 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001873 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00001874 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00001875 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1876 ObjectType);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001877 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00001878 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001879
Douglas Gregord1067e52009-08-06 06:41:21 +00001880 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00001881 NNS == DTN->getQualifier() &&
1882 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00001883 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001884
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001885 if (DTN->isIdentifier())
1886 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1887 ObjectType);
1888
1889 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1890 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00001891 }
Mike Stump1eb44332009-09-09 15:08:12 +00001892
Douglas Gregord1067e52009-08-06 06:41:21 +00001893 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001894 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00001895 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00001896 if (!TransTemplate)
1897 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001898
Douglas Gregord1067e52009-08-06 06:41:21 +00001899 if (!getDerived().AlwaysRebuild() &&
1900 TransTemplate == Template)
1901 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001902
Douglas Gregord1067e52009-08-06 06:41:21 +00001903 return TemplateName(TransTemplate);
1904 }
Mike Stump1eb44332009-09-09 15:08:12 +00001905
John McCallf7a1a742009-11-24 19:00:30 +00001906 // These should be getting filtered out before they reach the AST.
1907 assert(false && "overloaded function decl survived to here");
1908 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00001909}
1910
1911template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00001912void TreeTransform<Derived>::InventTemplateArgumentLoc(
1913 const TemplateArgument &Arg,
1914 TemplateArgumentLoc &Output) {
1915 SourceLocation Loc = getDerived().getBaseLocation();
1916 switch (Arg.getKind()) {
1917 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00001918 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00001919 break;
1920
1921 case TemplateArgument::Type:
1922 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00001923 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall833ca992009-10-29 08:12:44 +00001924
1925 break;
1926
Douglas Gregor788cd062009-11-11 01:00:40 +00001927 case TemplateArgument::Template:
1928 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1929 break;
1930
John McCall833ca992009-10-29 08:12:44 +00001931 case TemplateArgument::Expression:
1932 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1933 break;
1934
1935 case TemplateArgument::Declaration:
1936 case TemplateArgument::Integral:
1937 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00001938 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00001939 break;
1940 }
1941}
1942
1943template<typename Derived>
1944bool TreeTransform<Derived>::TransformTemplateArgument(
1945 const TemplateArgumentLoc &Input,
1946 TemplateArgumentLoc &Output) {
1947 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00001948 switch (Arg.getKind()) {
1949 case TemplateArgument::Null:
1950 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00001951 Output = Input;
1952 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00001953
Douglas Gregor670444e2009-08-04 22:27:00 +00001954 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00001955 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00001956 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00001957 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00001958
1959 DI = getDerived().TransformType(DI);
1960 if (!DI) return true;
1961
1962 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1963 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00001964 }
Mike Stump1eb44332009-09-09 15:08:12 +00001965
Douglas Gregor670444e2009-08-04 22:27:00 +00001966 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00001967 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00001968 DeclarationName Name;
1969 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1970 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00001971 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00001972 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00001973 if (!D) return true;
1974
John McCall828bff22009-10-29 18:45:58 +00001975 Expr *SourceExpr = Input.getSourceDeclExpression();
1976 if (SourceExpr) {
1977 EnterExpressionEvaluationContext Unevaluated(getSema(),
1978 Action::Unevaluated);
1979 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1980 if (E.isInvalid())
1981 SourceExpr = NULL;
1982 else {
1983 SourceExpr = E.takeAs<Expr>();
1984 SourceExpr->Retain();
1985 }
1986 }
1987
1988 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00001989 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00001990 }
Mike Stump1eb44332009-09-09 15:08:12 +00001991
Douglas Gregor788cd062009-11-11 01:00:40 +00001992 case TemplateArgument::Template: {
1993 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1994 TemplateName Template
1995 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1996 if (Template.isNull())
1997 return true;
1998
1999 Output = TemplateArgumentLoc(TemplateArgument(Template),
2000 Input.getTemplateQualifierRange(),
2001 Input.getTemplateNameLoc());
2002 return false;
2003 }
2004
Douglas Gregor670444e2009-08-04 22:27:00 +00002005 case TemplateArgument::Expression: {
2006 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002007 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002008 Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002009
John McCall833ca992009-10-29 08:12:44 +00002010 Expr *InputExpr = Input.getSourceExpression();
2011 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2012
2013 Sema::OwningExprResult E
2014 = getDerived().TransformExpr(InputExpr);
2015 if (E.isInvalid()) return true;
2016
2017 Expr *ETaken = E.takeAs<Expr>();
John McCall828bff22009-10-29 18:45:58 +00002018 ETaken->Retain();
John McCall833ca992009-10-29 08:12:44 +00002019 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2020 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002021 }
Mike Stump1eb44332009-09-09 15:08:12 +00002022
Douglas Gregor670444e2009-08-04 22:27:00 +00002023 case TemplateArgument::Pack: {
2024 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2025 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002026 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002027 AEnd = Arg.pack_end();
2028 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002029
John McCall833ca992009-10-29 08:12:44 +00002030 // FIXME: preserve source information here when we start
2031 // caring about parameter packs.
2032
John McCall828bff22009-10-29 18:45:58 +00002033 TemplateArgumentLoc InputArg;
2034 TemplateArgumentLoc OutputArg;
2035 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2036 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002037 return true;
2038
John McCall828bff22009-10-29 18:45:58 +00002039 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002040 }
2041 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002042 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002043 true);
John McCall828bff22009-10-29 18:45:58 +00002044 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002045 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002046 }
2047 }
Mike Stump1eb44332009-09-09 15:08:12 +00002048
Douglas Gregor670444e2009-08-04 22:27:00 +00002049 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002050 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002051}
2052
Douglas Gregor577f75a2009-08-04 16:50:30 +00002053//===----------------------------------------------------------------------===//
2054// Type transformation
2055//===----------------------------------------------------------------------===//
2056
2057template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002058QualType TreeTransform<Derived>::TransformType(QualType T,
2059 QualType ObjectType) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002060 if (getDerived().AlreadyTransformed(T))
2061 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002062
John McCalla2becad2009-10-21 00:40:46 +00002063 // Temporary workaround. All of these transformations should
2064 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002065 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002066 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCalla2becad2009-10-21 00:40:46 +00002067
Douglas Gregor124b8782010-02-16 19:09:40 +00002068 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall0953e762009-09-24 19:53:00 +00002069
John McCalla2becad2009-10-21 00:40:46 +00002070 if (!NewDI)
2071 return QualType();
2072
2073 return NewDI->getType();
2074}
2075
2076template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002077TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2078 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002079 if (getDerived().AlreadyTransformed(DI->getType()))
2080 return DI;
2081
2082 TypeLocBuilder TLB;
2083
2084 TypeLoc TL = DI->getTypeLoc();
2085 TLB.reserve(TL.getFullDataSize());
2086
Douglas Gregor124b8782010-02-16 19:09:40 +00002087 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002088 if (Result.isNull())
2089 return 0;
2090
John McCalla93c9342009-12-07 02:54:59 +00002091 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002092}
2093
2094template<typename Derived>
2095QualType
Douglas Gregor124b8782010-02-16 19:09:40 +00002096TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2097 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002098 switch (T.getTypeLocClass()) {
2099#define ABSTRACT_TYPELOC(CLASS, PARENT)
2100#define TYPELOC(CLASS, PARENT) \
2101 case TypeLoc::CLASS: \
Douglas Gregor124b8782010-02-16 19:09:40 +00002102 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2103 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002104#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002105 }
Mike Stump1eb44332009-09-09 15:08:12 +00002106
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002107 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002108 return QualType();
2109}
2110
2111/// FIXME: By default, this routine adds type qualifiers only to types
2112/// that can have qualifiers, and silently suppresses those qualifiers
2113/// that are not permitted (e.g., qualifiers on reference or function
2114/// types). This is the right thing for template instantiation, but
2115/// probably not for other clients.
2116template<typename Derived>
2117QualType
2118TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002119 QualifiedTypeLoc T,
2120 QualType ObjectType) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002121 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002122
Douglas Gregor124b8782010-02-16 19:09:40 +00002123 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2124 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002125 if (Result.isNull())
2126 return QualType();
2127
2128 // Silently suppress qualifiers if the result type can't be qualified.
2129 // FIXME: this is the right thing for template instantiation, but
2130 // probably not for other clients.
2131 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002132 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002133
John McCalla2becad2009-10-21 00:40:46 +00002134 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2135
2136 TLB.push<QualifiedTypeLoc>(Result);
2137
2138 // No location information to preserve.
2139
2140 return Result;
2141}
2142
2143template <class TyLoc> static inline
2144QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2145 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2146 NewT.setNameLoc(T.getNameLoc());
2147 return T.getType();
2148}
2149
2150// Ugly metaprogramming macros because I couldn't be bothered to make
2151// the equivalent template version work.
2152#define TransformPointerLikeType(TypeClass) do { \
2153 QualType PointeeType \
2154 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2155 if (PointeeType.isNull()) \
2156 return QualType(); \
2157 \
2158 QualType Result = TL.getType(); \
2159 if (getDerived().AlwaysRebuild() || \
2160 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall85737a72009-10-30 00:06:24 +00002161 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2162 TL.getSigilLoc()); \
John McCalla2becad2009-10-21 00:40:46 +00002163 if (Result.isNull()) \
2164 return QualType(); \
2165 } \
2166 \
2167 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2168 NewT.setSigilLoc(TL.getSigilLoc()); \
2169 \
2170 return Result; \
2171} while(0)
2172
John McCalla2becad2009-10-21 00:40:46 +00002173template<typename Derived>
2174QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002175 BuiltinTypeLoc T,
2176 QualType ObjectType) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002177 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2178 NewT.setBuiltinLoc(T.getBuiltinLoc());
2179 if (T.needsExtraLocalData())
2180 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2181 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002182}
Mike Stump1eb44332009-09-09 15:08:12 +00002183
Douglas Gregor577f75a2009-08-04 16:50:30 +00002184template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002185QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002186 ComplexTypeLoc T,
2187 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002188 // FIXME: recurse?
2189 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002190}
Mike Stump1eb44332009-09-09 15:08:12 +00002191
Douglas Gregor577f75a2009-08-04 16:50:30 +00002192template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002193QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002194 PointerTypeLoc TL,
2195 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002196 TransformPointerLikeType(PointerType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002197}
Mike Stump1eb44332009-09-09 15:08:12 +00002198
2199template<typename Derived>
2200QualType
John McCalla2becad2009-10-21 00:40:46 +00002201TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002202 BlockPointerTypeLoc TL,
2203 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002204 TransformPointerLikeType(BlockPointerType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002205}
2206
John McCall85737a72009-10-30 00:06:24 +00002207/// Transforms a reference type. Note that somewhat paradoxically we
2208/// don't care whether the type itself is an l-value type or an r-value
2209/// type; we only care if the type was *written* as an l-value type
2210/// or an r-value type.
2211template<typename Derived>
2212QualType
2213TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002214 ReferenceTypeLoc TL,
2215 QualType ObjectType) {
John McCall85737a72009-10-30 00:06:24 +00002216 const ReferenceType *T = TL.getTypePtr();
2217
2218 // Note that this works with the pointee-as-written.
2219 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2220 if (PointeeType.isNull())
2221 return QualType();
2222
2223 QualType Result = TL.getType();
2224 if (getDerived().AlwaysRebuild() ||
2225 PointeeType != T->getPointeeTypeAsWritten()) {
2226 Result = getDerived().RebuildReferenceType(PointeeType,
2227 T->isSpelledAsLValue(),
2228 TL.getSigilLoc());
2229 if (Result.isNull())
2230 return QualType();
2231 }
2232
2233 // r-value references can be rebuilt as l-value references.
2234 ReferenceTypeLoc NewTL;
2235 if (isa<LValueReferenceType>(Result))
2236 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2237 else
2238 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2239 NewTL.setSigilLoc(TL.getSigilLoc());
2240
2241 return Result;
2242}
2243
Mike Stump1eb44332009-09-09 15:08:12 +00002244template<typename Derived>
2245QualType
John McCalla2becad2009-10-21 00:40:46 +00002246TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002247 LValueReferenceTypeLoc TL,
2248 QualType ObjectType) {
2249 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002250}
2251
Mike Stump1eb44332009-09-09 15:08:12 +00002252template<typename Derived>
2253QualType
John McCalla2becad2009-10-21 00:40:46 +00002254TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002255 RValueReferenceTypeLoc TL,
2256 QualType ObjectType) {
2257 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002258}
Mike Stump1eb44332009-09-09 15:08:12 +00002259
Douglas Gregor577f75a2009-08-04 16:50:30 +00002260template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002261QualType
John McCalla2becad2009-10-21 00:40:46 +00002262TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002263 MemberPointerTypeLoc TL,
2264 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002265 MemberPointerType *T = TL.getTypePtr();
2266
2267 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002268 if (PointeeType.isNull())
2269 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002270
John McCalla2becad2009-10-21 00:40:46 +00002271 // TODO: preserve source information for this.
2272 QualType ClassType
2273 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002274 if (ClassType.isNull())
2275 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002276
John McCalla2becad2009-10-21 00:40:46 +00002277 QualType Result = TL.getType();
2278 if (getDerived().AlwaysRebuild() ||
2279 PointeeType != T->getPointeeType() ||
2280 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002281 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2282 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002283 if (Result.isNull())
2284 return QualType();
2285 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002286
John McCalla2becad2009-10-21 00:40:46 +00002287 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2288 NewTL.setSigilLoc(TL.getSigilLoc());
2289
2290 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002291}
2292
Mike Stump1eb44332009-09-09 15:08:12 +00002293template<typename Derived>
2294QualType
John McCalla2becad2009-10-21 00:40:46 +00002295TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002296 ConstantArrayTypeLoc TL,
2297 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002298 ConstantArrayType *T = TL.getTypePtr();
2299 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002300 if (ElementType.isNull())
2301 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002302
John McCalla2becad2009-10-21 00:40:46 +00002303 QualType Result = TL.getType();
2304 if (getDerived().AlwaysRebuild() ||
2305 ElementType != T->getElementType()) {
2306 Result = getDerived().RebuildConstantArrayType(ElementType,
2307 T->getSizeModifier(),
2308 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002309 T->getIndexTypeCVRQualifiers(),
2310 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002311 if (Result.isNull())
2312 return QualType();
2313 }
2314
2315 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2316 NewTL.setLBracketLoc(TL.getLBracketLoc());
2317 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002318
John McCalla2becad2009-10-21 00:40:46 +00002319 Expr *Size = TL.getSizeExpr();
2320 if (Size) {
2321 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2322 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2323 }
2324 NewTL.setSizeExpr(Size);
2325
2326 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002327}
Mike Stump1eb44332009-09-09 15:08:12 +00002328
Douglas Gregor577f75a2009-08-04 16:50:30 +00002329template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002330QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002331 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002332 IncompleteArrayTypeLoc TL,
2333 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002334 IncompleteArrayType *T = TL.getTypePtr();
2335 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002336 if (ElementType.isNull())
2337 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002338
John McCalla2becad2009-10-21 00:40:46 +00002339 QualType Result = TL.getType();
2340 if (getDerived().AlwaysRebuild() ||
2341 ElementType != T->getElementType()) {
2342 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002343 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002344 T->getIndexTypeCVRQualifiers(),
2345 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002346 if (Result.isNull())
2347 return QualType();
2348 }
2349
2350 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2351 NewTL.setLBracketLoc(TL.getLBracketLoc());
2352 NewTL.setRBracketLoc(TL.getRBracketLoc());
2353 NewTL.setSizeExpr(0);
2354
2355 return Result;
2356}
2357
2358template<typename Derived>
2359QualType
2360TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002361 VariableArrayTypeLoc TL,
2362 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002363 VariableArrayType *T = TL.getTypePtr();
2364 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2365 if (ElementType.isNull())
2366 return QualType();
2367
2368 // Array bounds are not potentially evaluated contexts
2369 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2370
2371 Sema::OwningExprResult SizeResult
2372 = getDerived().TransformExpr(T->getSizeExpr());
2373 if (SizeResult.isInvalid())
2374 return QualType();
2375
2376 Expr *Size = static_cast<Expr*>(SizeResult.get());
2377
2378 QualType Result = TL.getType();
2379 if (getDerived().AlwaysRebuild() ||
2380 ElementType != T->getElementType() ||
2381 Size != T->getSizeExpr()) {
2382 Result = getDerived().RebuildVariableArrayType(ElementType,
2383 T->getSizeModifier(),
2384 move(SizeResult),
2385 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002386 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002387 if (Result.isNull())
2388 return QualType();
2389 }
2390 else SizeResult.take();
2391
2392 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2393 NewTL.setLBracketLoc(TL.getLBracketLoc());
2394 NewTL.setRBracketLoc(TL.getRBracketLoc());
2395 NewTL.setSizeExpr(Size);
2396
2397 return Result;
2398}
2399
2400template<typename Derived>
2401QualType
2402TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002403 DependentSizedArrayTypeLoc TL,
2404 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002405 DependentSizedArrayType *T = TL.getTypePtr();
2406 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2407 if (ElementType.isNull())
2408 return QualType();
2409
2410 // Array bounds are not potentially evaluated contexts
2411 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2412
2413 Sema::OwningExprResult SizeResult
2414 = getDerived().TransformExpr(T->getSizeExpr());
2415 if (SizeResult.isInvalid())
2416 return QualType();
2417
2418 Expr *Size = static_cast<Expr*>(SizeResult.get());
2419
2420 QualType Result = TL.getType();
2421 if (getDerived().AlwaysRebuild() ||
2422 ElementType != T->getElementType() ||
2423 Size != T->getSizeExpr()) {
2424 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2425 T->getSizeModifier(),
2426 move(SizeResult),
2427 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002428 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002429 if (Result.isNull())
2430 return QualType();
2431 }
2432 else SizeResult.take();
2433
2434 // We might have any sort of array type now, but fortunately they
2435 // all have the same location layout.
2436 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2437 NewTL.setLBracketLoc(TL.getLBracketLoc());
2438 NewTL.setRBracketLoc(TL.getRBracketLoc());
2439 NewTL.setSizeExpr(Size);
2440
2441 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002442}
Mike Stump1eb44332009-09-09 15:08:12 +00002443
2444template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002445QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002446 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002447 DependentSizedExtVectorTypeLoc TL,
2448 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002449 DependentSizedExtVectorType *T = TL.getTypePtr();
2450
2451 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002452 QualType ElementType = getDerived().TransformType(T->getElementType());
2453 if (ElementType.isNull())
2454 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002455
Douglas Gregor670444e2009-08-04 22:27:00 +00002456 // Vector sizes are not potentially evaluated contexts
2457 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2458
Douglas Gregor577f75a2009-08-04 16:50:30 +00002459 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2460 if (Size.isInvalid())
2461 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002462
John McCalla2becad2009-10-21 00:40:46 +00002463 QualType Result = TL.getType();
2464 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002465 ElementType != T->getElementType() ||
2466 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002467 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002468 move(Size),
2469 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002470 if (Result.isNull())
2471 return QualType();
2472 }
2473 else Size.take();
2474
2475 // Result might be dependent or not.
2476 if (isa<DependentSizedExtVectorType>(Result)) {
2477 DependentSizedExtVectorTypeLoc NewTL
2478 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2479 NewTL.setNameLoc(TL.getNameLoc());
2480 } else {
2481 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2482 NewTL.setNameLoc(TL.getNameLoc());
2483 }
2484
2485 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002486}
Mike Stump1eb44332009-09-09 15:08:12 +00002487
2488template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002489QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002490 VectorTypeLoc TL,
2491 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002492 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002493 QualType ElementType = getDerived().TransformType(T->getElementType());
2494 if (ElementType.isNull())
2495 return QualType();
2496
John McCalla2becad2009-10-21 00:40:46 +00002497 QualType Result = TL.getType();
2498 if (getDerived().AlwaysRebuild() ||
2499 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002500 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2501 T->isAltiVec(), T->isPixel());
John McCalla2becad2009-10-21 00:40:46 +00002502 if (Result.isNull())
2503 return QualType();
2504 }
2505
2506 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2507 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002508
John McCalla2becad2009-10-21 00:40:46 +00002509 return Result;
2510}
2511
2512template<typename Derived>
2513QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002514 ExtVectorTypeLoc TL,
2515 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002516 VectorType *T = TL.getTypePtr();
2517 QualType ElementType = getDerived().TransformType(T->getElementType());
2518 if (ElementType.isNull())
2519 return QualType();
2520
2521 QualType Result = TL.getType();
2522 if (getDerived().AlwaysRebuild() ||
2523 ElementType != T->getElementType()) {
2524 Result = getDerived().RebuildExtVectorType(ElementType,
2525 T->getNumElements(),
2526 /*FIXME*/ SourceLocation());
2527 if (Result.isNull())
2528 return QualType();
2529 }
2530
2531 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2532 NewTL.setNameLoc(TL.getNameLoc());
2533
2534 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002535}
Mike Stump1eb44332009-09-09 15:08:12 +00002536
2537template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00002538ParmVarDecl *
2539TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2540 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2541 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2542 if (!NewDI)
2543 return 0;
2544
2545 if (NewDI == OldDI)
2546 return OldParm;
2547 else
2548 return ParmVarDecl::Create(SemaRef.Context,
2549 OldParm->getDeclContext(),
2550 OldParm->getLocation(),
2551 OldParm->getIdentifier(),
2552 NewDI->getType(),
2553 NewDI,
2554 OldParm->getStorageClass(),
2555 /* DefArg */ NULL);
2556}
2557
2558template<typename Derived>
2559bool TreeTransform<Derived>::
2560 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2561 llvm::SmallVectorImpl<QualType> &PTypes,
2562 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2563 FunctionProtoType *T = TL.getTypePtr();
2564
2565 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2566 ParmVarDecl *OldParm = TL.getArg(i);
2567
2568 QualType NewType;
2569 ParmVarDecl *NewParm;
2570
2571 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00002572 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2573 if (!NewParm)
2574 return true;
2575 NewType = NewParm->getType();
2576
2577 // Deal with the possibility that we don't have a parameter
2578 // declaration for this parameter.
2579 } else {
2580 NewParm = 0;
2581
2582 QualType OldType = T->getArgType(i);
2583 NewType = getDerived().TransformType(OldType);
2584 if (NewType.isNull())
2585 return true;
2586 }
2587
2588 PTypes.push_back(NewType);
2589 PVars.push_back(NewParm);
2590 }
2591
2592 return false;
2593}
2594
2595template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002596QualType
John McCalla2becad2009-10-21 00:40:46 +00002597TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002598 FunctionProtoTypeLoc TL,
2599 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002600 FunctionProtoType *T = TL.getTypePtr();
2601 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002602 if (ResultType.isNull())
2603 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002604
John McCalla2becad2009-10-21 00:40:46 +00002605 // Transform the parameters.
Douglas Gregor577f75a2009-08-04 16:50:30 +00002606 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002607 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall21ef0fa2010-03-11 09:03:00 +00002608 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2609 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002610
John McCalla2becad2009-10-21 00:40:46 +00002611 QualType Result = TL.getType();
2612 if (getDerived().AlwaysRebuild() ||
2613 ResultType != T->getResultType() ||
2614 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2615 Result = getDerived().RebuildFunctionProtoType(ResultType,
2616 ParamTypes.data(),
2617 ParamTypes.size(),
2618 T->isVariadic(),
2619 T->getTypeQuals());
2620 if (Result.isNull())
2621 return QualType();
2622 }
Mike Stump1eb44332009-09-09 15:08:12 +00002623
John McCalla2becad2009-10-21 00:40:46 +00002624 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2625 NewTL.setLParenLoc(TL.getLParenLoc());
2626 NewTL.setRParenLoc(TL.getRParenLoc());
2627 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2628 NewTL.setArg(i, ParamDecls[i]);
2629
2630 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002631}
Mike Stump1eb44332009-09-09 15:08:12 +00002632
Douglas Gregor577f75a2009-08-04 16:50:30 +00002633template<typename Derived>
2634QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002635 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002636 FunctionNoProtoTypeLoc TL,
2637 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002638 FunctionNoProtoType *T = TL.getTypePtr();
2639 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2640 if (ResultType.isNull())
2641 return QualType();
2642
2643 QualType Result = TL.getType();
2644 if (getDerived().AlwaysRebuild() ||
2645 ResultType != T->getResultType())
2646 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2647
2648 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2649 NewTL.setLParenLoc(TL.getLParenLoc());
2650 NewTL.setRParenLoc(TL.getRParenLoc());
2651
2652 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002653}
Mike Stump1eb44332009-09-09 15:08:12 +00002654
John McCalled976492009-12-04 22:46:56 +00002655template<typename Derived> QualType
2656TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002657 UnresolvedUsingTypeLoc TL,
2658 QualType ObjectType) {
John McCalled976492009-12-04 22:46:56 +00002659 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002660 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00002661 if (!D)
2662 return QualType();
2663
2664 QualType Result = TL.getType();
2665 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2666 Result = getDerived().RebuildUnresolvedUsingType(D);
2667 if (Result.isNull())
2668 return QualType();
2669 }
2670
2671 // We might get an arbitrary type spec type back. We should at
2672 // least always get a type spec type, though.
2673 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2674 NewTL.setNameLoc(TL.getNameLoc());
2675
2676 return Result;
2677}
2678
Douglas Gregor577f75a2009-08-04 16:50:30 +00002679template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002680QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002681 TypedefTypeLoc TL,
2682 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002683 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002684 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002685 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2686 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002687 if (!Typedef)
2688 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002689
John McCalla2becad2009-10-21 00:40:46 +00002690 QualType Result = TL.getType();
2691 if (getDerived().AlwaysRebuild() ||
2692 Typedef != T->getDecl()) {
2693 Result = getDerived().RebuildTypedefType(Typedef);
2694 if (Result.isNull())
2695 return QualType();
2696 }
Mike Stump1eb44332009-09-09 15:08:12 +00002697
John McCalla2becad2009-10-21 00:40:46 +00002698 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2699 NewTL.setNameLoc(TL.getNameLoc());
2700
2701 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002702}
Mike Stump1eb44332009-09-09 15:08:12 +00002703
Douglas Gregor577f75a2009-08-04 16:50:30 +00002704template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002705QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002706 TypeOfExprTypeLoc TL,
2707 QualType ObjectType) {
Douglas Gregor670444e2009-08-04 22:27:00 +00002708 // typeof expressions are not potentially evaluated contexts
2709 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002710
John McCallcfb708c2010-01-13 20:03:27 +00002711 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002712 if (E.isInvalid())
2713 return QualType();
2714
John McCalla2becad2009-10-21 00:40:46 +00002715 QualType Result = TL.getType();
2716 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00002717 E.get() != TL.getUnderlyingExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002718 Result = getDerived().RebuildTypeOfExprType(move(E));
2719 if (Result.isNull())
2720 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002721 }
John McCalla2becad2009-10-21 00:40:46 +00002722 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002723
John McCalla2becad2009-10-21 00:40:46 +00002724 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002725 NewTL.setTypeofLoc(TL.getTypeofLoc());
2726 NewTL.setLParenLoc(TL.getLParenLoc());
2727 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00002728
2729 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002730}
Mike Stump1eb44332009-09-09 15:08:12 +00002731
2732template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002733QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002734 TypeOfTypeLoc TL,
2735 QualType ObjectType) {
John McCallcfb708c2010-01-13 20:03:27 +00002736 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2737 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2738 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00002739 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002740
John McCalla2becad2009-10-21 00:40:46 +00002741 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00002742 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2743 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00002744 if (Result.isNull())
2745 return QualType();
2746 }
Mike Stump1eb44332009-09-09 15:08:12 +00002747
John McCalla2becad2009-10-21 00:40:46 +00002748 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002749 NewTL.setTypeofLoc(TL.getTypeofLoc());
2750 NewTL.setLParenLoc(TL.getLParenLoc());
2751 NewTL.setRParenLoc(TL.getRParenLoc());
2752 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00002753
2754 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002755}
Mike Stump1eb44332009-09-09 15:08:12 +00002756
2757template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002758QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002759 DecltypeTypeLoc TL,
2760 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002761 DecltypeType *T = TL.getTypePtr();
2762
Douglas Gregor670444e2009-08-04 22:27:00 +00002763 // decltype expressions are not potentially evaluated contexts
2764 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002765
Douglas Gregor577f75a2009-08-04 16:50:30 +00002766 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2767 if (E.isInvalid())
2768 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002769
John McCalla2becad2009-10-21 00:40:46 +00002770 QualType Result = TL.getType();
2771 if (getDerived().AlwaysRebuild() ||
2772 E.get() != T->getUnderlyingExpr()) {
2773 Result = getDerived().RebuildDecltypeType(move(E));
2774 if (Result.isNull())
2775 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002776 }
John McCalla2becad2009-10-21 00:40:46 +00002777 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002778
John McCalla2becad2009-10-21 00:40:46 +00002779 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2780 NewTL.setNameLoc(TL.getNameLoc());
2781
2782 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002783}
2784
2785template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002786QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002787 RecordTypeLoc TL,
2788 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002789 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002790 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002791 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2792 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002793 if (!Record)
2794 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002795
John McCalla2becad2009-10-21 00:40:46 +00002796 QualType Result = TL.getType();
2797 if (getDerived().AlwaysRebuild() ||
2798 Record != T->getDecl()) {
2799 Result = getDerived().RebuildRecordType(Record);
2800 if (Result.isNull())
2801 return QualType();
2802 }
Mike Stump1eb44332009-09-09 15:08:12 +00002803
John McCalla2becad2009-10-21 00:40:46 +00002804 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2805 NewTL.setNameLoc(TL.getNameLoc());
2806
2807 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002808}
Mike Stump1eb44332009-09-09 15:08:12 +00002809
2810template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002811QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002812 EnumTypeLoc TL,
2813 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002814 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002815 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002816 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2817 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002818 if (!Enum)
2819 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002820
John McCalla2becad2009-10-21 00:40:46 +00002821 QualType Result = TL.getType();
2822 if (getDerived().AlwaysRebuild() ||
2823 Enum != T->getDecl()) {
2824 Result = getDerived().RebuildEnumType(Enum);
2825 if (Result.isNull())
2826 return QualType();
2827 }
Mike Stump1eb44332009-09-09 15:08:12 +00002828
John McCalla2becad2009-10-21 00:40:46 +00002829 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2830 NewTL.setNameLoc(TL.getNameLoc());
2831
2832 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002833}
John McCall7da24312009-09-05 00:15:47 +00002834
2835template <typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002836QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002837 ElaboratedTypeLoc TL,
2838 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002839 ElaboratedType *T = TL.getTypePtr();
2840
2841 // FIXME: this should be a nested type.
John McCall7da24312009-09-05 00:15:47 +00002842 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2843 if (Underlying.isNull())
2844 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002845
John McCalla2becad2009-10-21 00:40:46 +00002846 QualType Result = TL.getType();
2847 if (getDerived().AlwaysRebuild() ||
2848 Underlying != T->getUnderlyingType()) {
2849 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2850 if (Result.isNull())
2851 return QualType();
2852 }
Mike Stump1eb44332009-09-09 15:08:12 +00002853
John McCalla2becad2009-10-21 00:40:46 +00002854 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2855 NewTL.setNameLoc(TL.getNameLoc());
2856
2857 return Result;
John McCall7da24312009-09-05 00:15:47 +00002858}
Mike Stump1eb44332009-09-09 15:08:12 +00002859
John McCall3cb0ebd2010-03-10 03:28:59 +00002860template<typename Derived>
2861QualType TreeTransform<Derived>::TransformInjectedClassNameType(
2862 TypeLocBuilder &TLB,
2863 InjectedClassNameTypeLoc TL,
2864 QualType ObjectType) {
2865 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
2866 TL.getTypePtr()->getDecl());
2867 if (!D) return QualType();
2868
2869 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
2870 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
2871 return T;
2872}
2873
Mike Stump1eb44332009-09-09 15:08:12 +00002874
Douglas Gregor577f75a2009-08-04 16:50:30 +00002875template<typename Derived>
2876QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00002877 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002878 TemplateTypeParmTypeLoc TL,
2879 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002880 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002881}
2882
Mike Stump1eb44332009-09-09 15:08:12 +00002883template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00002884QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00002885 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002886 SubstTemplateTypeParmTypeLoc TL,
2887 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002888 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00002889}
2890
2891template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002892QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2893 const TemplateSpecializationType *TST,
2894 QualType ObjectType) {
2895 // FIXME: this entire method is a temporary workaround; callers
2896 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00002897
John McCall833ca992009-10-29 08:12:44 +00002898 // Fake up a TemplateSpecializationTypeLoc.
2899 TypeLocBuilder TLB;
2900 TemplateSpecializationTypeLoc TL
2901 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2902
John McCall828bff22009-10-29 18:45:58 +00002903 SourceLocation BaseLoc = getDerived().getBaseLocation();
2904
2905 TL.setTemplateNameLoc(BaseLoc);
2906 TL.setLAngleLoc(BaseLoc);
2907 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00002908 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2909 const TemplateArgument &TA = TST->getArg(i);
2910 TemplateArgumentLoc TAL;
2911 getDerived().InventTemplateArgumentLoc(TA, TAL);
2912 TL.setArgLocInfo(i, TAL.getLocInfo());
2913 }
2914
2915 TypeLocBuilder IgnoredTLB;
2916 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00002917}
2918
2919template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002920QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00002921 TypeLocBuilder &TLB,
2922 TemplateSpecializationTypeLoc TL,
2923 QualType ObjectType) {
2924 const TemplateSpecializationType *T = TL.getTypePtr();
2925
Mike Stump1eb44332009-09-09 15:08:12 +00002926 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00002927 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002928 if (Template.isNull())
2929 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002930
John McCalld5532b62009-11-23 01:53:49 +00002931 TemplateArgumentListInfo NewTemplateArgs;
2932 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2933 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2934
2935 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2936 TemplateArgumentLoc Loc;
2937 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00002938 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00002939 NewTemplateArgs.addArgument(Loc);
2940 }
Mike Stump1eb44332009-09-09 15:08:12 +00002941
John McCall833ca992009-10-29 08:12:44 +00002942 // FIXME: maybe don't rebuild if all the template arguments are the same.
2943
2944 QualType Result =
2945 getDerived().RebuildTemplateSpecializationType(Template,
2946 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00002947 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00002948
2949 if (!Result.isNull()) {
2950 TemplateSpecializationTypeLoc NewTL
2951 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2952 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2953 NewTL.setLAngleLoc(TL.getLAngleLoc());
2954 NewTL.setRAngleLoc(TL.getRAngleLoc());
2955 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2956 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002957 }
Mike Stump1eb44332009-09-09 15:08:12 +00002958
John McCall833ca992009-10-29 08:12:44 +00002959 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002960}
Mike Stump1eb44332009-09-09 15:08:12 +00002961
2962template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002963QualType
2964TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002965 QualifiedNameTypeLoc TL,
2966 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002967 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002968 NestedNameSpecifier *NNS
2969 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002970 SourceRange(),
2971 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002972 if (!NNS)
2973 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002974
Douglas Gregor577f75a2009-08-04 16:50:30 +00002975 QualType Named = getDerived().TransformType(T->getNamedType());
2976 if (Named.isNull())
2977 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002978
John McCalla2becad2009-10-21 00:40:46 +00002979 QualType Result = TL.getType();
2980 if (getDerived().AlwaysRebuild() ||
2981 NNS != T->getQualifier() ||
2982 Named != T->getNamedType()) {
2983 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2984 if (Result.isNull())
2985 return QualType();
2986 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002987
John McCalla2becad2009-10-21 00:40:46 +00002988 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2989 NewTL.setNameLoc(TL.getNameLoc());
2990
2991 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002992}
Mike Stump1eb44332009-09-09 15:08:12 +00002993
2994template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002995QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002996 TypenameTypeLoc TL,
2997 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002998 TypenameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00002999
3000 /* FIXME: preserve source information better than this */
3001 SourceRange SR(TL.getNameLoc());
3002
Douglas Gregor577f75a2009-08-04 16:50:30 +00003003 NestedNameSpecifier *NNS
Douglas Gregor124b8782010-02-16 19:09:40 +00003004 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregoredc90502010-02-25 04:46:04 +00003005 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003006 if (!NNS)
3007 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003008
John McCalla2becad2009-10-21 00:40:46 +00003009 QualType Result;
3010
Douglas Gregor577f75a2009-08-04 16:50:30 +00003011 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump1eb44332009-09-09 15:08:12 +00003012 QualType NewTemplateId
Douglas Gregor577f75a2009-08-04 16:50:30 +00003013 = getDerived().TransformType(QualType(TemplateId, 0));
3014 if (NewTemplateId.isNull())
3015 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003016
Douglas Gregor577f75a2009-08-04 16:50:30 +00003017 if (!getDerived().AlwaysRebuild() &&
3018 NNS == T->getQualifier() &&
3019 NewTemplateId == QualType(TemplateId, 0))
3020 return QualType(T, 0);
Mike Stump1eb44332009-09-09 15:08:12 +00003021
John McCalla2becad2009-10-21 00:40:46 +00003022 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
3023 } else {
John McCall833ca992009-10-29 08:12:44 +00003024 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003025 }
John McCalla2becad2009-10-21 00:40:46 +00003026 if (Result.isNull())
3027 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003028
John McCalla2becad2009-10-21 00:40:46 +00003029 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
3030 NewTL.setNameLoc(TL.getNameLoc());
3031
3032 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003033}
Mike Stump1eb44332009-09-09 15:08:12 +00003034
Douglas Gregor577f75a2009-08-04 16:50:30 +00003035template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003036QualType
3037TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003038 ObjCInterfaceTypeLoc TL,
3039 QualType ObjectType) {
John McCall54e14c42009-10-22 22:37:11 +00003040 assert(false && "TransformObjCInterfaceType unimplemented");
3041 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003042}
Mike Stump1eb44332009-09-09 15:08:12 +00003043
3044template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003045QualType
3046TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003047 ObjCObjectPointerTypeLoc TL,
3048 QualType ObjectType) {
John McCall54e14c42009-10-22 22:37:11 +00003049 assert(false && "TransformObjCObjectPointerType unimplemented");
3050 return QualType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003051}
3052
Douglas Gregor577f75a2009-08-04 16:50:30 +00003053//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003054// Statement transformation
3055//===----------------------------------------------------------------------===//
3056template<typename Derived>
3057Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003058TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3059 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003060}
3061
3062template<typename Derived>
3063Sema::OwningStmtResult
3064TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3065 return getDerived().TransformCompoundStmt(S, false);
3066}
3067
3068template<typename Derived>
3069Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003070TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003071 bool IsStmtExpr) {
3072 bool SubStmtChanged = false;
3073 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3074 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3075 B != BEnd; ++B) {
3076 OwningStmtResult Result = getDerived().TransformStmt(*B);
3077 if (Result.isInvalid())
3078 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003079
Douglas Gregor43959a92009-08-20 07:17:43 +00003080 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3081 Statements.push_back(Result.takeAs<Stmt>());
3082 }
Mike Stump1eb44332009-09-09 15:08:12 +00003083
Douglas Gregor43959a92009-08-20 07:17:43 +00003084 if (!getDerived().AlwaysRebuild() &&
3085 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003086 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003087
3088 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3089 move_arg(Statements),
3090 S->getRBracLoc(),
3091 IsStmtExpr);
3092}
Mike Stump1eb44332009-09-09 15:08:12 +00003093
Douglas Gregor43959a92009-08-20 07:17:43 +00003094template<typename Derived>
3095Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003096TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman264c1f82009-11-19 03:14:00 +00003097 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3098 {
3099 // The case value expressions are not potentially evaluated.
3100 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003101
Eli Friedman264c1f82009-11-19 03:14:00 +00003102 // Transform the left-hand case value.
3103 LHS = getDerived().TransformExpr(S->getLHS());
3104 if (LHS.isInvalid())
3105 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003106
Eli Friedman264c1f82009-11-19 03:14:00 +00003107 // Transform the right-hand case value (for the GNU case-range extension).
3108 RHS = getDerived().TransformExpr(S->getRHS());
3109 if (RHS.isInvalid())
3110 return SemaRef.StmtError();
3111 }
Mike Stump1eb44332009-09-09 15:08:12 +00003112
Douglas Gregor43959a92009-08-20 07:17:43 +00003113 // Build the case statement.
3114 // Case statements are always rebuilt so that they will attached to their
3115 // transformed switch statement.
3116 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3117 move(LHS),
3118 S->getEllipsisLoc(),
3119 move(RHS),
3120 S->getColonLoc());
3121 if (Case.isInvalid())
3122 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003123
Douglas Gregor43959a92009-08-20 07:17:43 +00003124 // Transform the statement following the case
3125 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3126 if (SubStmt.isInvalid())
3127 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003128
Douglas Gregor43959a92009-08-20 07:17:43 +00003129 // Attach the body to the case statement
3130 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3131}
3132
3133template<typename Derived>
3134Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003135TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003136 // Transform the statement following the default case
3137 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3138 if (SubStmt.isInvalid())
3139 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003140
Douglas Gregor43959a92009-08-20 07:17:43 +00003141 // Default statements are always rebuilt
3142 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3143 move(SubStmt));
3144}
Mike Stump1eb44332009-09-09 15:08:12 +00003145
Douglas Gregor43959a92009-08-20 07:17:43 +00003146template<typename Derived>
3147Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003148TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003149 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3150 if (SubStmt.isInvalid())
3151 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003152
Douglas Gregor43959a92009-08-20 07:17:43 +00003153 // FIXME: Pass the real colon location in.
3154 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3155 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3156 move(SubStmt));
3157}
Mike Stump1eb44332009-09-09 15:08:12 +00003158
Douglas Gregor43959a92009-08-20 07:17:43 +00003159template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003160Sema::OwningStmtResult
3161TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003162 // Transform the condition
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003163 OwningExprResult Cond(SemaRef);
3164 VarDecl *ConditionVar = 0;
3165 if (S->getConditionVariable()) {
3166 ConditionVar
3167 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003168 getDerived().TransformDefinition(
3169 S->getConditionVariable()->getLocation(),
3170 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003171 if (!ConditionVar)
3172 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003173 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003174 Cond = getDerived().TransformExpr(S->getCond());
3175
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003176 if (Cond.isInvalid())
3177 return SemaRef.StmtError();
3178 }
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003179
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003180 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump1eb44332009-09-09 15:08:12 +00003181
Douglas Gregor43959a92009-08-20 07:17:43 +00003182 // Transform the "then" branch.
3183 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3184 if (Then.isInvalid())
3185 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003186
Douglas Gregor43959a92009-08-20 07:17:43 +00003187 // Transform the "else" branch.
3188 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3189 if (Else.isInvalid())
3190 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003191
Douglas Gregor43959a92009-08-20 07:17:43 +00003192 if (!getDerived().AlwaysRebuild() &&
3193 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003194 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003195 Then.get() == S->getThen() &&
3196 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003197 return SemaRef.Owned(S->Retain());
3198
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003199 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3200 move(Then),
Mike Stump1eb44332009-09-09 15:08:12 +00003201 S->getElseLoc(), move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +00003202}
3203
3204template<typename Derived>
3205Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003206TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003207 // Transform the condition.
Douglas Gregord3d53012009-11-24 17:07:59 +00003208 OwningExprResult Cond(SemaRef);
3209 VarDecl *ConditionVar = 0;
3210 if (S->getConditionVariable()) {
3211 ConditionVar
3212 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003213 getDerived().TransformDefinition(
3214 S->getConditionVariable()->getLocation(),
3215 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003216 if (!ConditionVar)
3217 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003218 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003219 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003220
3221 if (Cond.isInvalid())
3222 return SemaRef.StmtError();
3223 }
Mike Stump1eb44332009-09-09 15:08:12 +00003224
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003225 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003226
Douglas Gregor43959a92009-08-20 07:17:43 +00003227 // Rebuild the switch statement.
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003228 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3229 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003230 if (Switch.isInvalid())
3231 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003232
Douglas Gregor43959a92009-08-20 07:17:43 +00003233 // Transform the body of the switch statement.
3234 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3235 if (Body.isInvalid())
3236 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003237
Douglas Gregor43959a92009-08-20 07:17:43 +00003238 // Complete the switch statement.
3239 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3240 move(Body));
3241}
Mike Stump1eb44332009-09-09 15:08:12 +00003242
Douglas Gregor43959a92009-08-20 07:17:43 +00003243template<typename Derived>
3244Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003245TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003246 // Transform the condition
Douglas Gregor5656e142009-11-24 21:15:44 +00003247 OwningExprResult Cond(SemaRef);
3248 VarDecl *ConditionVar = 0;
3249 if (S->getConditionVariable()) {
3250 ConditionVar
3251 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003252 getDerived().TransformDefinition(
3253 S->getConditionVariable()->getLocation(),
3254 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003255 if (!ConditionVar)
3256 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003257 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003258 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003259
3260 if (Cond.isInvalid())
3261 return SemaRef.StmtError();
3262 }
Mike Stump1eb44332009-09-09 15:08:12 +00003263
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003264 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump1eb44332009-09-09 15:08:12 +00003265
Douglas Gregor43959a92009-08-20 07:17:43 +00003266 // Transform the body
3267 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3268 if (Body.isInvalid())
3269 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003270
Douglas Gregor43959a92009-08-20 07:17:43 +00003271 if (!getDerived().AlwaysRebuild() &&
3272 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003273 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003274 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003275 return SemaRef.Owned(S->Retain());
3276
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003277 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3278 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003279}
Mike Stump1eb44332009-09-09 15:08:12 +00003280
Douglas Gregor43959a92009-08-20 07:17:43 +00003281template<typename Derived>
3282Sema::OwningStmtResult
3283TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3284 // Transform the condition
3285 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3286 if (Cond.isInvalid())
3287 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003288
Douglas Gregor43959a92009-08-20 07:17:43 +00003289 // Transform the body
3290 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3291 if (Body.isInvalid())
3292 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003293
Douglas Gregor43959a92009-08-20 07:17:43 +00003294 if (!getDerived().AlwaysRebuild() &&
3295 Cond.get() == S->getCond() &&
3296 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003297 return SemaRef.Owned(S->Retain());
3298
Douglas Gregor43959a92009-08-20 07:17:43 +00003299 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3300 /*FIXME:*/S->getWhileLoc(), move(Cond),
3301 S->getRParenLoc());
3302}
Mike Stump1eb44332009-09-09 15:08:12 +00003303
Douglas Gregor43959a92009-08-20 07:17:43 +00003304template<typename Derived>
3305Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003306TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003307 // Transform the initialization statement
3308 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3309 if (Init.isInvalid())
3310 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003311
Douglas Gregor43959a92009-08-20 07:17:43 +00003312 // Transform the condition
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003313 OwningExprResult Cond(SemaRef);
3314 VarDecl *ConditionVar = 0;
3315 if (S->getConditionVariable()) {
3316 ConditionVar
3317 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003318 getDerived().TransformDefinition(
3319 S->getConditionVariable()->getLocation(),
3320 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003321 if (!ConditionVar)
3322 return SemaRef.StmtError();
3323 } else {
3324 Cond = getDerived().TransformExpr(S->getCond());
3325
3326 if (Cond.isInvalid())
3327 return SemaRef.StmtError();
3328 }
Mike Stump1eb44332009-09-09 15:08:12 +00003329
Douglas Gregor43959a92009-08-20 07:17:43 +00003330 // Transform the increment
3331 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3332 if (Inc.isInvalid())
3333 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003334
Douglas Gregor43959a92009-08-20 07:17:43 +00003335 // Transform the body
3336 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3337 if (Body.isInvalid())
3338 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003339
Douglas Gregor43959a92009-08-20 07:17:43 +00003340 if (!getDerived().AlwaysRebuild() &&
3341 Init.get() == S->getInit() &&
3342 Cond.get() == S->getCond() &&
3343 Inc.get() == S->getInc() &&
3344 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003345 return SemaRef.Owned(S->Retain());
3346
Douglas Gregor43959a92009-08-20 07:17:43 +00003347 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003348 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003349 ConditionVar,
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003350 getSema().MakeFullExpr(Inc),
Douglas Gregor43959a92009-08-20 07:17:43 +00003351 S->getRParenLoc(), move(Body));
3352}
3353
3354template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003355Sema::OwningStmtResult
3356TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003357 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003358 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003359 S->getLabel());
3360}
3361
3362template<typename Derived>
3363Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003364TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003365 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3366 if (Target.isInvalid())
3367 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003368
Douglas Gregor43959a92009-08-20 07:17:43 +00003369 if (!getDerived().AlwaysRebuild() &&
3370 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003371 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003372
3373 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3374 move(Target));
3375}
3376
3377template<typename Derived>
3378Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003379TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3380 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003381}
Mike Stump1eb44332009-09-09 15:08:12 +00003382
Douglas Gregor43959a92009-08-20 07:17:43 +00003383template<typename Derived>
3384Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003385TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3386 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003387}
Mike Stump1eb44332009-09-09 15:08:12 +00003388
Douglas Gregor43959a92009-08-20 07:17:43 +00003389template<typename Derived>
3390Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003391TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003392 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3393 if (Result.isInvalid())
3394 return SemaRef.StmtError();
3395
Mike Stump1eb44332009-09-09 15:08:12 +00003396 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003397 // to tell whether the return type of the function has changed.
3398 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3399}
Mike Stump1eb44332009-09-09 15:08:12 +00003400
Douglas Gregor43959a92009-08-20 07:17:43 +00003401template<typename Derived>
3402Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003403TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003404 bool DeclChanged = false;
3405 llvm::SmallVector<Decl *, 4> Decls;
3406 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3407 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003408 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3409 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003410 if (!Transformed)
3411 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003412
Douglas Gregor43959a92009-08-20 07:17:43 +00003413 if (Transformed != *D)
3414 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003415
Douglas Gregor43959a92009-08-20 07:17:43 +00003416 Decls.push_back(Transformed);
3417 }
Mike Stump1eb44332009-09-09 15:08:12 +00003418
Douglas Gregor43959a92009-08-20 07:17:43 +00003419 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003420 return SemaRef.Owned(S->Retain());
3421
3422 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003423 S->getStartLoc(), S->getEndLoc());
3424}
Mike Stump1eb44332009-09-09 15:08:12 +00003425
Douglas Gregor43959a92009-08-20 07:17:43 +00003426template<typename Derived>
3427Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003428TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003429 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003430 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003431}
3432
3433template<typename Derived>
3434Sema::OwningStmtResult
3435TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlsson703e3942010-01-24 05:50:09 +00003436
3437 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3438 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003439 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003440
Anders Carlsson703e3942010-01-24 05:50:09 +00003441 OwningExprResult AsmString(SemaRef);
3442 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3443
3444 bool ExprsChanged = false;
3445
3446 // Go through the outputs.
3447 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003448 Names.push_back(S->getOutputIdentifier(I));
Anders Carlssona5a79f72010-01-30 20:05:21 +00003449
Anders Carlsson703e3942010-01-24 05:50:09 +00003450 // No need to transform the constraint literal.
3451 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3452
3453 // Transform the output expr.
3454 Expr *OutputExpr = S->getOutputExpr(I);
3455 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3456 if (Result.isInvalid())
3457 return SemaRef.StmtError();
3458
3459 ExprsChanged |= Result.get() != OutputExpr;
3460
3461 Exprs.push_back(Result.takeAs<Expr>());
3462 }
3463
3464 // Go through the inputs.
3465 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003466 Names.push_back(S->getInputIdentifier(I));
Anders Carlssona5a79f72010-01-30 20:05:21 +00003467
Anders Carlsson703e3942010-01-24 05:50:09 +00003468 // No need to transform the constraint literal.
3469 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3470
3471 // Transform the input expr.
3472 Expr *InputExpr = S->getInputExpr(I);
3473 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3474 if (Result.isInvalid())
3475 return SemaRef.StmtError();
3476
3477 ExprsChanged |= Result.get() != InputExpr;
3478
3479 Exprs.push_back(Result.takeAs<Expr>());
3480 }
3481
3482 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3483 return SemaRef.Owned(S->Retain());
3484
3485 // Go through the clobbers.
3486 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3487 Clobbers.push_back(S->getClobber(I)->Retain());
3488
3489 // No need to transform the asm string literal.
3490 AsmString = SemaRef.Owned(S->getAsmString());
3491
3492 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3493 S->isSimple(),
3494 S->isVolatile(),
3495 S->getNumOutputs(),
3496 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003497 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003498 move_arg(Constraints),
3499 move_arg(Exprs),
3500 move(AsmString),
3501 move_arg(Clobbers),
3502 S->getRParenLoc(),
3503 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003504}
3505
3506
3507template<typename Derived>
3508Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003509TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003510 // FIXME: Implement this
3511 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003512 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003513}
Mike Stump1eb44332009-09-09 15:08:12 +00003514
Douglas Gregor43959a92009-08-20 07:17:43 +00003515template<typename Derived>
3516Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003517TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003518 // FIXME: Implement this
3519 assert(false && "Cannot transform an Objective-C @catch statement");
3520 return SemaRef.Owned(S->Retain());
3521}
Mike Stump1eb44332009-09-09 15:08:12 +00003522
Douglas Gregor43959a92009-08-20 07:17:43 +00003523template<typename Derived>
3524Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003525TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003526 // FIXME: Implement this
3527 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003528 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003529}
Mike Stump1eb44332009-09-09 15:08:12 +00003530
Douglas Gregor43959a92009-08-20 07:17:43 +00003531template<typename Derived>
3532Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003533TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003534 // FIXME: Implement this
3535 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003536 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003537}
Mike Stump1eb44332009-09-09 15:08:12 +00003538
Douglas Gregor43959a92009-08-20 07:17:43 +00003539template<typename Derived>
3540Sema::OwningStmtResult
3541TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003542 ObjCAtSynchronizedStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003543 // FIXME: Implement this
3544 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003545 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003546}
3547
3548template<typename Derived>
3549Sema::OwningStmtResult
3550TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003551 ObjCForCollectionStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003552 // FIXME: Implement this
3553 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003554 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003555}
3556
3557
3558template<typename Derived>
3559Sema::OwningStmtResult
3560TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3561 // Transform the exception declaration, if any.
3562 VarDecl *Var = 0;
3563 if (S->getExceptionDecl()) {
3564 VarDecl *ExceptionDecl = S->getExceptionDecl();
3565 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3566 ExceptionDecl->getDeclName());
3567
3568 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3569 if (T.isNull())
3570 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003571
Douglas Gregor43959a92009-08-20 07:17:43 +00003572 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3573 T,
John McCalla93c9342009-12-07 02:54:59 +00003574 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003575 ExceptionDecl->getIdentifier(),
3576 ExceptionDecl->getLocation(),
3577 /*FIXME: Inaccurate*/
3578 SourceRange(ExceptionDecl->getLocation()));
3579 if (!Var || Var->isInvalidDecl()) {
3580 if (Var)
3581 Var->Destroy(SemaRef.Context);
3582 return SemaRef.StmtError();
3583 }
3584 }
Mike Stump1eb44332009-09-09 15:08:12 +00003585
Douglas Gregor43959a92009-08-20 07:17:43 +00003586 // Transform the actual exception handler.
3587 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3588 if (Handler.isInvalid()) {
3589 if (Var)
3590 Var->Destroy(SemaRef.Context);
3591 return SemaRef.StmtError();
3592 }
Mike Stump1eb44332009-09-09 15:08:12 +00003593
Douglas Gregor43959a92009-08-20 07:17:43 +00003594 if (!getDerived().AlwaysRebuild() &&
3595 !Var &&
3596 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00003597 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003598
3599 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3600 Var,
3601 move(Handler));
3602}
Mike Stump1eb44332009-09-09 15:08:12 +00003603
Douglas Gregor43959a92009-08-20 07:17:43 +00003604template<typename Derived>
3605Sema::OwningStmtResult
3606TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3607 // Transform the try block itself.
Mike Stump1eb44332009-09-09 15:08:12 +00003608 OwningStmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00003609 = getDerived().TransformCompoundStmt(S->getTryBlock());
3610 if (TryBlock.isInvalid())
3611 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003612
Douglas Gregor43959a92009-08-20 07:17:43 +00003613 // Transform the handlers.
3614 bool HandlerChanged = false;
3615 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3616 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump1eb44332009-09-09 15:08:12 +00003617 OwningStmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00003618 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3619 if (Handler.isInvalid())
3620 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003621
Douglas Gregor43959a92009-08-20 07:17:43 +00003622 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3623 Handlers.push_back(Handler.takeAs<Stmt>());
3624 }
Mike Stump1eb44332009-09-09 15:08:12 +00003625
Douglas Gregor43959a92009-08-20 07:17:43 +00003626 if (!getDerived().AlwaysRebuild() &&
3627 TryBlock.get() == S->getTryBlock() &&
3628 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003629 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003630
3631 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump1eb44332009-09-09 15:08:12 +00003632 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00003633}
Mike Stump1eb44332009-09-09 15:08:12 +00003634
Douglas Gregor43959a92009-08-20 07:17:43 +00003635//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00003636// Expression transformation
3637//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00003638template<typename Derived>
3639Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003640TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003641 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003642}
Mike Stump1eb44332009-09-09 15:08:12 +00003643
3644template<typename Derived>
3645Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003646TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00003647 NestedNameSpecifier *Qualifier = 0;
3648 if (E->getQualifier()) {
3649 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003650 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00003651 if (!Qualifier)
3652 return SemaRef.ExprError();
3653 }
John McCalldbd872f2009-12-08 09:08:17 +00003654
3655 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003656 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
3657 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00003658 if (!ND)
3659 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003660
Douglas Gregora2813ce2009-10-23 18:54:35 +00003661 if (!getDerived().AlwaysRebuild() &&
3662 Qualifier == E->getQualifier() &&
3663 ND == E->getDecl() &&
John McCalldbd872f2009-12-08 09:08:17 +00003664 !E->hasExplicitTemplateArgumentList()) {
3665
3666 // Mark it referenced in the new context regardless.
3667 // FIXME: this is a bit instantiation-specific.
3668 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3669
Mike Stump1eb44332009-09-09 15:08:12 +00003670 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00003671 }
John McCalldbd872f2009-12-08 09:08:17 +00003672
3673 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3674 if (E->hasExplicitTemplateArgumentList()) {
3675 TemplateArgs = &TransArgs;
3676 TransArgs.setLAngleLoc(E->getLAngleLoc());
3677 TransArgs.setRAngleLoc(E->getRAngleLoc());
3678 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3679 TemplateArgumentLoc Loc;
3680 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3681 return SemaRef.ExprError();
3682 TransArgs.addArgument(Loc);
3683 }
3684 }
3685
Douglas Gregora2813ce2009-10-23 18:54:35 +00003686 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCalldbd872f2009-12-08 09:08:17 +00003687 ND, E->getLocation(), TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003688}
Mike Stump1eb44332009-09-09 15:08:12 +00003689
Douglas Gregorb98b1992009-08-11 05:31:07 +00003690template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003691Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003692TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003693 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003694}
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>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003699 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003700}
Mike Stump1eb44332009-09-09 15:08:12 +00003701
Douglas Gregorb98b1992009-08-11 05:31:07 +00003702template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003703Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003704TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003705 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003706}
Mike Stump1eb44332009-09-09 15:08:12 +00003707
Douglas Gregorb98b1992009-08-11 05:31:07 +00003708template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003709Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003710TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003711 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003712}
Mike Stump1eb44332009-09-09 15:08:12 +00003713
Douglas Gregorb98b1992009-08-11 05:31:07 +00003714template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003715Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003716TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003717 return SemaRef.Owned(E->Retain());
3718}
3719
3720template<typename Derived>
3721Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003722TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003723 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3724 if (SubExpr.isInvalid())
3725 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003726
Douglas Gregorb98b1992009-08-11 05:31:07 +00003727 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003728 return SemaRef.Owned(E->Retain());
3729
3730 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003731 E->getRParen());
3732}
3733
Mike Stump1eb44332009-09-09 15:08:12 +00003734template<typename Derived>
3735Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003736TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3737 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003738 if (SubExpr.isInvalid())
3739 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003740
Douglas Gregorb98b1992009-08-11 05:31:07 +00003741 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003742 return SemaRef.Owned(E->Retain());
3743
Douglas Gregorb98b1992009-08-11 05:31:07 +00003744 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3745 E->getOpcode(),
3746 move(SubExpr));
3747}
Mike Stump1eb44332009-09-09 15:08:12 +00003748
Douglas Gregorb98b1992009-08-11 05:31:07 +00003749template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003750Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003751TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003752 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00003753 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00003754
John McCalla93c9342009-12-07 02:54:59 +00003755 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00003756 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003757 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003758
John McCall5ab75172009-11-04 07:28:41 +00003759 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003760 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003761
John McCall5ab75172009-11-04 07:28:41 +00003762 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00003763 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003764 E->getSourceRange());
3765 }
Mike Stump1eb44332009-09-09 15:08:12 +00003766
Douglas Gregorb98b1992009-08-11 05:31:07 +00003767 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00003768 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003769 // C++0x [expr.sizeof]p1:
3770 // The operand is either an expression, which is an unevaluated operand
3771 // [...]
3772 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003773
Douglas Gregorb98b1992009-08-11 05:31:07 +00003774 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3775 if (SubExpr.isInvalid())
3776 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003777
Douglas Gregorb98b1992009-08-11 05:31:07 +00003778 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3779 return SemaRef.Owned(E->Retain());
3780 }
Mike Stump1eb44332009-09-09 15:08:12 +00003781
Douglas Gregorb98b1992009-08-11 05:31:07 +00003782 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3783 E->isSizeOf(),
3784 E->getSourceRange());
3785}
Mike Stump1eb44332009-09-09 15:08:12 +00003786
Douglas Gregorb98b1992009-08-11 05:31:07 +00003787template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003788Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003789TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003790 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3791 if (LHS.isInvalid())
3792 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003793
Douglas Gregorb98b1992009-08-11 05:31:07 +00003794 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3795 if (RHS.isInvalid())
3796 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003797
3798
Douglas Gregorb98b1992009-08-11 05:31:07 +00003799 if (!getDerived().AlwaysRebuild() &&
3800 LHS.get() == E->getLHS() &&
3801 RHS.get() == E->getRHS())
3802 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003803
Douglas Gregorb98b1992009-08-11 05:31:07 +00003804 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3805 /*FIXME:*/E->getLHS()->getLocStart(),
3806 move(RHS),
3807 E->getRBracketLoc());
3808}
Mike Stump1eb44332009-09-09 15:08:12 +00003809
3810template<typename Derived>
3811Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003812TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003813 // Transform the callee.
3814 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3815 if (Callee.isInvalid())
3816 return SemaRef.ExprError();
3817
3818 // Transform arguments.
3819 bool ArgChanged = false;
3820 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3821 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3822 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3823 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3824 if (Arg.isInvalid())
3825 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003826
Douglas Gregorb98b1992009-08-11 05:31:07 +00003827 // FIXME: Wrong source location information for the ','.
3828 FakeCommaLocs.push_back(
3829 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00003830
3831 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003832 Args.push_back(Arg.takeAs<Expr>());
3833 }
Mike Stump1eb44332009-09-09 15:08:12 +00003834
Douglas Gregorb98b1992009-08-11 05:31:07 +00003835 if (!getDerived().AlwaysRebuild() &&
3836 Callee.get() == E->getCallee() &&
3837 !ArgChanged)
3838 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003839
Douglas Gregorb98b1992009-08-11 05:31:07 +00003840 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00003841 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003842 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3843 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3844 move_arg(Args),
3845 FakeCommaLocs.data(),
3846 E->getRParenLoc());
3847}
Mike Stump1eb44332009-09-09 15:08:12 +00003848
3849template<typename Derived>
3850Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003851TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003852 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3853 if (Base.isInvalid())
3854 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003855
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003856 NestedNameSpecifier *Qualifier = 0;
3857 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00003858 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003859 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003860 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00003861 if (Qualifier == 0)
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003862 return SemaRef.ExprError();
3863 }
Mike Stump1eb44332009-09-09 15:08:12 +00003864
Eli Friedmanf595cc42009-12-04 06:40:45 +00003865 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003866 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
3867 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00003868 if (!Member)
3869 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003870
Douglas Gregorb98b1992009-08-11 05:31:07 +00003871 if (!getDerived().AlwaysRebuild() &&
3872 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003873 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003874 Member == E->getMemberDecl() &&
Anders Carlsson1f240322009-12-22 05:24:09 +00003875 !E->hasExplicitTemplateArgumentList()) {
3876
3877 // Mark it referenced in the new context regardless.
3878 // FIXME: this is a bit instantiation-specific.
3879 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00003880 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00003881 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00003882
John McCalld5532b62009-11-23 01:53:49 +00003883 TemplateArgumentListInfo TransArgs;
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003884 if (E->hasExplicitTemplateArgumentList()) {
John McCalld5532b62009-11-23 01:53:49 +00003885 TransArgs.setLAngleLoc(E->getLAngleLoc());
3886 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003887 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00003888 TemplateArgumentLoc Loc;
3889 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003890 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00003891 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003892 }
3893 }
3894
Douglas Gregorb98b1992009-08-11 05:31:07 +00003895 // FIXME: Bogus source location for the operator
3896 SourceLocation FakeOperatorLoc
3897 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3898
John McCallc2233c52010-01-15 08:34:02 +00003899 // FIXME: to do this check properly, we will need to preserve the
3900 // first-qualifier-in-scope here, just in case we had a dependent
3901 // base (and therefore couldn't do the check) and a
3902 // nested-name-qualifier (and therefore could do the lookup).
3903 NamedDecl *FirstQualifierInScope = 0;
3904
Douglas Gregorb98b1992009-08-11 05:31:07 +00003905 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3906 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003907 Qualifier,
3908 E->getQualifierRange(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003909 E->getMemberLoc(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003910 Member,
John McCalld5532b62009-11-23 01:53:49 +00003911 (E->hasExplicitTemplateArgumentList()
3912 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00003913 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003914}
Mike Stump1eb44332009-09-09 15:08:12 +00003915
Douglas Gregorb98b1992009-08-11 05:31:07 +00003916template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00003917Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003918TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003919 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3920 if (LHS.isInvalid())
3921 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003922
Douglas Gregorb98b1992009-08-11 05:31:07 +00003923 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3924 if (RHS.isInvalid())
3925 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003926
Douglas Gregorb98b1992009-08-11 05:31:07 +00003927 if (!getDerived().AlwaysRebuild() &&
3928 LHS.get() == E->getLHS() &&
3929 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00003930 return SemaRef.Owned(E->Retain());
3931
Douglas Gregorb98b1992009-08-11 05:31:07 +00003932 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3933 move(LHS), move(RHS));
3934}
3935
Mike Stump1eb44332009-09-09 15:08:12 +00003936template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00003937Sema::OwningExprResult
3938TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00003939 CompoundAssignOperator *E) {
3940 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003941}
Mike Stump1eb44332009-09-09 15:08:12 +00003942
Douglas Gregorb98b1992009-08-11 05:31:07 +00003943template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003944Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003945TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003946 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3947 if (Cond.isInvalid())
3948 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003949
Douglas Gregorb98b1992009-08-11 05:31:07 +00003950 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3951 if (LHS.isInvalid())
3952 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003953
Douglas Gregorb98b1992009-08-11 05:31:07 +00003954 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3955 if (RHS.isInvalid())
3956 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003957
Douglas Gregorb98b1992009-08-11 05:31:07 +00003958 if (!getDerived().AlwaysRebuild() &&
3959 Cond.get() == E->getCond() &&
3960 LHS.get() == E->getLHS() &&
3961 RHS.get() == E->getRHS())
3962 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003963
3964 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00003965 E->getQuestionLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00003966 move(LHS),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00003967 E->getColonLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003968 move(RHS));
3969}
Mike Stump1eb44332009-09-09 15:08:12 +00003970
3971template<typename Derived>
3972Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003973TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00003974 // Implicit casts are eliminated during transformation, since they
3975 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00003976 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003977}
Mike Stump1eb44332009-09-09 15:08:12 +00003978
Douglas Gregorb98b1992009-08-11 05:31:07 +00003979template<typename Derived>
3980Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003981TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00003982 TypeSourceInfo *OldT;
3983 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00003984 {
3985 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00003986 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003987 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3988 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00003989
John McCall9d125032010-01-15 18:39:57 +00003990 OldT = E->getTypeInfoAsWritten();
3991 NewT = getDerived().TransformType(OldT);
3992 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003993 return SemaRef.ExprError();
3994 }
Mike Stump1eb44332009-09-09 15:08:12 +00003995
Douglas Gregora88cfbf2009-12-12 18:16:41 +00003996 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00003997 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003998 if (SubExpr.isInvalid())
3999 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004000
Douglas Gregorb98b1992009-08-11 05:31:07 +00004001 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004002 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004003 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004004 return SemaRef.Owned(E->Retain());
4005
John McCall9d125032010-01-15 18:39:57 +00004006 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4007 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004008 E->getRParenLoc(),
4009 move(SubExpr));
4010}
Mike Stump1eb44332009-09-09 15:08:12 +00004011
Douglas Gregorb98b1992009-08-11 05:31:07 +00004012template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004013Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004014TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00004015 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4016 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4017 if (!NewT)
4018 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004019
Douglas Gregorb98b1992009-08-11 05:31:07 +00004020 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4021 if (Init.isInvalid())
4022 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004023
Douglas Gregorb98b1992009-08-11 05:31:07 +00004024 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00004025 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004026 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00004027 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004028
John McCall1d7d8d62010-01-19 22:33:45 +00004029 // Note: the expression type doesn't necessarily match the
4030 // type-as-written, but that's okay, because it should always be
4031 // derivable from the initializer.
4032
John McCall42f56b52010-01-18 19:35:47 +00004033 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004034 /*FIXME:*/E->getInitializer()->getLocEnd(),
4035 move(Init));
4036}
Mike Stump1eb44332009-09-09 15:08:12 +00004037
Douglas Gregorb98b1992009-08-11 05:31:07 +00004038template<typename Derived>
4039Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004040TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004041 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4042 if (Base.isInvalid())
4043 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004044
Douglas Gregorb98b1992009-08-11 05:31:07 +00004045 if (!getDerived().AlwaysRebuild() &&
4046 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00004047 return SemaRef.Owned(E->Retain());
4048
Douglas Gregorb98b1992009-08-11 05:31:07 +00004049 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004050 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004051 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4052 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4053 E->getAccessorLoc(),
4054 E->getAccessor());
4055}
Mike Stump1eb44332009-09-09 15:08:12 +00004056
Douglas Gregorb98b1992009-08-11 05:31:07 +00004057template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004058Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004059TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004060 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004061
Douglas Gregorb98b1992009-08-11 05:31:07 +00004062 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4063 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4064 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4065 if (Init.isInvalid())
4066 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004067
Douglas Gregorb98b1992009-08-11 05:31:07 +00004068 InitChanged = InitChanged || Init.get() != E->getInit(I);
4069 Inits.push_back(Init.takeAs<Expr>());
4070 }
Mike Stump1eb44332009-09-09 15:08:12 +00004071
Douglas Gregorb98b1992009-08-11 05:31:07 +00004072 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004073 return SemaRef.Owned(E->Retain());
4074
Douglas Gregorb98b1992009-08-11 05:31:07 +00004075 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004076 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004077}
Mike Stump1eb44332009-09-09 15:08:12 +00004078
Douglas Gregorb98b1992009-08-11 05:31:07 +00004079template<typename Derived>
4080Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004081TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004082 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004083
Douglas Gregor43959a92009-08-20 07:17:43 +00004084 // transform the initializer value
Douglas Gregorb98b1992009-08-11 05:31:07 +00004085 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4086 if (Init.isInvalid())
4087 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004088
Douglas Gregor43959a92009-08-20 07:17:43 +00004089 // transform the designators.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004090 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4091 bool ExprChanged = false;
4092 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4093 DEnd = E->designators_end();
4094 D != DEnd; ++D) {
4095 if (D->isFieldDesignator()) {
4096 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4097 D->getDotLoc(),
4098 D->getFieldLoc()));
4099 continue;
4100 }
Mike Stump1eb44332009-09-09 15:08:12 +00004101
Douglas Gregorb98b1992009-08-11 05:31:07 +00004102 if (D->isArrayDesignator()) {
4103 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4104 if (Index.isInvalid())
4105 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004106
4107 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004108 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004109
Douglas Gregorb98b1992009-08-11 05:31:07 +00004110 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4111 ArrayExprs.push_back(Index.release());
4112 continue;
4113 }
Mike Stump1eb44332009-09-09 15:08:12 +00004114
Douglas Gregorb98b1992009-08-11 05:31:07 +00004115 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump1eb44332009-09-09 15:08:12 +00004116 OwningExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004117 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4118 if (Start.isInvalid())
4119 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004120
Douglas Gregorb98b1992009-08-11 05:31:07 +00004121 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4122 if (End.isInvalid())
4123 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004124
4125 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004126 End.get(),
4127 D->getLBracketLoc(),
4128 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004129
Douglas Gregorb98b1992009-08-11 05:31:07 +00004130 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4131 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004132
Douglas Gregorb98b1992009-08-11 05:31:07 +00004133 ArrayExprs.push_back(Start.release());
4134 ArrayExprs.push_back(End.release());
4135 }
Mike Stump1eb44332009-09-09 15:08:12 +00004136
Douglas Gregorb98b1992009-08-11 05:31:07 +00004137 if (!getDerived().AlwaysRebuild() &&
4138 Init.get() == E->getInit() &&
4139 !ExprChanged)
4140 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004141
Douglas Gregorb98b1992009-08-11 05:31:07 +00004142 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4143 E->getEqualOrColonLoc(),
4144 E->usesGNUSyntax(), move(Init));
4145}
Mike Stump1eb44332009-09-09 15:08:12 +00004146
Douglas Gregorb98b1992009-08-11 05:31:07 +00004147template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004148Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004149TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004150 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004151 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4152
4153 // FIXME: Will we ever have proper type location here? Will we actually
4154 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004155 QualType T = getDerived().TransformType(E->getType());
4156 if (T.isNull())
4157 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004158
Douglas Gregorb98b1992009-08-11 05:31:07 +00004159 if (!getDerived().AlwaysRebuild() &&
4160 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004161 return SemaRef.Owned(E->Retain());
4162
Douglas Gregorb98b1992009-08-11 05:31:07 +00004163 return getDerived().RebuildImplicitValueInitExpr(T);
4164}
Mike Stump1eb44332009-09-09 15:08:12 +00004165
Douglas Gregorb98b1992009-08-11 05:31:07 +00004166template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004167Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004168TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004169 // FIXME: Do we want the type as written?
4170 QualType T;
Mike Stump1eb44332009-09-09 15:08:12 +00004171
Douglas Gregorb98b1992009-08-11 05:31:07 +00004172 {
4173 // FIXME: Source location isn't quite accurate.
4174 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4175 T = getDerived().TransformType(E->getType());
4176 if (T.isNull())
4177 return SemaRef.ExprError();
4178 }
Mike Stump1eb44332009-09-09 15:08:12 +00004179
Douglas Gregorb98b1992009-08-11 05:31:07 +00004180 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4181 if (SubExpr.isInvalid())
4182 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004183
Douglas Gregorb98b1992009-08-11 05:31:07 +00004184 if (!getDerived().AlwaysRebuild() &&
4185 T == E->getType() &&
4186 SubExpr.get() == E->getSubExpr())
4187 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004188
Douglas Gregorb98b1992009-08-11 05:31:07 +00004189 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4190 T, E->getRParenLoc());
4191}
4192
4193template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004194Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004195TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004196 bool ArgumentChanged = false;
4197 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4198 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4199 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4200 if (Init.isInvalid())
4201 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004202
Douglas Gregorb98b1992009-08-11 05:31:07 +00004203 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4204 Inits.push_back(Init.takeAs<Expr>());
4205 }
Mike Stump1eb44332009-09-09 15:08:12 +00004206
Douglas Gregorb98b1992009-08-11 05:31:07 +00004207 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4208 move_arg(Inits),
4209 E->getRParenLoc());
4210}
Mike Stump1eb44332009-09-09 15:08:12 +00004211
Douglas Gregorb98b1992009-08-11 05:31:07 +00004212/// \brief Transform an address-of-label expression.
4213///
4214/// By default, the transformation of an address-of-label expression always
4215/// rebuilds the expression, so that the label identifier can be resolved to
4216/// the corresponding label statement by semantic analysis.
4217template<typename Derived>
4218Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004219TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004220 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4221 E->getLabel());
4222}
Mike Stump1eb44332009-09-09 15:08:12 +00004223
4224template<typename Derived>
Douglas Gregorc86a6e92009-11-04 07:01:15 +00004225Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004226TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004227 OwningStmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004228 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4229 if (SubStmt.isInvalid())
4230 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004231
Douglas Gregorb98b1992009-08-11 05:31:07 +00004232 if (!getDerived().AlwaysRebuild() &&
4233 SubStmt.get() == E->getSubStmt())
4234 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004235
4236 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004237 move(SubStmt),
4238 E->getRParenLoc());
4239}
Mike Stump1eb44332009-09-09 15:08:12 +00004240
Douglas Gregorb98b1992009-08-11 05:31:07 +00004241template<typename Derived>
4242Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004243TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004244 QualType T1, T2;
4245 {
4246 // FIXME: Source location isn't quite accurate.
4247 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004248
Douglas Gregorb98b1992009-08-11 05:31:07 +00004249 T1 = getDerived().TransformType(E->getArgType1());
4250 if (T1.isNull())
4251 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004252
Douglas Gregorb98b1992009-08-11 05:31:07 +00004253 T2 = getDerived().TransformType(E->getArgType2());
4254 if (T2.isNull())
4255 return SemaRef.ExprError();
4256 }
4257
4258 if (!getDerived().AlwaysRebuild() &&
4259 T1 == E->getArgType1() &&
4260 T2 == E->getArgType2())
Mike Stump1eb44332009-09-09 15:08:12 +00004261 return SemaRef.Owned(E->Retain());
4262
Douglas Gregorb98b1992009-08-11 05:31:07 +00004263 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4264 T1, T2, E->getRParenLoc());
4265}
Mike Stump1eb44332009-09-09 15:08:12 +00004266
Douglas Gregorb98b1992009-08-11 05:31:07 +00004267template<typename Derived>
4268Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004269TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004270 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4271 if (Cond.isInvalid())
4272 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004273
Douglas Gregorb98b1992009-08-11 05:31:07 +00004274 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4275 if (LHS.isInvalid())
4276 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004277
Douglas Gregorb98b1992009-08-11 05:31:07 +00004278 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4279 if (RHS.isInvalid())
4280 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004281
Douglas Gregorb98b1992009-08-11 05:31:07 +00004282 if (!getDerived().AlwaysRebuild() &&
4283 Cond.get() == E->getCond() &&
4284 LHS.get() == E->getLHS() &&
4285 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004286 return SemaRef.Owned(E->Retain());
4287
Douglas Gregorb98b1992009-08-11 05:31:07 +00004288 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4289 move(Cond), move(LHS), move(RHS),
4290 E->getRParenLoc());
4291}
Mike Stump1eb44332009-09-09 15:08:12 +00004292
Douglas Gregorb98b1992009-08-11 05:31:07 +00004293template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004294Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004295TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004296 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004297}
4298
4299template<typename Derived>
4300Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004301TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004302 switch (E->getOperator()) {
4303 case OO_New:
4304 case OO_Delete:
4305 case OO_Array_New:
4306 case OO_Array_Delete:
4307 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4308 return SemaRef.ExprError();
4309
4310 case OO_Call: {
4311 // This is a call to an object's operator().
4312 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4313
4314 // Transform the object itself.
4315 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4316 if (Object.isInvalid())
4317 return SemaRef.ExprError();
4318
4319 // FIXME: Poor location information
4320 SourceLocation FakeLParenLoc
4321 = SemaRef.PP.getLocForEndOfToken(
4322 static_cast<Expr *>(Object.get())->getLocEnd());
4323
4324 // Transform the call arguments.
4325 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4326 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4327 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004328 if (getDerived().DropCallArgument(E->getArg(I)))
4329 break;
4330
Douglas Gregor668d6d92009-12-13 20:44:55 +00004331 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4332 if (Arg.isInvalid())
4333 return SemaRef.ExprError();
4334
4335 // FIXME: Poor source location information.
4336 SourceLocation FakeCommaLoc
4337 = SemaRef.PP.getLocForEndOfToken(
4338 static_cast<Expr *>(Arg.get())->getLocEnd());
4339 FakeCommaLocs.push_back(FakeCommaLoc);
4340 Args.push_back(Arg.release());
4341 }
4342
4343 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4344 move_arg(Args),
4345 FakeCommaLocs.data(),
4346 E->getLocEnd());
4347 }
4348
4349#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4350 case OO_##Name:
4351#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4352#include "clang/Basic/OperatorKinds.def"
4353 case OO_Subscript:
4354 // Handled below.
4355 break;
4356
4357 case OO_Conditional:
4358 llvm_unreachable("conditional operator is not actually overloadable");
4359 return SemaRef.ExprError();
4360
4361 case OO_None:
4362 case NUM_OVERLOADED_OPERATORS:
4363 llvm_unreachable("not an overloaded operator?");
4364 return SemaRef.ExprError();
4365 }
4366
Douglas Gregorb98b1992009-08-11 05:31:07 +00004367 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4368 if (Callee.isInvalid())
4369 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004370
John McCall454feb92009-12-08 09:21:05 +00004371 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004372 if (First.isInvalid())
4373 return SemaRef.ExprError();
4374
4375 OwningExprResult Second(SemaRef);
4376 if (E->getNumArgs() == 2) {
4377 Second = getDerived().TransformExpr(E->getArg(1));
4378 if (Second.isInvalid())
4379 return SemaRef.ExprError();
4380 }
Mike Stump1eb44332009-09-09 15:08:12 +00004381
Douglas Gregorb98b1992009-08-11 05:31:07 +00004382 if (!getDerived().AlwaysRebuild() &&
4383 Callee.get() == E->getCallee() &&
4384 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00004385 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4386 return SemaRef.Owned(E->Retain());
4387
Douglas Gregorb98b1992009-08-11 05:31:07 +00004388 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4389 E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004390 move(Callee),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004391 move(First),
4392 move(Second));
4393}
Mike Stump1eb44332009-09-09 15:08:12 +00004394
Douglas Gregorb98b1992009-08-11 05:31:07 +00004395template<typename Derived>
4396Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004397TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4398 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004399}
Mike Stump1eb44332009-09-09 15:08:12 +00004400
Douglas Gregorb98b1992009-08-11 05:31:07 +00004401template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004402Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004403TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004404 TypeSourceInfo *OldT;
4405 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004406 {
4407 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004408 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004409 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4410 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004411
John McCall9d125032010-01-15 18:39:57 +00004412 OldT = E->getTypeInfoAsWritten();
4413 NewT = getDerived().TransformType(OldT);
4414 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004415 return SemaRef.ExprError();
4416 }
Mike Stump1eb44332009-09-09 15:08:12 +00004417
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004418 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004419 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004420 if (SubExpr.isInvalid())
4421 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004422
Douglas Gregorb98b1992009-08-11 05:31:07 +00004423 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004424 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004425 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004426 return SemaRef.Owned(E->Retain());
4427
Douglas Gregorb98b1992009-08-11 05:31:07 +00004428 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00004429 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004430 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4431 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4432 SourceLocation FakeRParenLoc
4433 = SemaRef.PP.getLocForEndOfToken(
4434 E->getSubExpr()->getSourceRange().getEnd());
4435 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004436 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004437 FakeLAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00004438 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004439 FakeRAngleLoc,
4440 FakeRAngleLoc,
4441 move(SubExpr),
4442 FakeRParenLoc);
4443}
Mike Stump1eb44332009-09-09 15:08:12 +00004444
Douglas Gregorb98b1992009-08-11 05:31:07 +00004445template<typename Derived>
4446Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004447TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4448 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004449}
Mike Stump1eb44332009-09-09 15:08:12 +00004450
4451template<typename Derived>
4452Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004453TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4454 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004455}
4456
Douglas Gregorb98b1992009-08-11 05:31:07 +00004457template<typename Derived>
4458Sema::OwningExprResult
4459TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004460 CXXReinterpretCastExpr *E) {
4461 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004462}
Mike Stump1eb44332009-09-09 15:08:12 +00004463
Douglas Gregorb98b1992009-08-11 05:31:07 +00004464template<typename Derived>
4465Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004466TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4467 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004468}
Mike Stump1eb44332009-09-09 15:08:12 +00004469
Douglas Gregorb98b1992009-08-11 05:31:07 +00004470template<typename Derived>
4471Sema::OwningExprResult
4472TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004473 CXXFunctionalCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004474 TypeSourceInfo *OldT;
4475 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004476 {
4477 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004478
John McCall9d125032010-01-15 18:39:57 +00004479 OldT = E->getTypeInfoAsWritten();
4480 NewT = getDerived().TransformType(OldT);
4481 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004482 return SemaRef.ExprError();
4483 }
Mike Stump1eb44332009-09-09 15:08:12 +00004484
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004485 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004486 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004487 if (SubExpr.isInvalid())
4488 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004489
Douglas Gregorb98b1992009-08-11 05:31:07 +00004490 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004491 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004492 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004493 return SemaRef.Owned(E->Retain());
4494
Douglas Gregorb98b1992009-08-11 05:31:07 +00004495 // FIXME: The end of the type's source range is wrong
4496 return getDerived().RebuildCXXFunctionalCastExpr(
4497 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall9d125032010-01-15 18:39:57 +00004498 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004499 /*FIXME:*/E->getSubExpr()->getLocStart(),
4500 move(SubExpr),
4501 E->getRParenLoc());
4502}
Mike Stump1eb44332009-09-09 15:08:12 +00004503
Douglas Gregorb98b1992009-08-11 05:31:07 +00004504template<typename Derived>
4505Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004506TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004507 if (E->isTypeOperand()) {
4508 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004509
Douglas Gregorb98b1992009-08-11 05:31:07 +00004510 QualType T = getDerived().TransformType(E->getTypeOperand());
4511 if (T.isNull())
4512 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004513
Douglas Gregorb98b1992009-08-11 05:31:07 +00004514 if (!getDerived().AlwaysRebuild() &&
4515 T == E->getTypeOperand())
4516 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004517
Douglas Gregorb98b1992009-08-11 05:31:07 +00004518 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4519 /*FIXME:*/E->getLocStart(),
4520 T,
4521 E->getLocEnd());
4522 }
Mike Stump1eb44332009-09-09 15:08:12 +00004523
Douglas Gregorb98b1992009-08-11 05:31:07 +00004524 // We don't know whether the expression is potentially evaluated until
4525 // after we perform semantic analysis, so the expression is potentially
4526 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00004527 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004528 Action::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004529
Douglas Gregorb98b1992009-08-11 05:31:07 +00004530 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4531 if (SubExpr.isInvalid())
4532 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004533
Douglas Gregorb98b1992009-08-11 05:31:07 +00004534 if (!getDerived().AlwaysRebuild() &&
4535 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00004536 return SemaRef.Owned(E->Retain());
4537
Douglas Gregorb98b1992009-08-11 05:31:07 +00004538 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4539 /*FIXME:*/E->getLocStart(),
4540 move(SubExpr),
4541 E->getLocEnd());
4542}
4543
4544template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004545Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004546TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004547 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004548}
Mike Stump1eb44332009-09-09 15:08:12 +00004549
Douglas Gregorb98b1992009-08-11 05:31:07 +00004550template<typename Derived>
4551Sema::OwningExprResult
4552TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00004553 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004554 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004555}
Mike Stump1eb44332009-09-09 15:08:12 +00004556
Douglas Gregorb98b1992009-08-11 05:31:07 +00004557template<typename Derived>
4558Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004559TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004560 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004561
Douglas Gregorb98b1992009-08-11 05:31:07 +00004562 QualType T = getDerived().TransformType(E->getType());
4563 if (T.isNull())
4564 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004565
Douglas Gregorb98b1992009-08-11 05:31:07 +00004566 if (!getDerived().AlwaysRebuild() &&
4567 T == E->getType())
4568 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004569
Douglas Gregor828a1972010-01-07 23:12:05 +00004570 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004571}
Mike Stump1eb44332009-09-09 15:08:12 +00004572
Douglas Gregorb98b1992009-08-11 05:31:07 +00004573template<typename Derived>
4574Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004575TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004576 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4577 if (SubExpr.isInvalid())
4578 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004579
Douglas Gregorb98b1992009-08-11 05:31:07 +00004580 if (!getDerived().AlwaysRebuild() &&
4581 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004582 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004583
4584 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4585}
Mike Stump1eb44332009-09-09 15:08:12 +00004586
Douglas Gregorb98b1992009-08-11 05:31:07 +00004587template<typename Derived>
4588Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004589TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004590 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004591 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
4592 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004593 if (!Param)
4594 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004595
Chandler Carruth53cb6f82010-02-08 06:42:49 +00004596 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004597 Param == E->getParam())
4598 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004599
Douglas Gregor036aed12009-12-23 23:03:06 +00004600 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004601}
Mike Stump1eb44332009-09-09 15:08:12 +00004602
Douglas Gregorb98b1992009-08-11 05:31:07 +00004603template<typename Derived>
4604Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004605TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004606 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4607
4608 QualType T = getDerived().TransformType(E->getType());
4609 if (T.isNull())
4610 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004611
Douglas Gregorb98b1992009-08-11 05:31:07 +00004612 if (!getDerived().AlwaysRebuild() &&
4613 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004614 return SemaRef.Owned(E->Retain());
4615
4616 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004617 /*FIXME:*/E->getTypeBeginLoc(),
4618 T,
4619 E->getRParenLoc());
4620}
Mike Stump1eb44332009-09-09 15:08:12 +00004621
Douglas Gregorb98b1992009-08-11 05:31:07 +00004622template<typename Derived>
4623Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004624TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004625 // Transform the type that we're allocating
4626 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4627 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4628 if (AllocType.isNull())
4629 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004630
Douglas Gregorb98b1992009-08-11 05:31:07 +00004631 // Transform the size of the array we're allocating (if any).
4632 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4633 if (ArraySize.isInvalid())
4634 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004635
Douglas Gregorb98b1992009-08-11 05:31:07 +00004636 // Transform the placement arguments (if any).
4637 bool ArgumentChanged = false;
4638 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4639 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4640 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4641 if (Arg.isInvalid())
4642 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004643
Douglas Gregorb98b1992009-08-11 05:31:07 +00004644 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4645 PlacementArgs.push_back(Arg.take());
4646 }
Mike Stump1eb44332009-09-09 15:08:12 +00004647
Douglas Gregor43959a92009-08-20 07:17:43 +00004648 // transform the constructor arguments (if any).
Douglas Gregorb98b1992009-08-11 05:31:07 +00004649 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4650 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4651 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4652 if (Arg.isInvalid())
4653 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004654
Douglas Gregorb98b1992009-08-11 05:31:07 +00004655 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4656 ConstructorArgs.push_back(Arg.take());
4657 }
Mike Stump1eb44332009-09-09 15:08:12 +00004658
Douglas Gregor1af74512010-02-26 00:38:10 +00004659 // Transform constructor, new operator, and delete operator.
4660 CXXConstructorDecl *Constructor = 0;
4661 if (E->getConstructor()) {
4662 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004663 getDerived().TransformDecl(E->getLocStart(),
4664 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00004665 if (!Constructor)
4666 return SemaRef.ExprError();
4667 }
4668
4669 FunctionDecl *OperatorNew = 0;
4670 if (E->getOperatorNew()) {
4671 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004672 getDerived().TransformDecl(E->getLocStart(),
4673 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00004674 if (!OperatorNew)
4675 return SemaRef.ExprError();
4676 }
4677
4678 FunctionDecl *OperatorDelete = 0;
4679 if (E->getOperatorDelete()) {
4680 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004681 getDerived().TransformDecl(E->getLocStart(),
4682 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00004683 if (!OperatorDelete)
4684 return SemaRef.ExprError();
4685 }
4686
Douglas Gregorb98b1992009-08-11 05:31:07 +00004687 if (!getDerived().AlwaysRebuild() &&
4688 AllocType == E->getAllocatedType() &&
4689 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00004690 Constructor == E->getConstructor() &&
4691 OperatorNew == E->getOperatorNew() &&
4692 OperatorDelete == E->getOperatorDelete() &&
4693 !ArgumentChanged) {
4694 // Mark any declarations we need as referenced.
4695 // FIXME: instantiation-specific.
4696 if (Constructor)
4697 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
4698 if (OperatorNew)
4699 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
4700 if (OperatorDelete)
4701 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00004702 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00004703 }
Mike Stump1eb44332009-09-09 15:08:12 +00004704
Douglas Gregor5b5ad842009-12-22 17:13:37 +00004705 if (!ArraySize.get()) {
4706 // If no array size was specified, but the new expression was
4707 // instantiated with an array type (e.g., "new T" where T is
4708 // instantiated with "int[4]"), extract the outer bound from the
4709 // array type as our array size. We do this with constant and
4710 // dependently-sized array types.
4711 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4712 if (!ArrayT) {
4713 // Do nothing
4714 } else if (const ConstantArrayType *ConsArrayT
4715 = dyn_cast<ConstantArrayType>(ArrayT)) {
4716 ArraySize
4717 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4718 ConsArrayT->getSize(),
4719 SemaRef.Context.getSizeType(),
4720 /*FIXME:*/E->getLocStart()));
4721 AllocType = ConsArrayT->getElementType();
4722 } else if (const DependentSizedArrayType *DepArrayT
4723 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4724 if (DepArrayT->getSizeExpr()) {
4725 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4726 AllocType = DepArrayT->getElementType();
4727 }
4728 }
4729 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004730 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4731 E->isGlobalNew(),
4732 /*FIXME:*/E->getLocStart(),
4733 move_arg(PlacementArgs),
4734 /*FIXME:*/E->getLocStart(),
4735 E->isParenTypeId(),
4736 AllocType,
4737 /*FIXME:*/E->getLocStart(),
4738 /*FIXME:*/SourceRange(),
4739 move(ArraySize),
4740 /*FIXME:*/E->getLocStart(),
4741 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00004742 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004743}
Mike Stump1eb44332009-09-09 15:08:12 +00004744
Douglas Gregorb98b1992009-08-11 05:31:07 +00004745template<typename Derived>
4746Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004747TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004748 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4749 if (Operand.isInvalid())
4750 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004751
Douglas Gregor1af74512010-02-26 00:38:10 +00004752 // Transform the delete operator, if known.
4753 FunctionDecl *OperatorDelete = 0;
4754 if (E->getOperatorDelete()) {
4755 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004756 getDerived().TransformDecl(E->getLocStart(),
4757 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00004758 if (!OperatorDelete)
4759 return SemaRef.ExprError();
4760 }
4761
Douglas Gregorb98b1992009-08-11 05:31:07 +00004762 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00004763 Operand.get() == E->getArgument() &&
4764 OperatorDelete == E->getOperatorDelete()) {
4765 // Mark any declarations we need as referenced.
4766 // FIXME: instantiation-specific.
4767 if (OperatorDelete)
4768 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00004769 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00004770 }
Mike Stump1eb44332009-09-09 15:08:12 +00004771
Douglas Gregorb98b1992009-08-11 05:31:07 +00004772 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4773 E->isGlobalDelete(),
4774 E->isArrayForm(),
4775 move(Operand));
4776}
Mike Stump1eb44332009-09-09 15:08:12 +00004777
Douglas Gregorb98b1992009-08-11 05:31:07 +00004778template<typename Derived>
4779Sema::OwningExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00004780TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00004781 CXXPseudoDestructorExpr *E) {
Douglas Gregora71d8192009-09-04 17:36:40 +00004782 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4783 if (Base.isInvalid())
4784 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004785
Douglas Gregora2e7dd22010-02-25 01:56:36 +00004786 Sema::TypeTy *ObjectTypePtr = 0;
4787 bool MayBePseudoDestructor = false;
4788 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4789 E->getOperatorLoc(),
4790 E->isArrow()? tok::arrow : tok::period,
4791 ObjectTypePtr,
4792 MayBePseudoDestructor);
4793 if (Base.isInvalid())
4794 return SemaRef.ExprError();
4795
4796 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregora71d8192009-09-04 17:36:40 +00004797 NestedNameSpecifier *Qualifier
4798 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00004799 E->getQualifierRange(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00004800 ObjectType);
Douglas Gregora71d8192009-09-04 17:36:40 +00004801 if (E->getQualifier() && !Qualifier)
4802 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004803
Douglas Gregora2e7dd22010-02-25 01:56:36 +00004804 PseudoDestructorTypeStorage Destroyed;
4805 if (E->getDestroyedTypeInfo()) {
4806 TypeSourceInfo *DestroyedTypeInfo
4807 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
4808 if (!DestroyedTypeInfo)
4809 return SemaRef.ExprError();
4810 Destroyed = DestroyedTypeInfo;
4811 } else if (ObjectType->isDependentType()) {
4812 // We aren't likely to be able to resolve the identifier down to a type
4813 // now anyway, so just retain the identifier.
4814 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
4815 E->getDestroyedTypeLoc());
4816 } else {
4817 // Look for a destructor known with the given name.
4818 CXXScopeSpec SS;
4819 if (Qualifier) {
4820 SS.setScopeRep(Qualifier);
4821 SS.setRange(E->getQualifierRange());
4822 }
4823
4824 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
4825 *E->getDestroyedTypeIdentifier(),
4826 E->getDestroyedTypeLoc(),
4827 /*Scope=*/0,
4828 SS, ObjectTypePtr,
4829 false);
4830 if (!T)
4831 return SemaRef.ExprError();
4832
4833 Destroyed
4834 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
4835 E->getDestroyedTypeLoc());
4836 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004837
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004838 TypeSourceInfo *ScopeTypeInfo = 0;
4839 if (E->getScopeTypeInfo()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00004840 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
4841 ObjectType);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004842 if (!ScopeTypeInfo)
Douglas Gregora71d8192009-09-04 17:36:40 +00004843 return SemaRef.ExprError();
4844 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004845
Douglas Gregora71d8192009-09-04 17:36:40 +00004846 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4847 E->getOperatorLoc(),
4848 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00004849 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004850 E->getQualifierRange(),
4851 ScopeTypeInfo,
4852 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00004853 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00004854 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00004855}
Mike Stump1eb44332009-09-09 15:08:12 +00004856
Douglas Gregora71d8192009-09-04 17:36:40 +00004857template<typename Derived>
4858Sema::OwningExprResult
John McCallba135432009-11-21 08:51:07 +00004859TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00004860 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00004861 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4862
4863 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4864 Sema::LookupOrdinaryName);
4865
4866 // Transform all the decls.
4867 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4868 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004869 NamedDecl *InstD = static_cast<NamedDecl*>(
4870 getDerived().TransformDecl(Old->getNameLoc(),
4871 *I));
John McCall9f54ad42009-12-10 09:41:52 +00004872 if (!InstD) {
4873 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4874 // This can happen because of dependent hiding.
4875 if (isa<UsingShadowDecl>(*I))
4876 continue;
4877 else
4878 return SemaRef.ExprError();
4879 }
John McCallf7a1a742009-11-24 19:00:30 +00004880
4881 // Expand using declarations.
4882 if (isa<UsingDecl>(InstD)) {
4883 UsingDecl *UD = cast<UsingDecl>(InstD);
4884 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4885 E = UD->shadow_end(); I != E; ++I)
4886 R.addDecl(*I);
4887 continue;
4888 }
4889
4890 R.addDecl(InstD);
4891 }
4892
4893 // Resolve a kind, but don't do any further analysis. If it's
4894 // ambiguous, the callee needs to deal with it.
4895 R.resolveKind();
4896
4897 // Rebuild the nested-name qualifier, if present.
4898 CXXScopeSpec SS;
4899 NestedNameSpecifier *Qualifier = 0;
4900 if (Old->getQualifier()) {
4901 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004902 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00004903 if (!Qualifier)
4904 return SemaRef.ExprError();
4905
4906 SS.setScopeRep(Qualifier);
4907 SS.setRange(Old->getQualifierRange());
4908 }
4909
4910 // If we have no template arguments, it's a normal declaration name.
4911 if (!Old->hasExplicitTemplateArgs())
4912 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4913
4914 // If we have template arguments, rebuild them, then rebuild the
4915 // templateid expression.
4916 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4917 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4918 TemplateArgumentLoc Loc;
4919 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4920 return SemaRef.ExprError();
4921 TransArgs.addArgument(Loc);
4922 }
4923
4924 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4925 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004926}
Mike Stump1eb44332009-09-09 15:08:12 +00004927
Douglas Gregorb98b1992009-08-11 05:31:07 +00004928template<typename Derived>
4929Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004930TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004931 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004932
Douglas Gregorb98b1992009-08-11 05:31:07 +00004933 QualType T = getDerived().TransformType(E->getQueriedType());
4934 if (T.isNull())
4935 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004936
Douglas Gregorb98b1992009-08-11 05:31:07 +00004937 if (!getDerived().AlwaysRebuild() &&
4938 T == E->getQueriedType())
4939 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004940
Douglas Gregorb98b1992009-08-11 05:31:07 +00004941 // FIXME: Bad location information
4942 SourceLocation FakeLParenLoc
4943 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump1eb44332009-09-09 15:08:12 +00004944
4945 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004946 E->getLocStart(),
4947 /*FIXME:*/FakeLParenLoc,
4948 T,
4949 E->getLocEnd());
4950}
Mike Stump1eb44332009-09-09 15:08:12 +00004951
Douglas Gregorb98b1992009-08-11 05:31:07 +00004952template<typename Derived>
4953Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00004954TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall454feb92009-12-08 09:21:05 +00004955 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004956 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00004957 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004958 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004959 if (!NNS)
4960 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004961
4962 DeclarationName Name
Douglas Gregor81499bb2009-09-03 22:13:48 +00004963 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4964 if (!Name)
4965 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004966
John McCallf7a1a742009-11-24 19:00:30 +00004967 if (!E->hasExplicitTemplateArgs()) {
4968 if (!getDerived().AlwaysRebuild() &&
4969 NNS == E->getQualifier() &&
4970 Name == E->getDeclName())
4971 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004972
John McCallf7a1a742009-11-24 19:00:30 +00004973 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4974 E->getQualifierRange(),
4975 Name, E->getLocation(),
4976 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00004977 }
John McCalld5532b62009-11-23 01:53:49 +00004978
4979 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004980 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004981 TemplateArgumentLoc Loc;
4982 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb98b1992009-08-11 05:31:07 +00004983 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004984 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004985 }
4986
John McCallf7a1a742009-11-24 19:00:30 +00004987 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4988 E->getQualifierRange(),
4989 Name, E->getLocation(),
4990 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004991}
4992
4993template<typename Derived>
4994Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004995TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00004996 // CXXConstructExprs are always implicit, so when we have a
4997 // 1-argument construction we just transform that argument.
4998 if (E->getNumArgs() == 1 ||
4999 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5000 return getDerived().TransformExpr(E->getArg(0));
5001
Douglas Gregorb98b1992009-08-11 05:31:07 +00005002 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5003
5004 QualType T = getDerived().TransformType(E->getType());
5005 if (T.isNull())
5006 return SemaRef.ExprError();
5007
5008 CXXConstructorDecl *Constructor
5009 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005010 getDerived().TransformDecl(E->getLocStart(),
5011 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005012 if (!Constructor)
5013 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005014
Douglas Gregorb98b1992009-08-11 05:31:07 +00005015 bool ArgumentChanged = false;
5016 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00005017 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005018 ArgEnd = E->arg_end();
5019 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005020 if (getDerived().DropCallArgument(*Arg)) {
5021 ArgumentChanged = true;
5022 break;
5023 }
5024
Douglas Gregorb98b1992009-08-11 05:31:07 +00005025 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5026 if (TransArg.isInvalid())
5027 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005028
Douglas Gregorb98b1992009-08-11 05:31:07 +00005029 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5030 Args.push_back(TransArg.takeAs<Expr>());
5031 }
5032
5033 if (!getDerived().AlwaysRebuild() &&
5034 T == E->getType() &&
5035 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00005036 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00005037 // Mark the constructor as referenced.
5038 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00005039 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005040 return SemaRef.Owned(E->Retain());
Douglas Gregorc845aad2010-02-26 00:01:57 +00005041 }
Mike Stump1eb44332009-09-09 15:08:12 +00005042
Douglas Gregor4411d2e2009-12-14 16:27:04 +00005043 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5044 Constructor, E->isElidable(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005045 move_arg(Args));
5046}
Mike Stump1eb44332009-09-09 15:08:12 +00005047
Douglas Gregorb98b1992009-08-11 05:31:07 +00005048/// \brief Transform a C++ temporary-binding expression.
5049///
Douglas Gregor51326552009-12-24 18:51:59 +00005050/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5051/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005052template<typename Derived>
5053Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005054TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005055 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005056}
Mike Stump1eb44332009-09-09 15:08:12 +00005057
Anders Carlssoneb60edf2010-01-29 02:39:32 +00005058/// \brief Transform a C++ reference-binding expression.
5059///
5060/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5061/// transform the subexpression and return that.
5062template<typename Derived>
5063Sema::OwningExprResult
5064TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5065 return getDerived().TransformExpr(E->getSubExpr());
5066}
5067
Mike Stump1eb44332009-09-09 15:08:12 +00005068/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00005069/// be destroyed after the expression is evaluated.
5070///
Douglas Gregor51326552009-12-24 18:51:59 +00005071/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5072/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005073template<typename Derived>
5074Sema::OwningExprResult
5075TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00005076 CXXExprWithTemporaries *E) {
5077 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005078}
Mike Stump1eb44332009-09-09 15:08:12 +00005079
Douglas Gregorb98b1992009-08-11 05:31:07 +00005080template<typename Derived>
5081Sema::OwningExprResult
5082TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall454feb92009-12-08 09:21:05 +00005083 CXXTemporaryObjectExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005084 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5085 QualType T = getDerived().TransformType(E->getType());
5086 if (T.isNull())
5087 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005088
Douglas Gregorb98b1992009-08-11 05:31:07 +00005089 CXXConstructorDecl *Constructor
5090 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005091 getDerived().TransformDecl(E->getLocStart(),
5092 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005093 if (!Constructor)
5094 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005095
Douglas Gregorb98b1992009-08-11 05:31:07 +00005096 bool ArgumentChanged = false;
5097 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5098 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005099 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005100 ArgEnd = E->arg_end();
5101 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005102 if (getDerived().DropCallArgument(*Arg)) {
5103 ArgumentChanged = true;
5104 break;
5105 }
5106
Douglas Gregorb98b1992009-08-11 05:31:07 +00005107 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5108 if (TransArg.isInvalid())
5109 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005110
Douglas Gregorb98b1992009-08-11 05:31:07 +00005111 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5112 Args.push_back((Expr *)TransArg.release());
5113 }
Mike Stump1eb44332009-09-09 15:08:12 +00005114
Douglas Gregorb98b1992009-08-11 05:31:07 +00005115 if (!getDerived().AlwaysRebuild() &&
5116 T == E->getType() &&
5117 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005118 !ArgumentChanged) {
5119 // FIXME: Instantiation-specific
5120 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005121 return SemaRef.Owned(E->Retain());
Douglas Gregor91be6f52010-03-02 17:18:33 +00005122 }
Mike Stump1eb44332009-09-09 15:08:12 +00005123
Douglas Gregorb98b1992009-08-11 05:31:07 +00005124 // FIXME: Bogus location information
5125 SourceLocation CommaLoc;
5126 if (Args.size() > 1) {
5127 Expr *First = (Expr *)Args[0];
Mike Stump1eb44332009-09-09 15:08:12 +00005128 CommaLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005129 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5130 }
5131 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5132 T,
5133 /*FIXME:*/E->getTypeBeginLoc(),
5134 move_arg(Args),
5135 &CommaLoc,
5136 E->getLocEnd());
5137}
Mike Stump1eb44332009-09-09 15:08:12 +00005138
Douglas Gregorb98b1992009-08-11 05:31:07 +00005139template<typename Derived>
5140Sema::OwningExprResult
5141TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005142 CXXUnresolvedConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005143 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5144 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5145 if (T.isNull())
5146 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005147
Douglas Gregorb98b1992009-08-11 05:31:07 +00005148 bool ArgumentChanged = false;
5149 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5150 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5151 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5152 ArgEnd = E->arg_end();
5153 Arg != ArgEnd; ++Arg) {
5154 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5155 if (TransArg.isInvalid())
5156 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005157
Douglas Gregorb98b1992009-08-11 05:31:07 +00005158 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5159 FakeCommaLocs.push_back(
5160 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5161 Args.push_back(TransArg.takeAs<Expr>());
5162 }
Mike Stump1eb44332009-09-09 15:08:12 +00005163
Douglas Gregorb98b1992009-08-11 05:31:07 +00005164 if (!getDerived().AlwaysRebuild() &&
5165 T == E->getTypeAsWritten() &&
5166 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005167 return SemaRef.Owned(E->Retain());
5168
Douglas Gregorb98b1992009-08-11 05:31:07 +00005169 // FIXME: we're faking the locations of the commas
5170 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5171 T,
5172 E->getLParenLoc(),
5173 move_arg(Args),
5174 FakeCommaLocs.data(),
5175 E->getRParenLoc());
5176}
Mike Stump1eb44332009-09-09 15:08:12 +00005177
Douglas Gregorb98b1992009-08-11 05:31:07 +00005178template<typename Derived>
5179Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00005180TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall454feb92009-12-08 09:21:05 +00005181 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005182 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005183 OwningExprResult Base(SemaRef, (Expr*) 0);
5184 Expr *OldBase;
5185 QualType BaseType;
5186 QualType ObjectType;
5187 if (!E->isImplicitAccess()) {
5188 OldBase = E->getBase();
5189 Base = getDerived().TransformExpr(OldBase);
5190 if (Base.isInvalid())
5191 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005192
John McCallaa81e162009-12-01 22:10:20 +00005193 // Start the member reference and compute the object's type.
5194 Sema::TypeTy *ObjectTy = 0;
Douglas Gregord4dca082010-02-24 18:44:31 +00005195 bool MayBePseudoDestructor = false;
John McCallaa81e162009-12-01 22:10:20 +00005196 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5197 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005198 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005199 ObjectTy,
5200 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005201 if (Base.isInvalid())
5202 return SemaRef.ExprError();
5203
5204 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5205 BaseType = ((Expr*) Base.get())->getType();
5206 } else {
5207 OldBase = 0;
5208 BaseType = getDerived().TransformType(E->getBaseType());
5209 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5210 }
Mike Stump1eb44332009-09-09 15:08:12 +00005211
Douglas Gregor6cd21982009-10-20 05:58:46 +00005212 // Transform the first part of the nested-name-specifier that qualifies
5213 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005214 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005215 = getDerived().TransformFirstQualifierInScope(
5216 E->getFirstQualifierFoundInScope(),
5217 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005218
Douglas Gregora38c6872009-09-03 16:14:30 +00005219 NestedNameSpecifier *Qualifier = 0;
5220 if (E->getQualifier()) {
5221 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5222 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005223 ObjectType,
5224 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005225 if (!Qualifier)
5226 return SemaRef.ExprError();
5227 }
Mike Stump1eb44332009-09-09 15:08:12 +00005228
5229 DeclarationName Name
Douglas Gregordd62b152009-10-19 22:04:39 +00005230 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCallaa81e162009-12-01 22:10:20 +00005231 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00005232 if (!Name)
5233 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005234
John McCallaa81e162009-12-01 22:10:20 +00005235 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005236 // This is a reference to a member without an explicitly-specified
5237 // template argument list. Optimize for this common case.
5238 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005239 Base.get() == OldBase &&
5240 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005241 Qualifier == E->getQualifier() &&
5242 Name == E->getMember() &&
5243 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005244 return SemaRef.Owned(E->Retain());
5245
John McCall865d4472009-11-19 22:55:06 +00005246 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005247 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005248 E->isArrow(),
5249 E->getOperatorLoc(),
5250 Qualifier,
5251 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005252 FirstQualifierInScope,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005253 Name,
5254 E->getMemberLoc(),
John McCall129e2df2009-11-30 22:42:35 +00005255 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005256 }
5257
John McCalld5532b62009-11-23 01:53:49 +00005258 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005259 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005260 TemplateArgumentLoc Loc;
5261 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005262 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005263 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005264 }
Mike Stump1eb44332009-09-09 15:08:12 +00005265
John McCall865d4472009-11-19 22:55:06 +00005266 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005267 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005268 E->isArrow(),
5269 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005270 Qualifier,
5271 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005272 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005273 Name,
5274 E->getMemberLoc(),
5275 &TransArgs);
5276}
5277
5278template<typename Derived>
5279Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005280TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005281 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005282 OwningExprResult Base(SemaRef, (Expr*) 0);
5283 QualType BaseType;
5284 if (!Old->isImplicitAccess()) {
5285 Base = getDerived().TransformExpr(Old->getBase());
5286 if (Base.isInvalid())
5287 return SemaRef.ExprError();
5288 BaseType = ((Expr*) Base.get())->getType();
5289 } else {
5290 BaseType = getDerived().TransformType(Old->getBaseType());
5291 }
John McCall129e2df2009-11-30 22:42:35 +00005292
5293 NestedNameSpecifier *Qualifier = 0;
5294 if (Old->getQualifier()) {
5295 Qualifier
5296 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005297 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00005298 if (Qualifier == 0)
5299 return SemaRef.ExprError();
5300 }
5301
5302 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5303 Sema::LookupOrdinaryName);
5304
5305 // Transform all the decls.
5306 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5307 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005308 NamedDecl *InstD = static_cast<NamedDecl*>(
5309 getDerived().TransformDecl(Old->getMemberLoc(),
5310 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005311 if (!InstD) {
5312 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5313 // This can happen because of dependent hiding.
5314 if (isa<UsingShadowDecl>(*I))
5315 continue;
5316 else
5317 return SemaRef.ExprError();
5318 }
John McCall129e2df2009-11-30 22:42:35 +00005319
5320 // Expand using declarations.
5321 if (isa<UsingDecl>(InstD)) {
5322 UsingDecl *UD = cast<UsingDecl>(InstD);
5323 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5324 E = UD->shadow_end(); I != E; ++I)
5325 R.addDecl(*I);
5326 continue;
5327 }
5328
5329 R.addDecl(InstD);
5330 }
5331
5332 R.resolveKind();
5333
5334 TemplateArgumentListInfo TransArgs;
5335 if (Old->hasExplicitTemplateArgs()) {
5336 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5337 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5338 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5339 TemplateArgumentLoc Loc;
5340 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5341 Loc))
5342 return SemaRef.ExprError();
5343 TransArgs.addArgument(Loc);
5344 }
5345 }
John McCallc2233c52010-01-15 08:34:02 +00005346
5347 // FIXME: to do this check properly, we will need to preserve the
5348 // first-qualifier-in-scope here, just in case we had a dependent
5349 // base (and therefore couldn't do the check) and a
5350 // nested-name-qualifier (and therefore could do the lookup).
5351 NamedDecl *FirstQualifierInScope = 0;
John McCall129e2df2009-11-30 22:42:35 +00005352
5353 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005354 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00005355 Old->getOperatorLoc(),
5356 Old->isArrow(),
5357 Qualifier,
5358 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00005359 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005360 R,
5361 (Old->hasExplicitTemplateArgs()
5362 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005363}
5364
5365template<typename Derived>
5366Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005367TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005368 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005369}
5370
Mike Stump1eb44332009-09-09 15:08:12 +00005371template<typename Derived>
5372Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005373TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005374 // FIXME: poor source location
5375 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5376 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5377 if (EncodedType.isNull())
5378 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005379
Douglas Gregorb98b1992009-08-11 05:31:07 +00005380 if (!getDerived().AlwaysRebuild() &&
5381 EncodedType == E->getEncodedType())
Mike Stump1eb44332009-09-09 15:08:12 +00005382 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005383
5384 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5385 EncodedType,
5386 E->getRParenLoc());
5387}
Mike Stump1eb44332009-09-09 15:08:12 +00005388
Douglas Gregorb98b1992009-08-11 05:31:07 +00005389template<typename Derived>
5390Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005391TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005392 // FIXME: Implement this!
5393 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005394 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005395}
5396
Mike Stump1eb44332009-09-09 15:08:12 +00005397template<typename Derived>
5398Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005399TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005400 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005401}
5402
Mike Stump1eb44332009-09-09 15:08:12 +00005403template<typename Derived>
5404Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005405TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005406 ObjCProtocolDecl *Protocol
Douglas Gregorb98b1992009-08-11 05:31:07 +00005407 = cast_or_null<ObjCProtocolDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005408 getDerived().TransformDecl(E->getLocStart(),
5409 E->getProtocol()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005410 if (!Protocol)
5411 return SemaRef.ExprError();
5412
5413 if (!getDerived().AlwaysRebuild() &&
5414 Protocol == E->getProtocol())
Mike Stump1eb44332009-09-09 15:08:12 +00005415 return SemaRef.Owned(E->Retain());
5416
Douglas Gregorb98b1992009-08-11 05:31:07 +00005417 return getDerived().RebuildObjCProtocolExpr(Protocol,
5418 E->getAtLoc(),
5419 /*FIXME:*/E->getAtLoc(),
5420 /*FIXME:*/E->getAtLoc(),
5421 E->getRParenLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00005422
Douglas Gregorb98b1992009-08-11 05:31:07 +00005423}
5424
Mike Stump1eb44332009-09-09 15:08:12 +00005425template<typename Derived>
5426Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005427TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005428 // FIXME: Implement this!
5429 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005430 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005431}
5432
Mike Stump1eb44332009-09-09 15:08:12 +00005433template<typename Derived>
5434Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005435TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005436 // FIXME: Implement this!
5437 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005438 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005439}
5440
Mike Stump1eb44332009-09-09 15:08:12 +00005441template<typename Derived>
5442Sema::OwningExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00005443TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00005444 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005445 // FIXME: Implement this!
5446 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005447 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005448}
5449
Mike Stump1eb44332009-09-09 15:08:12 +00005450template<typename Derived>
5451Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005452TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005453 // FIXME: Implement this!
5454 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005455 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005456}
5457
Mike Stump1eb44332009-09-09 15:08:12 +00005458template<typename Derived>
5459Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005460TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005461 // FIXME: Implement this!
5462 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005463 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005464}
5465
Mike Stump1eb44332009-09-09 15:08:12 +00005466template<typename Derived>
5467Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005468TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005469 bool ArgumentChanged = false;
5470 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5471 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5472 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5473 if (SubExpr.isInvalid())
5474 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005475
Douglas Gregorb98b1992009-08-11 05:31:07 +00005476 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5477 SubExprs.push_back(SubExpr.takeAs<Expr>());
5478 }
Mike Stump1eb44332009-09-09 15:08:12 +00005479
Douglas Gregorb98b1992009-08-11 05:31:07 +00005480 if (!getDerived().AlwaysRebuild() &&
5481 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005482 return SemaRef.Owned(E->Retain());
5483
Douglas Gregorb98b1992009-08-11 05:31:07 +00005484 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5485 move_arg(SubExprs),
5486 E->getRParenLoc());
5487}
5488
Mike Stump1eb44332009-09-09 15:08:12 +00005489template<typename Derived>
5490Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005491TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005492 // FIXME: Implement this!
5493 assert(false && "Cannot transform block expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005494 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005495}
5496
Mike Stump1eb44332009-09-09 15:08:12 +00005497template<typename Derived>
5498Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005499TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005500 // FIXME: Implement this!
5501 assert(false && "Cannot transform block-related expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005502 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005503}
Mike Stump1eb44332009-09-09 15:08:12 +00005504
Douglas Gregorb98b1992009-08-11 05:31:07 +00005505//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00005506// Type reconstruction
5507//===----------------------------------------------------------------------===//
5508
Mike Stump1eb44332009-09-09 15:08:12 +00005509template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005510QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5511 SourceLocation Star) {
5512 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005513 getDerived().getBaseEntity());
5514}
5515
Mike Stump1eb44332009-09-09 15:08:12 +00005516template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005517QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5518 SourceLocation Star) {
5519 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005520 getDerived().getBaseEntity());
5521}
5522
Mike Stump1eb44332009-09-09 15:08:12 +00005523template<typename Derived>
5524QualType
John McCall85737a72009-10-30 00:06:24 +00005525TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5526 bool WrittenAsLValue,
5527 SourceLocation Sigil) {
5528 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5529 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005530}
5531
5532template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005533QualType
John McCall85737a72009-10-30 00:06:24 +00005534TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5535 QualType ClassType,
5536 SourceLocation Sigil) {
John McCall0953e762009-09-24 19:53:00 +00005537 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall85737a72009-10-30 00:06:24 +00005538 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005539}
5540
5541template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005542QualType
John McCall85737a72009-10-30 00:06:24 +00005543TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5544 SourceLocation Sigil) {
5545 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCalla2becad2009-10-21 00:40:46 +00005546 getDerived().getBaseEntity());
5547}
5548
5549template<typename Derived>
5550QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00005551TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5552 ArrayType::ArraySizeModifier SizeMod,
5553 const llvm::APInt *Size,
5554 Expr *SizeExpr,
5555 unsigned IndexTypeQuals,
5556 SourceRange BracketsRange) {
5557 if (SizeExpr || !Size)
5558 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5559 IndexTypeQuals, BracketsRange,
5560 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00005561
5562 QualType Types[] = {
5563 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5564 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5565 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00005566 };
5567 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5568 QualType SizeType;
5569 for (unsigned I = 0; I != NumTypes; ++I)
5570 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5571 SizeType = Types[I];
5572 break;
5573 }
Mike Stump1eb44332009-09-09 15:08:12 +00005574
Douglas Gregor577f75a2009-08-04 16:50:30 +00005575 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005576 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005577 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00005578 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005579}
Mike Stump1eb44332009-09-09 15:08:12 +00005580
Douglas Gregor577f75a2009-08-04 16:50:30 +00005581template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005582QualType
5583TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005584 ArrayType::ArraySizeModifier SizeMod,
5585 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00005586 unsigned IndexTypeQuals,
5587 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005588 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00005589 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005590}
5591
5592template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005593QualType
Mike Stump1eb44332009-09-09 15:08:12 +00005594TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005595 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00005596 unsigned IndexTypeQuals,
5597 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005598 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00005599 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005600}
Mike Stump1eb44332009-09-09 15:08:12 +00005601
Douglas Gregor577f75a2009-08-04 16:50:30 +00005602template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005603QualType
5604TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005605 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005606 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005607 unsigned IndexTypeQuals,
5608 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005609 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005610 SizeExpr.takeAs<Expr>(),
5611 IndexTypeQuals, BracketsRange);
5612}
5613
5614template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005615QualType
5616TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005617 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005618 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005619 unsigned IndexTypeQuals,
5620 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005621 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005622 SizeExpr.takeAs<Expr>(),
5623 IndexTypeQuals, BracketsRange);
5624}
5625
5626template<typename Derived>
5627QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson82287d12010-02-05 00:12:22 +00005628 unsigned NumElements,
5629 bool IsAltiVec, bool IsPixel) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005630 // FIXME: semantic checking!
John Thompson82287d12010-02-05 00:12:22 +00005631 return SemaRef.Context.getVectorType(ElementType, NumElements,
5632 IsAltiVec, IsPixel);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005633}
Mike Stump1eb44332009-09-09 15:08:12 +00005634
Douglas Gregor577f75a2009-08-04 16:50:30 +00005635template<typename Derived>
5636QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5637 unsigned NumElements,
5638 SourceLocation AttributeLoc) {
5639 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5640 NumElements, true);
5641 IntegerLiteral *VectorSize
Mike Stump1eb44332009-09-09 15:08:12 +00005642 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005643 AttributeLoc);
5644 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5645 AttributeLoc);
5646}
Mike Stump1eb44332009-09-09 15:08:12 +00005647
Douglas Gregor577f75a2009-08-04 16:50:30 +00005648template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005649QualType
5650TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005651 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005652 SourceLocation AttributeLoc) {
5653 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5654}
Mike Stump1eb44332009-09-09 15:08:12 +00005655
Douglas Gregor577f75a2009-08-04 16:50:30 +00005656template<typename Derived>
5657QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00005658 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005659 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00005660 bool Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005661 unsigned Quals) {
Mike Stump1eb44332009-09-09 15:08:12 +00005662 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005663 Quals,
5664 getDerived().getBaseLocation(),
5665 getDerived().getBaseEntity());
5666}
Mike Stump1eb44332009-09-09 15:08:12 +00005667
Douglas Gregor577f75a2009-08-04 16:50:30 +00005668template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005669QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5670 return SemaRef.Context.getFunctionNoProtoType(T);
5671}
5672
5673template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00005674QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5675 assert(D && "no decl found");
5676 if (D->isInvalidDecl()) return QualType();
5677
5678 TypeDecl *Ty;
5679 if (isa<UsingDecl>(D)) {
5680 UsingDecl *Using = cast<UsingDecl>(D);
5681 assert(Using->isTypeName() &&
5682 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5683
5684 // A valid resolved using typename decl points to exactly one type decl.
5685 assert(++Using->shadow_begin() == Using->shadow_end());
5686 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5687
5688 } else {
5689 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5690 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5691 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5692 }
5693
5694 return SemaRef.Context.getTypeDeclType(Ty);
5695}
5696
5697template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00005698QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005699 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5700}
5701
5702template<typename Derived>
5703QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5704 return SemaRef.Context.getTypeOfType(Underlying);
5705}
5706
5707template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00005708QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005709 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5710}
5711
5712template<typename Derived>
5713QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00005714 TemplateName Template,
5715 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00005716 const TemplateArgumentListInfo &TemplateArgs) {
5717 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005718}
Mike Stump1eb44332009-09-09 15:08:12 +00005719
Douglas Gregordcee1a12009-08-06 05:28:30 +00005720template<typename Derived>
5721NestedNameSpecifier *
5722TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5723 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00005724 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00005725 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00005726 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00005727 CXXScopeSpec SS;
5728 // FIXME: The source location information is all wrong.
5729 SS.setRange(Range);
5730 SS.setScopeRep(Prefix);
5731 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00005732 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00005733 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00005734 ObjectType,
5735 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00005736 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00005737}
5738
5739template<typename Derived>
5740NestedNameSpecifier *
5741TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5742 SourceRange Range,
5743 NamespaceDecl *NS) {
5744 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5745}
5746
5747template<typename Derived>
5748NestedNameSpecifier *
5749TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5750 SourceRange Range,
5751 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00005752 QualType T) {
5753 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00005754 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00005755 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00005756 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5757 T.getTypePtr());
5758 }
Mike Stump1eb44332009-09-09 15:08:12 +00005759
Douglas Gregordcee1a12009-08-06 05:28:30 +00005760 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5761 return 0;
5762}
Mike Stump1eb44332009-09-09 15:08:12 +00005763
Douglas Gregord1067e52009-08-06 06:41:21 +00005764template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005765TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00005766TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5767 bool TemplateKW,
5768 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00005769 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00005770 Template);
5771}
5772
5773template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005774TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00005775TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005776 const IdentifierInfo &II,
5777 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00005778 CXXScopeSpec SS;
5779 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump1eb44332009-09-09 15:08:12 +00005780 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00005781 UnqualifiedId Name;
5782 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005783 return getSema().ActOnDependentTemplateName(
5784 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005785 SS,
Douglas Gregor014e88d2009-11-03 23:16:33 +00005786 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00005787 ObjectType.getAsOpaquePtr(),
5788 /*EnteringContext=*/false)
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005789 .template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00005790}
Mike Stump1eb44332009-09-09 15:08:12 +00005791
Douglas Gregorb98b1992009-08-11 05:31:07 +00005792template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00005793TemplateName
5794TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5795 OverloadedOperatorKind Operator,
5796 QualType ObjectType) {
5797 CXXScopeSpec SS;
5798 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5799 SS.setScopeRep(Qualifier);
5800 UnqualifiedId Name;
5801 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5802 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5803 Operator, SymbolLocations);
5804 return getSema().ActOnDependentTemplateName(
5805 /*FIXME:*/getDerived().getBaseLocation(),
5806 SS,
5807 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00005808 ObjectType.getAsOpaquePtr(),
5809 /*EnteringContext=*/false)
Douglas Gregorca1bdd72009-11-04 00:56:37 +00005810 .template getAsVal<TemplateName>();
5811}
5812
5813template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005814Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005815TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5816 SourceLocation OpLoc,
5817 ExprArg Callee,
5818 ExprArg First,
5819 ExprArg Second) {
5820 Expr *FirstExpr = (Expr *)First.get();
5821 Expr *SecondExpr = (Expr *)Second.get();
John McCallba135432009-11-21 08:51:07 +00005822 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005823 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00005824
Douglas Gregorb98b1992009-08-11 05:31:07 +00005825 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00005826 if (Op == OO_Subscript) {
5827 if (!FirstExpr->getType()->isOverloadableType() &&
5828 !SecondExpr->getType()->isOverloadableType())
5829 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCallba135432009-11-21 08:51:07 +00005830 CalleeExpr->getLocStart(),
Sebastian Redlf322ed62009-10-29 20:17:01 +00005831 move(Second), OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00005832 } else if (Op == OO_Arrow) {
5833 // -> is never a builtin operation.
5834 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redlf322ed62009-10-29 20:17:01 +00005835 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005836 if (!FirstExpr->getType()->isOverloadableType()) {
5837 // The argument is not of overloadable type, so try to create a
5838 // built-in unary operation.
Mike Stump1eb44332009-09-09 15:08:12 +00005839 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005840 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00005841
Douglas Gregorb98b1992009-08-11 05:31:07 +00005842 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5843 }
5844 } else {
Mike Stump1eb44332009-09-09 15:08:12 +00005845 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005846 !SecondExpr->getType()->isOverloadableType()) {
5847 // Neither of the arguments is an overloadable type, so try to
5848 // create a built-in binary operation.
5849 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00005850 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00005851 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5852 if (Result.isInvalid())
5853 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005854
Douglas Gregorb98b1992009-08-11 05:31:07 +00005855 First.release();
5856 Second.release();
5857 return move(Result);
5858 }
5859 }
Mike Stump1eb44332009-09-09 15:08:12 +00005860
5861 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00005862 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00005863 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00005864
John McCallba135432009-11-21 08:51:07 +00005865 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5866 assert(ULE->requiresADL());
5867
5868 // FIXME: Do we have to check
5869 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00005870 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00005871 } else {
John McCall6e266892010-01-26 03:27:55 +00005872 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCallba135432009-11-21 08:51:07 +00005873 }
Mike Stump1eb44332009-09-09 15:08:12 +00005874
Douglas Gregorb98b1992009-08-11 05:31:07 +00005875 // Add any functions found via argument-dependent lookup.
5876 Expr *Args[2] = { FirstExpr, SecondExpr };
5877 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00005878
Douglas Gregorb98b1992009-08-11 05:31:07 +00005879 // Create the overloaded operator invocation for unary operators.
5880 if (NumArgs == 1 || isPostIncDec) {
Mike Stump1eb44332009-09-09 15:08:12 +00005881 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005882 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5883 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5884 }
Mike Stump1eb44332009-09-09 15:08:12 +00005885
Sebastian Redlf322ed62009-10-29 20:17:01 +00005886 if (Op == OO_Subscript)
John McCallba135432009-11-21 08:51:07 +00005887 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5888 OpLoc,
5889 move(First),
5890 move(Second));
Sebastian Redlf322ed62009-10-29 20:17:01 +00005891
Douglas Gregorb98b1992009-08-11 05:31:07 +00005892 // Create the overloaded operator invocation for binary operators.
Mike Stump1eb44332009-09-09 15:08:12 +00005893 BinaryOperator::Opcode Opc =
Douglas Gregorb98b1992009-08-11 05:31:07 +00005894 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00005895 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00005896 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5897 if (Result.isInvalid())
5898 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005899
Douglas Gregorb98b1992009-08-11 05:31:07 +00005900 First.release();
5901 Second.release();
Mike Stump1eb44332009-09-09 15:08:12 +00005902 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005903}
Mike Stump1eb44332009-09-09 15:08:12 +00005904
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005905template<typename Derived>
5906Sema::OwningExprResult
5907TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
5908 SourceLocation OperatorLoc,
5909 bool isArrow,
5910 NestedNameSpecifier *Qualifier,
5911 SourceRange QualifierRange,
5912 TypeSourceInfo *ScopeType,
5913 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005914 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005915 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005916 CXXScopeSpec SS;
5917 if (Qualifier) {
5918 SS.setRange(QualifierRange);
5919 SS.setScopeRep(Qualifier);
5920 }
5921
5922 Expr *BaseE = (Expr *)Base.get();
5923 QualType BaseType = BaseE->getType();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005924 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005925 (!isArrow && !BaseType->getAs<RecordType>()) ||
5926 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00005927 !BaseType->getAs<PointerType>()->getPointeeType()
5928 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005929 // This pseudo-destructor expression is still a pseudo-destructor.
5930 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
5931 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005932 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005933 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005934 /*FIXME?*/true);
5935 }
5936
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005937 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005938 DeclarationName Name
5939 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
5940 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
5941
5942 // FIXME: the ScopeType should be tacked onto SS.
5943
5944 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
5945 OperatorLoc, isArrow,
5946 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005947 Name, Destroyed.getLocation(),
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005948 /*TemplateArgs*/ 0);
5949}
5950
Douglas Gregor577f75a2009-08-04 16:50:30 +00005951} // end namespace clang
5952
5953#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H